Repository navigation
feat(scripts): add a requirement ID ledger and CI check - #415
brendanjryan wants to merge 3 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eab9b4eea0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| text = collapse("".join(el.itertext())) | ||
| following = children[index + 1] if index + 1 < len(children) else None | ||
| if text.endswith(":") and following is not None and is_list(following): | ||
| text += " " + collapse("".join(following.itertext())) |
There was a problem hiding this comment.
Preserve reference targets in statement hashes
When a tagged statement changes only a cross-reference, itertext() drops the change because RFC XML stores the destination in the target attribute of an empty <xref> element. For example, changing {{credential-header}} in req-core-001 to another section leaves the hash unchanged. The blocking check therefore accepts a changed requirement without a ledger update or reviewer note. Include reference targets in the statement representation before hashing, including references within an introduced list.
AGENTS.md reference: AGENTS.md:L40-L40
Useful? React with 👍 / 👎.
| if args.update: | ||
| ledger, errors = update(ledger, drafts) | ||
| args.ledger.write_text(format_ledger(ledger), encoding="utf-8") |
There was a problem hiding this comment.
Limit partial updates to the drafts being processed
When the supported positional paths select one draft, running --update passes only that draft's IDs to update() but still rewrites the entire shared ledger. Every active ID belonging to an unselected draft becomes retired, and the command exits successfully because its subsequent check uses the same incomplete draft set. A later full update refuses to reactivate those IDs, so the ledger must be manually restored. Either reject partial updates to the shared ledger, always read all drafts when updating it, or preserve entries outside the selected scope.
AGENTS.md reference: AGENTS.md:L40-L40
Useful? React with 👍 / 👎.
| for other in sorted(base, key=sort_key): | ||
| if other != req_id and base[other].digest == value and drafts.get(other) != value: |
There was a problem hiding this comment.
Scope renumbering comparisons to the same draft
When a rule is retired in one draft and identical wording is added to another, this global hash comparison rejects the new draft's correctly namespaced ID as renumbering. Using the committed ledger, retiring req-tempo-charge-038 and adding req-new-charge-001 with its text reproduces the failure, even though req-stripe-charge-012 already independently uses that same text. The suggested remedy, retaining the Tempo ID in the new draft, is itself rejected by read_drafts() as belonging to another draft. Restrict renumbering comparisons to the same draft namespace so independent methods can adopt shared requirement wording without blocking CI.
AGENTS.md reference: AGENTS.md:L40-L40
Useful? React with 👍 / 👎.
Spec Preview
|
There was a problem hiding this comment.
I re-reviewed after the latest push and found no new bugs. A human look is still worthwhile because this adds a blocking CI gate, and specs/requirements.lock falls under a CODEOWNERS entry.
What was reviewed:
- My three earlier inline points look fixed in the code. The renumbering loop now skips retired base IDs. The new-ID check reads
issued.get(draft, 0)once, so an ID numbered 000 gets an error message, not a traceback. Onpull_requestthe workflow reads the base ledger fromHEAD^1. - I also re-read the deletion, reactivation, retired-reuse, active-but-unused and new-ID-ordering checks in
check(), plus the empty-ledger fallback inpr-check.yml. - The tests and the ledger check were not run as part of this review.
Extended reasoning...
The change adds a new 337-line ledger checker with tests, a 202-line specs/requirements.lock, a blocking step in pr-check.yml, and doc updates in STYLE.md and AGENTS.md. It touches no auth, crypto or data-exposure code. The CI step only reads the base ledger with git show and mounts it read-only into the container. I deferred instead of approving because /specs/ is covered by a CODEOWNERS entry and the change sets a new blocking repository policy that a person should sign off on. Whether the three Codex inline comments were addressed can't be confirmed from the metadata.
Adds
specs/requirements.lock, a ledger of every requirement ID ever issued, and a blocking CI check that makes IDs work like protobuf field numbers: once issued, an ID is never renumbered, reused or deleted. Stacked on #414, and its ledger already holds the IDs tagged through #414.The ledger has one line per ID:
req-core-012 active 3f2a9c1b7e4d0a51, giving its status (activeorretired) and a hash of the rendered statement.scripts/check_requirement_ledger.pyrenders the drafts the waylint_requirements.pydoes, then compares them with the ledger, and the ledger with the base branch's ledger. It fails when:reservedrule);--update.--updaterewrites the ledger: new IDs are added, removed ones becomeretired, and edited statements get their new hash. A changed hash therefore shows up in the ledger's diff, and CI prints a note for each one, so reviewers see every rule whose text changed. Per STYLE.md, a wording change keeps its ID, and a change of meaning retires the ID and takes the next free number. The hash includes cross-reference targets, so pointing a rule at another section changes it; whitespace and line wrapping don't. Renumbering is detected within a draft only, so another draft may state the same rule under its own ID. Naming drafts (check_requirement_ledger.py <draft>) checks and updates only their IDs. A statement ending in a colon includes the list after it ("Clients MUST verify before authorizing payment:" and its items).Ledger contents: 199 active IDs (core 001–100, intent-charge 001–016, stripe-charge 001–022, tempo-charge 001–061 from #407), none retired.
CI: a new
Check requirement ID ledgerstep inpr-check.ymlreads the base branch's ledger withgit show(when there isn't one yet, it compares against an empty ledger). Unlike the requirement lint, it blocks the PR. Drafts with no IDs yet don't affect it. Also added tomake lint, STYLE.md and AGENTS.md.Checks:
pytest test_check_requirement_ledger.py test_lint_requirements.py(150 passed),check_requirement_ledger.py --base <its own ledger>passes, ruff and zizmor clean. Run locally with kramdown-rfc 1.7.39 from Gemfile.lock rather than the Docker image, which couldn't build offline here.Written with AI assistance (Pyramid).