From bba2fc14008a55308e270c4db0aaaecc34963762 Mon Sep 17 00:00:00 2001 From: Colin Faulkingham Date: Sat, 31 Oct 2026 19:58:48 +0000 Subject: [PATCH] Report omitted print-face selections in command-script exports (#10230) (#10235) * claim: #10230 * fix: report omitted print-face assignments in script exports --- apps/solidcraft-cli/tests/script_roundtrip.rs | 39 +++++++++++++++++++ crates/engine/src/cmd/script.rs | 3 +- crates/engine/src/cmd/script_tests.rs | 19 +++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/apps/solidcraft-cli/tests/script_roundtrip.rs b/apps/solidcraft-cli/tests/script_roundtrip.rs index 568c4bdb3..e959c6e89 100644 --- a/apps/solidcraft-cli/tests/script_roundtrip.rs +++ b/apps/solidcraft-cli/tests/script_roundtrip.rs @@ -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(); +} diff --git a/crates/engine/src/cmd/script.rs b/crates/engine/src/cmd/script.rs index d67c33095..d2bd90779 100644 --- a/crates/engine/src/cmd/script.rs +++ b/crates/engine/src/cmd/script.rs @@ -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, Vec)> (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"), diff --git a/crates/engine/src/cmd/script_tests.rs b/crates/engine/src/cmd/script_tests.rs index 1528d6174..75ff02d33 100644 --- a/crates/engine/src/cmd/script_tests.rs +++ b/crates/engine/src/cmd/script_tests.rs @@ -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();