From b045e308b235d638a47493c2ccd8a14dfbdf92c1 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Tue, 17 Nov 2026 02:48:31 +0000 Subject: [PATCH] fix(roadmap): stop implement early when a test outside diff_scope fails Stop the step when an exit check reports a failing test outside the Changes list of the group. Name the failing test and path, and classify the stop as a false premise. Closes #3983 --- .../.openspec.yaml | 2 ++ .../design.md | 32 +++++++++++++++++ .../proposal.md | 30 ++++++++++++++++ .../exit-checks/spec.md | 29 ++++++++++++++++ .../tasks.md | 13 +++++++ .../exit-checks/spec.md | 28 +++++++++++++++ src/devops_cli/lang/en/messages.py | 4 +++ .../roadmap/implement/implement_step.py | 34 ++++++++++++++++++- .../test_roadmap_implement_step_repair.py | 32 +++++++++++++++++ 9 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/.openspec.yaml create mode 100644 openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/design.md create mode 100644 openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/proposal.md create mode 100644 openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/specs/roadmap-implement-step/exit-checks/spec.md create mode 100644 openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/tasks.md diff --git a/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/.openspec.yaml b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/.openspec.yaml new file mode 100644 index 0000000000..bbe8b39365 --- /dev/null +++ b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-17 diff --git a/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/design.md b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/design.md new file mode 100644 index 0000000000..6f2a374ab6 --- /dev/null +++ b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/design.md @@ -0,0 +1,32 @@ +# Design + +## Decisions + +### Parse test output at step exit check +Parse the command output when a verification command fails during the step exit check. +Extract failing test node IDs starting with `FAILED `. +Map each failing test to its file path and compare that path to the group's `Changes:` list. +This uses the existing command output and requires no additional subprocess runs. + +### Classify stop as false premise +Classify the stop with `FailureClass.PREMISE_FALSE`. +This causes `_extra_ask` to return `None`, preventing any extra repair turn or model requests. +The item returns to New so the plan can be updated to include the test. + +### Allow Changes paths and change tasks.md +Treat the group's `Changes:` paths and the change's `tasks.md` as allowed paths. +A failure in a test file outside these paths triggers the early stop. + +### Format stop evidence clearly +Format the stop message to name both the failing test node ID and its file path outside `Changes:`. + +## Rejected alternatives + +### Block edits at tool boundary only +Rejected: it stops the edit attempt but does not stop the step or name the failing test. + +### Run a separate invariant test command +Rejected: it duplicates the verification check and increases execution time. + +### Classify stop as LimitReached or Blocked +Rejected: `LimitReached` spends the full budget, and `Blocked` waits for manual retry without fixing the plan. diff --git a/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/proposal.md b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/proposal.md new file mode 100644 index 0000000000..9830e9bd4b --- /dev/null +++ b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/proposal.md @@ -0,0 +1,30 @@ +# Proposal: #3983 + +## Why +The implement runner continues to attempt repairs when a test fails outside the `Changes:` list. +`diff_scope` forbids editing files outside `Changes:`. +The runner loops until it reaches `LimitReached` and blocks the item. +Stopping the step early preserves the token budget and returns the item to New with the failing test and path as evidence. +Closes #3983. + +## What Changes +Add an early stop in the step exit checks when a test outside the group's `Changes:` list fails. +Name the failing test and the path outside `Changes:` in the stop message. +Classify the stop as `premise_false` so no repair turn or fix step runs. +Add an offline unit test covering this behavior. + +## Capabilities +The implement runner detects out-of-scope test failures and stops before spending tokens on disallowed edits. + +## Impact +Items with out-of-scope test failures stop immediately and return to New for plan correction. +No breaking changes or new dependencies. + +## Feasibility +Confirmed against `src/devops_cli/roadmap/implement/implement_step.py` and `tests/roadmap/implement/test_roadmap_implement_step_repair.py`. + +## Existing Tool Considered +No open, maintained tool or library covers this need. +The early-stop guard is internal to the implement runner. +The change edits existing code in `src/devops_cli/roadmap/implement/implement_step.py`. +It adds no dependency. diff --git a/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/specs/roadmap-implement-step/exit-checks/spec.md b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/specs/roadmap-implement-step/exit-checks/spec.md new file mode 100644 index 0000000000..43f55000ab --- /dev/null +++ b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/specs/roadmap-implement-step/exit-checks/spec.md @@ -0,0 +1,29 @@ +## ADDED Requirements + +### Requirement: Stop on out-of-scope invariant test +The implement runner SHALL stop the step when an invariant test fails on a file outside the `Changes:` list. + +#### Scenario: Invariant test outside `Changes:` stops the step +- **WHEN** the step exit check reports a failing invariant test whose file is not in the group's `Changes:` list and is not the change's `tasks.md` +- **THEN** the step ends with a stop result and starts no fix step + +### Requirement: Stop names the test and path +The stop SHALL name the failing test and the path outside `Changes:`. + +#### Scenario: Stop evidence names the failing test and its path +- **WHEN** the guard stops a step for an out-of-scope test failure +- **THEN** the stop result holds the test identifier and its file path, and the item comment shows both + +### Requirement: Stop spends no further tokens +The stop SHALL not spend the remaining token budget on edit attempts. + +#### Scenario: No model request follows the stop +- **WHEN** the guard stops a step for an out-of-scope test failure +- **THEN** the step makes no model request after the stop and the recorded token spend does not increase + +### Requirement: Offline test covers the guard +An offline test SHALL cover a failing invariant test outside `Changes:`. + +#### Scenario: Offline test feeds a failing invariant test outside `Changes:` +- **WHEN** the offline test supplies a step result with a failing invariant test whose file is outside `Changes:` +- **THEN** the runner returns the stop with the test and path and makes no fix attempt diff --git a/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/tasks.md b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/tasks.md new file mode 100644 index 0000000000..5409693b13 --- /dev/null +++ b/openspec/changes/archive/2026-11-17-3983-stop-implement-early-out-of-scope-test/tasks.md @@ -0,0 +1,13 @@ +# Tasks + +## 1. Behavior + +- [x] 1.1 Add failing offline test for out-of-scope test failure early stop + - Verification: `$ uv run devops ci test tests/roadmap/implement/test_roadmap_implement_step_repair.py` fails on the base +- [x] 1.2 Implement early stop for out-of-scope test failure in implement step exit checks + - Verification: `$ uv run devops ci test tests/roadmap/implement/test_roadmap_implement_step_repair.py` passes + +## 2. Documents + +- [x] 2.1 Add message string and documentation for out-of-scope test failure early stop + - Verification: `$ uv run devops ci docs` passes diff --git a/openspec/specs/roadmap-implement-step/exit-checks/spec.md b/openspec/specs/roadmap-implement-step/exit-checks/spec.md index a53e6e5a60..30e8535205 100644 --- a/openspec/specs/roadmap-implement-step/exit-checks/spec.md +++ b/openspec/specs/roadmap-implement-step/exit-checks/spec.md @@ -451,3 +451,31 @@ The attempt event of a group step that changes no file SHALL hold the class `pla #### Scenario: One group changes no file and one changes a file - **WHEN** the trace records one group step that changes no file and one group step that changes a file - **THEN** the first attempt event holds `plan_defect`, and the second holds an empty class + +### Requirement: Stop on out-of-scope invariant test +The implement runner SHALL stop the step when an invariant test fails on a file outside the `Changes:` list. + +#### Scenario: Invariant test outside `Changes:` stops the step +- **WHEN** the step exit check reports a failing invariant test whose file is not in the group's `Changes:` list and is not the change's `tasks.md` +- **THEN** the step ends with a stop result and starts no fix step + +### Requirement: Stop names the test and path +The stop SHALL name the failing test and the path outside `Changes:`. + +#### Scenario: Stop evidence names the failing test and its path +- **WHEN** the guard stops a step for an out-of-scope test failure +- **THEN** the stop result holds the test identifier and its file path, and the item comment shows both + +### Requirement: Stop spends no further tokens +The stop SHALL not spend the remaining token budget on edit attempts. + +#### Scenario: No model request follows the stop +- **WHEN** the guard stops a step for an out-of-scope test failure +- **THEN** the step makes no model request after the stop and the recorded token spend does not increase + +### Requirement: Offline test covers the guard +An offline test SHALL cover a failing invariant test outside `Changes:`. + +#### Scenario: Offline test feeds a failing invariant test outside `Changes:` +- **WHEN** the offline test supplies a step result with a failing invariant test whose file is outside `Changes:` +- **THEN** the runner returns the stop with the test and path and makes no fix attempt diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index 0bfcf51676..a671d7682a 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -3460,6 +3460,10 @@ class RoadmapMessages: "made no model request. The repair scope is: {scope}. A person decides how to fix the " "check." ) + implement_stop_test_outside_changes: str = ( + "The test `{test}` failed on `{path}`, which is outside the `Changes:` list of the group. " + "The plan does not permit this change." + ) implement_stop_no_test_file: str = "A behavior group changed no test file. Write the failing test first, in a file under tests/." implement_stop_base_passes: str = ( "No test of the group fails on the base commit. The tests of {files} pass there, " diff --git a/src/devops_cli/roadmap/implement/implement_step.py b/src/devops_cli/roadmap/implement/implement_step.py index a27ca98740..6a3a0b12bf 100644 --- a/src/devops_cli/roadmap/implement/implement_step.py +++ b/src/devops_cli/roadmap/implement/implement_step.py @@ -160,6 +160,7 @@ from devops_cli.roadmap.implement.implement_trace import ImplementTrace from devops_cli.roadmap.implement.implement_wip import WipCommit, WipKeeper, restore_sources from devops_cli.roadmap.mcp import ROLE_IMPLEMENTATION, build_roadmap_mcp_toolset +from devops_cli.roadmap.plan_read import PlanReadError, group_files from devops_cli.roadmap.step_commit import step_commit_title from devops_cli.roadmap.step_files import ( CHECKBOXES, @@ -1169,6 +1170,7 @@ class _CommandStop: argv: Sequence[str] status: int negative: bool + output: str = "" def _command_failure( @@ -1202,7 +1204,10 @@ def _command_failure( if done.returncode == (1 if negative else 0): return None if stops is not None: - stops.append(_CommandStop(argv=argv, status=done.returncode, negative=negative)) + output = f"{done.stdout or ''}\n{done.stderr or ''}" + stops.append( + _CommandStop(argv=argv, status=done.returncode, negative=negative, output=output) + ) if negative and done.returncode == 0: return MESSAGES.roadmap.implement_stop_search_found.format( command=named, output=_tail(done) @@ -1652,6 +1657,26 @@ def _plan_failure( return None +def _out_of_scope_test(output: str, inputs: StepInputs, source: Path) -> tuple[str, str] | None: + """The first failing test and its path if that path is outside the group's `Changes:` list (#3983).""" + if inputs.fix is not None: + return None + tasks_path = (inputs.change / "tasks.md").relative_to(source).as_posix() + try: + changes = set(group_files(inputs.group.text).changes) + except PlanReadError: + changes = set(inputs.group.named_paths) + allowed = {*changes, tasks_path, "tasks.md"} + for line in output.splitlines(): + if not line.startswith("FAILED "): + continue + token = line[len("FAILED ") :].strip().split()[0] + test_path = token.partition("::")[0] + if test_path and test_path not in allowed: + return token, test_path + return None + + def _early_failure( source: Path, inputs: StepInputs, changed: list[str], log: ToolCallLog ) -> _Failure | None: @@ -1668,6 +1693,13 @@ def _early_failure( if not early: return None if stops and stops[0].status == 1 and not stops[0].negative: + out_of_scope = _out_of_scope_test(stops[0].output, inputs, source) + if out_of_scope is not None: + test, path = out_of_scope + reason = MESSAGES.roadmap.implement_stop_test_outside_changes.format( + test=test, path=path + ) + return _Failure(reason, klass=FailureClass.PREMISE_FALSE) return _Failure( early, frozenset(changed), diff --git a/tests/roadmap/implement/test_roadmap_implement_step_repair.py b/tests/roadmap/implement/test_roadmap_implement_step_repair.py index f83f79fb03..95937752c7 100644 --- a/tests/roadmap/implement/test_roadmap_implement_step_repair.py +++ b/tests/roadmap/implement/test_roadmap_implement_step_repair.py @@ -569,3 +569,35 @@ def test_foreign_change_accepts_a_file_whose_content_is_the_base_content(tmp_pat ask = _Ask("message", frozenset({"tests/test_sample.py"}), "changed: {paths}") assert _foreign_change(root, SimpleNamespace(change=change), tree, ask, base) is None + + +def test_a_failing_invariant_test_outside_changes_stops_the_step_with_no_extra_turn( + store: InMemoryRoadmapStore, + checkout: Path, + programs: ProcessFake, +) -> None: + programs.answer( + lambda call: command_text(call).startswith("uv run devops ci test"), + ProcessAnswer( + returncode=1, + stdout=( + "FAILED tests/k8s/test_perimeter.py::test_network_policy - AssertionError: assert False\n" + "1 failed in 0.12s\n" + ), + ), + ) + script = ModelScript(tool_calls(*the_whole_group()), say("Done.")) + + outcome = _step(store, checkout, script) + + assert ( + outcome.status, + outcome.failure_class, + len(script.seen), + ) == ( + StepStatus.STOPPED, + FailureClass.PREMISE_FALSE, + 2, + ) + assert "tests/k8s/test_perimeter.py::test_network_policy" in outcome.reason + assert "tests/k8s/test_perimeter.py" in outcome.reason