Skip to content

Official Codebase of 3DCodeVerse

Python

cli: a bad profile name dumped a traceback, and `--reference --no-run` spent money with no warning

gaoypengf1810144a970
diff --git a/harness/codeverse/cli/_common.py b/harness/codeverse/cli/_common.py
index 521ec8ca..adde8ae3 100644
--- a/harness/codeverse/cli/_common.py
+++ b/harness/codeverse/cli/_common.py
@@ -170,7 +170,10 @@ def resolve_dial(
``--max-minutes`` / ``--texture``) always wins over both.
"""
settings = settings or get_settings()
- prof = settings.apply_profile(profile_flag, force=True) if profile_flag else active_profile(settings)
+ try:
+ prof = settings.apply_profile(profile_flag, force=True) if profile_flag else active_profile(settings)
+ except ValueError as e: # e.g. `--profile bogus`: a typed error, not a raw traceback
+ raise CliError(str(e), code=2) from e
return ResolvedDial(
profile=prof.name,
generator=settings.default_generator,
diff --git a/harness/codeverse/cli/main.py b/harness/codeverse/cli/main.py
index 5eff3d5e..a7c0f89c 100644
--- a/harness/codeverse/cli/main.py
+++ b/harness/codeverse/cli/main.py
@@ -50,6 +50,15 @@ def _root(ctx: typer.Context, version: Annotated[bool, typer.Option("--version",
if ctx.invoked_subcommand is None:
console.print(ctx.get_help())
raise typer.Exit()
+ # Build the settings HERE so a bad configuration value is one typed error instead of a
+ # raw traceback out of whichever command happened to touch get_settings() first: the app
+ # runs with pretty_exceptions_enable=False, and `CV3D_PROFILE=bogus` used to dump a
+ # Python stack from every command — including `3dcv doctor`, the one you would run to
+ # find out what is wrong with your configuration.
+ try:
+ get_settings()
+ except ValueError as e:
+ raise C.CliError(f"bad configuration: {e}", code=2) from e
# --------------------------------------------------------------------------- make / resume
@@ -87,7 +96,9 @@ def make(
texture: Annotated[bool, typer.Option("--texture", help="run the text-to-image texture pass after the rounds (frozen on spec.options)")] = False,
seed: Annotated[int, typer.Option("--seed")] = 0,
force: Annotated[bool, typer.Option("--force", help="overwrite an existing run dir")] = False,
- no_run: Annotated[bool, typer.Option("--no-run", help="only create the workspace + spec.json")] = False,
+ no_run: Annotated[bool, typer.Option("--no-run", help="only create the workspace + spec.json and stop "
+ "(with --reference the reference pass still runs first: it makes model calls and writes "
+ "the grounded spec)")] = False,
) -> None:
"""Create a run (workspace + spec.json) and execute the track pipeline."""
image, dim, must, must_not, tag = image or [], dim or [], must or [], must_not or [], tag or []
@@ -133,6 +144,13 @@ def make(
"rounds": rounds, "max_usd": max_usd,
"candidates": candidates, "texture": texture}))
if reference:
+ # --reference runs even under --no-run, because the grounded spec IS the artifact
+ # it produces (reference/run.py writes it back to spec.json) — but the combination
+ # is otherwise read as "filesystem only", so say out loud that this part spends
+ # money and can block on a degraded provider before anything is written.
+ if no_run:
+ warn(f"--reference makes model calls now (1 planner call + {reference_views} image generation(s) "
+ f"+ {reference_views} vision check(s), ~$0.15 for 2 views) — --no-run stops after that")
spec = _ground_in_reference(spec, ws, n_views=reference_views)
if no_run:
ok(f"spec written: {ws.spec_path} (not run; `3dcv resume {run_slug}` to start)")
@@ -231,7 +249,10 @@ def resume(
ws = C.open_workspace(slug, runs_dir)
spec = C.load_spec(ws)
if spec.options.profile: # the dial the run was created with (judge samples, montage px, turn cap)
- get_settings().apply_profile(spec.options.profile, force=True)
+ try:
+ get_settings().apply_profile(spec.options.profile, force=True)
+ except ValueError as e: # a spec.json naming a profile this build no longer has
+ raise C.CliError(f"{ws.spec_path}: {e}", code=2) from e
raised = {k: v for k, v in {"max_usd": max_usd, "max_minutes": max_minutes, "max_rounds": rounds}.items() if v is not None}
if not force and (why := _finished_reason(ws, raised)):
raise C.CliError(f"run {ws.root.name} already finished ({why}); nothing to resume. "
diff --git a/harness/docs/RUNBOOK.md b/harness/docs/RUNBOOK.md
index ca9a3d0c..25f321fc 100644
--- a/harness/docs/RUNBOOK.md
+++ b/harness/docs/RUNBOOK.md
@@ -62,7 +62,8 @@ quick-judged, pairwise tie-break, winner kept; multiplies baseline cost ≈ N;
default from `settings.default_candidates`), `--texture` (run the texture pass after
finalise; see §6), `--max-usd`, `--max-minutes`, `--dim height=0.45`, `--must`,
`--must-not`, `--style`, `--tag`, `--seed`, `--slug`, `--runs-dir`, `--force`,
-`--no-run`.
+`--no-run` (workspace + spec.json only — except that `--reference` still runs its
+paid grounding pass first, since the grounded spec is what it writes).
Expected cost/time with gemini-3.7-flash: object tracks ≈ $0.7–0.9 and 12–36 min for
baseline + 1 refine; best-of-2 single-shot ≈ $0.25 / 8 min; graphics single-shot
diff --git a/harness/tests/cost/test_profiles.py b/harness/tests/cost/test_profiles.py
index d9d96d86..f75cbbfe 100644
--- a/harness/tests/cost/test_profiles.py
+++ b/harness/tests/cost/test_profiles.py
@@ -118,6 +118,31 @@ def test_unknown_profile_is_a_clear_error():
get_profile("cheapest")
+def test_a_bogus_profile_name_is_a_typed_cli_error_not_a_traceback(monkeypatch, tmp_path):
+ """SM-10: the profile is read while get_settings() builds, and `app` runs with
+ pretty_exceptions_enable=False, so one typo in an exported CV3D_PROFILE dumped a raw
+ Python stack from EVERY command — including `3dcv doctor`, the command you would run
+ to find out what is wrong with your configuration."""
+ runner = CliRunner()
+ monkeypatch.setenv("CV3D_PROFILE", "bogus")
+ get_settings.cache_clear()
+ try:
+ r = runner.invoke(app, ["doctor"])
+ out = " ".join(r.output.split()) # rich wraps at the console width
+ assert r.exit_code == 2 and r.exception.__class__.__name__ != "ValueError"
+ assert "unknown profile 'bogus'" in out and "economy, balanced, quality" in out
+ assert "Traceback" not in out
+ finally:
+ get_settings.cache_clear()
+ monkeypatch.delenv("CV3D_PROFILE")
+ get_settings.cache_clear()
+ r = runner.invoke(app, ["make", "x", "--profile", "bogus", "--no-run",
+ "--runs-dir", str(tmp_path / "runs"), "--slug", "b2"])
+ out = " ".join(r.output.split())
+ assert r.exit_code == 2 and "unknown profile 'bogus'" in out and "Traceback" not in out
+ get_settings.cache_clear()
+
+
def test_profile_table_and_cli():
rows = profile_table()
assert len(rows) == 3 and rows[0][0] == "economy"
diff --git a/harness/tests/flywheel_cli/test_cli.py b/harness/tests/flywheel_cli/test_cli.py
index edfd45e6..888c618e 100644
--- a/harness/tests/flywheel_cli/test_cli.py
+++ b/harness/tests/flywheel_cli/test_cli.py
@@ -10,6 +10,7 @@ from typer.testing import CliRunner
from codeverse.cli import _common as C
from codeverse.cli.main import app
+from codeverse.cli.main import make as make_cmd
from codeverse.contracts.spec import Spec
runner = CliRunner()
@@ -335,3 +336,31 @@ def test_render_graphics_regenerates_frames(tmp_path: Path, monkeypatch):
assert r.exit_code == 0, r.output
assert (out / "sheet.png").is_file() and len(list(out.glob("f*.png"))) == 2
assert "fake-gl" in r.output
+
+
+def test_reference_with_no_run_says_it_is_about_to_spend_money(tmp_path: Path, monkeypatch):
+ """SM-06: `--no-run` reads as "filesystem only" (its help said "only create the
+ workspace + spec.json"), but main.py grounds the reference BEFORE honouring it: 1
+ planner call + n_views image generations + n_views vision checks, ~$0.15, and a block
+ of up to model_timeout_s on a degraded provider. The pass is not wasted — the
+ grounded spec is written back to spec.json — so it keeps running, but the command must
+ say so instead of looking offline."""
+ import codeverse.reference as REF
+
+ calls = []
+
+ def fake_ground_spec(spec, ws, *, n_views=2, events=None, **kw):
+ calls.append(n_views)
+ raise SystemExit(7) # stop before any real model work
+
+ monkeypatch.setattr(REF, "ground_spec", fake_ground_spec)
+ runs = tmp_path / "runs"
+ r = runner.invoke(app, ["make", "a wooden stool", "--reference", "--no-run",
+ "--runs-dir", str(runs), "--slug", "refnorun"])
+ out = " ".join(r.output.split())
+ assert calls == [2], "the grounding pass still runs: the grounded spec is the artifact"
+ assert "--reference makes model calls now" in out and "$0.15" in out
+ import typing
+
+ help_text = typing.get_type_hints(make_cmd, include_extras=True)["no_run"].__metadata__[0].help
+ assert "with --reference the reference pass still runs first" in help_text