Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-11-08
skip_specs: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Design

## Decisions

- **Use one parametrized table in `tests/roadmap/test_roadmap_faults.py`, keyed by `FailureClass`, for the stage and implement cases.**: The project runs pytest already, and one table shows every case and lets the coverage gate compare the table with the enum.
- **Drive each stage and implement case through the real job with `JobWorld.run` on the edge fakes and a scripted model.**: The class, the action, the final label and the comment are written by the stop path, so a case that stops short of it proves nothing about recovery.
- **Make the coverage gate read `{case.klass for case in FAULT_CASES} == set(FailureClass)` and name each missing class.**: `tests/roadmap/test_roadmap_failure.py` reads `ACTION_BY_CLASS` the same way, so a new class fails the suite without a case.
- **Make the halt record unwritable by putting a regular file where its parent directory would be, not a directory at the record's path.**: `src/devops_cli/server/service.py:343` starts the Service halted when the record exists, and `_halt` then writes nothing. With a file as the parent, the record does not exist at construction, so `_halt` reaches `keep_state_record` and its write fails.
- **State the measured duration of the three fault modules in the module docstring and hold it under 60 seconds in a `process` step, and assert no elapsed bound in a test.**: `docs/TESTING.md:141` forbids an upper bound on wall-clock time, and the ast-grep rule `test-elapsed-upper-bound` fails a test that adds one, so the bound is a measurement a person repeats.
- **Keep every wait on the `clock` fixture and every edge on an in-memory fake.**: The hermetic floor fails a test that reaches a real edge, and the clock fixture records each wait, so the suite adds no real time.
- **Split the Service lane cases into a state-file module and a row module.**: Each step then reads a small set of files that fits the budget, and each module mirrors the module that it drives.
- **Assert the failed marks write through the stage failure record and the item's job record, not through a comment.**: `write_each` catches the `GitHubOperationError` as a plain `DevOpsCLIError` and `_write_failure` records its class and masked message, and the staged comment is never posted because it comes after the marks write.
- **Keep the intake-apply case in the row module even though `tests/roadmap/intake/test_roadmap_intake_github_requests.py` already asserts the class and the person's label.**: The existing test posts no comment and asserts no kept record, and the fault table needs the case for the count and for the Service lane matrix.

## Rejected alternatives

- **A custom fault harness beside pytest.**: The project already runs pytest and requires the Tests & Coverage check, so a second runner adds maintenance and no coverage.
- **Recorded provider responses replayed over HTTP.**: `docs/adr/0007-tests-double-only-process-edges.md` doubles only process edges, and the hermetic floor refuses a real network edge.
- **A hand-kept checklist that every class has a case.**: The checklist drifts from the code; `tests/roadmap/test_roadmap_failure.py:494` shows that comparing the enum with a table fails on a new class.
- **A per-test assert on elapsed time, or a 60-second assert on the suite.**: `docs/TESTING.md:141` holds `No test bounds elapsed wall-clock time from above.` and the rule `test-elapsed-upper-bound` in `.ast-grep/rules/` fails such an assert.
- **Live cluster and model calls for the killed pod and the OOM.**: The issue requires offline cases, and the exit status of the job's pod carries the killed pod and the OOM as 143 and 137.
- **Make the halt record unwritable with a directory at the record's path, as the earlier plan did.**: `src/devops_cli/server/service.py:343` holds `self._halted = halt_record is not None and halt_record.exists()`, so the Service starts halted and `_halt` never calls `keep_state_record`.
- **Assert that the stop comment names the write that failed after the draft pull request exists.**: `src/devops_cli/roadmap/stage/stage.py:1946` holds `def _write_failure(item: Item, exc: DevOpsCLIError) -> StageFailure:`, so the record names the error class and its masked message and the comment is never posted.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Proposal

## Why

The recovery paths of the stage and implement jobs are trusted only after a fault hits a live item: an OOM, a 25-minute generation, an XML parser error, a wrong plan path, a scratch file in the root. #3075 asks for an offline fault-injection suite that makes each fault happen and proves that the job recovers, names the class and the action, posts the right comment, and keeps the finished work.

## What Changes

- Add `tests/roadmap/test_roadmap_faults.py`, a parametrized table of one stage or implement fault case for every class of `FailureClass`, with the coverage gate and the count gate.
- Add `tests/roadmap/test_roadmap_run_state_faults.py` for the Service state files: a halt record that cannot be written, and an unreadable `schedule.json`, failure ledger and intake record.
- Add `tests/roadmap/test_roadmap_run_row_faults.py` for the Service rows: a `RoadmapItemChangedError` during intake apply, a Service stop between two stage items, and a failed marks write after the draft pull request exists.
- State the measured duration of the three fault modules in the docstring of `tests/roadmap/test_roadmap_faults.py` and hold it under the 60-second bound of the Tests & Coverage check.
- The change adds tests only, so it has no spec delta: every path of the change is under `tests/`, and no command, option, manifest or service behavior changes.
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

None.

## Impact

- Tests: `tests/roadmap/test_roadmap_faults.py`, `tests/roadmap/test_roadmap_run_state_faults.py`, `tests/roadmap/test_roadmap_run_row_faults.py`

## Feasibility

- The probe `The path `src/devops_cli/roadmap/failure.py` is a file of the staging commit.` confirms the taxonomy that every case keys on.
- The probe `The path `tests/support/fakes/model.py` is a file of the staging commit.` and the probe `The path `tests/support/fakes/process.py` is a file of the staging commit.` confirm the model and process fakes, and the probe lines for `tests/support/fakes/git.py`, `tests/support/fakes/kubernetes.py`, `tests/support/fakes/roadmap_store.py` and `tests/support/fakes/clock.py` confirm the git, cluster, store and clock fakes.
- The probe `The path `docs/TESTING.md` is a file of the staging commit.` confirms the testing document, whose line `docs/TESTING.md:141` holds `No test bounds elapsed wall-clock time from above.`
- `search_code` with `test_roadmap_faults` returned no match, and `list_files` of `tests/roadmap` holds no fault file, so the suite is new.
- `search_code` with `def test_each_class_has_exactly_one_default_action_in_one_table` shows `tests/roadmap/test_roadmap_failure.py:494` holds `def test_each_class_has_exactly_one_default_action_in_one_table() -> None:`, the test that compares `ACTION_BY_CLASS` with `FailureClass`, which the coverage gate copies.
- `search_code` with `ACTION_BY_CLASS: Final` shows `src/devops_cli/roadmap/failure.py:84` holds `ACTION_BY_CLASS: Final[Mapping[FailureClass, FailureAction]] = MappingProxyType(`, so the expected action of a case comes from the one table.
- `read_file` of `src/devops_cli/roadmap/implement/implement_run.py` shows the stop path: `src/devops_cli/roadmap/implement/implement_run.py:1544` holds `self.store.comment(` and `src/devops_cli/roadmap/implement/implement_run.py:1582` holds `derive_status(StatusFacts(stopped=True)),`, so a case asserts the posted comment and the final label.
- `read_file` of `src/devops_cli/roadmap/run.py` shows `src/devops_cli/roadmap/run.py:233` holds `def _read_schedule(schedule_path: Path) -> dict[str, datetime]:`, `src/devops_cli/roadmap/run.py:272` holds `def read_intake_record(path: Path) -> IntakeRecord:` and `src/devops_cli/roadmap/run.py:1044` holds `class FailureLedger:`.
- `read_file` of `src/devops_cli/roadmap/run.py` shows `src/devops_cli/roadmap/run.py:250` holds `except OSError, json.JSONDecodeError:`, so a `schedule.json` that is not JSON reads as no time and the row runs.
- `read_file` of `src/devops_cli/server/service.py` shows `src/devops_cli/server/service.py:158` holds `def keep_state_record(record: Path, payload: object) -> None:` and `src/devops_cli/server/service.py:165` holds `except OSError as exc:`, so a halt record that cannot be written is one error log line and the halt stays in memory.
- The defect of the earlier plan is real: `src/devops_cli/server/service.py:343` holds `self._halted = halt_record is not None and halt_record.exists()`, so a directory at the halt record's path starts the Service halted and `_halt` never writes. The plan now puts a regular file where the halt record's parent directory would be: `Path.exists` on the record is then False, and `keep_state_record` reaches `write_json_file`, whose `mkdir` of the parent raises `NotADirectoryError`, an `OSError`, so the error line is written and no record file is made.
- `read_file` of `src/devops_cli/output/file_writer.py` shows `src/devops_cli/output/file_writer.py:37` holds `target_path.parent.mkdir(parents=True, exist_ok=True)`, the line that raises on a parent that is a regular file.
- `read_file` of `src/devops_cli/roadmap/intake/intake.py` shows `src/devops_cli/roadmap/intake/intake.py:1315` holds `def apply_intake(` and `src/devops_cli/roadmap/intake/intake.py:1330` holds `except GitHubOperationError as exc:`, so a `RoadmapItemChangedError` is caught as a failed candidate and named by `raise_for_failed_placements`, which posts no comment.
- `search_code` with `RoadmapItemChangedError` shows `src/devops_cli/roadmap/stores/store.py:759` raises it, so the intake-apply fault is reachable through the in-memory store's `fail_write`.
- `search_code` with `store.set_marks(` shows `src/devops_cli/roadmap/stage/stage.py:1883` holds `store.set_marks(`, and `src/devops_cli/roadmap/stage/stage.py:1946` holds `def _write_failure(item: Item, exc: DevOpsCLIError) -> StageFailure:`, so a failed marks write after the pull request is opened is recorded as the error class and its masked text, and no staged comment is posted.
- `search_code` with `ServiceStoppingError` shows `src/devops_cli/exceptions/roadmap.py:40` holds `class ServiceStoppingError(RoadmapRunError):` and `src/devops_cli/roadmap/run.py:561` holds `except ServiceStoppingError:`, so the stop between two stage items ends the round as a stop and not as a failed round.
- `read_file` of `tests/support/roadmap_implement.py` shows `tests/support/roadmap_implement.py:480` holds `class JobWorld:` and `tests/support/roadmap_implement.py:505` holds `def run(`, so a case drives the real implement job on the fakes.
- `read_file` of `tests/support/roadmap_run.py` shows `tests/support/roadmap_run.py:392` holds `def poll_round(` and `tests/support/roadmap_run.py:542` holds `def lane_table(`, so a row case runs one lane round on the in-memory store.
- `apply_implement` needs a checkout of the repository at `JobWorld.repo.clone`, a client of the store, which `InMemoryRoadmapStore` gives, and a model client, which `ModelScript` gives with no network.
- `plan_implement` needs a checkout of the repository and a client of the store, both from the `job_world` fixture.
- `run_due_jobs` and `STAGE_ROW.runner` need a checkout of the repository at the lane's clone path and a client of the store, which `lane_table` and `InMemoryRoadmapStore` give.
- `read_intake_record`, `FailureLedger` and `keep_state_record` need a path under `tmp_path` and no network.
- `RoundPause.after` needs a clock, which the `clock` fixture gives, and no network.
- The `FailureClass` enum in `src/devops_cli/roadmap/failure.py` holds 19 members, counted from the source in the inputs: provider, parser, test, lint, types, plan_defect, premise_false, oom, timeout, refused_tool, conflict, ci_infra, no_change_in_fix, tests_lost, head_moved, output_cap, read_only_path, limit_reached and outside_plan. Each member stays and is restricted to the one case that group 1 gives it: provider to a provider HTTP 500, parser to a malformed tool call, test to a failing pytest log, lint to a failing ruff log, types to a failing mypy log, plan_defect to an unticked task group, premise_false to a false premise, oom to exit status 137, timeout to exit status 143, refused_tool to a refused command, conflict to a non-fast-forward push, ci_infra to a check whose log shows nothing, no_change_in_fix to a fix step that changes no file, tests_lost to a lost test, head_moved to a moved head, output_cap to an output cap, read_only_path to a read-only path, limit_reached to a reached limit and outside_plan to a change outside the plan. No member is removed and none is allowlisted, so the coverage gate of group 1 names a class that has no case.
- Group 3 completes the Service row cases and verifies that the complete fault suite adds no more than 60 seconds to the test check.
- The first checks against the real system are `uv run devops ci test tests/roadmap/test_roadmap_faults.py`, then `uv run devops ci test tests/roadmap/test_roadmap_run_state_faults.py`, then `uv run devops ci test tests/roadmap/test_roadmap_run_row_faults.py`, then the whole check `uv run devops ci`.

## Existing Tool Considered

pytest, already the project's runner (`pyproject.toml` sets `[tool.pytest.ini_options]`), with pytest-timeout for the hang bound and pytest-xdist for the workers. The repository's edge fakes cover every edge: `model_fake` in `tests/support/fakes/model.py`, `process_fake` in `tests/support/fakes/process.py`, `git_fake` in `tests/support/fakes/git.py`, `cluster` in `tests/support/fakes/kubernetes.py`, the in-memory roadmap store in `tests/support/fakes/roadmap_store.py` and the clock fixture in `tests/support/fakes/clock.py`. The change adds cases to that runner and no tool.

## Dependencies

- #4097: docs/TESTING.md — the open pull request changes the testing document that this plan reads for the rule that no test bounds elapsed time; that rule stays the same.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Tasks

## 1. Add the stage and implement fault matrix

Reads: `src/devops_cli/roadmap/failure.py`, `src/devops_cli/roadmap/implement/implement_run.py`, `tests/support/roadmap_implement.py`, `tests/support/model_script.py`, `tests/roadmap/implement/test_roadmap_implement_job.py`, `tests/roadmap/test_roadmap_failure.py`, `docs/TESTING.md`. Changes: `tests/roadmap/test_roadmap_faults.py` (new).

- [ ] 1.1 Add `tests/roadmap/test_roadmap_faults.py`. The module docstring says the suite runs offline on the edge fakes, that no wait is real, and states its measured duration. Define `FaultCase` with the case name, the `FailureClass`, the expected `FailureAction`, the expected status label, the expected comment body and the injection that installs the fault. Build `FAULT_CASES` with one case for each of the nineteen classes: a provider HTTP 500, a malformed tool call, an exit status 143, an exit status 137, a non-fast-forward push, a failing pytest log, a failing ruff log, a failing mypy log, an unticked task group, a false premise, a refused command, a check whose log shows nothing, a fix step that changes no file, a lost test, a moved head, an output cap, a read-only path, a reached limit and a change outside the plan. Each case runs the job through `JobWorld.run` on `job_world`, then asserts the stop is the item's, the class in the job record, `ACTION_BY_CLASS[case.klass] is case.action`, the final label `status/blocked`, the exact comment body, and the kept work: the branch, the `wip:` commit or the draft pull request. Add `test_every_failure_class_has_a_fault_case`, which compares the case classes with `set(FailureClass)` and names each missing class, and `test_the_fault_suite_has_at_least_twelve_cases`, which asserts the table holds at least 12 cases
- Verification: `$ uv run devops ci test tests/roadmap/test_roadmap_faults.py` passes

## 2. Add the Service state-file fault cases

Reads: `src/devops_cli/server/service.py`, `src/devops_cli/roadmap/run.py`, `src/devops_cli/output/file_writer.py`, `tests/roadmap/test_roadmap_run_failure_ledger.py`, `tests/roadmap/test_roadmap_run_service.py`. Changes: `tests/roadmap/test_roadmap_run_state_faults.py` (new).

- [ ] 2.1 Add `tests/roadmap/test_roadmap_run_state_faults.py` with four cases, each on a path under `tmp_path`. A halt record that cannot be written: write a regular file at `tmp_path / "blocker"`, give `RoundPause` the record `tmp_path / "blocker" / "service-halt.json"` and a refusal reader that answers True, then call `after`; the record does not exist at construction, the write raises `NotADirectoryError`, one `state_unkept` error line names the record and that class, `halted()` is True, the next round starts nothing, and no record file exists. An unreadable `schedule.json`: the bytes are not JSON, `_read_schedule` returns no time, the row runs, and `_record_success` writes a valid file with the job's time. An unreadable failure ledger: `FailureLedger(record=path)` raises `RoadmapRunError` naming the file and the remedy. An unreadable intake record: `read_intake_record(path)` raises `RoadmapRunError` naming the file and the remedy. Each case asserts the injected error class, the row result, the final state and that the earlier record is kept
- Verification: `$ uv run devops ci test tests/roadmap/test_roadmap_run_state_faults.py` passes

## 3. Add the Service row fault cases

Reads: `src/devops_cli/roadmap/run.py`, `src/devops_cli/roadmap/intake/intake.py`, `src/devops_cli/roadmap/stage/stage.py`, `tests/support/roadmap_run.py`, `tests/support/roadmap_stage.py`, `tests/roadmap/test_roadmap_run_intake_row.py`, `tests/roadmap/intake/test_roadmap_intake_github_requests.py`. Changes: `tests/roadmap/test_roadmap_run_row_faults.py` (new).

- [ ] 3.1 Add `tests/roadmap/test_roadmap_run_row_faults.py` with three cases on `lane_table`, `poll_round` and `apply_stage`. A `RoadmapItemChangedError` during intake apply: `fail_write(write="label_issue", error=RoadmapItemChangedError(...))` leaves the person's `priority/p1-high` label in place, counts the candidate as failed, raises the round error that names the item and `RoadmapItemChangedError`, and keeps the earlier placement record. A Service stop between two stage items: the second item's write raises `ServiceStoppingError`, the first item's stage record and branch stay, and the round ends as a stop and not as a failed round. A failed marks write after the draft pull request exists: `fail_write(write="set_marks", at=1)` makes the `set_marks` call that follows the pull request open raise `GitHubOperationError`, and `write_each` catches it as a plain `DevOpsCLIError` and records a `StageFailure` whose error class is `GitHubOperationError` and whose reason is the masked error message. The branch and the draft pull request stay on origin, the item posts no staged comment, and the item counts as failed in the row. Each case asserts the injected error class, the row result, the final status label, the failure record or the round error text, and the kept work
- Verification: `$ uv run devops ci test tests/roadmap/test_roadmap_run_row_faults.py` passes

## Criteria

- Group 1: At least 12 fault cases run offline in the test suite in under a stated time.
- Group 1: Each case asserts the final status label and the comment text.
- Group 1: Adding a failure class needs a case (a test checks that every class has one).
- Group 3: The suite adds no more than 60 seconds to the test check.
Loading