Skip to content

fix(ci): clip a drift report's quoted pair around its first difference - #1467

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/citation-drift-quote-window
Sep 23, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/citation-drift-quote-window

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Closes #1448.

check_doc_citations.py's drift report clipped quoted lines at QUOTE_WIDTH = 72
from column 0. When the difference between the two lines falls past that clip,
was: and now: print identically — the rule fires correctly and the operator
learns nothing:

doc/configure_admin_ops.md:158: `doc/configure.md:1219` moved
  was: | `h2_stream_shrink_ratio`                | 2                       | S…
  now: | `h2_stream_shrink_ratio`                | 2                       | S…

That is a markdown table row — wide by construction, with its meaningful content
well right of column 72. The class became reachable when #1458 taught the resolver
to read .md targets, because markdown citations disproportionately point at table
rows: configuration catalogues, metrics tables, threshold listings.

The fix: move the window, don't widen it

quote(line) becomes quote_pair(was, now). It finds the first differing offset
d; if d < QUOTE_WIDTH - 1 the window starts at 0, otherwise at
d - QUOTE_WIDTH // 2. Both lines are clipped from that same start, with …
on each truncated side.

QUOTE_WIDTH stays 72 and stays a hard ceiling, ellipses included. The issue
was explicit that removing or raising the clip is a different failure, and the
constant exists for a reason — an unbounded quote in a CI log.

The left anchor turned out not to be load-bearing. For any pair diverging
inside the first window, the new code returns start 0 and renders byte-identically
to the old line[:71] + "…". That is why FIXTURE_DRIFT_EXPECTED,
FIXTURE_PINNED_EXPECTED and all 16 real pinned blocks needed no change.

The same defect had a second call site

Rule 4's stale-pinned-block report also passed a pair through quote()
(check_doc_citations.py:1058-1059), so it carried the identical bug. Both call
sites now use quote_pair, and quote() is removed with no callers left.

The issue named only the drift report. Fixing one of the helper's two users would
have left the same defect live in the other, so this treats the helper as the root
cause — which is also this repository's usual remedy: remove the second copy rather
than patch one of them.

Verification

Red then green, with the production change reverted in a scratch copy while the
fixture and assertion were kept:

########## RED — production fix reverted, fixture + assertion kept ##########
FAIL self-test: the drift on a line whose difference falls past QUOTE_WIDTH (72)
reported the SAME text twice, so the report names nothing that moved:
    was: | `knob`    | 20      | Shrink threshold for recycled slots. The pool i…
    now: | `knob`    | 20      | Shrink threshold for recycled slots. The pool i…
EXIT=1

########## GREEN — fix restored ##########
OK self-test: 30 fixture line citations, 31 compared against a base revision, …
EXIT=0

Acceptance on the real tree — scratch clone, doc/configure.md:1219 (the
h2_stream_shrink_ratio row, 610 chars, description column starting at char 70)
edited in place Minimum: 2. → Minimum: 4.:

BEFORE  was `| `h2_stream_shrink_ratio`     | 2      | S…`, now `| `h2_stream_shrink_ratio`     | 2      | S…`
AFTER   was `…> active_streams * ratio`. Minimum: 2.        …`, now `…> active_streams * ratio`. Minimum: 4.        …`

Both halves measured at exactly 72 characters.

gate exit
--self-test 0
--root . 0
--base 3e9c271c 0
--root .github/scripts/testdata/citations (CI's broken-fixture step) 1, as required
python3 -m py_compile 0

Self-test constants

constant old → new why
FIXTURE_TOTAL 29 → 30 doc/drift.md gains one citation group (wide.md:11); doc/wide.md is a target and cites nothing
FIXTURE_DRIFT_COMPARED 30 → 31 that citation is one single-line span, so one compared line end

Unchanged and asserted green: FIXTURE_EXPECTED (9), FIXTURE_DRIFT_EXPECTED
(still 2 — the wide drift is asserted separately), FIXTURE_TEST_EXAMINED/CHECKED
(6/4; the new document carries no backticked identifier ≥13 chars, so rule 3 does
not leak into it), FIXTURE_PINNED/UNPINNED (3/1).

The new assertion is deliberately a property, per the issue: the two reported
halves must differ from each other, and neither may exceed QUOTE_WIDTH. It pins
no formatting, so it survives someone later changing the window strategy — and its
second half makes "do not remove the clip" mechanical rather than a comment.

Checked not test-shaped: tokens shared between the production hunk and the four
fixture files are English prose only (clip, line, report); no knob,
Minimum, Shrink, wide, 147 or 151.

doc/README.md is unaffected — it describes the rule and its command line, never
the quote width or anchoring (grepped for clip|72|width|truncat|ellips|…: empty).

`check_doc_citations.py` rendered every quoted line through one left-anchored
window — `line[:71]` plus an ellipsis, always from column 0 — and both halves of
a before/after pair went through it independently. A markdown table row is wide
by construction and carries its meaning in the last column, so a row whose text
changed past character 71 was reported with the same 72 characters printed
twice: the rule fired correctly and the report named nothing that had moved.
`doc/configure_admin_ops.md:158` cites exactly such a row,
`doc/configure.md:1219` — 610 characters wide, its description column beginning
at character 70. Pre-existing, and low-impact while the guarded surface was
source files only; #1458 made the class reachable by teaching the resolver to
read `.md` targets, because the citations that point at prose
disproportionately point at table rows.

Move the window instead of widening it. `quote_pair` finds the first offset at
which the two stripped lines diverge and, when that offset falls outside the
anchored window, clips BOTH from `offset - QUOTE_WIDTH // 2` with an ellipsis on
whichever side is truncated. `QUOTE_WIDTH` stays 72 and stays a hard ceiling on
every rendered quote, ellipses included: raising it would fix the table row by
making every long Rust line wrap a CI log, which is what the constant was chosen
against. No rule learns about file types — a Rust line whose only edit sits far
to the right is served by the same window. Both quote sites take a pair and
neither ever quotes a line alone, so rule 2's drifted line and rule 4's stale
pinned-block line both go through it.

`doc/wide.md` is the fixture: a 151-character catalogue row whose only edit sits
at character 147, cited as `wide.md:11` from the drift fixture at both revisions
so the rule compares rather than exempts it. The assertion is a property and not
a string — the two reported halves must differ from each other, and neither may
exceed `QUOTE_WIDTH` — so it survives a later change of window strategy, and its
second half makes "do not fix this by removing the clip" mechanical. Seen red:
with this commit's production change reverted and the fixture kept, `--self-test`
exits 1 printing the two identical clipped strings.

`FIXTURE_TOTAL` 29 -> 30 for the citation the drift fixture gains, and
`FIXTURE_DRIFT_COMPARED` 30 -> 31 for the one compared line end behind it. Every
other fixture constant is unchanged; `FIXTURE_TEST_EXAMINED` deliberately stays
at 6, because the new document carries no backticked identifier long enough to
be a rule 3 candidate.

`doc/README.md` is unaffected: its citation section describes the rule and its
command line, never the width or the anchoring of a quoted line.

Closes #1448.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 84a3235 into main Sep 23, 2026
24 checks passed
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.

A drift report clips wide lines at column 72, so a table-row change prints two identical strings

1 participant