Official Codebase of 3DCodeVerse
Python
render: refuse to publish a round the working tree is not at
gaoypengfa5a1aa3c95b
diff --git a/harness/codeverse/cli/main.py b/harness/codeverse/cli/main.pyindex 6d259dc6..3bdec569 100644--- a/harness/codeverse/cli/main.py+++ b/harness/codeverse/cli/main.py@@ -565,7 +565,7 @@ def render("""Render the current artifact (object.glb or the scene) with the canonical rig."""ws = C.open_workspace(slug, runs_dir)spec = C.load_spec(ws)- idx = round_index if round_index is not None else _latest_round(ws)+ idx = _render_round_or_refuse(ws, round_index)out_dir = out or ws.renders_dir(idx) / ("cli" if mode == "shaded" else f"cli_{mode}")if spec.track is Track.GRAPHICS:_render_graphics(ws, spec, out_dir)@@ -698,6 +698,56 @@ def _render_graphics(ws, spec: Spec, out_dir: Path) -> None:)+def _render_round_or_refuse(ws, round_index: int | None) -> int:+ """Which round this render is labelled as — refusing when the label would lie.++ ``render`` renders the WORKING TREE, which sits at the last round the run wrote.+ ``--round`` only chose the output folder, so `3dcv render X --round 3` wrote+ r03-labelled images of round 4's code, and with no flag at all a run whose best round+ was not its last silently published its worst one.++ Measured 2026-08-25 on tsr_scn_neon_alley: judge by round 0.338 / 0.375 / 0.529 /+ 0.632 / 0.000 — round 4 rendered completely blank, all eight tiles empty. The harness+ correctly kept r3 and the deliverable is correct, but the tree was left at r4, so a+ plain `3dcv render` re-rendered eight blank frames and was very nearly shipped.++ So: no flag renders the tree only when the tree IS the best round; otherwise this+ refuses and points at ``deliverable/``, which already holds the best round's code,+ sheet and a manifest naming the commit. Rendering a round other than the tree's would+ need that round checked out, which this command does not do — hence a refusal rather+ than a mislabelled image.+ """+ tree = _latest_round(ws)+ best = _best_round_of_record(ws)+ if round_index is not None:+ if round_index != tree:+ raise C.CliError(+ f"cannot render round {round_index}: `render` renders the working tree, which is at "+ f"round {tree}, and --round only labels the output folder. The best round's code, "+ f"renders and manifest are already packaged in {ws.deliverable} — read "+ f"{ws.deliverable / 'sheet.png'}, or `3dcv resume {ws.root.name}` to keep iterating.",+ code=2)+ return round_index+ if best is not None and best != tree:+ raise C.CliError(+ f"refusing to render: this run's BEST round is r{best} but the working tree is at "+ f"r{tree}, so this would render the wrong round — and r{tree} may be why it was not "+ f"chosen. Read {ws.deliverable / 'sheet.png'} (the packaged best round), or pass "+ f"--round {tree} to render the tree anyway.",+ code=2)+ return tree+++def _best_round_of_record(ws) -> int | None:+ """``record.best_round``, or None when there is no readable record yet."""+ try:+ rec = json.loads(ws.record_path.read_text())+ except (OSError, ValueError, AttributeError):+ return None+ best = rec.get("best_round")+ return best if isinstance(best, int) else None++def _latest_round(ws) -> int:rdir = ws.artifacts / "renders"idxs = (diff --git a/harness/tests/flywheel_cli/test_cli.py b/harness/tests/flywheel_cli/test_cli.pyindex 8174b3e0..811cd93b 100644--- a/harness/tests/flywheel_cli/test_cli.py+++ b/harness/tests/flywheel_cli/test_cli.py@@ -446,3 +446,59 @@ def test_texture_is_not_offered_on_tracks_that_have_no_glb(tmp_path: Path):stale = Spec.model_validate(json.loads((runs / "objq" / "spec.json").read_text()))assert texture_requested(stale)assert not texture_requested(stale.model_copy(update={"track": Track.GRAPHICS}))+++# --------------------------------------------------- render must not publish the wrong round+def _round_guard_ws(tmp_path: Path, *, best: int, tree: int):+ """A workspace whose record names `best` while the render tree sits at `tree`."""+ import json as _json++ from codeverse.workspace import Workspace++ ws = Workspace(tmp_path / "wronground")+ ws.create()+ for i in range(tree + 1):+ (ws.artifacts / "renders" / f"r{i:02d}").mkdir(parents=True, exist_ok=True)+ ws.record_path.write_text(_json.dumps({"best_round": best}))+ return ws+++def test_render_refuses_when_the_tree_is_not_the_best_round(tmp_path: Path):+ """`render` renders the WORKING TREE, and a run's tree sits at its LAST round — which+ is not always its best. Measured 2026-08-25 on tsr_scn_neon_alley: judge by round+ 0.338 / 0.375 / 0.529 / 0.632 / 0.000, round 4 rendering eight completely blank tiles.+ The harness correctly kept r3, but a plain `3dcv render` re-rendered the blank r4 and+ was very nearly published."""+ from codeverse.cli._common import CliError+ from codeverse.cli.main import _render_round_or_refuse++ ws = _round_guard_ws(tmp_path, best=3, tree=4)+ with pytest.raises(CliError) as ei:+ _render_round_or_refuse(ws, None)+ msg = str(ei.value)+ assert "BEST round is r3" in msg and "working tree is at r4" in msg+ assert "deliverable" in msg, "it must point at the packaged best round"+ assert "--round 4" in msg, "and offer the explicit escape"+ assert ei.value.exit_code == 2+++def test_render_round_flag_cannot_mislabel_another_rounds_code(tmp_path: Path):+ """--round only chose the OUTPUT FOLDER, so `render X --round 3` wrote r03-labelled+ images of round 4's code. Refuse rather than write a picture whose label is a lie."""+ from codeverse.cli._common import CliError+ from codeverse.cli.main import _render_round_or_refuse++ ws = _round_guard_ws(tmp_path, best=3, tree=4)+ with pytest.raises(CliError):+ _render_round_or_refuse(ws, 3)+ assert _render_round_or_refuse(ws, 4) == 4, "rendering the tree's own round is fine"+++def test_render_is_unaffected_when_the_best_round_is_the_last(tmp_path: Path):+ """The common case must not become noisier: no record, or best == tree, just renders."""+ from codeverse.cli.main import _render_round_or_refuse++ assert _render_round_or_refuse(_round_guard_ws(tmp_path / "a", best=2, tree=2), None) == 2+ ws = _round_guard_ws(tmp_path / "b", best=1, tree=1)+ ws.record_path.unlink() # a run that has not written a record yet+ assert _render_round_or_refuse(ws, None) == 1