Repository navigation
test(analysis): add source-role conformance corpus and authority check - #3618
Conversation
#3534) The source-role family (#3499, #3530, #3531, #3532, #3533) fixed individual producers and consumers; this adds the retained denominator: - cargo xtask check-rust-source-role-authority: a structural gate that rejects consumer-side role re-derivation (tests-root path checks, test-suffix naming, string-literal cfg(test) matching) outside the producer modules, names the owning producer API, and inventories the approved rust_index::is_test_file consumers. Scanning stops at each file's first top-level #[cfg(test)] item so test fixtures and assertions are out of scope. - crates/ripr/tests/data/source-role-corpus: four conformance cases (production library, explicit test target, naming lookalike, cfg variants) driven by an in-crate test asserting producer-owned facts through facts::build_index and the workspace layout classification. - The one production re-derivation the gate caught on main is fixed: TestTargetEvidence::fixture now classifies Integration-vs-InlineUnit through rust_index::is_test_file instead of a local path pattern. Verified: gate passes on the fixed tree and fails on an injected production re-derivation; full lib suite green (4,753 tests); clippy -D warnings and fmt clean; precommit green.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedNext included review available in 3 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 📒 Files selected for processing (4)
Summary by CodeRabbit
WalkthroughThe change adds a Rust source-role conformance corpus, replaces local test-file path checks with typed classification, and adds a CI-enforced xtask audit for consumer-side role derivation. ChangesSource-role conformance
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: 🔵 Low · up to The PR centralizes source-role classification and adds an enforced repository gate, but the gate can miss some production code around cfg(test), and parts of the conformance corpus and consumer inventory do not fully validate the intended cases. It is mergeable with explicit owner awareness and follow-up on these bounded enforcement and test-coverage gaps. Sequence Diagram(s)sequenceDiagram
participant CLI as xtask CLI
participant Check as check_rust_source_role_authority
participant Sources as crates/ripr/src
participant Report as source-role-authority.md
CLI->>Check: run check-rust-source-role-authority
Check->>Sources: scan production Rust sources
Sources-->>Check: source text and authority findings
Check->>Report: write policy report
Check-->>CLI: return check result
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
Full details: Description checkExplanation The description gives a useful summary, non-goals, and verification results, but it omits most required template sections, including scope classification, source-of-truth links, proof commands, rollback, claim boundary, traceability, engineering checks, gates, and CI economics. Resolution Complete the repository template. Add the missing sections and required checkbox or n/a entries, especially CI economics because this PR adds a precommit policy gate. Include exact proof commands and results, source/spec/test/code traceability, claim boundaries, rollback steps, and engineering and gate status. Full details: Linked Issues checkExplanation The PR implements the authority gate, four-case corpus, and one detected consumer fix [ Resolution Extend the retained corpus and consumer checks to cover the supported and limited matrix in Full details: Docstring CoverageExplanation Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 11 files. (7 skipped: 6 unsupported, 1 too large.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The executed precommit sequence now runs the new gate between check-architecture and check-public-api, matching the precommit report string (canonical precommit gate-list tests).
- cfg_variants: add a plain helper inside each cfg-gated module and assert CfgTestModule evidence role, so broken enclosing-cfg recognition fails even though each test fn carries #[test] independently (devin review). - explicit_test_target: move the test to a custom [[test]] path (tests/custom/smoke_case.rs) so manifest parsing, not conventional layout, determines executable-test membership (devin + codex review). - repair_attempt: drop the ineffective mutation-demo filter (gemini + devin review). - document raw_production_text's first-test-item boundary (devin review EyT8 residual, recorded on #3534).
check-workspace-shape scans every tracked Cargo.toml; the corpus case crates under crates/ripr/tests/data are fixture inputs for the conformance driver, not workspace members, so their manifests join the workspace_shape.txt allowlist with the reason recorded.
…lassify custom path - the negated cfg variant now uses not(not(test)) so the case discriminates cfg(test)-recognition mutations instead of an unrelated feature flag - raw_production_text stops only at unindented #[cfg(test)] lines, matching the documented top-level boundary; indented test items inside production modules no longer truncate the scan - the corpus driver classifies the custom [[test]] path through the workspace layout authority, not only the path authority
#3621) * docs(specs): ratify RIPR-SPEC-0153 and align capability/public wording (#3535) The source-role implementation train (#3499, #3519 disposition, #3530-#3534) is merged and the conformance corpus plus the check-rust-source-role-authority gate (#3618) pin the denominator, so the spec moves from proposed to accepted: - RIPR-SPEC-0153: ratification note; the typed FunctionSourceRole item-role model (#3531) and the governed harness registry (#3532) join the Behavior section; the config-identity note covers the 2 -> 3 bump; Test Mapping and Implementation Mapping gain the corpus driver, the authority gate, and the harness producers. - docs/specs/README.md: the 0153 row moves to accepted with the extended denominator description. - CAPABILITY_MATRIX.md: new source-role row (alpha) with the corpus and gate as evidence. - .ripr/traceability.toml: the 0153 behavior entry gains the corpus driver tests, the corpus fixture directory, and the harness registry code mapping. Downstream suppression removal stays owned by perl-lsp-swarm#9907 against a published artifact (release authority, #3529). * review: complete capability wiring for the source-role row - move the source-role row into the capability matrix table (it landed inside the Update Rules prose sentence, splitting it) - add the machine-readable entry to metrics/capabilities.toml (check-capabilities validates matrix rows against it 1:1) - complete the traceability code mapping (role composition, cfg predicates, test-style normalizers, facts builders, harness projection) and add ParameterizedExpansion to the ratified item-role list (devin review)
…role authority gate (#3629) * fix(xtask): scan production regions after test modules in the source-role authority gate The check-rust-source-role-authority scanner truncated each file at its first column-0 `#[cfg(test)]` line, so every production region below that line escaped the re-derivation ban. `analysis/mod.rs` is the worst case: its gated `mod source_role_corpus;` declaration sits at the top of the file, leaving almost the whole file unscanned (recorded as the residual on #3534 in the #3618 closeout). Replace the line truncation with a region-aware scanner: it lexes just enough Rust (line/block comments, string/raw-string/char literals, lifetimes) to track brace/paren depth, exempts the interiors of top-level `#[cfg(test)]` items in full (braced bodies and semicolon declarations, plus chained attributes), and rescans production code before, between, and after them. A line seam separates removed items so patterns cannot splice across an exemption. Deny rules, producer exemptions, the allowed-site inventory, and the `is_test_file` consumer inventory are unchanged; patterns still match as plain substrings of the returned production text. Proof: the #3534 injection (`contains("/tests/")` below line 19 of `analysis/mod.rs`) passed the gate before the fix and fails it after, naming the violation and owner; the gate stays green on the unmodified tree. 15 new unit tests pin the scanner table: production-only, test-mod-first-then-production, production-then-test-mod, gated declarations and free functions, multiple gated items, nested braces, brace-bearing strings and raw strings, char literals and lifetimes, cfg(test) spellings inside comments/strings, indented (nested) gated items, and extra attribute chains. * fix(xtask): three scanner precision fixes in the source-role authority gate Review round on #3629, all in the #3534 region-aware scanner: - Gated functions now end at the body brace, not the signature paren. The item skipper previously returned on any closer that unwound its depth to zero, so a gated "fn gated() { ... }" stopped at the signature's ")" and emitted the whole test body as production text - a denied spelling used only by the test helper rejected valid code. The head loop now ends declarations at the level-0 ";" and skips the first level-0 brace group as the balanced body; ")" / "]" closers only unwind the signature. - Square brackets count toward production nesting, so a valid #[cfg(test)] element inside a module-level array or "macro![...]" token tree is no longer mistaken for a top-level item whose skip discards tokens through the enclosing semicolon. - Raw-string prefixes cover the full Rust set (r, br, cr); the hash-aware terminator keeps an embedded quote from closing br#"..."# / cr#"..."# early and exposing braces to depth tracking. Plain b"..." / c"..." strings stay on the quote branch and are pinned alongside. Proof: the #3534 injection below analysis/mod.rs line 19 still turns the gate red with the violation named, and the gate stays green on the unmodified tree. 18 unit tests (15 prior + 3 new; the gated-free-fn assertion now pins body exemption via an unmatched denied spelling): signature-paren shape, array-nested cfg(test), and each raw prefix. * fix(xtask): three region-scanner precision fixes from review Review findings on #3629 (devin, coderabbit): cfg attr matching skipped comments so #[cfg(/* test-only */ test)] stayed in production scans; gated const/static items with block-expression initializers ended at the first top-level brace and leaked their tails; and attribute or doc-comment lines preceding a gated item (#[doc = r#"..."#]) triggered false authority violations. cfg token boundaries now skip trivia, the head keyword routes declarations to the top-level semicolon and definitions to the body brace, and the preceding attribute/doc run is trimmed with the item. Pinned by three new unit tests. * fix(xtask): end gated items at their close, continuing only through else chains Review finding on #3629 (devin): after a definition body closed, the scanner resumed at the close but kept looking for a later depth-0 semicolon, consuming following production code into the exempt item. The depth-0 brace-group branch now ends the item at the group's close, continuing only when the next token is a semicolon (initializer end, consumed) or an `else` token (an if/else initializer chain, also skipped); anything else ends the item and production scanning resumes. Else-if chains bail conservatively to end-of-file rather than guessing where the chain ends.
Closes #3534. Parent: #3213. Normative: RIPR-SPEC-0153.
Summary
The source-role family (#3499, #3530, #3531, #3532, #3533) fixed individual producers and consumers one at a time; each local test could pass while the integrated product still disagreed about whether the same item is a production subject, executable test, helper evidence, or unknown. This PR adds the retained denominator the issue asks for:
cargo xtask check-rust-source-role-authority— a structural gate that rejects consumer-side role re-derivation in production code: tests-root path checks, test-suffix naming inference, and string-literal#[cfg(test)]matching outside the producer modules. Every violation names the owning producer API (rust_index::is_test_file,SourceRoleContext::classify_with,facts::cfg_predicates). The approvedrust_index::is_test_fileconsumer set is an inventoried allowlist; new consumers must extend it with a reviewed reason. Scanning stops at each file's first top-level#[cfg(test)]item so test fixtures and assertions (which legitimately manipulate source text as data) stay out of scope.crates/ripr/tests/data/source-role-corpus/cases/(four case crates) driven by an in-crate test (analysis::source_role_corpus) asserting producer-owned facts throughfacts::build_indexand the workspace layout classification: production subject with no executable tests; explicit[[test]]target joining executable tests while production stays seeded; naming-lookalike rejection (src/price_test.rsstays production); plain/conjunct/negated cfg variants all reaching executable tests.TestTargetEvidence::fixtureclassified Integration-vs-InlineUnit with a localcontains("/tests/")/starts_with("tests/")pattern instead of therust_index::is_test_fileauthority.Non-goals
fixtures/source-role-corpus/README.md, which also maps the issue's mutation classes to the discriminating checks. Follow-up PRs extend the corpus per surface.Verification
is_test_filecallersfacts::build_index+ workspace classificationriprlib suite green (4,753 tests), clippy-D warningsand fmt clean,cargo xtask precommitgreen (including goldens check, fixtures, evidence-promotion honesty, traceability, command catalog)