From fc8d3a9458d3245f0513a0b930b35923f37415db Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Tue, 10 Nov 2026 02:11:05 +0000 Subject: [PATCH 1/2] fix(roadmap): the scenario check accepts a data file in the when Closes #4316 --- .../.openspec.yaml | 2 + .../design.md | 13 ++++ .../proposal.md | 38 ++++++++++ .../specs/roadmap-stage/spec.md | 28 ++++++++ .../tasks.md | 19 +++++ src/devops_cli/roadmap/stage/stage_change.py | 29 ++++++-- .../test_roadmap_stage_scenario_evidence.py | 71 +++++++++++++++++++ 7 files changed, 193 insertions(+), 7 deletions(-) create mode 100644 openspec/changes/4316-the-scenario-check-refuses-a-data/.openspec.yaml create mode 100644 openspec/changes/4316-the-scenario-check-refuses-a-data/design.md create mode 100644 openspec/changes/4316-the-scenario-check-refuses-a-data/proposal.md create mode 100644 openspec/changes/4316-the-scenario-check-refuses-a-data/specs/roadmap-stage/spec.md create mode 100644 openspec/changes/4316-the-scenario-check-refuses-a-data/tasks.md diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/.openspec.yaml b/openspec/changes/4316-the-scenario-check-refuses-a-data/.openspec.yaml new file mode 100644 index 0000000000..2b638f8381 --- /dev/null +++ b/openspec/changes/4316-the-scenario-check-refuses-a-data/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-10 diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/design.md b/openspec/changes/4316-the-scenario-check-refuses-a-data/design.md new file mode 100644 index 0000000000..09aaf78d84 --- /dev/null +++ b/openspec/changes/4316-the-scenario-check-refuses-a-data/design.md @@ -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. diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/proposal.md b/openspec/changes/4316-the-scenario-check-refuses-a-data/proposal.md new file mode 100644 index 0000000000..5c01efefa0 --- /dev/null +++ b/openspec/changes/4316-the-scenario-check-refuses-a-data/proposal.md @@ -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. diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/specs/roadmap-stage/spec.md b/openspec/changes/4316-the-scenario-check-refuses-a-data/specs/roadmap-stage/spec.md new file mode 100644 index 0000000000..f94616d8d8 --- /dev/null +++ b/openspec/changes/4316-the-scenario-check-refuses-a-data/specs/roadmap-stage/spec.md @@ -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`. diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/tasks.md b/openspec/changes/4316-the-scenario-check-refuses-a-data/tasks.md new file mode 100644 index 0000000000..821ba0ae95 --- /dev/null +++ b/openspec/changes/4316-the-scenario-check-refuses-a-data/tasks.md @@ -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 ..HEAD). diff --git a/src/devops_cli/roadmap/stage/stage_change.py b/src/devops_cli/roadmap/stage/stage_change.py index 7d7ece6fd2..16075089fa 100644 --- a/src/devops_cli/roadmap/stage/stage_change.py +++ b/src/devops_cli/roadmap/stage/stage_change.py @@ -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], @@ -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( diff --git a/tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py b/tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py index 4fd7992de7..d50ad6ce1b 100644 --- a/tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py +++ b/tests/roadmap/stage/test_roadmap_stage_scenario_evidence.py @@ -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) == [] From 080a9eef7f2564b177d9d07d544ecb2a694b709c Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Tue, 10 Nov 2026 02:15:13 +0000 Subject: [PATCH 2/2] docs(openspec): archive 4316 the scenario check accepts a data file --- .../.openspec.yaml | 0 .../design.md | 0 .../proposal.md | 0 .../specs/roadmap-stage/spec.md | 0 .../tasks.md | 0 openspec/specs/roadmap-stage/spec.md | 14 +++++++++++++- 6 files changed, 13 insertions(+), 1 deletion(-) rename openspec/changes/{4316-the-scenario-check-refuses-a-data => archive/2026-11-10-4316-the-scenario-check-refuses-a-data}/.openspec.yaml (100%) rename openspec/changes/{4316-the-scenario-check-refuses-a-data => archive/2026-11-10-4316-the-scenario-check-refuses-a-data}/design.md (100%) rename openspec/changes/{4316-the-scenario-check-refuses-a-data => archive/2026-11-10-4316-the-scenario-check-refuses-a-data}/proposal.md (100%) rename openspec/changes/{4316-the-scenario-check-refuses-a-data => archive/2026-11-10-4316-the-scenario-check-refuses-a-data}/specs/roadmap-stage/spec.md (100%) rename openspec/changes/{4316-the-scenario-check-refuses-a-data => archive/2026-11-10-4316-the-scenario-check-refuses-a-data}/tasks.md (100%) diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/.openspec.yaml b/openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/.openspec.yaml similarity index 100% rename from openspec/changes/4316-the-scenario-check-refuses-a-data/.openspec.yaml rename to openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/.openspec.yaml diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/design.md b/openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/design.md similarity index 100% rename from openspec/changes/4316-the-scenario-check-refuses-a-data/design.md rename to openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/design.md diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/proposal.md b/openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/proposal.md similarity index 100% rename from openspec/changes/4316-the-scenario-check-refuses-a-data/proposal.md rename to openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/proposal.md diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/specs/roadmap-stage/spec.md b/openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/specs/roadmap-stage/spec.md similarity index 100% rename from openspec/changes/4316-the-scenario-check-refuses-a-data/specs/roadmap-stage/spec.md rename to openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/specs/roadmap-stage/spec.md diff --git a/openspec/changes/4316-the-scenario-check-refuses-a-data/tasks.md b/openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/tasks.md similarity index 100% rename from openspec/changes/4316-the-scenario-check-refuses-a-data/tasks.md rename to openspec/changes/archive/2026-11-10-4316-the-scenario-check-refuses-a-data/tasks.md diff --git a/openspec/specs/roadmap-stage/spec.md b/openspec/specs/roadmap-stage/spec.md index 0f92096d04..d9362fda1f 100644 --- a/openspec/specs/roadmap-stage/spec.md +++ b/openspec/specs/roadmap-stage/spec.md @@ -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`. @@ -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.