Skip to content

ci(doc): report a file.rs:NNN citation whose line moved, not just a blank one - #1391

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
ci/citation-drift-guard
Sep 21, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
ci/citation-drift-guard

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

The guard added in #1371 fails a file.rs:NNN citation only when the cited line is blank.
A citation that drifts onto a different non-blank line passes silently. On one changeset in
this batch, 24 citations moved and the guard reported 2.

--base <revision> now resolves the merge base of <revision> and HEAD, reads the cited line
at both revisions, and reports any citation whose line text changed — blank or not. It is a
strict superset of the existing rule, which is untouched.

Verified against the real tree, independently of the authoring run. Clean:

OK: all 229 `file.rs:NNN` citations ... resolve to a non-blank line.
OK: none of the 340 cited lines compared against ba69fd28 changed their text.
CLEAN_EXIT=0

Then two lines inserted at the top of lib/src/protocol/kawa_h1/editor.rs:

OK: all 229 `file.rs:NNN` citations ... resolve to a non-blank line.     <- old rule STILL GREEN
::error::4 of 340 compared citations drifted since ba69fd28:
  kawa_h1/LIFECYCLE.md:164: `editor.rs:638-658` — :638 moved:
      was `let (te_count, te_all_suffix_chunked) = {`, now `// not through this predicate…`
  kawa_h1/LIFECYCLE.md:167: `editor.rs:659-662` — :659 moved:
      was `if te_count > 1`, now `})`
DRIFTED_EXIT=1

That is the gap, in one frame: the blank-line rule reports everything fine while four citations
point at the wrong code.

Re-anchoring is not flagged. A citation is compared only when the same path and the same
line numbers appear in the base revision of its own document, so repointing 1131 → 1152 is
accepted while leaving 1131 as the code moves is reported. Identity is the citation, not its
position.

Fail-closed, not skip. An unreachable base is an error, proved on a real --depth 1 clone.
The job checks out with fetch-depth: 0 — PRs stack here, so the base is often not main — and
passes github.event.pull_request.base.sha through env:, never interpolated into the shell.
A push to main or a tag has no changeset and says so on its own line rather than passing silently.

Self-test totals stay exact, none a floor: FIXTURE_TOTAL 14 → 19, plus FIXTURE_DRIFT_COMPARED
and two exact expected strings. The clean-fixture assertion now excludes doc/bad.md instead of
naming doc/good.md, so a fixture added later is covered the day it lands.

Follow-on (1) from the issue — measured and deliberately left. Aligning the line-citation
surface with the test-name rule's *.rs + CHANGELOG.md adds 190 files, 195 citations, 50
failures
, 27 of them in CHANGELOG.md — which is an append-only record of the tree at each
release and must not be renumbered to satisfy a guard. That is its own changeset. It also would
still not reach e2e/COVERAGE.md, which no rule reads. Numbers recorded in doc/README.md.

What this does not close, stated in the script header, doc/README.md and the commit: a
citation already wrong before the PR opened is carried forward unreported. That is Measurement 2
of the issue — editor.rs:1131, non-blank and wrong across three trees — and it needs the
surface widening above.

SELFTEST=0, real tree --base ba69fd28 → 0, broken-fixture step → 1, TEST=0 (917 passed).

Closes #1389

…lank one

check_doc_citations.py failed a citation only when the cited line was blank.
A citation that slid onto a different NON-BLANK line resolved, hit code, and
passed. #1389 measured the gap: on #1379's changeset, which
added +21 lines to lib/src/protocol/kawa_h1/editor.rs and +14 to
lib/src/protocol/mux/router.rs, 24 citations moved and the guard reported 2.
The other 22 all landed on code, and lib/src/protocol/kawa_h1/LIFECYCLE.md
alone cites editor.rs 21 times. The guard's presence was itself the hazard: a
green Doc citations job read as "the citations are right" when it only ever
meant "no citation landed on a blank line".

--base <revision> closes that with the base revision and no new data. Every
citation is resolved by the checker's own resolve_path/CITATION -- a naive
basename match reports false positives, because a bare mod.rs in
mux/LIFECYCLE.md binds to its sibling -- and the text of the cited line is read
at the merge base and at HEAD. Different text is reported whether or not the
new line is blank, at both ends of a range, which makes the rule a strict
superset of the blank-line rule for every line the changeset touched.
Comparison is on the stripped line, so a re-indent is not drift.

Re-anchoring is not drift. A citation is compared only when the same path and
the same line numbers are also present in the base revision of its own
document, so repointing editor.rs:1131 at editor.rs:1152 is accepted silently
and only a citation left pointing at text that changed underneath it is
reported. Identity is the citation and not its position, so moving a paragraph
does not excuse a stale number.

It fails closed. The base commit has to be in the object store and the default
actions/checkout is shallow, so the Doc citations job now checks out with
fetch-depth: 0 -- pull requests here stack on one another, so the base is often
not main and no narrower fetch covers every case -- and passes the pull
request's base sha through the environment rather than interpolating it into
the shell. An unreachable --base is an error and exit 1, never a skip: a guard
that answered a missing base with a clean run would be green forever while
comparing nothing. A main or tag push carries no changeset, and the run then
states on its own line that the rule did not run.

The self-test asserts the drift half in BOTH directions. testdata/citations/
gains a document whose five citations all resolve to a non-blank line at both
revisions -- so the older rules are green on it either way -- plus a drift.rs,
and a <name>.base second revision of each that no walk in the script can see.
The self-test commits those base revisions into a throwaway repository,
restores the head ones, and requires the SAME tree to exit 0 without --base and
1 with it, the two drifts to be the exact two expected, 17 cited line ends to
have been compared, and an unreachable base to be refused rather than skipped.
FIXTURE_TOTAL moves 14 -> 19 for the new document's five citations, and the
clean-fixture assertion is now stated by excluding doc/bad.md, so a fixture
added later is covered the day it lands.

On this tree the rule compares 340 cited line ends and reports none. Inserting
two lines at the top of editor.rs reddens it with two citations from
kawa_h1/LIFECYCLE.md while the blank-line rule stays green on all 229.

The scanned surface is unchanged and that is deliberate. #1389's follow-on
asked for the line-citation surface to be aligned with the test-name rule's
*.rs + CHANGELOG.md. Measured on 265d895 that adds 195 citations across 190
files and 50 pre-existing failures, 27 of them in CHANGELOG.md -- an
append-only record of the tree as it stood at each release, which must not be
renumbered to satisfy a guard. It is its own changeset, and it would still not
reach e2e/COVERAGE.md, which no rule reads.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 6da4e6c into main Sep 21, 2026
24 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the ci/citation-drift-guard branch September 21, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci(doc): the citation guard only fails a BLANK landing — 24 citations moved and it reported 2

1 participant