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,2 @@
schema: spec-driven
created: 2026-11-17
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions openspec/specs/roadmap-implement-step/exit-checks/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/devops_cli/lang/en/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
34 changes: 33 additions & 1 deletion src/devops_cli/roadmap/implement/implement_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1169,6 +1170,7 @@ class _CommandStop:
argv: Sequence[str]
status: int
negative: bool
output: str = ""


def _command_failure(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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),
Expand Down
32 changes: 32 additions & 0 deletions tests/roadmap/implement/test_roadmap_implement_step_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -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