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: clamp every path to a floor, not just the qualityFloors partition

kokorolx78fd1c241ea0
diff --git a/forge/_shared/spec_augmentation.py b/forge/_shared/spec_augmentation.py
index 86cc623..b7526e8 100644
--- a/forge/_shared/spec_augmentation.py
+++ b/forge/_shared/spec_augmentation.py
@@ -33,12 +33,20 @@ class SpecAugmentationError(ValueError):
pass
-def _stricter_tier(current: Any, proposed: Any) -> Any:
+def _stricter_tier(current: Any, proposed: Any, clamped: list[str]) -> Any:
if proposed not in TIER_ORDER:
raise SpecAugmentationError(f"unknown quality tier {proposed!r}; expected one of {', '.join(TIER_ORDER)}")
+ if current is None:
+ return proposed
if current not in TIER_ORDER:
+ # A malformed base tier is a base defect to surface, not a blank the plugin gets to fill:
+ # silently accepting the proposal here let a looser tier replace a typo'd stricter one.
+ raise SpecAugmentationError(f"the spec's existing quality tier {current!r} is not one of {', '.join(TIER_ORDER)}")
+ if TIER_ORDER.index(proposed) > TIER_ORDER.index(current):
return proposed
- return proposed if TIER_ORDER.index(proposed) > TIER_ORDER.index(current) else current
+ if proposed != current:
+ clamped.append(f"qualityBar: kept {current} over proposed {proposed}")
+ return current
def _raise_only_number(path: str, current: Any, proposed: Any, clamped: list[str]) -> Any:
@@ -85,6 +93,17 @@ def merge_spec_augmentation(spec: dict[str, Any], artifact: Any, *, domain_id: s
if "domain" in value:
raise SpecAugmentationError("assessmentPatch may not set objectClass.domain; the base sets it from domain resolution")
pre.setdefault("objectClass", {}).update(value)
+ elif key == "detailInventory" and isinstance(value, dict):
+ # The one floor-controlled value reachable through this partition. The clamp guards the
+ # VALUE, whichever partition carries it -- without this, a patch lowered the floor the
+ # strict validator reads while `clamped` reported nothing, and qualityFloors' own clamp
+ # never ran because the patched value arrived first.
+ inv = pre.setdefault(key, {})
+ for sub, proposed in value.items():
+ if sub == "targetMinDetails":
+ inv[sub] = _raise_only_number("targetMinDetails", inv.get(sub), proposed, clamped)
+ else:
+ inv[sub] = proposed
elif isinstance(value, dict):
pre.setdefault(key, {}).update(value)
else:
@@ -98,7 +117,7 @@ def merge_spec_augmentation(spec: dict[str, Any], artifact: Any, *, domain_id: s
contract = spec.setdefault("qualityContract", {})
for key, value in floors.items():
if key == "qualityBar":
- contract["qualityBar"] = _stricter_tier(contract.get("qualityBar"), value)
+ contract["qualityBar"] = _stricter_tier(contract.get("qualityBar"), value, clamped)
elif key == "targetMinDetails":
inv = pre.setdefault("detailInventory", {})
inv["targetMinDetails"] = _raise_only_number("targetMinDetails", inv.get("targetMinDetails"), value, clamped)
diff --git a/forge/tests/test_domain_spec_contract.py b/forge/tests/test_domain_spec_contract.py
index e9b140b..d9f3635 100644
--- a/forge/tests/test_domain_spec_contract.py
+++ b/forge/tests/test_domain_spec_contract.py
@@ -54,6 +54,55 @@ class RaiseOnly(unittest.TestCase):
self.assertEqual(spec["qualityContract"]["minimumSpecDepth"]["macroComponents"], 5)
+class RaiseOnlyCoversEveryPathToAFloor(unittest.TestCase):
+ """The clamp must guard the VALUE, not just the qualityFloors partition.
+
+ assessmentPatch merges into preSpecAssessment, and `detailInventory.targetMinDetails` -- the
+ exact number strict validation reads -- lives there. Before this test existed, a patch could
+ drop the floor 40 -> 2 with `clamped: []` reporting nothing, and plugin-cs2's own emit tool sent
+ the value through BOTH partitions with the unclamped one winning (found in review of PR #106 by
+ running the code, not by reading it).
+ """
+
+ def test_assessment_patch_cannot_lower_the_detail_floor(self) -> None:
+ spec = {"preSpecAssessment": {"detailInventory": {"targetMinDetails": 40}}}
+ record = merge_spec_augmentation(
+ spec, artifact(assessmentPatch={"detailInventory": {"targetMinDetails": 2}})
+ )
+ self.assertEqual(spec["preSpecAssessment"]["detailInventory"]["targetMinDetails"], 40)
+ self.assertTrue(record["clamped"], "the kept-over-proposed decision must leave a record")
+
+ def test_assessment_patch_may_still_raise_the_detail_floor(self) -> None:
+ spec = {"preSpecAssessment": {"detailInventory": {"targetMinDetails": 12}}}
+ record = merge_spec_augmentation(
+ spec, artifact(assessmentPatch={"detailInventory": {"targetMinDetails": 60}})
+ )
+ self.assertEqual(spec["preSpecAssessment"]["detailInventory"]["targetMinDetails"], 60)
+ self.assertEqual(record["clamped"], [])
+
+ def test_assessment_patch_other_detail_inventory_keys_still_merge(self) -> None:
+ spec = {"preSpecAssessment": {"detailInventory": {"targetMinDetails": 40}}}
+ merge_spec_augmentation(
+ spec, artifact(assessmentPatch={"detailInventory": {"expectedFinishes": ["anodized"]}})
+ )
+ self.assertEqual(
+ spec["preSpecAssessment"]["detailInventory"]["expectedFinishes"], ["anodized"]
+ )
+ self.assertEqual(spec["preSpecAssessment"]["detailInventory"]["targetMinDetails"], 40)
+
+ 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"}))
+ self.assertEqual(spec["qualityContract"]["qualityBar"], "ultra-complex")
+ self.assertTrue(record["clamped"], "a tier kept over a looser proposal must leave a record")
+
+ def test_a_malformed_base_tier_is_refused_not_silently_replaced(self) -> None:
+ spec = {"qualityContract": {"qualityBar": "Ultra-Complex"}}
+ with self.assertRaises(SpecAugmentationError) as ctx:
+ merge_spec_augmentation(spec, artifact(qualityFloors={"qualityBar": "simple"}))
+ self.assertIn("Ultra-Complex", str(ctx.exception))
+
+
class WhatAnArtifactMayNotDo(unittest.TestCase):
def test_it_may_not_set_a_base_owned_section(self) -> None:
with self.assertRaises(SpecAugmentationError) as ctx: