Repository navigation
fix(usage-retention): end the gate's production region only at a module boundary - #451
Merged
Merged
Conversation
…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
Merged
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 reportingr1=true r2=true r3=true r4=true r5=trueon 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 … {ormod …;— 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.rsfor the threshold and the delete helper — it is recorded inReading.bare_markersand 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_moduledecides one marker.Readinggainsbare_markers: Vec<String>(file@masked-offset); new rule R6 (r6()= the list is empty), included inall()and printed byblame().read()uses the checked boundary and records non-module markers for the fact substrate;RETENTION_FILEnow names the threshold file once instead of the same literal appearing in two places.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_toothgains a seventh tooth;the_scanner_sees_both_sidesasserts the new list is empty, placed before the roster-count assertion so the cause is named before the symptom.mod tests, which was the assumption rather than the check.#[cfg(test)] mod usage_retention_gate;insrc/main.rs. No production behaviour, no config or data-structure change, soconfig/config.example.tomlis 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_usersis used byroutestests,tx_facts::view_columnsandtx_rollup::written_columnsare 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
DELETEcount, 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 secondDELETE FROM usage_recordsin 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.rs24,228 → 36,742 chars, plusconfig.rs,router.rs,tx_facts.rs,tx_rollup.rs).Tests
cargo test— 615 passed, 0 failed, 0 ignored (614 on mergedmain; one test added)cargo fmt --check— cleancargo clippy --all-targets -- -D warnings— cleanProof 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,:243and:272— and rancargo test usage_retention_gateon the same tree twice:r1=true r2=true r3=true r4=true r5=truewith 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.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:
CHANGELOG.md:82records this gate as having "四条规则". That line is the v0.7.30 release entry — a record of what shipped then — so it stays as written rather than being brought forward.perf_gate,i18n_packandstate_gateall take the first marker). Whether the same hole matters in those corpora is a separate report; this PR stays on the gate usage retention gate ends a file's production region at the first #[cfg(test)], which is not always a module boundary #450 names.For anyone reading the release line:
v0.7.35predates both #449 and this change, so downloads still carry the silent drop.Checklist
fix/<description>)