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

Show on the map →

Called by none

Calls cmd_generate

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

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012inferredtest_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
lines 1198–1198monkeypatch.setattr(cli, "check_revision", lambda *_a, **_k: None)lines 1199–1199monkeypatch.setattr(cli, "check_tool_tree", lambda *_a, **_k: None)lines 1200–1211args = 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"], )lines 1213–1213assert cli.cmd_generate(args) == 1, "a misspelled arm was accepted"lines 1214–1214assert "index_onlyy" in capsys.readouterr().err, "the refusal did not name the unknown arm"

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

Show on the map →

Called by none

Calls cmd_generate

Checks

  • 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"
  • assert window["arms"] == ["index", "index_only"], (f"the window record does not name the arms that were asked for: {window}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012inferredtest_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
lines 1144–1144ran: list[str] = []lines 1145–1145monkeypatch.setattr(cli, "check_revision", lambda *_a, **_k: None)lines 1148–1148monkeypatch.setattr(cli, "check_tool_tree", lambda *_a, **_k: None)lines 1149–1156monkeypatch.setattr( cli, "run_cell", lambda cell, *_a, **_k: ( ran.append(cell.arm), execute.CellResult(cell.stem(), cell.arm, cell.model, True), )[1], )lines 1157–1157answers = tmp_path / "answers"lines 1158–1169args = 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"], )lines 1171–1171assert cli.cmd_generate(args) == 0lines 1172–1172assert set(ran) == {"index_only", "index"}, f"arms outside the request were spent: {set(ran)}"lines 1173–1173assert "baseline" not in ran, "the baseline arm was generated despite being excluded"lines 1175–1175window = json.loads((answers / "run.json").read_text())["windows"][-1]lines 1176–1178assert window["arms"] == ["index", "index_only"], ( f"the window record does not name the arms that were asked for: {window}" )

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

Show on the map →

Called by none

Calls all, cmd_grade

Checks

  • assert cli.cmd_grade(args) == 0
  • assert cli.cmd_grade(args) == 0
  • assert 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 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" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_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
lines 662–662answers = tmp_path / "answers"lines 663–663answers.mkdir()lines 664–664(answers / f"Q1_sonnet_{_A}_r1.md").write_text("an answer", encoding="utf-8")lines 666–666scores = iter([True, False])lines 668–674def scored(question, answer, rubric, arm): return score.QuestionResult( id=question.id, decisions=[ score.Decision("m", "conclusion", 2, next(scores), agreement=1.0, samples=3) ], )lines 676–676monkeypatch.setattr(cli, "score_question", scored)lines 677–677args = argparse.Namespace(rubric=MBEDTLS, answers=answers)lines 678–678assert cli.cmd_grade(args) == 0lines 679–679assert cli.cmd_grade(args) == 0lines 681–681latest = json.loads((answers / f"Q1_sonnet_{_A}_r1.grade.json").read_text())lines 682–682assert latest["score"] == 0.0, "the sidecar holds the LATEST pass"lines 684–684history = (answers / f"Q1_sonnet_{_A}_r1.grades.jsonl").read_text().splitlines()lines 685–685assert len(history) == 2, f"both passes must be retained, got {len(history)}"lines 686–686passes = [json.loads(line) for line in history]lines 687–687assert [p["score"] for p in passes] == [1.0, 0.0], "in the order they were graded"lines 688–688assert passes[0]["decisions"][0]["hit"] is True, "a pass keeps its DECISIONS, not just a score"lines 689–689assert passes[1]["decisions"][0]["hit"] is Falselines 690–692assert 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" )

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

Show on the map →

Called by none

Calls cmd_generate, load

Checks

  • 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)
  • assert json.loads((answers / "run.json").read_text())["resumed"] == sorted(done)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012inferredtest_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)

Activity · 18 steps
lines 1025–1025from acceptance.runner import plan as plan_cellslines 1027–1027rubric = _rubric_mod.load(MBEDTLS)lines 1030–1030cells = plan_cells(rubric, ("claude-sonnet-4-5-20250929",), 1, 7)lines 1031–1031done = {cells[0].stem(), cells[3].stem()}lines 1032–1032answers = tmp_path / "answers"lines 1033–1033answers.mkdir()lines 1034–1034◇ for stem in donelines 1035–1035(answers / f"{stem}.md").write_text("an answer from an earlier window", "utf-8")lines 1037–1037ran: list[str] = []lines 1039–1041def record(cell, *_a, **_k): ran.append(cell.stem()) return execute.CellResult(cell.stem(), cell.arm, cell.model, True, tool_calls=1)lines 1043–1043monkeypatch.setattr(cli, "run_cell", record)lines 1044–1044monkeypatch.setattr(cli, "check_revision", lambda *_a, **_k: None)lines 1047–1047monkeypatch.setattr(cli, "check_tool_tree", lambda *_a, **_k: None)lines 1048–1061args = 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, )lines 1062–1062assert cli.cmd_generate(args) == 0lines 1063–1063assert done.isdisjoint(ran), "a cell with a frozen answer was spent again"lines 1064–1064assert len(ran) == len(cells) - len(done)lines 1066–1066assert json.loads((answers / "run.json").read_text())["resumed"] == sorted(done)