Official Codebase of 3DCodeVerse
Python
articulated: promote a sub-part a joint names by word subset — the clock death
gaoypengbc7bead00dd9
diff --git a/harness/codeverse/contracts/plan.py b/harness/codeverse/contracts/plan.pyindex 7dd77a0e..55eb6e14 100644--- a/harness/codeverse/contracts/plan.py+++ b/harness/codeverse/contracts/plan.py@@ -9,6 +9,7 @@ plans are re-asked with the validation errors, before any generator runs.from __future__ import annotations+import contextlibimport mathimport refrom typing import Literal@@ -309,6 +310,47 @@ class ArticulatedPlan(StaticPlan):j[side] = by_name[hits[0]].get("name")notes.append(f"joint {j.get('name')}.{side} '{raw_name}' resolved to the one part it names: {j[side]}")+ # 1c. a joint that names a SUB-PART by a fragment (af_grandfather_clock 2026-08-31,+ # 3.7-flash: everything nested under clock_case, the joint said GlazedDoor, the child+ # spelt it longer — the exact-match promotion above missed it, 1b searches top-level+ # links only, and the re-ask complaint listed top-level parts only, so both re-asks+ # died the same way). Sub-part names are longer and decorated, so the affix rule is+ # too weak here: the match is WORD-SUBSET (every word of the reference appears in the+ # candidate's words — {glazed,door} ⊆ {glazed,front,door}; "arm" still never matches+ # "alarm"). A unique hit promotes the child and rewrites the joint side.+ sub_index: dict[str, tuple[dict, dict]] = {}+ for part in list(parts):+ for child in part.get("children") or []:+ if isinstance(child, dict) and child.get("name"):+ sub_index[to_snake(str(child["name"]))] = (part, child)+ for j in joints:+ for side in ("parent", "child"):+ raw_name = str(j.get(side, ""))+ key = to_snake(raw_name)+ if not key or key in by_name:+ continue+ kw = set(key.split("_"))+ hits = [k for k in sub_index if kw <= set(k.split("_"))]+ if len(hits) != 1:+ continue+ owner, child = sub_index[hits[0]]+ ckey = to_snake(str(child["name"]))+ if ckey not in by_name:+ promoted = {+ "name": child.get("name"), "role": child.get("role") or f"moving part of {owner.get('name')}",+ "description": child.get("description", ""), "bbox": child.get("bbox"),+ "material": child.get("material") or owner.get("material", ""),+ "attach_to": owner.get("name"), "instances": child.get("instances", 1),+ }+ parts.append(promoted)+ by_name[ckey] = promoted+ with contextlib.suppress(ValueError, KeyError):+ owner["children"].remove(child)+ notes.append(f"promoted sub-part {owner.get('name')}.{child.get('name')} to a link: "+ f"joint {j.get('name')} names it")+ j[side] = by_name[ckey].get("name")+ notes.append(f"joint {j.get('name')}.{side} '{raw_name}' resolved to sub-part {j[side]}")+# 2. revolute joints with a > 2π range: degrees written for radians → radians; a radian# range over 2π → continuousfor j in joints:@@ -415,9 +457,13 @@ class ArticulatedPlan(StaticPlan):p, c = to_snake(j.parent), to_snake(j.child)if p not in links or c not in links:unknown = ", ".join(n for n, k in ((j.parent, p), (j.child, c)) if k not in links)+ subs = sorted({c.name for part in self.parts for c in part.children})+ sub_note = (f" Sub-parts that exist but are NOT links: {', '.join(subs)} — a joint may "+ f"only move a top-level part; name one of those exactly to promote it, or a real part."+ if subs else "")raise ValueError(f"joint {j.name} references unknown link(s) {unknown} — the parts in this plan are: "- f"{', '.join(sorted(links))}. Use those exact names (or add the missing part).")+ f"{', '.join(sorted(links))}. Use those exact names (or add the missing part).{sub_note}")if c in parent_of:raise ValueError(f"link {j.child} has two parent joints")if c == root:diff --git a/harness/tests/core/test_plan_normalise.py b/harness/tests/core/test_plan_normalise.pyindex 388ef5d3..675c4668 100644--- a/harness/tests/core/test_plan_normalise.py+++ b/harness/tests/core/test_plan_normalise.py@@ -224,3 +224,39 @@ def test_an_ambiguous_root_link_still_fails_validation():with pytest.raises(ValidationError, match="root_link"):ArticulatedPlan.model_validate(d)++def test_a_joint_naming_a_sub_part_by_word_subset_promotes_it():+ """af_grandfather_clock: joint said GlazedDoor, the child was GlazedFrontDoor — no+ affix match, so 1b could not save it. 1c matches by word subset and promotes."""+ d = _raw()+ parent = d["parts"][0]+ parent.setdefault("children", []).append(+ {"name": "GlazedFrontDoor", "role": "hinged door", "description": "a glazed door",+ "bbox": {"center": list(parent["bbox"]["center"]), "extents": [e * 0.4 for e in parent["bbox"]["extents"]]},+ "material": "oak and glass"})+ d["joints"].append({"name": "CaseToGlazedDoor", "type": "revolute", "parent": parent["name"],+ "child": "GlazedDoor", "axis": [0, 1, 0], "pivot": [0.2, 0.5, 0],+ "lower": 0.0, "upper": 1.5, "rest": 0.0, "motion": "door swings open"})+ p = ArticulatedPlan.model_validate(d)+ names = [x.name for x in p.parts]+ assert "GlazedFrontDoor" in names+ j = next(x for x in p.joints if x.name == "CaseToGlazedDoor")+ assert j.child == "GlazedFrontDoor"+ assert any("resolved to sub-part GlazedFrontDoor" in n for n in p.normalisations)+++def test_the_unknown_link_complaint_lists_the_sub_parts():+ """The re-ask used to see only top-level parts — with everything nested, it was blind+ to the very children the joints meant, and both re-asks died the same way."""+ d = _raw()+ parent = d["parts"][0]+ parent.setdefault("children", []).append(+ {"name": "PendulumBob", "role": "bob", "description": "a brass disc",+ "bbox": {"center": list(parent["bbox"]["center"]), "extents": [0.1, 0.1, 0.02]},+ "material": "brass"})+ d["joints"].append({"name": "Mystery", "type": "revolute", "parent": parent["name"],+ "child": "SomethingElse", "axis": [0, 1, 0], "pivot": [0, 0, 0],+ "lower": 0.0, "upper": 1.0, "rest": 0.0, "motion": "?"})+ with pytest.raises(ValidationError, match=r"Sub-parts that exist but are NOT links:.*PendulumBob"):+ ArticulatedPlan.model_validate(d)+