M3: a publish refusal gives each left-out asset's id beside its name

A name can be shared, or read as a style or collection id, so listing it
in include or exclude could select another asset. The id selects only it.
This commit is contained in:
bflatastic
2026-12-06 02:11:22 +07:00
parent ed826d25c9
commit 6bfbd9ccf4
3 changed files with 20 additions and 15 deletions
+10 -5
View File
@@ -837,8 +837,8 @@ fn an_include_that_leaves_out_offered_assets_is_refused() {
ex(&mut s, "library.publish", json!({"include": [k.card]}));
}
/// The refusal names a left-out asset as it is called now, so that name works in `include` or
/// `exclude`: a component renamed since the last version is not named by its old name.
/// The refusal names a left-out asset as it is called now, not by its name in the last version,
/// and gives the id that selects only it: a name can be shared, or read as a style's id.
#[test]
fn a_refusal_names_a_renamed_asset_by_its_current_name() {
let mut s = Session::new();
@@ -846,8 +846,13 @@ fn a_refusal_names_a_renamed_asset_by_its_current_name() {
ex(&mut s, "library.publish", json!({}));
ex(&mut s, "node.set", json!({"id": k.button, "props": {"name": "Primary button"}}));
let e = s.execute("library.publish", &json!({"include": [k.card, "Brand"]})).unwrap_err().to_string();
assert!(e.contains("\"Primary button\""), "{e}");
assert!(e.contains(&format!("\"Primary button\" ({})", k.button.0)), "{e}");
assert!(!e.contains("\"Button\""), "{e}");
let r = ex(&mut s, "library.publish", json!({"include": [k.card, "Brand"], "exclude": ["Primary button"]}));
assert_eq!(r["components"], 1, "{r}");
// Renamed to the style's id, the component's name would select the style; its id selects it.
let style = s.doc().unwrap().styles[0].id.clone();
ex(&mut s, "node.set", json!({"id": k.button, "props": {"name": style}}));
let e = s.execute("library.publish", &json!({"include": [k.card, style]})).unwrap_err().to_string();
assert!(e.contains(&format!("\"{style}\" ({})", k.button.0)), "{e}");
let r = ex(&mut s, "library.publish", json!({"include": [k.card, style], "exclude": [k.button.0]}));
assert_eq!((r["components"].as_u64(), r["styles"].as_u64()), (Some(1), Some(1)), "{r}");
}
+8 -8
View File
@@ -339,7 +339,7 @@ fn publish_args(cmd: &str, doc: &Document, p: &Value, prev: Option<&LibraryManif
return Err(bad(
cmd,
format!(
"the last version offered {} that `include` leaves out: add them to `include` to keep offering them, or name them in `exclude` to stop",
"the last version offered {} that `include` leaves out: add their ids (in brackets) to `include` to keep offering them, or to `exclude` to stop",
left_out.join(", ")
),
));
@@ -352,26 +352,26 @@ fn publish_args(cmd: &str, doc: &Document, p: &Value, prev: Option<&LibraryManif
Ok((sel, description))
}
/// The names, as `doc` has them now, of the assets `prev` offered that are still publishable (`all`)
/// and not hidden, but neither `sel` nor `exclude` lists. Current names, since `include` and
/// `exclude` resolve names in `doc`: an asset renamed since `prev` is named as it can be listed.
/// The assets `prev` offered that are still publishable (`all`) and not hidden, but neither `sel`
/// nor `exclude` lists: each `"name" (id)`, its name as `doc` has it now and its id as `include` and
/// `exclude` take it. The id, since a name can be shared or read as a style or collection id.
fn withdrawn(doc: &Document, prev: &LibraryManifest, all: &Selection, sel: &Selection, exclude: &Selection) -> Vec<String> {
let shown = |name: Option<&str>| name.filter(|n| !crate::library::hidden_name(n)).map(|n| format!("\"{n}\""));
let shown = |name: Option<&str>, id: Value| name.filter(|n| !crate::library::hidden_name(n)).map(|n| format!("\"{n}\" ({id})"));
let components = prev
.components
.iter()
.filter(|a| a.published && all.components.contains(&a.id) && !sel.components.contains(&a.id) && !exclude.components.contains(&a.id))
.filter_map(|a| shown(doc.node(a.id).map(|n| n.name.as_str())));
.filter_map(|a| shown(doc.node(a.id).map(|n| n.name.as_str()), json!(a.id.0)));
let styles = prev
.styles
.iter()
.filter(|st| st.published && all.styles.contains(&st.id) && !sel.styles.contains(&st.id) && !exclude.styles.contains(&st.id))
.filter_map(|st| shown(doc.style(&st.id).map(|x| x.name.as_str())));
.filter_map(|st| shown(doc.style(&st.id).map(|x| x.name.as_str()), json!(st.id)));
let collections = prev
.collections
.iter()
.filter(|c| c.published && all.collections.contains(&c.id) && !sel.collections.contains(&c.id) && !exclude.collections.contains(&c.id))
.filter_map(|c| shown(doc.variables.collection_by_id(&c.id).map(|x| x.name.as_str())));
.filter_map(|c| shown(doc.variables.collection_by_id(&c.id).map(|x| x.name.as_str()), json!(c.id)));
components.chain(styles).chain(collections).collect()
}
File diff suppressed because one or more lines are too long