Command ids are SolveCraft's own: 173 ids that were another product's internal command ids become dotted, lower-case ids (<area>.<thing>[.<variant>]: solid.extrude, sketch.rectangle.two_point, sheet.flange, joint.drive, ...), in the registry, toolbar, dialogs, shortcuts, palette, control channel, MCP, examples, scenarios and docs
The old ids live only in crates/engine/src/legacy_ids.rs (the legacy migration table): find_command maps them, so old scripts, recipes and control calls keep working, and saved shortcuts, recent and pinned commands are migrated on load (designs store no command ids). Parity maps the observed catalog ids to ours through xtask/data/fusion-ids.tsv. The agent rule now reads: our own dotted id, never another product's. Cargo.toml's repository points at github.com/bherbruck/solvecraft. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
740360d7c3
commit
d10312b7fd
158 files changed
+3611
-3205
No files matched your search
@@ -17,7 +17,7 @@ fn err(s: &mut Session, id: &str, p: Value) -> String {
|
||||
}
|
||||
|
||||
fn volume(s: &mut Session) -> f64 {
|
||||
run(s, "MeasureCommand", json!({}))["total"]["volume_mm3"].as_f64().unwrap_or(f64::NAN)
|
||||
run(s, "inspect.measure", json!({}))["total"]["volume_mm3"].as_f64().unwrap_or(f64::NAN)
|
||||
}
|
||||
|
||||
fn rel(a: f64, b: f64) -> f64 {
|
||||
@@ -36,13 +36,13 @@ fn expr_of(s: &mut Session, name: &str) -> String {
|
||||
/// A sketched block 40 x (len / 2) x 10 whose width is an expression of a user parameter.
|
||||
fn block(s: &mut Session) {
|
||||
run(s, "parameters.add", json!({"name": "len", "expression": "60 mm", "comment": "overall length", "favorite": true}));
|
||||
run(s, "SketchCreate", json!({"plane": "XY", "name": "Base"}));
|
||||
run(s, "ShapeRectangleTwoPoint", json!({"p0": [0, 0], "p1": [40, 30]}));
|
||||
run(s, "ConstraintCoincident", json!({"a": "p1", "b": "origin"}));
|
||||
run(s, "SketchDimension", json!({"entities": ["l1"], "value": 40}));
|
||||
run(s, "SketchDimension", json!({"entities": ["l2"], "value": "len/2"}));
|
||||
run(s, "SketchStop", json!({}));
|
||||
run(s, "Extrude", json!({"distance": 10, "body_name": "Block"}));
|
||||
run(s, "sketch.create", json!({"plane": "XY", "name": "Base"}));
|
||||
run(s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 30]}));
|
||||
run(s, "sketch.constraint.coincident", json!({"a": "p1", "b": "origin"}));
|
||||
run(s, "sketch.dimension", json!({"entities": ["l1"], "value": 40}));
|
||||
run(s, "sketch.dimension", json!({"entities": ["l2"], "value": "len/2"}));
|
||||
run(s, "sketch.finish", json!({}));
|
||||
run(s, "solid.extrude", json!({"distance": 10, "body_name": "Block"}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -50,20 +50,20 @@ fn width_follows_an_expression() {
|
||||
let mut s = Session::default();
|
||||
block(&mut s);
|
||||
assert!(rel(volume(&mut s), 40.0 * 30.0 * 10.0) < 1e-9);
|
||||
let r = run(&mut s, "ChangeParameterCommand", json!({"name": "len", "expression": "100 mm"}));
|
||||
let r = run(&mut s, "parameters.change", json!({"name": "len", "expression": "100 mm"}));
|
||||
assert_eq!(r["errors"].as_array().map(Vec::len), Some(0), "{r}");
|
||||
assert!(rel(volume(&mut s), 40.0 * 50.0 * 10.0) < 1e-9);
|
||||
// Units convert: 4 in = 101.6 mm.
|
||||
run(&mut s, "ChangeParameterCommand", json!({"name": "len", "expression": "4 in"}));
|
||||
run(&mut s, "parameters.change", json!({"name": "len", "expression": "4 in"}));
|
||||
assert!(rel(volume(&mut s), 40.0 * 50.8 * 10.0) < 1e-9);
|
||||
// A parameter in inches reads bare numbers as inches.
|
||||
run(&mut s, "ChangeParameterCommand", json!({"name": "len", "expression": "5", "unit": "in"}));
|
||||
run(&mut s, "parameters.change", json!({"name": "len", "expression": "5", "unit": "in"}));
|
||||
assert!(rel(volume(&mut s), 40.0 * 63.5 * 10.0) < 1e-9);
|
||||
let l = run(&mut s, "parameters.list", json!({}));
|
||||
assert_eq!(row(&l, "len")["value"], 5.0, "{l}");
|
||||
assert_eq!(row(&l, "len")["unit"], "in");
|
||||
// A failing parameter fails the features using it, with its error.
|
||||
let e = err(&mut s, "ChangeParameterCommand", json!({"name": "len", "expression": "5 deg"}));
|
||||
let e = err(&mut s, "parameters.change", json!({"name": "len", "expression": "5 deg"}));
|
||||
assert!(e.contains("expected a length, got an angle"), "{e}");
|
||||
}
|
||||
|
||||
@@ -75,14 +75,14 @@ fn feature_inputs_are_named_and_editable() {
|
||||
let dist = l["parameters"].as_array().unwrap().iter().find(|r| r["input"] == "Distance").unwrap().clone();
|
||||
assert_eq!(dist["feature"], "Extrude1", "{l}");
|
||||
let d = dist["name"].as_str().unwrap().to_string();
|
||||
run(&mut s, "ChangeParameterCommand", json!({"name": d, "expression": "len / 3"}));
|
||||
run(&mut s, "parameters.change", json!({"name": d, "expression": "len / 3"}));
|
||||
assert!(rel(volume(&mut s), 40.0 * 30.0 * 20.0) < 1e-9);
|
||||
// Editing the feature keeps its parameter name.
|
||||
run(&mut s, "timeline.edit", json!({"feature": "Extrude1", "set": {"extent": {"distance": "12 mm"}}}));
|
||||
assert!(rel(volume(&mut s), 40.0 * 30.0 * 12.0) < 1e-9);
|
||||
assert_eq!(expr_of(&mut s, &d), "12 mm");
|
||||
// Another feature can use it.
|
||||
run(&mut s, "PrimitiveBox", json!({"length": d, "width": 5, "height": 5, "corner": [100, 0, 0]}));
|
||||
run(&mut s, "solid.box", json!({"length": d, "width": 5, "height": 5, "corner": [100, 0, 0]}));
|
||||
assert!(rel(volume(&mut s), 40.0 * 30.0 * 12.0 + 12.0 * 25.0) < 1e-9);
|
||||
let u = run(&mut s, "parameters.users", json!({"name": d}));
|
||||
assert_eq!(u["users"].as_array().map(Vec::len), Some(1), "{u}");
|
||||
@@ -101,7 +101,7 @@ fn unit_errors_and_cycles_are_refused() {
|
||||
assert!(e.contains("expected an angle, got a length"), "{e}");
|
||||
assert!(err(&mut s, "parameters.add", json!({"name": "x", "expression": "1", "unit": "furlong"})).contains("unknown unit"));
|
||||
run(&mut s, "parameters.add", json!({"name": "b", "expression": "a * 2"}));
|
||||
let e = err(&mut s, "ChangeParameterCommand", json!({"name": "a", "expression": "b + 1"}));
|
||||
let e = err(&mut s, "parameters.change", json!({"name": "a", "expression": "b + 1"}));
|
||||
assert!(e.contains("circular reference: a → b → a"), "{e}");
|
||||
assert!(err(&mut s, "parameters.add", json!({"name": "selfref", "expression": "selfref"})).contains("circular"));
|
||||
assert!(err(&mut s, "parameters.add", json!({"name": "a", "expression": "1"})).contains("already"));
|
||||
@@ -132,7 +132,7 @@ fn rename_updates_every_reference() {
|
||||
let l = run(&mut s, "parameters.list", json!({"favorites": true}));
|
||||
assert_eq!(l["count"], 1, "the favourite follows the rename");
|
||||
assert_eq!(row(&l, "length")["comment"], "overall length");
|
||||
run(&mut s, "ChangeParameterCommand", json!({"name": "length", "expression": "80"}));
|
||||
run(&mut s, "parameters.change", json!({"name": "length", "expression": "80"}));
|
||||
assert!(rel(volume(&mut s), 40.0 * 40.0 * 10.0) < 1e-9);
|
||||
// Model and feature parameters can be renamed too: dimensions and features follow.
|
||||
let dim = s.doc.features.first().and_then(|f| match &f.kind {
|
||||
@@ -140,17 +140,17 @@ fn rename_updates_every_reference() {
|
||||
_ => None,
|
||||
});
|
||||
let dim = dim.unwrap_or_default();
|
||||
run(&mut s, "ChangeParameterCommand", json!({"name": dim, "new_name": "base_w", "expression": "50"}));
|
||||
run(&mut s, "parameters.change", json!({"name": dim, "new_name": "base_w", "expression": "50"}));
|
||||
assert!(rel(volume(&mut s), 50.0 * 40.0 * 10.0) < 1e-9);
|
||||
let ext = s.doc.features.get(1).and_then(|f| f.param_names.first().cloned()).unwrap_or_default();
|
||||
run(&mut s, "parameters.rename", json!({"name": ext, "new_name": "thick"}));
|
||||
run(&mut s, "ChangeParameterCommand", json!({"name": "thick", "expression": "base_w / 10"}));
|
||||
run(&mut s, "parameters.change", json!({"name": "thick", "expression": "base_w / 10"}));
|
||||
assert!(rel(volume(&mut s), 50.0 * 40.0 * 5.0) < 1e-9);
|
||||
assert!(err(&mut s, "parameters.rename", json!({"name": "twice", "new_name": "length"})).contains("already"));
|
||||
assert!(err(&mut s, "parameters.rename", json!({"name": "nope", "new_name": "x"})).contains("unknown"));
|
||||
// Undo puts the old name back.
|
||||
run(&mut s, "UndoCommand", json!({}));
|
||||
run(&mut s, "UndoCommand", json!({}));
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert!(s.doc.features.get(1).is_some_and(|f| f.param_names.first() == Some(&ext)));
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ fn deleting_a_used_parameter_lists_its_users() {
|
||||
assert_eq!(u["users"].as_array().map(Vec::len), Some(2), "{u}");
|
||||
assert_eq!(u["drives"][0]["name"], "Base", "{u}");
|
||||
let dim = u["users"].as_array().unwrap().iter().find(|x| x["name"] != "spare").unwrap()["name"].as_str().unwrap().to_string();
|
||||
let e = err(&mut s, "ChangeParameterCommand", json!({"delete": dim}));
|
||||
let e = err(&mut s, "parameters.change", json!({"delete": dim}));
|
||||
assert!(e.contains("Base dimension"), "{e}");
|
||||
run(&mut s, "parameters.delete", json!({"name": "spare"}));
|
||||
assert!(s.doc.param("spare").is_none());
|
||||
|
||||
Reference in new issue
Block a user