diff --git a/crates/engine/src/cmd/config.rs b/crates/engine/src/cmd/config.rs index 9bb000fdd..6bf8a3071 100644 --- a/crates/engine/src/cmd/config.rs +++ b/crates/engine/src/cmd/config.rs @@ -331,6 +331,11 @@ fn row(s: &mut Session, p: &Value) -> Result { if rename.as_ref().is_some_and(|n| n != &name && s.doc.configs.rows.iter().any(|r| &r.name == n)) { return Err(bad(cmd, "configuration name already exists")); } + for (column, value) in s.doc.configs.columns.iter().zip(&cells) { + if matches!(column, Column::Suppress(_)) { + solidcraft_doc::config::suppression_cell(value).map_err(|e| bad(cmd, e.to_string()))?; + } + } let changes: Vec<_> = s .doc .configs @@ -743,6 +748,78 @@ mod tests { } } + #[test] + fn configuration_rows_reject_invalid_suppression_without_changes() { + let mut s = Session::default(); + run(&mut s, "sketch.create", json!({"plane":"XY", "name":"TestSketch"})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "config.configure", json!({"features":["TestSketch"]})); + let before = s.doc.clone(); + let undo_len = s.undo.len(); + for value in [json!("banana"), json!(""), json!(2), json!(-1)] { + for params in [ + json!({"name":"Bad", "values":{"suppress:TestSketch":value}}), + json!({"name":"Copy", "from":"Default", "values":{"TestSketch":value}}), + json!({"name":"Default", "rename":"Renamed", "values":{"TestSketch":value}}), + ] { + let error = s.execute("config.row", ¶ms).expect_err("invalid suppression must be rejected when saving a row"); + assert!(error.to_string().contains("suppression must be true or false"), "{params}: {error}"); + assert_eq!(s.doc, before, "{params}"); + assert_eq!(s.undo.len(), undo_len, "{params}"); + } + } + } + + #[test] + fn configuration_rows_validate_inherited_suppression_and_allow_repair() { + let mut s = Session::default(); + run(&mut s, "sketch.create", json!({"plane":"XY", "name":"TestSketch"})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "config.configure", json!({"features":["TestSketch"]})); + // A row saved by an older reader may already contain invalid suppression text. + s.doc_mut().configs.rows[0].cells[0] = "banana".into(); + let before = s.doc.clone(); + let undo_len = s.undo.len(); + for params in [json!({"name":"Copy", "from":"Default"}), json!({"name":"Default", "rename":"Renamed"})] { + let error = s.execute("config.row", ¶ms).expect_err("inherited invalid suppression must also be checked"); + assert!(error.to_string().contains("suppression must be true or false"), "{params}: {error}"); + assert_eq!(s.doc, before, "{params}"); + assert_eq!(s.undo.len(), undo_len, "{params}"); + } + run(&mut s, "config.row", json!({"name":"Default", "values":{"TestSketch":false}})); + assert_eq!(s.doc.configs.rows[0].cells[0], "false"); + run(&mut s, "config.activate", json!({"row":"Default"})); + assert!(!s.doc.features[0].suppressed); + } + + #[test] + fn configuration_rows_keep_supported_suppression_spellings() { + let mut s = Session::default(); + run(&mut s, "sketch.create", json!({"plane":"XY", "name":"TestSketch"})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "config.configure", json!({"features":["TestSketch"]})); + for (value, suppressed) in [ + (json!(true), true), + (json!(false), false), + (json!(1), true), + (json!(0), false), + (json!("true"), true), + (json!("false"), false), + (json!(" YES "), true), + (json!(" No "), false), + (json!("1"), true), + (json!("0"), false), + ] { + let before = s.doc.features.clone(); + run(&mut s, "config.row", json!({"name":"Accepted", "values":{"suppress:TestSketch":value}})); + assert_eq!(s.doc.features, before, "saving a row does not activate it"); + let text = value.as_str().map(str::to_owned).unwrap_or_else(|| value.to_string()); + assert_eq!(s.doc.configs.rows[1].cells[0], text, "accepted spellings are preserved"); + run(&mut s, "config.activate", json!({"row":"Accepted"})); + assert_eq!(s.doc.features[0].suppressed, suppressed, "{value}"); + } + } + #[test] fn configuration_rows_validate_the_final_parameter_graph_without_activating_it() { let mut s = Session::default(); diff --git a/docs/configurations.md b/docs/configurations.md index 12c46bfc9..4245bfe57 100644 --- a/docs/configurations.md +++ b/docs/configurations.md @@ -35,6 +35,10 @@ face appearances keep their existing priority. Physical material changes affect `delete` to remove it. Names must be unique. To remove a style column, use `config.column` with `material` or `appearance` set to the target body and `delete: true`. +Suppression cells accept `true`/`false`, `yes`/`no`, and `1`/`0`, ignoring case and surrounding +whitespace. Creating, copying, or editing a row checks its final suppression values before saving. +An invalid value leaves the table and undo history unchanged; accepted text keeps its spelling. + Body style columns target body names. Assignments remain stored when a row suppresses the feature that produces that body, and become visible when it returns.