Skip to content

test(analysis): add source-role conformance corpus and authority check - #3618

Merged
EffortlessSteven merged 8 commits into
mainfrom
test/3534-source-role-authority
Sep 1, 2026
Merged

EffortlessSteven merged 8 commits into
mainfrom
test/3534-source-role-authority

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

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 approved rust_index::is_test_file consumer 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.
  • Conformance corpus — 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 through facts::build_index and 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.rs stays production); plain/conjunct/negated cfg variants all reaching executable tests.
  • One production fix the gate caught on main: TestTargetEvidence::fixture classified Integration-vs-InlineUnit with a local contains("/tests/")/starts_with("tests/") pattern instead of the rust_index::is_test_file authority.

Non-goals

Verification

  • gate: pass on the fixed tree; fails on an injected production re-derivation (mutation demo in-session); consumer inventory flags unapproved is_test_file callers
  • corpus: 4 cases green through facts::build_index + workspace classification
  • full ripr lib suite green (4,753 tests), clippy -D warnings and fmt clean, cargo xtask precommit green (including goldens check, fixtures, evidence-promotion honesty, traceability, command catalog)

Devin Review

#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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-01T10:59:49.239309Z deeddc7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 06fd347a-fdb5-4beb-835c-27441c602401

📥 Commits

Reviewing files that changed from the base of the PR and between 2fec523 and ffe603e.

📒 Files selected for processing (4)
  • crates/ripr/src/analysis/source_role_corpus.rs
  • crates/ripr/tests/data/source-role-corpus/cases/cfg_variants/src/lib.rs
  • policy/workspace_shape.txt
  • xtask/src/main.rs

Summary by CodeRabbit

  • New Features

    • Added a source-role conformance test corpus covering production code, explicit test targets, naming lookalikes, and cfg(test) variants.
    • Added a precommit check to enforce consistent source-role classification and generate a policy report.
  • Bug Fixes

    • Improved test-file classification by using the authoritative source-role analysis instead of path-based detection.
  • Documentation

    • Documented the source-role corpus, supported cases, expected outcomes, and test commands.

Walkthrough

The 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.

Changes

Source-role conformance

Layer / File(s) Summary
Corpus driver, fixtures, and specifications
crates/ripr/src/analysis/*, crates/ripr/tests/data/source-role-corpus/*
The test corpus deterministically discovers fixtures and validates production roles, executable tests, test-file classification, explicit targets, naming lookalikes, and cfg(test) variants.
Typed test-file classification
crates/ripr/src/analysis/test_grip_evidence.rs
TestTargetEvidence::fixture uses rust_index::is_test_file(file) for test-kind classification.
Authority audit and precommit integration
xtask/src/command.rs, xtask/src/dispatch.rs, xtask/src/main.rs
The new command scans production Rust sources for role heuristics and unauthorized authority calls. It emits a policy report and runs during precommit checks.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: 🔵 Low · up to 2fec5

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
Loading

Poem

A rabbit checks each source in line
Typed roles bloom, precise and fine
No filename tricks slip through
The corpus keeps the contract true
An xtask gate reports what’s due

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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, rollba… 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 traceabil…
Linked Issues check ⚠️ Warning The PR implements the authority gate, four-case corpus, and one detected consumer fix [#3534]. It does not demonstrate the broader linked-issue requirements for the complete supported matrix, includin… Extend the retained corpus and consumer checks to cover the supported and limited matrix in #3534, or explicitly separate the unimplemented requirements into approved follow-up scope. Add evidence for deterministic behavior, mutation discri…
Docstring Coverage ⚠️ Warning 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:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the two primary changes: the source-role conformance corpus and the authority check.
Out of Scope Changes check ✅ Passed The changes remain related to #3534. The corpus fixtures, documentation, authority gate, precommit integration, and TestTargetEvidence fix all support source-role conformance or enforcement.
Full details: Description check

Explanation

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 check

Explanation

The PR implements the authority gate, four-case corpus, and one detected consumer fix [#3534]. It does not demonstrate the broader linked-issue requirements for the complete supported matrix, including benches, examples, production-like opt-ins, function and attribute variants, harness and composition cases, cache currentness, stale-role protection, public output parity, and the required conformance JSON and Markdown artifacts [#3534].

Resolution

Extend the retained corpus and consumer checks to cover the supported and limited matrix in #3534, or explicitly separate the unimplemented requirements into approved follow-up scope. Add evidence for deterministic behavior, mutation discrimination, stale-role handling, consumer parity, and the required bounded conformance reports.

Full details: Docstring Coverage

Explanation

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 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/3534-source-role-authority

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

gemini-code-assist[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

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).
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

- 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).
coderabbitai[bot]

This comment was marked as resolved.

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.
devin-ai-integration[bot]

This comment was marked as resolved.

…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

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

Devin Review

Comment thread xtask/src/main.rs Resolved
@EffortlessSteven
EffortlessSteven merged commit f74c799 into main Sep 1, 2026
32 checks passed
@EffortlessSteven
EffortlessSteven deleted the test/3534-source-role-authority branch September 1, 2026 14:09
EffortlessSteven added a commit that referenced this pull request Sep 1, 2026
#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)
EffortlessSteven added a commit that referenced this pull request Sep 3, 2026
…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.
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.

test(rust): build a source-role conformance corpus and ban consumer-side re-derivation

1 participant