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
2026-11-01 21:00:44 +00:00
committed by GitHub
parent 303236e524
commit 446590dca1
8 changed files with 224 additions and 5 deletions
+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();