Official Codebase of 3DCodeVerse
Python
tracks, record: four bugs — scene asset refine targets, a threejs fix reverted on soft findings, the brief cache ignoring config.yaml, graphics runs recorded at the wrong planner temperature
gaoypeng24459e837de6
diff --git a/harness/codeverse3d/record/telemetry.py b/harness/codeverse3d/record/telemetry.pyindex 7c7e6666..4e740f63 100644--- a/harness/codeverse3d/record/telemetry.py+++ b/harness/codeverse3d/record/telemetry.py@@ -85,12 +85,16 @@ def _judge_defaults() -> dict[str, Any]:"n_samples": _sig_default(init, "n_samples")}-def _planner_defaults() -> dict[str, Any]:+def _planner_defaults(record: RunRecord) -> dict[str, Any]:+ """The temperature THIS track plans at (``BaseTrack.plan_temperature``: graphics 0.5, the+ rest 0.4). ``planner.plan()``'s own default is never the one used — every track passes+ its own — so reading it reported 0.4 for every graphics run."""try:- from codeverse3d.tracks.planner import plan+ from codeverse3d.tracks import get_track++ return {"temperature": get_track(record.spec.track).plan_temperature}except Exception: # pragma: no coverreturn {}- return {"temperature": _sig_default(plan, "temperature")}def _generator_defaults(model_id: str) -> dict[str, Any]:@@ -128,7 +132,7 @@ def rubric_hash(name: str) -> str:def _role_settings(record: RunRecord) -> list[RoleSettings]:b = record.spec.backends- plan_d, judge_d = _planner_defaults(), _judge_defaults()+ plan_d, judge_d = _planner_defaults(record), _judge_defaults()spec: list[tuple[str, str, dict[str, Any]]] = [("planner", b.planner, plan_d),("generator", b.generator, _generator_defaults(b.generator)),diff --git a/harness/codeverse3d/tracks/planner.py b/harness/codeverse3d/tracks/planner.pyindex 73a8dfa1..081a6d2c 100644--- a/harness/codeverse3d/tracks/planner.py+++ b/harness/codeverse3d/tracks/planner.py@@ -19,7 +19,6 @@ from __future__ import annotationsimport hashlibimport jsonimport logging-import osimport refrom collections.abc import Callablefrom dataclasses import dataclass@@ -61,8 +60,10 @@ def brief_enabled(spec: Spec, *, default: bool = True) -> bool:def brief_cache_dir() -> Path:- root = os.environ.get("C3D_CACHE_DIR") or (Path.home() / ".cache" / "codeverse3d")- return Path(root) / "briefs"+ """``Settings.cache_dir``/briefs: ``C3D_CACHE_DIR`` AND the config file's ``cache_dir:``."""+ from codeverse3d.config import get_settings++ return get_settings().cache_dir / "briefs"def _reference_digest(spec: Spec) -> list[dict[str, str]]:diff --git a/harness/codeverse3d/tracks/prompting.py b/harness/codeverse3d/tracks/prompting.pyindex d2ad94f5..92968935 100644--- a/harness/codeverse3d/tracks/prompting.py+++ b/harness/codeverse3d/tracks/prompting.py@@ -658,8 +658,11 @@ def file_for_target_factory(ctx: RunContext):return _per_partif lang is Language.SCENE_THREEJS:- zones = {to_snake(z.name) for z in (getattr(plan, "zones", None) or [])}- assets = {to_snake(a.name) for a in (getattr(plan, "assets", None) or [])}+ zone_plans = list(getattr(plan, "zones", None) or [])+ zones = {to_snake(z.name) for z in zone_plans}+ assets = {to_snake(a.name): a.kind for a in (getattr(plan, "assets", None) or [])}+ # a merged asset's own file is only the variant shim: the geometry is its survivor's+ alias = {to_snake(k): to_snake(v) for k, v in (ctx.extra.get("asset_alias") or {}).items()}cameras = {to_snake(c.name) for c in (getattr(plan, "cameras", None) or [])}def _scene(target: str) -> list[str]:@@ -667,7 +670,11 @@ def file_for_target_factory(ctx: RunContext):if key in zones:return [f"src/zones/{key}.js"]if key in assets:- return [f"src/assets/{key}.js"]+ if assets[key] == "threejs":+ return [f"src/assets/{alias.get(key, key)}.js"]+ # a hero is public/assets/<snake>.glb, built in its own sub-workspace: the scene+ # fixes it where it is placed — the zones that list it — else as a whole+ return [f"src/zones/{to_snake(z.name)}.js" for z in zone_plans if key in {to_snake(c) for c in z.contents}]if key in cameras or key in ("camera", "cameras", "composition"):return ["src/scene.js"]if key in ("env", "environment", "lighting", "sky", "fog", "ground", "water", "light"):diff --git a/harness/codeverse3d/tracks/scene_assets.py b/harness/codeverse3d/tracks/scene_assets.pyindex 55a5ec81..03670f32 100644--- a/harness/codeverse3d/tracks/scene_assets.py+++ b/harness/codeverse3d/tracks/scene_assets.py@@ -248,11 +248,12 @@ def build_threejs_asset(ctx: RunContext, asset: AssetPlan, *, judge: bool) -> Asrender_asset = getattr(ctx.runtime, "render_asset", None)if ok and callable(render_asset) and _judge_wanted(ctx, asset, chk, judge=judge):def _after_fix(gen: RunContext) -> bool:- # a fix that breaks the module makes it NOT AVAILABLE — the zones must not import it+ # a fix that breaks the module makes it NOT AVAILABLE — the zones must not import it;+ # a SOFT finding (size, tris) is no reason to revert a fix that imports (the hero's rule)c = check(ctx)if c.ran and c.fatal:result.ok, result.path = False, ""- return c.ok+ return not (c.ran and c.fatal)def _snapshot() -> Callable[[], None]:before = (ctx.ws.root / rel).read_text()diff --git a/harness/docs/RUN_LAYOUT.md b/harness/docs/RUN_LAYOUT.mdindex 1172f8d0..8b6882f8 100644--- a/harness/docs/RUN_LAYOUT.md+++ b/harness/docs/RUN_LAYOUT.md@@ -99,7 +99,7 @@ the packager produces no diff.hashes; tool versions (python, blender, node, three, chrome, puppeteer);harness version + git sha; key-pool size; **price-table hash**; resolvedrender and limit settings. Sampling values are read from the call sites'- typed defaults (`VlmJudge.__init__`, `planner.plan`, and+ typed defaults (`VlmJudge.__init__`, the track's `plan_temperature`, and`record/telemetry.py::_generator_defaults` — a historical shim thatconfigures nothing, kept so old records still read back); avalue a call site hard-codes per task is left empty with `source` saying so,diff --git a/harness/tests/flywheel_cli/test_run_layout_cli.py b/harness/tests/flywheel_cli/test_run_layout_cli.pyindex 8b4b9cde..3eef911c 100644--- a/harness/tests/flywheel_cli/test_run_layout_cli.py+++ b/harness/tests/flywheel_cli/test_run_layout_cli.py@@ -140,6 +140,18 @@ def test_telemetry_handles_reconstructed_live_and_unavailable_ledgers(fake_run,assert tele.cost.n_calls == 0 and tele.settings is not None # settings never depend on the ledger+def test_the_settings_snapshot_records_the_temperature_the_track_planned_at(tmp_path):+ """The planner row reported ``planner.plan()``'s default 0.4 for every run — a default+ no track uses: each passes its own ``plan_temperature``, and graphics plans at 0.5."""+ from codeverse3d.contracts.common import Language+ from codeverse3d.record.telemetry import settings_snapshot++ for language, want in ((Language.GLSL_SHADER, 0.5), (Language.BLENDER, 0.4)):+ _ws, rec = make_fake_run(tmp_path / language.value, language=language)+ planner = next(r for r in settings_snapshot(rec).roles if r.role == "planner")+ assert (planner.temperature, planner.source) == (want, "default"), language++def test_rejected_texture_pass_is_not_delivered_or_linked(fake_run):"""Belt and braces: a stray canonical object_textured.glb from a rejected passis skipped by the deliverable AND by the gallery links (both gate on shipped)."""diff --git a/harness/tests/orchestrator_tracks/test_asset_alias_note.py b/harness/tests/orchestrator_tracks/test_asset_alias_note.pyindex 19941f97..84f8c292 100644--- a/harness/tests/orchestrator_tracks/test_asset_alias_note.py+++ b/harness/tests/orchestrator_tracks/test_asset_alias_note.py@@ -17,3 +17,27 @@ def test_the_note_round_trips_and_an_empty_map_is_still_a_note(tmp_ws):assert read_dedupe_note(tmp_ws) == {"SteppingStone": "PondRock"}write_dedupe_note(tmp_ws, {})assert read_dedupe_note(tmp_ws) == {}, "a stage that merged nothing says so (not None)"+++def test_a_refine_target_routes_to_the_file_that_really_holds_the_asset():+ """Every asset target used to map to ``src/assets/<snake>.js``. The skeleton writes+ that file only for a three.js asset: a merged asset's is the variant shim onto its+ survivor, and a blender hero ships as ``public/assets/<snake>.glb`` — so a refine+ session could "succeed" editing a file nothing imports."""+ from types import SimpleNamespace++ from codeverse3d.contracts.common import Language, Track+ from codeverse3d.contracts.plan import ScenePlan+ from codeverse3d.tracks.planner import plan_example+ from codeverse3d.tracks.prompting import file_for_target_factory++ plan = ScenePlan.model_validate(plan_example(Track.SCENE)) # Quay places Bollard and Crate (the hero)+ plan.assets.append(next(a for a in plan.assets if a.name == "Bollard").model_copy(update={"name": "Mooring"}))+ ctx = SimpleNamespace(plan=plan, language=Language.SCENE_THREEJS, runtime=SimpleNamespace(),+ extra={"asset_alias": {"Mooring": "Bollard"}})+ files_for = file_for_target_factory(ctx)+ assert files_for("Bollard") == ["src/assets/bollard.js"]+ assert files_for("Mooring") == ["src/assets/bollard.js"], "the survivor's factory, not the shim"+ assert files_for("Crate") == ["src/zones/quay.js"], "a hero is fixed where it is placed"+ plan.zones = [z for z in plan.zones if z.name != "Quay"]+ assert file_for_target_factory(ctx)("Crate") == [], "placed nowhere: a whole-scene task"diff --git a/harness/tests/orchestrator_tracks/test_planner_depth.py b/harness/tests/orchestrator_tracks/test_planner_depth.pyindex 921f69a2..413a9463 100644--- a/harness/tests/orchestrator_tracks/test_planner_depth.py+++ b/harness/tests/orchestrator_tracks/test_planner_depth.py@@ -209,6 +209,19 @@ def test_brief_is_cached_by_prompt_hash_and_the_second_call_is_free(tmp_path):assert calls["n"] == 2+def test_the_brief_cache_follows_the_config_files_cache_dir(tmp_path, monkeypatch):+ """``brief_cache_dir()`` read only $C3D_CACHE_DIR, so a ``cache_dir:`` set in+ 3dcodeverse.yaml moved every cache but this one — the briefs stayed in ~/.cache."""+ from codeverse3d.config import get_settings++ for env in ("C3D_CACHE_DIR", "CV3D_CACHE_DIR"):+ monkeypatch.delenv(env, raising=False)+ monkeypatch.chdir(tmp_path)+ (tmp_path / "3dcodeverse.yaml").write_text(f"cache_dir: {tmp_path / 'cfg-cache'}\n")+ get_settings.cache_clear()+ assert BR.brief_cache_dir() == tmp_path / "cfg-cache" / "briefs"++def test_reference_images_are_part_of_the_brief_cache_key(tmp_path):"""RS-4: expand_brief attaches spec.references and tells the model to read thedimensions off them, so a key that omits them let an --image run silentlydiff --git a/harness/tests/orchestrator_tracks/test_scene_hero_ladder.py b/harness/tests/orchestrator_tracks/test_scene_hero_ladder.pyindex 798abaf6..df909739 100644--- a/harness/tests/orchestrator_tracks/test_scene_hero_ladder.py+++ b/harness/tests/orchestrator_tracks/test_scene_hero_ladder.py@@ -339,3 +339,25 @@ def test_a_thin_hero_plan_is_asked_again_with_the_sheets_features_as_the_checkliassert thin[0]["n_parts"] == 1 and "a hinged lid" in thin[0]["features"]plan = json.loads((tmp_ws.root / "_assets" / SA.to_snake(hero.name) / "plan.json").read_text())assert len(plan["parts"]) > 1+++def test_a_threejs_fix_with_only_soft_findings_is_kept_and_judged_again(tmp_ws, settings, monkeypatch):+ """The three.js ``_after_fix`` returned ``check.ok``, which is False on a SOFT finding+ too (size off, too many triangles), so ``_judge_and_fix`` reverted a fix that imports+ fine and never judged it. A fix is undone only when the module no longer imports —+ the rule the hero's ``_after_fix`` (a successful build) already applied."""+ from codeverse3d.contracts.artifacts import RenderSet++ boat = "src/assets/fishing_boat.js"+ ctx, _hero = _scene(tmp_ws, settings, services=CardedServices(judge=FakeJudge(scores=(0.5, 0.7))),+ agent=FakeAgent(lambda job, ws: {boat: f"// {job.label}\n"}))+ asset = next(a for a in ctx.plan.assets if a.name == "FishingBoat")+ ctx.runtime.render_asset = lambda ws, name, out_dir: RenderSet(views=[]) # a verdict is possible+ checks = iter([SA.AssetCheck(ok=True, ran=True, tris=900, meshes=3, materials=2), # the generated module+ SA.AssetCheck(ok=False, ran=True, fatal=False, # the fix: soft finding only+ errors=["measured w=20.00 m but the plan says 8.00 m — rescale"])])+ monkeypatch.setattr(SA, "check_threejs_asset", lambda *a, **k: next(checks))+ monkeypatch.setattr(SA, "_judge_wanted", lambda *a, **k: True)+ res = SA.build_threejs_asset(ctx, asset, judge=True)+ assert res.ok and res.fixed and (res.score_before, res.score) == (0.5, 0.7)+ assert (tmp_ws.root / boat).read_text() == "// asset_fishing_boat_fix\n", "the fix that imports is kept"