Official Codebase of 3DCodeVerse
Python
cli: render, judge and resume refuse damaged or unsupported input with a typed error
gaoypengdfee1f4cf510
diff --git a/harness/codeverse3d/cli/inspect_cmd.py b/harness/codeverse3d/cli/inspect_cmd.pyindex 5fb4f636..7db7b1dc 100644--- a/harness/codeverse3d/cli/inspect_cmd.py+++ b/harness/codeverse3d/cli/inspect_cmd.py@@ -18,6 +18,7 @@ import typerfrom codeverse3d.cli import _common as Cfrom codeverse3d.cli._common import RunsDirOpt, console, kv_tablefrom codeverse3d.config import get_settings+from codeverse3d.contracts.artifacts import RENDER_MODESfrom codeverse3d.contracts.common import Trackfrom codeverse3d.contracts.spec import Spec@@ -43,6 +44,10 @@ 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)+ if mode not in RENDER_MODES:+ raise C.CliError(f"--mode must be one of {' | '.join(RENDER_MODES)}, not {mode!r}", code=2)+ if mode != "shaded" and spec.track in (Track.SCENE, Track.GRAPHICS): # was silently rendered shaded+ raise C.CliError(f"--mode {mode} is for object runs; a {spec.track.value} run renders shaded only", code=2)idx = _render_round_or_refuse(ws, round_index)out_dir = out or ws.renders_dir(idx) / ("cli" if mode == "shaded" else f"cli_{mode}")# writes into the run (a graphics render even rebuilds it): one writer per run dir@@ -95,10 +100,13 @@ def judge(artifacts/judge/rNN_cli.json."""from codeverse3d.addons import selectfrom codeverse3d.cli import _judge as J- from codeverse3d.record.record import load_record+ from codeverse3d.record.record import RecordError, load_recordws = C.open_workspace(slug, runs_dir)- rec = load_record(ws)+ try:+ rec = load_record(ws)+ except RecordError as e:+ raise C.CliError(str(e), code=2) from epicked = select.pick(ws.root, record=rec) if round_index is None else Noneidx = round_index if round_index is not None else (picked if picked is not None else _latest_round(ws))rnd = J.load_round(ws, rec, idx)@@ -106,6 +114,12 @@ def judge(raise C.CliError(f"round {idx} has no renders (rounds/r{idx:02d}.json / record.json)")rubric_name = J.rubric_for(rec, rnd, rubric)inp = J.build_judge_input(ws, rec, rnd)+ # an archived run keeps its sheet but may have pruned the per-view PNGs: say so, instead of+ # the judge's own FileNotFoundError / JudgeImageError escaping as a traceback+ missing = [v.path for v in inp.renders.views if not Path(v.path).is_file()]+ if missing:+ raise C.CliError(f"round {idx}: {len(missing)} of its {len(inp.renders.views)} judged renders are not on disk "+ f"(e.g. {missing[0]}): nothing to re-judge it from", code=2)judge_obj = J.make_judge(rec.spec, rubric_name, model or rec.spec.backends.judge, n)n_images = J.count_prompt_images(inp, rubric_name, judge_obj)from codeverse3d.cost.instrument import run_ledgerdiff --git a/harness/codeverse3d/cli/main.py b/harness/codeverse3d/cli/main.pyindex d0cf22c8..dde7b0db 100644--- a/harness/codeverse3d/cli/main.py+++ b/harness/codeverse3d/cli/main.py@@ -497,12 +497,16 @@ def _run_track(spec: Spec, ws, *, resume: bool, candidates: int | None = None, ff"interrupted; resume with `3dcode resume {ws.root.name}`", code=130) from Noneexcept Exception as e: # the track failed outside its own error handling+ from codeverse3d.orchestrator import StateCorruptfrom codeverse3d.tracks.lifecycle import SpecChangedif isinstance(e, SpecChanged):# a refusal with instructions, not a crash: no traceback, and the run# itself was never entered (reconcile_resume raises before any stage)raise C.CliError(str(e), code=2) from None+ if isinstance(e, StateCorrupt): # raised before any stage, like SpecChanged+ raise C.CliError(f"{e} — unreadable run state; move run_state.json aside and resume from the "+ f"round journal (rounds/)", code=2) from Noneerr_console.print_exception(max_frames=8)raise C.CliError(f"run failed: {type(e).__name__}: {e} (workspace {ws.root}; see events.jsonl)"diff --git a/harness/tests/flywheel_cli/test_cli.py b/harness/tests/flywheel_cli/test_cli.pyindex 63bd4826..d30f180a 100644--- a/harness/tests/flywheel_cli/test_cli.py+++ b/harness/tests/flywheel_cli/test_cli.py@@ -507,3 +507,32 @@ def test_a_config_file_that_is_not_a_mapping_is_a_bad_configuration(tmp_path: Paassert r.exit_code == 2 and "bad configuration" in r.output and "3dcodeverse.yaml" in r.output+def test_render_refuses_a_mode_it_would_not_honour(tmp_path: Path):+ """An unknown --mode escaped as a RenderError; on a scene or shader any mode rendered shaded, silently."""+ runs = tmp_path / "runs"+ for track, slug in (("static_object", "o"), ("scene", "s")):+ assert runner.invoke(app, ["make", "x", "--track", track, "--no-run", "--runs-dir", str(runs), "--slug", slug]).exit_code == 0+ r = runner.invoke(app, ["render", "o", "--mode", "bogus", "--runs-dir", str(runs)])+ assert r.exit_code == 2 and "--mode must be one of" in r.output and r.exception is None or isinstance(r.exception, SystemExit)+ r = runner.invoke(app, ["render", "s", "--mode", "wire", "--runs-dir", str(runs)])+ assert r.exit_code == 2 and "object runs" in r.output+++def test_judge_names_a_missing_record_or_missing_renders(tmp_path: Path, runs_dir: Path):+ """No record.json / pruned per-view PNGs escaped as RecordError / FileNotFoundError."""+ r = runner.invoke(app, ["make", "x", "--no-run", "--runs-dir", str(tmp_path / "r2"), "--slug", "nr"])+ r = runner.invoke(app, ["judge", "nr", "--runs-dir", str(tmp_path / "r2")])+ assert r.exit_code == 2 and "record.json" in r.output and isinstance(r.exception, SystemExit)+ for p in (runs_dir / "wooden_chair_ab12cd34").rglob("view_*.png"):+ p.unlink()+ r = runner.invoke(app, ["judge", "wooden_chair_ab12cd34", "--runs-dir", str(runs_dir), "--model", "gemini:x"])+ assert r.exit_code == 2 and "not on disk" in r.output and isinstance(r.exception, SystemExit)+++def test_resume_reports_a_corrupt_run_state_cleanly(made_run):+ runs, run_dir = made_run("--language", "threejs")+ (run_dir / "run_state.json").write_text("garbage")+ r = runner.invoke(app, ["resume", run_dir.name, "--runs-dir", str(runs)])+ assert r.exit_code == 2 and "run_state.json" in r.output and "Traceback" not in r.output++