Official Codebase of 3DCodeVerse
Python
cli: make refuses what it cannot run before the run exists — an unknown backend id, a blank prompt, a --dim that is not a positive length
gaoypeng2cc1a1537464
diff --git a/harness/codeverse3d/cli/_common.py b/harness/codeverse3d/cli/_common.pyindex 0bf08ca1..d4e5d9c1 100644--- a/harness/codeverse3d/cli/_common.py+++ b/harness/codeverse3d/cli/_common.py@@ -5,6 +5,7 @@ resolution every command goes through."""from __future__ import annotationsimport hashlib+import mathimport shutilfrom collections.abc import Iteratorfrom contextlib import ExitStack, contextmanager@@ -211,18 +212,48 @@ def create_workspace(root: Path, *, force: bool) -> Workspace:def parse_kv_floats(items: list[str], flag: str) -> dict[str, float]:+ """``key=value`` pairs of positive, finite floats (``--dim``: metres). ``height=0``,+ ``-1``, ``nan``, ``inf`` and a nameless ``=1`` used to be accepted, frozen on the spec and+ handed to the planner, the contract gate and the judge as a stated dimension."""out: dict[str, float] = {}for it in items:if "=" not in it:raise CliError(f"{flag} expects key=value, got {it!r}")- k, v = it.split("=", 1)+ k, v = (s.strip() for s in it.split("=", 1))+ if not k:+ raise CliError(f"{flag} expects key=value, got {it!r} (no key)")try:- out[k.strip()] = float(v)+ out[k] = float(v)except ValueError as e:raise CliError(f"{flag} {k}: not a number: {v!r}") from e+ if not math.isfinite(out[k]) or out[k] <= 0:+ raise CliError(f"{flag} {k}: must be a positive number, got {v!r}")return out+def check_backends(backends: Any) -> None:+ """Refuse a backend id this build cannot construct, before a run directory exists.++ The ids were only resolved when a stage first asked for the model or agent, so an+ unknown ``--generator`` (``antigravity:...``, a typo) surfaced AFTER the paid plan+ stage, as a traceback and an orphan run. The parsers are the constructors' own."""+ from codeverse3d.agents.registry import parse_agent_id+ from codeverse3d.models.registry import parse_model_id+ from codeverse3d.tracks.generation import is_single_shot, single_shot_model_id++ for role in ("generator", "planner", "judge", "captioner"):+ value = getattr(backends, role)+ try:+ if role != "generator":+ parse_model_id(value)+ elif is_single_shot(value):+ parse_model_id(single_shot_model_id(value))+ else:+ parse_agent_id(value)+ except ValueError as e:+ raise CliError(f"--{role} {value!r}: {e}", code=2) from None++# --------------------------------------------------------------------------- cost profiledef active_profile(settings: Any | None = None) -> Any:"""The :class:`~codeverse3d.cost.profiles.Profile` the current settings name."""diff --git a/harness/codeverse3d/cli/main.py b/harness/codeverse3d/cli/main.pyindex ef1eb658..d0cf22c8 100644--- a/harness/codeverse3d/cli/main.py+++ b/harness/codeverse3d/cli/main.py@@ -333,6 +333,8 @@ def make() -> 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 []+ if not prompt.strip(): # a blank prompt was planned, generated and judged as is+ raise C.CliError("the prompt is empty: say what to build", code=2)for p in image:if not p.is_file():raise C.CliError(f"reference image not found: {p}")@@ -373,6 +375,7 @@ def make(backends = settings.backends(generator=generator, planner=planner, judge=judge, captioner=captioner)+ C.check_backends(backends)# validate the whole Spec BEFORE touching the filesystem: an invalid# track/language combination must not leave an orphan run directory behind.try:diff --git a/harness/codeverse3d/models/registry.py b/harness/codeverse3d/models/registry.pyindex 36e54e74..d6eb5d97 100644--- a/harness/codeverse3d/models/registry.py+++ b/harness/codeverse3d/models/registry.py@@ -20,6 +20,8 @@ def parse_model_id(model_id: str) -> tuple[str, str]:provider, model = model_id.split(":", 1)if provider not in PROVIDERS:raise ValueError(f"unknown provider {provider!r}; known: {PROVIDERS}")+ if not model.strip():+ raise ValueError(f"model id {model_id!r} names no model")return provider, modeldiff --git a/harness/tests/flywheel_cli/test_cli.py b/harness/tests/flywheel_cli/test_cli.pyindex 5d4953ce..e94d37ce 100644--- a/harness/tests/flywheel_cli/test_cli.py+++ b/harness/tests/flywheel_cli/test_cli.py@@ -465,3 +465,31 @@ def test_flywheel_caption_defaults_to_the_configured_captioner(runs_dir: Path, mstr(runs_dir.parent / "side")])assert r.exit_code == 0, r.outputassert seen == ["fake:configured"]+++# --------------------------------------------------- the configuration sweep (2026-09-23): refused up front, cleanly[email protected]("flag,value", [+ ("--generator", "antigravity:gemini-3.7-flash"), ("--generator", "nocolon"), ("--generator", "single-shot:nope"),+ ("--generator", "single-shot:gemini:"), ("--planner", "gemini"), ("--judge", "bogus:model"),+ ("--captioner", "gemini:"),+], ids=lambda v: v.strip("-"))+def test_make_refuses_a_backend_id_it_cannot_build_before_the_run_exists(tmp_path: Path, flag: str, value: str):+ """An unknown id used to surface after the PAID plan stage, as a traceback and an orphan run."""+ r = runner.invoke(app, ["make", "a cup", flag, value, "--no-run", "--runs-dir", str(tmp_path / "runs"), "--slug", "b"])+ assert r.exit_code == 2 and flag in r.output and "Traceback" not in r.output+ assert not (tmp_path / "runs" / "b").exists()++[email protected]("args", [["--dim", "height=0"], ["--dim", "height=-1"], ["--dim", "height=nan"],+ ["--dim", "height=inf"], ["--dim", "=1"]], ids=lambda a: a[-1])+def test_make_refuses_a_dimension_that_is_not_a_positive_length(tmp_path: Path, args: list[str]):+ r = runner.invoke(app, ["make", "a cup", *args, "--no-run", "--runs-dir", str(tmp_path / "runs"), "--slug", "d"])+ assert r.exit_code == 1 and "--dim" in r.output and not (tmp_path / "runs" / "d").exists()+++def test_make_refuses_a_blank_prompt(tmp_path: Path):+ r = runner.invoke(app, ["make", " ", "--no-run", "--runs-dir", str(tmp_path / "runs")])+ assert r.exit_code == 2 and "prompt is empty" in r.output+ assert not (tmp_path / "runs").exists() or not any((tmp_path / "runs").iterdir())++