Skip to content

ci(doc): forbid a file.rs:NNN citation in a Rust comment, and convert the live ones to symbols - #1493

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
ci/forbid-rust-comment-line-citations
Sep 24, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
ci/forbid-rust-comment-line-citations

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Refs #1473, refs #1466.

A file.rs:NNN citation written in a Rust comment is outside check_doc_citations.py's scope entirely — it resolves only doc/** and **/LIFECYCLE.md. So those citations drift with no signal, and nothing stops a new one being written.

#1473 asked which way to close that, and its author stated an inclination:

My inclination is (2)-by-symbol: a line number in a comment is a pointer with no owner, and this issue is what that costs.

That is what ships here: convert the live ones to symbols, then forbid the form rather than resolve it. Forbidding is the cheaper rule — extending the resolver to **/*.rs would widen the drift comparison across a codebase where line shifts are constant and legitimate.

The population is 8, not 4

A prefix grep for (lib|command|bin|e2e)/src/…\.rs:[0-9]+ finds four. Driving the script's own PATH regex finds eight — the extra live one is unbackticked and sibling-relative:

// Mirror of h1.rs:361-368 for the H2-backend → H2-frontend

A prefix-keyed extractor walks straight past it. That is the same shape as #1459, and it is why rule 5 fires through rule 1's own resolve_path (sibling-first) rather than a fresh pattern: the rule and the resolver cannot disagree about which file a citation names.

citation verdict
h2.rs header → lib/src/lib.rs:1006-1010 wrong — resolves to pub enum RequiredEvents; real targets ~220 lines off
mux/mod.rs ×2 → lib/src/https.rs:650-655 wrong — resolves to an Arc::new(snapshot) block; real write-up 367 lines off
h2.rs → h1.rs:361-368 adjacent — lands on the enclosing if status == SocketResult::Closed, 2–8 lines above the arm_writable() mirror the prose describes
mux/stream.rs → lib/src/metrics/mod.rs:44 correct — converts anyway, keeping the claim and losing the number
h2_flood_detector.rs → h2.rs:6946 exempt — scoped "at the pre-extraction revision"
mux/stream.rs ×2 → kawa/… external — resolve to no file here; skipped and counted

Symbols were chosen by reading the real target and walking back to its enclosing item, not guessed: Readiness::arm_writable / Readiness::signal_pending_write, HttpsSession::close, ConnectionH1::readable's close-delimited EOF branch.

All five edits are line-count neutral (10 insertions, 10 deletions), deliberately — rule 2 compares cited-line text, and a shifted line is a false drift report. Confirmed after the fact: 327 compared, zero drifted.

Rule 5's scope

Every *.rs in the tree, not a directory list. The defect is a property of the form, not of the citing directory; scoping to lib|command|bin|e2e/src would leave sim/, fuzz/, lib/benches, lib/examples, integration tests and every build.rs free to reintroduce it while reading as a rule that covers Rust comments.

That it is not narrowed to nothing is proven rather than asserted: restricting rust_files to those four directories turns --self-test red on four separate assertions.

CHANGELOG.md and other historical .md records cannot trip it — the rule reads *.rs. doc/README.md's own "One surface gap" paragraph is the precedent for that.

Historical in-comment anchors follow NOT_A_TEST's existing precedent rather than a new mechanism: HISTORICAL_CITATIONS = {(citing file, exact citation text): reason}, with one entry and its reason spelled out. The comment states that an entry without a reason is an unreviewed silencing, and that a live pointer does not belong there.

Seen red, then green

Planting one citation in lib/src/metrics/mod.rs:

::error::1 of 4 `file.rs:NNN` citations written in a Rust comment name a line in this tree:
  lib/src/metrics/mod.rs:44: `lib/src/metrics/mod.rs:44` — a line number cited from a Rust comment,
  naming lib/src/metrics/mod.rs; cite the SYMBOL instead (`Type::method`), with the path and no line number
EXIT=1

Removed:

OK: no `file.rs:NNN` citation in a Rust comment names a line in this tree
    (3 seen; 2 name no file here, 1 exempt as historical).
EXIT=0

Both CI self-test modes stay green: --self-test exit 0, and the deliberately-broken fixture tree exits 1 with do not resolve present, which is what ci.yml asserts.

Verification

cargo +nightly fmt --all -- --check                     exit 0
cargo build  --locked --no-default-features --features crypto-ring,…   exit 0
cargo clippy --all-targets --locked … -- -D warnings    exit 0, 0 diagnostics
cargo test -p sozu-lib --locked …    ok. 1100 passed; 0 failed    baseline held exactly
check_doc_citations.py --root .      211 citations, 519 test names, 16 pinned; rule 5: 3 seen, 2 external, 1 exempt
check_doc_citations.py --base 9472cd96   327 compared, 0 drifted, 0 exempt spans
check_doc_citations.py --self-test   exit 0
check_doc_citations.py --root .github/scripts/testdata/citations   exit 1, as ci.yml requires
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked   exit 0

Comments-only in Rust, so sozu-lib stays at 1100 exactly. Every pre-existing checker count preserved. Zero new #[allow], #[ignore], or async fn; Cargo manifests and the generated proto untouched.

doc/README.md

Four stale scope statements corrected, not one: the "a citation inside a comment is outside its scope entirely" sentence, the "Nothing mechanical enforces this yet" paragraph, the local-run section, and the "One surface gap" paragraph.

Its worked example is still symbol-accurate after #1479 — both symbols exist — but "now lands" was re-tensed to "landed, at that revision", because #1479 has since inverted that write path and the present tense named a tree nobody can check it against.

What this does and does not close

#1473 is fully addressed. Its part 1 was already done by #1480; its part 2 asked for the scope decision, and the author's stated preference is what shipped, now mechanically enforced rather than a review convention.

#1466 is not closed by this, and is marked Refs rather than Closes. Its four h2.rs citations lived in the doc surface, not Rust comments — which is exactly why rules 1 and 2 were each "individually satisfied" by them — and they are already gone from main, converted to symbol form in LIFECYCLE.md when #1479 landed. What remains is #1466's structural ask: a --audit mode, because a change detector cannot find a defect that predates its first observation. Rule 5 does not deliver that — it leaves doc/** and **/LIFECYCLE.md free to carry line numbers, where a frozen-wrong citation is still invisible.

check_doc_citations.py resolved citations in doc/** and every **/LIFECYCLE.md
only, so the same citation written in a //, /// or //! comment was outside all
four of its rules: never extracted, never resolved, never drift-compared, and
never reported as unresolvable either. sozu#1473 measured the cost on the worst
shape — two SAFETY: comments justifying from_utf8_unchecked whose claim was true
and whose proof path pointed at a Method match arm instead of the function they
named. sozu#1466 found the same defect frozen: a citation already wrong when the
drift rule first saw it is exempt forever, because "unchanged" is the condition
for being exempt.

A fifth rule now FORBIDS the form rather than resolving it. Extending the
resolver over **/*.rs was measured and rejected: at 19fd5d8 the tree held 90
such tokens and 68 had already drifted, so the resolver would have failed on
most of the population it guarded, and it would have widened the drift rule
across a codebase where line shifts are constant and legitimate. Forbidding
imports no pre-existing failure and has nothing to renumber. It reads every
*.rs — not lib|command|bin|e2e/src alone — and resolves sibling-first through
the resolver's own resolve_path, which is what reaches a bare h1.rs:361-368
written from mux/h2.rs; the finder grep in #1473, keyed on a lib/src/-style
prefix, walks past that shape, and a rule built on the same prefix would have
shipped green over it. A citation naming no file here — the two into the pinned
kawa dependency — is skipped and counted beside what was checked. CHANGELOG.md
is not read: it is an append-only record carrying quoted tool transcripts, and a
rule that failed on one would be asking for the record to be rewritten.

Five citations converted, every one re-derived against the tree rather than
renumbered. Three were wrong. mux/h2.rs's module preamble cited
lib/src/lib.rs:1006-1010 for "arm writable / signal pending write" and landed on
pub enum RequiredEvents, ~220 lines from Readiness::arm_writable and
Readiness::signal_pending_write. Both mux/mod.rs shutdown sites cited
lib/src/https.rs:650-655 for a write-up about SHUT_RD and TCP RST and landed on
an Arc::new(snapshot) block, ~370 lines from the comment inside
HttpsSession::close. The fourth, mux/stream.rs's lib/src/metrics/mod.rs:44, was
correct and still converts — it keeps its claim and loses the number. The fifth
is the one no prefix-keyed grep reports: mux/h2.rs:5233's bare h1.rs:361-368,
now ConnectionH1::readable's close-delimited EOF branch. All five edits are
line-count neutral, so no citation in doc/** or any LIFECYCLE.md moved and the
drift rule compares 327 cited lines unchanged.

One citation is declared historical rather than converted: h2_flood_detector.rs
cites h2.rs:6946 for H2FloodDetector::default()'s test call sites AT THE
PRE-EXTRACTION REVISION, which the same sentence says out loud. That extraction
deleted the impl Default it describes, so there is no symbol to cite and no line
to renumber onto — renumbering would falsify a record. HISTORICAL_CITATIONS
holds it, keyed on the citing file and the exact citation text, with the reason;
an entry without a reason is an unreviewed silencing of the rule, as for
NOT_A_TEST.

Seen red: planting one lib/src/metrics/mod.rs:44 in a comment in
lib/src/metrics/mod.rs takes the run to exit 1 naming that file, that text and
the file it resolves to; removing it restores exit 0 with the file
byte-identical. Narrowing rust_files to lib|command|bin|e2e also turns
--self-test red, on four assertions, so the scope decision is asserted rather
than described. The self-test gains a fixture per shape — single line, range, /
group, bare sibling binding to mod/h2.rs rather than the root h2.rs, and an
external citation that must stay silent — with both totals asserted, and a
fixture exemption table whose one entry moves a verdict.

doc/README.md records the convention, the rejected alternative and the escape
hatch; its worked example is re-tensed to the revision it was measured at, since
sozu#1479 has inverted that write path since. The ci.yml box gains one clause,
per its own instruction that an ADDED rule gets one.

Refs #1466
Refs #1473

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 6172929 into main Sep 24, 2026
54 of 55 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the ci/forbid-rust-comment-line-citations branch September 24, 2026 05:15
FlorentinDUBOIS added a commit that referenced this pull request Sep 24, 2026
…saw it (#1495)

Every rule in check_doc_citations.py either resolves a citation or forbids a
form, and none of them can see a citation that was already wrong the first
time it was seen. The drift rule cannot by construction: it compares a
citation's text between two revisions, so "unchanged" is exactly the condition
for being exempt, and a change detector cannot find a defect that predates its
first observation. #1493 closed that hole for Rust comments by forbidding the
form; doc/** and **/LIFECYCLE.md keep their line numbers, because there a
number is sometimes the only way to name a span with no symbol.

--audit reads every citation's prose against its cited line on two heuristics:
the target is a comment while the prose names a statement, a call, an insert or
a push, or the prose names a symbol that is neither within eight lines of the
span nor an item enclosing it. Measured against #1466's own four citations at
5d5191e, the comment signal reports three and the symbol signal reports the
fourth, which lands on ordinary code. It is advisory: it always exits 0, never
edits a citation, and is deliberately absent from ci.yml, because a heuristic
that fails a build is one people learn to silence.

Its first run at 6172929 examined 108 of the surface's 221 cited spans and
reported 13: six wrong citations and seven false positives, a ratio printed in
its own output rather than engineered down. The six are repaired here, and
every run prints what it declined to check -- 111 citations naming nothing
either heuristic can test, more than half the surface.

Refs #1466

Signed-off-by: Florentin Dubois <[email protected]>
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.

1 participant