Skip to content

Rebuild the object in a reference image as a code-only, procedural, quality-gated, animation-ready Three.js model. Token-efficient image-to-3D.

fix: refuse non-dict assessmentPatch values for guarded keys

kokorolxcb9c4b8b00f4
diff --git a/forge/_shared/spec_augmentation.py b/forge/_shared/spec_augmentation.py
index b7526e8..9999cb6 100644
--- a/forge/_shared/spec_augmentation.py
+++ b/forge/_shared/spec_augmentation.py
@@ -89,6 +89,12 @@ def merge_spec_augmentation(spec: dict[str, Any], artifact: Any, *, domain_id: s
raise SpecAugmentationError("assessmentPatch must be an object")
pre = spec.setdefault("preSpecAssessment", {})
for key, value in patch.items():
+ if key in ("objectClass", "detailInventory") and not isinstance(value, dict):
+ # These two carry guarded values (the domain marker, the raise-only detail floor). A
+ # non-dict replacement would fall through to the plain-assignment branch below and
+ # clobber the dict both guards live in -- refusing it keeps every path to a floor
+ # clamped, not just the well-formed one.
+ raise SpecAugmentationError(f"assessmentPatch.{key} must be an object, got {value!r}")
if key == "objectClass" and isinstance(value, dict):
if "domain" in value:
raise SpecAugmentationError("assessmentPatch may not set objectClass.domain; the base sets it from domain resolution")
diff --git a/forge/tests/test_domain_spec_contract.py b/forge/tests/test_domain_spec_contract.py
index d9f3635..59bb54c 100644
--- a/forge/tests/test_domain_spec_contract.py
+++ b/forge/tests/test_domain_spec_contract.py
@@ -90,6 +90,23 @@ class RaiseOnlyCoversEveryPathToAFloor(unittest.TestCase):
)
self.assertEqual(spec["preSpecAssessment"]["detailInventory"]["targetMinDetails"], 40)
+ def test_a_non_dict_detail_inventory_patch_is_refused_not_applied(self) -> None:
+ # A non-dict value used to fall through to the plain-assignment branch and clobber the
+ # whole dict the floor lives in -- strict validation then saw no positive targetMinDetails
+ # and disabled the detail gate entirely, with `clamped` reporting nothing.
+ spec = {"preSpecAssessment": {"detailInventory": {"targetMinDetails": 40}}}
+ with self.assertRaises(SpecAugmentationError):
+ merge_spec_augmentation(spec, artifact(assessmentPatch={"detailInventory": 0}))
+ self.assertEqual(spec["preSpecAssessment"]["detailInventory"]["targetMinDetails"], 40)
+
+ def test_a_non_dict_object_class_patch_is_refused_not_applied(self) -> None:
+ spec = {"preSpecAssessment": {"objectClass": {"domain": "base"}}}
+ with self.assertRaises(SpecAugmentationError):
+ merge_spec_augmentation(
+ spec, artifact(assessmentPatch={"objectClass": "weapon"}), domain_id="testdomain"
+ )
+ self.assertEqual(spec["preSpecAssessment"]["objectClass"], {"domain": "base"})
+
def test_a_kept_tier_is_recorded_like_a_kept_number(self) -> None:
spec = {"qualityContract": {"qualityBar": "ultra-complex"}}
record = merge_spec_augmentation(spec, artifact(qualityFloors={"qualityBar": "simple"}))