diff --git a/docs/roadmap/stage.md b/docs/roadmap/stage.md index cb0d19bebf..280c1cfbf1 100644 --- a/docs/roadmap/stage.md +++ b/docs/roadmap/stage.md @@ -79,6 +79,10 @@ The MCP server publishes no tool for `roadmap eval stage`: the command is no row The trace gate refuses a Feasibility sentence that claims a read of the run for a path that the plan runs did not see. A read word (`read`, `reads`, `reading`, `ran`, or the tool `read_file`, also in a span `` `read_file path` ``) is a claim of the run when it has no subject (`` Read `x` ``, `the same read`, `` a quick read of `x` ``), when it is a passive or a participle (`` `x` was read ``, `` `x`, read at the base ``), or when its subject names the run or its author (`I`, `we`, `the run`, `the planner`). A verb of a list has the subject of the list, as in `` I listed `src/`, opened `x` and read `y` ``. A read whose subject is other words, such as `this plan`, `group 2`, `the probe` or `it`, says what the plan or the code does, and `read-only` is no read word. The gate judges the path that the read takes: the path of its `` `read_file path` `` span, without the start and end line after the path, as in `` `read_file path 50 215` ``, the path before a participle, the subject of a passive, else the first path of its object, else the last path before it, else the first path of its result. The object ends at `;`, at a comma before a new clause, or at a verb of the result, such as `shows`, and a pronoun at its start, such as `it` or `that file`, makes the read take the path before it. So in "`read_file` on it showed the text `x.py`" the read takes the path before it, not `x.py`. A run saw a path that a tool call took as its argument. A `search_code` or `callers` match shows one line, so a read whose object is a citation of that line, `path:line` or `path:line:text`, counts as seen. `read_file`, a read that takes the line through a pronoun or from its result, and a claim of the whole file do not. A probe line is no read: it says only whether a path is a file. +## Constant claims + +The stage reply holds `constant_claims`. Each entry gives a constant name and its integer value in the staged tree that the plan relies on. The plan check refuses a claim whose value differs from the staged value of that constant. It also refuses a claim that names no module-level integer of the staged tree. A constant that the plan creates is not a claim. + ## The spec delta The spec of each capability in the reply has four lists, one for each delta kind of OpenSpec: `added`, `modified`, `renamed` and `removed` (#5340). A rename gives `from_name` and `to_name`, and the delta file writes it as a `- FROM:` line and a `- TO:` line under `## RENAMED Requirements`. A removal gives the name, the `reason` and an optional `migration`, and the delta file writes it as a requirement header with a `**Reason**:` line and a `**Migration**:` line under `## REMOVED Requirements`. The archive renames before it modifies, so a `modified` requirement whose text no longer fits its old name gets a `renamed` entry and takes the new name. The job copies the base scenarios that such a block omits from the old name. The gate refuses a rename or a removal on a new capability, a `from_name` or a removed name that the base spec does not have, and a `to_name` that the base spec has already. `openspec validate --strict` passes these names: it gives only the first rename that `openspec archive` refuses, as an INFO line, and no line for such a removal, which the archive skips with a warning. The review reports a `modified` requirement whose name no longer fits its text as `spec_delta_wrong`. diff --git a/openspec/changes/3388-the-stage-plan-states-constant-claims/.openspec.yaml b/openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/.openspec.yaml similarity index 100% rename from openspec/changes/3388-the-stage-plan-states-constant-claims/.openspec.yaml rename to openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/.openspec.yaml diff --git a/openspec/changes/3388-the-stage-plan-states-constant-claims/design.md b/openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/design.md similarity index 100% rename from openspec/changes/3388-the-stage-plan-states-constant-claims/design.md rename to openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/design.md diff --git a/openspec/changes/3388-the-stage-plan-states-constant-claims/proposal.md b/openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/proposal.md similarity index 100% rename from openspec/changes/3388-the-stage-plan-states-constant-claims/proposal.md rename to openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/proposal.md diff --git a/openspec/changes/3388-the-stage-plan-states-constant-claims/specs/roadmap-stage/claims/spec.md b/openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/specs/roadmap-stage/claims/spec.md similarity index 100% rename from openspec/changes/3388-the-stage-plan-states-constant-claims/specs/roadmap-stage/claims/spec.md rename to openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/specs/roadmap-stage/claims/spec.md diff --git a/openspec/changes/3388-the-stage-plan-states-constant-claims/tasks.md b/openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/tasks.md similarity index 91% rename from openspec/changes/3388-the-stage-plan-states-constant-claims/tasks.md rename to openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/tasks.md index 009b4f4d85..00e72249df 100644 --- a/openspec/changes/3388-the-stage-plan-states-constant-claims/tasks.md +++ b/openspec/changes/archive/2026-11-23-3388-the-stage-plan-states-constant-claims/tasks.md @@ -4,38 +4,38 @@ Kind: behavior. Reads: `src/devops_cli/roadmap/stage/stage_change.py`, `src/devops_cli/ai/tasks/roadmap_stage_change.md`, `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py`, `tests/roadmap/stage/test_roadmap_stage_constants.py`. Changes: `src/devops_cli/roadmap/stage/stage_change.py`, `src/devops_cli/ai/tasks/roadmap_stage_change.md`, `tests/roadmap/stage/test_roadmap_stage_constants.py`, `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py`. -- [ ] 1.1 Write `test_the_stage_reply_holds_constant_claims` for `StageConstantClaim` and `constant_claims` in `tests/roadmap/stage/test_roadmap_stage_constants.py`; it fails on the base, where `StageProposal` ends its fields at `src/devops_cli/roadmap/stage/stage_change.py:699:security: Line = ""` and holds no `constant_claims`. Add `test_the_plan_check_accepts_the_plan_of_this_change`, which builds the plan's own `StageProposal` and asserts that `content_problems` returns no problem for it. Add `StageConstantClaim` to the models of `test_each_list_of_keys_of_the_reply_is_the_fields_of_a_model` in `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` for the key bullet of `src/devops_cli/ai/tasks/roadmap_stage_change.md` +- [x] 1.1 Write `test_the_stage_reply_holds_constant_claims` for `StageConstantClaim` and `constant_claims` in `tests/roadmap/stage/test_roadmap_stage_constants.py`; it fails on the base, where `StageProposal` ends its fields at `src/devops_cli/roadmap/stage/stage_change.py:699:security: Line = ""` and holds no `constant_claims`. Add `test_the_plan_check_accepts_the_plan_of_this_change`, which builds the plan's own `StageProposal` and asserts that `content_problems` returns no problem for it. Add `StageConstantClaim` to the models of `test_each_list_of_keys_of_the_reply_is_the_fields_of_a_model` in `tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` for the key bullet of `src/devops_cli/ai/tasks/roadmap_stage_change.md` - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_constants.py tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` fails on the base -- [ ] 1.2 Add `StageConstantClaim` with `name` and `value`, and the `constant_claims` list with an empty default, to `StageProposal` in `src/devops_cli/roadmap/stage/stage_change.py`, and refuse a `name` that is not a Python identifier. Add the `constant_claims` bullet with its key list to the reply keys of `src/devops_cli/ai/tasks/roadmap_stage_change.md`, with the rule that a claim names a constant of the staged tree and that a constant the plan creates is no claim. Run `uv run devops roadmap eval stage --replay` and record the score before and after the prompt change +- [x] 1.2 Add `StageConstantClaim` with `name` and `value`, and the `constant_claims` list with an empty default, to `StageProposal` in `src/devops_cli/roadmap/stage/stage_change.py`, and refuse a `name` that is not a Python identifier. Add the `constant_claims` bullet with its key list to the reply keys of `src/devops_cli/ai/tasks/roadmap_stage_change.md`, with the rule that a claim names a constant of the staged tree and that a constant the plan creates is no claim. Run `uv run devops roadmap eval stage --replay` and record the score before and after the prompt change - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_constants.py tests/roadmap/stage/test_roadmap_stage_prompt_rules.py` passes -- [ ] 1.3 Edit `src/devops_cli/ai/tasks/roadmap_stage_change.md` +- [x] 1.3 Edit `src/devops_cli/ai/tasks/roadmap_stage_change.md` - Verification: `$ uv run devops ci docs` passes ## 2. Judge each structured claim in the plan check Kind: behavior. Reads: `src/devops_cli/roadmap/stage/stage_change.py`, `src/devops_cli/roadmap/stage/stage_constants.py`, `src/devops_cli/lang/en/messages.py`, `tests/roadmap/stage/test_roadmap_stage_plan.py`. Changes: `src/devops_cli/roadmap/stage/stage_change.py`, `src/devops_cli/lang/en/messages.py`, `tests/roadmap/stage/test_roadmap_stage_plan.py`. -- [ ] 2.1 Write `test_check_proposal_refuses_a_wrong_constant_claim`, `test_check_proposal_refuses_a_claim_the_tree_does_not_define`, `test_check_proposal_runs_the_prose_scan_only_with_no_claim_list` and `test_check_proposal_judges_no_claim_without_staged_values` in `tests/roadmap/stage/test_roadmap_stage_plan.py`. They fail on the base, where `check_proposal` judges only the prose of `src/devops_cli/roadmap/stage/stage_change.py:2440:ProposalGate.CONSTANTS: constant_problems(plan_texts(proposal), constants or {}),`. Keep `test_the_plan_check_accepts_the_plan_of_this_change` passing: it builds the plan's own `StageProposal` and asserts that `content_problems` returns no problem for it +- [x] 2.1 Write `test_check_proposal_refuses_a_wrong_constant_claim`, `test_check_proposal_refuses_a_claim_the_tree_does_not_define`, `test_check_proposal_runs_the_prose_scan_only_with_no_claim_list` and `test_check_proposal_judges_no_claim_without_staged_values` in `tests/roadmap/stage/test_roadmap_stage_plan.py`. They fail on the base, where `check_proposal` judges only the prose of `src/devops_cli/roadmap/stage/stage_change.py:2440:ProposalGate.CONSTANTS: constant_problems(plan_texts(proposal), constants or {}),`. Keep `test_the_plan_check_accepts_the_plan_of_this_change` passing: it builds the plan's own `StageProposal` and asserts that `content_problems` returns no problem for it - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_plan.py tests/roadmap/stage/test_roadmap_stage_constants.py` fails on the base -- [ ] 2.2 Add `claim_problems` to `src/devops_cli/roadmap/stage/stage_change.py`: with no `constants` it judges no claim; otherwise it refuses a claim whose value differs with `stage_problem_constant_mismatch`, and a claim whose name the mapping lacks with the new `stage_problem_constant_undefined`. Run the prose scan only when `constant_claims` is empty. Add `stage_problem_constant_undefined` to `src/devops_cli/lang/en/messages.py`. Run `uv run devops roadmap eval stage --replay` and record the score before and after the gate change +- [x] 2.2 Add `claim_problems` to `src/devops_cli/roadmap/stage/stage_change.py`: with no `constants` it judges no claim; otherwise it refuses a claim whose value differs with `stage_problem_constant_mismatch`, and a claim whose name the mapping lacks with the new `stage_problem_constant_undefined`. Run the prose scan only when `constant_claims` is empty. Add `stage_problem_constant_undefined` to `src/devops_cli/lang/en/messages.py`. Run `uv run devops roadmap eval stage --replay` and record the score before and after the gate change - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_plan.py tests/roadmap/stage/test_roadmap_stage_constants.py` passes ## 3. Read the staged value of each claimed name Kind: behavior. Reads: `src/devops_cli/roadmap/stage/stage_constants.py`, `src/devops_cli/roadmap/stage/stage.py`, `tests/roadmap/stage/test_roadmap_stage_apply.py`. Changes: `src/devops_cli/roadmap/stage/stage_constants.py`, `src/devops_cli/roadmap/stage/stage.py`, `tests/roadmap/stage/test_roadmap_stage_constants.py`. -- [ ] 3.1 Write `test_claimed_names_adds_the_names_of_the_claims` for `claimed_names` in `tests/roadmap/stage/test_roadmap_stage_constants.py`; it fails on the base, where `src/devops_cli/roadmap/stage/stage_constants.py:287:__all__ = [` lists no `claimed_names`. Keep the stage job cases of `tests/roadmap/stage/test_roadmap_stage_apply.py` passing +- [x] 3.1 Write `test_claimed_names_adds_the_names_of_the_claims` for `claimed_names` in `tests/roadmap/stage/test_roadmap_stage_constants.py`; it fails on the base, where `src/devops_cli/roadmap/stage/stage_constants.py:287:__all__ = [` lists no `claimed_names`. Keep the stage job cases of `tests/roadmap/stage/test_roadmap_stage_apply.py` passing - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_constants.py tests/roadmap/stage/test_roadmap_stage_apply.py` fails on the base -- [ ] 3.2 Add `claimed_names(texts, claimed)` to `src/devops_cli/roadmap/stage/stage_constants.py`: the names that `candidate_names` finds in `texts`, with each claimed name. Call it at `src/devops_cli/roadmap/stage/stage.py:2230:constants = staged_constants(self._source, self._sha, candidate_names(plan_texts(proposal)))`, so the reader sees each claimed name +- [x] 3.2 Add `claimed_names(texts, claimed)` to `src/devops_cli/roadmap/stage/stage_constants.py`: the names that `candidate_names` finds in `texts`, with each claimed name. Call it at `src/devops_cli/roadmap/stage/stage.py:2230:constants = staged_constants(self._source, self._sha, candidate_names(plan_texts(proposal)))`, so the reader sees each claimed name - Verification: `$ uv run devops ci test tests/roadmap/stage/test_roadmap_stage_constants.py tests/roadmap/stage/test_roadmap_stage_apply.py` passes ## 4. Describe the claim list in the stage guide Kind: other. Reads: `docs/roadmap/stage.md`, `src/devops_cli/ai/tasks/roadmap_stage_change.md`. Changes: `docs/roadmap/stage.md`. -- [ ] 4.1 Describe the `constant_claims` key of the stage reply in `docs/roadmap/stage.md`: one entry for each constant that the plan relies on, with its staged value, the refusal of a claim that differs from the staged value, and the refusal of a claim that names no module-level integer of the staged tree +- [x] 4.1 Describe the `constant_claims` key of the stage reply in `docs/roadmap/stage.md`: one entry for each constant that the plan relies on, with its staged value, the refusal of a claim that differs from the staged value, and the refusal of a claim that names no module-level integer of the staged tree - Verification: `$ uv run devops ci docs` passes -- [ ] 4.2 Edit `docs/roadmap/stage.md` +- [x] 4.2 Edit `docs/roadmap/stage.md` - Verification: `$ uv run devops ci docs` passes ## Workflow follow-up diff --git a/openspec/specs/roadmap-stage/claims/spec.md b/openspec/specs/roadmap-stage/claims/spec.md index 079b775942..758b508060 100644 --- a/openspec/specs/roadmap-stage/claims/spec.md +++ b/openspec/specs/roadmap-stage/claims/spec.md @@ -71,19 +71,19 @@ The plan check SHALL refuse a plan when a sentence names one known module-level - **WHEN** A task says "Raise `SUMMARY_MAX_CHARS` to 80", or a test patches `SUMMARY_MAX_CHARS` to 1, and the staged tree sets `SUMMARY_MAX_CHARS = 60`. - **THEN** The check returns no problem about `SUMMARY_MAX_CHARS`, because the staged tree is the commit before the change. -### Requirement: A constant that the staged tree does not define is ignored -The plan check MUST skip a constant name that the staged tree does not define as a module-level integer assignment. +### Requirement: The prose scan ignores a constant that the staged tree does not define +The prose scan of constant claims MUST skip a constant name that the staged tree does not define as a module-level integer assignment. #### Scenario: New plan constant - **WHEN** A design decision names `PLAN_SUMMARY_MAX_CHARS = 47`, and the staged tree does not define `PLAN_SUMMARY_MAX_CHARS`. - **THEN** The check returns no problem about `PLAN_SUMMARY_MAX_CHARS`. #### Scenario: Non-literal assignment -- **WHEN** A staged module sets `SUMMARY_MAX_CHARS` from a call, and the plan says `SUMMARY_MAX_CHARS` is 40. +- **WHEN** A staged module sets `SUMMARY_MAX_CHARS` from a call, and the plan gives it the value 40. - **THEN** The check returns no problem about `SUMMARY_MAX_CHARS`. #### Scenario: Ambiguous definition -- **WHEN** Two staged modules set `SUMMARY_MAX_CHARS` to different integers, and the plan says `SUMMARY_MAX_CHARS` is 40. +- **WHEN** Two staged modules set `SUMMARY_MAX_CHARS` to different integers, and the plan gives it the value 40. - **THEN** The check returns no problem about `SUMMARY_MAX_CHARS`, because the tree holds no one value. ### Requirement: The check reads constants without running staged code @@ -116,12 +116,16 @@ The stage eval replay MUST pass the constants of a case to the plan check and MU - **THEN** The replay runs the check with an empty mapping and keeps the result it gives today. ### Requirement: The prompt asks for the staged value of a constant -The plan stage prompt SHALL tell the model to cite the staged value of each constant that the plan relies on, and to give no new name to the bound of a constant that the staged tree defines. +The plan stage prompt SHALL list `constant_claims` among the reply keys and tell the model to cite the staged value of each constant that the plan relies on, with the constant name and its value, and to give no new name to the bound of a constant that the staged tree defines. It SHALL state that a claim names a constant that the staged tree defines, and that a constant the plan creates is no claim. #### Scenario: Prompt rule - **WHEN** The prompt rules test reads `src/devops_cli/ai/tasks/roadmap_stage_change.md`. - **THEN** The text holds an instruction to cite the staged value of each constant that the plan relies on. +#### Scenario: Prompt claim rule +- **WHEN** The test reads the text of `src/devops_cli/ai/tasks/roadmap_stage_change.md`. +- **THEN** The text holds the sentence that a claim names a constant of the staged tree and that a constant the plan creates is no claim. + ### Requirement: A read of a model attribute that the model lacks is refused The stage proposal check SHALL refuse a plan that names an attribute that the Pydantic model of the staged commit does not define, and SHALL name the reference and the module of the model in the problem. @@ -334,3 +338,58 @@ The plan check SHALL refuse a plan that cites a `devops` command line that gives #### Scenario: The summary option is missing from a plan line - **WHEN** a plan cites `devops pr describe 1` in its Feasibility text - **THEN** the citation gate returns a problem that names `--summary`, and the plan check refuses the plan + +### Requirement: The stage reply holds structured constant claims +`StageProposal` SHALL hold `constant_claims`, a list of `StageConstantClaim` entries that each give a constant `name` and an integer `value`, and the list MUST be empty when a reply omits it. `StageConstantClaim` MUST refuse a `name` that is not a Python identifier. + +#### Scenario: A reply with one claim +- **WHEN** A reply gives `constant_claims` with the name `SUMMARY_MAX_CHARS` and the value 60. +- **THEN** The validated proposal holds one entry, and the entry keeps the name `SUMMARY_MAX_CHARS` and the value 60. + +#### Scenario: A reply with no claim list +- **WHEN** A reply gives no `constant_claims`. +- **THEN** The validated proposal holds an empty `constant_claims` and no validation error. + +#### Scenario: A name with a hyphen +- **WHEN** A reply gives the claim name `SUMMARY-MAX`. +- **THEN** Validation raises an error for `constant_claims`. + +### Requirement: A structured claim matches the staged value +`check_proposal` SHALL refuse a claim whose value differs from the staged value of its name, and the message SHALL name the constant and the staged value. `check_proposal` SHALL refuse a claim whose name the staged values do not hold, and the message SHALL name the constant. + +#### Scenario: A claim with the staged value +- **WHEN** The plan claims `SUMMARY_MAX_CHARS` with the value 60, and the staged value is 60. +- **THEN** No problem names `SUMMARY_MAX_CHARS`. + +#### Scenario: A claim with another value +- **WHEN** The plan claims `SUMMARY_MAX_CHARS` with the value 40, and the staged value is 60. +- **THEN** One problem names `SUMMARY_MAX_CHARS` and the staged value 60. + +#### Scenario: A claim the staged values do not hold +- **WHEN** The plan claims `PLAN_SUMMARY_MAX_CHARS` with the value 47, and the staged values hold no such name. +- **THEN** One problem names `PLAN_SUMMARY_MAX_CHARS`. + +### Requirement: The prose scan runs only when the claim list is empty +`check_proposal` SHALL run the prose scan of constant claims only when `constant_claims` is empty. + +#### Scenario: A reply with no claim list and a prose claim +- **WHEN** A reply gives no `constant_claims`, and a design decision quotes `SUMMARY_MAX_CHARS: Final[int] = 40` while the staged tree sets `SUMMARY_MAX_CHARS = 60`. +- **THEN** The check returns the prose problem for that sentence. + +#### Scenario: A reply with a claim list and a prose claim +- **WHEN** A reply gives a claim for `SUMMARY_MAX_CHARS` and a sentence holds two numbers beside it. +- **THEN** The check returns no prose problem for that sentence. + +### Requirement: A caller with no staged values judges no claim +`check_proposal` SHALL judge no constant claim when its caller gives no staged values. + +#### Scenario: A caller with no staged values +- **WHEN** `check_proposal` runs with no `constants` argument on a plan whose claim list holds a claim for `SUMMARY_MAX_CHARS`. +- **THEN** No problem names `SUMMARY_MAX_CHARS`. + +### Requirement: The stage job reads the value of each claimed name +The stage job SHALL read the staged value of each name in `constant_claims` and pass it to `check_proposal`. + +#### Scenario: A claim of a name no plan text cites +- **WHEN** A reply claims `SUMMARY_MAX_CHARS` and no plan text names the constant. +- **THEN** The job reads the staged value 60 for the claim. diff --git a/src/devops_cli/ai/tasks/roadmap_stage_change.md b/src/devops_cli/ai/tasks/roadmap_stage_change.md index 42b41ac870..e783e0fddc 100644 --- a/src/devops_cli/ai/tasks/roadmap_stage_change.md +++ b/src/devops_cli/ai/tasks/roadmap_stage_change.md @@ -61,5 +61,6 @@ The reply has these keys and no other, at the top level or inside any entry: - `criteria`: a list of objects with the keys `criterion`, `group` and `reason`. The body of the issue may hold a list under a heading `Acceptance criteria`, written by a person before the block `devops-roadmap-refine`. Give one entry for each top-level item of that list, and none for the list in the refine block. `criterion` is the text of the item, copied character for character, without the `[ ]` mark. `group` is the number of the group that delivers it, counted from 1 in the order of `groups`, or the string `pending-person` when only a person can deliver it. `reason` is a string, and it is never blank when `group` is `pending-person`. An issue with no such list gets an empty list. The check refuses a reply that leaves one item out. Map a global, performance, or hermeticity criterion to the task group that delivers or completes the suite. - `dependencies`: a list of strings, one for each `overlaps` entry, each `metric_senders` entry and each `issue_dependencies` entry that the context lists, the latter as `#: `. Name the pull request number and the shared path, or the metric name and the other files. Give an empty list only when the context lists no overlap and no sender. - `security`: a string that answers what crosses a trust boundary, what a person must confirm, and what test fails if the rule breaks when the plan names a security trigger, or an empty string. +- `constant_claims`: a list of objects with the keys `name` and `value`. A claim names a constant of the staged tree and that a constant the plan creates is no claim. - Texts: no text of the plan is a placeholder such as `x`, `todo` or `none`, and the `why`, `existing_tool`, each line of `feasibility`, each decision and each task has at least 10 characters. The check refuses a reply that breaks this rule. The `summary` never ends with `...`. - Texts: the `why`, `existing_tool`, `purpose` and the `text` of a requirement are on one line and start with a word, never with `-`, `#`, `>`, `1.`, `[ ]`, a rule, a fence or an HTML tag. The check refuses a reply that breaks this rule. Any other text is joined to one line. diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index cfe18bcc8e..5b8b5ebcac 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -5570,6 +5570,10 @@ class RoadmapMessages: stage_problem_constant_mismatch: str = ( "{constant} is {staged} in the staged tree, but the plan says {plan}." ) + stage_problem_constant_undefined: str = ( + "The plan claims the constant '{constant}' with the value {value}, but the staged " + "tree does not define that name as a module-level integer." + ) stage_problem_trace_tool: str = ( "The Feasibility section names the tool `{tool}`, but the run did not call it." ) diff --git a/src/devops_cli/roadmap/stage/stage.py b/src/devops_cli/roadmap/stage/stage.py index 5827eaa903..e62a5d2367 100644 --- a/src/devops_cli/roadmap/stage/stage.py +++ b/src/devops_cli/roadmap/stage/stage.py @@ -248,7 +248,10 @@ class leaves the count as it is. shared_texts, staging_title, ) -from devops_cli.roadmap.stage.stage_constants import candidate_names, staged_constants +from devops_cli.roadmap.stage.stage_constants import ( + claimed_names, + staged_constants, +) from devops_cli.roadmap.stage.stage_context_facts import collect_stage_facts_context from devops_cli.roadmap.stage.stage_filter import split_filter_entry from devops_cli.roadmap.stage.stage_findings import ( @@ -2706,7 +2709,11 @@ def _gate_problems( if self._grep is not None else None ) - constants = staged_constants(self._source, self._sha, candidate_names(plan_texts(proposal))) + constants = staged_constants( + self._source, + self._sha, + claimed_names(plan_texts(proposal), (claim.name for claim in proposal.constant_claims)), + ) references = self._probe_references(proposal.groups) found = check_gates( proposal, diff --git a/src/devops_cli/roadmap/stage/stage_change.py b/src/devops_cli/roadmap/stage/stage_change.py index 2d43f62bf1..0093d3faac 100644 --- a/src/devops_cli/roadmap/stage/stage_change.py +++ b/src/devops_cli/roadmap/stage/stage_change.py @@ -513,6 +513,20 @@ def _unchanged_has_reason(self) -> Self: return self +class StageConstantClaim(_Reply): + """A claim that an existing constant of the staged tree holds an integer value (#3388).""" + + name: str + value: int + + @field_validator("name") + @classmethod + def _is_identifier(cls, name: str) -> str: + if not name.isidentifier(): + raise ValueError(f"{name!r} is not a Python identifier") + return name + + class GroupKind(StrEnum): """What a task group does. `behavior` adds or changes what the code does: its work starts with a failing test. `manifest` creates or changes a rule file, a dashboard file or a case file: its @@ -732,6 +746,7 @@ class StageProposal(_Reply): dependencies: list[Line] = Field(default_factory=list) references: list[StageReference] = Field(default_factory=list) security: OptionalLine = "" + constant_claims: list[StageConstantClaim] = Field(default_factory=list) # The plan reader fills this list from `## Weakened checks` of `proposal.md` (#3490). The reply # schema does not show it: `render_change` writes no such section, so a key in a reply is lost. weakened_checks: SkipJsonSchema[list[WeakenedCheck]] = Field(default_factory=list) @@ -1723,6 +1738,36 @@ def _lists_path(listed: Collection[str], path: str) -> bool: ) +def claim_problems( + claims: Sequence[StageConstantClaim], + constants: Mapping[str, int] | None, +) -> list[str]: + """What is wrong with a structured constant claim (#3388). A claim whose name the staged + values do not hold is refused, and a claim whose value differs from the staged value is + refused. With no staged values it judges no claim.""" + if not constants: + return [] + texts_msg = MESSAGES.roadmap + problems: list[str] = [] + for claim in claims: + if claim.name not in constants: + problems.append( + texts_msg.stage_problem_constant_undefined.format( + constant=claim.name, + value=claim.value, + ) + ) + elif constants[claim.name] != claim.value: + problems.append( + texts_msg.stage_problem_constant_mismatch.format( + constant=claim.name, + staged=constants[claim.name], + plan=claim.value, + ) + ) + return list(dict.fromkeys(problems)) + + def _what_changes_problems(proposal: StageProposal, tree: StagedTree) -> list[str]: """One problem for each repository path in a code span of a What Changes item that no group lists in `changes` or `creates` (#3411). The check reads the tree to tell a path from a word, @@ -3076,7 +3121,11 @@ def check_gates( proposal, registry, ), - ProposalGate.CONSTANTS: constant_problems(plan_texts(proposal), constants or {}), + ProposalGate.CONSTANTS: ( + claim_problems(proposal.constant_claims, constants) + if proposal.constant_claims + else constant_problems(plan_texts(proposal), constants or {}) + ), ProposalGate.TRACE: _trace_problems(proposal, trace, probes, judged), ProposalGate.GROUP_FILES: group_files_problems(proposal.groups, tree), } diff --git a/src/devops_cli/roadmap/stage/stage_constants.py b/src/devops_cli/roadmap/stage/stage_constants.py index 97394af69c..fa1e1fb5cd 100644 --- a/src/devops_cli/roadmap/stage/stage_constants.py +++ b/src/devops_cli/roadmap/stage/stage_constants.py @@ -76,6 +76,11 @@ def candidate_names(texts: Iterable[str]) -> set[str]: return names +def claimed_names(texts: Iterable[str], claimed: Iterable[str]) -> set[str]: + """The candidate constant names of `texts`, unioned with `claimed` (#3388).""" + return candidate_names(texts) | set(claimed) + + def _sentences(text: str) -> list[str]: """The sentences of `text`.""" sentences: list[str] = [] @@ -286,6 +291,7 @@ def constant_problems(texts: Iterable[str], constants: Mapping[str, int]) -> lis __all__ = [ "candidate_names", + "claimed_names", "constant_problems", "parse_constants", "staged_constants", diff --git a/tests/roadmap/stage/test_roadmap_stage_constants.py b/tests/roadmap/stage/test_roadmap_stage_constants.py index 5dc9b7c688..2ca9cfe537 100644 --- a/tests/roadmap/stage/test_roadmap_stage_constants.py +++ b/tests/roadmap/stage/test_roadmap_stage_constants.py @@ -2,14 +2,23 @@ from __future__ import annotations +from typing import Any + import pytest +from pydantic import ValidationError +from devops_cli.roadmap.stage.stage_change import ( + StageProposal, + content_problems, +) from devops_cli.roadmap.stage.stage_constants import ( candidate_names, + claimed_names, constant_problems, parse_constants, staged_constants, ) +from tests.support.builders import make_stage_proposal from tests.support.paths import REPO_ROOT @@ -181,3 +190,196 @@ def test_staged_constants_reads_repository() -> None: # `src/devops_cli/roadmap/pull_form.py` defines `SUMMARY_MAX_CHARS: Final[int] = 60` constants = staged_constants(REPO_ROOT, "HEAD", ["SUMMARY_MAX_CHARS"]) assert constants.get("SUMMARY_MAX_CHARS") == 60 + + +def test_the_stage_reply_holds_constant_claims() -> None: + plan = make_stage_proposal(constant_claims=[{"name": "SUMMARY_MAX_CHARS", "value": 60}]) + assert len(plan.constant_claims) == 1 + assert plan.constant_claims[0].name == "SUMMARY_MAX_CHARS" + assert plan.constant_claims[0].value == 60 + + empty_plan = make_stage_proposal() + assert empty_plan.constant_claims == [] + + with pytest.raises(ValidationError, match="is not a Python identifier"): + StageProposal.model_validate( + {**PLAN_OF_THIS_CHANGE, "constant_claims": [{"name": "SUMMARY-MAX", "value": 60}]} + ) + + +PLAN_OF_THIS_CHANGE: dict[str, Any] = { + "summary": "The stage plan states constant claims", + "pull_request_body": ( + "The plan check reads constant claims from prose, so it skips a sentence with two " + "numbers and a new name for an existing bound, and a wrong bound passes (#3388)." + ), + "why": ( + "Issue #3388: the plan check reads constant claims from prose, so it skips a sentence " + "with two numbers and a new name for an existing bound, and a wrong bound passes." + ), + "what_changes": [ + "Add `StageConstantClaim` with `name` and `value`, and the `constant_claims` list with an empty default, to `StageProposal` in `src/devops_cli/roadmap/stage/stage_change.py`.", + "Refuse a claim whose value differs from the staged value, and a claim whose name the staged values do not hold, in `check_proposal`.", + "Run the prose scan of constant claims only when `constant_claims` is empty.", + "Add `stage_problem_constant_undefined` to `src/devops_cli/lang/en/messages.py` for a claim that names no module-level integer of the staged tree.", + "List `constant_claims` among the reply keys of `src/devops_cli/ai/tasks/roadmap_stage_change.md`.", + "Add `claimed_names` to `src/devops_cli/roadmap/stage/stage_constants.py` and call it in `src/devops_cli/roadmap/stage/stage.py`.", + "Describe the claim list in `docs/roadmap/stage.md`.", + ], + "skip_specs": False, + "feasibility": [ + "`src/devops_cli/roadmap/stage/stage_change.py:3094: ProposalGate.CONSTANTS: constant_problems(plan_texts(proposal), constants or {}),` is the prose scan that the plan keeps as the fallback.", + "`staged_constants` needs a checkout of the repository at the staged commit, because it runs `git grep` and `git show` (`src/devops_cli/roadmap/stage/stage_constants.py:229:def staged_constants(source: Path, sha: str, names: Iterable[str]) -> dict[str, int]:`).", + "`constant_problems` needs no checkout, no client and no network: the caller gives the staged values as a mapping (`src/devops_cli/roadmap/stage/stage_constants.py:257:def constant_problems(texts: Iterable[str], constants: Mapping[str, int]) -> list[str]:`).", + ], + "existing_tool": ( + "No open tool covers the check: about 12k tokens to build, 3k tokens a month to keep " + "and fix, and 1 to 2 days of elapsed time." + ), + "decisions": [ + { + "decision": "constant_claims is a field of StageProposal with an empty default", + "reason": "A reply with no structured claim has no value to compare, and the prose scan is the only reading of it.", + } + ], + "rejected": [ + { + "alternative": "Parse the claims from the prose with a second reader", + "evidence": "src/devops_cli/roadmap/stage/stage_constants.py:257: constant_problems skips a sentence with two numbers.", + } + ], + "specs": [ + { + "capability": "roadmap-stage/claims", + "purpose": None, + "added": [ + { + "name": "The stage reply holds structured constant claims", + "text": "The stage reply SHALL hold structured constant claims.", + "scenarios": [ + { + "name": "A reply with one claim", + "when": "A reply gives constant_claims with the name SUMMARY_MAX_CHARS and the value 60", + "then": "The validated proposal holds one entry", + } + ], + } + ], + "modified": [], + "renamed": [], + "removed": [], + } + ], + "groups": [ + { + "title": "Add the constant-claim field to the stage reply and the prompt", + "kind": "behavior", + "reads": [ + "src/devops_cli/roadmap/stage/stage_change.py", + "src/devops_cli/ai/tasks/roadmap_stage_change.md", + "tests/roadmap/stage/test_roadmap_stage_prompt_rules.py", + "tests/roadmap/stage/test_roadmap_stage_constants.py", + ], + "changes": [ + "src/devops_cli/roadmap/stage/stage_change.py", + "src/devops_cli/ai/tasks/roadmap_stage_change.md", + "tests/roadmap/stage/test_roadmap_stage_constants.py", + "tests/roadmap/stage/test_roadmap_stage_prompt_rules.py", + ], + "creates": [], + "creates_lines": {}, + "test": ( + "Write `test_the_stage_reply_holds_constant_claims` in " + "`tests/roadmap/stage/test_roadmap_stage_constants.py` and " + "`test_the_plan_check_accepts_the_plan_of_this_change`, which builds the plan's " + "own `StageProposal` and asserts that `content_problems` returns no problem for it, " + "and verify that `src/devops_cli/roadmap/stage/stage_change.py` fails on the base" + ), + "implementation": ( + "Add `StageConstantClaim` and `constant_claims` to `StageProposal` in `stage_change.py`" + ), + "documentation": None, + "verify": "uv run devops ci test tests/roadmap/stage/test_roadmap_stage_constants.py tests/roadmap/stage/test_roadmap_stage_prompt_rules.py", + }, + { + "title": "Judge each structured claim in the plan check", + "kind": "behavior", + "reads": [ + "src/devops_cli/roadmap/stage/stage_change.py", + "src/devops_cli/roadmap/stage/stage_constants.py", + "src/devops_cli/lang/en/messages.py", + "tests/roadmap/stage/test_roadmap_stage_plan.py", + ], + "changes": [ + "src/devops_cli/roadmap/stage/stage_change.py", + "src/devops_cli/lang/en/messages.py", + "tests/roadmap/stage/test_roadmap_stage_plan.py", + ], + "creates": [], + "creates_lines": {}, + "test": ( + "Write `test_check_proposal_refuses_a_wrong_constant_claim` and " + "`test_check_proposal_refuses_a_claim_the_tree_does_not_define` in " + "`tests/roadmap/stage/test_roadmap_stage_plan.py`; it fails on the base, where " + "`src/devops_cli/roadmap/stage/stage_change.py:3094: ProposalGate.CONSTANTS: constant_problems(plan_texts(proposal), constants or {}),` " + "judges only the prose" + ), + "implementation": "Add `claim_problems` to `stage_change.py`", + "documentation": None, + "verify": "uv run devops ci test tests/roadmap/stage/test_roadmap_stage_plan.py tests/roadmap/stage/test_roadmap_stage_constants.py", + }, + { + "title": "Read the staged value of each claimed name", + "kind": "behavior", + "reads": [ + "src/devops_cli/roadmap/stage/stage_constants.py", + "src/devops_cli/roadmap/stage/stage.py", + "tests/roadmap/stage/test_roadmap_stage_apply.py", + ], + "changes": [ + "src/devops_cli/roadmap/stage/stage_constants.py", + "src/devops_cli/roadmap/stage/stage.py", + "tests/roadmap/stage/test_roadmap_stage_constants.py", + ], + "creates": [], + "creates_lines": {}, + "test": ( + "Write `test_claimed_names_adds_the_names_of_the_claims` in " + "`tests/roadmap/stage/test_roadmap_stage_constants.py`" + ), + "implementation": "Add `claimed_names` to `stage_constants.py`", + "documentation": None, + "verify": "uv run devops ci test tests/roadmap/stage/test_roadmap_stage_constants.py tests/roadmap/stage/test_roadmap_stage_apply.py", + }, + { + "title": "Describe the claim list in the stage guide", + "kind": "other", + "reads": [ + "docs/roadmap/stage.md", + "src/devops_cli/ai/tasks/roadmap_stage_change.md", + ], + "changes": ["docs/roadmap/stage.md"], + "creates": [], + "creates_lines": {}, + "test": None, + "implementation": "Describe the constant_claims key in `docs/roadmap/stage.md`", + "documentation": "Edit `docs/roadmap/stage.md`", + "verify": "uv run devops ci docs", + }, + ], + "constant_claims": [{"name": "SUMMARY_MAX_CHARS", "value": 60}], +} + + +def test_the_plan_check_accepts_the_plan_of_this_change() -> None: + assert content_problems(StageProposal.model_validate(PLAN_OF_THIS_CHANGE)) == [] + + +def test_claimed_names_adds_the_names_of_the_claims() -> None: + texts = ["A plan mentions SUMMARY_MAX_CHARS."] + claimed = ["BODY_MAX_CHARS", "OTHER_BOUND"] + assert claimed_names(texts, claimed) == { + "SUMMARY_MAX_CHARS", + "BODY_MAX_CHARS", + "OTHER_BOUND", + } diff --git a/tests/roadmap/stage/test_roadmap_stage_plan.py b/tests/roadmap/stage/test_roadmap_stage_plan.py index d1f91e7678..b5af6bd48f 100644 --- a/tests/roadmap/stage/test_roadmap_stage_plan.py +++ b/tests/roadmap/stage/test_roadmap_stage_plan.py @@ -49,6 +49,7 @@ ) from devops_cli.roadmap.stage.stage_change import ( CREATED_LINE_TOKENS, + StageConstantClaim, StageDecision, StageGroup, StageProposal, @@ -3007,6 +3008,75 @@ def test_check_proposal_refuses_a_plan_number_differing_from_a_constant() -> Non ) +def test_check_proposal_refuses_a_wrong_constant_claim() -> None: + constants = {"SUMMARY_MAX_CHARS": 60} + claim = StageConstantClaim(name="SUMMARY_MAX_CHARS", value=40) + proposal = make_stage_proposal(constant_claims=[claim]) + problems = check_proposal( + proposal, ["comment-thread"], SAMPLE_TREE, constants=constants, registry=() + ) + assert problems == ["SUMMARY_MAX_CHARS is 60 in the staged tree, but the plan says 40."] + + claim_match = StageConstantClaim(name="SUMMARY_MAX_CHARS", value=60) + proposal_match = make_stage_proposal(constant_claims=[claim_match]) + assert ( + check_proposal( + proposal_match, ["comment-thread"], SAMPLE_TREE, constants=constants, registry=() + ) + == [] + ) + + +def test_check_proposal_refuses_a_claim_the_tree_does_not_define() -> None: + constants = {"SUMMARY_MAX_CHARS": 60} + claim = StageConstantClaim(name="PLAN_SUMMARY_MAX_CHARS", value=47) + proposal = make_stage_proposal(constant_claims=[claim]) + problems = check_proposal( + proposal, ["comment-thread"], SAMPLE_TREE, constants=constants, registry=() + ) + assert problems == [ + "The plan claims the constant 'PLAN_SUMMARY_MAX_CHARS' with the value 47, but the staged tree does not define that name as a module-level integer." + ] + + +def test_check_proposal_runs_the_prose_scan_only_with_no_claim_list() -> None: + constants = {"SUMMARY_MAX_CHARS": 60} + spec = make_stage_proposal().specs[0] + req = spec.added[0] + scenario_40 = req.scenarios[0].model_copy( + update={"when": "A spec scenario says `SUMMARY_MAX_CHARS` is 40."} + ) + spec_40 = spec.model_copy( + update={"added": [req.model_copy(update={"scenarios": [scenario_40]})]} + ) + proposal_prose = make_stage_proposal(specs=[spec_40], constant_claims=[]) + problems = check_proposal( + proposal_prose, ["comment-thread"], SAMPLE_TREE, constants=constants, registry=() + ) + assert problems == ["SUMMARY_MAX_CHARS is 60 in the staged tree, but the plan says 40."] + + claim_60 = StageConstantClaim(name="SUMMARY_MAX_CHARS", value=60) + proposal_with_claim = make_stage_proposal(specs=[spec_40], constant_claims=[claim_60]) + assert ( + check_proposal( + proposal_with_claim, ["comment-thread"], SAMPLE_TREE, constants=constants, registry=() + ) + == [] + ) + + +def test_check_proposal_judges_no_claim_without_staged_values() -> None: + claim = StageConstantClaim(name="SUMMARY_MAX_CHARS", value=40) + proposal = make_stage_proposal(constant_claims=[claim]) + assert ( + check_proposal(proposal, ["comment-thread"], SAMPLE_TREE, constants={}, registry=()) == [] + ) + assert ( + check_proposal(proposal, ["comment-thread"], SAMPLE_TREE, constants=None, registry=()) == [] + ) + assert check_proposal(proposal, ["comment-thread"], SAMPLE_TREE, registry=()) == [] + + # ── Reference probe and move derivation (#3373) ────────────────────────────── diff --git a/tests/roadmap/stage/test_roadmap_stage_prompt_rules.py b/tests/roadmap/stage/test_roadmap_stage_prompt_rules.py index 62d43bd759..881bdf0a9f 100644 --- a/tests/roadmap/stage/test_roadmap_stage_prompt_rules.py +++ b/tests/roadmap/stage/test_roadmap_stage_prompt_rules.py @@ -23,6 +23,7 @@ PURPOSE_MIN_CHARS, SUMMARY_MAX_CHARS, GroupKind, + StageConstantClaim, StageDecision, StageGroup, StageProposal, @@ -111,6 +112,7 @@ def test_the_top_level_keys_of_the_reply_are_the_fields_of_the_proposal() -> Non StageReference, StageRename, StageRemoval, + StageConstantClaim, ], ) def test_each_list_of_keys_of_the_reply_is_the_fields_of_a_model(