Repository navigation
Refuse a --previous-report stamped under a foreign repo identity (#342) - #531
Merged
Merged
Conversation
Mechanism (verified before designing the fix): finding identity is `(family, repo, path)` (`Finding.match_key`), and for `--single-repo <path>` the `repo` component is the directory BASENAME (`runner.build_context`). Nothing tied a written report to the identity its run covered, and nothing checked one on the way back in. Point `--previous-report` at a baseline built under a different basename and every finding key misses: `regressions()` reads every current critical/error finding as new, and `uncited_resolutions()` reads every baseline contested finding as vanished without citation — 36 phantom regressions and 23 phantom `uncited-resolution` errors in the issue's own PR #333 reproduction, exit code 0 throughout. A benign operator path/scope slip reported in the vocabulary of the family's most serious findings. Fix, write side: every report is now stamped with the repo(s) its run covered — a `Repo-Identity: <slug>[, <slug>...]` header line beside `Status:`/`Kind:` (sorted, comma-separated; `(none)` for an explicit empty set), emitted by `report.render`'s new `repo_slugs` keyword and read back by the new `report.parse_repo_identity`. Neither the `doc-health` spec's "Health report contract" requirement nor `specs/022-modified-block-currency-reporting/contracts/report-section.md` (the one byte-level report contract in this repo) enumerates the top header line-for-line, so adding one line is not a contract violation; both were read before this was written. Fix, read side, the identity rule (`runner.main`): every repo THIS run covers must already be a member of the baseline's stamped identity — `current_repo_slugs <= previous_repo_slugs`. This is the single-repo case ("the slug must be IN the baseline's set") generalized to an aggregation run ("equality or subset"), reasoned from how the two comparison rules key: a repo the current run has that the baseline never scanned makes every one of that repo's critical/error findings miss `previous_keys` by construction (`regressions()`), which is the exact phantom-regression mechanism the issue reports — a foreign-basename baseline is the disjoint-sets instance of this same rule. A violation REFUSES: `runner.main` exits nonzero with a message naming both stamped identities and the uncovered repo(s) (`REFUSE previous-report-identity-mismatch: ...`), styled after `verify-openxwallet-pin.py`'s fail-closed refusals. The mirror direction — the baseline knows a repo THIS run does not (a proper superset, which the subset rule accepts) — is closed separately: `uncited_resolutions` gained an `unavailable_repos` parameter so a contested finding for a repo outside this run's scope is never read as resolved just because this run never looked at it (fix-shape item 3 of the issue). Backward compatibility: a `--previous-report` carrying no `Repo-Identity:` stamp (every report in `health/reports/*.md` as of 2026-08-31, and every report this change's own tests build without passing `repo_slugs`) is accepted exactly as today, with one `[repo-identity] WARNING` line on stderr naming the gap — so the nightly does not break the night this lands, and phases in as reports become stamped. Tests (tests/doc-health/test_suite.py, +8): stamp round-trips through render -> parse (sorted, positioned before "## Headline"); the stamp is omitted (byte-identical output) when `repo_slugs` is not passed, and reads back as `None` (never confused with an empty set, which round-trips as `frozenset()` via the explicit `(none)` spelling); a foreign-identity baseline reproduced in the issue's own shape — a repo built under directory basename `base-wt`, diffed by a run over a checkout named `openxFactory` — REFUSES with both identities named and writes no report; matching identity compares normally; an unstamped legacy baseline is accepted with a warning and reproduces the exact outcome of the pre-existing `test_full_run_still_fires_uncited_resolution_when_genuinely_resolved` (behaviour unchanged); a superset baseline is accepted but does not manufacture a resolution for the repo outside the run's scope, while a repo inside scope still owes its citation. `python3 -m pytest tests/doc-health -q`: 1339 passed on the unmodified worktree (baseline), 1347 passed after (1339 + 8 new, zero regressions). Real-corpus sanity: ran `scripts/doc-health.py --single-repo . --family location-conformance --previous-report <xFactory root's committed health/reports/2026-08-26.md, origin/main>` from a detached worktree of this branch named `openxFactory` (basename matters — the issue is about exactly that). That baseline predates this change and carries no stamp, so the legacy path fires: one `[repo-identity] WARNING` line on stderr, exit code and finding counts unchanged from the pre-fix behaviour. docs/doc-health.md: added a sentence on the identity stamp and the refusal under "Finding Severities" (beside the existing regression rule) and in the "Report Contract" section describing report contents. Closes #342 Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
Hi @brettheap! 👋
Your private repo does not have access to Sourcery.
Please upgrade to continue using Sourcery ✨
There was a problem hiding this comment.
Pull request overview
This PR hardens doc-health.py --previous-report comparisons by stamping each report with the repo identity (repo slug set) it was generated under and refusing comparisons when a stamped baseline does not cover the current run’s scope, preventing phantom regressions and uncited-resolution errors caused by identity mismatches.
Changes:
- Add
Repo-Identity:header stamping inreport.render()plus parsing viareport.parse_repo_identity(). - Enforce baseline identity compatibility in
runner.main(current_repo_slugs <= previous_repo_slugs), with backward-compatible warnings for unstamped legacy baselines. - Prevent
uncited_resolutions()from manufacturing resolutions for repos outside the current run’s scope (unavailable_repos), plus add tests and docs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/doc-health/test_suite.py | Adds regression tests covering repo-identity stamping, backward compatibility, refusal behavior, and unavailable-repo suppression. |
| scripts/doc_health/runner.py | Computes current repo identity, parses baseline identity, refuses mismatches, warns on legacy baselines, and threads unavailable_repos + repo_slugs. |
| scripts/doc_health/report.py | Introduces identity stamp constants + parsing, adds unavailable_repos exclusion to uncited_resolutions, and stamps reports during render. |
| docs/doc-health.md | Documents the new identity stamp and refusal behavior in the doc-health report contract/behavior overview. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+343
to
+345
| m = REPO_IDENTITY_RE.search(text) | ||
| if not m: | ||
| return None |
| assert report.parse_repo_identity(text) is None | ||
|
|
||
|
|
||
| def test_render_stamps_an_explicit_empty_repo_set_as_none_not_absent(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mechanism (verified before designing the fix)
Finding identity is
(family, repo, path)(Finding.match_key), and for--single-repo <path>therepocomponent is the directory basename(
runner.build_context). Nothing tied a written report to the identity itsrun covered, and nothing checked one on the way back in. Point
--previous-reportat a baseline built under a different basename and everyfinding key misses:
regressions()reads every current critical/errorfinding as new, and
uncited_resolutions()reads every baseline contestedfinding as vanished without citation — 36 phantom regressions and 23
phantom
uncited-resolutionerrors in the issue's own PR #333reproduction, exit code 0 throughout.
Fix
Write side — every report is stamped with the repo(s) its run covered: a
Repo-Identity: <slug>[, <slug>...]header line besideStatus:/Kind:(sorted, comma-separated;
(none)for an explicit empty set), emitted byreport.render's newrepo_slugskeyword and read back by the newreport.parse_repo_identity. Neither thedoc-healthspec's "Health reportcontract" requirement nor
specs/022-modified-block-currency-reporting/contracts/report-section.md(the one byte-level report contract in this repo) enumerates the top header
line-for-line, so this is not a contract violation — both were read before
writing this.
Read side, the identity rule (
runner.main) — every repo the currentrun covers must already be a member of the baseline's stamped identity:
current_repo_slugs <= previous_repo_slugs. This generalizes thesingle-repo case ("the slug must be IN the baseline's set") to an
aggregation run ("equality or subset"), reasoned from how the two
comparison rules key: a repo the current run has that the baseline never
scanned makes every one of that repo's critical/error findings miss
previous_keysby construction (regressions()) — the exactphantom-regression mechanism the issue reports, with a foreign-basename
baseline as the disjoint-sets instance of the same rule. A violation
REFUSES:
runner.mainexits nonzero withREFUSE previous-report-identity-mismatch: ...naming both stamped identities andthe uncovered repo(s), styled after
verify-openxwallet-pin.py'sfail-closed refusals.
The mirror direction — the baseline knows a repo the current run does
not (a proper superset, which the subset rule accepts) — is closed
separately:
uncited_resolutionsgained anunavailable_reposparameter soa contested finding for a repo outside the run's scope is never read as
resolved just because this run never looked at it (fix-shape item 3 of the
issue).
Backward compatibility
A
--previous-reportcarrying noRepo-Identity:stamp (every report inhealth/reports/*.mdas of 2026-08-31) is accepted exactly as today, withone
[repo-identity] WARNINGline on stderr naming the gap — the nightlydoes not break the night this lands, and phases in as reports become
stamped.
Tests
tests/doc-health/test_suite.py, +8 tests:## Headline)repo_slugsis notpassed, and reads back as
None— never confused with an explicitlyempty, stamped set (
frozenset()via(none))built under directory basename
base-wt, diffed by a run over a checkoutnamed
openxFactory— REFUSES, names both identities, writes no reportexact outcome of the pre-existing
test_full_run_still_fires_uncited_resolution_when_genuinely_resolved(behaviour unchanged)
the repo outside the run's scope, while a repo inside scope still owes its
citation
python3 -m pytest tests/doc-health -q: 1339 passed on the unmodifiedworktree (baseline), 1347 passed after (1339 + 8 new, zero
regressions).
Real-corpus sanity
Ran
scripts/doc-health.py --single-repo . --family location-conformance --previous-report <xFactory root's committedhealth/reports/2026-08-26.md, origin/main>from a detached worktree of this branch namedopenxFactory(basename matters — the issue is about exactly that). That baseline
predates this change and carries no stamp, so the legacy path fires: one
[repo-identity] WARNINGline on stderr, exit code 0, and theFindings By Family/Ranked Plansections byte-identical to a parallel run ofunmodified
origin/maincode against the same corpus and baseline (0critical, 12 error, 0 warning, 0 info; 12 regressions — pre-existing corpus
drift since 2026-08-26, unrelated to and unaffected by this change).
Docs / spec
docs/doc-health.md: added a sentence on the identity stamp and therefusal under "Finding Severities" (beside the existing regression rule)
and in "Report Contract" describing report contents.
openspec/specs/doc-health/spec.md's "Health report contract" and"Finding severity and regression handling" requirements were read and do
not enumerate the header byte-level or otherwise constrain this — no
ratified scenario conflicts, so no OpenSpec change was needed for this
fix.
Closes #342
🤖 Generated with Claude Code