Skip to content

fix(usage-retention): end the gate's production region only at a module boundary - #451

Merged
argszero merged 1 commit into
mainfrom
fix/usage-retention-gate-module-boundary
Nov 27, 2026
Merged

argszero merged 1 commit into
mainfrom
fix/usage-retention-gate-module-boundary

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

The retention gate decides where a file's production code ends, and it cut at the first #[cfg(test)]. That marker is an attribute, not a module: when it attributes a single test-only helper, every reader below it leaves the scanned region — and it leaves before the roster is built, so the rule #449 added (R5, roster complete) cannot see it. The gate goes on reporting r1=true r2=true r3=true r4=true r5=true on a roster that is a strict prefix of the file.

This change makes the boundary one the code checks. The production region now ends at the first #[cfg(test)] that introduces a module (mod … { or mod …; — visibility prefixes, stacked attributes and the one-line form are all recognised). A #[cfg(test)] that does not introduce a module truncates nothing, and in the two files this gate takes facts from — src/routes/ for the roster, src/usage_retention.rs for the threshold and the delete helper — it is recorded in Reading.bare_markers and the new rule R6 (boundary decidable) fails the verdict.

Related Issue

Closes #450

Changes

  • production_region(masked) -> (&str, Vec<usize>) returns the region plus the offsets of markers that are not module boundaries; attributes_a_module decides one marker.
  • Reading gains bare_markers: Vec<String> (file@masked-offset); new rule R6 (r6() = the list is empty), included in all() and printed by blame().
  • read() uses the checked boundary and records non-module markers for the fact substrate; RETENTION_FILE now names the threshold file once instead of the same literal appearing in two places.
  • New test a_bare_test_marker_is_not_a_module_boundary: a synthetic corpus in exactly the shape of the issue, asserted in both directions — the helper does not cut, the module does (four spellings), and the helper is recorded.
  • every_usage_retention_rule_has_a_tooth gains a seventh tooth; the_scanner_sees_both_sides asserts the new list is empty, placed before the roster-count assertion so the cause is named before the symptom.
  • A small factual fix: the constant's doc comment said the marker is always followed by mod tests, which was the assumption rather than the check.
  • Module doc: the rules heading says six, R6 is stated, and the range section states R6's scope (next section).
  • Test-only: this module is #[cfg(test)] mod usage_retention_gate; in src/main.rs. No production behaviour, no config or data-structure change, so config/config.example.toml is untouched.

Scope of R6, stated rather than implied

R6's quantity is the corpus the gate takes facts from, not every file in the tree. #[cfg(test)] legitimately attributes single items elsewhere in this repository, and several of them must stay at module scope — db::seed_test_users is used by routes tests, tx_facts::view_columns and tx_rollup::written_columns are read by gate modules — so a rule demanding module-only markers tree-wide would be a demand this change cannot meet.

Those files contribute only the DELETE count, and there the fail-open is closed by the boundary change itself: their regions now run past a single-item marker instead of stopping at it, so a second DELETE FROM usage_records in test-only code would redden R4 loudly rather than be cut away.

The measurement behind that scoping: under the new boundary nothing in the verdict moves on merged main — delete sites 1 → 1, readers 6 → 6, every rule green — while five files' regions grow (db.rs 24,228 → 36,742 chars, plus config.rs, router.rs, tx_facts.rs, tx_rollup.rs).

Tests

  • cargo test — 615 passed, 0 failed, 0 ignored (614 on merged main; one test added)
  • cargo fmt --check — clean
  • cargo clippy --all-targets -- -D warnings — clean

Proof that the fix has teeth. I injected the issue's own shape into src/routes/admin.rs — #[cfg(test)] fn fixture_reader_probe() -> i64 { 0 } above its three production readers, which sit at :212, :243 and :272 — and ran cargo test usage_retention_gate on the same tree twice:

  • before this patch: 5 passed, 1 failed, and the failure was the roster-count control, not a rule. The verdict read r1=true r2=true r3=true r4=true r5=true with the roster down to three readers (ops.rs ×2, org.rs) — the gate was green on a strict prefix of the file, and only a count floor noticed the three missing readers.
  • after this patch: 5 passed, 2 failed, each naming the cause — r6=false · 非模块标记 ["routes/admin.rs@470"], with all six readers back in the roster.

The probe was then removed; the committed diff touches only src/usage_retention_gate.rs.

Two things I deliberately left alone:

For anyone reading the release line: v0.7.35 predates both #449 and this change, so downloads still carry the silent drop.

Checklist

  • Branch name follows the convention (fix/<description>)
  • Commit message uses Conventional Commits
  • Single purpose, minimal change
  • No config or data-structure change, so no example file to sync

…le boundary

The gate cut a file's production code at the first `#[cfg(test)]`. That marker
is an attribute, not a module: when it attributes a single test-only helper,
every reader below it leaves the scanned region — and it leaves before the
roster is built, so R5 (#449), which judges the roster, cannot see it. The
verdict stays green on a roster that is a strict prefix of the file.

The boundary is now one the code checks: the region ends at the first
`#[cfg(test)]` that introduces a module (`mod … {` / `mod …;`), and a marker
that does not is recorded in `Reading.bare_markers` and fails the new rule R6
in the two files the gate takes facts from (`src/routes/` for the roster,
`src/usage_retention.rs` for the threshold and the delete helper).

Test-only module: no production behaviour change, no config or data-structure
change.

Closes #450
@argszero
argszero merged commit b419c54 into main Nov 27, 2026
2 checks passed
@argszero argszero mentioned this pull request Dec 3, 2026
argszero added a commit that referenced this pull request Dec 3, 2026
Five commits since v0.7.35 (#449, #451, #452, #453, #454). No schema change
(18 either side). The version string moves in the five carriers the deploy
gate guards: Cargo.toml, Cargo.lock, Dockerfile, docker-compose.yml and the
new CHANGELOG heading.

Co-authored-by: argszero <argszero@users.noreply.github.com>
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.

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

1 participant