Official Codebase of 3DCodeVerse
Python
plan: the self-joint error names both links instead of saying "parent == child"
ziyao6cb4b86b7d99
diff --git a/harness/codeverse/contracts/plan.py b/harness/codeverse/contracts/plan.pyindex 474346a8..18e509a2 100644--- a/harness/codeverse/contracts/plan.py+++ b/harness/codeverse/contracts/plan.py@@ -225,7 +225,15 @@ class JointPlan(BaseModel):if self.type == "prismatic" and (self.upper - self.lower) > 5.0:raise ValueError(f"joint {self.name}: prismatic range > 5 m is implausible")if to_snake(self.parent) == to_snake(self.child):- raise ValueError(f"joint {self.name}: parent == child")+ # name BOTH sides: pydantic truncates the offending value right after the+ # joint name, so "parent == child" was all the model ever saw, and it rewrote+ # the same joint through every re-ask (7 runs lost that way, 2026-09-03).+ same = "" if self.parent == self.child else (+ f" ('{self.parent}' and '{self.child}' are the same name once normalised)")+ raise ValueError(+ f"joint {self.name}: parent and child are both '{self.parent}'{same} — a joint "+ f"connects TWO different links; name the moving link as child and what it is "+ f"attached to as parent, or drop the joint if nothing moves")return selfdiff --git a/harness/tests/urdf_joints/test_mimic.py b/harness/tests/urdf_joints/test_mimic.pyindex 31c0e777..b38701df 100644--- a/harness/tests/urdf_joints/test_mimic.py+++ b/harness/tests/urdf_joints/test_mimic.py@@ -326,3 +326,22 @@ def test_a_self_mimic_says_it_names_itself(tmp_path):'<mimic joint="rib_a_hinge" multiplier="1" offset="0"/>')with pytest.raises(UrdfError, match="names itself"):_robot(tmp_path, text)+++def test_a_self_joint_says_which_links_collided():+ """`parent == child` was the whole message, and pydantic truncates the offending value+ right after the joint name — so a model that wrote one had nothing to act on and+ rewrote the same joint through every re-ask (7 plan calls died that way on+ 2026-09-03). Both sides are named now, and a collision that only exists after+ normalisation says so."""+ import pytest as _pytest++ from codeverse.contracts.plan import JointPlan++ common = {"type": "revolute", "axis": [0, 0, 1], "pivot": [0, 0, 0],+ "lower": 0.0, "upper": 1.0, "rest": 0.0}+ with _pytest.raises(Exception, match="parent and child are both 'Sash'"):+ JointPlan.model_validate({"name": "SashHinge", "parent": "Sash", "child": "Sash", **common})+ with _pytest.raises(Exception, match="same name once normalised"):+ JointPlan.model_validate({"name": "SashHinge", "parent": "SashFrame", "child": "sash_frame",+ **common})