diff --git a/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/.openspec.yaml b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/.openspec.yaml new file mode 100644 index 0000000000..71884884ae --- /dev/null +++ b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/.openspec.yaml @@ -0,0 +1,3 @@ +schema: spec-driven +created: 2026-11-15 +skip_specs: false diff --git a/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/design.md b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/design.md new file mode 100644 index 0000000000..1c29a2aff5 --- /dev/null +++ b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/design.md @@ -0,0 +1,26 @@ +# Design: #4083 + +## Context + +`path_problems` reads the groups and the staged tree and returns the problems of a plan. The stage +job passes it the tree at the staging commit; the eval replay passes it the tree of the case. A +workflow change is an `other` group, so it has no `test` field, but it can list any path in +`changes`. + +## Decisions + +- The rule lives in `workflow_contract_problems`, a new function that `path_problems` calls. The + function reads `changes` only, so a group that reads a workflow and changes no workflow needs no + contract test, and the `reads` of a group do not satisfy the rule. +- The workflow directory and the contract test path are module constants, + `WORKFLOW_DIRECTORY` and `WORKFLOW_CONTRACT_TEST`, so the message and the rule read one text. +- The message names the group, the workflow and the contract test, so one sentence is enough to + repair the plan. + +## Risks + +- A change that edits no contract test but is covered by an existing assertion in + `tests/invariants/test_workflow_contracts.py` still needs the file in `changes`, and a pin bump + that an existing assertion holds fails the rule. The owner can relax the rule if that case + becomes common. +- The rule reads the suffix `.yml` only, as the repository holds no `.yaml` workflow. diff --git a/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/proposal.md b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/proposal.md new file mode 100644 index 0000000000..4bf2638226 --- /dev/null +++ b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/proposal.md @@ -0,0 +1,38 @@ +# Proposal: #4083 + +## Why + +The stage planner can put an edit of `.github/workflows/ci.yml` in one group and the workflow +contract test in a later group, or in no group. The group then verifies the workflow with +actionlint and zizmor, which pass on the base commit and read no step of the change. AGENTS.md +rule 4 asks for the test first, and the contract test is the executable test of a workflow +change. Closes #4083. + +## What Changes + +- `path_problems` in `src/devops_cli/roadmap/stage/stage_paths.py` reports a problem for each + `.github/workflows/*.yml` file that a group changes when the `changes` of that group holds no + `tests/invariants/test_workflow_contracts.py`. +- A message, `roadmap.stage_problem_workflow_contract`, names the group, the workflow and the + contract test. + +## Capabilities + +`roadmap-stage/paths-gate`: one new requirement for the workflow contract rule. + +## Impact + +The stage job and the stage eval replay. No command or option changes. The golden set holds no `good` plan that changes a workflow, so the replay still +passes. + +## Feasibility + +Premise checked on 2026-11-15 against `origin/main` (ca62d6a9f): `path_problems` holds no rule for +`.github/workflows/`, and the case `2163-coverage-measures-branches-and-ci-keeps` holds a group +that changes `.github/workflows/ci.yml` with no contract test. The new tests fail before the +change and pass after it. + +## Existing Tool Considered + +The rule extends `path_problems`, which the stage job already calls. actionlint and zizmor read +the syntax of the workflow only, so they cannot replace the contract test. No new tool. diff --git a/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/specs/roadmap-stage/paths-gate/spec.md b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/specs/roadmap-stage/paths-gate/spec.md new file mode 100644 index 0000000000..1174ce6f81 --- /dev/null +++ b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/specs/roadmap-stage/paths-gate/spec.md @@ -0,0 +1,20 @@ +## ADDED Requirements + +### Requirement: A workflow change carries its contract test in the same group +`path_problems` SHALL report a problem for each file under `.github/workflows/` with the suffix `.yml` that a group lists in `changes` when the `changes` of that group holds no `tests/invariants/test_workflow_contracts.py`. The problem SHALL name the group, the workflow and the contract test. The rule SHALL read `changes` only, so a group that reads a workflow and changes no workflow needs no contract test. + +#### Scenario: A workflow change without the contract test +- **WHEN** a group lists `.github/workflows/ci.yml` in `changes` and holds no `tests/invariants/test_workflow_contracts.py` +- **THEN** `path_problems` returns one problem, and it names the group, the workflow and the contract test + +#### Scenario: A workflow change with the contract test +- **WHEN** a group lists `.github/workflows/ci.yml` and `tests/invariants/test_workflow_contracts.py` in `changes` +- **THEN** `path_problems` returns no problem for the workflow contract rule + +#### Scenario: A source change that reads a workflow +- **WHEN** a group reads `.github/workflows/ci.yml` and changes only a file under `src/` +- **THEN** `path_problems` returns no problem for the workflow contract rule + +#### Scenario: Each workflow file of a group +- **WHEN** a group lists `.github/workflows/ci.yml` and `.github/workflows/release.yml` in `changes` and holds no contract test +- **THEN** `path_problems` returns one problem for each workflow file diff --git a/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/tasks.md b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/tasks.md new file mode 100644 index 0000000000..cad8c33822 --- /dev/null +++ b/openspec/changes/archive/2026-11-15-4083-workflow-change-requires-contract-test/tasks.md @@ -0,0 +1,5 @@ +# Tasks: #4083 + +- [x] 1.1 Add `workflow_contract_problems` and its message, and call it from `path_problems`. +- [x] 1.2 Add the four tests of the rule to `tests/roadmap/stage/test_roadmap_stage_paths.py`. +- [x] 2.1 Run the stage path, prompt and eval gate tests, and the static gate. diff --git a/openspec/specs/roadmap-stage/paths-gate/spec.md b/openspec/specs/roadmap-stage/paths-gate/spec.md index 62175b1b66..fc1eeb2d24 100644 --- a/openspec/specs/roadmap-stage/paths-gate/spec.md +++ b/openspec/specs/roadmap-stage/paths-gate/spec.md @@ -341,3 +341,29 @@ The stage job SHALL treat a Python module as moved only when a task group lists #### Scenario: A group moves a module into a sub-package - **WHEN** a group lists `src/devops_cli/roadmap/stage_probe.py` in `changes` and creates `src/devops_cli/roadmap/stage/probe.py`. - **THEN** the group moves `src/devops_cli/roadmap/stage_probe.py`, with the dotted name `devops_cli.roadmap.stage_probe`. + +### Requirement: A workflow change carries its contract test in the same group +`path_problems` SHALL report a problem for each file under `.github/workflows/` with the suffix `.yml` that a group lists in `changes` when the `changes` of that group holds no `tests/invariants/test_workflow_contracts.py`. The problem SHALL name the group, the workflow and the contract test. The rule SHALL read `changes` only, so a group that reads a workflow and changes no workflow needs no contract test. + +#### Scenario: A workflow change without the contract test +- **WHEN** a group lists `.github/workflows/ci.yml` in `changes` and holds no `tests/invariants/test_workflow_contracts.py` +- **THEN** `path_problems` returns one problem, and it names the group, the workflow and the contract test + +#### Scenario: A workflow change with the contract test +- **WHEN** a group lists `.github/workflows/ci.yml` and `tests/invariants/test_workflow_contracts.py` in `changes` +- **THEN** `path_problems` returns no problem for the workflow contract rule + +#### Scenario: A source change that reads a workflow +- **WHEN** a group reads `.github/workflows/ci.yml` and changes only a file under `src/` +- **THEN** `path_problems` returns no problem for the workflow contract rule + +#### Scenario: Each workflow file of a group +- **WHEN** a group lists `.github/workflows/ci.yml` and `.github/workflows/release.yml` in `changes` and holds no contract test +- **THEN** `path_problems` returns one problem for each workflow file + +### Requirement: The stage prompt asks for the contract test of a workflow change +The stage prompt `src/devops_cli/ai/tasks/roadmap_stage_change.md` SHALL tell the model that a group that changes a file under `.github/workflows/` lists `tests/invariants/test_workflow_contracts.py` in `changes` in the same group. + +#### Scenario: The planner reads the prompt +- **WHEN** the stage planner prompt is read +- **THEN** it holds the workflow directory and the contract test path in one instruction diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index 369cddb63a..73faf31331 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -5114,6 +5114,11 @@ class RoadmapMessages: "to `reads`, to the `Changes:` line or to a task of the group: the implement job cannot " "edit a test that the plan leaves out." ) + stage_problem_workflow_contract: str = ( + "Group {group} changes the workflow `{path}` and its `changes` holds no `{test}`. Add " + "the contract test to `changes`, and write its case in this group: actionlint and " + "zizmor pass without a test of the change." + ) stage_problem_constant_mismatch: str = ( "{constant} is {staged} in the staged tree, but the plan says {plan}." ) diff --git a/src/devops_cli/roadmap/stage/stage_paths.py b/src/devops_cli/roadmap/stage/stage_paths.py index 117898b3fa..07ee110ee1 100644 --- a/src/devops_cli/roadmap/stage/stage_paths.py +++ b/src/devops_cli/roadmap/stage/stage_paths.py @@ -660,6 +660,26 @@ def existing_test_problems( return problems +WORKFLOW_DIRECTORY = ".github/workflows/" +WORKFLOW_CONTRACT_TEST = "tests/invariants/test_workflow_contracts.py" + + +def workflow_contract_problems(groups: Sequence[StageGroup]) -> list[str]: + """One sentence for each workflow that a group changes without the contract test of + `tests/invariants/test_workflow_contracts.py` in the `changes` of the same group (#4083). + Actionlint and zizmor pass on a workflow that no contract test reads, and a later group + leaves the change with no test in the group that makes it.""" + return [ + MESSAGES.roadmap.stage_problem_workflow_contract.format( + group=number, path=path, test=WORKFLOW_CONTRACT_TEST + ) + for number, group in enumerate(groups, start=1) + if WORKFLOW_CONTRACT_TEST not in group.changes + for path in group.changes + if path.startswith(WORKFLOW_DIRECTORY) and path.endswith(".yml") + ] + + def path_problems( groups: Sequence[StageGroup], tree: StagedTree, @@ -699,6 +719,7 @@ def path_problems( reported.add(path) problems.append(_problem(number, place, path, tree, creators.get(path))) problems.extend(caller_problems(groups, tree)) + problems.extend(workflow_contract_problems(groups)) if references is not None: problems.extend(missing_reference_problems(groups, references)) return problems diff --git a/tests/roadmap/stage/test_roadmap_stage_form.py b/tests/roadmap/stage/test_roadmap_stage_form.py index aea972d105..3271b9fbf4 100644 --- a/tests/roadmap/stage/test_roadmap_stage_form.py +++ b/tests/roadmap/stage/test_roadmap_stage_form.py @@ -408,8 +408,11 @@ def _example_paths(text: str) -> list[str]: def _mirrored(path: str) -> bool: - """Whether the folder of `path` sits under `tests/` and mirrors a package of `src/devops_cli`.""" + """Whether the folder of `path` sits under `tests/` and mirrors a package of `src/devops_cli`, + or is the acceptance folder of the invariants (#4083).""" folder = Path(path).parent + if folder == Path("tests/invariants"): + return True package = REPO_ROOT / "src" / "devops_cli" / folder.relative_to("tests") return folder != Path("tests") and package.is_dir() diff --git a/tests/roadmap/stage/test_roadmap_stage_paths.py b/tests/roadmap/stage/test_roadmap_stage_paths.py index 3e2b18714c..abc3086afb 100644 --- a/tests/roadmap/stage/test_roadmap_stage_paths.py +++ b/tests/roadmap/stage/test_roadmap_stage_paths.py @@ -67,6 +67,59 @@ def _problems(*groups: StageGroup, tree: StagedTree = TREE) -> list[str]: return path_problems(groups, tree) +WORKFLOW = ".github/workflows/sample.yml" +CONTRACT_TEST = "tests/invariants/test_workflow_contracts.py" +WORKFLOW_TREE = StagedTree( + [ + "README.md", + "src/devops_cli/sample.py", + "tests/test_sample.py", + ".github/workflows/sample.yml", + "tests/invariants/test_workflow_contracts.py", + ] +) + + +# ── A workflow change carries its contract test in the same group (#4083) ────── + + +def test_a_workflow_change_without_the_contract_test_is_a_problem() -> None: + group = _group(changes=[WORKFLOW], reads=[]) + + (problem,) = path_problems([group], WORKFLOW_TREE) + + assert (f"`{WORKFLOW}`" in problem, f"`{CONTRACT_TEST}`" in problem, "Group 1" in problem) == ( + True, + True, + True, + ) + + +def test_a_workflow_change_with_the_contract_test_passes() -> None: + group = _group(changes=[WORKFLOW, CONTRACT_TEST], reads=[]) + + assert path_problems([group], WORKFLOW_TREE) == [] + + +def test_group_that_reads_a_workflow_and_changes_no_workflow_needs_no_contract_test() -> None: + group = _group(reads=[WORKFLOW]) + + assert path_problems([group], WORKFLOW_TREE) == [] + + +def test_each_workflow_file_of_a_group_needs_the_contract_test() -> None: + workflows = [".github/workflows/ci.yml", ".github/workflows/release.yml"] + tree = StagedTree([*WORKFLOW_TREE.files, *workflows]) + group = _group(changes=workflows, reads=[]) + + problems = path_problems([group], tree) + + assert [any(workflow in problem for problem in problems) for workflow in workflows] == [ + True, + True, + ] + + # ── A path that is a file, or that a group creates ──────────────────────────── diff --git a/tests/roadmap/stage/test_roadmap_stage_plan.py b/tests/roadmap/stage/test_roadmap_stage_plan.py index ab9f353f1c..534758fd7e 100644 --- a/tests/roadmap/stage/test_roadmap_stage_plan.py +++ b/tests/roadmap/stage/test_roadmap_stage_plan.py @@ -62,7 +62,7 @@ ) from devops_cli.roadmap.stage.stage_criteria import StageCriterion from devops_cli.roadmap.stage.stage_left_out import LeftOutKind -from devops_cli.roadmap.stage.stage_paths import StagedTree +from devops_cli.roadmap.stage.stage_paths import WORKFLOW_CONTRACT_TEST, StagedTree from devops_cli.roadmap.stage.stage_plan_record import delete_plan_record, plan_record_path from devops_cli.roadmap.stage.stage_references import reference_answer, reference_files from devops_cli.roadmap.stage.stage_registry import RegistryCount, registry_table @@ -2151,10 +2151,16 @@ def _tree(*paths: str) -> StagedTree: def _changing(*paths: str) -> StageProposal: - """The sample proposal, with one group that changes only `paths`.""" + """The sample proposal, with one group that changes only `paths`. A workflow change also lists + the contract test that the path rule needs (#4083).""" + listed = ( + (*paths, WORKFLOW_CONTRACT_TEST) + if any(path.startswith(".github/workflows/") for path in paths) + else paths + ) return make_stage_proposal( - groups=[_changed("Change the paths", *paths)], - what_changes=[f"`{path}` changes." for path in paths], + groups=[_changed("Change the paths", *listed)], + what_changes=[f"`{path}` changes." for path in listed], ) @@ -2162,7 +2168,9 @@ def _changing(*paths: str) -> StageProposal: def test_a_spec_delta_on_a_change_of_tests_workflows_documents_or_plans_is_refused( path: str, ) -> None: - assert check_proposal(_changing(path), [], _tree(path), registry=()) == [NO_SPEC_PROBLEM] + assert check_proposal( + _changing(path), [], _tree(path, WORKFLOW_CONTRACT_TEST), registry=() + ) == [NO_SPEC_PROBLEM] def test_a_spec_delta_on_every_path_of_every_group_that_needs_none_is_refused() -> None: