fix(engine): report design variant in timeline.inspect and accept in timeline.add (#10748) (#10792)

* fix(engine): report design variant in timeline.inspect and accept in timeline.add (#10748)

* ci: refresh checks to clear cancelled workflow run
This commit is contained in:
Kushagra Kumar authored and GitHub committed 2026-11-01 21:00:44 +00:00
1 parent 303236e524
commit 446590dca1
8 files changed
+224 -5

No files matched your search

+161
View File
@@ -2433,6 +2433,167 @@ impl FeatureKind {
FeatureKind::MeshConvert { .. } => "MeshConvertFeature",
}
}
/// Design-file variant key (e.g. `"extrude"`, `"box"`, `"sheet_flange"`).
pub fn kind_key(&self) -> &'static str {
match self {
FeatureKind::BodyTransfer { .. } => "body_transfer",
FeatureKind::Sketch { .. } => "sketch",
FeatureKind::Extrude { .. } => "extrude",
FeatureKind::Revolve { .. } => "revolve",
FeatureKind::Fillet { .. } => "fillet",
FeatureKind::Chamfer { .. } => "chamfer",
FeatureKind::Box { .. } => "box",
FeatureKind::Cylinder { .. } => "cylinder",
FeatureKind::Sphere { .. } => "sphere",
FeatureKind::Torus { .. } => "torus",
FeatureKind::Cone { .. } => "cone",
FeatureKind::Combine { .. } => "combine",
FeatureKind::Pattern { .. } => "pattern",
FeatureKind::Mirror { .. } => "mirror",
FeatureKind::Hole { .. } => "hole",
FeatureKind::Thread { .. } => "thread",
FeatureKind::Loft { .. } => "loft",
FeatureKind::Sweep { .. } => "sweep",
FeatureKind::Shell { .. } => "shell",
FeatureKind::Draft { .. } => "draft",
FeatureKind::ConstructionPlane { .. } => "construction_plane",
FeatureKind::Split { .. } => "split",
FeatureKind::ConstructionAxis { .. } => "construction_axis",
FeatureKind::ConstructionPoint { .. } => "construction_point",
FeatureKind::SplitFace { .. } => "split_face",
FeatureKind::Scale { .. } => "scale",
FeatureKind::OffsetFace { .. } => "offset_face",
FeatureKind::DeleteFace { .. } => "delete_face",
FeatureKind::BoundingSolid { .. } => "bounding_solid",
FeatureKind::Pipe { .. } => "pipe",
FeatureKind::FrameMember { .. } => "frame_member",
FeatureKind::Emboss { .. } => "emboss",
FeatureKind::Rib { .. } => "rib",
FeatureKind::ReplaceFace { .. } => "replace_face",
FeatureKind::Align { .. } => "align",
FeatureKind::Coil { .. } => "coil",
FeatureKind::SheetBase { .. } => "sheet_base",
FeatureKind::SheetContour { .. } => "sheet_contour",
FeatureKind::SheetFlange { .. } => "sheet_flange",
FeatureKind::SheetHem { .. } => "sheet_hem",
FeatureKind::SheetPerforate { .. } => "sheet_perforate",
FeatureKind::SheetFold { .. } => "sheet_fold",
FeatureKind::SheetPath { .. } => "sheet_path",
FeatureKind::SheetUnfold { .. } => "sheet_unfold",
FeatureKind::SheetConvert { .. } => "sheet_convert",
FeatureKind::Boss { .. } => "boss",
FeatureKind::Lip { .. } => "lip",
FeatureKind::SnapFit { .. } => "snap_fit",
FeatureKind::Rest { .. } => "rest",
FeatureKind::BoundaryFill { .. } => "boundary_fill",
FeatureKind::Remove { .. } => "remove",
FeatureKind::Patch { .. } => "patch",
FeatureKind::Stitch { .. } => "stitch",
FeatureKind::Thicken { .. } => "thicken",
FeatureKind::SurfaceExtrude { .. } => "surface_extrude",
FeatureKind::Unstitch { .. } => "unstitch",
FeatureKind::ReverseNormal { .. } => "reverse_normal",
FeatureKind::SurfaceUntrim { .. } => "surface_untrim",
FeatureKind::SurfaceRevolve { .. } => "surface_revolve",
FeatureKind::SurfaceSweep { .. } => "surface_sweep",
FeatureKind::SurfaceLoft { .. } => "surface_loft",
FeatureKind::SurfaceOffset { .. } => "surface_offset",
FeatureKind::SurfaceRuled { .. } => "surface_ruled",
FeatureKind::SurfaceExtend { .. } => "surface_extend",
FeatureKind::SurfaceBlend { .. } => "surface_blend",
FeatureKind::SurfaceBoundary { .. } => "surface_boundary",
FeatureKind::SurfaceNetwork { .. } => "surface_network",
FeatureKind::SurfaceMatch { .. } => "surface_match",
FeatureKind::SurfaceFair { .. } => "surface_fair",
FeatureKind::SurfaceTrim { .. } => "surface_trim",
FeatureKind::Move { .. } => "move",
FeatureKind::Import { .. } => "import",
FeatureKind::MeshConvert { .. } => "mesh_convert",
FeatureKind::MeshImport { .. } => "mesh_import",
}
}
/// Map a display or Rust type name (e.g. `"HoleFeature"`, `"EdgeFlangeFeature"`)
/// to the canonical design-file variant key (`"hole"`, `"sheet_flange"`).
pub fn type_name_to_kind_key(name: &str) -> Option<&'static str> {
Some(match name {
"BodyTransferFeature" => "body_transfer",
"Sketch" => "sketch",
"ExtrudeFeature" => "extrude",
"RevolveFeature" => "revolve",
"FilletFeature" => "fillet",
"ChamferFeature" => "chamfer",
"BoxFeature" => "box",
"CylinderFeature" => "cylinder",
"SphereFeature" => "sphere",
"TorusFeature" => "torus",
"ConeFeature" => "cone",
"CombineFeature" => "combine",
"RectangularPatternFeature" | "PathPatternFeature" | "CircularPatternFeature" => "pattern",
"MirrorFeature" => "mirror",
"ConstructionPlane" => "construction_plane",
"HoleFeature" => "hole",
"ThreadFeature" => "thread",
"LoftFeature" => "loft",
"SweepFeature" => "sweep",
"ShellFeature" => "shell",
"DraftFeature" => "draft",
"SplitBodyFeature" => "split",
"SplitFaceFeature" => "split_face",
"ConstructionAxis" => "construction_axis",
"ConstructionPoint" => "construction_point",
"MoveFeature" => "move",
"ScaleFeature" => "scale",
"OffsetFacesFeature" => "offset_face",
"DeleteFaceFeature" => "delete_face",
"OffsetSurfaceFeature" => "surface_offset",
"BoundingSolidFeature" => "bounding_solid",
"PipeFeature" => "pipe",
"FrameMemberFeature" => "frame_member",
"EmbossFeature" => "emboss",
"BossFeature" => "boss",
"LipFeature" | "GrooveFeature" => "lip",
"SnapFitFeature" => "snap_fit",
"RestFeature" => "rest",
"BoundaryFillFeature" => "boundary_fill",
"BaseFlangeFeature" => "sheet_base",
"ContourFlangeFeature" => "sheet_contour",
"EdgeFlangeFeature" => "sheet_flange",
"HemFeature" => "sheet_hem",
"PerforateFeature" => "sheet_perforate",
"FoldFeature" => "sheet_fold",
"PathFlangeFeature" => "sheet_path",
"UnfoldFeature" | "RefoldFeature" => "sheet_unfold",
"ConvertToSheetMetalFeature" => "sheet_convert",
"CoilFeature" => "coil",
"RibFeature" | "WebFeature" => "rib",
"ReplaceFaceFeature" => "replace_face",
"AlignFeature" => "align",
"RemoveFeature" => "remove",
"PatchFeature" => "patch",
"SurfaceExtrudeFeature" => "surface_extrude",
"SurfaceRevolveFeature" => "surface_revolve",
"SurfaceSweepFeature" => "surface_sweep",
"SurfaceLoftFeature" => "surface_loft",
"BlendFeature" => "surface_blend",
"BoundaryFeature" => "surface_boundary",
"MatchFeature" => "surface_match",
"FairFeature" => "surface_fair",
"StitchFeature" => "stitch",
"ThickenFeature" => "thicken",
"TrimFeature" => "surface_trim",
"ExtendFeature" => "surface_extend",
"RuledSurfaceFeature" => "surface_ruled",
"UnstitchFeature" => "unstitch",
"ReverseNormalFeature" => "reverse_normal",
"UntrimFeature" => "surface_untrim",
"BaseFeature" => "import",
"MeshFeature" => "mesh_import",
"MeshConvertFeature" => "mesh_convert",
_ => return None,
})
}
/// Default name prefix (`Extrude` → `Extrude1`).
pub fn base_name(&self) -> &'static str {
match self {
+16
View File
@@ -885,3 +885,19 @@ fn browser_data_survives_a_save_and_old_designs_read_unchanged() {
assert_eq!(resaved["browser_groups"], groups, "{order}");
}
}
/// #10748: verify that type names map to their canonical design-file kind keys.
#[test]
fn feature_kind_key_and_type_name_mappings() {
assert_eq!(FeatureKind::type_name_to_kind_key("HoleFeature"), Some("hole"));
assert_eq!(FeatureKind::type_name_to_kind_key("BoxFeature"), Some("box"));
assert_eq!(FeatureKind::type_name_to_kind_key("EdgeFlangeFeature"), Some("sheet_flange"));
assert_eq!(FeatureKind::type_name_to_kind_key("RectangularPatternFeature"), Some("pattern"));
assert_eq!(FeatureKind::type_name_to_kind_key("PathPatternFeature"), Some("pattern"));
assert_eq!(FeatureKind::type_name_to_kind_key("CircularPatternFeature"), Some("pattern"));
assert_eq!(FeatureKind::type_name_to_kind_key("ExtrudeFeature"), Some("extrude"));
assert_eq!(FeatureKind::type_name_to_kind_key("SplitBodyFeature"), Some("split"));
assert_eq!(FeatureKind::type_name_to_kind_key("BaseFeature"), Some("import"));
assert_eq!(FeatureKind::type_name_to_kind_key("MeshFeature"), Some("mesh_import"));
assert_eq!(FeatureKind::type_name_to_kind_key("NonExistent"), None);
}
+1 -1
View File
@@ -1123,7 +1123,7 @@ fn inspect_feature(s: &mut Session, p: &Value) -> Result<Value> {
let rolled_back = s.doc.features.iter().position(|x| x.id == id).is_some_and(|i| i >= marker);
let r = s.model.result(id);
Ok(json!({
"id": f.id, "name": f.name, "type": f.kind.type_name(), "suppressed": f.suppressed, "rolled_back": rolled_back,
"id": f.id, "name": f.name, "type": f.kind.kind_key(), "type_name": f.kind.type_name(), "suppressed": f.suppressed, "rolled_back": rolled_back,
"definition": def, "omitted": omitted, "inputs": inputs,
"error": r.and_then(|r| r.error.clone()), "warning": r.and_then(|r| r.warning.clone()),
"boolean_diagnostics": r.map(|r| &r.boolean_diagnostics),
+13
View File
@@ -36,6 +36,19 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
.and_then(Value::as_object)
.ok_or_else(|| bad(cmd, "`feature` must be a feature object, as a design file or timeline.inspect has it"))?;
let mut raw = raw.clone();
if let Some(Value::Object(def)) = raw.remove("definition") {
for (k, v) in def {
raw.entry(k).or_insert(v);
}
}
for meta in ["omitted", "inputs", "error", "warning", "boolean_diagnostics", "rolled_back", "type_name"] {
raw.remove(meta);
}
if let Some(kind_str) = raw.get("type").and_then(Value::as_str)
&& let Some(canonical) = FeatureKind::type_name_to_kind_key(kind_str)
{
raw.insert("type".into(), json!(canonical));
}
resolve_legacy_names(&mut raw, &s.doc);
let feature = recorded_feature(cmd, &raw)?;
let params = step_params(cmd, p.get("params"))?;
+28
View File
@@ -243,6 +243,34 @@ fn a_recorded_feature_that_does_not_fit_is_refused_and_changes_nothing() {
assert!(s.doc.feature(r["feature"].as_u64().unwrap()).is_some_and(|f| !f.param_names.is_empty()), "its inputs get parameter names");
}
/// #10748: `timeline.inspect` reports a feature's design variant name in `type` and display name
/// in `type_name`; `timeline.add` accepts `timeline.inspect` results and inspect type names.
#[test]
fn timeline_add_accepts_inspect_result_and_type_names() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 20, "width": 10, "height": 5, "name": "Block"}));
let mut inspected = run(&mut s, "timeline.inspect", json!({"feature": "Block"}));
assert_eq!(inspected["type"], "box", "inspect type is the design file variant name");
assert_eq!(inspected["type_name"], "BoxFeature", "inspect type_name is the display type");
// 1. timeline.add accepts the full inspected object directly in a new session
let mut s2 = Session::default();
let added = run(&mut s2, "timeline.add", json!({"feature": inspected.clone()}));
assert!(added["error"].is_null(), "{added}");
assert_eq!(s2.doc.features.len(), 1);
// 2. timeline.add with id 0 allocates a new id in the current session
inspected["id"] = json!(0);
let added2 = run(&mut s, "timeline.add", json!({"feature": inspected}));
assert!(added2["error"].is_null(), "{added2}");
assert_eq!(s.doc.features.len(), 2);
// 3. timeline.add accepts the inspect type name (e.g. BoxFeature, HoleFeature)
let added_by_type_name =
run(&mut s, "timeline.add", json!({"feature": {"type": "BoxFeature", "length": "5", "width": "5", "height": "5", "corner": [50, 0, 0]}}));
assert!(added_by_type_name["error"].is_null(), "{added_by_type_name}");
}
#[test]
fn the_script_is_written_to_a_file_that_replays() {
let mut s = Session::default();
+2 -1
View File
@@ -1131,7 +1131,8 @@ fn timeline_inspect_shows_what_timeline_edit_changes() {
run(&mut s, "solid.extrude", json!({"distance": 10, "name": "Slab"}));
run(&mut s, "solid.fillet", json!({"edges": [[20, 0, 10]], "radius": 2, "name": "Round"}));
let i = run(&mut s, "timeline.inspect", json!({"feature": "Slab"}));
assert_eq!(i["type"], "ExtrudeFeature", "{i}");
assert_eq!(i["type"], "extrude", "{i}");
assert_eq!(i["type_name"], "ExtrudeFeature", "{i}");
assert_eq!(i["definition"]["extent"]["distance"], "10", "{i}");
assert_eq!(i["definition"]["operation"], "new_body", "{i}");
assert!(i["definition"].get("type").is_none() && i["definition"].get("param_names").is_none(), "{i}");
+1 -1
View File
@@ -282,7 +282,7 @@ edited with the sketch commands. Expressions are text (`"30"`, `"30 mm"`, `"widt
```json
{"command": "timeline.inspect", "params": {"feature": "Slab"}}
→ {"type": "ExtrudeFeature",
→ {"type": "extrude", "type_name": "ExtrudeFeature",
"definition": {"sketch": 1, "profiles": {"type": "all"}, "operation": "new_body",
"extent": {"distance": "10", "direction": "positive"}},
"inputs": [{"label": "Distance", "param": "d1", "expression": "10", "unit": "mm"}], …}
+2 -2
View File
@@ -519,8 +519,8 @@ Search lists both under the same name, and the label lookup gives both the same
## A feature's type
A feature type has one name: its design-file key, such as `sheet_flange`. The label (Flange) is
its display name. Replies and scripts should use the design-file key; today `timeline.inspect`
reports a different name (`EdgeFlangeFeature`), so a script can't match one against the other.
its display name. Replies and scripts use the design-file key (`timeline.inspect` reports both
`type: "sheet_flange"` and `type_name: "EdgeFlangeFeature"`).
## Open questions for the maintainer