test_acceptance_cli.py¶
tests/test_acceptance_cli.py
Tests for the acceptance CLI, chiefly that its phases stay separate.
test_an_unknown_arm_is_refused_by_name
None test_acceptance_cli.test_an_unknown_arm_is_refused_by_name(Path tmp_path, monkeypatch, capsys)
An unknown arm name must be refused by name rather than silently dropped.
tests/test_acceptance_cli.py:1185
Checks
assert cli.cmd_generate(args) == 1, "a misspelled arm was accepted"assert "index_onlyy" in capsys.readouterr().err, "the refusal did not name the unknown arm"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | inferred | test_an_unknown_arm_is_refused_by_name → cmd_generate → tool_identity → _substrate → compiled_languages |
Source · 32 lines
def test_an_unknown_arm_is_refused_by_name(tmp_path: Path, monkeypatch, capsys) -> None:
"""REFUSED BY NAME, like every other declaration in this project. A typo'd arm that silently
matched nothing would generate zero cells and report success — a run directory with no answers
and a green exit code, which reads as "the grid is cheap" rather than "the filter was wrong".
VERSION 2: THIS PASSED FOR THE WRONG REASON. `repo` does not exist, so `check_revision` refused
before the arm filter ran and the exit code was 1 either way. Both preflight checks are now
stubbed and the refusal must name the misspelled arm.
@brief An unknown arm is refused.
@return None.
@version 2
"""
monkeypatch.setattr(cli, "check_revision", lambda *_a, **_k: None)
monkeypatch.setattr(cli, "check_tool_tree", lambda *_a, **_k: None)
args = cli.argparse.Namespace(
rubric=MBEDTLS,
models=["claude-haiku-5-5"],
replicates=1,
seed=7,
repo=tmp_path / "repo",
out=tmp_path / "answers",
mcp_config=None,
timeout=60,
resume=False,
arms=["index_onlyy"],
)
assert cli.cmd_generate(args) == 1, "a misspelled arm was accepted"
assert "index_onlyy" in capsys.readouterr().err, "the refusal did not name the unknown arm"
Activity · 5 steps
test_arms_can_be_narrowed_and_the_record_says_which
None test_acceptance_cli.test_arms_can_be_narrowed_and_the_record_says_which(Path tmp_path, monkeypatch)
Generating a subset of arms spends only those arms, and the record says so.
tests/test_acceptance_cli.py:1129
Checks
assert cli.cmd_generate(args) == 0assert set(ran) == {"index_only", "index"}, f"arms outside the request were spent: {set(ran)}"assert "baseline" not in ran, "the baseline arm was generated despite being excluded"assert window["arms"] == ["index", "index_only"], (f"the window record does not name the arms that were asked for: {window}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | inferred | test_arms_can_be_narrowed_and_the_record_says_which → cmd_generate → tool_identity → _substrate → compiled_languages |
Source · 52 lines
def test_arms_can_be_narrowed_and_the_record_says_which(tmp_path: Path, monkeypatch) -> None:
"""A PROBE THAT ONLY NEEDS THE INDEX ARMS MUST NOT PAY FOR THE BASELINE. The baseline arm
makes no index calls at all, so for a measurement about index-call waste its cells are pure
spend. Without this flag the choices were to buy them anyway or to plant fake answer files so
`--resume` would skip them — and a fake answer makes the run record lie, which is worse than
the cost.
THE RECORD MUST NAME THE SUBSET. A directory holding only two arms is indistinguishable from
a three-arm run that lost a third of its cells, unless the window says which arms were asked
for. Absent when every arm ran, so "all arms" and "nobody recorded" do not read alike.
@brief --arms narrows generation and is recorded.
@return None.
@version 1
"""
ran: list[str] = []
monkeypatch.setattr(cli, "check_revision", lambda *_a, **_k: None)
## FIXTURE, NOT BEHAVIOUR: `generate` now refuses a modified clew tree, and this test runs
## in a working checkout. The tree check is covered by tests/test_tool_tree_refusal.py.
monkeypatch.setattr(cli, "check_tool_tree", lambda *_a, **_k: None)
monkeypatch.setattr(
cli,
"run_cell",
lambda cell, *_a, **_k: (
ran.append(cell.arm),
execute.CellResult(cell.stem(), cell.arm, cell.model, True),
)[1],
)
answers = tmp_path / "answers"
args = cli.argparse.Namespace(
rubric=MBEDTLS,
models=["claude-haiku-5-5"],
replicates=1,
seed=7,
repo=tmp_path / "repo",
out=answers,
mcp_config=None,
timeout=60,
resume=False,
arms=["index_only", "index"],
)
assert cli.cmd_generate(args) == 0
assert set(ran) == {"index_only", "index"}, f"arms outside the request were spent: {set(ran)}"
assert "baseline" not in ran, "the baseline arm was generated despite being excluded"
window = json.loads((answers / "run.json").read_text())["windows"][-1]
assert window["arms"] == ["index", "index_only"], (
f"the window record does not name the arms that were asked for: {window}"
)
Activity · 11 steps
test_grading_appends_a_pass_history
None test_acceptance_cli.test_grading_appends_a_pass_history(Path tmp_path, pytest.MonkeyPatch monkeypatch)
Every grading pass is retained, not just the latest.
tests/test_acceptance_cli.py:646
Checks
assert cli.cmd_grade(args) == 0assert cli.cmd_grade(args) == 0assert latest["score"] == 0.0, "the sidecar holds the LATEST pass"assert len(history) == 2, f"both passes must be retained, got {len(history)}"assert [p["score"] for p in passes] == [1.0, 0.0], "in the order they were graded"assert passes[0]["decisions"][0]["hit"] is True, "a pass keeps its DECISIONS, not just a score"assert passes[1]["decisions"][0]["hit"] is Falseassert all(p["rubric_digest"] == latest["rubric_digest"] for p in passes), ("each pass records the rubric it graded against, or a drift cannot be told from noise" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-054 | inferred | test_grading_appends_a_pass_history → all |
Source · 49 lines
def test_grading_appends_a_pass_history(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""MEASURED, AND THE MEASUREMENT ATE ITS OWN EVIDENCE. Regrading five cells against an
unchanged rubric moved one by -12.1 points, and which marks flipped is now unrecoverable —
the second pass overwrote the first. A variance figure needs BOTH passes; grading kept one.
`<stem>.grade.json` still holds the latest pass, so every existing consumer is unchanged.
The history rides beside it as one JSON object per line, appended, so a regrade adds
evidence instead of replacing it and the cost is a few kilobytes per cell.
DECISIONS ARE KEPT IN THE HISTORY, not just the score. "The cell moved 12 points" is the
question; "these two marks flipped" is the answer, and only the decisions carry it.
@brief Grading appends rather than replacing.
@return None.
@version 1
"""
answers = tmp_path / "answers"
answers.mkdir()
(answers / f"Q1_sonnet_{_A}_r1.md").write_text("an answer", encoding="utf-8")
scores = iter([True, False])
def scored(question, answer, rubric, arm):
return score.QuestionResult(
id=question.id,
decisions=[
score.Decision("m", "conclusion", 2, next(scores), agreement=1.0, samples=3)
],
)
monkeypatch.setattr(cli, "score_question", scored)
args = argparse.Namespace(rubric=MBEDTLS, answers=answers)
assert cli.cmd_grade(args) == 0
assert cli.cmd_grade(args) == 0
latest = json.loads((answers / f"Q1_sonnet_{_A}_r1.grade.json").read_text())
assert latest["score"] == 0.0, "the sidecar holds the LATEST pass"
history = (answers / f"Q1_sonnet_{_A}_r1.grades.jsonl").read_text().splitlines()
assert len(history) == 2, f"both passes must be retained, got {len(history)}"
passes = [json.loads(line) for line in history]
assert [p["score"] for p in passes] == [1.0, 0.0], "in the order they were graded"
assert passes[0]["decisions"][0]["hit"] is True, "a pass keeps its DECISIONS, not just a score"
assert passes[1]["decisions"][0]["hit"] is False
assert all(p["rubric_digest"] == latest["rubric_digest"] for p in passes), (
"each pass records the rubric it graded against, or a drift cannot be told from noise"
)
Activity · 18 steps
test_resume_does_not_respend_a_cell_that_already_has_an_answer
None test_acceptance_cli.test_resume_does_not_respend_a_cell_that_already_has_an_answer(Path tmp_path, pytest.MonkeyPatch monkeypatch)
Resuming skips the cells that already produced an answer.
tests/test_acceptance_cli.py:1005
Checks
assert cli.cmd_generate(args) == 0assert done.isdisjoint(ran), "a cell with a frozen answer was spent again"assert len(ran) == len(cells) - len(done)assert json.loads((answers / "run.json").read_text())["resumed"] == sorted(done)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | inferred | test_resume_does_not_respend_a_cell_that_already_has_an_answer → cmd_generate → tool_identity → _substrate → compiled_languages |
Source · 64 lines
def test_resume_does_not_respend_a_cell_that_already_has_an_answer(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""GENERATION IS THE PHASE THAT CANNOT BE RE-RUN CHEAPLY, and it had no way to resume: the
loop walks the whole plan unconditionally and a failed cell writes no `.md` and is passed
over. A capacity window inside a serial grid therefore loses those cells permanently, and
re-running spends every completed cell again to reach them.
OPT-IN, SO THE DEFAULT CONTRACT IS UNCHANGED. Without `--resume` a second `generate` still
re-spends everything, which is what every past measurement assumed. With it, the frozen
`.md` is treated as the record it already is.
THE PRESENCE OF `.md` IS THE RIGHT TEST because `run_cell` writes it LAST and only on
success — a transport failure leaves `.meta.json` and `.raw.json` but no answer, so a cell
that errored is correctly retried rather than skipped.
@brief --resume skips answered cells.
@return None.
@version 1
"""
from acceptance.runner import plan as plan_cells
rubric = _rubric_mod.load(MBEDTLS)
## FIXTURE, NOT BEHAVIOUR: the stems the frozen answers are written under must use the
## same model id `cmd_generate` is given, and `--models` now refuses an alias.
cells = plan_cells(rubric, ("claude-sonnet-4-5-20250929",), 1, 7)
done = {cells[0].stem(), cells[3].stem()}
answers = tmp_path / "answers"
answers.mkdir()
for stem in done:
(answers / f"{stem}.md").write_text("an answer from an earlier window", "utf-8")
ran: list[str] = []
def record(cell, *_a, **_k):
ran.append(cell.stem())
return execute.CellResult(cell.stem(), cell.arm, cell.model, True, tool_calls=1)
monkeypatch.setattr(cli, "run_cell", record)
monkeypatch.setattr(cli, "check_revision", lambda *_a, **_k: None)
## FIXTURE, NOT BEHAVIOUR: `generate` now refuses a modified clew tree, and this test runs
## in a working checkout. The tree check is covered by tests/test_tool_tree_refusal.py.
monkeypatch.setattr(cli, "check_tool_tree", lambda *_a, **_k: None)
args = cli.argparse.Namespace(
rubric=MBEDTLS,
## FIXTURE, NOT BEHAVIOUR. This said `m` (resp. `sonnet`) until `--models` began
## refusing an alias. What this test guards is unchanged; only the example string
## had to become a real pinned id to reach the code under test.
models=["claude-sonnet-4-5-20250929"],
replicates=1,
seed=7,
repo=tmp_path / "repo",
out=answers,
mcp_config=None,
timeout=60,
resume=True,
)
assert cli.cmd_generate(args) == 0
assert done.isdisjoint(ran), "a cell with a frozen answer was spent again"
assert len(ran) == len(cells) - len(done)
## THE RUN RECORD SAYS SO. A grid assembled over several windows must not read as one pass.
assert json.loads((answers / "run.json").read_text())["resumed"] == sorted(done)