Skip to content

usage retention gate ends a file's production region at the first #[cfg(test)], which is not always a module boundary #450

Done

Description

@argszero

The retention gate decides where a file's production code ends by cutting at the first #[cfg(test)]. That marker does not always start a test module — it can attribute a single test-only helper — and when it does, every reader below it is outside the scanned region, so it is neither paired nor recorded. R5, added in #449, cannot see this: it judges the roster it was given, and this removes entries before the roster is built.

The cut

src/usage_retention_gate.rs (merged main 278dbbde4):

/// 读者源码里生产区的结束标记(之后是 `#[cfg(test)] mod tests`)。
const TESTS_MARK: &str = "#[cfg(test)]";

and in read():

let prod = match masked.find(TESTS_MARK) {
    Some(i) => &masked[..i],
    ...

Everything after that offset is dropped for the rest of the file, without a record of where the cut happened or what it was attributed to.

Why it is the same class as #448, one layer deeper

#[cfg(test)] is an attribute, not a module. A file that grows a test-only helper —

#[cfg(test)]
fn fixture_reader() -> i64 { /* ... */ }

— ends its production region at that line. Every FROM usage_records below it stops existing for the gate: it is not a Reader, and with #449 merged it is not in Reading.unpaired either, because the drop happens before the reader scan rather than inside it. The verdict stays green on a roster that is a strict prefix of the file.

The module doc and read()'s own comment both describe the cut as "#[cfg(test)] mod tests", which is what the code assumes rather than what it checks.

Measured state today (merged main 278dbbde4, read over the REST contents API)

The scanned corpus carries the marker in exactly two files, and both attribute a module:

file marker attributed to
src/routes/ops.rs :296 mod tests {
src/routes/mod.rs :750 mod tests {
src/routes/admin.rs none —
src/routes/org.rs none —

So this is latent, not reachable today, and no reader is currently lost. ops.rs's two production readers (:80, :139) sit well above the marker.

Note for anyone reading the release line: v0.7.35 predates both this and #449, so the shipped release has the #448 drop as well.

Suggested minimal change (test-only file)

Make the boundary one the code checks rather than one it assumes, in the shape #449 used:

  • cut only at #[cfg(test)] that introduces a module, and
  • record any #[cfg(test)] that does not — the offset, as Reading.unpaired records unpaired sites — with a rule that fails the verdict when the list is non-empty.

That keeps the roster derived, keeps the discipline "a guarantee states its own enforcement", and gives the tooth test a seventh mutation. Alternative shapes are fine; the point is that the boundary is recorded rather than silently applied.

Precedent, stated honestly

C2179 (share-edit-state-boundary-gate-scope-20260930) ruled that a purely latent gate-scope hole with no reachable symptom is not worth building, and this hole is latent. It is filed rather than assumed for the same reason #448 was: what the gate protects is usage_records.cost, the only copy of the anchored-currency amount (src/usage_retention.rs:26-27), so the first reader written below such a helper is an irreversible-loss path rather than a display defect.

Activity

  1. added
    bug
    on Nov 26, 2026
  2. argszero commented on Nov 26, 2026

    @argszero
    OwnerAuthor

    Claiming this one as the next contribution. The fix stays inside the same test-only gate and follows the shape #449 just merged: make the production-region boundary one the code checks instead of one it assumes, and record the markers that are not module boundaries so the verdict fails rather than the roster quietly shrinking.

    Branch and PR to follow next cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions