test_matrix.py¶
tests/test_matrix.py
Tests for the grid driver.
test_a_failed_target_does_not_stop_the_grid
None test_matrix.test_a_failed_target_does_not_stop_the_grid(Path tmp_path, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture capsys)
One target failing does not stop the others.
Checks
assert prepared == ["alpha", "beta"], "a failed target must not stop provisioning the rest"assert code == 1, "the exit code is the number of failed targets"assert "alpha" in out and "provision" in out, "the failure must be named with its phase"assert "1/2 target(s) completed every phase" in out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | inferred | test_a_failed_target_does_not_stop_the_grid → drive → _prepare → provision → write_provision_record → tool_identity → _substrate → compiled_languages |
Source · 38 lines
def test_a_failed_target_does_not_stop_the_grid(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
) -> None:
"""A provisioning problem on one repository is not a reason to spend nothing on the other
three — a weekend run that aborts on target one has cost a weekend and produced nothing.
THE FAILURE IS NAMED, NOT COUNTED. "some targets failed" sends a reader to the logs; the
name and the phase send them to the cause.
@brief A failure is isolated and named.
@return None.
@version 1
"""
targets = tmp_path / "targets"
for name in ("alpha", "beta"):
(targets / name).mkdir(parents=True)
(targets / name / "questions.yaml").write_text("not a rubric\n", encoding="utf-8")
prepared: list[str] = []
def fake_prepare(rubric_path, out):
name = rubric_path.parent.name
prepared.append(name)
if name == "alpha":
return matrix.TargetOutcome(name, False, "provision", "pinned commit not reachable")
return object(), out / name, object()
monkeypatch.setattr(matrix, "_prepare", fake_prepare)
monkeypatch.setattr(matrix, "run_phase", lambda *_a, **_k: True)
code = matrix.drive(_args(out=tmp_path / "grid", targets=targets))
assert prepared == ["alpha", "beta"], "a failed target must not stop provisioning the rest"
out = capsys.readouterr().out
assert code == 1, "the exit code is the number of failed targets"
assert "alpha" in out and "provision" in out, "the failure must be named with its phase"
assert "1/2 target(s) completed every phase" in out
Activity · 14 steps
test_drive_refuses_an_unknown_selection
None test_matrix.test_drive_refuses_an_unknown_selection(pytest.CaptureFixture capsys)
The driver turns a bad selection into a refusal, not a traceback.
Checks
assert rc != 0assert "nosuchtarget" in capsys.readouterr().err
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | inferred | test_drive_refuses_an_unknown_selection → drive → _prepare → provision → write_provision_record → tool_identity → _substrate → compiled_languages |
Source · 8 lines
def test_drive_refuses_an_unknown_selection(capsys: pytest.CaptureFixture) -> None:
"""@brief An unknown `--only` exits non-zero before provisioning.
@return None.
@version 1
"""
rc = matrix.drive(_args(only=["nosuchtarget"], provision_only=True))
assert rc != 0
assert "nosuchtarget" in capsys.readouterr().err1 more lines, not shown
Activity · 3 steps
test_provision_only_runs_no_phases
None test_matrix.test_provision_only_runs_no_phases(Path tmp_path, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture capsys)
Provision-only stops before generation.
Checks
assert code == 0assert "provision" in out.lower()assert "generate" not in out.lower(), "no phase may be announced, let alone run"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | inferred | test_provision_only_runs_no_phases → drive → _prepare → provision → write_provision_record → tool_identity → _substrate → compiled_languages |
Source · 34 lines
def test_provision_only_runs_no_phases(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
) -> None:
"""THE PRE-FLIGHT AN EXPENSIVE RUN NEEDS. Provisioning is where a grid fails cheaply — a pin
that moved, a declaration the build did not record, an MCP config whose tools never register
— and every one of those is worth finding before a weekend of agent calls rather than on
cell 40 of 120.
Asserted by making phase execution EXPLODE: if provision-only ever reaches a phase, this
fails loudly instead of quietly spending the budget it exists to protect.
@brief Provision-only spends nothing.
@return None.
@version 1
"""
targets = tmp_path / "targets"
(targets / "alpha").mkdir(parents=True)
(targets / "alpha" / "questions.yaml").write_text("stub\n", encoding="utf-8")
monkeypatch.setattr(
matrix, "_prepare", lambda rubric_path, out: (object(), out / "alpha", object())
)
def explode(*_a, **_k):
raise AssertionError("provision-only must not run a phase")
monkeypatch.setattr(matrix, "run_phase", explode)
code = matrix.drive(_args(out=tmp_path / "grid", targets=targets, provision_only=True))
assert code == 0
out = capsys.readouterr().out
assert "provision" in out.lower()
assert "generate" not in out.lower(), "no phase may be announced, let alone run"
Activity · 11 steps
test_without_provision_only_the_phases_run
None test_matrix.test_without_provision_only_the_phases_run(Path tmp_path, pytest.MonkeyPatch monkeypatch)
Without the flag, the phases still run.
Checks
assert matrix.drive(_args(out=tmp_path / "grid", targets=targets)) == 0assert ran == ["generate", "grade", "report"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-012 | inferred | test_without_provision_only_the_phases_run → drive → _prepare → provision → write_provision_record → tool_identity → _substrate → compiled_languages |
Source · 24 lines
def test_without_provision_only_the_phases_run(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""THE CONTROL FOR THE TEST ABOVE. A flag that skipped the phases unconditionally would pass
it, and a grid that provisions and then silently does nothing is the worst possible outcome
of a driver whose whole job is to run the grid.
@brief The default still drives every phase.
@return None.
@version 1
"""
targets = tmp_path / "targets"
(targets / "alpha").mkdir(parents=True)
(targets / "alpha" / "questions.yaml").write_text("stub\n", encoding="utf-8")
monkeypatch.setattr(
matrix, "_prepare", lambda rubric_path, out: (object(), out / "alpha", object())
)
ran: list[str] = []
monkeypatch.setattr(matrix, "run_phase", lambda phase, argv: ran.append(phase) or True)
assert matrix.drive(_args(out=tmp_path / "grid", targets=targets)) == 0
assert ran == ["generate", "grade", "report"]