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

Filter by extension

Filter by extension

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

## Decisions

**The rule reads the command's tokens, not the step's parser.** `shlex.split` gives the tokens of a `uv run devops ci test <module>` command, and a token whose path is a test module under `tests/` is a module the command runs. A directory token, such as `tests/roadmap/`, is no module. A token with shell syntax around it stays a path and not a module, so the rule never reads a command that the step refuses.

**The group's modules come from its own text.** The `test` task names the module, and `changes`, `creates` and `reads` name the module that the group touches. A behavior group that writes its test in the task text but creates the file through a group path is accepted, as the sample group is.

**A negative search stays accepted.** A behavior group may prove a removed name with `! git grep`, as the rule of #3427 accepts, and no test module exists for it.

**A command with a form problem gets the form problem only.** A second problem for the same command tells the model nothing new, and `form_problems` already refuses a command that the step cannot run.

**The message names the module that the group should run.** The model fixes the command from the problem alone, as it does for every other form problem.

## Rejected alternatives

- **A rule in `check_proposal` rather than `form_problems`.** The fault is the form of a command, which `form_problems` already judges, and the two checks share the command parse.
- **Accept a test directory.** A directory runs every test, and the step then proves more than the group, but it does not prove the group's test: the group's module may not exist yet in a way that the command names.
- **Require the module of the `test` task only.** A group may write its test in a file that a `creates` path names and a task sentence that the `test` text does not name in a code span.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Proposal: #3463

## Why

The stage form check accepts a `behavior` group whose `verify` command runs no test. `_behavior_problems` requires a `test` and a `verify`, and `form_problems` judges the form of the command (#3427), but no rule reads the command's target. A behavior group with `uv run devops ci docs` or `uv run devops ci test tests/roadmap/` passes, and the step proves nothing about the behavior that the group changes. The prompt at `src/devops_cli/ai/tasks/roadmap_stage_change.md` already says that a behavior group's `verify` runs its test; no check enforces it. Closes #3463.

## What Changes

- `form_problems` refuses a `behavior` group whose `verify` command names no test module of the group, or names a test module that `test`, `changes`, `creates` and `reads` do not name. A test directory is no test module. A negative search stays accepted, and a command with a form problem gets only the form problem.
- The problem names the group, the command and the test module that the group should run.
- The stage prompt needs no change: it states the rule.
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `roadmap-stage/tests-gate`: A behavior group runs a test module of the group.

## Impact

- Code: `src/devops_cli/roadmap/stage/stage_form.py`, `src/devops_cli/lang/en/messages.py`
- Tests: `tests/roadmap/stage/test_roadmap_stage_form.py`, `tests/roadmap/stage/test_roadmap_stage_plan.py`

## Feasibility

Read on 2026-11-14 against `origin/main` at `04107728d`.

- The check that accepts the group: `src/devops_cli/roadmap/stage/stage_form.py:247:def form_problems`, and `src/devops_cli/roadmap/stage/stage_change.py:585:def _behavior_problems` requires only the presence of `test` and `verify`.
- The gap reproduces on the sample group of `tests/support/builders.py`: `form_problems([group with verify="uv run devops ci docs"])` returns `[]`, and so does `uv run devops ci test tests/roadmap/`.
- The prompt states the rule: `src/devops_cli/ai/tasks/roadmap_stage_change.md:18`, a `behavior` group's `verify` runs its test.
- The test-module test lives in the same module: `src/devops_cli/roadmap/stage/stage_form.py:147:def _is_test_module`.

## Existing Tool Considered

No open, maintained tool checks the verify of a repository-specific plan. The rule extends `form_problems`, which already parses each command with `shlex.split`. The cost is about 2,000 tokens to build and test, and about 40 lines of code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## ADDED Requirements

### Requirement: A behavior group runs a test module of the group
`form_problems` SHALL refuse a `behavior` group whose `verify` command names no test module, or names a test module that its `test`, `changes`, `creates` and `reads` do not name. A directory under `tests/` SHALL be no test module. A negative search SHALL stay accepted, and a command with a form problem SHALL get the form problem only. The problem SHALL name the group, the command and the test module that the group should run.

#### Scenario: A command that runs no test module
- **WHEN** a behavior group has the verify `uv run devops ci docs` and the test module `tests/test_sample.py`
- **THEN** `form_problems` returns one problem that names the group, the command and `tests/test_sample.py`

#### Scenario: The verify names a test directory
- **WHEN** a behavior group has the verify `uv run devops ci test tests/roadmap/` and the test module `tests/roadmap/test_roadmap_stage_form.py`
- **THEN** `form_problems` returns one problem for that group

#### Scenario: The group runs its own test module
- **WHEN** a behavior group has the verify `uv run devops ci test tests/test_sample.py` and its `test` text names `tests/test_sample.py`
- **THEN** `form_problems` returns no problem for that group

#### Scenario: An other group runs another command
- **WHEN** an `other` group has the verify `uv run devops ci docs`
- **THEN** `form_problems` returns no problem for that group
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Tasks

## 1. Refuse a behavior verify that runs no test

Kind: behavior. Reads: `src/devops_cli/roadmap/stage/stage_form.py`, `src/devops_cli/roadmap/stage/stage_change.py`, `src/devops_cli/ai/tasks/roadmap_stage_change.md`. Changes: `src/devops_cli/roadmap/stage/stage_form.py`, `src/devops_cli/lang/en/messages.py`, `tests/roadmap/stage/test_roadmap_stage_form.py`, `tests/roadmap/stage/test_roadmap_stage_plan.py`.

- [x] 1.1 Add the rule to `form_problems` for a `behavior` group, with the problem text in `RoadmapMessages`
- Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_form.py` passes
- [x] 1.2 Add the four cases: no test module, a test directory, the group's own module, and an `other` group
- Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_form.py` passes
- [x] 1.3 Keep the existing plan tests true, where a test of the path rule uses a behavior group with a verify of another module
- Verification: `$ uv run devops ci test tests/roadmap/stage` passes

## 2. Run the gates

Kind: other. Reads: `tests/roadmap/`. Changes: none.

- [x] 2.1 Run the gate of the branch
- Verification: `$ uv run devops ci --check --only lint,format,typecheck` passes
- Verification: `$ uv run devops ci docs` passes
19 changes: 19 additions & 0 deletions openspec/specs/roadmap-stage/tests-gate/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,22 @@ The problem of a test path that names no file of the commit SHALL end with the s
#### Scenario: A text that names a test file of the commit passes
- **WHEN** The scanned text names `tests/roadmap/test_roadmap_limit_classes.py` and the commit holds that file.
- **THEN** The check reports no missing path.

### Requirement: A behavior group runs a test module of the group
`form_problems` SHALL refuse a `behavior` group whose `verify` command names no test module, or names a test module that its `test`, `changes`, `creates` and `reads` do not name. A directory under `tests/` SHALL be no test module. A negative search SHALL stay accepted, and a command with a form problem SHALL get the form problem only. The problem SHALL name the group, the command and the test module that the group should run.

#### Scenario: A command that runs no test module
- **WHEN** a behavior group has the verify `uv run devops ci docs` and the test module `tests/test_sample.py`
- **THEN** `form_problems` returns one problem that names the group, the command and `tests/test_sample.py`

#### Scenario: The verify names a test directory
- **WHEN** a behavior group has the verify `uv run devops ci test tests/roadmap/` and the test module `tests/roadmap/test_roadmap_stage_form.py`
- **THEN** `form_problems` returns one problem for that group

#### Scenario: The group runs its own test module
- **WHEN** a behavior group has the verify `uv run devops ci test tests/test_sample.py` and its `test` text names `tests/test_sample.py`
- **THEN** `form_problems` returns no problem for that group

#### Scenario: An other group runs another command
- **WHEN** an `other` group has the verify `uv run devops ci docs`
- **THEN** `form_problems` returns no problem for that group
4 changes: 4 additions & 0 deletions src/devops_cli/lang/en/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4816,6 +4816,10 @@ class RoadmapMessages:
"Group {group} gives the `verify` command `{command}`, and the step cannot run it: "
"{reason}. Give `uv run devops <command>` or `! git grep -n <name> src/ tests/`."
)
stage_problem_behavior_verify_test: str = (
"Group {group} gives the `verify` command `{command}`, which runs no test module of the "
"group. Run {module}."
)
stage_problem_manifest_kind: str = (
"Group {group} has the kind other and changes `{path}`. "
"Use the kind manifest for a group that creates or changes a case path."
Expand Down
38 changes: 38 additions & 0 deletions src/devops_cli/roadmap/stage/stage_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,43 @@ def _verify_problems(number: int, command: str) -> list[str]:
return problems


def _test_modules_in(text: str) -> list[PurePosixPath]:
"""The test modules that `text` names in code spans, in order."""
found = (PurePosixPath(span[1:-1]) for span in _CODE_SPAN.findall(text))
return [path for path in found if _is_test_module(path)]


def _behavior_test_run_problems(number: int, group: StageGroup) -> list[str]:
"""The problem of a `behavior` group whose `verify` runs no test module of the group (#3463):
the command must name a test module that `test`, `changes`, `creates` or `reads` names."""
if group.kind != "behavior" or group.verify is None:
return []
if _verify_problems(number, group.verify) or negative_search_parts(group.verify) is not None:
# The form rule refuses another command, and a negative search proves a removed name.
return []
command = group.verify.strip()
# The form rule already refused a command line that shlex cannot read.
ran = [PurePosixPath(word) for word in shlex.split(command)]
ran = [path for path in ran if _is_test_module(path)]
candidates = [
*_test_modules_in(group.test or ""),
*(
path
for path in map(PurePosixPath, (*group.changes, *group.creates, *group.reads))
if _is_test_module(path)
),
]
if ran and any(path in candidates for path in ran):
return []
return [
MESSAGES.roadmap.stage_problem_behavior_verify_test.format(
group=number,
command=shown(command, CONST_ROADMAP_IMPLEMENT_VERIFY_CHARS),
module=f"`{candidates[0]}`" if candidates else "a test module of the group",
)
]


def _manifest_verify_problems(number: int, group: StageGroup) -> list[str]:
"""The problem of the `verify` command of a `manifest` group: it must be `uv run devops ci test`
followed by one path of the group or its folder."""
Expand Down Expand Up @@ -255,6 +292,7 @@ def form_problems(groups: Sequence[StageGroup]) -> list[str]:
problems.extend(_task_problems(number, group))
if group.verify is not None:
problems.extend(_verify_problems(number, group.verify))
problems.extend(_behavior_test_run_problems(number, group))
problems.extend(_manifest_verify_problems(number, group))
if group.kind == "other":
for case_path in (*group.changes, *group.creates):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_every_verify_form_that_the_gate_admits_is_a_command_that_the_step_runs(
]
base = make_stage_proposal().groups[0].model_dump()
for verify in admitted:
group = StageGroup.model_validate({**base, "verify": verify})
group = StageGroup.model_validate({**base, "kind": "other", "test": None, "verify": verify})
assert form_problems([group]) == [], verify
assert commands_failure(checkout, [verify]) is None, verify

Expand Down
75 changes: 71 additions & 4 deletions tests/roadmap/stage/test_roadmap_stage_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,28 @@ def test_a_pytest_verify_command_is_refused_with_the_form_to_use() -> None:
"verify",
[
f"uv run devops ci test {MIRRORED}",
"! git grep -n -w old_name src/ tests/",
],
)
def test_a_test_run_or_a_negative_search_is_a_verify_command(verify: str) -> None:
plan = _plan(CODE, MIRRORED, creates=(MIRRORED,), verify=verify)

assert _problems(plan) == []


@pytest.mark.parametrize(
"verify",
[
"uv run devops ci",
"uv run devops openspec check",
"uv run devops docs check",
"uv run devops k8s image-pins",
"! git grep -n -w old_name src/ tests/",
],
)
def test_a_devops_command_or_a_negative_search_is_a_verify_command(verify: str) -> None:
plan = _plan(CODE, MIRRORED, creates=(MIRRORED,), verify=verify)
def test_a_project_command_is_a_verify_command_of_an_other_group(verify: str) -> None:
group = _group(kind="other", test=None, verify=verify)

assert _problems(plan) == []
assert form_problems([group]) == []


@pytest.mark.parametrize(
Expand Down Expand Up @@ -660,3 +671,59 @@ def test_a_manifest_verify_that_runs_a_path_of_the_group_is_accepted() -> None:
)

assert form_problems([group]) == []


# ── A behavior group runs its test (#3463) ────────────────────────────────────


def test_a_behavior_group_that_runs_no_test_module_is_refused() -> None:
(problem,) = form_problems([_group(verify="uv run devops ci docs")])

assert (
problem.startswith("Group 1 gives the `verify` command `uv run devops ci docs`"),
"tests/test_sample.py" in problem,
) == (True, True)


def test_a_verify_that_names_a_test_directory_is_refused() -> None:
(problem,) = form_problems([_group(verify="uv run devops ci test tests/roadmap/")])

assert problem.startswith(
"Group 1 gives the `verify` command `uv run devops ci test tests/roadmap/`"
)


def test_a_behavior_group_that_runs_its_test_module_is_accepted() -> None:
group = _group(verify="uv run devops ci test tests/test_sample.py")

assert form_problems([group]) == []


def test_an_other_group_that_runs_no_test_module_is_accepted() -> None:
group = _group(kind="other", test=None, verify="uv run devops ci docs")

assert form_problems([group]) == []


def test_a_manifest_verify_that_names_no_path_of_the_group_is_refused() -> None:
group = _group(
kind="manifest",
reads=["docs/manifest.yaml"],
changes=["src/devops_cli/sample.py", "tests/test_sample.py", "docs/manifest.yaml"],
verify="uv run devops ci test tests/other/test_x.py",
)

(problem,) = [text for text in form_problems([group]) if "manifest group must be" in text]

assert "tests/other/test_x.py" in problem


def test_a_manifest_verify_that_names_the_folder_of_its_path_is_accepted() -> None:
group = _group(
kind="manifest",
reads=["docs/manifest.yaml"],
changes=["src/devops_cli/sample.py", "tests/test_sample.py", "docs/manifest.yaml"],
verify="uv run devops ci test docs/",
)

assert [text for text in form_problems([group]) if "manifest group must be" in text] == []
11 changes: 6 additions & 5 deletions tests/roadmap/stage/test_roadmap_stage_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,12 +1540,13 @@ def test_a_path_in_a_verify_command_is_checked_and_a_created_path_passes(
model_fake: ModelFake,
openspec: OpenSpecFake,
) -> None:
model_fake.answer(
_naming(
"src/devops_cli/sample.py", verify="uv run devops ci test tests/old/test_sample.py"
),
make_stage_proposal(),
naming = _naming(
"src/devops_cli/sample.py", verify="uv run devops ci test tests/old/test_sample.py"
)
group = naming.groups[0].model_copy(
update={"test": "Run `tests/old/test_sample.py` for the changed path"}
)
model_fake.answer(make_stage_proposal(groups=[group]), make_stage_proposal())

plan = _plan(store, stage_repo)

Expand Down