Report omitted print-face selections in command-script exports (#10230) (#10235)

* claim: #10230

* fix: report omitted print-face assignments in script exports
This commit is contained in:
Colin Faulkingham
2026-10-31 19:58:48 +00:00
committed by GitHub
parent 538d7fcb43
commit bba2fc1400
3 changed files with 60 additions and 1 deletions
@@ -123,3 +123,42 @@ fn a_design_naming_a_sketch_and_its_extrude_alike_replays_from_its_script() {
assert_eq!(names, ["Block", "Block"], "{first:#}");
assert_eq!(second["commands"], first["commands"], "the replayed design's script has the same steps");
}
/// #10230: script export must disclose the print-face state that replay leaves out.
#[test]
fn script_export_warns_about_omitted_print_faces_on_stderr() {
let dir = std::env::temp_dir().join(format!("solidcraft-print-face-script-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let saved = dir.join("block.sc");
let exported = dir.join("block.json");
let mut s = Session::default();
s.execute("solid.box", &json!({"length": 20, "width": 10, "height": 5, "body_name": "Block"})).unwrap();
s.execute("body.print_face", &json!({"body": "Block", "point": [10, 5, 0]})).unwrap();
s.execute("file.save", &json!({"path": saved})).unwrap();
let native = std::fs::read(&saved).unwrap();
for to_file in [false, true] {
let mut cmd = std::process::Command::new(env!("CARGO_BIN_EXE_solidcraft-cli"));
cmd.arg("script").arg(&saved);
if to_file {
cmd.arg("--out").arg(&exported);
}
let out = cmd.output().unwrap();
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(out.status.success(), "{stderr}");
assert!(stderr.contains("note: the script leaves out print-face assignments (body.print_face)"), "{stderr}");
let script = if to_file {
assert!(out.stdout.is_empty(), "--out must keep stdout empty");
std::fs::read(&exported).unwrap()
} else {
out.stdout
};
let script: Value = serde_json::from_slice(&script).unwrap();
let mut replayed = Session::default();
replayed.run_script(&script).unwrap();
assert!(replayed.doc.print_faces.is_empty());
assert_eq!(replayed.doc.features, s.doc.features);
assert_eq!(std::fs::read(&saved).unwrap(), native, "export must not change the source design");
}
std::fs::remove_dir_all(dir).unwrap();
}
+2 -1
View File
@@ -21,7 +21,7 @@ pub static COMMANDS: &[CommandSpec] = &[
),
CommandSpec::new("timeline.export_script", "Export Command Script", export_script).icon("export").noundo().doc_only().params(
"path?: write the script to this file → script: {commands: [...]} that rebuilds the design (solidcraft-cli eval/run), \
steps, omitted: what the script leaves out (appearances, folders, views, configurations); components and assemblies \
steps, omitted: what the script leaves out (appearances, folders, views, configurations, print-face assignments); components and assemblies \
are not supported yet",
),
];
@@ -198,6 +198,7 @@ pub(crate) fn script_steps(doc: &Document) -> Result<(Vec<Value>, Vec<String>)>
(doc.configs.is_empty(), "configurations"),
(doc.canvases.is_empty(), "canvases (reference images)"),
(doc.point_clouds.is_empty(), "point clouds"),
(doc.print_faces.is_empty(), "print-face assignments (body.print_face)"),
(doc.named_views.is_empty(), "named views"),
(doc.browser_groups.is_empty() && doc.browser_order.is_empty(), "Browser folders and order"),
(doc.timeline_groups.is_empty(), "timeline folders"),
+19
View File
@@ -170,6 +170,25 @@ fn what_the_script_leaves_out_is_listed_and_components_are_refused() {
assert!(e.contains("not supported yet"), "{e}");
}
#[test]
fn omitted_print_faces_are_reported_without_changing_the_design() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 20, "width": 10, "height": 5, "body_name": "Block"}));
assert_eq!(run(&mut s, "timeline.export_script", json!({}))["omitted"], json!([]));
run(&mut s, "body.print_face", json!({"body": "Block", "point": [10, 5, 0]}));
let before = (*s.doc).clone();
let r = run(&mut s, "timeline.export_script", json!({}));
assert_eq!(r["omitted"], json!(["print-face assignments (body.print_face)"]));
assert_eq!(*s.doc, before, "export must keep the saved print-face assignment");
let mut t = replay(&r["script"]);
assert!(t.doc.print_faces.is_empty(), "the reported omission matches the replay");
same(&mut s, &mut t);
run(&mut s, "body.print_face", json!({"body": "Block"}));
assert_eq!(run(&mut s, "timeline.export_script", json!({}))["omitted"], json!([]));
}
#[test]
fn a_recorded_feature_that_does_not_fit_is_refused_and_changes_nothing() {
let mut s = Session::default();