test_grader.py

tests/test_grader.py

Tests for the acceptance grader's scoring arithmetic and judge blindness.

test_extracting_items_that_match_no_member_is_refused

None test_grader.test_extracting_items_that_match_no_member_is_refused(monkeypatch)

Extracting items but matching no member must be refused, not scored zero.

tests/test_grader.py:679

Show on the map →

Called by none

Calls all, score_set

Checks

  • assert all(d.hit is None for d in out), (f"a total member mismatch was scored instead of refused: {[(d.mark, d.hit) for d in out]}" )
  • assert "key mismatch" in out[0].detail, f"the refusal does not say why: {out[0].detail!r}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_extracting_items_that_match_no_member_is_refused → all
Source · 39 lines
def test_extracting_items_that_match_no_member_is_refused(monkeypatch) -> None:
    """**THE HARNESS ALREADY PUBLISHED THIS FAILURE AND NOTHING NOTICED.** A trailing `:796` kept
    an answer's `src/facade/external_bridge.cpp:796` from equalling the member's
    `src/facade/external_bridge.cpp`, so a cell that named 4 of 7 members correctly scored 0 of 8
    set decisions, and the precision detail printed four MEMBER paths as "not in the set".

    `_key` now strips the citation, so that instance cannot recur. **This guard is for the next
    normalisation gap**, which will be just as unanticipated. The signature is specific: the
    extractor found things and NONE of them matched any member. That is far more likely a
    mis-keying than an answer that named only irrelevant files.

    The fixture deliberately uses a separator the current `_key` does NOT fold — a backslash
    path — so it stands in for a future gap rather than re-testing the one just fixed.

    @brief A total mismatch is unruled.
    @return None.
    @version 1
    """
    mark = Mark(
        text="every file that creates a thread",
        type="set",
        weight=2,
        members=[{"value": "src/facade/external_bridge.cpp"}, {"value": "src/mcp/health.cpp"}],
        extract="List the files.",
    )
    monkeypatch.setattr(
        score,
        "ask",
        lambda *_a, **_k: judge.Reply(text="ITEMS:\nsrc\\facade\\other_thing.cpp\nEND"),
    )

    out = score.score_set(mark, "an answer", "claude-sonnet-4-5-20250929", samples=1)

    assert all(d.hit is None for d in out), (
        f"a total member mismatch was scored instead of refused: {[(d.mark, d.hit) for d in out]}"
    )
    assert "key mismatch" in out[0].detail, f"the refusal does not say why: {out[0].detail!r}"

Activity · 5 steps
lines 697–703mark = Mark( text="every file that creates a thread", type="set", weight=2, members=[{"value": "src/facade/external_bridge.cpp"}, {"value": "src/mcp/health.cpp"}], extract="List the files.", )lines 704–708monkeypatch.setattr( score, "ask", lambda *_a, **_k: judge.Reply(text="ITEMS:\nsrc\\facade\\other_thing.cpp\nEND"), )lines 710–710out = score.score_set(mark, "an answer", "claude-sonnet-4-5-20250929", samples=1)lines 712–714assert all(d.hit is None for d in out), ( f"a total member mismatch was scored instead of refused: {[(d.mark, d.hit) for d in out]}" )lines 715–715assert "key mismatch" in out[0].detail, f"the refusal does not say why: {out[0].detail!r}"

test_set_scoring_counts_members_and_precision

None test_grader.test_set_scoring_counts_members_and_precision(pytest.MonkeyPatch monkeypatch)

A set mark yields one decision per member plus one for precision.

tests/test_grader.py:129

Show on the map →

Called by none

Calls all, score_set

Checks

  • assert len(out) == 3, "two members plus precision"
  • assert [d.hit for d in out] == [True, True, False]
  • assert "library/z.c" in out[-1].detail
  • assert all(d.weight == 2 for d in out)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_set_scoring_counts_members_and_precision → all
Source · 27 lines
def test_set_scoring_counts_members_and_precision(monkeypatch: pytest.MonkeyPatch) -> None:
    """PRECISION IS A DECISION. An answer that names both correct files AND a spurious one has
    full recall and loses the precision decision — which is what removes the incentive to dump
    every path in the repository once grading is known to be mechanical.

    @brief Set decisions and the precision penalty.
    @return None.
    @version 1
    """
    mark = Mark(
        text="every file with a thread-creation site",
        type="set",
        weight=2,
        extract="List them.",
        members=({"value": "programs/ssl/a.c"}, {"value": "programs/test/b.c"}),
    )
    monkeypatch.setattr(
        judge, "ask", lambda *_a, **_k: judge.Reply(text="ITEMS:\na.c\nb.c\nlibrary/z.c\nEND")
    )
    monkeypatch.setattr(score, "ask", judge.ask)
    out = score.score_set(mark, "answer", "claude-x-1")
    assert len(out) == 3, "two members plus precision"
    assert [d.hit for d in out] == [True, True, False]
    assert "library/z.c" in out[-1].detail
    assert all(d.weight == 2 for d in out)

Activity · 8 steps
lines 138–144mark = Mark( text="every file with a thread-creation site", type="set", weight=2, extract="List them.", members=({"value": "programs/ssl/a.c"}, {"value": "programs/test/b.c"}), )lines 145–147monkeypatch.setattr( judge, "ask", lambda *_a, **_k: judge.Reply(text="ITEMS:\na.c\nb.c\nlibrary/z.c\nEND") )lines 148–148monkeypatch.setattr(score, "ask", judge.ask)lines 149–149out = score.score_set(mark, "answer", "claude-x-1")lines 150–150assert len(out) == 3, "two members plus precision"lines 151–151assert [d.hit for d in out] == [True, True, False]lines 152–152assert "library/z.c" in out[-1].detaillines 153–153assert all(d.weight == 2 for d in out)

test_vote_records_the_reason_each_attempt_failed

None test_grader.test_vote_records_the_reason_each_attempt_failed(pytest.MonkeyPatch monkeypatch)

An unruled vote records WHY, not just how many failed.

tests/test_grader.py:321

Show on the map →

Called by none

Calls all, vote

Checks

  • assert voted.verdict is None and voted.errors == 3
  • assert voted.reasons and all("overloaded" in r for r in voted.reasons)
  • assert "no VERDICT line" in voted.reasons[0]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-054inferredtest_vote_records_the_reason_each_attempt_failed → all
Source · 20 lines
def test_vote_records_the_reason_each_attempt_failed(monkeypatch: pytest.MonkeyPatch) -> None:
    """ "3/3 calls failed" cannot tell a reader whether the judge was rate-limited, timed out, or
    replied without a verdict block — three failures needing three different responses. Recording
    only the tally made an unruled decision uninvestigable after the fact.

    @brief Failure reasons are kept.
    @return None.
    @version 1
    """
    monkeypatch.setattr(judge, "ask", lambda *_a, **_k: judge.Reply(error="rc=1: overloaded"))
    voted = judge.vote("m", "a", "claude-x-1", 3)
    assert voted.verdict is None and voted.errors == 3
    assert voted.reasons and all("overloaded" in r for r in voted.reasons)

    ## A reply that arrives but carries no verdict block is a DIFFERENT failure and says so.
    monkeypatch.setattr(judge, "ask", lambda *_a, **_k: judge.Reply(text="I think it is fine."))
    voted = judge.vote("m", "a", "claude-x-1", 1)
    assert "no VERDICT line" in voted.reasons[0]

Activity · 7 steps
lines 330–330monkeypatch.setattr(judge, "ask", lambda *_a, **_k: judge.Reply(error="rc=1: overloaded"))lines 331–331voted = judge.vote("m", "a", "claude-x-1", 3)lines 332–332assert voted.verdict is None and voted.errors == 3lines 333–333assert voted.reasons and all("overloaded" in r for r in voted.reasons)lines 336–336monkeypatch.setattr(judge, "ask", lambda *_a, **_k: judge.Reply(text="I think it is fine."))lines 337–337voted = judge.vote("m", "a", "claude-x-1", 1)lines 338–338assert "no VERDICT line" in voted.reasons[0]