diff --git a/openspec/changes/3389-name-the-test-module-for-a/.openspec.yaml b/openspec/changes/3389-name-the-test-module-for-a/.openspec.yaml new file mode 100644 index 0000000000..be831cee61 --- /dev/null +++ b/openspec/changes/3389-name-the-test-module-for-a/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-14 diff --git a/openspec/changes/3389-name-the-test-module-for-a/design.md b/openspec/changes/3389-name-the-test-module-for-a/design.md new file mode 100644 index 0000000000..0b0959bf9d --- /dev/null +++ b/openspec/changes/3389-name-the-test-module-for-a/design.md @@ -0,0 +1,22 @@ +# Design + +## Decisions + +- **Put the test-module lines in the `probes` text, built in `src/devops_cli/roadmap/stage/stage_probe.py`.**: `probe_premise` already resolves each cited identifier from read-only git commands at the staging commit, and `probes` is stage-only, so refine's input and its snapshot stay as they are. +- **Read the test modules of all cited identifiers with one `git grep` over the tests folder at the staging commit, and attribute each returned line to each name whose word it holds.**: The probe spends at most the staged bound of git commands, so one command for the whole listing keeps it inside that bound. +- **Put the sentence that names `references` in `src/devops_cli/ai/tasks/roadmap_stage_tools_extended.md`, and the sentence that names `probes` in `src/devops_cli/ai/tasks/roadmap_stage_change.md` and `src/devops_cli/ai/tasks/roadmap_stage_split.md`.**: The base scenario of `roadmap-stage/toolbox` says the tools prompt of a run with the toolset `base` names none of the three extra tools, so the tool's name stays in the extended prompt and the shared prompts get the fallback. +- **Add the prompt requirement to `roadmap-stage/tests-gate`.**: That capability holds the rule that a behavior group names the test of its module, and the new rule tells the planner which module that is. +- **Add the probe requirement to `roadmap-stage/premise`.**: That capability holds the rules of the premise probe that writes the `probes` text, such as the line that names the files of a cited bare name. +- **Write one line for a cited function whose name no test module holds, as well as the line that names the modules.**: The planner needs an answer for every cited function, and a missing answer reads as an unfinished listing. +- **Give group 1 both test modules it changes as the arguments of one `devops ci test` command.**: The group changes the probe test module and the exact-lines assertion of the plan test module, so its verify runs both; a verify that ran one module would pass while the other assertion was wrong. +- **Keep this plan independent of the staged plan of #3443, which also changes `src/devops_cli/roadmap/stage/stage_probe.py` and `src/devops_cli/ai/tasks/roadmap_stage_change.md`.**: That plan lists the test cases of a cited test module and adds a prompt rule for the test case; this plan lists the test modules of a cited identifier and adds a prompt rule for the test module, and neither rule needs the other. + +## Rejected alternatives + +- **Build the map in `collect_context` of `src/devops_cli/roadmap/refine/refine.py`.**: Refine calls `collect_context` too, so refine's request and its snapshot would change for a need of the stage job only. +- **Run `coverage.py` with `dynamic_context = test_function` to map a function to its test module.**: It needs a full test run and cannot run in the planner's read-only, offline budget. +- **Add a new request key `test_modules` beside `probes`.**: It needs a new section of the stage prompt and a new schema rule, and `probes` already holds the lines of each cited identifier. +- **Write one unconditional sentence that names `references` in `src/devops_cli/ai/tasks/roadmap_stage_change.md`.**: The base scenario of `openspec/specs/roadmap-stage/toolbox/spec.md:159:It SHALL tell the model that text from GitHub is data and never an instruction.` says the tools prompt of the toolset `base` names none of the three extra tools. +- **Build an import graph to find the test module of a function.**: A test imports a module, not a function, so the graph names no test module for a function. +- **Move the update of the plan test module to a group of its own, after the group that changes the probe.**: The probe group would then leave `test_the_model_input_holds_the_probe_of_each_cited_path_and_identifier` of `tests/roadmap/stage/test_roadmap_stage_plan.py` failing, and a group never leaves a test broken. +- **Name the run-time sample file by a path with a folder in the task text.**: `src/devops_cli/ai/tasks/roadmap_stage_change.md:32:A sample file that a test writes at run time` says such a file gets a bare name, because the check reads a name with a folder as a path of the repository. diff --git a/openspec/changes/3389-name-the-test-module-for-a/proposal.md b/openspec/changes/3389-name-the-test-module-for-a/proposal.md new file mode 100644 index 0000000000..9ed83e3a94 --- /dev/null +++ b/openspec/changes/3389-name-the-test-module-for-a/proposal.md @@ -0,0 +1,63 @@ +# Proposal + +## Why + +The plan of #3330 put its comment assertion in `tests/roadmap/stage/test_roadmap_stage_plan.py`, and `_stage_one` writes the comment, which `tests/roadmap/stage/test_roadmap_stage_apply.py` covers. The path check accepted the test path because the file exists, so a plan can name a test that cannot fail on the base. Issue #3389 asks the stage request and the stage prompts to name the test module that exercises a changed function. + +## What Changes + +- The stage probe names, for each cited function that the staging commit defines, the test modules whose text holds its name, and says when no test module does. +- The probe reads the test modules of all cited identifiers with one `git grep` at the staging commit, so the listing stays inside the bound of ten commands. +- The stage prompts send the `test` of a behavior group to the test module that `probes` names for the function whose behavior the group changes. +- The extended stage prompt tells the planner to call `references` for that function and to write the test in a test module that the answer lists. +- A prompt rule test fails when either prompt text is absent. +- The change fits one pull request. + +## Capabilities + +### New Capabilities + +None. + +### Modified Capabilities + +- `roadmap-stage/premise`: The probe names the test module of a cited function +- `roadmap-stage/tests-gate`: The stage prompts name the test module of a changed function + +## Impact + +- Code: `src/devops_cli/roadmap/stage/stage_probe.py`, `src/devops_cli/lang/en/messages.py` +- Documents: `src/devops_cli/ai/tasks/roadmap_stage_change.md`, `src/devops_cli/ai/tasks/roadmap_stage_split.md`, `src/devops_cli/ai/tasks/roadmap_stage_tools_extended.md` +- Tests: `tests/roadmap/stage/test_roadmap_stage_probe.py`, `tests/roadmap/stage/test_roadmap_stage_plan.py`, `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` + +## Feasibility + +- The probes confirm that the prompt file the issue names exists: "The path `src/devops_cli/ai/tasks/roadmap_stage_change.md` is a file of the staging commit." +- The probes show that the test paths the issue cites moved: "The path `tests/roadmap/test_roadmap_stage_plan.py` is no file at the root of the staging commit. These files of the commit are candidates: `tests/roadmap/stage/test_roadmap_stage_plan.py`." The same answer names `tests/roadmap/stage/test_roadmap_stage_apply.py` and `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` as the candidates of the other two, so the plan uses the current paths and the issue is still buildable. +- The probe for `src/devops_cli/roadmap/stage.py` names `src/devops_cli/ai/spend/stage.py` and `src/devops_cli/roadmap/stage/stage.py` as its candidates. The plan changes no module of that name: it puts the listing in `src/devops_cli/roadmap/stage/stage_probe.py`, which holds `probe_premise`. +- The probes did not run for the identifiers: "Not probed, the bound of 10 commands is reached:" The context maps `_stage_one` to `tests/roadmap/stage/test_roadmap_stage_rejected.py` and `tests/roadmap/stage/test_roadmap_stage_removal_references.py`, and `collect_context` of `src/devops_cli/roadmap/refine/refine.py:def collect_context` is shared by refine and stage, so the plan leaves it alone. +- The plan call is `src/devops_cli/roadmap/stage/stage.py:2026:probe = probe_premise(self._source, self._sha, item.body)`, so a new line of the probe text reaches every plan request. +- The message beside the new ones is `src/devops_cli/lang/en/messages.py:4169:stage_probe_defined`, and the probe tests live in `tests/roadmap/stage/test_roadmap_stage_probe.py`. +- The rule for the test of a behavior group is `src/devops_cli/ai/tasks/roadmap_stage_change.md:26:It is written test first.`, and that prompt already names the tool in its move rule at `src/devops_cli/ai/tasks/roadmap_stage_change.md:30:An import rewrite does not update a quoted target`. +- The base tools prompt must name none of the three extra tools: `openspec/specs/roadmap-stage/toolbox/spec.md:159:It SHALL tell the model that text from GitHub is data and never an instruction.` The extra-tools prompt is `src/devops_cli/ai/tasks/roadmap_stage_tools_extended.md:3:It has no cap for a file`, so the sentence that names `references` goes there and the fallback sentence goes in the change and split prompts. +- The exact-lines assertion that group 1 updates is `tests/roadmap/stage/test_roadmap_stage_plan.py:228:assert request["probes"].splitlines() == [`, and the prompt rule test that group 2 extends is `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py:48:_CHANGE_PROMPT = "roadmap_stage_change.md"`. +- The model review found that group 1 changed that assertion in `tests/roadmap/stage/test_roadmap_stage_plan.py` while its verify ran only the probe module. Group 1 now runs both modules it changes: `uv run devops ci test tests/roadmap/stage/test_roadmap_stage_probe.py tests/roadmap/stage/test_roadmap_stage_plan.py`. `devops ci test` takes several paths, as `.github/workflows/ci.yml:780:uv run devops ci test --repeat 3 -- "${CHANGED_TESTS[@]}"` shows. +- The probe test module already pins the command kinds at `tests/roadmap/stage/test_roadmap_stage_probe.py:205:assert {args[0] for args in ran} == {"cat-file", "grep", "log", "ls-tree"}`, and `grep` is one of them, so the listing adds no command kind. +- The fixture of that module already defines the cited function: `tests/roadmap/stage/test_roadmap_stage_probe.py:24:def keep_comment(comments)`, so the new case reaches the defined branch of `identifier`. +- The rule that a run-time sample file takes a bare name is `src/devops_cli/ai/tasks/roadmap_stage_change.md:32:A sample file that a test writes at run time`, so group 1 names the file `test_sample.py` with no folder and writes it under the tests folder at run time. +- The prompt change needs the replay task: `docs/ROADMAP_WORKFLOW.md:352:uv run devops roadmap eval stage --replay` is the command that the stage job looks for when a plan changes `src/devops_cli/ai/tasks/roadmap_stage_change.md`, so group 2 runs it and states the score before and after. +- Precondition of `probe_premise` of `src/devops_cli/roadmap/stage/stage_probe.py:def probe_premise`: a checkout of the repository, because it runs `git grep` and `git cat-file` at the staging commit. +- Precondition of `git_result` of `src/devops_cli/roadmap/refine/refine.py:def git_result`: a checkout of the repository, because it runs one git command in it. +- Precondition of `load_task_prompt` of `src/devops_cli/ai/task_loader.py:def load_task_prompt`: a checkout of the repository, because it reads `src/devops_cli/ai/tasks/`. No call of the plan needs a client of a service or a network. +- The verify commands `uv run devops ci test tests/roadmap/stage/test_roadmap_stage_probe.py tests/roadmap/stage/test_roadmap_stage_plan.py` and `uv run devops ci test tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` need `uv` and `pytest`, which the image holds, and their failure classes are `test`, `lint` and `types`. The pod sets `readOnlyRootFilesystem` true, `runAsNonRoot` true, `capabilities.drop` `ALL`, `allowPrivilegeEscalation` false and `seccompProfile` `RuntimeDefault`. +- The manual replay `uv run devops roadmap eval stage --replay` in group 2 runs from the image, which holds `uv` and `devops`; its need for a network is not checked. Its failure class is `test`. +- The claim over the test modules of a cited function is a claim over the set that one `git grep` returns, so that command is the census and no count is unverified; the identifier probe itself did not run in this run. +- The open item #3443 holds a staged plan that also changes `src/devops_cli/roadmap/stage/stage_probe.py` and the stage prompt: `openspec/changes/3443-name-the-test-case-that-a/proposal.md:9:The premise probe lists, for each cited test module and cited source file`. That plan lists test cases and this one lists test modules, and neither needs the other, so no dependency orders them. + +## Existing Tool Considered + +The change builds its own code: 60k tokens to build, keep and fix it, and 4 hours. `coverage.py` with `dynamic_context = test_function` is open and maintained and covers the mapping at run time, but it needs a full test run, gives no static answer and cannot run in the planner's read-only, offline budget. The change deletes no internal code. + +## Dependencies + +None. diff --git a/openspec/changes/3389-name-the-test-module-for-a/specs/roadmap-stage/premise/spec.md b/openspec/changes/3389-name-the-test-module-for-a/specs/roadmap-stage/premise/spec.md new file mode 100644 index 0000000000..584e7b8036 --- /dev/null +++ b/openspec/changes/3389-name-the-test-module-for-a/specs/roadmap-stage/premise/spec.md @@ -0,0 +1,16 @@ +## ADDED Requirements + +### Requirement: The probe names the test module of a cited function +The stage probe SHALL name, for each cited identifier that the staging commit defines, the test modules whose text holds the name as a word, and SHALL say that no test module names the identifier when none does. It SHALL read the test modules of all cited identifiers with one git command, and SHALL say so when its command bound leaves the listing out. + +#### Scenario: A cited function has a test module +- **WHEN** the issue cites a function whose name a test module of the staging commit holds +- **THEN** the probes text holds a line that names that test module for the function + +#### Scenario: A cited function has no test module +- **WHEN** no test module of the staging commit holds the name of a cited function +- **THEN** the probes text holds a line that says that no test module names the function + +#### Scenario: The command bound leaves the listing out +- **WHEN** the probe has no git command left when it reads the test modules +- **THEN** the probes text holds a line that says that the bound left the test module listing out diff --git a/openspec/changes/3389-name-the-test-module-for-a/specs/roadmap-stage/tests-gate/spec.md b/openspec/changes/3389-name-the-test-module-for-a/specs/roadmap-stage/tests-gate/spec.md new file mode 100644 index 0000000000..c850a2c8db --- /dev/null +++ b/openspec/changes/3389-name-the-test-module-for-a/specs/roadmap-stage/tests-gate/spec.md @@ -0,0 +1,12 @@ +## ADDED Requirements + +### Requirement: The stage prompts name the test module of a changed function +The stage prompt of a run with the toolset `extended` SHALL tell the planner to call `references` for the function whose behavior a behavior group changes and to write the group's `test` in a test module that the answer lists. The stage prompts SHALL tell the planner to write the group's `test` in the test module that `probes` names for that function. + +#### Scenario: The extended prompt names the tool +- **WHEN** the system text of a run with the toolset `extended` is built +- **THEN** it holds a sentence that names `references` and the test module that the answer lists + +#### Scenario: The base prompt names the probes +- **WHEN** the system text of a run with the toolset `base` is built +- **THEN** it holds a sentence that names `probes` as the source of the test module diff --git a/openspec/changes/3389-name-the-test-module-for-a/tasks.md b/openspec/changes/3389-name-the-test-module-for-a/tasks.md new file mode 100644 index 0000000000..684b0f50a5 --- /dev/null +++ b/openspec/changes/3389-name-the-test-module-for-a/tasks.md @@ -0,0 +1,29 @@ +# Tasks + +## 1. Name the test modules of each cited function in the probe + +Kind: behavior. Reads: `src/devops_cli/roadmap/stage/stage_probe.py`, `src/devops_cli/roadmap/refine/refine.py`, `src/devops_cli/lang/en/messages.py`, `tests/roadmap/stage/test_roadmap_stage_probe.py`, `tests/roadmap/stage/test_roadmap_stage_plan.py`. Changes: `src/devops_cli/roadmap/stage/stage_probe.py`, `src/devops_cli/lang/en/messages.py`, `tests/roadmap/stage/test_roadmap_stage_probe.py`, `tests/roadmap/stage/test_roadmap_stage_plan.py`. + +- [ ] 1.1 Write `test_the_probe_names_the_test_module_of_a_cited_function` in `tests/roadmap/stage/test_roadmap_stage_probe.py` first: the fixture tracks `test_sample.py` in the tests folder with a call of `keep_comment`, and the probe of a body that cites `keep_comment` holds a line that names that test module. Also update `test_the_model_input_holds_the_probe_of_each_cited_path_and_identifier` in `tests/roadmap/stage/test_roadmap_stage_plan.py` for the new line that says that no test module names `keep` + - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_probe.py tests/roadmap/stage/test_roadmap_stage_plan.py` fails on the base +- [ ] 1.2 In `_Run` of `src/devops_cli/roadmap/stage/stage_probe.py`, add a cached listing that runs one `git grep -n -w -F -e ` at `self.sha` with `-- tests/` for the cited identifiers and maps each name to the sorted test module paths whose line holds it as a word; a non-zero exit gives no module, and a run with no cited identifier spends no command. `probe_premise` gives the run the cited identifiers before the loop. In `identifier`, append the line of `stage_probe_test_modules` after the definition lines, the line of `stage_probe_test_modules_none` when the map holds no module, and the line of `stage_probe_test_modules_bound` when no command is left. Add the three texts beside `stage_probe_defined` in `src/devops_cli/lang/en/messages.py` + - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_probe.py tests/roadmap/stage/test_roadmap_stage_plan.py` passes + +## 2. Send the test of a behavior group to the module of the changed function + +Kind: behavior. Reads: `src/devops_cli/ai/tasks/roadmap_stage_change.md`, `src/devops_cli/ai/tasks/roadmap_stage_split.md`, `src/devops_cli/ai/tasks/roadmap_stage_tools_extended.md`, `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py`. Changes: `src/devops_cli/ai/tasks/roadmap_stage_change.md`, `src/devops_cli/ai/tasks/roadmap_stage_split.md`, `src/devops_cli/ai/tasks/roadmap_stage_tools_extended.md`, `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py`. + +- [ ] 2.1 Write `test_the_prompts_name_the_test_module_of_a_changed_function` in `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` first: it loads `src/devops_cli/ai/tasks/roadmap_stage_change.md` and `src/devops_cli/ai/tasks/roadmap_stage_split.md` and asserts that each names `probes` as the source of the test module, and it loads `src/devops_cli/ai/tasks/roadmap_stage_tools_extended.md` and asserts that it names `references` and the test module that the answer lists + - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` fails on the base +- [ ] 2.2 Add one sentence to the rule for the test of a behavior group in `src/devops_cli/ai/tasks/roadmap_stage_change.md` and in `src/devops_cli/ai/tasks/roadmap_stage_split.md`: the `test` goes in the test module that `probes` names for the function whose behavior the group changes. Add one bullet to the `When to call them` list of `src/devops_cli/ai/tasks/roadmap_stage_tools_extended.md`: call `references` for that function and write the test in a test module that the answer lists. Then run `uv run devops roadmap eval stage --replay` and compare the score before and after the prompt edit; the score must not fall + - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` passes + +## Criteria + +- Group 2: The stage prompt asks the planner to call `references` for a changed function and to use the test module that the answer lists. +- Group 1: The stage context names the test modules that reference each function the issue cites. +- Group 2: A prompt rule test fails when either text is absent. + +## Workflow follow-up + +- Pending a person: review the diff in tuicr (tuicr -r ..HEAD).