Official Codebase of 3DCodeVerse
Python
tests: spatial_tools, scene_gates, graphics — 81 tests go that cover no line another test does not (−1 175 lines)
gaoypengcd1d597a53ca
diff --git a/harness/tests/graphics/test_frame_stats.py b/harness/tests/graphics/test_frame_stats.pyindex 0d0d0556..9aeb2e44 100644--- a/harness/tests/graphics/test_frame_stats.py+++ b/harness/tests/graphics/test_frame_stats.py@@ -28,15 +28,6 @@ def _kinds(gate):return {f.data["kind"]: f.severity for f in gate.findings}-def test_moving_colourful_sequence_passes(tmp_path):- frames = [(t, _png(tmp_path / f"f{i}.png", _gradient(t))) for i, t in enumerate((0.0, 1.0, 2.5, 4.0))]- seq = sequence_stats(frames)- assert len(seq.frames) == 4 and seq.mean_diff > 0.01 and not seq.static and not seq.any_nan- assert seq.mean_colourfulness > 0.15 and 0.2 < seq.mean_lum < 0.8- gate = frame_gate(seq)- assert gate.passed and "static" not in _kinds(gate)--def test_static_sequence_warns_only_when_motion_expected(tmp_path):frames = [(t, _png(tmp_path / f"s{i}.png", _gradient(0.0, moving=False))) for i, t in enumerate((0.0, 1.0, 2.5))]seq = sequence_stats(frames)diff --git a/harness/tests/graphics/test_gl_runtime.py b/harness/tests/graphics/test_gl_runtime.pyindex 55f0e638..fd0616ca 100644--- a/harness/tests/graphics/test_gl_runtime.py+++ b/harness/tests/graphics/test_gl_runtime.py@@ -58,18 +58,6 @@ def test_shader_skeleton_builds_and_writes_artifacts(tmp_ws, host):assert (ws.artifacts / "build.json").is_file()-def test_shader_compile_error_maps_to_agent_line(tmp_ws, host):- ws = _ws_with_plan(tmp_ws)- (ws.src / "common.glsl").write_text("float twice(float x) { return 2.0 * x; }\n")- (ws.src / "shader.frag").write_text(- "// line 1\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n vec2 uv = fragCoord / u_resolution.xy;\n"- " float v = twice(nope);\n fragColor = vec4(uv, v, 1.0);\n}\n")- br = GlslShaderRuntime(host=host).build(ws, **SMALL)- assert not br.ok and br.error_type == "GlslCompileError"- assert br.error_file == "src/shader.frag" and br.error_line == 4- assert "src/shader.frag:4" in br.error_message and "nope" in br.error_message--def test_feedback_and_nan_detection(tmp_ws, host):ws = _ws_with_plan(tmp_ws)(ws.src / "shader.frag").write_text(diff --git a/harness/tests/graphics/test_stale_invalidation.py b/harness/tests/graphics/test_stale_invalidation.pyindex aa505809..239b2af0 100644--- a/harness/tests/graphics/test_stale_invalidation.py+++ b/harness/tests/graphics/test_stale_invalidation.py@@ -1,10 +1,4 @@-"""GL builds must not leave the previous build's artifacts looking current (offline).--frames_sheet.png / preview.gif / metrics.json are written only on ok and were never-cleared; the MissingEntryFile early returns never reached GlHost._run's frames wipe.-Both wipes now happen at the top of build() (``_gl_common.invalidate_stale_outputs``)-plus a failure-path invalidation in ``finish_build``.-"""+"""A failed GL build must not leave the previous build's outputs looking current (offline)."""from __future__ import annotationsdiff --git a/harness/tests/graphics/test_track.py b/harness/tests/graphics/test_track.pyindex dcf90fa9..75ebd00d 100644--- a/harness/tests/graphics/test_track.py+++ b/harness/tests/graphics/test_track.py@@ -1,8 +1,7 @@-"""Offline: GraphicsTrack end-to-end with fakes (no GL, no network) + planner + prompts + rubric."""+"""Offline: the graphics track with fakes (no GL, no network) — judge replay and planner."""from __future__ import annotations-import jsonfrom pathlib import Pathfrom typing import Any@@ -14,35 +13,27 @@ from codeverse3d.config import Settingsfrom codeverse3d.contracts.artifacts import BuildResultfrom codeverse3d.contracts.common import Backends, Budget, Language, Trackfrom codeverse3d.contracts.plan import GraphicsPlan-from codeverse3d.contracts.run import RunStatusfrom codeverse3d.contracts.spec import Constraints, Spec-from codeverse3d.judges.rubrics import load_rubricfrom codeverse3d.languages._gl_common import finish_build, judge_timesfrom codeverse3d.languages.glsl_shader import GlslShaderRuntime-from codeverse3d.languages.opengl_python import OpenGLPythonRuntime-from codeverse3d.proc import EventLog-from codeverse3d.prompts import renderfrom codeverse3d.spatial.gl_render import GlFrame, GlResult, gif_times-from codeverse3d.tracks import get_track, planner-from codeverse3d.tracks.graphics import GraphicsTrack, graphics_prompt_context+from codeverse3d.tracks import planner+from codeverse3d.tracks.graphics import GraphicsTrackfrom codeverse3d.tracks.planner import PlanningError, ensure_acceptancefrom codeverse3d.workspace import Workspacefrom tests.orchestrator_tracks.fakes import FakeAgent, FakeChatModel, FakeJudge, FakeServices-FAIL_MARK = "RAISE_BUILD_ERROR"-STATIC_MARK = "STATIC_FRAMES"--def make_spec(language: Language = Language.GLSL_SHADER, *, generator: str = "fake:fake-model", max_rounds: int = 3) -> Spec:- return Spec(id="g1", track=Track.GRAPHICS, language=language, prompt="animated neon rain on a window with bokeh city lights",+def make_spec(*, max_rounds: int = 3) -> Spec:+ return Spec(id="g1", track=Track.GRAPHICS, language=Language.GLSL_SHADER, prompt="animated neon rain on a window with bokeh city lights",constraints=Constraints(must_have=["bokeh lights"]),budget=Budget(max_rounds=max_rounds, max_minutes=10, max_repair_attempts=2),- backends=Backends(planner="fake:planner", generator=generator, judge="fake:judge"))+ backends=Backends(planner="fake:planner", generator="fake:fake-model", judge="fake:judge"))-def _frame(path: Path, t: float, static: bool) -> None:+def _frame(path: Path, t: float) -> None:x = np.linspace(0, 1, 64, dtype=np.float32)[None, :].repeat(36, 0)- shift = 0.0 if static else 0.3 * t+ shift = 0.3 * trgb = np.stack([0.5 + 0.5 * np.sin(6 * (x + shift)), x * 0.5 + 0.2, 0.6 - 0.4 * x], -1)path.parent.mkdir(parents=True, exist_ok=True)Image.fromarray((rgb * 255).astype(np.uint8), "RGB").save(path)@@ -54,21 +45,11 @@ class FakeGlRuntime(GlslShaderRuntime):entry_globs = ("src/shader.frag", "src/common.glsl")- def __init__(self) -> None:- super().__init__()- self.builds = 0-def build(self, ws: Workspace, *, timeout_s: int | None = None, **kw: Any) -> BuildResult:- self.builds += 1- src = (ws.src / "shader.frag").read_text()- if FAIL_MARK in src:- res = GlResult(ok=False, mode="shader", stage="compile", error_type="GlslCompileError",- error_message="src/shader.frag:3: error: `nope' undeclared")- return finish_build(ws, res, language="glsl_shader", error_file="src/shader.frag", error_line=3)frames = []for i, t in enumerate(judge_times(8.0) + gif_times(8.0, 4)):p = ws.artifacts / "frames" / f"f{i:02d}_t{t:06.2f}.png"- _frame(p, t, STATIC_MARK in src)+ _frame(p, t)frames.append(GlFrame(index=i, time=t, path=str(p), judge=i < 5))res = GlResult(ok=True, mode="shader", stage="render", renderer="fake-gl", frames=frames)return finish_build(ws, res, language="glsl_shader", census={"convention": "mainImage"})@@ -99,57 +80,6 @@ def _plan(spec, ws, model, budget=None):return planner.plan(spec, "fake:planner", GraphicsPlan, ws, model=model, budget=budget)-def test_graphics_track_end_to_end(tmp_path, settings):- spec = make_spec(max_rounds=3)- ws = Workspace(tmp_path / "runs" / "rain")- judge = FakeJudge(scores=(0.55, 0.72, 0.9), targets=("RainDrops", "CityBokeh"))- agent = FakeAgent(_writer)- runtime = FakeGlRuntime()- track = GraphicsTrack(services=_services(), judge=judge, agent=agent, planner_model=FakeChatModel(lambda req: plan_example()),- settings=settings, runtime=runtime)- assert isinstance(get_track(Track.GRAPHICS), GraphicsTrack)- rec = track.run(spec, ws)- assert rec.status is RunStatus.MAX_ROUNDS and [r.kind for r in rec.rounds] == ["baseline", "refine", "refine", "refine"]- assert [r.score for r in rec.rounds] == pytest.approx([0.55, 0.72, 0.9, 0.9])- assert rec.extra["rubric"] == "shader_v2"- plan = GraphicsPlan.model_validate(json.loads(ws.plan_path.read_text()))- assert any(a.text.startswith("Includes: bokeh") for a in plan.acceptance)- # renders are the frames (views named t=<s>s) + a sheet, per round- r0 = rec.rounds[0]- assert r0.renders is not None and [v.name for v in r0.renders.views] == ["t=0s", "t=1s", "t=2.5s", "t=4s", "t=6s"]- assert r0.renders.views[2].time_s == 2.5 and Path(r0.renders.contact_sheet).is_file()- assert (ws.renders_dir(0) / "sheet.png").is_file() and (ws.artifacts / "preview.gif").is_file()- # gates: lint + gl_frames; no measurement- assert {g.gate for g in r0.gates} == {"lint:glsl_shader", "gl_frames"} and r0.measurement is None- assert (ws.gates_dir(0) / "gl_frames.json").is_file()- # judge saw frame metrics in the extra context and the plan digest- inp = judge.calls[0]- assert "FRAME METRICS" in inp.extra_context and "mean_lum" in inp.extra_context and "CityBokeh" in inp.plan_summary- # prompts: baseline is concrete (passes table, key visuals, contract, tools), refine carries judge + metrics- p0 = agent.jobs[0].prompt- assert "| RainDrops |" in p0 and "rain drops with trails" in p0 and "glsl_shader authoring contract" in p0 and "gl_frames" in p0- # the brief's recipes were seeded into the harness-owned src/recipes.glsl before the session (measured- # 2026-08-26, seed_v1: seeded into common.glsl they were overwritten), the prompt names them, every- # session's job carries the file as read-only, and common.glsl stays the agent's (skeleton, minus the- # helpers recipes.glsl now provides)- recipes = (ws.src / "recipes.glsl").read_text()- assert recipes.startswith("// harness-owned:") and "vec3 bokehSoft(vec2 p, float t)" in recipes and "vec2 dropsLayer(" in recipes- common = (ws.src / "common.glsl").read_text()- assert "// harness-owned:" not in common and "bokehSoft" not in common and common.startswith("// src/common.glsl")- assert "provided by src/recipes.glsl" in common.splitlines()[1] # the skeleton's own hash/noise/fbm were trimmed- assert all(j.read_only == ["src/recipes.glsl"] for j in agent.jobs) and all(j.edit_only is False for j in agent.jobs[:1])- assert "Verified helpers in the harness-owned, read-only `src/recipes.glsl`" in p0 and "`vec3 bokehSoft(vec2 p, float t)`" in p0- assert "harness-owned, read-only `src/recipes.glsl`" in agent.jobs[1].prompt and "`bokehSoft`" in agent.jobs[1].prompt- p1 = agent.jobs[1].prompt- assert "Refine" in p1 and "Frame metrics" in p1 and "Previous score 0.55" in p1- assert rec.rounds[1].instructions and all("[judge/" in i or "[gate/" in i for i in rec.rounds[1].instructions)- kinds = [e["event"] for e in EventLog(ws.events_path).read()]- for k in ("plan.done", "recipes.seeded", "round.start", "build.done", "gates.done", "judge.done", "refine.planned", "stop", "run.done"):- assert k in kinds, k- seeded = next(e for e in EventLog(ws.events_path).read() if e["event"] == "recipes.seeded")- assert {"dropsLayer", "bokehSoft"} <= set(seeded["names"]) and seeded["present"] == seeded["names"] # + the night-sky chapter--def test_a_replayed_round_reads_the_payload_the_in_run_judge_read(tmp_path, settings):"""``3dcode judge`` / calibration (``cli/_judge.build_judge_input``) replayed a graphics round witha digest of the plan's title and summary alone — no style, passes, key visuals or motion — while@@ -168,46 +98,6 @@ def test_a_replayed_round_reads_the_payload_the_in_run_judge_read(tmp_path, settassert "Passes: CityBokeh (fullscreen)" in replay.plan_summary and "Motion: drops slide down" in replay.plan_summary-def test_static_frames_become_a_gate_warning_and_refine_task(tmp_path, settings):- spec = make_spec(max_rounds=1)- ws = Workspace(tmp_path / "runs" / "static")-- def writer(job, ws_):- return {"src/shader.frag": f"// {STATIC_MARK}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {{ fragColor = vec4(1.0, 0.5, 0.2, 1.0); }}\n"}-- judge = FakeJudge(scores=(0.5, 0.5), targets=("overall",))- track = GraphicsTrack(services=_services(), judge=judge, agent=FakeAgent(writer), planner_model=FakeChatModel(lambda req: plan_example()),- settings=settings, runtime=FakeGlRuntime())- rec = track.run(spec, ws)- gl = next(g for g in rec.rounds[0].gates if g.gate == "gl_frames")- assert gl.passed and any(f.data["kind"] == "static" for f in gl.findings)- # the gate's warning is visible to the judge input and the refine round carried a task- assert "static" in judge.calls[0].extra_context.lower()---def test_build_failure_routes_to_rebuild_task(tmp_path, settings):- spec = make_spec(max_rounds=2)- ws = Workspace(tmp_path / "runs" / "broken")- calls = {"n": 0}-- def writer(job, ws_):- calls["n"] += 1- if calls["n"] <= 3: # baseline + 2 repair attempts keep failing- return {"src/shader.frag": f"void mainImage(out vec4 fragColor, in vec2 fragCoord) {{ fragColor = vec4(nope); }} // {FAIL_MARK} {calls['n']}\n"}- return _writer(job, ws_)-- agent = FakeAgent(writer)- track = GraphicsTrack(services=_services(), judge=FakeJudge(scores=(0.8,)), agent=agent, planner_model=FakeChatModel(lambda req: plan_example()),- settings=settings, runtime=FakeGlRuntime())- rec = track.run(spec, ws)- assert rec.rounds[0].build is not None and not rec.rounds[0].build.ok- assert rec.rounds[0].build.error_file == "src/shader.frag" and rec.rounds[0].build.error_line == 3- assert rec.rounds[1].kind == "refine" and rec.rounds[1].instructions == ["rebuild: previous round did not build"]- assert rec.rounds[1].build is not None and rec.rounds[1].build.ok- labels = [j.label for j in agent.jobs]- assert labels[0] == "baseline" and any(lb.startswith("r00_baseline_repair") for lb in labels) and "rebuild" in labels--def test_planner_reask_and_acceptance(tmp_ws):spec = make_spec()attempts = {"n": 0}@@ -233,27 +123,3 @@ def test_planner_reask_and_acceptance(tmp_ws):sys_prompt = planner.build_system_prompt(spec, GraphicsPlan)assert "ART-DIRECTOR" in sys_prompt and "NeonRainWindow" in sys_promptassert model.requests[0].temperature == 0.5 and model.requests[0].max_output_tokens == planner.PLAN_TOKENS_MAX---def test_templates_render_and_rubric_loads(tmp_path, settings):- rubric = load_rubric("shader_v2")- assert rubric.track_hint == "graphics" and {c.id for c in rubric.criteria} >= {"likeness", "motion_quality", "technical_cleanliness"}- assert {c.id for c in rubric.caps} >= {"nan_pixels", "static_frames", "black_or_blown", "build_error"}- spec = make_spec(language=Language.OPENGL_PYTHON, generator="single-shot:fake:fake-model")- ws = Workspace(tmp_path / "runs" / "tpl").create()- track = GraphicsTrack(services=_services(), settings=settings, runtime=OpenGLPythonRuntime()) # nothing is built- from codeverse3d.orchestrator import RunState-- ctx = track.build_context(spec, ws, EventLog(ws.events_path), RunState.load_or_new(ws, resume=False))- ctx.plan = GraphicsPlan.model_validate(plan_example())- base = graphics_prompt_context(ctx, skeleton_files={"src/program.py": "# x"}, previous_error="")- assert base["expected_files"] == ["src/program.py"] and base["single_shot"] and "=== FILE:" in base["output_format"]- gen = render("tracks/generate_graphics.j2", **base)- assert "src/program.py" in gen and "| CityBokeh |" in gen and "1280x720" in gen- ref = render("tracks/refine_graphics.j2", **graphics_prompt_context(- ctx, round_index=1, tasks=["[judge/effect] overall: more bokeh"], targets=["overall"], files=["src/program.py"],- judge_summary="Previous score 0.5", frame_notes="(no frame metrics)", current_files={"src/program.py": "# y"}))- assert "more bokeh" in ref and "--- src/program.py ---" in ref- from codeverse3d.judges.base import plan_summary-- assert "CityBokeh" in plan_summary(ctx.plan, ctx.language)diff --git a/harness/tests/graphics/test_wrap_lint.py b/harness/tests/graphics/test_wrap_lint.pyindex ec529090..9ad0d6eb 100644--- a/harness/tests/graphics/test_wrap_lint.py+++ b/harness/tests/graphics/test_wrap_lint.py@@ -21,18 +21,6 @@ SHADER = "void mainImage(out vec4 fragColor, in vec2 fragCoord) {\n vec2 uv =COMMON = "float hash(float n) { return fract(sin(n) * 43758.5453); }\n"-def test_compose_line_map_with_common_and_trailer():- c = compose(SHADER, COMMON)- assert c.convention == "mainImage" and not c.uses_feedback- header_lines = HEADER.count("\n")- assert c.source.startswith("#version 330 core")- # common.glsl line 1 sits right after the header; shader.frag line 1 right after common- assert c.line_map.locate(header_lines + 1) == ("src/common.glsl", 1)- assert c.line_map.locate(header_lines + 2) == ("src/shader.frag", 1)- assert c.line_map.locate(header_lines + 4) == ("src/shader.frag", 3)- assert c.source.rstrip().endswith("void main() { mainImage(fragColor, gl_FragCoord.xy); }")--def test_plain_main_convention_has_no_trailer_and_comments_ignored():src = "// mainImage is mentioned here only in a comment; u_prev too\nvoid main() { fragColor = vec4(1.0); }\n"c = compose(src)@@ -77,8 +65,7 @@ def test_glsl_lint_rules():def test_mixed_comments_blank_only_the_comments():- """A `/*` inside a `//` comment opens nothing: the two-pass stripper (blocks, then lines)- blanked everything up to a later `*/`, so the lint never saw the code in between."""+ """A `/*` inside a `//` comment opens nothing (the old two-pass stripper blanked real code)."""src = ("// tweak /* the fog here\nfloat fogAmt(float d) { return d; }\nuniform float u_extra;\n// end */\n""/* a // inside a block */ float x() { return 1.0; }\n")stripped = strip_comments(src)diff --git a/harness/tests/scene_gates/test_frame_metrics.py b/harness/tests/scene_gates/test_frame_metrics.pyindex 770dd57f..5932c3af 100644--- a/harness/tests/scene_gates/test_frame_metrics.py+++ b/harness/tests/scene_gates/test_frame_metrics.py@@ -8,7 +8,6 @@ from pathlib import Pathfrom codeverse3d.contracts.artifacts import RenderSet, RenderView, Severityfrom codeverse3d.judges.rubrics import apply_caps, load_rubricfrom codeverse3d.spatial.frame_metrics import (- FRAME_GATE,frame_findings,frame_gate_from_renders,frame_summary_text,@@ -31,13 +30,7 @@ def _kinds(report):return [(f.data["kind"], f.severity, f.target) for f in report.findings]-def test_clean_frames_pass_with_info():- rep = frame_findings(_metrics(_chk("Establishing"), _chk("overview_top", "orbit")))- assert rep.gate == FRAME_GATE and rep.passed- assert [f.data["kind"] for f in rep.findings] == ["frames_ok"]---def test_dark_frame_is_error_on_authored_with_concrete_hint():+def test_dark_frame_is_error_on_authored_with_concrete_hint_and_warns_on_orbit():rep = frame_findings(_metrics(_chk("Establishing", mean_lum=0.07, dark_frac=0.41)))assert not rep.passedf = rep.findings[0]@@ -45,12 +38,8 @@ def test_dark_frame_is_error_on_authored_with_concrete_hint():assert "0.07" in f.message and "41%" in f.messageassert "sunRig(" in f.fix_hint and "fill" in f.fix_hint and "NOT black" in f.fix_hint # the rig env.js builds, not a second sunassert f.data["view"] == "Establishing" and f.data["mean_lum"] == 0.07---def test_dark_frame_on_orbit_view_only_warns():- rep = frame_findings(_metrics(_chk("eye_front", "orbit", mean_lum=0.04, dark_frac=0.77)))- assert rep.passed- assert _kinds(rep) == [("dark_frame", Severity.WARN, "eye_front")]+ orbit = frame_findings(_metrics(_chk("eye_front", "orbit", mean_lum=0.04, dark_frac=0.77)))+ assert orbit.passed and _kinds(orbit) == [("dark_frame", Severity.WARN, "eye_front")]def test_blown_and_flat_frames():@@ -62,11 +51,6 @@ def test_blown_and_flat_frames():assert not rep.passed-def test_flat_is_not_duplicated_on_dark_frames():- rep = frame_findings(_metrics(_chk("Night", mean_lum=0.05, dark_frac=0.9, modal_frac=1.0)))- assert [k for k, _, _ in _kinds(rep)] == ["dark_frame"]--def test_camera_in_geometry_and_near_hit():rep = frame_findings(_metrics(_chk("Buried", camera_in_geometry=True, inside_mesh_bbox=["Tower"], nearest_hit_m=0.1),_chk("Close", nearest_hit_m=0.3)))@@ -75,17 +59,13 @@ def test_camera_in_geometry_and_near_hit():def test_a_lens_whose_sight_rays_end_within_reach_is_blocked():- """cmp6's crypt (2026-09-09): a squat pillar 0.8 m before AthanorDetail filled the frame and- the judge called the hidden hero "a massive untextured grey box" for two rounds."""rep = frame_findings(_metrics(_chk("AthanorDetail", nearest_hit_m=0.8, nearest_hit_name="StonePillar_3", near_rays=7, rays_total=9,near_limit_m=1.5),_chk("WorkTable", nearest_hit_m=0.9, nearest_hit_name="Bench", near_rays=2, rays_total=9),_chk("overview_top", kind="overview", nearest_hit_m=0.8, near_rays=9, rays_total=9)))assert [(k, s, t) for k, s, t in _kinds(rep)] == [("camera_blocked", Severity.ERROR, "AthanorDetail")]assert "StonePillar_3" in rep.findings[0].message and not rep.passed- # the measured crypt shape: only 3 of 9 rays end within reach, but the line of sight to the- # hero is cut at 0.9 m of 2.8 m — a WARN that names the pillar; a close-up meets its own- # subject near the full distance and stays quiet+ # few rays within reach but the line of sight to the target is cut: a WARN; a close-up stays quietcut = frame_findings(_metrics(_chk("AthanorDetail", nearest_hit_m=0.897, near_rays=3, rays_total=9, target_distance_m=2.8,target_hit_m=0.9, target_hit_name="VaultPillarMasonry"),_chk("HeroCloseUp", nearest_hit_m=1.1, near_rays=4, rays_total=9, target_distance_m=1.6,@@ -95,7 +75,6 @@ def test_a_lens_whose_sight_rays_end_within_reach_is_blocked():def test_a_lens_under_a_ground_surface_is_named_even_when_its_frame_looks_fine():- """cmp6's lighthouse: SlipwaySurge under the headland for three rounds, the frame 'fine'."""rep = frame_findings(_metrics(_chk("SlipwaySurge", eye_height_m=2.0, ground_below_m=2.0, ground_below_name="Sea",ground_above_m=1.4, ground_above_name="HeadlandTerrain"), ground_y=4.8))assert [(k, s) for k, s, _ in _kinds(rep)] == [("camera_under_ground_mesh", Severity.WARN)]@@ -106,9 +85,7 @@ def test_a_lens_under_a_ground_surface_is_named_even_when_its_frame_looks_fine()def test_eye_height_is_measured_under_the_lens_when_the_census_has_it():- """Relief terrain: a camera at eye level over a low patch is not an ant. Loop 21's ski- station (2026-09-09): eye 3.20 m, the highest snow 3.14 m → "0.06 m above ground —- ant's-eye view", repeated by the judge as a major issue on a frame shot from 1.6 m."""+ """Relief terrain: eye height is measured to the ground under the lens, not the highest ground."""rep = frame_findings(_metrics(_chk("Hill", eye_height_m=3.2, ground_below_m=1.62, ground_below_name="SnowTerrain"),_chk("Ant", eye_height_m=3.2, ground_below_m=0.06, ground_below_name="SnowTerrain"),_chk("Drone", eye_height_m=98.0, ground_below_m=95.0, ground_below_name="Ground"),@@ -121,10 +98,7 @@ def test_eye_height_is_measured_under_the_lens_when_the_census_has_it():def test_eye_height_sanity_against_ground():- # a camera below the scene's highest ground surface whose frame renders fine is NOT- # buried — census ground_y is the TOP of every ground mesh, so a hill or a raised bed- # puts it above a camera standing in the open (measured: this false ERROR capped a- # finished japanese garden at 0.50)+ # below the highest ground (census ground_y is the TOP of every ground mesh) with a fine frame: only a WARNrep = frame_findings(_metrics(_chk("Under", eye_height_m=-0.5), _chk("Ant", eye_height_m=0.1), _chk("Sat", eye_height_m=120.0),ground_y=0.0))assert [(k, s) for k, s, _ in _kinds(rep)] == [@@ -150,13 +124,6 @@ def test_content_small_roles():assert rep.findings[0].data["role"] == "establishing" and not rep.passed-def test_missing_coverage_metric_is_tolerated():- c = _chk("Establishing")- for k in ("content_frac", "ground_frac", "sky_frac"):- c.pop(k)- assert frame_findings(_metrics(c)).passed--def test_frame_gate_from_paths_and_renderset(tmp_path: Path):out = tmp_path / "r00"out.mkdir()@@ -194,17 +161,7 @@ def test_frame_summary_text_table():assert frame_summary_text({}) == "frame checks: no camera_checks in metrics"-# ------------------------------------------------- a hero that is loaded and never placeddef test_a_loaded_glb_that_reaches_no_frame_is_flagged():- """Measured 2026-08-25 on tsr_scn_boat_workshop_v2: src/scene.js loads- /assets/clinker_skiff.glb — a real Blender hero, authored, built, copied into- public/assets — while src/zones/central_bay.js calls a procedural buildClinkerSkiff().- The hull in every shipped frame is JavaScript. Nothing flagged it, and the check the- teaser wave used to verify the multi-language claim (plan.json -> assets[].kind) still- said blender_glb, because the plan records what was PLANNED, not what rendered."""- from codeverse3d.contracts.artifacts import Severity- from codeverse3d.spatial.frame_metrics import frame_findings-rep = frame_findings({"camera_checks": [], "census": {"glb_assets": [{"url": "/assets/clinker_skiff.glb", "meshes": 7, "meshes_in_scene": 0, "in_scene": False},{"url": "/assets/potbelly_stove.glb", "meshes": 5, "meshes_in_scene": 5, "in_scene": True},@@ -216,11 +173,8 @@ def test_a_loaded_glb_that_reaches_no_frame_is_flagged():assert rep.passed, "a WARN must not fail the gate"--def test_a_hero_in_the_scene_but_in_no_authored_frame_is_an_error():- """cmp6's crypt (2026-09-09): the athanor stood behind a pillar in every authored shot and- the judge called the HERO a grey box — ``glb_frac`` is the mask render per GLB per camera."""+ """``glb_frac`` is the mask render per GLB per camera."""url = "/assets/athanor.glb"census = {"ground_y": 0.0, "glb_assets": [{"url": url, "meshes": 9, "meshes_in_scene": 9, "in_scene": True, "size_m": 2.2}]}unseen = frame_findings({"census": census, "camera_checks": [diff --git a/harness/tests/scene_gates/test_judge_views.py b/harness/tests/scene_gates/test_judge_views.pyindex 88c0615e..d275d440 100644--- a/harness/tests/scene_gates/test_judge_views.py+++ b/harness/tests/scene_gates/test_judge_views.py@@ -45,27 +45,6 @@ def test_small_sets_pass_through():assert select_judge_views(rs, max_n=0).views == []-def test_max_n_and_custom_orbit_names():- rs = _rs()- sel = select_judge_views(rs, max_n=4)- assert [(v.name, v.time_s) for v in sel.views] == [(n, 0.0) for n in AUTHORED] + [("overview_front_right", 0.0)]- # unknown orbit names → everything counts as authored (9 at t=0 + the first two at t=1.5)- sel2 = select_judge_views(rs, max_n=12, orbit_names=["nothing"])- assert len(sel2.views) == 11 and sum(1 for v in sel2.views if v.time_s == 0.0) == 9---def test_metrics_path_for_locates_sibling_file(tmp_path: Path):- out = tmp_path / "r01"- out.mkdir()- (out / "a_t0.png").write_bytes(b"")- rs = RenderSet(views=[RenderView(name="a", path=str(out / "a_t0.png"))])- assert metrics_path_for(rs) is None- (out / "metrics.json").write_text("{}")- assert metrics_path_for(rs) == out / "metrics.json"- assert metrics_path_for(RenderSet(contact_sheet=str(out / "sheet.png"))) == out / "metrics.json"- assert metrics_path_for(RenderSet()) is None--def test_metrics_path_for_prefers_stamped_out_dir(tmp_path: Path):out = tmp_path / "r02"out.mkdir()@@ -78,24 +57,3 @@ def test_metrics_path_for_prefers_stamped_out_dir(tmp_path: Path):(elsewhere / "metrics.json").write_text("{}")rs2 = RenderSet(out_dir=str(tmp_path / "gone"), views=[RenderView(name="a", path=str(elsewhere / "a.png"))])assert metrics_path_for(rs2) == elsewhere / "metrics.json"---def test_mark_judge_views_serialises_stamped_flags(tmp_path: Path):- import json-- from codeverse3d.spatial.render_scene import _mark_judge_views-- views_json = tmp_path / "views.json"- views_json.write_text(json.dumps([- {"name": "a", "time_s": 0.0, "path": "a.png"},- {"name": "b", "time_s": 0.0, "path": "b.png"},- {"name": "a", "time_s": 1.5, "path": "a2.png"},- ]))- views = [- RenderView(name="a", path="a.png", time_s=0.0, judge=True),- RenderView(name="b", path="b.png", time_s=0.0, judge=False),- RenderView(name="a", path="a2.png", time_s=1.5, judge=True),- ]- _mark_judge_views(views_json, views)- flags = {(e["name"], e["time_s"]): e["judge"] for e in json.loads(views_json.read_text())}- assert flags == {("a", 0.0): True, ("b", 0.0): False, ("a", 1.5): True}diff --git a/harness/tests/scene_gates/test_live_hero_in_frame.py b/harness/tests/scene_gates/test_live_hero_in_frame.pyindex 54d83863..20744304 100644--- a/harness/tests/scene_gates/test_live_hero_in_frame.py+++ b/harness/tests/scene_gates/test_live_hero_in_frame.py@@ -1,9 +1,7 @@"""Browser-backed: a Blender hero (GLB) in the scene but in no authored frame is an ERROR.-cmp6's crypt (2026-09-09): the athanor stood behind a squat pillar in every authored shot; the-judge called the HERO "a massive untextured grey box" and two refine rounds rebuilt the wrong-thing. ``glbCoverage`` renders each loaded GLB as a white mask against black solids-(occlusion included) per camera; the gate reads ``camera_checks[].glb_frac``.+``glbCoverage`` renders each loaded GLB as a white mask against black solids (occlusion included)+per camera; the gate reads ``camera_checks[].glb_frac``."""from __future__ import annotations@@ -13,7 +11,7 @@ import mathimport pytestfrom codeverse3d.proc import read_json_or_none-from codeverse3d.spatial.frame_metrics import HERO_MIN_FRAC, frame_gate_from_renders+from codeverse3d.spatial.frame_metrics import frame_gate_from_rendersfrom codeverse3d.spatial.render_scene import render_scenefrom codeverse3d.workspace import Workspacefrom tests.scene_runtime.conftest import needs_browser@@ -63,28 +61,13 @@ def _with_hero(ws: Workspace, *, hidden: bool, roofed: bool = False, away_camerascene.write_text(text)-def test_a_hero_in_an_authored_frame_passes(starter_ws: Workspace):- _with_hero(starter_ws, hidden=False)- out = starter_ws.renders_dir(0)- rs = render_scene(starter_ws, out, times=(0.0,), width=640, height=360, fps_seconds=0.2)- assert rs.console_errors == []- m = read_json_or_none(out / "metrics.json")- rows = {r["url"]: r for r in m["census"]["glb_assets"]}- assert rows[URL]["in_scene"] is True and abs(rows[URL]["size_m"] - 4.0) < 0.05, rows[URL]- chk = {c["name"]: c for c in m["camera_checks"]}- seen = chk["overview"]["glb_frac"][URL]- assert seen > HERO_MIN_FRAC, chk["overview"]["glb_frac"] # the establishing shot sees the cube- others = [chk[n]["glb_frac"].get(URL, 0.0) for n in ("pond_low", "windmill")]- assert max(others) < seen, (seen, others) # the other shots look away from it- gate = frame_gate_from_renders(rs)- assert not [f for f in gate.findings if f.data["kind"].startswith("hero_")], [f.message for f in gate.findings]--def test_a_hero_behind_a_wall_in_every_authored_frame_is_an_error(starter_ws: Workspace):_with_hero(starter_ws, hidden=True)out = starter_ws.renders_dir(0)rs = render_scene(starter_ws, out, times=(0.0,), width=640, height=360, fps_seconds=0.2)m = read_json_or_none(out / "metrics.json")+ row = next(r for r in m["census"]["glb_assets"] if r["url"] == URL)+ assert row["in_scene"] is True and abs(row["size_m"] - 4.0) < 0.05, rowchk = {c["name"]: c for c in m["camera_checks"]}assert chk["overview"]["glb_frac"].get(URL, 0.0) < 0.002, chk["overview"]["glb_frac"] # in the scene, behind the wallgate = frame_gate_from_renders(rs)@@ -98,9 +81,7 @@ def test_a_hero_behind_a_wall_in_every_authored_frame_is_an_error(starter_ws: Wodef test_the_overview_rig_lifts_the_room_shells_lid_but_an_authored_camera_keeps_it(starter_ws: Workspace):- """cmp7's bakery (2026-09-09): the pairwise judge saw the harness interior as "a tiny fragment- in the overviews" — a closed box. The rig hides the harness-injected shell's ceiling when- the eye is above it; the authored cameras (and the census) keep the room as built."""+ """The rig hides the harness-injected shell's ceiling when the eye is above it; authored cameras keep it."""_with_hero(starter_ws, hidden=False, roofed=True)out = starter_ws.renders_dir(0)rs = render_scene(starter_ws, out, times=(0.0,), width=640, height=360, fps_seconds=0.2)@@ -116,10 +97,7 @@ def test_the_overview_rig_lifts_the_room_shells_lid_but_an_authored_camera_keepsdef test_a_camera_named_for_the_hero_is_re_aimed_when_the_hero_is_out_of_its_frame(starter_ws: Workspace):- """Loop 25's lighthouse (2026-09-09): `LanternDetail` shot the tower wall for three rounds- while `hero_unseen` read 0.0 % each time — cameras belong to the plan and no session moved- it. The host re-aims a hero-named camera at the hero's centre when that centre is outside- the frustum, and the repair log says so."""+ """The host re-aims a hero-named camera at the hero's centre when it is outside the frustum, and logs it."""_with_hero(starter_ws, hidden=False, away_camera=True)out = starter_ws.renders_dir(0)rs = render_scene(starter_ws, out, times=(0.0,), width=640, height=360, fps_seconds=0.2)diff --git a/harness/tests/scene_gates/test_orbit_framing.py b/harness/tests/scene_gates/test_orbit_framing.pyindex 870246f9..ab6c8292 100644--- a/harness/tests/scene_gates/test_orbit_framing.py+++ b/harness/tests/scene_gates/test_orbit_framing.py@@ -41,8 +41,10 @@ BOUNDS = {"min": [-13, -1.5, -13], "max": [13, 6.5, 13]}def test_framing_box_is_content_union_not_ground_or_sky():box = _call("framingBox", GARDEN, BOUNDS)assert box["min"] == pytest.approx([-12.3, -0.3, -9.1]) and box["max"] == pytest.approx([10.4, 5.8, 11.7])- # without bounds: same union+ # without bounds: same union; no groups → the census content_bbox; no census → Noneassert _call("framingBox", GARDEN)["size"] == pytest.approx(box["size"])+ assert _call("framingBox", {"content_bbox": GARDEN["content_bbox"], "groups": []})["size"] == pytest.approx(GARDEN["content_bbox"]["size"])+ assert _call("framingBox", None) is Nonedef test_framing_box_drops_scatter_that_sprawls_past_bounds_and_clamps():@@ -59,11 +61,6 @@ def test_framing_box_drops_scatter_that_sprawls_past_bounds_and_clamps():assert box3["min"][0] == pytest.approx(-13 * 1.1) and box3["max"][2] == pytest.approx(13 * 1.1)-def test_framing_box_falls_back_to_content_bbox():- assert _call("framingBox", {"content_bbox": GARDEN["content_bbox"], "groups": []})["size"] == pytest.approx(GARDEN["content_bbox"]["size"])- assert _call("framingBox", None) is None--def _ndc_of_corners(bbox, cam, aspect):"""Project bbox corners with a THREE-style lookAt camera (Y-up); returns max |x|,|y| in NDC."""eye, tgt, fov = cam["position"], cam["lookAt"], cam["fov"]@@ -89,7 +86,7 @@ def _ndc_of_corners(bbox, cam, aspect):return worst[email protected]("bbox", [GARDEN["content_bbox"], _box([-40, -1, -40], [40, 9, 40]), _box([-3, 0, -1], [3, 12, 1])])[email protected]("bbox", [GARDEN["content_bbox"], _box([-3, 0, -1], [3, 12, 1])])def test_overview_fit_is_tight_every_corner_just_inside_frame(bbox):views = [{"name": "overview_front_right", "azimuth": 40, "elevation": 32},{"name": "overview_back_left", "azimuth": 220, "elevation": 32},@@ -99,14 +96,3 @@ def test_overview_fit_is_tight_every_corner_just_inside_frame(bbox):worst = _ndc_of_corners(bbox, cam, 16 / 9)assert worst <= 1.0 + 1e-6, (cam["name"], worst) # every corner inside the frameassert worst >= 0.80, (cam["name"], worst) # ...and the box fills it (tight, not a sphere fit)---def test_garden_rig_is_much_closer_than_the_sphere_fit():- views = [{"name": "overview_front_right", "azimuth": 40, "elevation": 32}, {"name": "overview_top", "azimuth": 0, "elevation": 87},- {"name": "eye_front", "azimuth": 0, "elevation": 10}]- cams = {c["name"]: c for c in _call("fitOrbitCameras", GARDEN["content_bbox"], views, {"groundY": 0.37, "aspect": 16 / 9})}- ov = cams["overview_front_right"]- assert math.dist(ov["position"], ov["lookAt"]) < 38 # the sphere fit gave ≈ 42 m- assert cams["overview_top"]["position"][1] < 32 # was ≈ 45 m- eye = cams["eye_front"]- assert 1.5 < eye["position"][1] < 4 and eye["lookAt"][0] == pytest.approx(-0.95, abs=0.1) # looks at the content centrediff --git a/harness/tests/scene_gates/test_placement.py b/harness/tests/scene_gates/test_placement.pyindex 07ba37c0..5fe76a33 100644--- a/harness/tests/scene_gates/test_placement.py+++ b/harness/tests/scene_gates/test_placement.py@@ -1,8 +1,4 @@-"""scene_placement gate (2026-08-26): census placement table → findings, hints, caps, routing.--Pure python over a fake census dict — the node-level measurement is exercised in-``tests/scene_runtime/test_placement_census.py``.-"""+"""scene_placement gate: census placement table → findings and hints (pure python over a fake census)."""from __future__ import annotations@@ -12,9 +8,6 @@ from types import SimpleNamespacefrom codeverse3d.contracts.artifacts import BuildResult, Severityfrom codeverse3d.contracts.common import Languagefrom codeverse3d.contracts.plan import AssetPlan, BBox, CameraPlan, ScenePlan, ZonePlan-from codeverse3d.judges.rubrics import apply_caps, load_rubric-from codeverse3d.languages import get_runtime-from codeverse3d.orchestrator import build_refine_instructionsfrom codeverse3d.spatial.scene_placement import (GATE,infer_indoor,@@ -42,13 +35,6 @@ def _by_kind(report, kind):return [f for f in report.findings if f.data.get("kind") == kind]-def test_supported_and_exempt_rows_pass_with_a_summary_line():- r = placement_findings(_table(_row("Crate"), _row("Bird", exempt="free"), _row("Ground", zone="Environment", exempt="backdrop")))- assert r.gate == GATE and r.passed- assert [f.data["kind"] for f in r.findings] == ["summary"]- assert "1 assets checked (3 placed" in r.findings[0].message and "0 floating, 0 sunken" in r.findings[0].message--def test_floating_severity_by_gap_then_by_count():r = placement_findings(_table(_row("Lantern", gap=0.3), _row("Cup", gap=0.08, support="Table")))fl = _by_kind(r, "floating")@@ -93,17 +79,6 @@ def test_sunken_thresholds_height_fraction_and_name_words():assert "sunken 0.40 m into Terrain" in lantern.message and "raise Yard/Lantern by 0.40 m" in lantern.fix_hint-def test_interpenetration_pairs_and_error_above_sixty_percent():- pairs = [{"a": "CrateA", "b": "CrateB", "zone_a": "Yard", "zone_b": "Yard", "aabb_overlap": 0.5, "inside_frac": 0.25, "samples": 24},- {"a": "Post", "b": "Wall", "zone_a": "Yard", "zone_b": "House", "aabb_overlap": 0.9, "inside_frac": 0.6, "samples": 16}]- r = placement_findings(_table(_row("CrateA"), _row("CrateB"), pairs=pairs))- inter = _by_kind(r, "interpenetration")- # worst first: ERROR before WARN- assert [(f.target, f.severity) for f in inter] == [("Yard/Post", Severity.ERROR), ("Yard/CrateA", Severity.WARN)]- assert "interpenetration: Yard/CrateA and Yard/CrateB overlap (50%" in inter[1].message- assert "move Yard/Post out of House/Wall" in inter[0].fix_hint--def test_findings_are_capped_per_kind_and_the_summary_counts_them():r = placement_findings(_table(*[_row(f"Pebble{i}", gap=0.06 + i * 0.01) for i in range(12)]))fl = _by_kind(r, "floating")@@ -117,19 +92,6 @@ def test_probe_error_is_a_warning_that_passes():assert r.passed and r.findings[0].severity == Severity.WARN and "placement probe failed: boom" in r.findings[0].message-def test_scene_v1_floating_part_cap_fires_on_a_placement_error():- rubric = load_rubric("scene_v1")- floating = placement_findings(_table(_row("Lantern", gap=0.3)))- res = apply_caps(rubric, 0.9, [floating], {}, [])- assert res.overall == 0.6 and {c.rule for c in res.caps_applied} == {"floating_part", "floating_or_sunken_asset"}- assert "Lantern" in res.caps_applied[0].evidence- sunken = placement_findings(_table(_row("Lantern", sunk=0.4, into="Terrain", h=0.6)))- assert apply_caps(rubric, 0.9, [sunken], {}, []).overall == 0.6- # WARN-level findings (a mounted sign, a small hover) never cap- warn = placement_findings(_table(_row("Sign", gap=0.9, attached=("Post",)), _row("Cup", gap=0.08)))- assert apply_caps(rubric, 0.9, [warn], {}, []).overall == 0.9--def _plan():bb = BBox(center=(0, 0, 0), extents=(10, 5, 10))return ScenePlan(title="t", summary="s", setting="meadow", mood="calm", bounds=bb, environment="sunny",@@ -138,16 +100,6 @@ def _plan():animation=[], effects=[])-def test_error_findings_become_zone_routed_refine_tasks_one_per_asset():- plan = _plan()- r = placement_findings(_table(_row("Lantern", gap=0.3), _row("Bench", gap=0.4), _row("Vase", zone="House", gap=0.5)))- rt = get_runtime(Language.SCENE_THREEJS)- tasks = build_refine_instructions(None, [r], [], plan, file_for_target=lambda target: rt.files_for(plan, target))- assert sorted((t.target, tuple(t.files)) for t in tasks) == [("House/Vase", ("src/zones/house.js",)), ("Yard/Bench", ("src/zones/yard.js",)),- ("Yard/Lantern", ("src/zones/yard.js",))]- assert all(t.kind == f"gate:{GATE}" and "lower " in t.instruction for t in tasks)--def test_pipeline_gates_are_placement_alone_and_never_raise(tmp_path):from codeverse3d.workspace import Workspace@@ -180,9 +132,7 @@ def test_check_placement_reads_the_last_census_and_the_table_text(tmp_path):def test_check_placement_returns_the_round_gates_verdict(tmp_path):- """One verdict: the tool reads the same census, plan and stage records the round gate does,- so the plan checks it used to leave out (fog, zone contents, ...) are in it, and an asset- the asset stage could not build is not "missing" in either (2026-09-22)."""+ """The tool's verdict is the round gate's: same census, plan and stage records."""from codeverse3d.spatial.registry import ToolContext, get_toolfrom codeverse3d.workspace import Workspace@@ -218,7 +168,6 @@ def _contract_plan() -> ScenePlan:def test_contract_checks_fire_on_atmosphere_contents_scale_and_bounds():- """One census, five distinct deterministic failures the VLM used to carry alone."""far = _row("FarCrate")far["bbox"] = {"min": [100, 0, 100], "max": [101, 1, 101], "size": [1, 1, 1]}census = {"fog": None, "background": None,@@ -236,9 +185,7 @@ def test_contract_checks_fire_on_atmosphere_contents_scale_and_bounds():def test_a_wrapper_of_instances_is_scale_checked_as_one_instance():- """Loop 9 lighthouse (2026-09-07): 'PathAndFence/PicketFences' measured 14.73 m against the- plan's 2.4 m fence panel — a 6.1x ERROR the judge repeated and the repair obeyed by- shrinking the whole run to dots. The row's `families` carry the instance."""+ """The row's `families` carry the instance: a run of fence panels is not one 14 m panel."""bb = BBox(center=(0, 0, 0), extents=(40, 8, 40))plan = ScenePlan(title="t", summary="s", setting="headland", mood="blue hour", bounds=bb, environment="dusk",@@ -263,8 +210,6 @@ def test_a_wrapper_of_instances_is_scale_checked_as_one_instance():def test_the_typed_interior_flag_wins_over_the_setting_words():- """D69's `interior` is the plan's word; the setting-text inference stays for plans- written before it existed."""from codeverse3d.spatial.scene_placement import is_interiorassert is_interior({"setting": "a mountain meadow at dawn", "interior": True})@@ -274,8 +219,6 @@ def test_the_typed_interior_flag_wins_over_the_setting_words():def test_fog_that_ends_inside_the_plan_is_warned_for_exteriors_only():- """Measured 2026-09-08 over eleven exterior runs: fog far >= 2 x the plan span scored- >= 0.60, the three at 1.4-1.6 x scored 0.42-0.60 with 'world edge' verdicts."""plan = _contract_plan() # 40 m boundscensus = {"fog": {"type": "Fog", "near": 18, "far": 50, "density": None}, "background": "#aabbcc","placement": _table(_row("Lantern", h=0.6), _row("Bench", h=0.9), _row("BenchB", zone="House", h=0.9))}@@ -289,16 +232,6 @@ def test_fog_that_ends_inside_the_plan_is_warned_for_exteriors_only():assert not [f for f in placement_gate_safe(census, plan=inside).findings if f.data.get("kind") == "fog_short"]-def test_contract_checks_stay_quiet_on_a_dressed_in_bounds_scene():- census = {"fog": {"type": "Fog", "near": 10, "far": 60}, "background": "#aabbcc",- "placement": _table(_row("Lantern_3", h=0.6), _row("Bench", h=0.9),- _row("BenchB", zone="House", h=0.9))}- rep = placement_gate_safe(census, plan=_contract_plan())- contract_kinds = {"no_fog", "no_background", "missing_content", "zone_empty", "scale", "out_of_bounds"}- assert not [f for f in rep.findings if f.data.get("kind") in contract_kinds], [(f.data.get("kind"), f.message) for f in rep.findings]- assert rep.passed--def test_interpenetration_pairs_report_once_at_worst_overlap():pair = {"a": "Planter", "b": "Arbor", "zone_a": "Yard", "zone_b": "Yard"}r = placement_findings(_table(_row("Planter"), _row("Arbor"),@@ -310,9 +243,6 @@ def test_interpenetration_pairs_report_once_at_worst_overlap():def test_density_gate_fires_on_a_zone_far_under_its_layout_budget():- """scene_final_v1's top standing defects (flat_ground 12 / undressed 11 / monotonous 10)- while every zone had a BINDING layout budget nobody enforced. The census counts every- instance (InstancedMesh.count included), so the check is pure arithmetic."""layouts = {"Yard": {"placements": [{"asset": "Lantern", "count": 6}],"mid_props": 20, "small_props": 40, "ground_cover": 400},"House": {"placements": [], "mid_props": 2}} # budget 2 < threshold: ignored@@ -330,8 +260,6 @@ def test_density_gate_fires_on_a_zone_far_under_its_layout_budget():def test_no_backdrop_fires_outdoors_and_stays_quiet_with_a_ring_or_indoors():- """world_edge_visible stood in 11/19 scene_final_v1 verdicts; the env contract's- silhouette ring is measurable: standing geometry must reach past the play area."""base = {"fog": {"type": "Fog"}, "background": "#aabbcc","placement": _table(_row("Lantern_3", h=0.6), _row("Bench", h=0.9),_row("BenchB", zone="House", h=0.9))}@@ -351,10 +279,7 @@ def test_no_backdrop_fires_outdoors_and_stays_quiet_with_a_ring_or_indoors():assert not [f for f in rep.findings if f.data.get("kind") == "no_backdrop"]-def test_a_group_or_row_with_a_null_box_is_skipped_not_a_crash():- """sota_sydney_opera: a zone group with no geometry measures min/max/size as nulls, and- the backdrop reach did None - None — the whole placement gate degraded to one WARN."""null_box = {"min": [None, None, None], "max": [None, None, None], "size": [None, None, None]}ghost = _row("Bench")ghost["bbox"] = null_box@@ -368,9 +293,7 @@ def test_a_group_or_row_with_a_null_box_is_skipped_not_a_crash():def test_a_ring_of_identical_copies_round_the_world_is_warned_but_not_a_rotunda():- """2026-09-09, five of six exteriors: "a ring of identical cones stamped round the perimeter"- — the census measures the ring (host_census `stamps`); columns round a rotunda sit inside- the content and are architecture."""+ """Columns round a rotunda sit inside the content and are architecture, not a stamped ring."""plan = _contract_plan() # 40 m half-extentring = {"name": "FarPeaks", "n": 16, "radius_m": 36.0, "radius_cv": 0.01, "gap_cv": 0.02, "size_cv": 0.0}census = {"fog": {"type": "Fog", "near": 10, "far": 120}, "background": "#aabbcc",diff --git a/harness/tests/scene_gates/test_scene_textures_stage.py b/harness/tests/scene_gates/test_scene_textures_stage.pyindex f9e586b8..14df8445 100644--- a/harness/tests/scene_gates/test_scene_textures_stage.py+++ b/harness/tests/scene_gates/test_scene_textures_stage.py@@ -1,37 +1,15 @@-"""The scene texture pack, wired into the loop.--`texturing.plan.scene_texture_pack` generates a tileable pack into `public/textures/`,-and `texture_pack_prompt` — whose own docstring says "Prompt snippet for zone/env-generation" — describes it with the exact loading idiom. Nothing in `tracks/scene.py`-called either: `Spec.options.texture` does nothing on this track, and the generator was-never told a pack could exist.--Measured on bench/out/scene_baseline (2026-09-05): of 24 judge issues over five scored-cells, **four say the GROUND is a flat untextured colour**, in near-identical words-("single flat brown color", "single flat color with no cobblestone texture", "flat,-untextured blueish plane with no material blending"). It is the most consistent defect-in the battery, and it is a harness gap rather than a limit of three.js.--OFF by default: it costs an image-model call per run and what that buys is unmeasured.-"""+"""The scene texture pack as the env and zone prompts see it (the wiring is pinned by the prompt manifest)."""from __future__ import annotationsimport pytest-from codeverse3d.config import get_settings--[email protected](autouse=True)-def _clean_settings(monkeypatch):- monkeypatch.delenv("C3D_SCENE_TEXTURES", raising=False)- get_settings.cache_clear()- yield- get_settings.cache_clear()+from codeverse3d.config import Settingsdef test_the_switch_is_off_by_default():- assert get_settings().scene_textures is False+ """D58: the pack costs an image-model call per run, so it is off unless switched on."""+ assert Settings.model_fields["scene_textures"].default is Falsedef _render(name: str, **extra):@@ -49,59 +27,6 @@ def _render(name: str, **extra):return render(f"tracks/{name}", **base)-MANIFEST = {- "cobblestone": {"file": "cobblestone.png", "family": "stone", "role": "ground",- "tile_size_m": 2.0, "roughness": 0.85},-}--[email protected]("template", ["scene_env.j2", "scene_zone.j2"])-def test_the_pack_reaches_both_prompts(template: str):- from codeverse3d.texturing.plan import texture_pack_prompt-- snippet = texture_pack_prompt(MANIFEST)- with_pack = _render(template, textures=snippet)- assert "/public/textures/cobblestone.png" in with_pack- assert "loaders.texture.load" in with_pack, "the loading idiom has to travel with the list"--[email protected]("template", ["scene_env.j2", "scene_zone.j2"])-def test_no_pack_adds_nothing_to_either_prompt(template: str):- from codeverse3d.texturing.plan import texture_pack_prompt-- assert texture_pack_prompt({}) == ""- empty = _render(template, textures="")- assert "textures" not in empty.lower().split("## output")[0] or "/public/textures/" not in empty---def test_the_prompt_context_carries_the_manifest_the_stage_produced(monkeypatch):- """`_ctx` is the ONE place env and zone prompts get their context, so the manifest has- to arrive there or the stage generates textures nothing is told about — which is- exactly the state the loop was in before this."""- from types import SimpleNamespace-- import codeverse3d.tracks.scene as S- from codeverse3d.contracts.plan import BBox, CameraPlan, ScenePlan, ZonePlan-- seen: dict = {}- monkeypatch.setattr(S, "base_prompt_context", lambda ctx, **kw: seen.update(kw) or kw)-- bb = BBox(center=(0, 0, 0), extents=(10, 5, 10))- plan = ScenePlan(title="t", summary="s", setting="yard", mood="calm", bounds=bb, environment="sunny",- zones=[ZonePlan(name="Yard", description="d", bbox=bb, contents=[])], assets=[],- cameras=[CameraPlan(name="overview", position=(1, 1, 1), look_at=(0, 0, 0), fov=50, purpose="p")],- animation=[], effects=[])-- ctx = SimpleNamespace(plan=plan, extra={"textures": MANIFEST})- S.SceneTrack()._ctx(ctx) # type: ignore[arg-type]- assert "/public/textures/cobblestone.png" in seen["textures"]-- ctx_none = SimpleNamespace(plan=plan, extra={})- seen.clear()- S.SceneTrack()._ctx(ctx_none) # type: ignore[arg-type]- assert seen["textures"] == "", "no pack, no prompt block"--GROUND_MANIFEST = {"raked_zen_gravel": {"file": "raked_zen_gravel.png", "family": "stone", "role": "ground","tile_size_m": 1.0, "roughness": 0.95},@@ -113,12 +38,7 @@ GROUND_MANIFEST = {def test_the_pack_says_outright_that_the_ground_is_what_it_is_for():- """Measured 2026-09-05: the first two cells of the texture arm generated 8 and 9- textures, carried the block verbatim in their env prompt, and used ZERO of them across- `env.js` and six zone modules. Three things told the model to write a procedural- colour blend — the plan's own ground sentence, the cookbook chapter "Ground that reads- real (blend, paths, edges — never one flat colour)", and that chapter's position after- the block — against one passive list. A passive offer loses."""+ """A passive offer loses to the cookbook's ground chapter: the pack names its ground maps outright."""from codeverse3d.texturing.plan import texture_pack_prompttext = texture_pack_prompt(GROUND_MANIFEST)@@ -127,15 +47,8 @@ def test_the_pack_says_outright_that_the_ground_is_what_it_is_for():assert "`raked_zen_gravel`" in text and "`dark_slate_flagstone`" in texttail = text.split("The ground is what this pack is for")[1]assert "`aged_cedar_planks`" not in tail, "a prop texture is not a ground map"---def test_a_pack_with_no_ground_map_makes_no_ground_claim():- from codeverse3d.texturing.plan import texture_pack_prompt-- props = {k: v for k, v in GROUND_MANIFEST.items() if v["role"] == "prop"}- text = texture_pack_prompt(props)- assert "aged_cedar_planks.png" in text- assert "The ground is what this pack is for" not in text+ props = texture_pack_prompt({k: v for k, v in GROUND_MANIFEST.items() if v["role"] == "prop"})+ assert "aged_cedar_planks.png" in props and "The ground is what this pack is for" not in props@pytest.mark.parametrize("template", ["scene_env.j2", "scene_zone.j2"])@@ -143,4 +56,3 @@ def test_the_pack_has_the_last_word_over_the_recipes(template: str):"""The cookbook's ground chapter is long and specific; whichever comes last wins."""out = _render(template, textures="TEXTURE_BLOCK_MARKER", recipes="RECIPE_MARKER")assert out.index("RECIPE_MARKER") < out.index("TEXTURE_BLOCK_MARKER")-diff --git a/harness/tests/scene_gates/test_software_fps.py b/harness/tests/scene_gates/test_software_fps.pyindex 0d54a06c..2d277743 100644--- a/harness/tests/scene_gates/test_software_fps.py+++ b/harness/tests/scene_gates/test_software_fps.py@@ -1,19 +1,4 @@-"""A frame rate measured on a CPU rasteriser is the box's, not the scene's.--Measured on `bench/out/scene_baseline` (2026-09-05). With the machine's eight GPUs at-~100 % from other work, the GPU probe's negative verdict is cached for 20 minutes, so-cells fell back to SwiftShader one at a time. Across four scored cells `fps` was-measured on TWO DIFFERENT RENDERERS:-- japanese_garden 11.5 fps ANGLE (NVIDIA Corporation, NVIDIA RTX 6000 Ada …)- rooftop_garden 5.1 fps ANGLE (Google, … SwiftShader driver)- medieval_market 7.1 fps ANGLE (Google, … SwiftShader driver)- snowy_hut 2.0 fps ANGLE (Google, … SwiftShader driver) — 4 frames in 2 s--`render_console` raised "low frame rate" below 20 for all of them and the judge was told-"PROBE: measured N fps" as a fact. Two of the four judge issues marked **critical** in-that battery were frame-rate complaints, so the box was being scored as the model.-"""+"""A frame rate measured on a CPU rasteriser is the box's, not the scene's."""from __future__ import annotations@@ -26,22 +11,13 @@ CPU = "ANGLE (Google, Vulkan 1.3.0 (SwiftShader Device (Subzero) (0x0000C0DE)),@pytest.mark.parametrize("renderer,software", [- (GPU, False),- (CPU, True),("Mesa/X.org llvmpipe (LLVM 15.0.7, 256 bits)", True),- ("ANGLE (Intel, Mesa Intel(R) UHD Graphics)", False),("", False), # unknown: not claimable as software])def test_the_renderer_string_decides(renderer: str, software: bool) -> None:assert RenderSet(renderer=renderer, fps=9.0).software_rendered is software-def test_a_cpu_measurement_is_not_offered_as_a_frame_rate() -> None:- assert RenderSet(renderer=CPU, fps=2.0).hardware_fps is None- assert RenderSet(renderer=GPU, fps=11.5).hardware_fps == 11.5- assert RenderSet(renderer=GPU, fps=None).hardware_fps is None--def test_the_gate_does_not_fire_on_a_cpu_frame_rate() -> None:from types import SimpleNamespace@@ -71,8 +47,7 @@ def test_the_gate_does_not_fire_on_a_cpu_frame_rate() -> None:def test_the_judge_is_told_a_cpu_number_is_not_the_scene() -> None:- """Dropping it silently would hide a genuinely heavy scene from a reader, so the- line stays — labelled, with an instruction not to raise an issue from it."""+ """The line stays (a heavy scene must stay visible), labelled, with an instruction not to raise an issue."""from codeverse3d.judges.prompt_builder import view_rig_sectioncpu = view_rig_section(RenderSet(renderer=CPU, fps=2.0), [], scene=True)@@ -82,12 +57,7 @@ def test_the_judge_is_told_a_cpu_number_is_not_the_scene() -> None:def test_a_probe_with_no_boot_record_is_a_harness_failure_not_a_verdict() -> None:- """`probe_scene.mjs` always carries `boot` in its summary, so an absent one means the- driver produced no parsable output — not that the scene failed to boot. desert_canyon- (bench/out/scene_baseline, 2026-09-05) spent three repair attempts on- "[?] scene did not boot" with an identical signature while its own- artifacts/scene_probe.json recorded `ok: true, boot.ok: true, stage: ready`, and the- workspace boots in 600 ms today, unchanged."""+ """No `boot` in the driver summary means the driver output was lost, not that the scene failed to boot."""from codeverse3d.spatial.probes import probe_reportreport, census = probe_report({})@@ -103,11 +73,7 @@ def test_a_probe_with_no_boot_record_is_a_harness_failure_not_a_verdict() -> Nondef test_a_harness_failure_finding_makes_the_probe_result_not_ok() -> None:- """`SceneProbeResult.ok` is "the tool could run" (`Observation.failed = not ok`), and- the agent-facing `findings` deliberately exclude harness failures. A report carrying- one and nothing else therefore used to come back ok / no errors / no findings — a probe- that reads healthy and measured nothing, the exact shape that let desert_canyon's lost- output pass as a verdict about the scene."""+ """`ok` is "the tool could run"; a harness failure is an error, never an agent-facing finding."""from codeverse3d.contracts.artifacts import GateFinding, GateReport, Severityfrom codeverse3d.spatial.probes import _resultdiff --git a/harness/tests/scene_gates/test_zone_contents_nesting.py b/harness/tests/scene_gates/test_zone_contents_nesting.pyindex 2bcc8d2d..b8b8fbcd 100644--- a/harness/tests/scene_gates/test_zone_contents_nesting.py+++ b/harness/tests/scene_gates/test_zone_contents_nesting.py@@ -1,22 +1,4 @@-"""A zone that wraps its content in one group has still placed it.--Measured 2026-09-05 on `bench/out/scene_fixed` (floating_islands): three zones were-reported "missing planned contents: FloatingRock, Windmill, SkyPine" while the zone-module built each one and named it exactly that — `windmill.name = 'Windmill'`,-`rock.name = 'FloatingRock_1'` — and added them all to a group called `IslandAssembly`.-The placement table lists direct children of a zone, so the check saw one row named-`IslandAssembly` and called the plan unmet.--**All five** of arm B's remaining `scene_placement` ERRORs were this family, including the-two that looked like the model renaming things. `PineSway_0` and `LanternPost1` are the-names the ZONE gave the placed objects, but each contains the asset module's own root one-level further down — `inner` reads `['SnowyPineTree', 'Trunk', 'Boughs', …]` and-`['HutPorchLantern']`. Re-probing all three recorded workspaces takes the contract from-5 ERRORs to **0**.--The last test below still pins the rule for a subtree that genuinely does not carry the-planned name; that shape did not occur in this corpus.-"""+"""A zone that wraps its content in one group has still placed it: planned names are looked up under the row."""from __future__ import annotations@@ -51,14 +33,8 @@ def test_content_one_group_down_is_found():assert _missing(out) == [], "the zone built and named all three; only the shape differed"-def test_content_that_really_is_absent_is_still_reported():- out = contract_findings(_census(WRAPPED), _plan(["Windmill", "RopeBridge"]))- assert _missing(out) == ["RopeBridge"]--def test_a_subtree_that_carries_the_name_nowhere_still_reads_as_missing():- """The rule is "somewhere under this row", not "anywhere in the scene": a zone whose- whole subtree never mentions the planned content is still missing it."""+ """The rule is "somewhere under this row", not "anywhere in the scene"."""row = {"name": "Trees", "zone": "WindmillIsland", "inner": ["PineSway_0", "PineSway_1"]}out = contract_findings(_census(row), _plan(["SnowyPineTree"]))assert _missing(out) == ["SnowyPineTree"]@@ -66,32 +42,10 @@ def test_a_subtree_that_carries_the_name_nowhere_still_reads_as_missing():assert "give the object the plan's name" in hint-def test_a_row_with_no_inner_list_behaves_as_before():- row = {"name": "Windmill", "zone": "WindmillIsland"}- assert _missing(contract_findings(_census(row), _plan(["Windmill"]))) == []- assert _missing(contract_findings(_census(row), _plan(["SkyPine"]))) == ["SkyPine"]--def test_an_unavailable_hero_is_not_missing_content():- """A hero the asset stage could not build was withheld from the zone ("NOT AVAILABLE —- do not reference"); the contract check must not ERROR every round on its absence."""- from codeverse3d.spatial.scene_placement import contract_findings-+ """A hero the asset stage could not build was withheld from the zone: its absence is not an ERROR."""plan = {"zones": [{"name": "IncenseTerrace", "contents": ["BronzeCenser", "StoneBench"]}], "assets": []}census = {"placement": {"assets": [{"name": "StoneBench", "zone": "IncenseTerrace", "inner": []}]}}missing = [f for f in contract_findings(census, plan) if f.data.get("kind") == "missing_content"]assert missing and "BronzeCenser" in missing[0].messageassert not [f for f in contract_findings(census, plan, unavailable=["BronzeCenser"]) if f.data.get("kind") == "missing_content"]---def test_a_zone_whose_only_content_was_never_built_is_not_empty():- """zone_empty follows the same rule as missing_content: a zone told its only planned hero- is NOT AVAILABLE placed nothing because it was told to."""- from codeverse3d.spatial.scene_placement import contract_findings-- plan = {"zones": [{"name": "IncenseTerrace", "contents": ["BronzeCenser"]},- {"name": "Courtyard", "contents": ["StoneBench"]}], "assets": []}- census = {"placement": {"assets": [{"name": "StoneBench", "zone": "Courtyard", "inner": []}]}}- empty = [f.target for f in contract_findings(census, plan) if f.data.get("kind") == "zone_empty"]- assert empty == ["IncenseTerrace"]- assert not [f for f in contract_findings(census, plan, unavailable=["BronzeCenser"]) if f.data.get("kind") == "zone_empty"]diff --git a/harness/tests/spatial_tools/test_complexity.py b/harness/tests/spatial_tools/test_complexity.pyindex e0628252..1f6a5be8 100644--- a/harness/tests/spatial_tools/test_complexity.py+++ b/harness/tests/spatial_tools/test_complexity.py@@ -6,18 +6,16 @@ from __future__ import annotationsimport mathfrom pathlib import Path-import numpy as npimport pytestimport trimeshfrom codeverse3d.spatial.complexity import (COMPLEXITY_WEIGHTS,- ComplexityVector,band_of,complexity_of_glb,complexity_of_parts,)-from codeverse3d.spatial.measure import measure_glb, part_meshes+from codeverse3d.spatial.measure import part_meshesdef _export(path: Path, parts: dict[str, trimesh.Trimesh]) -> Path:@@ -84,36 +82,6 @@ def test_detail_beats_primitives(tmp_path: Path) -> None:assert rich.hollowness > plain.hollowness-def test_hollowness_separates_tube_from_solid(tmp_path: Path) -> None:- solid = trimesh.creation.cylinder(radius=0.05, height=0.3, sections=32)- tube = trimesh.creation.annulus(r_min=0.04, r_max=0.05, height=0.3)- assert complexity_of_parts({"Solid": solid}).hollowness < 0.05- assert complexity_of_parts({"Tube": tube}).hollowness > 0.5---def test_silhouette_frame_beats_block(tmp_path: Path) -> None:- block = complexity_of_parts({"Block": trimesh.creation.box(extents=(0.4, 0.4, 0.4))})- bars = {}- for i in range(4):- bar = trimesh.creation.box(extents=(0.4, 0.02, 0.02))- angle = i * math.pi / 2- bar.apply_transform(trimesh.transformations.rotation_matrix(angle, (1, 0, 0)))- bar.apply_translation((0, 0.19 * math.cos(angle), 0.19 * math.sin(angle)))- bars[f"Bar_{i}"] = bar- frame = complexity_of_parts(bars)- assert block.silhouette < 2.0 # a solid box projects to a square: crack P²/4πA ≈ 1.3- assert frame.silhouette > 2 * block.silhouette---def test_deterministic(tmp_path: Path) -> None:- import codeverse3d.spatial.measure as measure-- glb = detailed_scene(tmp_path / "rich.glb")- first = complexity_of_glb(glb)- measure._lru.clear()- assert complexity_of_glb(glb).model_dump() == first.model_dump()--def test_degenerate_input_never_raises() -> None:empty = complexity_of_parts({})assert empty.index == 0.0 and empty.extra["error"] == "no geometry"@@ -121,14 +89,6 @@ def test_degenerate_input_never_raises() -> None:assert none_only.part_count == 0-def test_measure_glb_carries_the_vector(stool_glb: Path) -> None:- block = measure_glb(stool_glb).extra["complexity"]- vec = ComplexityVector.model_validate(block)- assert vec.part_count == 5- assert vec.tri_count == measure_glb(stool_glb).tri_count- assert vec.version >= 1--def test_symmetry_groups_count_geometric_families(solid_stool_glb: Path) -> None:parts = part_meshes(trimesh.load(str(solid_stool_glb), force="scene", process=False))vec = complexity_of_parts(parts)@@ -140,22 +100,3 @@ def test_bands_are_ordered() -> None:labels = [band_of(x) for x in (0.0, 0.3, 0.45, 0.6, 0.9)]assert labels == ["trivial", "simple", "moderate", "complex", "intricate"]assert band_of(1.0) == "intricate"---def test_assembly_depth_sees_subassemblies(tmp_path: Path) -> None:- sc = trimesh.Scene()- box = trimesh.creation.box(extents=(0.2, 0.2, 0.2))- sc.add_geometry(box, node_name="Base", geom_name="Base")- child = trimesh.creation.box(extents=(0.1, 0.1, 0.1))- child.apply_translation((0, 0.15, 0))- sc.add_geometry(child, node_name="Top", geom_name="Top", parent_node_name="Base")- path = tmp_path / "nested.glb"- sc.export(str(path))- assert complexity_of_glb(path).assembly_depth >= 2---def test_normalisers_saturate_and_floor() -> None:- tiny = complexity_of_parts({"Dot": trimesh.creation.box(extents=(0.01, 0.01, 0.01))})- assert tiny.components["part_count"] == 0.0 # one part is the floor of the scale- assert tiny.index < 0.25 and tiny.band == "trivial"- assert np.isfinite(tiny.index)diff --git a/harness/tests/spatial_tools/test_connectivity.py b/harness/tests/spatial_tools/test_connectivity.pyindex de35b975..14f6d678 100644--- a/harness/tests/spatial_tools/test_connectivity.py+++ b/harness/tests/spatial_tools/test_connectivity.py@@ -18,18 +18,6 @@ from codeverse3d.spatial.connectivity import (from tests.spatial_tools.conftest import FLOAT_GAP_M-def test_floating_leg_found_with_exact_gap(stool_glb: Path) -> None:- r = check_connectivity(stool_glb)- assert r.gate == "connectivity" and not r.passed- errs = r.errors- assert len(errs) == 1 and errs[0].target == "Leg_3"- d = errs[0].data- assert d["nearest"] == "Seat"- assert d["gap_m"] == pytest.approx(FLOAT_GAP_M, abs=1e-4)- assert np.allclose(d["gap_vector_m"], (0.0, FLOAT_GAP_M, 0.0), atol=1e-4)- assert "translate 'Leg_3' by (+0.0000, +0.0050, +0.0000) m (GLB frame: Y-up, +Z front)" in errs[0].fix_hint--def test_hints_use_the_authoring_frame(stool_glb: Path) -> None:"""The 5 mm gap is along GLB +y (up). A Blender/CadQuery/URDF agent codes in Z-up, sothe pasted hint must say +z (a literal '+y' would move the leg towards the back)."""@@ -52,47 +40,6 @@ def test_hints_use_the_authoring_frame(stool_glb: Path) -> None:assert ground and "(z=0)" in ground[0].message and "z=0, cadquery frame" in ground[0].fix_hint-def test_solid_stool_passes(solid_stool_glb: Path) -> None:- r = check_connectivity(solid_stool_glb)- assert r.passed and not r.errors- assert any("connected" in f.message for f in r.findings)---def test_penetration_is_flagged(tmp_path: Path) -> None:- sc = trimesh.Scene()- a = trimesh.creation.box(extents=(0.2, 0.2, 0.2))- a.apply_translation((0, 0.1, 0))- b = trimesh.creation.box(extents=(0.2, 0.2, 0.2))- b.apply_translation((0, 0.1 + 0.2 - 0.03, 0)) # 30 mm deep into A- sc.add_geometry(a, node_name="A", geom_name="A")- sc.add_geometry(b, node_name="B", geom_name="B")- p = tmp_path / "pen.glb"- sc.export(str(p))- r = check_connectivity(p)- pen = [f for f in r.findings if "interpenetrate" in f.message]- assert pen and pen[0].severity == Severity.ERROR- assert pen[0].data["depth_m"] == pytest.approx(0.03, abs=0.004)- assert pen[0].data["kind"] == "penetration" and {pen[0].target, pen[0].data["other"]} == {"A", "B"}- assert {"depth_m", "fraction_inside", "local_fraction", "inside_count", "through_ratio", "thickness_m",- "container", "entering"} <= set(pen[0].data)- assert pen[0].data["thickness_m"] == pytest.approx(0.2, abs=1e-6)---def test_hairline_overlap_is_fine(tmp_path: Path) -> None:- sc = trimesh.Scene()- a = trimesh.creation.box(extents=(0.2, 0.2, 0.2))- a.apply_translation((0, 0.1, 0))- b = trimesh.creation.box(extents=(0.1, 0.1, 0.1))- b.apply_translation((0, 0.2 + 0.05 - 0.001, 0)) # 1 mm weld overlap- sc.add_geometry(a, node_name="A", geom_name="A")- sc.add_geometry(b, node_name="B", geom_name="B")- p = tmp_path / "weld.glb"- sc.export(str(p))- r = check_connectivity(p)- assert r.passed- assert not [f for f in r.findings if "interpenetrate" in f.message]--def test_tiny_island_warns(tmp_path: Path) -> None:body = trimesh.creation.box(extents=(0.3, 0.3, 0.3))body.apply_translation((0, 0.15, 0))@@ -136,12 +83,7 @@ def _open_bottom_box(extents, translation) -> trimesh.Trimesh:def test_interpenetration_is_found_between_two_non_watertight_parts(tmp_path: Path) -> None:- """CG-2: penetration_depth skipped any direction whose target was not watertight- (``Trimesh.contains`` needs one), so when NEITHER part was watertight it returned- (0.0, 0.0) — indistinguishable from "no overlap", with no warning that the check had- not run. A 0.2 m post driven 50 mm into a base then passed the gate as soon as both- were modelled as open shells; only the mixed closed/open case still fired, which is- why the shipped tests stayed green."""+ """Open shells (not watertight) are measured too — they once read as "no overlap"."""base_ext, post_ext = (0.4, 0.2, 0.4), (0.2, 0.2, 0.2)base_at, post_at = (0, 0.1, 0), (0, 0.25, 0) # post bottom 50 mm below the base's top faceclosed = (trimesh.creation.box(extents=base_ext), trimesh.creation.box(extents=post_ext))@@ -161,11 +103,10 @@ def test_interpenetration_is_found_between_two_non_watertight_parts(tmp_path: Pascene.export(str(glb))r = check_connectivity(glb)assert not r.passed and any("interpenetrate" in f.message for f in r.errors)-def _stool_with_a_leg_short_at_the_top(path: Path, gap_m: float = FLOAT_GAP_M) -> Path:- """The stool, but Leg_3 is shortened by ``gap_m`` at the TOP only.- It still stands on the floor and is ``gap_m`` shy of the seat — the single- commonest static-object defect, and the one CG-1 waved through."""++def _stool_with_a_leg_short_at_the_top(path: Path, gap_m: float = FLOAT_GAP_M) -> Path:+ """The stool, but Leg_3 is shortened by ``gap_m`` at the TOP only: on the floor, shy of the seat."""from tests.spatial_tools.conftest import LEG_XZsc = trimesh.Scene()@@ -183,9 +124,7 @@ def _stool_with_a_leg_short_at_the_top(path: Path, gap_m: float = FLOAT_GAP_M) -def test_a_part_detached_at_the_top_is_floating_even_though_it_reaches_the_floor(tmp_path: Path) -> None:- """CG-1: every ground-touching component was unioned into `support`, so a part- that merely reached y=0 counted as supported. Byte for byte the same defect as- the lifted-leg control — it must be reported the same way."""+ """Reaching the floor is not being supported: a leg shy of the seat is floating."""p = _stool_with_a_leg_short_at_the_top(tmp_path / "top_gap.glb")r = check_connectivity(p)@@ -199,22 +138,6 @@ def test_a_part_detached_at_the_top_is_floating_even_though_it_reaches_the_floorassert not [f for f in r.findings if "parts are connected" in f.message]-def test_two_grounded_islands_are_not_one_connected_assembly(tmp_path: Path) -> None:- """The minimal shape of the same bug: two boxes 2 m apart, both on the floor,- used to pass as 'all 2 parts are connected (0 contacts)'."""- sc = trimesh.Scene()- for i, x in enumerate((0.0, 2.0)):- m = trimesh.creation.box((0.5, 0.5, 0.5))- m.apply_translation((x, 0.25, 0))- sc.add_geometry(m, node_name=f"P{i}", geom_name=f"P{i}")- p = tmp_path / "two_grounded.glb"- sc.export(str(p))-- r = check_connectivity(p)-- assert not r.passed and len(r.errors) == 1- assert not [f for f in r.findings if "parts are connected" in f.message]-def _hat_and_body(path: Path, dy: float) -> Path:"""'hat' floating 100 mm above 'body', the pair translated by ``dy``."""sc = trimesh.Scene()@@ -229,12 +152,7 @@ def _hat_and_body(path: Path, dy: float) -> Path:def test_a_model_authored_below_the_floor_still_reports_its_floating_part(tmp_path: Path) -> None:- """CG-3: `grounded` was the one-sided `bounds[0][1] <= gap_m`, so a part buried 1 m- UNDER the floor counted as touching the ground. Every part of a sunk model therefore- landed in `grounded`, hence in `support`, and no floating finding could be emitted at- all — one routine agent mistake (authoring around the origin instead of on the floor,- which the contract gate already flags separately) silently switched the whole- connectivity floating check off for the run."""+ """A model authored below the floor must not switch the floating check off."""on_ground = check_connectivity(_hat_and_body(tmp_path / "f2_on_ground.glb", 0.0))sunk = check_connectivity(_hat_and_body(tmp_path / "f2_sunk.glb", -1.0))@@ -274,14 +192,7 @@ def _ledger(r):def test_thin_rod_through_a_plate_is_measured_and_named_but_severity_stays_on_depth(tmp_path: Path) -> None:- """An 8 mm rod, 1 m long, standing through a 10 mm plate. The overlap band is ~1 % of- the rod's surface, under PENETRATION_MIN_FRACTION, and its deepest point is 5 mm, under- PENETRATION_ERROR_M — so the 4ddde32 gate said nothing on this GLB (verified against- the committed module, 2026-08-30). The dense local pass finds it and the through-ratio- says the rod reaches the plate's far side — as a MEASUREMENT: it is a WARN, because the- same number is what a stile through a seat or a boom seated in a mast reads, and the- picture, not the gate, decides whether that is a defect (corpus re-run: a 0.9 ERROR line- flipped 9 runs of designed joinery)."""+ """An 8 mm rod through a 10 mm plate: found by the dense pass, through-ratio measured, still a WARN."""rod = _cylinder_y(0.004, 1.0, (0, 0.5, 0))plate = trimesh.creation.box(extents=(0.3, 0.01, 0.3))plate.apply_translation((0, 0.505, 0))@@ -305,28 +216,8 @@ def test_thin_rod_through_a_plate_is_measured_and_named_but_severity_stays_on_deassert over[0][2:] == [pytest.approx(5.0, abs=0.5), pytest.approx(d["through_ratio"], abs=0.01)]-def test_a_designed_socket_stays_a_warn_with_a_low_through_ratio(tmp_path: Path) -> None:- """A branch neck seated 3 mm into a pipe block (pipe_tee's BranchPipeNeck x MainPipeRun):- above the 2 mm WARN line, nowhere near the far side of anything — WARN, and the message- does not talk about reaching through."""- pipe = trimesh.creation.box(extents=(0.3, 0.1, 0.1))- pipe.apply_translation((0, 0.05, 0))- neck = _cylinder_y(0.02, 0.1, (0, 0.1 - 0.003 + 0.05, 0))-- r = check_connectivity(_scene(tmp_path / "socket.glb", MainPipeRun=pipe, BranchNeck=neck))-- pen = _penetrations(r)- assert r.passed and len(pen) == 1 and pen[0].severity == Severity.WARN- d = pen[0].data- assert d["depth_m"] == pytest.approx(0.003, abs=0.0005)- assert d["through_ratio"] < 0.2- assert "reaches" not in pen[0].message and "where they meet" in pen[0].message--def test_a_thin_part_sunk_into_a_thick_one_is_not_through(tmp_path: Path) -> None:- """h2h_microscope's FieldIlluminator: a 5 mm disc sunk 2.3 mm into the base. Measured- one way, the base's top surface reaches 82 % of the way through the disc; the pair's- through-ratio is the min over both directions, so a designed inset stays a WARN."""+ """A 5 mm disc sunk 2.3 mm into a base: the through-ratio is the min over both directions, so a WARN."""base = trimesh.creation.box(extents=(0.2, 0.05, 0.2))base.apply_translation((0, 0.025, 0))disc = _cylinder_y(0.02, 0.005, (0, 0.05 - 0.0023 + 0.0025, 0))@@ -336,12 +227,11 @@ def test_a_thin_part_sunk_into_a_thick_one_is_not_through(tmp_path: Path) -> Nonpen = _penetrations(r)assert r.passed and len(pen) == 1 and pen[0].severity == Severity.WARNassert pen[0].data["through_ratio"] < 0.2, pen[0].data+ assert "reaches" not in pen[0].message and "where they meet" in pen[0].messagedef test_contact_ledger_carries_contacts_overlaps_and_ground_gaps(tmp_path: Path) -> None:- """The 1 mm weld of test_hairline_overlap_is_fine is below the WARN line — no finding —- but the judge payload needs to know it is there to call it a weld, so the INFO ledger- lists it, with the contact and every part's height above the ground."""+ """A 1 mm weld is below the WARN line — no finding — but the INFO ledger lists it for the judge."""a = trimesh.creation.box(extents=(0.2, 0.2, 0.2))a.apply_translation((0, 0.1, 0))b = trimesh.creation.box(extents=(0.1, 0.1, 0.1))@@ -377,11 +267,7 @@ def test_planned_edges_are_measured_regardless_of_the_aabb_prefilter(solid_stooldef test_a_deep_overlap_only_the_dense_pass_can_see_is_a_warn_with_every_number(tmp_path: Path) -> None:- """A 40 mm square stile driven 17 mm into a 0.45 m seat slab — the corpus's commonest new- finding (rear stiles through seats on 14 dining chairs). The overlap is ~1 % of either- surface, so the 4ddde32 gate never saw it; the dense pass measures it, but a member the- eye cannot see inside a slab must not cap the run at 0.7 on its own: WARN, depth and- through-ratio in data, and the judge decides from the picture (D46 d)."""+ """D46 d: a stile 17 mm into a seat slab (a sliver of either surface) is a WARN with every number."""seat = trimesh.creation.box(extents=(0.45, 0.036, 0.45))seat.apply_translation((0, 0.45, 0)) # underside at y = 0.432stile = trimesh.creation.box(extents=(0.03, 1.0, 0.03)) # a 1 m backrest postdiff --git a/harness/tests/spatial_tools/test_contract.py b/harness/tests/spatial_tools/test_contract.pyindex ce9bb42d..17b14902 100644--- a/harness/tests/spatial_tools/test_contract.py+++ b/harness/tests/spatial_tools/test_contract.py@@ -9,7 +9,6 @@ from codeverse3d.contracts.plan import BBox, CameraPlan, PartPlan, ScenePlan, Stfrom codeverse3d.spatial.contract import (check_contract,match_parts,- plan_bbox_to_glb,planned_joins,)from codeverse3d.spatial.measure import measure_glb@@ -26,19 +25,6 @@ def _stool_plan(**overrides) -> StaticPlan:return StaticPlan(**data)-def test_frame_conversion() -> None:- b = plan_bbox_to_glb(BBox(center=(1, 2, 3), extents=(4, 5, 6)), "blender")- assert b.center == (1, 3, -2) and b.extents == (4, 6, 5)- same = plan_bbox_to_glb(BBox(center=(1, 2, 3), extents=(4, 5, 6)), "threejs")- assert same.center == (1, 2, 3)---def test_stool_matches_plan(solid_stool_glb: Path) -> None:- r = check_contract(measure_glb(solid_stool_glb), _stool_plan(), language="blender")- assert r.passed, [f.message for f in r.findings]- assert not [f for f in r.findings if f.severity == Severity.WARN]--def test_missing_part_is_error(solid_stool_glb: Path) -> None:plan = _stool_plan()plan.parts.append(PartPlan(name="Backrest", role="back", description="d", bbox=BBox(center=(0, 0.18, 0.6), extents=(0.4, 0.03, 0.3))))@@ -84,19 +70,8 @@ def test_ground_and_footprint_warnings() -> None:assert "above the ground" in msgs and "footprint centre" in msgs-def test_match_parts_instances() -> None:- rows = [PartMeasure(name=n, bbox_min=(0, 0, 0), bbox_max=(1, 1, 1)) for n in ("Leg_0", "Leg_1", "leg2", "Seat", "Extra")]- matched, extra = match_parts(_stool_plan().parts, rows)- assert {m.name for m in matched["Leg"]} == {"Leg_0", "Leg_1", "leg2"}- assert [e.name for e in extra] == ["Extra"]--def test_planned_joins_pair_a_spanning_child_with_every_touching_parent_copy() -> None:- """An X-braced table: Brace runs Leg_1 → Leg_3 and its AABB also grazes Leg_0 at the- crossing, so three copies tie at gap 0. ``min`` on list order joined it to Leg_0 alone- and the gate printed "OPEN: Brace→Leg_0" for a brace that touches two legs; the gate- measures each candidate exactly and keeps the contact row per child, so the resolver- emits every tied copy and no guess. Leg_2 is clear of the box: not a candidate."""+ """An X-braced table: every parent copy the brace's box touches is a candidate (ties are not broken by order)."""plan = StaticPlan(object_name="Table", summary="s", overall_bbox=BBox(center=(0, 0, 0.375), extents=(1.0, 1.0, 0.75)),parts=[PartPlan(name="Top", role="top", description="d", bbox=BBox(center=(0, 0, 0.73), extents=(1.0, 1.0, 0.04))),@@ -122,8 +97,7 @@ def test_planned_joins_pair_a_spanning_child_with_every_touching_parent_copy() -def test_an_exact_name_wins_over_another_part_instance_pattern() -> None:- """Order must not decide it either: 'Slat1' is claimed by Slat1 even when the- Slat instances are matched first, and Slat still collects its real instances."""+ """An exact name wins over another part's instance pattern ('Slat1' is not an instance of Slat)."""plan = [PartPlan(name=n, role="r", description="d", bbox=BBox(center=(0, 0, 0), extents=(1, 1, 1)))for n in ("Slat", "Slat1")]rows = [PartMeasure(name=n, bbox_min=(0, 0, 0), bbox_max=(1, 1, 1))@@ -136,29 +110,6 @@ def test_an_exact_name_wins_over_another_part_instance_pattern() -> None:assert extra == []-def test_the_gate_does_not_fire_on_a_glb_that_matches_the_plan_exactly() -> None:- """The end-to-end harm of CG-4: a false ERROR set passed=False, which fires- static_object_v1's contract_violation rule and caps the judge overall at 0.75 —- and the fix hint told the agent to create a part that already existed."""- plan = StaticPlan(- object_name="Rack", summary="s", overall_bbox=BBox(center=(0, 0, 0.5), extents=(1.0, 0.4, 0.64)),- parts=[PartPlan(name="Shelf", role="shelf", description="d", bbox=BBox(center=(0, 0, 0.2), extents=(1.0, 0.4, 0.04))),- PartPlan(name="Shelf2", role="shelf", description="d", bbox=BBox(center=(0, 0, 0.8), extents=(1.0, 0.4, 0.04)))],- )- m = Measurement(- bbox_min=(-0.5, 0.18, -0.2), bbox_max=(0.5, 0.82, 0.2), extents=(1.0, 0.64, 0.4),- center=(0.0, 0.5, 0.0), tri_count=24, n_meshes=2, n_islands=2,- ground_gap_m=0.0, footprint_offset_m=0.0,- parts=[PartMeasure(name="Shelf", bbox_min=(-0.5, 0.18, -0.2), bbox_max=(0.5, 0.22, 0.2)),- PartMeasure(name="Shelf2", bbox_min=(-0.5, 0.78, -0.2), bbox_max=(0.5, 0.82, 0.2))],- )-- r = check_contract(m, plan, language="blender")-- assert r.passed, [f.message for f in r.findings]- assert not [f for f in r.errors if "missing" in f.message]--def test_scene_plan_bounds() -> None:plan = ScenePlan(title="t", summary="s", setting="x", bounds=BBox(center=(0, 0, 0), extents=(10, 10, 10)), environment="e",zones=[ZonePlan(name="Harbour", description="d", bbox=BBox(center=(0, 0, 0), extents=(5, 5, 5)))],@@ -172,9 +123,7 @@ def test_scene_plan_bounds() -> None:def test_hints_are_written_in_the_authoring_frame() -> None:- """Blender plan (Z-up): Leg 5×5 cm footprint, 40 cm tall. The build made the leg 25 cm- DEEP (Blender y) — sizes, deltas and centres in the hint must be Z-up so the agent- changes the right dimension (in the GLB frame the same error reads as 'z+20cm')."""+ """Sizes, deltas and centres in the hint are in the language's frame (Blender: Z-up)."""plan = StaticPlan(object_name="Stool", summary="s", overall_bbox=BBox(center=(0, 0, 0.225), extents=(0.5, 0.5, 0.45)),parts=[PartPlan(name="Seat", role="seat", description="d", bbox=BBox(center=(0, 0, 0.425), extents=(0.5, 0.5, 0.05))),PartPlan(name="Leg", role="leg", description="d", bbox=BBox(center=(0.2, -0.2, 0.2), extents=(0.05, 0.05, 0.40)))])@@ -229,8 +178,6 @@ def test_a_standing_box_has_no_orientation_finding() -> None:def test_a_box_rotated_90_about_x_is_lying_down() -> None:- """Rotating the planned (0.4, 0.2, 1.2) box 90° about x swaps its y and z extents:- in Blender's frame it is now 0.2 m tall with the 1.2 m height running along y."""r = check_contract(_measurement_glb((0.4, 0.2, 1.2)), _one_part_plan((0.4, 0.2, 1.2), up=2), language="blender")o = _orientation(r.findings)assert len(o) == 1 and o[0].severity == Severity.ERROR and not r.passed@@ -256,32 +203,18 @@ def test_a_yaw_of_90_is_a_turned_warning() -> None:assert "turned 90° about z" in o[0].message and o[0].data["best_axis"] == "x"-def test_a_near_cube_says_nothing_however_it_is_permuted() -> None:- plan = _one_part_plan((0.5, 0.45, 0.55), up=2)- for ext in ((0.55, 0.5, 0.45), (0.45, 0.55, 0.5), (0.5, 0.45, 0.55)):- assert not _orientation(check_contract(_measurement_glb(ext), plan, language="blender").findings), ext---def test_a_sizing_error_is_a_contract_violation_not_an_orientation() -> None:- """Planner box 2× too big all round, and a build only half as tall: both deviate- (ERROR on the bbox) but nothing is sideways, so no orientation finding."""- plan = _one_part_plan((0.4, 0.2, 1.2), up=2)- for ext in ((0.2, 0.6, 0.1), (0.4, 0.6, 0.2)):- r = check_contract(_measurement_glb(ext), plan, language="blender")- assert not r.passed and any("bbox deviates" in f.message for f in r.errors)- assert not _orientation(r.findings), ext- # a cabinet planned 1.0 wide × 1.5 tall built 1.4 wide × 1.2 tall: its width is within- # 7% of the planned height, but 1.25× shorter is a proportion error, not a rotation- r = check_contract(_measurement_glb((1.4, 1.2, 0.5)), _one_part_plan((1.0, 0.5, 1.5), up=2), language="blender")[email protected]("glb, plan", [+ ((0.2, 0.6, 0.1), (0.4, 0.2, 1.2)), # 2× too big all round, half as tall: a bbox ERROR only+ ((1.4, 1.2, 0.5), (1.0, 0.5, 1.5)), # 1.25× shorter is a proportion error, not a rotation+ ((1.38, 0.458, 0.68), (0.48, 0.52, 0.81)), # a turn about x cannot change x, which grew 2.9×+])+def test_a_sizing_error_is_a_contract_violation_not_an_orientation(glb, plan) -> None:+ r = check_contract(_measurement_glb(glb), _one_part_plan(plan, up=2), language="blender")assert not r.passed and not _orientation(r.findings)def test_stood_on_end_needs_a_2x_change_in_height() -> None:- """Planners under-size tall objects: loop_w7 orrery_tj_ss r02 (threejs) was planned- 0.48×0.32×0.48 m and built 0.374×0.468×0.351 m, upright by eye — its height matches- the planned width within 3% and it is 1.46× taller than planned, which must NOT read- as 'stood on end'. A bench planned 1.5 m wide × 0.45 m tall that measures 0.45 wide- × 1.5 m tall is."""+ """An under-sized tall plan built 1.46× taller is not 'stood on end'; a bench on its end is."""orrery = _one_part_plan((0.48, 0.32, 0.48), up=1)assert not _orientation(check_contract(_measurement_glb((0.374, 0.468, 0.351)), orrery, language="threejs").findings)bench = _one_part_plan((1.5, 0.5, 0.45), up=2)@@ -289,21 +222,8 @@ def test_stood_on_end_needs_a_2x_change_in_height() -> None:assert len(o) == 1 and o[0].severity == Severity.ERROR and o[0].data["pose"] == "stood" and o[0].data["best_axis"] == "x"-def test_the_turning_axis_must_keep_its_extent() -> None:- """sysprompt_ab_blender36 b36_v0_01r r01: a 'dining chair' planned 0.48×0.52×0.81 m- came out as a 1.38×0.68×0.46 m table. Its height shrank 1.8× and 0.68 m along y is- within 16% of the planned 0.81 m height — but a turn about x cannot change the x- extent, and x grew 2.9×: wrong object, not a rotated one."""- r = check_contract(_measurement_glb((1.38, 0.458, 0.68)), _one_part_plan((0.48, 0.52, 0.81), up=2), language="blender")- assert not r.passed and not _orientation(r.findings)--def test_the_brilliana_c_clamp_is_caught_with_the_real_planner_box() -> None:- """h2h_brilliana_v1: the planner's box for 'a C-clamp with a threaded screw and swivel- pad' (cadquery, 12.5×9.6×22 cm) against the gallery GLB's measured extents- (astra3d-brilliana/gallery/c-clamp-mv, GLB 13.7×2.4×18.3 cm) — a clamp lying flat,- which the in-run judge missed and the visual re-judge caught. Note the planner's- 9.6 cm for a 2.4 cm thin axis: only the long axis can be required to reappear."""+ """A C-clamp lying flat against the real planner box: only the long axis must reappear."""plan = _one_part_plan((0.125, 0.096, 0.22), up=2)r = check_contract(_measurement_glb((0.137, 0.024, 0.183)), plan, language="cadquery")o = _orientation(r.findings)diff --git a/harness/tests/spatial_tools/test_mcp_server.py b/harness/tests/spatial_tools/test_mcp_server.pyindex 0452aad7..aa7fedf1 100644--- a/harness/tests/spatial_tools/test_mcp_server.py+++ b/harness/tests/spatial_tools/test_mcp_server.py@@ -11,17 +11,10 @@ import pytestfrom PIL import Imagefrom pydantic import ValidationError-from codeverse3d.spatial.mcp_server import build_context, encode_image, main, observation_content+from codeverse3d.spatial.mcp_server import encode_image, main, observation_contentfrom codeverse3d.spatial.registry import Observation, ToolContext-def test_build_context_infers_from_spec(stool_ctx: ToolContext) -> None:- ctx = build_context(stool_ctx.workspace.root)- assert ctx.language == "blender" and ctx.track == "static_object"- ctx = build_context(stool_ctx.workspace.root, language="threejs", round_index=2)- assert ctx.language == "threejs" and ctx.round_index == 2--def test_observation_content_blocks(tmp_path: Path) -> None:from PIL import Image@@ -40,12 +33,7 @@ def test_observation_content_blocks(tmp_path: Path) -> None:def test_result_payload_is_bounded_by_outcome(tmp_path: Path) -> None:- """Since the harness decides what is an error, no single result may hand the model an- unbounded blob. Text is capped here (an Observation built by hand never passes through- ``observe``'s truncation), and the image budget shrinks with the outcome: gemini-cli's- error path re-sends the WHOLE result as text, base64 images included — a 275 kB contact- sheet arrives as ~261k prompt tokens instead of ~516 (docs/COST.md §30) — and its own- 40 000-char truncation does not fire for a multi-part MCP result."""+ """Text is capped and the image budget shrinks with the outcome (gemini-cli re-sends an error as text, docs/COST.md §30)."""from PIL import Imagefrom codeverse3d.spatial.mcp_server import MAX_TEXT_CHARS, max_images_for@@ -67,10 +55,7 @@ def test_result_payload_is_bounded_by_outcome(tmp_path: Path) -> None:def test_the_byte_bound_keeps_the_sheet_drops_the_rest_and_says_so(tmp_path: Path) -> None:- """The count and the 1024 px downscale bound PIXELS, not bytes. images[0] is the- contact sheet and the rest are per-view repeats of it, so the budget must stop at the- first image that does not fit — dropping the sheet and shipping the views would be the- worst of both — and the text must say what did not come."""+ """The byte budget stops at the first image that does not fit (images[0] is the sheet) and says what did not come."""from PIL import Imagefrom codeverse3d.spatial.mcp_server import MAX_IMAGE_BYTES, encode_image@@ -102,44 +87,22 @@ def test_the_byte_bound_keeps_the_sheet_drops_the_rest_and_says_so(tmp_path: Patassert "1 image(s) not attached" in blocks[0].text-def test_an_oversized_sheet_is_downscaled_not_dropped(tmp_path: Path) -> None:- """The byte bound had ~1 % of headroom over the largest recorded sheet, so a slightly- taller one lost EVERY image and the round was judged on text alone. The first image- is the sheet; it gets re-encoded smaller until it fits, and the text says so."""- from PIL import Image-- from codeverse3d.spatial.mcp_server import MAX_IMAGE_BYTES-- big = tmp_path / "sheet.png"- Image.effect_noise((1600, 4200), 90).convert("RGB").save(big) # noise: PNG cannot shrink it- assert len(encode_image(str(big))) > MAX_IMAGE_BYTES-- blocks = observation_content(Observation(ok=True, text="t", images=[str(big)]))- images = [b for b in blocks if b.type == "image"]- assert len(images) == 1 and len(images[0].data) <= MAX_IMAGE_BYTES- assert "re-encoded at" in blocks[0].text---def test_every_bound_holds_including_the_note(tmp_path: Path) -> None:- """The "not attached" note used to be appended AFTER the hard slice, so the ceiling- was soft by the length of the note."""- from codeverse3d.spatial.mcp_server import MAX_TEXT_CHARS+def test_an_oversized_sheet_is_downscaled_and_every_bound_holds_including_the_note(tmp_path: Path) -> None:+ """The sheet is re-encoded smaller until it fits (never dropped), and the note stays under the text cap."""+ from codeverse3d.spatial.mcp_server import MAX_IMAGE_BYTES, MAX_TEXT_CHARSheavy = tmp_path / "heavy.png"Image.effect_noise((1600, 4200), 90).convert("RGB").save(heavy)blocks = observation_content(Observation(ok=True, text="x" * 20_000,images=[str(heavy), str(heavy)]))- assert len(blocks[0].text) <= MAX_TEXT_CHARS- assert "not attached" in blocks[0].text or "re-encoded" in blocks[0].text+ assert len(encode_image(str(heavy))) > MAX_IMAGE_BYTES+ images = [b for b in blocks if b.type == "image"]+ assert len(images) == 1 and len(images[0].data) <= MAX_IMAGE_BYTES+ assert len(blocks[0].text) <= MAX_TEXT_CHARS and "re-encoded at" in blocks[0].textdef test_is_error_is_failed_not_the_verdict(stool_ctx: ToolContext) -> None:- """The one coupling every other bound assumes, checked through the server itself.-- A tool that RAN and answered FAIL must reach the model as an ordinary result, so the- vendor sends its images as images; re-couple this to ``not obs.ok`` and the- base64-as-text blow-up of docs/COST.md §30 comes back. This used to be a grep over- ``make_server``'s source, which passes for any code that merely mentions the name."""+ """A FAIL verdict is an ordinary result (its images go as images); only a tool that could not run is is_error."""from mcp import typesfrom codeverse3d.spatial import mcp_server@@ -165,11 +128,7 @@ def test_is_error_is_failed_not_the_verdict(stool_ctx: ToolContext) -> None:def test_a_failure_cannot_also_be_a_pass() -> None:- """``failed`` implies ``not ok``. The pair was two independent booleans, so- ``Observation(ok=True, failed=True)`` was constructible — an is_error result whose- verdict says the gate passed, which nothing downstream can read consistently."""--+ """``failed`` implies ``not ok``."""with pytest.raises(ValidationError, match="has no verdict"):Observation(ok=True, failed=True, text="both")assert Observation(ok=False, failed=True, text="could not run").faileddiff --git a/harness/tests/spatial_tools/test_measure.py b/harness/tests/spatial_tools/test_measure.pyindex 827e993d..73cad6b1 100644--- a/harness/tests/spatial_tools/test_measure.py+++ b/harness/tests/spatial_tools/test_measure.py@@ -10,37 +10,17 @@ from codeverse3d.spatial.measure import (GlbLoadError,instance_groups,measure_glb,- measure_summary_table,)-def test_measure_stool(stool_glb: Path) -> None:- m = measure_glb(stool_glb)- assert {p.name for p in m.parts} == {"Seat", "Leg_0", "Leg_1", "Leg_2", "Leg_3"}- assert m.extents == pytest.approx((0.4, 0.45, 0.4), abs=1e-6)- assert m.ground_gap_m == pytest.approx(0.0, abs=1e-6)- assert m.footprint_offset_m == pytest.approx(0.0, abs=1e-6)- assert m.n_islands == 5 and m.n_meshes == 5- seat = next(p for p in m.parts if p.name == "Seat")- assert seat.tri_count == 12 and seat.watertight and seat.volume_m3 == pytest.approx(0.4 * 0.04 * 0.4, rel=1e-6)- assert m.frame == "y_up_pos_z_front"- assert m.extra["findings"] == []---def test_summary_table_groups_instances(stool_glb: Path) -> None:- table = measure_summary_table(measure_glb(stool_glb))- assert "Leg ×4 (Leg_0..3)" in table- assert "| Seat |" in table- assert "40.0×45.0×40.0" in table- assert table.count("\n") < 40--def test_instance_groups() -> None:g = instance_groups(["Leg_3", "Leg_0", "Seat", "Bolt.1", "Bolt.2", "Rail_1"])assert g["Leg"] == ["Leg_0", "Leg_3"]assert g["Bolt"] == ["Bolt.1", "Bolt.2"]assert g["Seat"] == ["Seat"]assert g["Rail_1"] == ["Rail_1"] # singleton keeps its full name+ # a bare base beside indexed siblings joins their group (it once crashed the judge input)+ assert instance_groups(["lens", "lens_2", "lens_1"])["lens"] == ["lens", "lens_1", "lens_2"]def test_missing_file_raises(tmp_path: Path) -> None:@@ -60,13 +40,6 @@ def test_degenerate_mesh_is_a_finding(tmp_path: Path) -> None:assert m.extents[1] == 0.0-def test_unnamed_single_mesh(tmp_path: Path) -> None:- p = tmp_path / "box.glb"- trimesh.creation.box(extents=(1, 1, 1)).export(str(p))- m = measure_glb(p)- assert len(m.parts) == 1 and m.tri_count == 12--def test_cyclic_scene_graph_does_not_hang(tmp_path: Path) -> None:"""A GLB node named like the loader's base frame ('world') closes a cycle in thescene graph; measuring must terminate (with the geometry still counted once)."""@@ -81,7 +54,6 @@ def test_cyclic_scene_graph_does_not_hang(tmp_path: Path) -> None:assert [k for k, v in part_meshes(scene).items() if v is not None]-# --------------------------------------------------------------------- parse memo (F24)def test_cached_parts_identity_and_invalidation(stool_glb: Path) -> None:from codeverse3d.spatial.measure import cached_parts@@ -104,27 +76,6 @@ def test_measure_glb_memoized_and_isolated(stool_glb: Path) -> None:assert measure_glb(stool_glb).extra["findings"] == []-def test_load_scene_is_never_cached(stool_glb: Path) -> None:- """Texturing mutates scenes in place — load_scene must hand out fresh objects."""- from codeverse3d.spatial.measure import load_scene-- s1 = load_scene(stool_glb)- s2 = load_scene(stool_glb)- assert s1 is not s2- g1 = s1.geometry[next(iter(s1.geometry))]- assert g1 is not s2.geometry[next(iter(s2.geometry))]---def test_instance_groups_bare_base_beside_indexed_siblings() -> None:- """`lens` next to `lens_1` lands in the same group (the bare name is the regex- non-match) — this crashed the judge input assembly with AttributeError on the- None match until 2026-08-28 (scope_tj_ss r1/r2 lost their judgments to it)."""- g = instance_groups(["lens", "lens_2", "lens_1", "tripod"])- assert g["lens"] == ["lens", "lens_1", "lens_2"]- assert g["tripod"] == ["tripod"]---# ------------------------------------------------- 2026-08-30: world transforms and node namesdef _root_pivot_scene(dup_names: bool = False) -> trimesh.Scene:"""Two 0.1 x 0.1 x 0.4 posts authored Z-up under a root 'pivot' carrying the Z-up→Y-uprotation — what THREE.GLTFExporter writes for a Z-up scene."""@@ -139,22 +90,8 @@ def _root_pivot_scene(dup_names: bool = False) -> trimesh.Scene:return sc-def test_world_transform_composes_every_edge_up_to_the_root() -> None:- """``scene.graph.get`` left a scene-root matrix out of its descendants' world frames on- the brilliana desk lamp (an upright lamp measured lying down, 2026-08-30); the edge- walk is what the render rig agrees with. Here: the rotation on world→pivot must reach- a grandchild, composed in the right order."""- from codeverse3d.spatial.measure import world_transform-- sc = _root_pivot_scene()- t = world_transform(sc, "Post_1")- # Post_1 sits at x=0.3, z=0.2 in the Z-up frame → world x=0.3, y=0.2- assert np.allclose(t[:3, 3], (0.3, 0.2, 0.0), atol=1e-9)- assert np.allclose(t[:3, :3], [[1, 0, 0], [0, 0, 1], [0, -1, 0]], atol=1e-9)- assert np.allclose(world_transform(sc, sc.graph.base_frame), np.eye(4))--def test_a_root_pivot_glb_measures_upright(tmp_path: Path) -> None:+ """A scene-root rotation reaches every descendant's world frame (an upright lamp once measured lying down)."""p = tmp_path / "pivot.glb"p.write_bytes(_root_pivot_scene().export(file_type="glb"))m = measure_glb(p)@@ -164,9 +101,7 @@ def test_a_root_pivot_glb_measures_upright(tmp_path: Path) -> None:def test_duplicate_or_unnamed_glTF_nodes_are_named_in_the_findings(tmp_path: Path) -> None:- """The harness's own exporters name every node uniquely; a foreign THREE export with- 'Arm' x2 and 21 unnamed nodes mis-posed under trimesh — the reader must be told the- numbers are approximate rather than trust them (desk-lamp-q2, 2026-08-30)."""+ """Duplicate or unnamed nodes mis-pose under trimesh: the reader is told the numbers are approximate."""import jsonimport structdiff --git a/harness/tests/spatial_tools/test_observe.py b/harness/tests/spatial_tools/test_observe.pyindex 8b601838..dc4ee6e4 100644--- a/harness/tests/spatial_tools/test_observe.py+++ b/harness/tests/spatial_tools/test_observe.py@@ -15,11 +15,7 @@ from codeverse3d.spatial.observe import (fmt_numbers,gate_observation,image_budget,- lint_lines,- rel_path,render_observation,- sanitize_text,- truncate,)@@ -28,26 +24,12 @@ def test_fmt_numbers_compact() -> None:assert "a=1.2346" in s and "b=[0.1, 0.2]" in s and "c=yes" in s and "{1 keys}" in s and "…" in s-def test_truncate_keeps_head_and_tail() -> None:- text = "\n".join(f"line {i}" for i in range(500))- t = truncate(text, 400)- assert t.startswith("line 0") and t.endswith("line 499") and "chars omitted" in t- assert truncate("short") == "short"--def test_image_budget_keeps_sheet_first() -> None:imgs = [f"/x/{i}.png" for i in range(10)]out = image_budget(imgs, max_n=3)assert out == imgs[:3]-def test_paths_are_workspace_relative(tmp_path: Path) -> None:- p = tmp_path / "artifacts" / "object.glb"- assert rel_path(p, tmp_path) == "artifacts/object.glb"- assert rel_path("/elsewhere/file.py", tmp_path) == "file.py"- assert sanitize_text(f"error in {tmp_path}/src/model.py:3", tmp_path) == "error in src/model.py:3"--def test_gate_observation_errors_first() -> None:rep = GateReport(gate="g", passed=False, findings=[GateFinding(gate="g", severity=Severity.INFO, message="fyi"),@@ -62,22 +44,8 @@ def test_gate_observation_errors_first() -> None:assert obs.numbers["errors"] == 1 and obs.numbers["error_data"]["B"]["gap_m"] == 0.01-def test_render_observation(tmp_path: Path) -> None:- rs = RenderSet(views=[RenderView(name="front", path=str(tmp_path / "a/view_front.png"), camera_position=(0, 1, 2), fov=35)],- contact_sheet=str(tmp_path / "a/sheet.png"), renderer="swiftshader")- obs = render_observation(rs, tmp_path, note="hello")- assert obs.ok and obs.images[0].endswith("sheet.png") and len(obs.images) == 2- assert "a/view_front.png" in obs.text and str(tmp_path) not in obs.text- assert "cam=(0, 1, 2)" in obs.text--def test_render_with_no_views_is_a_failure_console_errors_are_a_verdict(tmp_path: Path) -> None:- """The negative renders are not one answer. Nothing rendered and nothing logged: the- tool's product is pictures, it has none and no reason, and nothing the agent edits- changes that — an MCP error (``failed``). Console errors: the scene RAN far enough to- log them, so it is a verdict the agent fixes, even when the boot failure left zero- views (`render_scene` returns exactly that) — reporting THAT as a broken call buys a- blind retry of the thing that just explained itself. Both lead the text."""+ """No views and no log: the tool failed. Console errors (even with zero views): a verdict the agent fixes."""empty = render_observation(RenderSet(views=[], renderer="fake"), tmp_path, note="shaded render")assert not empty.ok and empty.failedassert empty.text.startswith("RENDER PRODUCED NO VIEWS (fake)")@@ -97,16 +65,6 @@ def test_render_with_no_views_is_a_failure_console_errors_are_a_verdict(tmp_pathassert "SyntaxError" in booted.text-def test_lint_lines_split_by_severity(tmp_path: Path) -> None:- rep = GateReport(gate="lint:x", passed=False, findings=[- GateFinding(gate="lint:x", severity=Severity.ERROR, target=str(tmp_path / "src" / "a.py"), message="bad", fix_hint="fix it"),- GateFinding(gate="lint:x", severity=Severity.WARN, message="meh"),- GateFinding(gate="lint:x", severity=Severity.INFO, message="fyi"),- ])- assert lint_lines(rep, tmp_path, errors_only=True) == ["- ERROR (src/a.py): bad", " fix: fix it"]- assert lint_lines(rep, tmp_path, errors_only=False) == ["- WARN: meh"]--def test_build_failure_lines_relative_file_and_tail_dedupe(tmp_path: Path) -> None:# (ii) an already-relative error_file is shown as-is from any cwd (rel_path would give the bare name)# (iii) a stderr tail that is already part of the message is not repeateddiff --git a/harness/tests/spatial_tools/test_render_common.py b/harness/tests/spatial_tools/test_render_common.pyindex 2882f7e7..c09d395f 100644--- a/harness/tests/spatial_tools/test_render_common.py+++ b/harness/tests/spatial_tools/test_render_common.py@@ -1,130 +1,18 @@-"""The shared render/tool core: `spatial._render_common`, the sheet + gif writers,-`measure.solid_parts` and the `tool_common` helpers. Each test pins one merge that-removed a duplicate implementation.-"""+"""Render caching: one cache authority, keyed by content and GPU mode, safe under concurrent writers."""from __future__ import annotations-import jsonfrom pathlib import Pathimport pytest-from PIL import Image-from codeverse3d.conventions import OBJECT_VIEWS, SCENE_VIEWS-from codeverse3d.spatial import _render_common as rc+from codeverse3d.conventions import OBJECT_VIEWSfrom codeverse3d.spatial.registry import ToolContextfrom codeverse3d.workspace import Workspace-# --------------------------------------------------------------------------- _render_common-def test_out_directory_creates_and_clears_stale_side_cars(tmp_path: Path) -> None:- d = tmp_path / "a" / "b"- (tmp_path / "a").mkdir()- d.mkdir()- (d / "metrics.json").write_text('{"stale": true}')- (d / "keep.png").write_bytes(b"x")- out = rc.out_directory(d, clean=("metrics.json", "views.json"))- assert out == d.resolve() and out.is_dir()- assert not (d / "metrics.json").exists() and (d / "keep.png").is_file()- # creating a missing directory is the common case- assert rc.out_directory(tmp_path / "fresh").is_dir()---def test_view_specs_is_the_one_camera_payload() -> None:- specs = rc.view_specs(OBJECT_VIEWS)- assert [s["name"] for s in specs] == [v.name for v in OBJECT_VIEWS]- assert all(set(s) == {"name", "azimuth", "elevation"} for s in specs)- assert all(isinstance(s["azimuth"], float) and isinstance(s["elevation"], float) for s in specs)- # what the scene driver receives is exactly this, JSON-encoded- from codeverse3d.spatial.render_scene import _views_json-- assert json.loads(_views_json(SCENE_VIEWS)) == rc.view_specs(SCENE_VIEWS)---def test_build_sheet_uses_the_settings_grid_and_guards_empty(tmp_path: Path) -> None:- assert rc.build_sheet([], tmp_path / "none.png") is None- for i in range(2):- Image.new("RGB", (64, 64), (10 * i, 0, 0)).save(tmp_path / f"v{i}.png")- out = rc.build_sheet([(f"v{i}", tmp_path / f"v{i}.png") for i in range(2)], tmp_path / "sheet.png")- assert out and Path(out).is_file()- from codeverse3d.config import get_settings-- tile = get_settings().render.sheet_tile- with Image.open(out) as im:- assert im.width == 2 * (tile + 6) + 6 # two columns at the configured tile size---# --------------------------------------------------------------------------- sheet: cells + gif-def test_contact_sheet_keeps_a_non_square_cell(tmp_path: Path) -> None:- from codeverse3d.spatial.sheet import LABEL_H, PAD, contact_sheet, tile_size-- src = tmp_path / "wide.png"- Image.new("RGB", (1280, 720), (30, 60, 90)).save(src)- assert tile_size(480, sample=src) == (480, 270)- assert tile_size(480) == (480, 480) and tile_size((300, 100)) == (300, 100)- out = contact_sheet([("t=0s", src), ("t=1s", src)], tmp_path / "s.png", cols=2, tile=(480, 270))- with Image.open(out) as im:- assert im.size == (2 * (480 + PAD) + PAD, (270 + LABEL_H + PAD) + PAD)---def test_gl_contact_sheet_and_gif_go_through_the_shared_writers(tmp_path: Path) -> None:- from codeverse3d.spatial.gl_render import GlFrame, write_contact_sheet, write_gif- from codeverse3d.spatial.sheet import LABEL_H, PAD-- frames = []- for i in range(3):- p = tmp_path / f"f{i}.png"- Image.new("RGB", (640, 360), (20 * i, 40, 60)).save(p)- frames.append(GlFrame(index=i, time=i * 1.5, path=str(p)))- sheet = write_contact_sheet(frames, tmp_path / "sheet.png", cols=2, tile_w=320)- with Image.open(sheet) as im: # 16:9 cells, 2 columns, 2 rows- assert im.size == (2 * (320 + PAD) + PAD, 2 * (180 + LABEL_H + PAD) + PAD)- gif = write_gif(frames, tmp_path / "p.gif", width=160, fps=6)- assert gif and Path(gif).is_file()- with Image.open(gif) as im:- assert im.n_frames == 3 and im.width == 160- assert write_gif(frames[:1], tmp_path / "one.gif") is None # < 2 frames = no preview---# --------------------------------------------------------------------------- parts loader-def test_solid_parts_is_cached_parts_without_the_empty_ones(stool_glb: Path) -> None:- from codeverse3d.spatial.measure import cached_parts, solid_parts-- solid = solid_parts(stool_glb)- assert solid and list(solid) == [k for k, v in cached_parts(stool_glb).items() if v is not None and len(v.faces)]- assert all(v is not None and len(v.faces) for v in solid.values())---def test_shared_number_formatters() -> None:- from codeverse3d.spatial.connectivity import _fmt_vec as conn_vec- from codeverse3d.spatial.measure import fmt_extent_cm, fmt_vec-- assert fmt_extent_cm([0.34, 0.47]) == "34.0×47.0"- assert fmt_vec([-0.00001, 0.5, 0]) == "(+0.000, +0.500, +0.000)" # never '-0.000'- assert conn_vec((-0.00001, 0.5, 0.0)) == "(+0.0000, +0.5000, +0.0000)" # 4 decimals, same shape- assert fmt_vec([1.23456], digits=2) == "(+1.23)"---# --------------------------------------------------------------------------- tool plumbing-def test_tool_out_dir_is_round_stamped(stool_ctx: ToolContext) -> None:- from codeverse3d.spatial.tool_common import render_cache_dir, tool_out_dir-- d = tool_out_dir(stool_ctx, "sections")- assert d.is_dir() and d.name == f"r{stool_ctx.round_index:02d}_sections"- assert d.parent == stool_ctx.workspace.artifacts / "tool_renders"- glb = stool_ctx.workspace.artifacts / "object.glb"- a = render_cache_dir(stool_ctx, glb, mode="shaded")- b = render_cache_dir(stool_ctx, glb, mode="clay")- assert a != b and a.is_dir() and a.parent == d.parent--def test_cached_render_glb_leaves_the_cache_to_render_glb(stool_ctx: ToolContext, monkeypatch: pytest.MonkeyPatch) -> None:- """One cache authority. ``tool_common`` used to short-circuit on its own- ``renderset.json`` marker keyed on the GLB's size+mtime, so a rebuild that landed on- the same stamp served stale PNGs and a copied workspace served views pointing into the- ORIGINAL one. ``render.render_glb`` (sha256 + CACHE_VERSION + rig signature) decides now.- """+ """``render.render_glb`` (content hash) is the one cache authority: a same-size, same-mtime rebuild re-renders."""import codeverse3d.spatial.tool_common as tcfrom codeverse3d.contracts.artifacts import RenderSet, RenderView@@ -152,10 +40,7 @@ def test_cached_render_glb_leaves_the_cache_to_render_glb(stool_ctx: ToolContextdef test_store_in_cache_survives_a_concurrent_identical_writer(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:- """The pid-only tmp name let two threads of one judge fan-out share a tmp dir: the- loser's cleanup deleted the winner's half-copied PNGs AFTER a successful render- (FileNotFoundError out of a call whose render had succeeded). Per-writer names +- tolerant rename: no exception, and the cache ends up complete."""+ """Two writers of one cache entry (a judge fan-out): no exception, and the cache ends up complete."""import shutilimport threadingimport time@@ -194,9 +79,7 @@ def test_store_in_cache_survives_a_concurrent_identical_writer(tmp_path: Path, mdef test_object_render_cache_is_keyed_by_gpu_mode(stool_glb: Path, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:- """gpu=on and gpu=off used to share one cache key, so a hit served the OTHER- backend's pixels and misreported RenderSet.renderer. The requested mode joins- the key ('auto' fragments from 'on'/'off' by design — owner default)."""+ """The requested GPU mode is part of the cache key: gpu=off is never served gpu=on's pixels."""from types import SimpleNamespacefrom codeverse3d.spatial import render as R@@ -244,4 +127,3 @@ def test_gl_metrics_summary_is_the_one_frame_stats_formatter(tmp_ws: Workspace,assert "fix:" not in "\n".join(no_hints)monkeypatch.setattr("codeverse3d.languages._gl_common.read_metrics", lambda ws: None)assert gl_metrics_summary(tmp_ws) == (["(no frame metrics)"], {}, True)-diff --git a/harness/tests/spatial_tools/test_sections.py b/harness/tests/spatial_tools/test_sections.pyindex 9e44ffbe..d29280e4 100644--- a/harness/tests/spatial_tools/test_sections.py+++ b/harness/tests/spatial_tools/test_sections.py@@ -11,20 +11,11 @@ from PIL import Imagefrom codeverse3d.spatial.sections import SliceManifest, cross_section, judge_slices-def test_cross_section_stool(stool_glb: Path, tmp_path: Path) -> None:- out = tmp_path / "sec.png"- o = cross_section(stool_glb, "y", 0.5, out)- assert o.ok and o.images == [str(out)] and out.is_file()- assert o.numbers["n_loops"] == 4- assert o.numbers["total_area_m2"] == pytest.approx(4 * 3.14159 * 0.02**2, rel=0.05)- assert set(o.numbers["parts_cut"]) == {"Leg_0", "Leg_1", "Leg_2", "Leg_3"}- assert "Plane axes: x horizontal, z vertical" in o.text--def test_cross_section_position_is_a_fraction_of_the_selected_parts(stool_glb: Path, tmp_path: Path) -> None:o = cross_section(stool_glb, "y", 0.5, tmp_path / "s.png", parts=["Seat"]) # the seat's own mid-planeassert o.ok and o.numbers["parts_cut"] == {"Seat": 1} and o.numbers["at_m"] == pytest.approx(0.43)assert o.numbers["total_area_m2"] == pytest.approx(0.16, rel=1e-3)+ assert "Plane axes: x horizontal, z vertical" in o.textdef test_cross_section_that_cuts_nothing_answers_without_an_image(tmp_path: Path) -> None:diff --git a/harness/tests/spatial_tools/test_silhouette.py b/harness/tests/spatial_tools/test_silhouette.pyindex 15ea9c15..c8f0a6ea 100644--- a/harness/tests/spatial_tools/test_silhouette.py+++ b/harness/tests/spatial_tools/test_silhouette.py@@ -15,18 +15,14 @@ def _disc(path: Path, size: tuple[int, int], box: tuple[int, int, int, int], bg=return path-def test_same_shape_different_framing(tmp_path: Path) -> None:+def test_iou_ignores_framing_but_not_aspect(tmp_path: Path) -> None:a = _disc(tmp_path / "a.png", (400, 300), (100, 50, 300, 250))b = _disc(tmp_path / "b.png", (512, 512), (56, 56, 456, 456), fg=(80, 20, 20))r = compare_silhouette(b, a, diff_png=tmp_path / "diff.png")assert r["iou"] > 0.95 and r["aspect_ratio_err"] < 0.02 and r["reliable"]assert (tmp_path / "diff.png").is_file()---def test_different_aspect(tmp_path: Path) -> None:- a = _disc(tmp_path / "a.png", (400, 400), (100, 100, 300, 300))- b = _disc(tmp_path / "b.png", (400, 400), (50, 150, 350, 250)) # wide ellipse- r = compare_silhouette(b, a)+ wide = _disc(tmp_path / "w.png", (400, 400), (50, 150, 350, 250))+ r = compare_silhouette(wide, _disc(tmp_path / "c.png", (400, 400), (100, 100, 300, 300)))assert r["aspect_ratio_err"] > 1.0 and r["iou"] < 0.8@@ -57,29 +53,17 @@ def test_unreliable_when_empty(tmp_path: Path) -> None:assert r["iou"] == 0.0 and not r["reliable"]-def test_a_photo_the_background_model_failed_on_is_unreliable(tmp_path: Path) -> None:- """A corner-to-corner mask is failed background segmentation, not a silhouette."""+def test_a_mask_that_fills_its_frame_is_failed_segmentation_but_a_tight_render_is_not(tmp_path: Path) -> None:+ """Bbox cover > 0.98 is failed background segmentation; a tightly cropped render (~0.9) still passes."""import numpy as np- from PIL import Imagefrom codeverse3d.spatial.silhouette import _bbox_cover- rng = np.random.default_rng(0)busy = tmp_path / "busy.jpg"- Image.fromarray(rng.integers(0, 255, (300, 400, 3), dtype=np.uint8)).save(busy)+ Image.fromarray(np.random.default_rng(0).integers(0, 255, (300, 400, 3), dtype=np.uint8)).save(busy)clean = _disc(tmp_path / "clean.png", (400, 300), (150, 90, 250, 210))-- assert _bbox_cover(foreground_mask(busy)) > 0.98, "a noise field localises nothing"- assert _bbox_cover(foreground_mask(clean)) < 0.98, "a disc on a flat backdrop does"+ assert _bbox_cover(foreground_mask(busy)) > 0.98assert compare_silhouette(clean, busy)["reliable"] is False- assert compare_silhouette(clean, clean)["reliable"] is True---def test_a_render_that_fills_its_frame_is_still_reliable(tmp_path: Path) -> None:- """The bar must not condemn the render side. Real single-view renders measured at- bbox coverage 0.60-0.69; a tight crop must still pass."""- from codeverse3d.spatial.silhouette import _bbox_cover-tight = _disc(tmp_path / "tight.png", (300, 300), (12, 12, 288, 288))assert 0.80 < _bbox_cover(foreground_mask(tight)) < 0.98assert compare_silhouette(tight, tight)["reliable"] is Truediff --git a/harness/tests/spatial_tools/test_tools.py b/harness/tests/spatial_tools/test_tools.pyindex a3fea681..00e1e0ea 100644--- a/harness/tests/spatial_tools/test_tools.py+++ b/harness/tests/spatial_tools/test_tools.py@@ -86,18 +86,6 @@ def test_connectivity_and_section_tools(stool_ctx: ToolContext) -> None:assert not obs.ok and "x|y|z" in obs.text-def test_check_contract_tool(stool_ctx: ToolContext) -> None:- obs = get_tool("check_contract").call(stool_ctx, {})- assert not obs.ok and "plan.json not found" in obs.text- plan = StaticPlan(object_name="Stool", summary="s", overall_bbox=BBox(center=(0, 0, 0.225), extents=(0.4, 0.4, 0.45)),- parts=[PartPlan(name="Seat", role="r", description="d", bbox=BBox(center=(0, 0, 0.43), extents=(0.4, 0.4, 0.04))),- PartPlan(name="Leg", role="r", description="d", bbox=BBox(center=(0, 0, 0.205), extents=(0.04, 0.04, 0.41)), instances=4),- PartPlan(name="Backrest", role="r", description="d", bbox=BBox(center=(0, 0.18, 0.6), extents=(0.4, 0.03, 0.3)))])- stool_ctx.workspace.write_json(stool_ctx.workspace.plan_path, plan)- obs = get_tool("check_contract").call(stool_ctx, {})- assert not obs.ok and "Backrest" in obs.text and "missing" in obs.text--# --------------------------------------------------------------------------- build with a fake runtimeclass _FakeRuntime:def __init__(self, *, lint_errors: bool = False, build_ok: bool = True, glb: Path | None = None, root: Path | None = None):@@ -148,19 +136,8 @@ def test_build_tool_failure_is_error_first(stool_ctx: ToolContext, monkeypatch:assert obs.numbers["error_line"] == 7-def test_build_tool_lint_blocks(stool_ctx: ToolContext, monkeypatch: pytest.MonkeyPatch) -> None:- _patch_runtime(monkeypatch, _FakeRuntime(lint_errors=True))- obs = get_tool("build").call(stool_ctx, {})- assert not obs.ok and obs.text.startswith("LINT FAILED") and "close the bracket" in obs.text- assert obs.numbers["stage"] == "lint"--def test_a_negative_verdict_is_not_a_tool_failure(stool_ctx: ToolContext, monkeypatch: pytest.MonkeyPatch) -> None:- """``ok`` is the VERDICT, ``failed`` is 'the tool could not run', and only ``failed``- reaches the model as an MCP error. Over 217 recorded gemini-cli sessions the old- ``is_error = not ok`` reported 63% of 1404 joint_sweep calls and 23% of 2073 builds as- broken calls, and the model retries a broken call at ~117k prompt tokens each. Both- directions here, plus the rule that makes it safe: the FAIL verdict LEADS the text."""+ """``ok`` is the verdict, ``failed`` is 'the tool could not run' (only that is an MCP error); FAIL leads the text."""import codeverse3d.spatial.tools as tsws = stool_ctx.workspace@@ -190,32 +167,15 @@ def test_a_negative_verdict_is_not_a_tool_failure(stool_ctx: ToolContext, monkeydef test_build_that_leaves_no_readable_glb_is_a_failure(stool_ctx: ToolContext, monkeypatch: pytest.MonkeyPatch) -> None:- """The runtime reported success and left nothing measurable: the tool could not- answer (a real error), and the headline must not read BUILD OK."""+ """Success with nothing measurable is a tool failure, and the headline must not read BUILD OK."""_patch_runtime(monkeypatch, _FakeRuntime(glb=stool_ctx.workspace.artifacts / "gone.glb"))obs = get_tool("build").call(stool_ctx, {})assert not obs.ok and obs.failedassert obs.text.startswith("BUILD PRODUCED NO USABLE GLB") and "GLB unreadable" in obs.text-def test_build_failure_refuses_stale_glb(stool_ctx: ToolContext, monkeypatch: pytest.MonkeyPatch) -> None:- """A failed build after a success: the old object.glb survives as evidence but- glb_path refuses to treat it as current (build.json says ok:false)."""- _patch_runtime(monkeypatch, _FakeRuntime(glb=stool_ctx.workspace.artifacts / "object.glb"))- assert get_tool("build").call(stool_ctx, {}).ok- assert get_tool("measure").call(stool_ctx, {}).ok # ok:true status → still usable- _patch_runtime(monkeypatch, _FakeRuntime(build_ok=False))- assert not get_tool("build").call(stool_ctx, {}).ok- assert json.loads((stool_ctx.workspace.artifacts / "build.json").read_text())["ok"] is False- assert (stool_ctx.workspace.artifacts / "object.glb").is_file() # evidence stays on disk- for name in ("measure", "render_views", "check_connectivity"):- obs = get_tool(name).call(stool_ctx, {})- assert not obs.ok and "build FAILED" in obs.text, name--def test_build_lint_fail_refuses_stale_glb(stool_ctx: ToolContext, monkeypatch: pytest.MonkeyPatch) -> None:- """A lint refusal is the latest build status: the previous build.json- (ok: true) + object.glb are no longer readable as current."""+ """A lint refusal is the latest build status: the previous GLB is no longer readable as current."""_patch_runtime(monkeypatch, _FakeRuntime(glb=stool_ctx.workspace.artifacts / "object.glb"))assert get_tool("build").call(stool_ctx, {}).ok_patch_runtime(monkeypatch, _FakeRuntime(lint_errors=True))@@ -227,13 +187,6 @@ def test_build_lint_fail_refuses_stale_glb(stool_ctx: ToolContext, monkeypatch:assert not obs.ok and "build FAILED" in obs.text-def test_hand_placed_glb_without_build_status_still_measures(stool_ctx: ToolContext) -> None:- """No build.json → glb_path stays permissive: first-measure flows and- hand-assembled (test/import) workspaces keep working."""- assert not (stool_ctx.workspace.artifacts / "build.json").exists()- assert get_tool("measure").call(stool_ctx, {}).ok--def _fake_render_glb(glb, out_dir, *, views=None, mode="shaded", width=768, height=768, isolate=None, explode=0.0, sheet=True, background="studio", **_):out_dir = Path(out_dir)out_dir.mkdir(parents=True, exist_ok=True)@@ -270,10 +223,7 @@ def test_render_views_cached(stool_ctx: ToolContext, fake_renderer) -> None:assert obs.numbers["views"] == ["front_right_high", "back_left_high", "front", "top"]assert "artifacts/tool_renders/r00_" in obs.text and str(stool_ctx.workspace.root) not in obs.textagain = get_tool("render_views").call(stool_ctx, {})- # same args → the same deterministic out_dir, which is what lets render_glb's OWN cache- # (sha256 of the glb + CACHE_VERSION + rig signature) skip the work. It is reached every- # time: tool_common used to keep a second size+mtime marker here and short-circuit above- # it, which served stale PNGs. This fake renderer has no cache, hence two calls.+ # same args → the same out_dir, where render_glb's own cache decides (this fake has none: two calls)assert again.images == obs.images and fake_renderer.calls == 2obs = get_tool("render_views").call(stool_ctx, {"views": ["front", "back", "left", "right", "top"]})assert obs.ok and len(obs.images) == 1 # > 4 views → sheet only@@ -281,15 +231,13 @@ def test_render_views_cached(stool_ctx: ToolContext, fake_renderer) -> None:assert not obs.ok and "front_right_high" in obs.textobs = get_tool("render_views").call(stool_ctx, {"mode": "xray"})assert not obs.ok and "shaded" in obs.text- # 'depth' was advertised from the first commit and never drawn by any renderer:- # a usage error with the mode list, not a RenderError from deep inside the rig+ # an unknown mode is a usage error with the mode list, not a RenderError from inside the rigobs = get_tool("render_views").call(stool_ctx, {"mode": "depth"})assert not obs.ok and "shaded" in obs.text and "failed" not in obs.textdef test_render_tool_with_no_view_is_a_tool_failure(stool_ctx: ToolContext, monkeypatch: pytest.MonkeyPatch) -> None:- """A renderer that comes back with nothing left the agent no picture and no verdict:- ``failed`` (an MCP error), not an ordinary result whose text happens to say '0 view(s)'."""+ """A renderer that returns nothing is ``failed`` (an MCP error), not a result saying '0 view(s)'."""import codeverse3d.spatial.render as rendermonkeypatch.setattr(render, "render_glb", lambda *a, **k: RenderSet(views=[], renderer="fake"))@@ -431,11 +379,7 @@ class _GlRuntime(_NoGlbRuntime):def test_gl_tools_lead_with_the_frame_gate_verdict(tmp_ws: Workspace, monkeypatch: pytest.MonkeyPatch) -> None:- """The shader compiled and the frames rendered, and the ``gl_frames`` gate still failed.- All three tools that print an "… OK" headline over that gate (``build`` on a graphics- workspace, ``gl_probe``, ``gl_frames``) must put the FAIL verdict ABOVE it — otherwise- the only verdict the model reads is "PROBE OK" — and none of them is a tool failure:- the code ran, and re-running it blind is exactly the retry this costs money."""+ """A failed ``gl_frames`` gate leads the text above every "… OK" headline, and is a verdict, not a tool failure."""import codeverse3d.languages._gl_common as gl_build # the one metrics readerfrom codeverse3d.spatial.frame_stats import FrameStat, SequenceStats@@ -457,17 +401,6 @@ def test_gl_tools_lead_with_the_frame_gate_verdict(tmp_ws: Workspace, monkeypatcassert obs.numbers["gate_errors"] == 1, name-def test_load_plan_recognises_graphics_plan(tmp_ws: Workspace) -> None:- from codeverse3d.contracts.plan import GraphicsPlan, PassPlan- from codeverse3d.spatial.tool_common import load_plan-- plan = GraphicsPlan(title="Neon rain", summary="s", style="cyberpunk",- passes=[PassPlan(name="Rain", description="drops")])- tmp_ws.write_json(tmp_ws.plan_path, plan)- loaded = load_plan(tmp_ws.plan_path)- assert isinstance(loaded, GraphicsPlan) and loaded.title == "Neon rain"--# --------------------------------------------------------------------------- the gate tools on a stooldef _stool_plan_with_missing_backrest() -> StaticPlan:return StaticPlan(object_name="Stool", summary="s", overall_bbox=BBox(center=(0, 0, 0.225), extents=(0.4, 0.4, 0.45)),@@ -477,10 +410,7 @@ def _stool_plan_with_missing_backrest() -> StaticPlan:def test_connectivity_tool_resolves_instance_names_like_the_track_does(stool_ctx: ToolContext) -> None:- """The plan says ``Leg`` attaches to ``Seat``; the GLB has ``Leg_0..3``. The tool used to- hand the gate the raw plan names, so the agent-facing ledger listed ``Leg`` under- planned_unresolved while the track's gate resolved it (965 of 2 666 raw names over 357- stored rounds, 2026-08-30). One resolver now: ``spatial.contract.planned_joins``."""+ """The tool resolves planned joins (``Leg`` → ``Leg_0..3``) through ``planned_joins``, as the track's gate does."""ws = stool_ctx.workspacews.write_json(ws.plan_path, StaticPlan(object_name="Stool", summary="s", overall_bbox=BBox(center=(0, 0, 0.225), extents=(0.4, 0.4, 0.45)),@@ -492,21 +422,3 @@ def test_connectivity_tool_resolves_instance_names_like_the_track_does(stool_ctxassert ledger["planned_unresolved"] == []assert {(a, b) for a, b, *_ in ledger["planned"]} == {(f"Leg_{i}", "Seat") for i in range(4)}assert {row[3] for row in ledger["planned"] if row[0] == "Leg_3"} == {"open"} # the 5 mm floating leg---def test_a_failed_build_tells_the_agent_WHY_not_to_build_again(tmp_ws):- """After a failed build the GLB is absent (staging publishes nothing), and the- old order reported 'does not exist yet — run `build` first' to an agent that had- just built: art_med_tool_chest burned its remaining turns on that (2026-08-27)."""- from codeverse3d.spatial.tool_common import ToolUsageError, glb_path-- ctx = ToolContext(workspace=tmp_ws, language="urdf_blender", track="articulated_object")- tmp_ws.artifacts.mkdir(parents=True, exist_ok=True)- tmp_ws.write_json(tmp_ws.artifacts / "build.json",- BuildResult(ok=False, language="urdf_blender", error_type="RestPenetration",- error_message="links interpenetrate by 140.0 mm at lid/base"))- with pytest.raises(ToolUsageError) as e:- glb_path(ctx)- msg = str(e.value)- assert "FAILED" in msg and "interpenetrate" in msg- assert "run `build` first" not in msg, "a build that ran and failed is not 'not built yet'"