Skip to content

Official Codebase of 3DCodeVerse

Python

cli: make and resume refuse --max-minutes 0 — it paid for the plan and stopped with no round

gaoypeng2ade7dcc50fb
diff --git a/harness/codeverse3d/cli/_common.py b/harness/codeverse3d/cli/_common.py
index d4e5d9c1..393bb416 100644
--- a/harness/codeverse3d/cli/_common.py
+++ b/harness/codeverse3d/cli/_common.py
@@ -231,6 +231,13 @@ def parse_kv_floats(items: list[str], flag: str) -> dict[str, float]:
return out
+def check_minutes(max_minutes: float | None) -> None:
+ """``--max-minutes`` must leave the run some time: 0 planned (paid), then stopped at the
+ first clock check with no round — a ``budget`` run with nothing in it."""
+ if max_minutes is not None and max_minutes <= 0:
+ raise CliError(f"--max-minutes must be above 0 (got {max_minutes:g}): a run with no time builds nothing", code=2)
+
+
def check_backends(backends: Any) -> None:
"""Refuse a backend id this build cannot construct, before a run directory exists.
diff --git a/harness/codeverse3d/cli/main.py b/harness/codeverse3d/cli/main.py
index c4a8c71e..c7933680 100644
--- a/harness/codeverse3d/cli/main.py
+++ b/harness/codeverse3d/cli/main.py
@@ -335,6 +335,7 @@ def make(
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)
+ C.check_minutes(max_minutes)
for p in image:
if not p.is_file():
raise C.CliError(f"reference image not found: {p}")
@@ -614,6 +615,7 @@ def resume(
first — the only way to continue a BUDGET-stopped run. A run that already
reached a terminal state is refused unless ``--force``, which archives its rounds
(``rounds/pre_force/``) and starts it again at round 0 — paid, and a new final state."""
+ C.check_minutes(max_minutes)
ws = C.open_workspace(slug, runs_dir)
# the run mutex, before the spec is rewritten (a budget raise is a mutation)
with C.mutating(ws, what=f"3dcode resume {ws.root.name}"):
diff --git a/harness/tests/flywheel_cli/test_cli.py b/harness/tests/flywheel_cli/test_cli.py
index d2db05b3..176f55d5 100644
--- a/harness/tests/flywheel_cli/test_cli.py
+++ b/harness/tests/flywheel_cli/test_cli.py
@@ -560,3 +560,12 @@ def test_a_judge_unavailable_run_resumes_as_it_is(made_run, stub_track):
stub_track(lambda spec, resume, force: entered.append((resume, force)))
assert runner.invoke(app, ["resume", run_dir.name, "--runs-dir", str(runs)]).exit_code == 130
assert entered == [(True, False)]
+
+
+def test_a_zero_minute_budget_is_refused(made_run, tmp_path: Path):
+ """--max-minutes 0 planned (paid) and stopped at the first clock check with no round."""
+ r = runner.invoke(app, ["make", "a cup", "--max-minutes", "0", "--no-run", "--runs-dir", str(tmp_path / "z"), "--slug", "z"])
+ assert r.exit_code == 2 and "--max-minutes" in r.output and not (tmp_path / "z" / "z").exists()
+ runs, run_dir = made_run()
+ r = runner.invoke(app, ["resume", run_dir.name, "--runs-dir", str(runs), "--max-minutes", "0"])
+ assert r.exit_code == 2 and "--max-minutes" in r.output