Official Codebase of 3DCodeVerse
Python
tests: scene, render — fold twin renders and retries, make two always-true asserts real
gaoypengb713eadfe361
diff --git a/harness/tests/scene_gates/test_placement.py b/harness/tests/scene_gates/test_placement.pyindex e945a39d..07ba37c0 100644--- a/harness/tests/scene_gates/test_placement.py+++ b/harness/tests/scene_gates/test_placement.py@@ -259,7 +259,7 @@ def test_a_wrapper_of_instances_is_scale_checked_as_one_instance():scale = [f for f in placement_gate_safe(census, plan=plan).findings if f.data.get("kind") == "scale"]assert len(scale) == 1 and scale[0].data["instances"] == 12assert scale[0].message.startswith("each of the 12 picket_fence instances in Yard/PicketFences measures 9.60 m")- assert scale[0].data["fix_hint"].startswith("scale each picket_fence") if "fix_hint" in scale[0].data else True+ assert scale[0].fix_hint.startswith("scale each picket_fence")def test_the_typed_interior_flag_wins_over_the_setting_words():diff --git a/harness/tests/scene_gates/test_scene_textures_stage.py b/harness/tests/scene_gates/test_scene_textures_stage.pyindex 6dde03fe..f9e586b8 100644--- a/harness/tests/scene_gates/test_scene_textures_stage.py+++ b/harness/tests/scene_gates/test_scene_textures_stage.py@@ -144,28 +144,3 @@ def test_the_pack_has_the_last_word_over_the_recipes(template: str):out = _render(template, textures="TEXTURE_BLOCK_MARKER", recipes="RECIPE_MARKER")assert out.index("RECIPE_MARKER") < out.index("TEXTURE_BLOCK_MARKER")--def test_the_stage_writes_the_pack_and_books_nothing_itself(monkeypatch, tmp_path):- """The pack is paid for through the metered image and chat models: its money is on the- run's ledger (the only record of it), and the stage has no second book to keep — a- context with no budget at all is enough."""- from types import SimpleNamespace-- import codeverse3d.reference as reference- import codeverse3d.texturing.plan as plan_mod- import codeverse3d.tracks.scene as S- from codeverse3d.contracts.common import Usage-- usage = Usage(cost_usd=0.07)- pack = SimpleNamespace(manifest=lambda: MANIFEST, usage=usage, source="vlm")- monkeypatch.setattr(plan_mod, "scene_texture_pack", lambda *a, **k: pack)- monkeypatch.setattr(reference, "_image_model", lambda _m: None)-- ctx = SimpleNamespace(- plan=None,- ws=SimpleNamespace(public=tmp_path / "public", commit=lambda *_a, **_k: None),- spec=SimpleNamespace(backends=SimpleNamespace(planner=None)),- settings=SimpleNamespace(cache_dir=tmp_path / "cache"),- events=SimpleNamespace(emit=lambda *a, **k: None),- )- assert S.SceneTrack()._textures_stage(ctx) == MANIFEST # type: ignore[arg-type]diff --git a/harness/tests/scene_runtime/test_lint.py b/harness/tests/scene_runtime/test_lint.pyindex f437684b..224fcf78 100644--- a/harness/tests/scene_runtime/test_lint.py+++ b/harness/tests/scene_runtime/test_lint.py@@ -49,7 +49,7 @@ def test_forbidden_imports_and_globals(ws):errs = _msgs(rep, Severity.ERROR)text = " | ".join(m for _, m in errs)assert "import 'gsap' is not allowed" in text- assert "https://unpkg.com" in text or "not allowed" in text+ assert "https://unpkg.com" in textassert "missing file './missing.js'" in textassert "requestAnimationFrame" in textassert "creating a renderer" in textdiff --git a/harness/tests/scene_runtime/test_post.py b/harness/tests/scene_runtime/test_post.pyindex a850899c..bc4bdcba 100644--- a/harness/tests/scene_runtime/test_post.py+++ b/harness/tests/scene_runtime/test_post.py@@ -16,7 +16,6 @@ the SAME scene:from __future__ import annotations-import jsonfrom pathlib import Pathimport numpy as np@@ -117,7 +116,11 @@ def test_bloom_is_selective_not_a_brightness_threshold(tmp_path):p_raw, p_post = render(plain, tmp_path / "p_raw", "--no-post"), render(plain, tmp_path / "p_post")assert read_json_or_none(tmp_path / "e_post" / "metrics.json")["census"]["post"]["bloom_sources"] >= 1- assert read_json_or_none(tmp_path / "p_post" / "metrics.json")["census"]["post"]["bloom_sources"] == 0+ post = read_json_or_none(tmp_path / "p_post" / "metrics.json")["census"]["post"]+ assert post["bloom_sources"] == 0+ # an ungraded scene reports a neutral grade; --no-post leaves the chain off+ assert post["enabled"] is True and post["grade_neutral"] is True and post["warnings"] == []+ assert read_json_or_none(tmp_path / "p_raw" / "metrics.json")["census"]["post"] == {"enabled": False}assert mean_lum(e_post) - mean_lum(e_raw) > 0.004, "emissive box did not bloom"assert abs(mean_lum(p_post) - mean_lum(p_raw)) < 0.005, "a merely bright box must not bloom"@@ -135,23 +138,3 @@ def test_scene_grade_hint_reaches_the_shader_and_is_clamped(tmp_path):assert grade["exposure"] == 8.0 # clamped from 99assert grade["warmth"] == pytest.approx(0.4)assert read_json_or_none(out / "metrics.json")["census"]["post"]["grade_neutral"] is False---@needs_node-@needs_browser-def test_no_post_leaves_the_chain_off(tmp_path):- ws = make_ws(tmp_path, "off", BRIGHT)- out = tmp_path / "off_out"- render(ws, out, "--no-post")- assert read_json_or_none(out / "metrics.json")["census"]["post"] == {"enabled": False}---@needs_node-@needs_browser-def test_ungraded_scene_reports_a_neutral_grade(tmp_path):- ws = make_ws(tmp_path, "ungraded", BRIGHT)- out = tmp_path / "ungraded_out"- render(ws, out)- post = read_json_or_none(out / "metrics.json")["census"]["post"]- assert post["enabled"] is True and post["grade_neutral"] is True- assert post["warnings"] == [] and json.dumps(post) # serialisable into metrics.jsondiff --git a/harness/tests/scene_runtime/test_render_scene.py b/harness/tests/scene_runtime/test_render_scene.pyindex d03b03a0..feedfe21 100644--- a/harness/tests/scene_runtime/test_render_scene.py+++ b/harness/tests/scene_runtime/test_render_scene.py@@ -308,8 +308,6 @@ def test_every_driver_invocation_carries_the_env_flags(monkeypatch, switch, ws,monkeypatch.delenv(k, raising=False)# defaults: camera repair ON everywhere, settle on (no flag), exposure off- probes_mod.probe_scene(ws)- assert _flags(captured["probe_scene.mjs"]) == ["--camera-repair"]probes_mod.run_probe(ws, compile=True, timeout_s=5.0)assert _flags(captured["probe_scene.mjs"]) == ["--camera-repair"], "combined build lost the default-ON policy"with pytest.raises(SceneRenderError):@@ -322,5 +320,3 @@ def test_every_driver_invocation_carries_the_env_flags(monkeypatch, switch, ws,switch("C3D_CAMERA_REPAIR", "false")probes_mod.run_probe(ws, compile=True, timeout_s=5.0)assert _flags(captured["probe_scene.mjs"]) == ["--no-settle"]- probes_mod.probe_scene(ws)- assert _flags(captured["probe_scene.mjs"]) == ["--no-settle"]diff --git a/harness/tests/scene_runtime/test_scene_driver_retry.py b/harness/tests/scene_runtime/test_scene_driver_retry.pyindex e9c514df..39872d34 100644--- a/harness/tests/scene_runtime/test_scene_driver_retry.py+++ b/harness/tests/scene_runtime/test_scene_driver_retry.py@@ -47,14 +47,6 @@ def test_a_lost_browser_is_retried_on_an_owned_browser(monkeypatch):assert envs[1]["C3D_BROWSER_REUSE"] == "off", "the retry must not reuse the browser that died"-def test_a_scene_that_failed_is_not_retried(monkeypatch):- """Exit 1 is a verdict about the scene — console errors, a scene that did not- boot — not a driver failure. Re-rendering it would only spend the time again."""- envs = _record(monkeypatch, [_result(1, {"ok": False, "error": "scene did not boot"})])- r = run_scene_script("render_scene.mjs", ["--ws", "x"], timeout_s=10)- assert r.rc == 1 and len(envs) == 1--def test_a_driver_error_that_is_not_a_browser_loss_is_not_retried(monkeypatch):envs = _record(monkeypatch, [_result(2, {"ok": False, "error": "--ws and --out are required"})])with pytest.raises(SceneRenderError, match="--ws and --out are required"):@@ -88,11 +80,13 @@ def test_a_driver_that_exits_0_with_no_summary_is_retried(monkeypatch):def test_a_driver_that_answered_is_not_retried_for_a_failing_verdict(monkeypatch):- """Exit 1 WITH a summary is a scene that failed — a verdict, and complete."""+ """Exit 1 WITH a summary is a scene that failed — console errors, a scene that did not+ boot — a verdict, and complete, not a driver failure. Re-rendering it would only+ spend the time again."""envs = _record(monkeypatch, [_result(1, {"ok": False, "boot": {"ok": False, "stage": "createScene","error": "TypeError: x is not a function"}})])r = run_scene_script("probe_scene.mjs", ["--ws", "x"], timeout_s=10)- assert r.summary["boot"]["stage"] == "createScene" and len(envs) == 1+ assert r.rc == 1 and r.summary["boot"]["stage"] == "createScene" and len(envs) == 1def test_a_transient_host_failure_is_retried_on_the_same_browser(monkeypatch):diff --git a/harness/tests/threejs_render/test_build.py b/harness/tests/threejs_render/test_build.pyindex 4b7a9e54..9f28819a 100644--- a/harness/tests/threejs_render/test_build.py+++ b/harness/tests/threejs_render/test_build.py@@ -84,7 +84,7 @@ def test_build_keeps_source_placement_and_warns(stool_ws: Workspace):p = stool_ws.src / "object.js"p.write_text(p.read_text().replace("return root;", "root.position.set(0.5, 0.2, 0); return root;"))res = ThreeJsRuntime().build(stool_ws)- assert res.ok and "normalised_offset" not in res.census+ assert res.okoff = res.census["placement_offset"]assert off is not None and abs(off[0] + 0.5) < 1e-4 and abs(off[1] + 0.2) < 1e-4assert any("off ground/centre" in w and "exported as authored" in w for w in res.census["warnings"])diff --git a/harness/tests/threejs_render/test_cli_flush.py b/harness/tests/threejs_render/test_cli_flush.pyindex 567ea569..24362c16 100644--- a/harness/tests/threejs_render/test_cli_flush.py+++ b/harness/tests/threejs_render/test_cli_flush.py@@ -44,7 +44,3 @@ def test_a_large_summary_survives_the_pipe(tmp_path, code: int):assert res.last_json is not None, "the summary was truncated mid-JSON"assert res.last_json["tail"] == "LAST" and len(res.last_json["blob"]) == PAYLOAD_BYTES--def test_a_small_summary_still_works(tmp_path):- res = run_node(_driver(tmp_path, 10, 0), [], timeout_s=60, check=False)- assert res.rc == 0 and res.last_json["tail"] == "LAST"diff --git a/harness/tests/threejs_render/test_render_retry.py b/harness/tests/threejs_render/test_render_retry.pyindex d1541d13..d2fce115 100644--- a/harness/tests/threejs_render/test_render_retry.py+++ b/harness/tests/threejs_render/test_render_retry.py@@ -27,18 +27,19 @@ def _glb(tmp_path: Path) -> Path:return p-def test_transient_failure_is_retried_with_double_timeout(tmp_path, monkeypatch):- calls: list[float] = []+def test_transient_failure_is_retried_with_double_timeout_on_the_shared_browser(tmp_path, monkeypatch):+ calls: list[tuple[float, bool]] = []def fake(glb, out_dir, params, *, gpu, timeout_s, own_browser=False):- calls.append(timeout_s)+ calls.append((timeout_s, own_browser))if len(calls) == 1:- raise RenderError("render_glb failed: node script render_glb.mjs exited 1: Waiting failed")+ raise RenderError("render_glb failed: node script render_glb.mjs exited 1: Waiting failed: 30000 ms exceeded")return {"views": [], "renderer": "fake", "duration_ms": 1}monkeypatch.setattr(R, "_run_render", fake)rs = render_glb(_glb(tmp_path), tmp_path / "out", use_cache=False, timeout_s=100)- assert rs.renderer == "fake" and calls == [100, 200]+ # a slow box is not a reason to give up browser reuse+ assert rs.renderer == "fake" and calls == [(100, False), (200, False)]def test_real_failure_is_not_retried(tmp_path, monkeypatch):@@ -75,16 +76,3 @@ def test_a_lost_browser_is_retried_on_a_browser_of_our_own(tmp_path, monkeypatchassert rs.renderer == "fake"assert seen == [False, True], "the retry must not go back to the browser that just died"--def test_a_transient_that_is_not_a_browser_loss_keeps_the_shared_browser(tmp_path, monkeypatch):- seen: list[bool] = []-- def fake(glb, out_dir, params, *, gpu, timeout_s, own_browser=False):- seen.append(own_browser)- if len(seen) == 1:- raise RenderError("render_glb failed: Waiting failed: 30000 ms exceeded")- return {"views": [], "renderer": "fake", "duration_ms": 1}-- monkeypatch.setattr(R, "_run_render", fake)- render_glb(_glb(tmp_path), tmp_path / "out", use_cache=False, timeout_s=100)- assert seen == [False, False], "a slow box is not a reason to give up browser reuse"