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.

tests/test_matrix.py:143

Show on the map →

Called by none

Calls _args, drive

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

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012inferredtest_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
lines 156–156targets = tmp_path / "targets"lines 157–157◇ for name in ("alpha", "beta")lines 158–158(targets / name).mkdir(parents=True)lines 159–159(targets / name / "questions.yaml").write_text("not a rubric\n", encoding="utf-8")lines 161–161prepared: list[str] = []lines 163–168def 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()lines 170–170monkeypatch.setattr(matrix, "_prepare", fake_prepare)lines 171–171monkeypatch.setattr(matrix, "run_phase", lambda *_a, **_k: True)lines 172–172code = matrix.drive(_args(out=tmp_path / "grid", targets=targets))lines 174–174assert prepared == ["alpha", "beta"], "a failed target must not stop provisioning the rest"lines 175–175out = capsys.readouterr().outlines 176–176assert code == 1, "the exit code is the number of failed targets"lines 177–177assert "alpha" in out and "provision" in out, "the failure must be named with its phase"lines 178–178assert "1/2 target(s) completed every phase" in out

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.

tests/test_matrix.py:425

Show on the map →

Called by none

Calls _args, drive

Checks

  • assert rc != 0
  • assert "nosuchtarget" in capsys.readouterr().err

Result: passed

Verifies

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

1 more lines, not shown

Activity · 3 steps
lines 430–430rc = matrix.drive(_args(only=["nosuchtarget"], provision_only=True))lines 431–431assert rc != 0lines 432–432assert "nosuchtarget" in capsys.readouterr().err

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.

tests/test_matrix.py:184

Show on the map →

Called by none

Calls _args, drive

Checks

  • assert code == 0
  • assert "provision" in out.lower()
  • assert "generate" not in out.lower(), "no phase may be announced, let alone run"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012inferredtest_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
lines 199–199targets = tmp_path / "targets"lines 200–200(targets / "alpha").mkdir(parents=True)lines 201–201(targets / "alpha" / "questions.yaml").write_text("stub\n", encoding="utf-8")lines 203–205monkeypatch.setattr( matrix, "_prepare", lambda rubric_path, out: (object(), out / "alpha", object()) )lines 207–208def explode(*_a, **_k): raise AssertionError("provision-only must not run a phase")lines 210–210monkeypatch.setattr(matrix, "run_phase", explode)lines 211–211code = matrix.drive(_args(out=tmp_path / "grid", targets=targets, provision_only=True))lines 212–212assert code == 0lines 213–213out = capsys.readouterr().outlines 214–214assert "provision" in out.lower()lines 215–215assert "generate" not in out.lower(), "no phase may be announced, let alone run"

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.

tests/test_matrix.py:221

Show on the map →

Called by none

Calls _args, drive

Checks

  • assert matrix.drive(_args(out=tmp_path / "grid", targets=targets)) == 0
  • assert ran == ["generate", "grade", "report"]

Result: passed

Verifies

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

Activity · 8 steps
lines 232–232targets = tmp_path / "targets"lines 233–233(targets / "alpha").mkdir(parents=True)lines 234–234(targets / "alpha" / "questions.yaml").write_text("stub\n", encoding="utf-8")lines 236–238monkeypatch.setattr( matrix, "_prepare", lambda rubric_path, out: (object(), out / "alpha", object()) )lines 239–239ran: list[str] = []lines 240–240monkeypatch.setattr(matrix, "run_phase", lambda phase, argv: ran.append(phase) or True)lines 241–241assert matrix.drive(_args(out=tmp_path / "grid", targets=targets)) == 0lines 242–242assert ran == ["generate", "grade", "report"]