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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-10
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Design

## Decisions

- **Judge a path of the `when` only when a behavior group changes, creates or reads it.**: A group that touches the path builds or uses it as code, and its test must name it. A path that no group touches is data of the scenario.
- **Judge every code identifier of the `when`.**: A function or a class in a condition is code under test, as before.
- **Judge every path and identifier of the `then`.**: The `then` states the behavior under test.
- **Keep the rule that one named span satisfies the scenario.**: The scenario then keeps its present reading, and only the set of spans changes.

## Rejected alternatives

- **Skip every path of the `when`.**: A scenario "`src/x.py` holds a bad line" would need no test of `src/x.py`, and the gate would lose the defects it catches.
- **Skip a scenario that names a data file anywhere.**: A `then` that names code with no test must stay refused.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Proposal: #4316

## Why

The scenario check refuses a spec scenario that names a data file as a condition (#4316). `_scenario_problems` in `src/devops_cli/roadmap/stage/stage_change.py` takes each code span of the `when` and the `then` that is a repository path or a code identifier, and needs a behavior test that names one of them. A scenario that says what a fixture holds, such as "`.github/labels.yml` declares no `scope/floor`", names the file as input data, and the test builds that data in memory. A live stage run on #3599 with the live stage model was refused with "Scenario 'A scope that no label declares' names `.github/labels.yml` with no behavior test." The stage job logs of 2026-11-04 to 2026-11-09 hold 8 such failures. Closes #4316.

## What Changes

- The check judges the code spans of the `then`, and the code spans of the `when` that are no path or whose path a behavior group changes, creates or reads.
- A path in the `when` that no behavior group touches is input data and needs no test text.
- A `then` that names code with no behavior test is refused as before.
- The change carries a spec delta because it changes which plans the stage job refuses.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `roadmap-stage`: A scenario that names code has a behavior test

## Impact

- Code: `src/devops_cli/roadmap/stage/stage_change.py`
- Tests: `tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py`

## Feasibility

- The cause is in the code: `_scenario_problems` put every path and identifier of `when` and `then` into one list and refused the scenario when no behavior test named any of them. The scenario of the live run is the test input.
- The failure text of the live run is in the logs: "Scenario 'A scope that no label declares' names `.github/labels.yml` with no behavior test." and the `when` "the title of the issue is `fix(floor): the job drops a comment` and `.github/labels.yml` declares no `scope/floor`".
- First check against the real system: `uv run devops roadmap eval stage --replay`, which keeps 81 of 317 defects caught by a gate, 0 missed, and 5 of 5 good plans accepted. The 24 `contrived_test` defects stay caught.
- Second check: `uv run devops ci test tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py`.

## Existing Tool Considered

No library judges a scenario of a spec delta, and the project holds no such helper. The change moves the choice of spans into one function. Cost: about 25 000 tokens to build, 3 000 to keep and 1 hour. The change deletes no internal code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## MODIFIED Requirements

### Requirement: A scenario that names code has a behavior test
`check_proposal` SHALL refuse a spec scenario that names a function or a file when no behavior group's `test` or `verify` names it and the scenario names no command. It SHALL judge the code spans of the `then`, and the code spans of the `when` that are no path or whose path a behavior group changes, creates or reads. It SHALL NOT judge a path of the `when` that no behavior group touches, because that path is input data.

#### Scenario: A scenario names `_loki_mode` and no task tests it
- **WHEN** A spec scenario's `then` names `_loki_mode` in a code span, and no behavior group's `test` or `verify` names `_loki_mode`.
- **THEN** `check_proposal` returns one problem that names the scenario and `_loki_mode`.

#### Scenario: A scenario that cites `helm template`
- **WHEN** A spec scenario's `then` names `_loki_mode` and `helm template` in code spans, and no behavior group's `test` names `_loki_mode`.
- **THEN** `check_proposal` returns no scenario problem.

#### Scenario: A behavior test names the function
- **WHEN** A spec scenario's `then` names `_loki_mode` in a code span, and a behavior group's `test` names `_loki_mode`.
- **THEN** `check_proposal` returns no scenario problem.

#### Scenario: A data file in the condition
- **WHEN** A spec scenario's `when` says `.github/labels.yml` declares no `scope/floor`, and no behavior group changes, creates or reads `.github/labels.yml`, and no test names it.
- **THEN** `check_proposal` returns no scenario problem.

#### Scenario: A file that a behavior group reads
- **WHEN** A spec scenario's `when` names `.github/labels.yml`, a behavior group reads it, and no behavior group's `test` or `verify` names it.
- **THEN** `check_proposal` returns one problem that names the scenario and `.github/labels.yml`.

#### Scenario: A file in the result
- **WHEN** A spec scenario's `then` names `.github/labels.yml` and no behavior group's `test` or `verify` names it.
- **THEN** `check_proposal` returns one problem that names the scenario and `.github/labels.yml`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Tasks

## 1. Judge the code that a scenario tests

Reads: `src/devops_cli/roadmap/stage/stage_change.py`, `tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py`. Changes: `src/devops_cli/roadmap/stage/stage_change.py`, `tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py`.

- [x] 1.1 In `tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py`, assert that a data file in the `when` that no group touches needs no test text, and that a `then` path, a `when` path that a group changes or reads, and a `then` identifier with no test are refused
- Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py` fails on the base
- [x] 1.2 In `src/devops_cli/roadmap/stage/stage_change.py`, choose the judged spans of a scenario in `_judged_spans`
- Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py` passes

## 2. Keep the golden replay

- [x] 2.1 Run the replay and state that every gate refuses what it must refuse and that 5 of 5 good plans pass
- Verification: `$ uv run devops roadmap eval stage --replay`

## Workflow follow-up

- Pending a person: review the diff in tuicr (tuicr -r <base>..HEAD).
14 changes: 13 additions & 1 deletion openspec/specs/roadmap-stage/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,7 @@ When the stage job records a failure in the job record of an item, it SHALL writ
- **THEN** `check_proposal` returns no own-change problem.

### Requirement: A scenario that names code has a behavior test
`check_proposal` SHALL refuse a spec scenario that names a function or a file when no behavior group's `test` or `verify` names it and the scenario names no command.
`check_proposal` SHALL refuse a spec scenario that names a function or a file when no behavior group's `test` or `verify` names it and the scenario names no command. It SHALL judge the code spans of the `then`, and the code spans of the `when` that are no path or whose path a behavior group changes, creates or reads. It SHALL NOT judge a path of the `when` that no behavior group touches, because that path is input data.

#### Scenario: A scenario names `_loki_mode` and no task tests it
- **WHEN** A spec scenario's `then` names `_loki_mode` in a code span, and no behavior group's `test` or `verify` names `_loki_mode`.
Expand All @@ -3106,6 +3106,18 @@ When the stage job records a failure in the job record of an item, it SHALL writ
- **WHEN** A spec scenario's `then` names `_loki_mode` in a code span, and a behavior group's `test` names `_loki_mode`.
- **THEN** `check_proposal` returns no scenario problem.

#### Scenario: A data file in the condition
- **WHEN** A spec scenario's `when` says `.github/labels.yml` declares no `scope/floor`, and no behavior group changes, creates or reads `.github/labels.yml`, and no test names it.
- **THEN** `check_proposal` returns no scenario problem.

#### Scenario: A file that a behavior group reads
- **WHEN** A spec scenario's `when` names `.github/labels.yml`, a behavior group reads it, and no behavior group's `test` or `verify` names it.
- **THEN** `check_proposal` returns one problem that names the scenario and `.github/labels.yml`.

#### Scenario: A file in the result
- **WHEN** A spec scenario's `then` names `.github/labels.yml` and no behavior group's `test` or `verify` names it.
- **THEN** `check_proposal` returns one problem that names the scenario and `.github/labels.yml`.

### Requirement: A quoted reference search names only covered files
`check_proposal` SHALL refuse each file that a quoted `References to` answer lists outside `openspec/changes/archive/` and that no group `changes` or `creates` path and no design decision names.

Expand Down
29 changes: 22 additions & 7 deletions src/devops_cli/roadmap/stage/stage_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,22 @@ def _is_code_identifier(span: str) -> bool:
return bool(_CODE_IDENTIFIER.match(span)) and ("." in span or "_" in span)


def _judged_spans(scenario: StageScenario, tree: StagedTree, touched: Collection[str]) -> list[str]:
"""The code spans of `scenario` that need a behavior test (#4316): the code of the `then`, which
states the behavior under test, and the code of the `when` that is no path or whose path a
behavior group changes, creates or reads. A path of the `when` that no group touches is input
data, such as the file that a fixture holds, and the test builds it with no reason to name it."""
spans = [
*(
span
for span in code_spans(scenario.when)
if (path := tree.as_path(span)) is None or path in touched
),
*code_spans(scenario.then),
]
return [span for span in spans if tree.as_path(span) is not None or _is_code_identifier(span)]


def _scenario_problems(
specs: Sequence[StageSpec],
groups: Sequence[StageGroup],
Expand All @@ -860,19 +876,18 @@ def _scenario_problems(
behavior_groups = [g for g in groups if g.kind == GroupKind.BEHAVIOR]
behavior_tests = [g.test for g in behavior_groups if g.test]
behavior_verifies = [g.verify for g in behavior_groups if g.verify]
touched = {p for g in behavior_groups for p in (*g.reads, *g.changes, *g.creates)}
problems: list[str] = []

for spec in specs:
for req in (*spec.added, *spec.modified):
for scenario in req.scenarios:
spans = [*code_spans(scenario.when), *code_spans(scenario.then)]
if any(_is_scenario_command(span) for span in spans):
if any(
_is_scenario_command(span)
for span in (*code_spans(scenario.when), *code_spans(scenario.then))
):
continue
code_spans_in_scenario = [
span
for span in spans
if tree.as_path(span) is not None or _is_code_identifier(span)
]
code_spans_in_scenario = _judged_spans(scenario, tree, touched)
if not code_spans_in_scenario:
continue
satisfied = any(
Expand Down
71 changes: 71 additions & 0 deletions tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,74 @@ def test_a_behavior_group_that_names_the_code_in_test_has_no_scenario_problem()
problems = check_proposal(proposal, ["comment-thread"], TREE)

assert not any("The loki mode" in p or "_loki_mode" in p for p in problems)


# ── A data file in the `when` of a scenario (#4316) ───────────────────────────

DATA_FILE = ".github/labels.yml"
DATA_TREE = StagedTree(["src/devops_cli/sample.py", "tests/test_sample.py", DATA_FILE])
FIXTURE_WHEN = (
"the title of the issue is `fix(floor): the job drops a comment` and "
f"`{DATA_FILE}` declares no `scope/floor`"
)


def _scenario_problems_of(
when: str, then: str, group: StageGroup | None = None, tree: StagedTree = DATA_TREE
) -> list[str]:
scenario = StageScenario(name="A scope that no label declares", when=when, then=then)
proposal = make_stage_proposal(specs=[_spec_with([scenario])], groups=[group or _group()])
return [p for p in check_proposal(proposal, ["comment-thread"], tree) if "no behavior" in p]


def test_a_data_file_in_the_when_that_no_group_touches_needs_no_test_text() -> None:
problems = _scenario_problems_of(FIXTURE_WHEN, "the job refuses the title")

assert problems == []


def test_a_data_file_in_the_when_with_a_code_name_in_the_then_needs_the_code_tested() -> None:
problems = _scenario_problems_of(FIXTURE_WHEN, "`_scope_check` raises a failure")

assert len(problems) == 1
assert "_scope_check" in problems[0]


def test_a_path_in_the_then_is_judged_also_when_it_is_a_data_file() -> None:
problems = _scenario_problems_of("a scope is checked", f"the job reads `{DATA_FILE}`")

assert len(problems) == 1
assert DATA_FILE in problems[0]


def test_a_path_in_the_then_that_no_test_names_is_refused() -> None:
problems = _scenario_problems_of("the job runs", "`src/devops_cli/sample.py` holds the fix")

assert len(problems) == 1
assert "src/devops_cli/sample.py" in problems[0]


def test_a_path_in_the_when_that_a_behavior_group_changes_needs_a_test_that_names_it() -> None:
problems = _scenario_problems_of(
"`src/devops_cli/sample.py` holds a bad line", "the job refuses the plan"
)

assert len(problems) == 1
assert "src/devops_cli/sample.py" in problems[0]


def test_a_path_in_the_when_that_a_behavior_group_reads_needs_a_test_that_names_it() -> None:
group = _group()
group.reads = [DATA_FILE]

problems = _scenario_problems_of(FIXTURE_WHEN, "the job refuses the title", group)

assert len(problems) == 1
assert DATA_FILE in problems[0]


def test_a_path_in_the_when_that_the_test_names_passes() -> None:
group = _group(test=f"Write `test_x` in `tests/test_sample.py` for `{DATA_FILE}`")
group.reads = [DATA_FILE]

assert _scenario_problems_of(FIXTURE_WHEN, "the job refuses the title", group) == []
Loading