Official Codebase of 3DCodeVerse
Python
bench: scene_regate calls the round gate's own entry point — its copy of the stage reading goes
gaoypengcadf82c4df2c
diff --git a/eval/bench/scene_regate.py b/eval/bench/scene_regate.pyindex fbb81011..f93b0b08 100644--- a/eval/bench/scene_regate.py+++ b/eval/bench/scene_regate.py@@ -35,7 +35,8 @@ for _p in (Path(__file__).resolve().parents[2] / "harness", Path(__file__).resolfrom bench.scene_stats import scene_records # noqa: E402from codeverse3d.config import get_settings # noqa: E402from codeverse3d.contracts.artifacts import Severity # noqa: E402-from codeverse3d.spatial.scene_placement import placement_gate_safe # noqa: E402+from codeverse3d.spatial.scene_placement import placement_gate # noqa: E402+from codeverse3d.workspace import Workspace # noqa: E402GATE = "scene_placement"@@ -71,33 +72,17 @@ def probe(ws: Path, *, timeout_s: float) -> dict | None:return payload.get("census") if (payload.get("boot") or {}).get("ok") else None-def stage_layouts(run: Path) -> dict:- """The per-zone layouts the run recorded. `contract_findings` needs them: the- instance-budget check ("zone X holds ~179 instances but its layout budgeted 443")- has no basis without them, and leaving them out makes a REAL finding look like one- the gate change removed — which is what happened the first time this ran."""- f = run / "stages" / "layouts.json"- if not f.is_file():- return {}- try:- data = json.loads(f.read_text())- except (OSError, ValueError):- return {}- # the stage file is the envelope {stage, inputs_hash, result}; the gate wants the- # result, which is the zone-name -> layout mapping- inner = data.get("result") if isinstance(data, dict) else None- return inner if isinstance(inner, dict) else {}--def regate(run: Path, *, timeout_s: float) -> dict:record = json.loads((run / "record.json").read_text())before = recorded_errors(record)census = probe(run, timeout_s=timeout_s)if census is None:return {"run": run.name, "booted": False, "before": before, "after": None}- # the round's own entry point, so this measures the GATE and not a copy of it- # (it owns the per-kind cap and the indoor inference as well)- report = placement_gate_safe(census, plan=record.get("plan") or {}, layouts=stage_layouts(run))+ # the round's own entry point (D82), so this measures the GATE and not a copy of it: it+ # reads the zone layouts and the assets the asset stage could not build from stages/ —+ # a first version of this script passed the layouts envelope unopened and a REAL density+ # finding read as one the gate change had removed+ report = placement_gate(Workspace(run), census, record.get("plan") or {})after = [f.message for f in (report.findings if report else []) if f.severity == Severity.ERROR]return {"run": run.name, "booted": True, "before": before, "after": after}diff --git a/eval/tests/test_scene_regate.py b/eval/tests/test_scene_regate.pyindex 474cd3b9..b6a8d332 100644--- a/eval/tests/test_scene_regate.py+++ b/eval/tests/test_scene_regate.py@@ -13,7 +13,7 @@ from __future__ import annotationsimport jsonfrom pathlib import Path-from bench.scene_regate import _head, recorded_errors, scene_runs, stage_layouts+from bench.scene_regate import _head, recorded_errors, regate, scene_runsdef _run(root: Path, name: str, *, track: str = "scene", with_src: bool = True) -> Path:@@ -25,20 +25,28 @@ def _run(root: Path, name: str, *, track: str = "scene", with_src: bool = True)return d-def test_the_layouts_envelope_is_opened(tmp_path: Path) -> None:- """`stages/layouts.json` is `{stage, inputs_hash, result}`; the gate wants `result`,- which is the zone-name -> layout mapping."""+def test_regate_reads_the_stage_records_the_round_gate_reads(tmp_path: Path, monkeypatch) -> None:+ """The layouts envelope is opened (coastal_village's real density finding came back) and an+ asset the asset stage never built is not "missing": re-gating calls the round's own entry+ point, which reads both from ``stages/``."""+ import bench.scene_regate as sr+run = _run(tmp_path, "a")+ plan = {"zones": [{"name": "VillageQuay", "contents": ["Bollard", "BronzeCenser"]}], "assets": []}+ (run / "record.json").write_text(json.dumps({"spec": {"track": "scene"}, "plan": plan, "rounds": []}))(run / "stages").mkdir()- (run / "stages" / "layouts.json").write_text(json.dumps({- "stage": "layouts", "inputs_hash": "abc",- "result": {"VillageQuay": {"zone": "VillageQuay", "placements": [1, 2]}},- }))- assert stage_layouts(run) == {"VillageQuay": {"zone": "VillageQuay", "placements": [1, 2]}}---def test_a_run_without_layouts_yields_an_empty_mapping(tmp_path: Path) -> None:- assert stage_layouts(_run(tmp_path, "b")) == {}+ (run / "stages" / "layouts.json").write_text(json.dumps({"stage": "layouts", "inputs_hash": "abc", "result": {+ "VillageQuay": {"placements": [{"asset": "Bollard", "count": 43}], "ground_cover": 400}}}))+ (run / "stages" / "assets.json").write_text(json.dumps({"stage": "assets", "inputs_hash": "abc", "result": {+ "BronzeCenser": {"name": "BronzeCenser", "ok": False}}}))+ census = {"fog": {"type": "Fog"}, "background": "#aabbcc",+ "groups": [{"name": "VillageQuay", "instances": 179}],+ "placement": {"assets": [{"name": "Bollard", "zone": "VillageQuay", "ground_gap_m": 0.0,+ "support": "Ground"}], "pairs": []}}+ monkeypatch.setattr(sr, "probe", lambda ws, timeout_s: census)+ after = regate(run, timeout_s=1.0)["after"]+ assert any("holds ~179 instances but its layout budgeted 443" in m for m in after), after+ assert not any("BronzeCenser" in m for m in after), afterdef test_only_scene_runs_with_a_workspace_are_re_gated(tmp_path: Path) -> None: