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: make the registry tests hermetic instead of machine-dependent

kokorolxdee8da0861a3
diff --git a/forge/tests/test_domain_registry.py b/forge/tests/test_domain_registry.py
index 16b05a0..5e31bfd 100644
--- a/forge/tests/test_domain_registry.py
+++ b/forge/tests/test_domain_registry.py
@@ -6,7 +6,11 @@ assertions, which already pin the 21 / 23 / 25 step counts per profile.
from __future__ import annotations
+import contextlib
+import json
+import os
import sys
+import tempfile
import textwrap
import unittest
from pathlib import Path
@@ -31,9 +35,15 @@ class Registry(unittest.TestCase):
def test_generic_resolves_to_no_domain(self) -> None:
self.assertIsNone(domain_profile("generic"))
- def test_both_in_repo_domains_are_registered(self) -> None:
- # Two consumers, one of them destined to leave the repo. A seam with one consumer is a rename.
- self.assertEqual(sorted(registered_domains()), ["character", "cs2"])
+ def test_both_registry_sources_register_hermetically(self) -> None:
+ # A seam with one consumer is a rename, so both sources are exercised: the in-repo module,
+ # and an installed plugin's domain.json. Neither half may depend on what this machine
+ # happens to have under ~/.img2 -- the old form of this test asserted the INSTALLED cs2
+ # plugin and was green or red depending on the machine, which is what turned CI red.
+ with self._temp_img2_home({}):
+ self.assertEqual(sorted(registered_domains()), ["character"])
+ with self._temp_img2_home({"fixture-plugin": {"id": "fixture-dom"}}):
+ self.assertEqual(sorted(registered_domains()), ["character", "fixture-dom"])
def test_an_unregistered_profile_fails_loud_and_names_what_is_available(self) -> None:
with self.assertRaises(DomainRegistryError) as ctx:
@@ -77,14 +87,42 @@ class Registry(unittest.TestCase):
self.assertIn("passAnchorBefore", str(ctx.exception))
def test_two_providers_claiming_one_id_is_ambiguous(self) -> None:
- with self.assertRaises(DomainRegistryError) as ctx:
- self._with_temp_domain(
- "dupe",
- 'DOMAIN = {"id": "cs2"}',
- registered_domains,
- )
+ # Collides with the in-repo `character` module rather than an installed plugin, so the
+ # refusal is provable on a machine with nothing installed. IMG2_HOME is pinned empty for
+ # the same reason: a real installation must not be able to add a second collision path.
+ with self._temp_img2_home({}):
+ with self.assertRaises(DomainRegistryError) as ctx:
+ self._with_temp_domain(
+ "dupe",
+ 'DOMAIN = {"id": "character"}',
+ registered_domains,
+ )
self.assertIn("declared twice", str(ctx.exception))
+ @contextlib.contextmanager
+ def _temp_img2_home(self, plugins: dict[str, dict]):
+ """A disposable $IMG2_HOME holding exactly `plugins` ({registry_id: domain_entry})."""
+ with tempfile.TemporaryDirectory() as tmp:
+ home = Path(tmp)
+ rows = []
+ for registry_id, domain_entry in plugins.items():
+ rows.append({"id": registry_id})
+ plugin_dir = home / "plugins" / registry_id
+ plugin_dir.mkdir(parents=True)
+ (plugin_dir / "domain.json").write_text(json.dumps(domain_entry), encoding="utf-8")
+ (home / "plugins.json").write_text(
+ json.dumps({"version": 1, "plugins": rows}), encoding="utf-8"
+ )
+ prior = os.environ.get("IMG2_HOME")
+ os.environ["IMG2_HOME"] = str(home)
+ try:
+ yield home
+ finally:
+ if prior is None:
+ os.environ.pop("IMG2_HOME", None)
+ else:
+ os.environ["IMG2_HOME"] = prior
+
def _with_temp_domain(self, stem: str, body: str, action):
"""Drop a domain module into the package for one assertion, then remove it."""
path = Path(domains.__file__).resolve().parent / f"zz_{stem}.py"
diff --git a/forge/tests/test_workflow_state.py b/forge/tests/test_workflow_state.py
index b4ea52f..df27471 100644
--- a/forge/tests/test_workflow_state.py
+++ b/forge/tests/test_workflow_state.py
@@ -1,6 +1,8 @@
from __future__ import annotations
import json
+import os
+import shutil
import subprocess
import sys
import tempfile
@@ -55,14 +57,54 @@ class WorkflowStateTest(unittest.TestCase):
self.assertLess(ids.index("material-evidence"), ids.index("material-spec-wiring"))
self.assertLess(ids.index("material-spec-wiring"), ids.index("strict-validation"))
- def test_cs2_state_includes_classification_and_manifest_before_pre_spec(self):
- state = new_state("knife.png", profile="cs2")
+ def test_plugin_domain_steps_splice_before_their_anchors(self):
+ """A plugin-contributed domain drives the checklist through the registry, hermetically.
+
+ This test used to build a `cs2` state and passed only on machines where the cs2 plugin
+ happened to be installed under ~/.img2 -- the machine-global dependency that turned CI
+ red. It now installs a fixture plugin (mirroring cs2's `domain.json` shape: setup steps
+ anchored before `local-spec-search`, one pass step anchored before `ai-review-recorded`)
+ into a disposable $IMG2_HOME and asserts the same splice-order semantics.
+ """
+ domain_entry = {
+ "id": "fixture-dom",
+ "setupSteps": [
+ ["fx-contract-read", "Read {plugin_dir}/grimoire/contract.md completely"],
+ ["fx-classification", "Obtain an authoritative fixture classification record"],
+ ["fx-manifest", "python3 {plugin_dir}/tools/manifest.py {reference} --out fx.json"],
+ ],
+ "setupAnchorBefore": "local-spec-search",
+ "passSteps": [
+ ["fx-review", "python3 {plugin_dir}/tools/review.py --spec {spec} --out fx-review.json"]
+ ],
+ "passAnchorBefore": "ai-review-recorded",
+ }
+ home = Path(tempfile.mkdtemp(prefix="img2-home-"))
+ self.addCleanup(shutil.rmtree, home, True)
+ plugin_dir = home / "plugins" / "fixture-plugin"
+ plugin_dir.mkdir(parents=True)
+ (plugin_dir / "domain.json").write_text(json.dumps(domain_entry), encoding="utf-8")
+ (home / "plugins.json").write_text(
+ json.dumps({"version": 1, "plugins": [{"id": "fixture-plugin"}]}), encoding="utf-8"
+ )
+ prior = os.environ.get("IMG2_HOME")
+ os.environ["IMG2_HOME"] = str(home)
+ try:
+ state = new_state("fixture.png", profile="fixture-dom")
+ finally:
+ if prior is None:
+ os.environ.pop("IMG2_HOME", None)
+ else:
+ os.environ["IMG2_HOME"] = prior
ids = [entry["id"] for entry in state["checklist"]]
- self.assertLess(ids.index("cs2-contract-read"), ids.index("cs2-authoritative-classification"))
- self.assertLess(ids.index("cs2-authoritative-classification"), ids.index("pre-spec-assessment"))
- self.assertLess(ids.index("cs2-manifest"), ids.index("pre-spec-assessment"))
- self.assertLess(ids.index("pass-gate-check"), ids.index("cs2-review"))
- self.assertLess(ids.index("cs2-review"), ids.index("ai-review-recorded"))
+ self.assertLess(ids.index("fx-contract-read"), ids.index("fx-classification"))
+ self.assertLess(ids.index("fx-classification"), ids.index("fx-manifest"))
+ self.assertLess(ids.index("fx-manifest"), ids.index("local-spec-search"))
+ self.assertLess(ids.index("local-spec-search"), ids.index("pre-spec-assessment"))
+ self.assertLess(ids.index("pass-gate-check"), ids.index("fx-review"))
+ self.assertLess(ids.index("fx-review"), ids.index("ai-review-recorded"))
+ by_id = {entry["id"]: entry for entry in state["checklist"]}
+ self.assertIn(str(plugin_dir), by_id["fx-manifest"]["command"])
def test_character_state_requires_contract_landmarks_and_route_decision(self):
state = new_state("character.png", profile="character")