From 40b2d51d8d3cb9948999a2290ec49dd14ab3cb6a Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Fri, 30 Oct 2026 23:00:08 +0000 Subject: [PATCH 1/8] docs(openspec): plan the step that keeps the existing tests (#2804) --- .../.openspec.yaml | 2 + .../2804-step-keeps-existing-tests/design.md | 23 +++++ .../proposal.md | 46 ++++++++++ .../specs/roadmap-implement-step/spec.md | 83 +++++++++++++++++++ .../2804-step-keeps-existing-tests/tasks.md | 27 ++++++ 5 files changed, 181 insertions(+) create mode 100644 openspec/changes/2804-step-keeps-existing-tests/.openspec.yaml create mode 100644 openspec/changes/2804-step-keeps-existing-tests/design.md create mode 100644 openspec/changes/2804-step-keeps-existing-tests/proposal.md create mode 100644 openspec/changes/2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md create mode 100644 openspec/changes/2804-step-keeps-existing-tests/tasks.md diff --git a/openspec/changes/2804-step-keeps-existing-tests/.openspec.yaml b/openspec/changes/2804-step-keeps-existing-tests/.openspec.yaml new file mode 100644 index 0000000000..4bfa67093b --- /dev/null +++ b/openspec/changes/2804-step-keeps-existing-tests/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-10-30 diff --git a/openspec/changes/2804-step-keeps-existing-tests/design.md b/openspec/changes/2804-step-keeps-existing-tests/design.md new file mode 100644 index 0000000000..704d8d518d --- /dev/null +++ b/openspec/changes/2804-step-keeps-existing-tests/design.md @@ -0,0 +1,23 @@ +# Design + +## Decisions + +- **The rule is by qualified name.** A test is `test_x` or `Class.test_x`, with the names of nested classes joined by dots. A rename is a loss. A change of the body is not. The issue asks for the rule by name, and a name is the one fact that a parser gives with no guess. +- **Which defs count.** A function or an async function whose name starts with `test_`. The walk goes into classes, and into the blocks of `if`, `try`, `with`, `for`, `while` and `match`, so a test that a platform check guards is kept as well. The walk stops at a function: a `def test_x` inside a function is a helper of that test. Decorators do not matter, so a parametrized test is one function and its cases are not names. +- **Which files count.** A path under `tests/` that ends with `.py`, listed by git as changed, between the start commit and the checkout. A file that the step did not touch cannot lose a test. A new file has no tests to lose. A file that is not Python is not parsed. +- **A deleted file loses all its tests, unless they moved.** The check lists the changes with `--no-renames`, so a move is a delete plus an add, whatever the git settings are. A lost name is excused by one name that is new in a changed test file: new means that the name is in the file after the run and was not in that file at the start. Each new name excuses one lost name, in the order of the sorted paths. A step that moves a test and keeps a copy in the old file is not a loss either way. +- **A syntax error is skipped, and not reported.** At the start, a file that does not parse gives no list, so the file keeps no test from the check. After the run, `ruff check` reports the error, and the repair turn can fix it. A second reason for the same file would be a double report. A file that does not parse after the run adds no new names, so it excuses no loss. A bad parse does not hide a loss in another file. +- **The check runs second.** It runs after the head check and the restore of `tasks.md`, and after the no-change check, because it needs the staged tree. It runs before the formatter and the verification commands. A verification command can run the whole test file for minutes, and the step discards the work anyway. The reason is also the most useful one: it names the tests, and not a symptom of their loss. The formatter does not change names. A repair turn runs the exit checks again from the start, so a repair turn cannot remove a test and pass. +- **No extra turn.** A lost test is a loss of work the agent chose, and a rewrite is the fix, not a one-line edit. The step stops, as the issue asks, and the diff in the stop comment shows the work. A person who wants to remove a test does it in a pull request of their own. +- **The reason is bounded.** It names the file and at most `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` functions, then the count of the rest. It names at most `CONST_ROADMAP_IMPLEMENT_REASON_PATHS` files with the same count rule. The stop comment cuts a reason to `CONST_ROADMAP_IMPLEMENT_REASON_CHARS` characters in any case. +- **Pure functions in a module of their own.** `implement_step.py` is 1,300 lines. The module `implement_test_names.py` holds `test_names(text)` and `lost_tests(before, after)`, with no I/O. `implement_step.py` reads git and formats the reason. + +## Rejected alternatives + +- **`pytest --collect-only` before and after.** It imports the modules and runs their top-level code, and it needs a second checkout at the start commit. A file with an import error gives no list. Rejected for cost and risk, see the proposal. +- **Compare the count of tests.** A step that deletes one test and adds one passes. The issue asks for names. +- **Use the rename detection of git.** `git diff -M` pairs a deleted file with an added file by a similarity guess. A step that replaces a file with a small new file is not a rename, and a threshold would decide the result. A name comparison needs no threshold. +- **A regular expression for `def test_`.** The issue forbids it, and it cannot tell a method from a function, or a def in a string. +- **Give the agent an extra turn to restore the tests.** The restore is a rewrite of work the agent chose to drop, and the issue asks for a stop. A person decides about a removal. +- **Check every test file in the repository.** A file that the step did not change cannot lose a test, and the check would depend on the whole tree. +- **Skip the check when the group names the file.** A group that names a test file asks for tests to be added. It never asks for a removal. The merged pull request had such a group. diff --git a/openspec/changes/2804-step-keeps-existing-tests/proposal.md b/openspec/changes/2804-step-keeps-existing-tests/proposal.md new file mode 100644 index 0000000000..22e0d5116c --- /dev/null +++ b/openspec/changes/2804-step-keeps-existing-tests/proposal.md @@ -0,0 +1,46 @@ +# Proposal + +## Why + +Issue #2804. The implement job made a pull request for #2745. In it, the agent replaced the whole of `tests/test_config_write_history.py` with two new tests. The file had seven tests at the start of the step. The step passed all its checks and the pull request was merged, because a deleted test cannot fail. + +The step judges the work with the verification commands of the group, `ruff check` and `mypy --strict`. Nothing checks that the step keeps the tests that existed before it. A step may add tests. It may not remove one. + +## What Changes + +- A new exit check lists, for each test file that the step changed and that existed at the start commit, the test functions of the file at the start. When one of them is not in the file after the run, the step stops. The reason names the file and the missing functions, up to a fixed number of them. +- A test file is a Python file under `tests/`. A test function is a function or an async function whose name starts with `test_`, at module level or in a class, also inside an `if`, `try` or `with` block. A function is named by its qualified name: `test_x` or `Class.test_x`. A parametrized test is one function. A function inside another function is not a test. +- A step that deletes a test file loses all its tests. A step that moves tests from one file to another loses none, when each moved test has the same qualified name in a test file that the step changed and did not have it at the start. A step that renames a test loses the test: the rule is by name. +- A file with a syntax error is skipped. At the start, there is no list to compare. After the run, the static check judges the file, so the new check does not report it twice. +- The check runs second, after the check that `HEAD` did not move, and before the formatter and the verification commands. It is cheap, and the verification commands can run for minutes. The step discards the work in any case, so it must not spend that time first. The check gives no extra turn: a lost test is not a fault of style that one edit removes. +- The module `implement_test_names.py` holds the list of names and the comparison, in pure functions. `implement_step.py` holds only the git calls and the reason text. +- The instructions of the step tell the agent the rule. +- A consumer observes the exit order and a new reason, so the change carries a spec delta. It modifies one requirement of `roadmap-implement-step` and adds one. +- This change fits one pull request. + +## Capabilities + +### Modified Capabilities + +- `roadmap-implement-step`: the order of the exit checks, and a new requirement for the check that keeps the existing tests. + +## Impact + +- `src/devops_cli/roadmap/implement_step.py`, a new `src/devops_cli/roadmap/implement_test_names.py`, `src/devops_cli/lang/en/messages.py`, `src/devops_cli/config/constants.py`, `src/devops_cli/ai/tasks/roadmap_implement_step.md`. +- A new `tests/test_roadmap_implement_step_tests_kept.py`, and a new `tests/test_roadmap_implement_test_names.py`. +- The documents that `devops docs generate --sync-readme` writes. + +## Feasibility + +- The defect is real. In `git show 72b82e38 -- tests/test_config_write_history.py`, the file has 7 test functions at `72b82e38~1` and 2 at `72b82e38`. A walk of both versions with the standard library `ast` lists the 7 lost names, such as `test_the_first_write_of_a_config_file_records_its_keys_and_keeps_no_copy`. The same commit adds `tests/config/test_config_file_mode.py`, and none of the 7 names is in it. So a rule by qualified name stops this commit, also when the rule excuses moved tests. +- No exit check looks at tests today. `_exit_failure` in `implement_step.py` runs, in order: the head check, `_restore_tasks`, the no-change check, `_format_failure`, `_verification_failure` and `_static_failure`. None reads a test name. +- `_stage` cannot list a deleted file. It runs `git diff --cached --name-only --diff-filter=ACMR`, and `D` is not in the filter. The new check lists its own paths. `git diff --cached --name-status --no-renames -z -- tests` gives a delete plus an add for a move, in the same shape on every machine, whatever `diff.renames` says. Git 2.55.0 was run for this. +- The text at the start is `git show :`. The step already runs git through `_git_output`, and the start commit is in the tree of the checkout. +- `ast.parse` from the standard library gives the names, and raises `SyntaxError` for a file that does not parse. `ast.iter_child_nodes` walks into `if`, `try`, `with` and class bodies, and the walk can stop at a function. A rename in git needs a similarity guess, and the check needs none: it compares names. +- The rule for a moved test is by evidence. Git shows a move as a delete plus an add when renames are off. The tests of the deleted file are not lost when the same qualified name is new in a changed test file. A name that the other file had at the start is not new: that file has the test already, and a delete of a duplicate must still stop. + +## Existing Tool Considered + +The standard library `ast` lists the test names, and git lists the changed paths and the text at the start commit. `pytest --collect-only` was considered. It imports the test modules, so it runs the code of a file that the agent wrote, needs the dependencies of every module, and takes seconds for each file. It also needs the files at the start, in a second checkout. A parse of the text needs none of this. `pytest` also finds names that a plugin makes. The rule here needs the names that a person wrote. + +The change builds about 50 lines of product code and the tests. Cost, estimated: 60k tokens of agent work to build it, small upkeep, and 1 hour of elapsed time. The change deletes no code. diff --git a/openspec/changes/2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md b/openspec/changes/2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md new file mode 100644 index 0000000000..82aae49cc9 --- /dev/null +++ b/openspec/changes/2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md @@ -0,0 +1,83 @@ +# Spec Delta + +## MODIFIED Requirements + +### Requirement: A failed exit check stops the step and resets the checkout +The exit checks SHALL run in this order: the agent made no commit, no test that existed at the start is lost, each verification command passes, the static checks pass, and every task of the group is ticked. The step SHALL stop at the first check that fails, name it as the reason, make no commit, and reset the checkout. A failed static check, and a task left unticked after the first four checks, first get the extra turn of their own requirements. + +#### Scenario: A verification command fails +- **WHEN** the model ends its run with the files written and the tasks ticked, and the verification command exits 1 +- **THEN** the step reports stopped, the reason names the command and its exit status, the checkout holds no new commit, and the written files are gone + +#### Scenario: A static check fails +- **WHEN** the verification command exits 0 and `ruff check` exits 1 on the changed file, in the first turn and in the extra turn +- **THEN** the step reports stopped with the reason that `ruff check` failed, makes no commit and resets the checkout + +#### Scenario: A task stays unticked +- **WHEN** the model ends its run and leaves a task of the group unticked, the verification command and the static checks exit 0, and the extra turn leaves the task unticked +- **THEN** the step reports stopped, the reason names the unticked task, and the checkout is reset + +#### Scenario: A task stays unticked and a verification command fails +- **WHEN** the model ends its run and leaves a task of the group unticked, and the verification command exits 1 +- **THEN** the step reports stopped with the reason that names the command and its exit status, the model gets no extra turn, and the checkout is reset + +#### Scenario: The model changes another group +- **WHEN** the model changes the text of a task of group 2 while it works on group 1 +- **THEN** the step reports done, and the commit holds group 2 as it was + +#### Scenario: A task that the agent removes +- **WHEN** the model removes a task of group 1 from the `tasks.md` and ticks the others +- **THEN** the step ticks no task of group 1, gives the extra turn, and stops with the reason that names the first unticked task when the turn changes nothing + +#### Scenario: A task that the agent moves +- **WHEN** the model swaps the texts of two tasks of group 1 and ticks them +- **THEN** the step reports done, and the commit holds the tasks in their order from before the run, ticked + +#### Scenario: A heading that the agent changes +- **WHEN** the model changes the heading of group 1 +- **THEN** the step reports done, and the commit holds the heading from before the run + +#### Scenario: A tasks file that is gone +- **WHEN** the model removes the `tasks.md` of the change +- **THEN** the step writes the file from before the run, gives the extra turn for the unticked tasks, and stops with the reason that names the first unticked task when the turn changes nothing + +#### Scenario: A verification command outside the allowlist +- **WHEN** a Verification line of the group names `curl http://example.com` +- **THEN** the step reports stopped, the reason names `curl` as not allowed, the command does not run, and the checkout is reset + +#### Scenario: A test that the agent removes +- **WHEN** the model replaces a test file with a file that holds fewer of its tests, and ticks the tasks +- **THEN** the step reports stopped with the reason that names the file and the missing tests, no verification command runs, and the checkout is reset + +## ADDED Requirements + +### Requirement: A step keeps the tests that existed +Every test that a `.py` file under `tests/` held at the commit where the step started SHALL be in the checkout after the run, by qualified name (`test_x` or `Class.test_x`), unless the same qualified name is new in another changed test file. A test is a function named `test_*`. When a test is lost, the step SHALL stop with a reason that names the file and at most `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` of its tests, and SHALL give no extra turn. A file that does not parse is skipped. + +#### Scenario: A test file that the agent replaces +- **WHEN** a test file holds `test_a` and `test_b` at the start, and the model writes a file that holds `test_c` +- **THEN** the step reports stopped, the reason names the file, `test_a` and `test_b`, and the checkout is reset + +#### Scenario: A test that the agent adds +- **WHEN** the model adds `test_c` to a test file that holds `test_a` and `test_b` +- **THEN** the step reports done + +#### Scenario: A test that the agent renames +- **WHEN** the model renames `test_a` to `test_z` in its file +- **THEN** the step reports stopped, and the reason names `test_a` + +#### Scenario: A test file that the agent deletes +- **WHEN** the model deletes a test file that holds `test_a` +- **THEN** the step reports stopped, and the reason names the file and `test_a` + +#### Scenario: A test that the agent moves +- **WHEN** the model moves `Check.test_a` from one test file to a new test file +- **THEN** the step reports done + +#### Scenario: A file that does not parse +- **WHEN** a test file has a syntax error after the run, or at the start +- **THEN** this check does not stop the step, and the static check judges the file + +#### Scenario: A long list of lost tests +- **WHEN** the model drops more than `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` tests of a file +- **THEN** the reason names that many tests in order and gives the count of the rest diff --git a/openspec/changes/2804-step-keeps-existing-tests/tasks.md b/openspec/changes/2804-step-keeps-existing-tests/tasks.md new file mode 100644 index 0000000000..94aba2d04d --- /dev/null +++ b/openspec/changes/2804-step-keeps-existing-tests/tasks.md @@ -0,0 +1,27 @@ +# Tasks + +## 1. The names and the comparison + +- [ ] Write failing tests in `tests/test_roadmap_implement_test_names.py`: module-level and class tests get qualified names; async tests, tests in `if` and `try` blocks, and nested classes count; a parametrized test is one name; a function inside a function and a non-test function do not count; a file that does not parse gives no names; the lost names of a file that drops, renames or deletes a test; a moved test is excused by a new name in another file, and a name that the other file had before is not new; the names are sorted. + - Verification: `uv run devops ci test tests/test_roadmap_implement_test_names.py` +- [ ] Add `src/devops_cli/roadmap/implement_test_names.py` with `test_names` and `lost_tests`, built on the standard library `ast`. + - Verification: `uv run devops ci test tests/test_roadmap_implement_test_names.py` + +## 2. The exit check + +- [ ] Write failing tests in `tests/test_roadmap_implement_step_tests_kept.py`: a step that replaces a test file and drops tests stops with a reason that names the file and the tests; a step that adds a test to an existing file ends done; a step that renames a test stops; a step that deletes a test file stops; a step that moves tests to a new file ends done; a new test file and a file with a syntax error do not crash the check; a file with a syntax error after the run is judged by `ruff check` only; the reason names a bounded number of tests and files; the check runs before the verification commands; a fix step gets the check; the extra turn for a static failure cannot remove a test. + - Verification: `uv run devops ci test tests/test_roadmap_implement_step_tests_kept.py` +- [ ] Change `src/devops_cli/roadmap/implement_step.py`, `src/devops_cli/lang/en/messages.py` and `src/devops_cli/config/constants.py`: list the changed test files with git, read the text at the start commit, run the comparison and return the reason. + - Verification: `uv run devops ci test tests/test_roadmap_implement_step_tests_kept.py tests/test_roadmap_implement_step.py tests/test_roadmap_implement_step_repair.py tests/test_roadmap_implement_step_ticks.py` + +## 3. The instructions and the documentation + +- [ ] Word the rule in `src/devops_cli/ai/tasks/roadmap_implement_step.md` and in the help of `devops roadmap implement`. + - Verification: `uv run devops ci test tests/test_ai_task_implement.py tests/test_roadmap_implement_step.py` +- [ ] Regenerate the documentation. + - Verification: `uv run devops docs generate --sync-readme` and `uv run devops docs check` + +## 4. Archive + +- [ ] Archive the change. + - Verification: `uv run devops openspec archive 2804-step-keeps-existing-tests` From 2e3e2038d5af0bb7193c7b6207a016332ad675aa Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Fri, 30 Oct 2026 23:01:25 +0000 Subject: [PATCH 2/8] feat(roadmap): list the tests of a file and the tests a step loses (#2804) --- .../2804-step-keeps-existing-tests/tasks.md | 4 +- .../roadmap/implement_test_names.py | 79 +++++++++ tests/test_roadmap_implement_test_names.py | 152 ++++++++++++++++++ 3 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 src/devops_cli/roadmap/implement_test_names.py create mode 100644 tests/test_roadmap_implement_test_names.py diff --git a/openspec/changes/2804-step-keeps-existing-tests/tasks.md b/openspec/changes/2804-step-keeps-existing-tests/tasks.md index 94aba2d04d..3212b52890 100644 --- a/openspec/changes/2804-step-keeps-existing-tests/tasks.md +++ b/openspec/changes/2804-step-keeps-existing-tests/tasks.md @@ -2,9 +2,9 @@ ## 1. The names and the comparison -- [ ] Write failing tests in `tests/test_roadmap_implement_test_names.py`: module-level and class tests get qualified names; async tests, tests in `if` and `try` blocks, and nested classes count; a parametrized test is one name; a function inside a function and a non-test function do not count; a file that does not parse gives no names; the lost names of a file that drops, renames or deletes a test; a moved test is excused by a new name in another file, and a name that the other file had before is not new; the names are sorted. +- [x] Write failing tests in `tests/test_roadmap_implement_test_names.py`: module-level and class tests get qualified names; async tests, tests in `if` and `try` blocks, and nested classes count; a parametrized test is one name; a function inside a function and a non-test function do not count; a file that does not parse gives no names; the lost names of a file that drops, renames or deletes a test; a moved test is excused by a new name in another file, and a name that the other file had before is not new; the names are sorted. - Verification: `uv run devops ci test tests/test_roadmap_implement_test_names.py` -- [ ] Add `src/devops_cli/roadmap/implement_test_names.py` with `test_names` and `lost_tests`, built on the standard library `ast`. +- [x] Add `src/devops_cli/roadmap/implement_test_names.py` with `test_names` and `lost_tests`, built on the standard library `ast`. - Verification: `uv run devops ci test tests/test_roadmap_implement_test_names.py` ## 2. The exit check diff --git a/src/devops_cli/roadmap/implement_test_names.py b/src/devops_cli/roadmap/implement_test_names.py new file mode 100644 index 0000000000..36b7c71b7e --- /dev/null +++ b/src/devops_cli/roadmap/implement_test_names.py @@ -0,0 +1,79 @@ +"""The tests that a step of `devops roadmap implement` keeps (#2804): the names of the tests in a +file, and the tests that a file lost. + +A test is a function or an async function whose name starts with `test_`, at module level or in a +class, also inside an `if`, `try`, `with` or loop block. Its name is the qualified name: `test_x`, +or `Class.test_x`. The standard library `ast` lists them, so a decorator, a parameter and the body +do not matter. A function inside a function is a helper and is no test. +""" + +from __future__ import annotations + +import ast +from collections import Counter +from collections.abc import Iterator, Mapping + +_TEST_PREFIX = "test_" +_BLOCKS = (ast.stmt, ast.ExceptHandler, ast.match_case) + +# The names of the tests of one file, or None when the file does not parse. +FileTests = frozenset[str] | None + + +def _walk(node: ast.AST, prefix: str) -> Iterator[str]: + """The qualified names of the tests under `node`. The walk goes into statements only: a test is + never inside an expression.""" + for child in ast.iter_child_nodes(node): + if isinstance(child, ast.FunctionDef | ast.AsyncFunctionDef): + if child.name.startswith(_TEST_PREFIX): + yield prefix + child.name + elif isinstance(child, ast.ClassDef): + yield from _walk(child, f"{prefix}{child.name}.") + elif isinstance(child, _BLOCKS): + yield from _walk(child, prefix) + + +def defined_tests(text: str) -> FileTests: + """The qualified names of the tests in the Python source `text`, or None when it does not + parse. The caller skips such a file: the static check reports its error.""" + try: + tree = ast.parse(text) + except SyntaxError, ValueError: + return None + return frozenset(_walk(tree, "")) + + +def _new_names(before: Mapping[str, FileTests], after: Mapping[str, FileTests]) -> Counter[str]: + """How many files hold each name that the run added to them. A file that does not parse, at the + start or after the run, adds none: its list is not known.""" + added: Counter[str] = Counter() + for path, names in after.items(): + if names is None or (path in before and before[path] is None): + continue + added.update(names - (before.get(path) or frozenset())) + return added + + +def lost_tests( + before: Mapping[str, FileTests], after: Mapping[str, FileTests] +) -> dict[str, list[str]]: + """The tests that each file lost, by path in sorted order, each list sorted. `before` maps a + path to its tests at the start and `after` maps it to its tests after the run. A path that is + not in `after` was deleted, and loses every test. A path that is not in `before` is new. A file + that does not parse is skipped. A lost test is excused by a test of the same qualified name + that is new in another file, once: the test moved.""" + excuses = _new_names(before, after) + lost: dict[str, list[str]] = {} + for path in sorted(before): + started, now = before[path], after.get(path, frozenset()) + if started is None or now is None: + continue + gone = [] + for name in sorted(started - now): + if excuses[name] > 0: + excuses[name] -= 1 + else: + gone.append(name) + if gone: + lost[path] = gone + return lost diff --git a/tests/test_roadmap_implement_test_names.py b/tests/test_roadmap_implement_test_names.py new file mode 100644 index 0000000000..d9629bc279 --- /dev/null +++ b/tests/test_roadmap_implement_test_names.py @@ -0,0 +1,152 @@ +"""The names of the tests in a file and the tests that a step loses (#2804). The functions are pure: +they read the text of a file, and they do no I/O.""" + +from __future__ import annotations + +import pytest + +from devops_cli.roadmap.implement_test_names import defined_tests, lost_tests + +TESTS = """\ +import sys + +import pytest + + +def test_plain() -> None: ... + + +async def test_async() -> None: ... + + +@pytest.mark.parametrize("n", [1, 2, 3]) +def test_cases(n: int) -> None: ... + + +def helper() -> None: + def test_inside_a_function() -> None: ... + + +class TestOuter: + def test_method(self) -> None: ... + + async def test_async_method(self) -> None: ... + + def not_a_test(self) -> None: ... + + class TestInner: + def test_deep(self) -> None: ... + + +if sys.platform == "linux": + def test_on_linux() -> None: ... +else: + def test_elsewhere() -> None: ... + +try: + import tomllib +except ImportError: + def test_without_toml() -> None: ... + +with open("x") as stream: + def test_in_a_block() -> None: ... + +test_value = 1 +""" + + +def test_defined_tests_lists_the_qualified_names_of_every_test() -> None: + assert defined_tests(TESTS) == frozenset( + { + "test_plain", + "test_async", + "test_cases", + "TestOuter.test_method", + "TestOuter.test_async_method", + "TestOuter.TestInner.test_deep", + "test_on_linux", + "test_elsewhere", + "test_without_toml", + "test_in_a_block", + } + ) + + +@pytest.mark.parametrize("text", ["def test_a(:\n", "def test_a():\n x = 1\n y = 2\n", "\0"]) +def test_defined_tests_of_a_file_that_does_not_parse_is_none(text: str) -> None: + assert defined_tests(text) is None + + +def test_defined_tests_of_an_empty_file_is_empty() -> None: + assert defined_tests("") == frozenset() + + +def _names(*names: str) -> frozenset[str]: + return frozenset(names) + + +def test_a_file_that_drops_a_test_loses_it() -> None: + before = {"tests/test_a.py": _names("test_a", "test_b")} + after = {"tests/test_a.py": _names("test_a", "test_c")} + + assert lost_tests(before, after) == {"tests/test_a.py": ["test_b"]} + + +def test_a_file_that_adds_tests_loses_none() -> None: + before = {"tests/test_a.py": _names("test_a")} + after = {"tests/test_a.py": _names("test_a", "test_b")} + + assert lost_tests(before, after) == {} + + +def test_a_deleted_file_loses_all_its_tests_in_order() -> None: + before = {"tests/test_a.py": _names("test_b", "test_a", "TestC.test_d")} + + assert lost_tests(before, {}) == {"tests/test_a.py": ["TestC.test_d", "test_a", "test_b"]} + + +def test_a_new_file_loses_nothing() -> None: + assert lost_tests({}, {"tests/test_new.py": _names("test_a")}) == {} + + +def test_a_test_that_moves_to_another_file_is_not_lost() -> None: + before = {"tests/test_a.py": _names("TestA.test_x", "test_y")} + after = {"tests/test_b.py": _names("TestA.test_x", "test_y")} + + assert lost_tests(before, after) == {} + + +def test_a_name_that_the_other_file_had_before_is_not_a_move() -> None: + """File A is deleted, and file B had `test_x` already: no test moved, one was removed.""" + before = {"tests/test_a.py": _names("test_x"), "tests/test_b.py": _names("test_x", "test_z")} + after = {"tests/test_b.py": _names("test_x", "test_z", "test_w")} + + assert lost_tests(before, after) == {"tests/test_a.py": ["test_x"]} + + +def test_one_new_name_excuses_one_lost_name() -> None: + before = {"tests/test_a.py": _names("test_x"), "tests/test_b.py": _names("test_x")} + after = {"tests/test_c.py": _names("test_x")} + + assert lost_tests(before, after) == {"tests/test_b.py": ["test_x"]} + + +def test_a_renamed_test_is_lost() -> None: + before = {"tests/test_a.py": _names("test_old")} + after = {"tests/test_a.py": _names("test_new")} + + assert lost_tests(before, after) == {"tests/test_a.py": ["test_old"]} + + +def test_a_file_that_did_not_parse_at_the_start_is_skipped() -> None: + before = {"tests/test_a.py": None} + after = {"tests/test_a.py": _names("test_a")} + + assert lost_tests(before, after) == {} + + +def test_a_file_that_does_not_parse_after_the_run_is_skipped_and_excuses_nothing() -> None: + before = {"tests/test_a.py": _names("test_a"), "tests/test_b.py": _names("test_b")} + after: dict[str, frozenset[str] | None] = {"tests/test_a.py": None} + + assert lost_tests(before, after) == {"tests/test_b.py": ["test_b"]} From 31ab029a19eaf22f03b1f64b6a5b05e18a93427f Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Fri, 30 Oct 2026 23:05:50 +0000 Subject: [PATCH 3/8] fix(roadmap): a step stops when it loses a test that existed (#2804) --- .../2804-step-keeps-existing-tests/tasks.md | 4 +- src/devops_cli/config/constants.py | 3 + src/devops_cli/lang/en/messages.py | 5 + src/devops_cli/roadmap/implement_step.py | 33 +- .../roadmap/implement_test_names.py | 36 +++ .../test_roadmap_implement_step_tests_kept.py | 281 ++++++++++++++++++ 6 files changed, 355 insertions(+), 7 deletions(-) create mode 100644 tests/test_roadmap_implement_step_tests_kept.py diff --git a/openspec/changes/2804-step-keeps-existing-tests/tasks.md b/openspec/changes/2804-step-keeps-existing-tests/tasks.md index 3212b52890..769d565387 100644 --- a/openspec/changes/2804-step-keeps-existing-tests/tasks.md +++ b/openspec/changes/2804-step-keeps-existing-tests/tasks.md @@ -9,9 +9,9 @@ ## 2. The exit check -- [ ] Write failing tests in `tests/test_roadmap_implement_step_tests_kept.py`: a step that replaces a test file and drops tests stops with a reason that names the file and the tests; a step that adds a test to an existing file ends done; a step that renames a test stops; a step that deletes a test file stops; a step that moves tests to a new file ends done; a new test file and a file with a syntax error do not crash the check; a file with a syntax error after the run is judged by `ruff check` only; the reason names a bounded number of tests and files; the check runs before the verification commands; a fix step gets the check; the extra turn for a static failure cannot remove a test. +- [x] Write failing tests in `tests/test_roadmap_implement_step_tests_kept.py`: a step that replaces a test file and drops tests stops with a reason that names the file and the tests; a step that adds a test to an existing file ends done; a step that renames a test stops; a step that deletes a test file stops; a step that moves tests to a new file ends done; a new test file and a file with a syntax error do not crash the check; a file with a syntax error after the run is judged by `ruff check` only; the reason names a bounded number of tests and files; the check runs before the verification commands; a fix step gets the check; the extra turn for a static failure cannot remove a test. - Verification: `uv run devops ci test tests/test_roadmap_implement_step_tests_kept.py` -- [ ] Change `src/devops_cli/roadmap/implement_step.py`, `src/devops_cli/lang/en/messages.py` and `src/devops_cli/config/constants.py`: list the changed test files with git, read the text at the start commit, run the comparison and return the reason. +- [x] Change `src/devops_cli/roadmap/implement_step.py`, `src/devops_cli/lang/en/messages.py` and `src/devops_cli/config/constants.py`: list the changed test files with git, read the text at the start commit, run the comparison and return the reason. - Verification: `uv run devops ci test tests/test_roadmap_implement_step_tests_kept.py tests/test_roadmap_implement_step.py tests/test_roadmap_implement_step_repair.py tests/test_roadmap_implement_step_ticks.py` ## 3. The instructions and the documentation diff --git a/src/devops_cli/config/constants.py b/src/devops_cli/config/constants.py index 96f252fbd7..eaee26ba4b 100644 --- a/src/devops_cli/config/constants.py +++ b/src/devops_cli/config/constants.py @@ -3004,6 +3004,9 @@ class WebhookExposure(StrEnum): # The most paths that a reason of a stop names, and the most characters of a reason in the stop # comment (#2721). A reason may be as long as the tail of a command or a list of files. CONST_ROADMAP_IMPLEMENT_REASON_PATHS: Final[int] = 20 +# The most tests of one file that the reason of a stop for a lost test names (#2804). The reason +# gives the count of the rest. +CONST_ROADMAP_IMPLEMENT_REASON_TESTS: Final[int] = 10 CONST_ROADMAP_IMPLEMENT_REASON_CHARS: Final[int] = 4000 # The most characters of the message of a pydantic-ai error that a roadmap job keeps for the reason # of a stopped run or a warning, and the most that the masking reads (#2758, #2562). The read is a diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index 6d431dc69a..7c6727b552 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -2074,6 +2074,11 @@ class RoadmapMessages: "The agent made a symbolic link: {paths}. The step does not format a link." ) implement_stop_no_change: str = "The agent changed no file." + implement_stop_tests_lost: str = ( + "The agent removed tests that existed at the start of the step. " + "A step may add tests. It may not remove or rename one.\n{files}" + ) + implement_tests_lost_file: str = "{path}: {tests}" implement_stop_head_moved: str = ( "The agent moved HEAD from {start} to {head}. A step makes the only commit." ) diff --git a/src/devops_cli/roadmap/implement_step.py b/src/devops_cli/roadmap/implement_step.py index 5cf915a323..f6b60048a1 100644 --- a/src/devops_cli/roadmap/implement_step.py +++ b/src/devops_cli/roadmap/implement_step.py @@ -83,6 +83,7 @@ CONST_ROADMAP_IMPLEMENT_PROBLEM_HEADINGS, CONST_ROADMAP_IMPLEMENT_REASON_CHARS, CONST_ROADMAP_IMPLEMENT_REASON_PATHS, + CONST_ROADMAP_IMPLEMENT_REASON_TESTS, CONST_ROADMAP_IMPLEMENT_TOOL_MAX_CHARS, CONST_ROADMAP_IMPLEMENT_TOOL_RETRIES, CONST_ROADMAP_IMPLEMENT_TURN_RESERVE_TOKENS, @@ -101,6 +102,7 @@ record_run_spend, ) from devops_cli.roadmap.implement_shell_refusal import shell_refusal_hooks +from devops_cli.roadmap.implement_test_names import lost_since from devops_cli.roadmap.implement_tool_log import ToolCallLog from devops_cli.security.sanitizer import mask_secrets @@ -912,16 +914,34 @@ def _python_files(changed: Sequence[str]) -> list[str]: return [path for path in changed if path.endswith(".py")] -def _paths_text(names: Sequence[str]) -> str: - """`names` as one line, cut to `CONST_ROADMAP_IMPLEMENT_REASON_PATHS` paths, with the count of - the rest.""" - shown = names[:CONST_ROADMAP_IMPLEMENT_REASON_PATHS] - paths = ", ".join(shown) +def _paths_text( + names: Sequence[str], limit: int = CONST_ROADMAP_IMPLEMENT_REASON_PATHS, separator: str = ", " +) -> str: + """`names` as one line, cut to `limit` names, with the count of the rest.""" + shown = names[:limit] + paths = separator.join(shown) if len(names) > len(shown): paths += MESSAGES.roadmap.implement_paths_more.format(count=len(names) - len(shown)) return paths +def _tests_failure(source: Path, start: str) -> str | None: + """Why the step stops when a test file lost a test that it had at `start`, else None. The reason + names each file with up to `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` of its tests. A file that does + not parse is skipped: `_static_failure` reports its error.""" + lost = lost_since(lambda *args: _git_output(source, *args), start) + if not lost: + return None + texts = MESSAGES.roadmap + files = [ + texts.implement_tests_lost_file.format( + path=path, tests=_paths_text(tests, CONST_ROADMAP_IMPLEMENT_REASON_TESTS) + ) + for path, tests in lost.items() + ] + return texts.implement_stop_tests_lost.format(files=_paths_text(files, separator="\n")) + + def _link_failure(source: Path, files: Sequence[str]) -> str | None: """Why the step stops when one of `files` is a symbolic link, else None. The formatter writes through a link, also to a file outside the checkout, so no tool gets a link.""" @@ -1001,6 +1021,9 @@ def _exit_failure(source: Path, inputs: StepInputs, start: str) -> _Failure | No changed = _stage(source) if not changed: return _Failure(MESSAGES.roadmap.implement_stop_no_change) + lost = _tests_failure(source, start) + if lost: + return _Failure(lost) early = _format_failure(source, changed) or _verification_failure(source, inputs.group) if early: return _Failure(early) diff --git a/src/devops_cli/roadmap/implement_test_names.py b/src/devops_cli/roadmap/implement_test_names.py index 36b7c71b7e..9a0aa43112 100644 --- a/src/devops_cli/roadmap/implement_test_names.py +++ b/src/devops_cli/roadmap/implement_test_names.py @@ -12,8 +12,10 @@ import ast from collections import Counter from collections.abc import Iterator, Mapping +from typing import Protocol _TEST_PREFIX = "test_" +_TESTS_DIR = "tests" _BLOCKS = (ast.stmt, ast.ExceptHandler, ast.match_case) # The names of the tests of one file, or None when the file does not parse. @@ -77,3 +79,37 @@ def lost_tests( if gone: lost[path] = gone return lost + + +class GitOutput(Protocol): + """A git command in the checkout. It returns what the command printed and raises when git + fails.""" + + def __call__(self, *args: str) -> str: ... + + +def _changes(git: GitOutput, start: str) -> Iterator[tuple[str, str]]: + """The status and the path of each Python file under `tests/` that differs between the commit + `start` and the index. Renames are off, so a move is a delete plus an add whatever the git + settings are.""" + listing = git( + "diff", "--cached", "--name-status", "--no-renames", "-z", start, "--", _TESTS_DIR + ).split("\0") + for status, path in zip(listing[0::2], listing[1::2], strict=False): + if path.endswith(".py"): + yield status, path + + +def lost_since(git: GitOutput, start: str) -> dict[str, list[str]]: + """The tests that each test file lost between the commit `start` and the index, for the paths + in sorted order (`lost_tests`). The index holds the files as the commit would. A file that was + added has no tests at the start. A file that was deleted, or replaced by a link, has none + after the run.""" + before: dict[str, FileTests] = {} + after: dict[str, FileTests] = {} + for status, path in _changes(git, start): + if status != "A": + before[path] = defined_tests(git("show", f"{start}:{path}")) + if status not in ("D", "T"): + after[path] = defined_tests(git("show", f":{path}")) + return lost_tests(before, after) diff --git a/tests/test_roadmap_implement_step_tests_kept.py b/tests/test_roadmap_implement_step_tests_kept.py new file mode 100644 index 0000000000..6023b74855 --- /dev/null +++ b/tests/test_roadmap_implement_step_tests_kept.py @@ -0,0 +1,281 @@ +"""A step keeps the tests that existed when it started (#2804): for each test file that the step +changed, every test of the file at the start is still in the checkout, by qualified name. A step +that loses one stops, before the formatter and the verification commands run. + +The model is a pydantic-ai `FunctionModel` from `ModelScript`. Git runs for real on a checkout in +`tmp_path`, and every other program is answered by `process_fake`. +""" + +from __future__ import annotations + +import subprocess +from pathlib import Path +from typing import Any + +import pytest + +from devops_cli.config.constants import CONST_ROADMAP_IMPLEMENT_REASON_TESTS +from devops_cli.roadmap.implement_step import ( + FixRequest, + StepOutcome, + StepStatus, + run_fix_step, + run_step, +) +from devops_cli.roadmap.memory_store import InMemoryRoadmapStore +from tests.support.fakes.process import ProcessAnswer, ProcessCall, ProcessFake +from tests.support.implement_step import ( + SHOUT_CODE, + TASKS_PATH, + TICKED, + WINDOW, + command_text, + git, + is_clean_at, + programs_run, + write_call, +) +from tests.support.model_script import ModelScript, say, tool_calls + +pytestmark = pytest.mark.usefixtures("keyring_store") + +OLD = '''\ +"""The tests that exist.""" + + +def test_a() -> None: ... + + +async def test_b() -> None: ... + + +class TestKept: + def test_c(self) -> None: ... +''' +OLD_PATH = "tests/test_old.py" +SOURCE = write_call("src/sample.py", SHOUT_CODE) +TICK = write_call(TASKS_PATH, TICKED) +REASON = ( + "The agent removed tests that existed at the start of the step. A step may add tests. " + "It may not remove or rename one.\n" +) +SYNTAX_ERROR = "def test_a(:\n" + + +@pytest.fixture +def store(implement_store: InMemoryRoadmapStore) -> InMemoryRoadmapStore: + return implement_store + + +@pytest.fixture +def checkout(implement_checkout: Path) -> Path: + """The sample checkout with one more commit: the test file `tests/test_old.py`.""" + (implement_checkout / OLD_PATH).write_text(OLD, encoding="utf-8") + git(implement_checkout, "add", "-A") + git(implement_checkout, "commit", "-q", "-m", "add the old tests") + return implement_checkout + + +@pytest.fixture +def programs(implement_programs: ProcessFake) -> ProcessFake: + return implement_programs + + +def _run(store: InMemoryRoadmapStore, checkout: Path, script: ModelScript) -> StepOutcome: + return run_step(store, item=1, group=1, source=checkout, model=script.model(), window=WINDOW) + + +def _script(*work: tuple[str, dict[str, Any]], removes: Path | None = None) -> ModelScript: + """The agent writes the files of `work` and ticks the tasks. When it also removes a file, the + removal is scripted as an effect: the agent's shell is a process edge that a test fakes.""" + effects = {2: removes.unlink} if removes else None + return ModelScript(tool_calls(*work, TICK), say("Done."), effects=effects) + + +def _lint_fails_on(word: str, programs: ProcessFake) -> None: + def answer(call: ProcessCall) -> subprocess.CompletedProcess[str]: + assert call.cwd is not None + names = call.argv[call.argv.index("--") + 1 :] + failed = any(word in (call.cwd / name).read_text(encoding="utf-8") for name in names) + return subprocess.CompletedProcess( + call.argv, 1 if failed else 0, stdout=f"{word}: bad\n" if failed else "", stderr="" + ) + + programs.answer( + lambda call: command_text(call).startswith("uv run ruff check"), + ProcessAnswer(side_effect=answer), + ) + + +def test_a_step_that_replaces_a_test_file_and_drops_tests_stops_and_names_them( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + head = git(checkout, "rev-parse", "HEAD") + script = _script(write_call(OLD_PATH, "def test_new() -> None: ...\n"), SOURCE) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason, outcome.commit) == ( + StepStatus.STOPPED, + f"{REASON}{OLD_PATH}: TestKept.test_c, test_a, test_b", + "", + ) + assert is_clean_at(checkout, head) + + +def test_the_check_runs_before_the_formatter_and_the_verification_commands( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + script = _script(write_call(OLD_PATH, "def test_new() -> None: ...\n"), SOURCE) + + outcome = _run(store, checkout, script) + + assert outcome.status is StepStatus.STOPPED + assert programs_run(programs, "uv") == [] + assert len(script.seen) == 2 + + +def test_a_step_that_adds_a_test_to_an_existing_file_ends_done( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + script = _script(write_call(OLD_PATH, OLD + "\n\ndef test_added() -> None: ...\n"), SOURCE) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason) == (StepStatus.DONE, "") + assert "test_added" in git(checkout, "show", f"HEAD:{OLD_PATH}") + + +def test_a_step_that_renames_a_test_stops( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + script = _script(write_call(OLD_PATH, OLD.replace("def test_a(", "def test_z(")), SOURCE) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason) == (StepStatus.STOPPED, f"{REASON}{OLD_PATH}: test_a") + + +def test_a_step_that_deletes_a_test_file_stops( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + script = _script(SOURCE, removes=checkout / OLD_PATH) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason) == ( + StepStatus.STOPPED, + f"{REASON}{OLD_PATH}: TestKept.test_c, test_a, test_b", + ) + + +def test_a_step_that_moves_the_tests_to_a_new_file_ends_done( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + moved = "tests/test_moved.py" + script = _script(write_call(moved, OLD), SOURCE, removes=checkout / OLD_PATH) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason) == (StepStatus.DONE, "") + assert git(checkout, "show", f"HEAD:{moved}") + "\n" == OLD + + +def test_a_step_that_moves_only_some_of_the_tests_stops_with_the_rest( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + script = _script( + write_call("tests/test_moved.py", "def test_a() -> None: ...\n"), + SOURCE, + removes=checkout / OLD_PATH, + ) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason) == ( + StepStatus.STOPPED, + f"{REASON}{OLD_PATH}: TestKept.test_c, test_b", + ) + + +def test_a_test_file_that_did_not_parse_at_the_start_does_not_crash_the_check( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + (checkout / OLD_PATH).write_text(SYNTAX_ERROR, encoding="utf-8") + git(checkout, "commit", "-q", "-am", "break the old tests") + script = _script(write_call(OLD_PATH, OLD), SOURCE) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason) == (StepStatus.DONE, "") + + +def test_a_test_file_that_does_not_parse_after_the_run_is_judged_by_the_static_check_alone( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + _lint_fails_on("def test_a(:", programs) + script = ModelScript( + tool_calls(write_call(OLD_PATH, SYNTAX_ERROR), SOURCE, TICK), say("Done."), say("No fix.") + ) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason) == ( + StepStatus.STOPPED, + f"uv run ruff check -- src/sample.py {OLD_PATH} exited with status 1.\ndef test_a(:: bad", + ) + + +def test_the_reason_names_a_bounded_number_of_tests( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + count = CONST_ROADMAP_IMPLEMENT_REASON_TESTS + 2 + many = "".join(f"def test_{n:02d}() -> None: ...\n" for n in range(count)) + (checkout / OLD_PATH).write_text(many, encoding="utf-8") + git(checkout, "commit", "-q", "-am", "many tests") + script = _script(write_call(OLD_PATH, "def test_new() -> None: ...\n"), SOURCE) + + outcome = _run(store, checkout, script) + + names = ", ".join(f"test_{n:02d}" for n in range(CONST_ROADMAP_IMPLEMENT_REASON_TESTS)) + assert outcome.reason == f"{REASON}{OLD_PATH}: {names} and 2 more" + + +def test_a_fix_step_keeps_the_tests_as_well( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + script = ModelScript( + tool_calls(SOURCE), say("Done."), effects={2: (checkout / OLD_PATH).unlink} + ) + + outcome = run_fix_step( + store, + item=1, + fix=FixRequest(check="Static Analysis", log="E501"), + source=checkout, + model=script.model(), + window=WINDOW, + ) + + assert (outcome.status, outcome.commit) == (StepStatus.STOPPED, "") + assert outcome.reason.startswith(REASON) + + +def test_the_extra_turn_for_a_static_failure_cannot_remove_a_test( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + _lint_fails_on("import os", programs) + added = OLD + "\n\ndef test_added() -> None: ...\n" + script = ModelScript( + tool_calls(write_call(OLD_PATH, "import os\n" + added), SOURCE, TICK), + say("Done."), + tool_calls(write_call(OLD_PATH, "def test_added() -> None: ...\n")), + say("Fixed."), + ) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason) == ( + StepStatus.STOPPED, + f"{REASON}{OLD_PATH}: TestKept.test_c, test_a, test_b", + ) From b6b9a366901038f99d0b71bb4e683a28617ee49e Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Fri, 30 Oct 2026 23:06:47 +0000 Subject: [PATCH 4/8] docs(roadmap): tell the agent and the help that a step keeps its tests (#2804) --- README.md | 2 +- docs/CLI_REFERENCE.md | 2 +- docs/commands/roadmap.md | 2 +- openspec/changes/2804-step-keeps-existing-tests/tasks.md | 4 ++-- src/devops_cli/ai/tasks/roadmap_implement_step.md | 1 + src/devops_cli/lang/en/help.py | 3 ++- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d3c76ae6b2..763bbc7a71 100644 --- a/README.md +++ b/README.md @@ -376,7 +376,7 @@ and excessive permissions fail it, and every other finding is shown. | | | `devops roadmap alternatives [OPTIONS]` | Check open items for an open, maintained tool or library that already covers their need, in whole or in part. For each item, one agent run searches the web with Firecrawl and reads the facts of each candidate from GitHub and PyPI: its license, its last activity and whether it is archived. The verdict is covers, partly, none or not-applicable. With --confirm, a check posts one comment, replaces the block `devops-roadmap-alternatives` in the item's body, and records the check in the job record. It changes no label and closes no issue. A person decides what a tool means for the item. The run takes open New and Ready items that a person with write access opened: first the items with no check, lowest number first, then the items whose check is older than roadmap.alternatives.recheck_days or whose text changed since. The check is off, and the plan says why, for a private repository or with no Firecrawl key. An item whose model call fails or whose reply cites a URL that no tool returned is skipped and reported; the others are written, and the command then exits 1. | | | `devops roadmap stage [OPTIONS]` | Make Ready items Staged: for each item that a label filter names, make the branch \/\-\ at the fetched default branch, write the OpenSpec change of the item in task groups that each fit the step budget, make one commit as the identity of the session, push it, and open a draft pull request whose title is `docs(openspec): plan # ` and whose body starts with `Plans #` and holds no closing keyword. The branch keeps the type of the issue. The Status of the item stays Ready, and the job never marks the pull request ready. One comment on the issue names the branch, the pull request and the task groups with their measures. The default filter is status=ready, priority=p0-critical, priority=p1-high and type=bug. The job leaves out an item that is not Ready, an item with the label needs-split, an item that an account without write access opened, an item that depends on an open issue, an item that a pushed branch or a worktree holds, an item whose plan is on the default branch or whose change is archived there, and an item whose text looks like a secret; the plan says why. A task group over the budget goes back to the model once, and a group still over it stops the item. An item whose model call fails is skipped and reported, the others are still staged, and the command then exits 1. Each run also removes the draft and the branch of a closed item when only the identity of the session wrote to them. | | | `devops roadmap run [OPTIONS]` | Run the roadmap jobs that are due, in order: metrics, then intake, refine and the alternatives check, and record each one's last success. Intake is due on an issue reopened, and decides at most 5 candidates a run and keeps a record of those it left beside the schedule; refine is due every hour, on a first run, and after an intake that placed a critical fix or a P0 item; the alternatives check is due once a day and on a first run, and checks at most roadmap.alternatives.limit items. Without --confirm, or with --dry-run, prints the due list and runs nothing. | -| | `devops roadmap implement [OPTIONS]` | Implement a Staged item, in bounded steps. With --group it runs one task group of the change of an item in the checkout --source: the agent is pydantic-ai's Coder on the model of ai.tasks.implement. Its inputs are the item's title, problem and acceptance criteria, the change's proposal, design and tasks, the group, and the files the group names. The command refuses to start when they do not fit the window of the task, or when the checkout has uncommitted changes. The shell of the agent runs only git, uv, ruff and mypy, with a scratch home. When the agent returns, the command runs the verification commands of the group and ruff and mypy on the changed Python files, and checks that the agent made no commit and every task of the group is ticked. The command writes the tasks file back to its text before the run and keeps only the ticks of the group, so no edit of that file stops the step. An agent that forgets a tick gets one more turn that asks only for the ticks, and that may change only the tasks file. When every check passes, it commits the checkout as ' (#\)'. Otherwise it resets the checkout to the commit where the step started, reports the step as stopped with the reason and the masked diff of the work it discarded, and exits 1. It writes nothing to GitHub. Without --group it is the job. It takes each Staged or Planned item that a label filter names (default: status=ready, priority=p0-critical, priority=p1-high, type=bug, effort=low). A Staged item has its staged branch and draft on origin. A Planned item has its change folder on the default branch and no branch: the job makes the branch \/\-\ there, with the slug of the folder, and opens the draft when the branch first holds a commit. The job rebases the branch, runs a step for each task group that has an unticked task, regenerates the documentation, archives the change, pushes, sets the title and the body of the pull request (the title of the issue, and a body that closes it), watches the checks, runs one fix step for a failed check, and marks the pull request ready. A step that fails stops the item: the job comments why and shows the masked diff of the discarded work, sets the Status to Ready, and runs the item again only after a comment 'implement: retry'. The job never merges. --confirm runs steps only when the setting roadmap.implement.in_runner is true, which only the pod of a runner Job sets: the shell of the agent is no security boundary. | +| | `devops roadmap implement [OPTIONS]` | Implement a Staged item, in bounded steps. With --group it runs one task group of the change of an item in the checkout --source: the agent is pydantic-ai's Coder on the model of ai.tasks.implement. Its inputs are the item's title, problem and acceptance criteria, the change's proposal, design and tasks, the group, and the files the group names. The command refuses to start when they do not fit the window of the task, or when the checkout has uncommitted changes. The shell of the agent runs only git, uv, ruff and mypy, with a scratch home. When the agent returns, the command runs the verification commands of the group and ruff and mypy on the changed Python files, and checks that the agent made no commit, removed or renamed no test that existed at the start of the step, and ticked every task of the group. The command writes the tasks file back to its text before the run and keeps only the ticks of the group, so no edit of that file stops the step. An agent that forgets a tick gets one more turn that asks only for the ticks, and that may change only the tasks file. When every check passes, it commits the checkout as ' (#\)'. Otherwise it resets the checkout to the commit where the step started, reports the step as stopped with the reason and the masked diff of the work it discarded, and exits 1. It writes nothing to GitHub. Without --group it is the job. It takes each Staged or Planned item that a label filter names (default: status=ready, priority=p0-critical, priority=p1-high, type=bug, effort=low). A Staged item has its staged branch and draft on origin. A Planned item has its change folder on the default branch and no branch: the job makes the branch \/\-\ there, with the slug of the folder, and opens the draft when the branch first holds a commit. The job rebases the branch, runs a step for each task group that has an unticked task, regenerates the documentation, archives the change, pushes, sets the title and the body of the pull request (the title of the issue, and a body that closes it), watches the checks, runs one fix step for a failed check, and marks the pull request ready. A step that fails stops the item: the job comments why and shows the masked diff of the discarded work, sets the Status to Ready, and runs the item again only after a comment 'implement: retry'. The job never merges. --confirm runs steps only when the setting roadmap.implement.in_runner is true, which only the pod of a runner Job sets: the shell of the agent is no security boundary. | | | `devops roadmap return [OPTIONS] ` | Return an item to New with an evidence comment, handing it back to refinement when it cannot be built as specified or needs a refactor beyond its scope. The item gets the label status/new in place of its other status/* label. | | [**pr**](docs/commands/pr.md) | `devops pr list [OPTIONS]` | List pull requests with base targeting and review status. | | | `devops pr view [OPTIONS] ` | View details of a pull request. | diff --git a/docs/CLI_REFERENCE.md b/docs/CLI_REFERENCE.md index 63a4c1aa37..eaa762a8e8 100644 --- a/docs/CLI_REFERENCE.md +++ b/docs/CLI_REFERENCE.md @@ -6471,7 +6471,7 @@ devops roadmap run [OPTIONS] ### `devops roadmap implement` -**Implement a Staged item, in bounded steps. With --group it runs one task group of the change of an item in the checkout --source: the agent is pydantic-ai's Coder on the model of ai.tasks.implement. Its inputs are the item's title, problem and acceptance criteria, the change's proposal, design and tasks, the group, and the files the group names. The command refuses to start when they do not fit the window of the task, or when the checkout has uncommitted changes. The shell of the agent runs only git, uv, ruff and mypy, with a scratch home. When the agent returns, the command runs the verification commands of the group and ruff and mypy on the changed Python files, and checks that the agent made no commit and every task of the group is ticked. The command writes the tasks file back to its text before the run and keeps only the ticks of the group, so no edit of that file stops the step. An agent that forgets a tick gets one more turn that asks only for the ticks, and that may change only the tasks file. When every check passes, it commits the checkout as ' (#\)'. Otherwise it resets the checkout to the commit where the step started, reports the step as stopped with the reason and the masked diff of the work it discarded, and exits 1. It writes nothing to GitHub. Without --group it is the job. It takes each Staged or Planned item that a label filter names (default: status=ready, priority=p0-critical, priority=p1-high, type=bug, effort=low). A Staged item has its staged branch and draft on origin. A Planned item has its change folder on the default branch and no branch: the job makes the branch \/\-\ there, with the slug of the folder, and opens the draft when the branch first holds a commit. The job rebases the branch, runs a step for each task group that has an unticked task, regenerates the documentation, archives the change, pushes, sets the title and the body of the pull request (the title of the issue, and a body that closes it), watches the checks, runs one fix step for a failed check, and marks the pull request ready. A step that fails stops the item: the job comments why and shows the masked diff of the discarded work, sets the Status to Ready, and runs the item again only after a comment 'implement: retry'. The job never merges. --confirm runs steps only when the setting roadmap.implement.in_runner is true, which only the pod of a runner Job sets: the shell of the agent is no security boundary.** +**Implement a Staged item, in bounded steps. With --group it runs one task group of the change of an item in the checkout --source: the agent is pydantic-ai's Coder on the model of ai.tasks.implement. Its inputs are the item's title, problem and acceptance criteria, the change's proposal, design and tasks, the group, and the files the group names. The command refuses to start when they do not fit the window of the task, or when the checkout has uncommitted changes. The shell of the agent runs only git, uv, ruff and mypy, with a scratch home. When the agent returns, the command runs the verification commands of the group and ruff and mypy on the changed Python files, and checks that the agent made no commit, removed or renamed no test that existed at the start of the step, and ticked every task of the group. The command writes the tasks file back to its text before the run and keeps only the ticks of the group, so no edit of that file stops the step. An agent that forgets a tick gets one more turn that asks only for the ticks, and that may change only the tasks file. When every check passes, it commits the checkout as ' (#\)'. Otherwise it resets the checkout to the commit where the step started, reports the step as stopped with the reason and the masked diff of the work it discarded, and exits 1. It writes nothing to GitHub. Without --group it is the job. It takes each Staged or Planned item that a label filter names (default: status=ready, priority=p0-critical, priority=p1-high, type=bug, effort=low). A Staged item has its staged branch and draft on origin. A Planned item has its change folder on the default branch and no branch: the job makes the branch \/\-\ there, with the slug of the folder, and opens the draft when the branch first holds a commit. The job rebases the branch, runs a step for each task group that has an unticked task, regenerates the documentation, archives the change, pushes, sets the title and the body of the pull request (the title of the issue, and a body that closes it), watches the checks, runs one fix step for a failed check, and marks the pull request ready. A step that fails stops the item: the job comments why and shows the masked diff of the discarded work, sets the Status to Ready, and runs the item again only after a comment 'implement: retry'. The job never merges. --confirm runs steps only when the setting roadmap.implement.in_runner is true, which only the pod of a runner Job sets: the shell of the agent is no security boundary.** ```bash devops roadmap implement [OPTIONS] diff --git a/docs/commands/roadmap.md b/docs/commands/roadmap.md index 09f19e83b8..bd2ea435dd 100644 --- a/docs/commands/roadmap.md +++ b/docs/commands/roadmap.md @@ -132,7 +132,7 @@ devops roadmap run [OPTIONS] ## `devops roadmap implement` -**Implement a Staged item, in bounded steps. With --group it runs one task group of the change of an item in the checkout --source: the agent is pydantic-ai's Coder on the model of ai.tasks.implement. Its inputs are the item's title, problem and acceptance criteria, the change's proposal, design and tasks, the group, and the files the group names. The command refuses to start when they do not fit the window of the task, or when the checkout has uncommitted changes. The shell of the agent runs only git, uv, ruff and mypy, with a scratch home. When the agent returns, the command runs the verification commands of the group and ruff and mypy on the changed Python files, and checks that the agent made no commit and every task of the group is ticked. The command writes the tasks file back to its text before the run and keeps only the ticks of the group, so no edit of that file stops the step. An agent that forgets a tick gets one more turn that asks only for the ticks, and that may change only the tasks file. When every check passes, it commits the checkout as ' (#\)'. Otherwise it resets the checkout to the commit where the step started, reports the step as stopped with the reason and the masked diff of the work it discarded, and exits 1. It writes nothing to GitHub. Without --group it is the job. It takes each Staged or Planned item that a label filter names (default: status=ready, priority=p0-critical, priority=p1-high, type=bug, effort=low). A Staged item has its staged branch and draft on origin. A Planned item has its change folder on the default branch and no branch: the job makes the branch \/\-\ there, with the slug of the folder, and opens the draft when the branch first holds a commit. The job rebases the branch, runs a step for each task group that has an unticked task, regenerates the documentation, archives the change, pushes, sets the title and the body of the pull request (the title of the issue, and a body that closes it), watches the checks, runs one fix step for a failed check, and marks the pull request ready. A step that fails stops the item: the job comments why and shows the masked diff of the discarded work, sets the Status to Ready, and runs the item again only after a comment 'implement: retry'. The job never merges. --confirm runs steps only when the setting roadmap.implement.in_runner is true, which only the pod of a runner Job sets: the shell of the agent is no security boundary.** +**Implement a Staged item, in bounded steps. With --group it runs one task group of the change of an item in the checkout --source: the agent is pydantic-ai's Coder on the model of ai.tasks.implement. Its inputs are the item's title, problem and acceptance criteria, the change's proposal, design and tasks, the group, and the files the group names. The command refuses to start when they do not fit the window of the task, or when the checkout has uncommitted changes. The shell of the agent runs only git, uv, ruff and mypy, with a scratch home. When the agent returns, the command runs the verification commands of the group and ruff and mypy on the changed Python files, and checks that the agent made no commit, removed or renamed no test that existed at the start of the step, and ticked every task of the group. The command writes the tasks file back to its text before the run and keeps only the ticks of the group, so no edit of that file stops the step. An agent that forgets a tick gets one more turn that asks only for the ticks, and that may change only the tasks file. When every check passes, it commits the checkout as ' (#\)'. Otherwise it resets the checkout to the commit where the step started, reports the step as stopped with the reason and the masked diff of the work it discarded, and exits 1. It writes nothing to GitHub. Without --group it is the job. It takes each Staged or Planned item that a label filter names (default: status=ready, priority=p0-critical, priority=p1-high, type=bug, effort=low). A Staged item has its staged branch and draft on origin. A Planned item has its change folder on the default branch and no branch: the job makes the branch \/\-\ there, with the slug of the folder, and opens the draft when the branch first holds a commit. The job rebases the branch, runs a step for each task group that has an unticked task, regenerates the documentation, archives the change, pushes, sets the title and the body of the pull request (the title of the issue, and a body that closes it), watches the checks, runs one fix step for a failed check, and marks the pull request ready. A step that fails stops the item: the job comments why and shows the masked diff of the discarded work, sets the Status to Ready, and runs the item again only after a comment 'implement: retry'. The job never merges. --confirm runs steps only when the setting roadmap.implement.in_runner is true, which only the pod of a runner Job sets: the shell of the agent is no security boundary.** ```bash devops roadmap implement [OPTIONS] diff --git a/openspec/changes/2804-step-keeps-existing-tests/tasks.md b/openspec/changes/2804-step-keeps-existing-tests/tasks.md index 769d565387..ec6a597fab 100644 --- a/openspec/changes/2804-step-keeps-existing-tests/tasks.md +++ b/openspec/changes/2804-step-keeps-existing-tests/tasks.md @@ -16,9 +16,9 @@ ## 3. The instructions and the documentation -- [ ] Word the rule in `src/devops_cli/ai/tasks/roadmap_implement_step.md` and in the help of `devops roadmap implement`. +- [x] Word the rule in `src/devops_cli/ai/tasks/roadmap_implement_step.md` and in the help of `devops roadmap implement`. - Verification: `uv run devops ci test tests/test_ai_task_implement.py tests/test_roadmap_implement_step.py` -- [ ] Regenerate the documentation. +- [x] Regenerate the documentation. - Verification: `uv run devops docs generate --sync-readme` and `uv run devops docs check` ## 4. Archive diff --git a/src/devops_cli/ai/tasks/roadmap_implement_step.md b/src/devops_cli/ai/tasks/roadmap_implement_step.md index 76890ea150..5b644ce767 100644 --- a/src/devops_cli/ai/tasks/roadmap_implement_step.md +++ b/src/devops_cli/ai/tasks/roadmap_implement_step.md @@ -17,6 +17,7 @@ Keep these rules of the project: - Use an open library or the standard library before you write a helper. Do not write your own parser for URLs, IP addresses, paths or Markdown. - Write no code in the product that detects a test. A test doubles only the edges of the process: another program, the network, the clock and the keyring. - Swallow no error. Fix a defect at its cause. +- Keep every test that exists. You may add tests. Do not remove, rename or replace a test. A test that you move to another file keeps its name. If a step loses a test, it stops and all your work is lost. To change a test file, add to it or edit the test. - Keep the complexity of a function at 10 or less, and its nesting at 5 or less. - Write the prose of documents, messages and comments in simple, short sentences. - Write no secret, internal host name, private IP address or e-mail address. Use `example.com` and the addresses of RFC 5737. diff --git a/src/devops_cli/lang/en/help.py b/src/devops_cli/lang/en/help.py index 87aba37374..2f22dff3ab 100644 --- a/src/devops_cli/lang/en/help.py +++ b/src/devops_cli/lang/en/help.py @@ -1317,7 +1317,8 @@ class RoadmapCommandHelp: "checkout has uncommitted changes. The shell of the agent runs only git, uv, ruff and " "mypy, with a scratch home. When the agent returns, the command runs the verification " "commands of the group and ruff and mypy on the changed Python files, and checks that " - "the agent made no commit and every task of the group is ticked. The command writes the " + "the agent made no commit, removed or renamed no test that existed at the start of the " + "step, and ticked every task of the group. The command writes the " "tasks file back to its text before the run and keeps only the ticks of the group, so no " "edit of that file stops the step. " "An agent that forgets a tick gets one more turn that asks only for the ticks, and that " From 9cd1769609c9aae49ffeba8de618b57a14cda37b Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Fri, 30 Oct 2026 23:07:23 +0000 Subject: [PATCH 5/8] test(roadmap): read the reason limit when the test runs (#2804) --- tests/test_roadmap_implement_step_tests_kept.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_roadmap_implement_step_tests_kept.py b/tests/test_roadmap_implement_step_tests_kept.py index 6023b74855..031eecd90f 100644 --- a/tests/test_roadmap_implement_step_tests_kept.py +++ b/tests/test_roadmap_implement_step_tests_kept.py @@ -14,7 +14,7 @@ import pytest -from devops_cli.config.constants import CONST_ROADMAP_IMPLEMENT_REASON_TESTS +from devops_cli.config import constants from devops_cli.roadmap.implement_step import ( FixRequest, StepOutcome, @@ -229,7 +229,7 @@ def test_a_test_file_that_does_not_parse_after_the_run_is_judged_by_the_static_c def test_the_reason_names_a_bounded_number_of_tests( store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake ) -> None: - count = CONST_ROADMAP_IMPLEMENT_REASON_TESTS + 2 + count = constants.CONST_ROADMAP_IMPLEMENT_REASON_TESTS + 2 many = "".join(f"def test_{n:02d}() -> None: ...\n" for n in range(count)) (checkout / OLD_PATH).write_text(many, encoding="utf-8") git(checkout, "commit", "-q", "-am", "many tests") @@ -237,7 +237,9 @@ def test_the_reason_names_a_bounded_number_of_tests( outcome = _run(store, checkout, script) - names = ", ".join(f"test_{n:02d}" for n in range(CONST_ROADMAP_IMPLEMENT_REASON_TESTS)) + names = ", ".join( + f"test_{n:02d}" for n in range(constants.CONST_ROADMAP_IMPLEMENT_REASON_TESTS) + ) assert outcome.reason == f"{REASON}{OLD_PATH}: {names} and 2 more" From 875d60ab3abfc4c959375ece6828fcf6710a0213 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Fri, 30 Oct 2026 23:11:39 +0000 Subject: [PATCH 6/8] docs(openspec): archive the change that keeps the existing tests (#2804) --- .../.openspec.yaml | 0 .../design.md | 0 .../proposal.md | 0 .../specs/roadmap-implement-step/spec.md | 0 .../tasks.md | 2 +- openspec/specs/roadmap-implement-step/spec.md | 37 ++++++++++++++++++- 6 files changed, 37 insertions(+), 2 deletions(-) rename openspec/changes/{2804-step-keeps-existing-tests => archive/2026-10-30-2804-step-keeps-existing-tests}/.openspec.yaml (100%) rename openspec/changes/{2804-step-keeps-existing-tests => archive/2026-10-30-2804-step-keeps-existing-tests}/design.md (100%) rename openspec/changes/{2804-step-keeps-existing-tests => archive/2026-10-30-2804-step-keeps-existing-tests}/proposal.md (100%) rename openspec/changes/{2804-step-keeps-existing-tests => archive/2026-10-30-2804-step-keeps-existing-tests}/specs/roadmap-implement-step/spec.md (100%) rename openspec/changes/{2804-step-keeps-existing-tests => archive/2026-10-30-2804-step-keeps-existing-tests}/tasks.md (99%) diff --git a/openspec/changes/2804-step-keeps-existing-tests/.openspec.yaml b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/.openspec.yaml similarity index 100% rename from openspec/changes/2804-step-keeps-existing-tests/.openspec.yaml rename to openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/.openspec.yaml diff --git a/openspec/changes/2804-step-keeps-existing-tests/design.md b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/design.md similarity index 100% rename from openspec/changes/2804-step-keeps-existing-tests/design.md rename to openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/design.md diff --git a/openspec/changes/2804-step-keeps-existing-tests/proposal.md b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/proposal.md similarity index 100% rename from openspec/changes/2804-step-keeps-existing-tests/proposal.md rename to openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/proposal.md diff --git a/openspec/changes/2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md similarity index 100% rename from openspec/changes/2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md rename to openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md diff --git a/openspec/changes/2804-step-keeps-existing-tests/tasks.md b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/tasks.md similarity index 99% rename from openspec/changes/2804-step-keeps-existing-tests/tasks.md rename to openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/tasks.md index ec6a597fab..03059a236a 100644 --- a/openspec/changes/2804-step-keeps-existing-tests/tasks.md +++ b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/tasks.md @@ -23,5 +23,5 @@ ## 4. Archive -- [ ] Archive the change. +- [x] Archive the change. - Verification: `uv run devops openspec archive 2804-step-keeps-existing-tests` diff --git a/openspec/specs/roadmap-implement-step/spec.md b/openspec/specs/roadmap-implement-step/spec.md index aae626c7a1..15419bcec6 100644 --- a/openspec/specs/roadmap-implement-step/spec.md +++ b/openspec/specs/roadmap-implement-step/spec.md @@ -13,7 +13,7 @@ What `devops roadmap implement` reads, runs, checks, commits and reports when it - **THEN** the step reports done, the checkout holds one new commit titled `The first group (#7)`, that commit holds the three files, and the tasks of group 1 are ticked in the commit ### Requirement: A failed exit check stops the step and resets the checkout -The exit checks SHALL run in this order: the agent made no commit, each verification command passes, the static checks pass, and every task of the group is ticked. The step SHALL stop at the first check that fails, name it as the reason, make no commit, and reset the checkout. A failed static check, and a task left unticked after the first three checks, first get the extra turn of their own requirements. +The exit checks SHALL run in this order: the agent made no commit, no test that existed at the start is lost, each verification command passes, the static checks pass, and every task of the group is ticked. The step SHALL stop at the first check that fails, name it as the reason, make no commit, and reset the checkout. A failed static check, and a task left unticked after the first four checks, first get the extra turn of their own requirements. #### Scenario: A verification command fails - **WHEN** the model ends its run with the files written and the tasks ticked, and the verification command exits 1 @@ -55,6 +55,10 @@ The exit checks SHALL run in this order: the agent made no commit, each verifica - **WHEN** a Verification line of the group names `curl http://example.com` - **THEN** the step reports stopped, the reason names `curl` as not allowed, the command does not run, and the checkout is reset +#### Scenario: A test that the agent removes +- **WHEN** the model replaces a test file with a file that holds fewer of its tests, and ticks the tasks +- **THEN** the step reports stopped with the reason that names the file and the missing tests, no verification command runs, and the checkout is reset + ### Requirement: A step makes the only commit The first exit check SHALL be that `HEAD` is still the commit where the step started. @@ -564,3 +568,34 @@ The turn for a failed static check SHALL change no file except `tasks.md` and th #### Scenario: The turn changes a file that the step changed - **WHEN** the model changes `src/sample.py` in the extra turn, and the step had changed it - **THEN** the step checks all exit checks again and does not stop for the change + +### Requirement: A step keeps the tests that existed +Every test that a `.py` file under `tests/` held at the commit where the step started SHALL be in the checkout after the run, by qualified name (`test_x` or `Class.test_x`), unless the same qualified name is new in another changed test file. A test is a function named `test_*`. When a test is lost, the step SHALL stop with a reason that names the file and at most `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` of its tests, and SHALL give no extra turn. A file that does not parse is skipped. + +#### Scenario: A test file that the agent replaces +- **WHEN** a test file holds `test_a` and `test_b` at the start, and the model writes a file that holds `test_c` +- **THEN** the step reports stopped, the reason names the file, `test_a` and `test_b`, and the checkout is reset + +#### Scenario: A test that the agent adds +- **WHEN** the model adds `test_c` to a test file that holds `test_a` and `test_b` +- **THEN** the step reports done + +#### Scenario: A test that the agent renames +- **WHEN** the model renames `test_a` to `test_z` in its file +- **THEN** the step reports stopped, and the reason names `test_a` + +#### Scenario: A test file that the agent deletes +- **WHEN** the model deletes a test file that holds `test_a` +- **THEN** the step reports stopped, and the reason names the file and `test_a` + +#### Scenario: A test that the agent moves +- **WHEN** the model moves `Check.test_a` from one test file to a new test file +- **THEN** the step reports done + +#### Scenario: A file that does not parse +- **WHEN** a test file has a syntax error after the run, or at the start +- **THEN** this check does not stop the step, and the static check judges the file + +#### Scenario: A long list of lost tests +- **WHEN** the model drops more than `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` tests of a file +- **THEN** the reason names that many tests in order and gives the count of the rest From 899bc2dab26d4f2b17cde6a0386ec6e9d9f78051 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Fri, 30 Oct 2026 23:18:08 +0000 Subject: [PATCH 7/8] fix(roadmap): a test stays in its own file and a BOM hides no test (#2804) A test that moved to another file excused its loss by name. A file that pytest does not collect could hide the loss. Now every test stays in its own file, as the issue asks. A byte order mark at the start of a file no longer makes the check skip the file. --- .../ai/tasks/roadmap_implement_step.md | 2 +- .../roadmap/implement_test_names.py | 33 +++++-------------- .../test_roadmap_implement_step_tests_kept.py | 33 ++++++++++++------- tests/test_roadmap_implement_test_names.py | 26 +++++---------- 4 files changed, 40 insertions(+), 54 deletions(-) diff --git a/src/devops_cli/ai/tasks/roadmap_implement_step.md b/src/devops_cli/ai/tasks/roadmap_implement_step.md index 5b644ce767..db843646f7 100644 --- a/src/devops_cli/ai/tasks/roadmap_implement_step.md +++ b/src/devops_cli/ai/tasks/roadmap_implement_step.md @@ -17,7 +17,7 @@ Keep these rules of the project: - Use an open library or the standard library before you write a helper. Do not write your own parser for URLs, IP addresses, paths or Markdown. - Write no code in the product that detects a test. A test doubles only the edges of the process: another program, the network, the clock and the keyring. - Swallow no error. Fix a defect at its cause. -- Keep every test that exists. You may add tests. Do not remove, rename or replace a test. A test that you move to another file keeps its name. If a step loses a test, it stops and all your work is lost. To change a test file, add to it or edit the test. +- Keep every test that exists. You may add tests. Do not remove, rename or replace a test. If a step loses a test, it stops and all your work is lost. To change a test file, add to it or edit the test. - Keep the complexity of a function at 10 or less, and its nesting at 5 or less. - Write the prose of documents, messages and comments in simple, short sentences. - Write no secret, internal host name, private IP address or e-mail address. Use `example.com` and the addresses of RFC 5737. diff --git a/src/devops_cli/roadmap/implement_test_names.py b/src/devops_cli/roadmap/implement_test_names.py index 9a0aa43112..95bcaf8aeb 100644 --- a/src/devops_cli/roadmap/implement_test_names.py +++ b/src/devops_cli/roadmap/implement_test_names.py @@ -1,21 +1,23 @@ """The tests that a step of `devops roadmap implement` keeps (#2804): the names of the tests in a -file, and the tests that a file lost. +file, and the tests that a file lost. Every test stays in its own file. A test is a function or an async function whose name starts with `test_`, at module level or in a class, also inside an `if`, `try`, `with` or loop block. Its name is the qualified name: `test_x`, or `Class.test_x`. The standard library `ast` lists them, so a decorator, a parameter and the body -do not matter. A function inside a function is a helper and is no test. +do not matter. A function inside a function is a helper and is no test. A byte order mark at the +start of a file does not matter. The check has known limits: it reads names, so a test that keeps +its name and loses its body, and a test that an `if False:` block hides, are not found. """ from __future__ import annotations import ast -from collections import Counter from collections.abc import Iterator, Mapping from typing import Protocol _TEST_PREFIX = "test_" _TESTS_DIR = "tests" +_BYTE_ORDER_MARK = "\ufeff" _BLOCKS = (ast.stmt, ast.ExceptHandler, ast.match_case) # The names of the tests of one file, or None when the file does not parse. @@ -39,43 +41,26 @@ def defined_tests(text: str) -> FileTests: """The qualified names of the tests in the Python source `text`, or None when it does not parse. The caller skips such a file: the static check reports its error.""" try: - tree = ast.parse(text) + tree = ast.parse(text.removeprefix(_BYTE_ORDER_MARK)) except SyntaxError, ValueError: return None return frozenset(_walk(tree, "")) -def _new_names(before: Mapping[str, FileTests], after: Mapping[str, FileTests]) -> Counter[str]: - """How many files hold each name that the run added to them. A file that does not parse, at the - start or after the run, adds none: its list is not known.""" - added: Counter[str] = Counter() - for path, names in after.items(): - if names is None or (path in before and before[path] is None): - continue - added.update(names - (before.get(path) or frozenset())) - return added - - def lost_tests( before: Mapping[str, FileTests], after: Mapping[str, FileTests] ) -> dict[str, list[str]]: """The tests that each file lost, by path in sorted order, each list sorted. `before` maps a path to its tests at the start and `after` maps it to its tests after the run. A path that is not in `after` was deleted, and loses every test. A path that is not in `before` is new. A file - that does not parse is skipped. A lost test is excused by a test of the same qualified name - that is new in another file, once: the test moved.""" - excuses = _new_names(before, after) + that does not parse is skipped. Every test stays in its own file: a test that moves to another + file is lost.""" lost: dict[str, list[str]] = {} for path in sorted(before): started, now = before[path], after.get(path, frozenset()) if started is None or now is None: continue - gone = [] - for name in sorted(started - now): - if excuses[name] > 0: - excuses[name] -= 1 - else: - gone.append(name) + gone = sorted(started - now) if gone: lost[path] = gone return lost diff --git a/tests/test_roadmap_implement_step_tests_kept.py b/tests/test_roadmap_implement_step_tests_kept.py index 031eecd90f..17fd029547 100644 --- a/tests/test_roadmap_implement_step_tests_kept.py +++ b/tests/test_roadmap_implement_step_tests_kept.py @@ -169,32 +169,43 @@ def test_a_step_that_deletes_a_test_file_stops( ) -def test_a_step_that_moves_the_tests_to_a_new_file_ends_done( +def test_a_step_that_moves_the_tests_to_a_new_file_stops( store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake ) -> None: - moved = "tests/test_moved.py" - script = _script(write_call(moved, OLD), SOURCE, removes=checkout / OLD_PATH) + """Every test stays in its file. A person moves tests in a pull request of their own.""" + script = _script(write_call("tests/test_moved.py", OLD), SOURCE, removes=checkout / OLD_PATH) outcome = _run(store, checkout, script) - assert (outcome.status, outcome.reason) == (StepStatus.DONE, "") - assert git(checkout, "show", f"HEAD:{moved}") + "\n" == OLD + assert (outcome.status, outcome.reason) == ( + StepStatus.STOPPED, + f"{REASON}{OLD_PATH}: TestKept.test_c, test_a, test_b", + ) -def test_a_step_that_moves_only_some_of_the_tests_stops_with_the_rest( +def test_a_step_that_moves_the_tests_to_a_file_that_pytest_does_not_collect_stops( store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake ) -> None: - script = _script( - write_call("tests/test_moved.py", "def test_a() -> None: ...\n"), - SOURCE, - removes=checkout / OLD_PATH, + script = _script(write_call("tests/conftest.py", OLD), SOURCE, removes=checkout / OLD_PATH) + + outcome = _run(store, checkout, script) + + assert (outcome.status, outcome.reason) == ( + StepStatus.STOPPED, + f"{REASON}{OLD_PATH}: TestKept.test_c, test_a, test_b", ) + +def test_a_step_that_replaces_a_test_file_with_a_byte_order_mark_still_stops( + store: InMemoryRoadmapStore, checkout: Path, programs: ProcessFake +) -> None: + script = _script(write_call(OLD_PATH, "\ufeffdef test_new() -> None: ...\n"), SOURCE) + outcome = _run(store, checkout, script) assert (outcome.status, outcome.reason) == ( StepStatus.STOPPED, - f"{REASON}{OLD_PATH}: TestKept.test_c, test_b", + f"{REASON}{OLD_PATH}: TestKept.test_c, test_a, test_b", ) diff --git a/tests/test_roadmap_implement_test_names.py b/tests/test_roadmap_implement_test_names.py index d9629bc279..540af2f586 100644 --- a/tests/test_roadmap_implement_test_names.py +++ b/tests/test_roadmap_implement_test_names.py @@ -77,6 +77,10 @@ def test_defined_tests_of_a_file_that_does_not_parse_is_none(text: str) -> None: assert defined_tests(text) is None +def test_defined_tests_ignores_a_byte_order_mark_at_the_start() -> None: + assert defined_tests("\ufeffdef test_a(): pass\n") == frozenset({"test_a"}) + + def test_defined_tests_of_an_empty_file_is_empty() -> None: assert defined_tests("") == frozenset() @@ -109,26 +113,12 @@ def test_a_new_file_loses_nothing() -> None: assert lost_tests({}, {"tests/test_new.py": _names("test_a")}) == {} -def test_a_test_that_moves_to_another_file_is_not_lost() -> None: +def test_a_test_that_moves_to_another_file_is_lost() -> None: + """Every test stays in its file, even when the other file holds a test of the same name.""" before = {"tests/test_a.py": _names("TestA.test_x", "test_y")} after = {"tests/test_b.py": _names("TestA.test_x", "test_y")} - assert lost_tests(before, after) == {} - - -def test_a_name_that_the_other_file_had_before_is_not_a_move() -> None: - """File A is deleted, and file B had `test_x` already: no test moved, one was removed.""" - before = {"tests/test_a.py": _names("test_x"), "tests/test_b.py": _names("test_x", "test_z")} - after = {"tests/test_b.py": _names("test_x", "test_z", "test_w")} - - assert lost_tests(before, after) == {"tests/test_a.py": ["test_x"]} - - -def test_one_new_name_excuses_one_lost_name() -> None: - before = {"tests/test_a.py": _names("test_x"), "tests/test_b.py": _names("test_x")} - after = {"tests/test_c.py": _names("test_x")} - - assert lost_tests(before, after) == {"tests/test_b.py": ["test_x"]} + assert lost_tests(before, after) == {"tests/test_a.py": ["TestA.test_x", "test_y"]} def test_a_renamed_test_is_lost() -> None: @@ -145,7 +135,7 @@ def test_a_file_that_did_not_parse_at_the_start_is_skipped() -> None: assert lost_tests(before, after) == {} -def test_a_file_that_does_not_parse_after_the_run_is_skipped_and_excuses_nothing() -> None: +def test_a_file_that_does_not_parse_after_the_run_is_skipped() -> None: before = {"tests/test_a.py": _names("test_a"), "tests/test_b.py": _names("test_b")} after: dict[str, frozenset[str] | None] = {"tests/test_a.py": None} From a18440f5ecdab25db0fe69dcd056b7c233633b9e Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Fri, 30 Oct 2026 23:18:12 +0000 Subject: [PATCH 8/8] docs(openspec): state the rule that a test stays in its file (#2804) --- .../2026-10-30-2804-step-keeps-existing-tests/design.md | 6 ++++-- .../2026-10-30-2804-step-keeps-existing-tests/proposal.md | 6 +++--- .../specs/roadmap-implement-step/spec.md | 8 ++++++-- .../2026-10-30-2804-step-keeps-existing-tests/tasks.md | 4 ++-- openspec/specs/roadmap-implement-step/spec.md | 8 ++++++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/design.md b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/design.md index 704d8d518d..62c5091337 100644 --- a/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/design.md +++ b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/design.md @@ -5,12 +5,14 @@ - **The rule is by qualified name.** A test is `test_x` or `Class.test_x`, with the names of nested classes joined by dots. A rename is a loss. A change of the body is not. The issue asks for the rule by name, and a name is the one fact that a parser gives with no guess. - **Which defs count.** A function or an async function whose name starts with `test_`. The walk goes into classes, and into the blocks of `if`, `try`, `with`, `for`, `while` and `match`, so a test that a platform check guards is kept as well. The walk stops at a function: a `def test_x` inside a function is a helper of that test. Decorators do not matter, so a parametrized test is one function and its cases are not names. - **Which files count.** A path under `tests/` that ends with `.py`, listed by git as changed, between the start commit and the checkout. A file that the step did not touch cannot lose a test. A new file has no tests to lose. A file that is not Python is not parsed. -- **A deleted file loses all its tests, unless they moved.** The check lists the changes with `--no-renames`, so a move is a delete plus an add, whatever the git settings are. A lost name is excused by one name that is new in a changed test file: new means that the name is in the file after the run and was not in that file at the start. Each new name excuses one lost name, in the order of the sorted paths. A step that moves a test and keeps a copy in the old file is not a loss either way. +- **Every test stays in its own file.** A deleted file loses all its tests. A test that moves to another file is lost too: the issue asks that each test is still in its file, and a person moves tests in a pull request of their own. The check lists the changes with `--no-renames`, so a move is a delete plus an add, whatever the git settings are. A same-name test in another file excuses nothing, so a move to a file that pytest does not collect (`tests/conftest.py`) cannot hide a loss. - **A syntax error is skipped, and not reported.** At the start, a file that does not parse gives no list, so the file keeps no test from the check. After the run, `ruff check` reports the error, and the repair turn can fix it. A second reason for the same file would be a double report. A file that does not parse after the run adds no new names, so it excuses no loss. A bad parse does not hide a loss in another file. - **The check runs second.** It runs after the head check and the restore of `tasks.md`, and after the no-change check, because it needs the staged tree. It runs before the formatter and the verification commands. A verification command can run the whole test file for minutes, and the step discards the work anyway. The reason is also the most useful one: it names the tests, and not a symptom of their loss. The formatter does not change names. A repair turn runs the exit checks again from the start, so a repair turn cannot remove a test and pass. - **No extra turn.** A lost test is a loss of work the agent chose, and a rewrite is the fix, not a one-line edit. The step stops, as the issue asks, and the diff in the stop comment shows the work. A person who wants to remove a test does it in a pull request of their own. - **The reason is bounded.** It names the file and at most `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` functions, then the count of the rest. It names at most `CONST_ROADMAP_IMPLEMENT_REASON_PATHS` files with the same count rule. The stop comment cuts a reason to `CONST_ROADMAP_IMPLEMENT_REASON_CHARS` characters in any case. -- **Pure functions in a module of their own.** `implement_step.py` is 1,300 lines. The module `implement_test_names.py` holds `test_names(text)` and `lost_tests(before, after)`, with no I/O. `implement_step.py` reads git and formats the reason. +- **Pure functions in a module of their own.** `implement_step.py` is 1,300 lines. The module `implement_test_names.py` holds `defined_tests(text)`, `lost_tests(before, after)` and `lost_since(git, start)`, which reads git through a function that the caller gives. `implement_step.py` formats the reason. +- **A byte order mark is ignored.** `defined_tests` removes one at the start of the text, as Python does when it reads a file. A file with a mark is judged like any other. +- **Known limits.** The rule reads names. A test that keeps its name and loses its body, a test that an `if False:` block hides, and a duplicate `def` of one name that the agent removes, are not found. A body check is out of scope: the verification commands run the tests. ## Rejected alternatives diff --git a/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/proposal.md b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/proposal.md index 22e0d5116c..83cc8cb30c 100644 --- a/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/proposal.md +++ b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/proposal.md @@ -10,7 +10,7 @@ The step judges the work with the verification commands of the group, `ruff chec - A new exit check lists, for each test file that the step changed and that existed at the start commit, the test functions of the file at the start. When one of them is not in the file after the run, the step stops. The reason names the file and the missing functions, up to a fixed number of them. - A test file is a Python file under `tests/`. A test function is a function or an async function whose name starts with `test_`, at module level or in a class, also inside an `if`, `try` or `with` block. A function is named by its qualified name: `test_x` or `Class.test_x`. A parametrized test is one function. A function inside another function is not a test. -- A step that deletes a test file loses all its tests. A step that moves tests from one file to another loses none, when each moved test has the same qualified name in a test file that the step changed and did not have it at the start. A step that renames a test loses the test: the rule is by name. +- A step that deletes a test file loses all its tests. A step that moves a test from one file to another loses it: every test stays in its file, and a person moves tests in a pull request of their own. A step that renames a test loses the test: the rule is by name. - A file with a syntax error is skipped. At the start, there is no list to compare. After the run, the static check judges the file, so the new check does not report it twice. - The check runs second, after the check that `HEAD` did not move, and before the formatter and the verification commands. It is cheap, and the verification commands can run for minutes. The step discards the work in any case, so it must not spend that time first. The check gives no extra turn: a lost test is not a fault of style that one edit removes. - The module `implement_test_names.py` holds the list of names and the comparison, in pure functions. `implement_step.py` holds only the git calls and the reason text. @@ -32,12 +32,12 @@ The step judges the work with the verification commands of the group, `ruff chec ## Feasibility -- The defect is real. In `git show 72b82e38 -- tests/test_config_write_history.py`, the file has 7 test functions at `72b82e38~1` and 2 at `72b82e38`. A walk of both versions with the standard library `ast` lists the 7 lost names, such as `test_the_first_write_of_a_config_file_records_its_keys_and_keeps_no_copy`. The same commit adds `tests/config/test_config_file_mode.py`, and none of the 7 names is in it. So a rule by qualified name stops this commit, also when the rule excuses moved tests. +- The defect is real. In `git show 72b82e38 -- tests/test_config_write_history.py`, the file has 7 test functions at `72b82e38~1` and 2 at `72b82e38`. A walk of both versions with the standard library `ast` lists the 7 lost names, such as `test_the_first_write_of_a_config_file_records_its_keys_and_keeps_no_copy`. The same commit adds `tests/config/test_config_file_mode.py`, and none of the 7 names is in it. So a rule by qualified name stops this commit. - No exit check looks at tests today. `_exit_failure` in `implement_step.py` runs, in order: the head check, `_restore_tasks`, the no-change check, `_format_failure`, `_verification_failure` and `_static_failure`. None reads a test name. - `_stage` cannot list a deleted file. It runs `git diff --cached --name-only --diff-filter=ACMR`, and `D` is not in the filter. The new check lists its own paths. `git diff --cached --name-status --no-renames -z -- tests` gives a delete plus an add for a move, in the same shape on every machine, whatever `diff.renames` says. Git 2.55.0 was run for this. - The text at the start is `git show :`. The step already runs git through `_git_output`, and the start commit is in the tree of the checkout. - `ast.parse` from the standard library gives the names, and raises `SyntaxError` for a file that does not parse. `ast.iter_child_nodes` walks into `if`, `try`, `with` and class bodies, and the walk can stop at a function. A rename in git needs a similarity guess, and the check needs none: it compares names. -- The rule for a moved test is by evidence. Git shows a move as a delete plus an add when renames are off. The tests of the deleted file are not lost when the same qualified name is new in a changed test file. A name that the other file had at the start is not new: that file has the test already, and a delete of a duplicate must still stop. +- The rule for a moved test is the rule of the issue. Git shows a move as a delete plus an add when renames are off, and the delete loses the tests. No same-name test in another file excuses a loss: a file that pytest does not collect would hide it. ## Existing Tool Considered diff --git a/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md index 82aae49cc9..8ad7171730 100644 --- a/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md +++ b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/specs/roadmap-implement-step/spec.md @@ -52,7 +52,7 @@ The exit checks SHALL run in this order: the agent made no commit, no test that ## ADDED Requirements ### Requirement: A step keeps the tests that existed -Every test that a `.py` file under `tests/` held at the commit where the step started SHALL be in the checkout after the run, by qualified name (`test_x` or `Class.test_x`), unless the same qualified name is new in another changed test file. A test is a function named `test_*`. When a test is lost, the step SHALL stop with a reason that names the file and at most `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` of its tests, and SHALL give no extra turn. A file that does not parse is skipped. +Every test that a `.py` file under `tests/` held at the commit where the step started SHALL be in the checkout after the run, by qualified name (`test_x` or `Class.test_x`). A test is a function named `test_*`. When a test is lost, the step SHALL stop with a reason that names the file and at most `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` of its tests, and SHALL give no extra turn. A file that does not parse is skipped. #### Scenario: A test file that the agent replaces - **WHEN** a test file holds `test_a` and `test_b` at the start, and the model writes a file that holds `test_c` @@ -72,7 +72,11 @@ Every test that a `.py` file under `tests/` held at the commit where the step st #### Scenario: A test that the agent moves - **WHEN** the model moves `Check.test_a` from one test file to a new test file -- **THEN** the step reports done +- **THEN** the step reports stopped, and the reason names the old file and `Check.test_a` + +#### Scenario: A test that loses its body +- **WHEN** the model keeps the name of `test_a` and replaces its body with `pass` +- **THEN** this check does not stop the step: it reads names only #### Scenario: A file that does not parse - **WHEN** a test file has a syntax error after the run, or at the start diff --git a/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/tasks.md b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/tasks.md index 03059a236a..b593e45638 100644 --- a/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/tasks.md +++ b/openspec/changes/archive/2026-10-30-2804-step-keeps-existing-tests/tasks.md @@ -2,9 +2,9 @@ ## 1. The names and the comparison -- [x] Write failing tests in `tests/test_roadmap_implement_test_names.py`: module-level and class tests get qualified names; async tests, tests in `if` and `try` blocks, and nested classes count; a parametrized test is one name; a function inside a function and a non-test function do not count; a file that does not parse gives no names; the lost names of a file that drops, renames or deletes a test; a moved test is excused by a new name in another file, and a name that the other file had before is not new; the names are sorted. +- [x] Write failing tests in `tests/test_roadmap_implement_test_names.py`: module-level and class tests get qualified names; async tests, tests in `if` and `try` blocks, and nested classes count; a parametrized test is one name; a function inside a function and a non-test function do not count; a file that does not parse gives no names; the lost names of a file that drops, renames or deletes a test; a moved test is lost; a byte order mark does not hide a test; the names are sorted. - Verification: `uv run devops ci test tests/test_roadmap_implement_test_names.py` -- [x] Add `src/devops_cli/roadmap/implement_test_names.py` with `test_names` and `lost_tests`, built on the standard library `ast`. +- [x] Add `src/devops_cli/roadmap/implement_test_names.py` with `defined_tests` and `lost_tests`, built on the standard library `ast`. - Verification: `uv run devops ci test tests/test_roadmap_implement_test_names.py` ## 2. The exit check diff --git a/openspec/specs/roadmap-implement-step/spec.md b/openspec/specs/roadmap-implement-step/spec.md index 15419bcec6..0e864ecafe 100644 --- a/openspec/specs/roadmap-implement-step/spec.md +++ b/openspec/specs/roadmap-implement-step/spec.md @@ -570,7 +570,7 @@ The turn for a failed static check SHALL change no file except `tasks.md` and th - **THEN** the step checks all exit checks again and does not stop for the change ### Requirement: A step keeps the tests that existed -Every test that a `.py` file under `tests/` held at the commit where the step started SHALL be in the checkout after the run, by qualified name (`test_x` or `Class.test_x`), unless the same qualified name is new in another changed test file. A test is a function named `test_*`. When a test is lost, the step SHALL stop with a reason that names the file and at most `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` of its tests, and SHALL give no extra turn. A file that does not parse is skipped. +Every test that a `.py` file under `tests/` held at the commit where the step started SHALL be in the checkout after the run, by qualified name (`test_x` or `Class.test_x`). A test is a function named `test_*`. When a test is lost, the step SHALL stop with a reason that names the file and at most `CONST_ROADMAP_IMPLEMENT_REASON_TESTS` of its tests, and SHALL give no extra turn. A file that does not parse is skipped. #### Scenario: A test file that the agent replaces - **WHEN** a test file holds `test_a` and `test_b` at the start, and the model writes a file that holds `test_c` @@ -590,7 +590,11 @@ Every test that a `.py` file under `tests/` held at the commit where the step st #### Scenario: A test that the agent moves - **WHEN** the model moves `Check.test_a` from one test file to a new test file -- **THEN** the step reports done +- **THEN** the step reports stopped, and the reason names the old file and `Check.test_a` + +#### Scenario: A test that loses its body +- **WHEN** the model keeps the name of `test_a` and replaces its body with `pass` +- **THEN** this check does not stop the step: it reads names only #### Scenario: A file that does not parse - **WHEN** a test file has a syntax error after the run, or at the start