Skip to content

fix(analysis): resolve in-file test-module relative imports from their own scope (#10279) - #10291

Merged
EffortlessSteven merged 13 commits into
mainfrom
claude/project-thread-w6b15g
Oct 25, 2026
Merged

EffortlessSteven merged 13 commits into
mainfrom
claude/project-thread-w6b15g

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Requested by Steven · project thread

Summary

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm

Source-of-truth Links

Proposal: none
Spec: docs/specs/RIPR-SPEC-0159-bounded-helper-transfer.md (amended)
ADR: none
Plan item: #9971 lane (relative import routes)
Governing issue or accepted claim: #10279
Acceptance delta (one sentence): An in-file mod tests { use super::<entry>; } test is related to the entry's changed helper when the import, resolved from its inline-module scope, names the entry's module, and stays refused when it names another scope.

Candidate Relationships

Candidate branch (GitHub PR head is authoritative after publication): claude/project-thread-w6b15g
Stack parent or prerequisite PR (if any): #9934 (merged)
Proposed replacement of PR (if any; not yet accepted): none
Acceptance retained from a replaced candidate (if any): none
Accepted winner and losing candidate disposition (when decided): n/a

Scope

  • Production: crates/ripr/src/analysis/classify/call_identity.rs (unit_test_relative_import_names_entry), plus its caller in related_tests.rs.
  • Evidence:
    • two integration tests in crates/ripr/tests/crate_qualified_entry_reach.rs;
    • fixtures module_reach_super_import_in_file_tests (control, exposed) and module_reach_super_import_in_file_wrong_module (counterexample);
    • honesty-corpus rows, SPEC-0159 text, traceability and a changelog fragment;
    • the blessed spec0186-ex06 row and the Rust missed-credit ceiling.

Scope Classification

  • One production behavior

Non-goals: crediting an in-file import that resolves to a module that only re-exports the entry, or a test fn nested inside another fn. Both are accepted conservative losses, named in SPEC-0159. A raw r# test name gets no relation before this resolver runs; that is filed separately as #10377.

Verdict corpus

On the tree merged with main be652c8, spec0186-ex06-private-predicate-via-wrapper is credited (blessed). Rust results: 668 cases with 3 false verdicts. Measured missed credit is 142, so missed_credit_ceiling goes from 143 on main to 142. The PR is at the top of the Rust ceiling queue.

The control fixture module_reach_super_import_in_file_tests now shows both probes exposed. After #9934 the private boolean return is confirmed through the boundary-pinned wrapper (order_discount(10) == 5, order_discount(9) == 0). The fixture is re-blessed with that reason.

Proof

On head 9a9e29c (local, Linux):

cargo xtask precommit                                   # exit 0
cargo test -p ripr --test crate_qualified_entry_reach   # 41 passed
cargo xtask goldens check                               # exit 0
cargo xtask verdict-corpus check --language rust        # measured 142 = ceiling
  • The new in-file positives fail on main (same_test_file instead of helper_owner_call) and pass here. The one-line-header positive fails on the earlier first-column lookup.
  • Mutants killed: accepting every inline-scope spelling, using only the innermost module, and skipping the test-scope check.
  • The runtime-control integration tests (--test '*') passed on 18a78a7. The only change since then is the main merge and the ceiling.

Claim Boundary

May claim: the in-file mod tests { use super::entry; } layout gets helper-chain reach back. Must not claim: general Rust path resolution.

Rollback

Revert the commit; the resolver returns to refusing inline modules in the test file.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd

…r own scope (#10279)

The default Rust unit-test layout, `#[cfg(test)] mod tests { use super::entry; }`
beside the entry, lost helper-chain reach after #9914: the relative-import
resolver (#10128) refused any inline module in the test file, so the test
fell to proximity-only weak reach. Each `use` item that spells the import is
now resolved from the inline modules around it, and every such item must name
the entry's own module. A `super` that names another inline module, goes past
the crate root, or sits beside a glob, cfg-gated use or nearer binding stays
refused.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd
@EffortlessSteven EffortlessSteven self-assigned this Oct 25, 2026
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 175 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 61ff2f52-c034-4c3b-8899-a4d095b50a6a
Commits

Reviewing files that changed from the base of the PR and between be652c8 and 9a9e29c.

Files selected for processing: 23
  • .ripr/traceability.toml
  • changelog.d/10279-in-file-test-module-relative-import.md
  • crates/ripr/src/analysis/classify/call_identity.rs
  • crates/ripr/src/analysis/classify/related_tests.rs
  • crates/ripr/tests/crate_qualified_entry_reach.rs
  • docs/specs/RIPR-SPEC-0159-bounded-helper-transfer.md
  • fixtures/evidence-promotion-honesty-corpus/corpus.json
  • fixtures/module_reach_super_import_in_file_tests/SPEC.md
  • fixtures/module_reach_super_import_in_file_tests/diff.patch
  • fixtures/module_reach_super_import_in_file_tests/expected/CHANGELOG.md
  • fixtures/module_reach_super_import_in_file_tests/expected/check.json
  • fixtures/module_reach_super_import_in_file_tests/expected/human.txt
  • fixtures/module_reach_super_import_in_file_tests/input/Cargo.toml
  • fixtures/module_reach_super_import_in_file_tests/input/src/lib.rs
  • fixtures/module_reach_super_import_in_file_wrong_module/SPEC.md
  • fixtures/module_reach_super_import_in_file_wrong_module/diff.patch
  • fixtures/module_reach_super_import_in_file_wrong_module/expected/CHANGELOG.md
  • fixtures/module_reach_super_import_in_file_wrong_module/expected/check.json
  • fixtures/module_reach_super_import_in_file_wrong_module/expected/human.txt
  • fixtures/module_reach_super_import_in_file_wrong_module/input/Cargo.toml
  • fixtures/module_reach_super_import_in_file_wrong_module/input/src/lib.rs
  • fixtures/rust-verdict-corpus/expected/rows/spec0186-ex06-private-predicate-via-wrapper.json
  • fixtures/rust-verdict-corpus/spec-coverage.toml
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request resolves issue #10279 by updating the relative import resolution logic for in-file unit-test layouts (e.g., #[cfg(test)] mod tests { use super::entry; }). Each relative use item is now resolved from its specific position, accounting for any enclosing inline modules, and is credited if it resolves to the entry's module. The changes include updates to the analysis logic in call_identity.rs, specification documentation, new integration tests, and corresponding test fixtures. I have no feedback to provide as there are no review comments.

…s module (#10279)

Review of record finding: an import resolved in one inline module (`mod a {
use super::entry; }`) credited a test in a sibling module whose bare call it
does not bind (a prelude function named like the entry). One matching `use`
item must now sit in the test function's own inline module. Adds sibling,
nested-foreign, re-exporting-module and raw-name cases.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd
…, drop allow attribute (#10279)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd

@github-actions github-actions 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.

Verification questions

  • Confirm no sibling path outside the changed resolver and its direct evidence was exhaustively scanned.
  • Confirm the changed resolver has broad scope-path coverage only for direct use super::... forms; no evidence here establishes behavior for grouped or aliased import shapes.

Refuted

  • This PR changes a JS-backed worker handoff, async capture, GC, detach, or transfer boundary and therefore needs worker-memory review.; refuted because: The diff has no JavaScript/TypeScript files and changes only a Rust AST resolver plus tests, fixtures, documentation, and metadata. There is no worker, async, GC, detach, or transfer boundary to review on the right-hand diff.
  • The new fixtures are ready, blessed expected outputs suitable for the repository fixture gate.; refuted because: Their expected CHANGELOG files explicitly label the outputs Pending and provide a bless command, so the changed expectations are not yet evidence of a passing fixture validation run.
  • The wrong-scope fixture might still establish an oracle for the changed crate-root helper because its assertions mention order_discount and the same literals.; refuted because: The fixture explicitly models flat::order_discount, and the expected analysis retains same_test_file/weak reach rather than helper_owner_call; exact literals alone do not establish ownership of the changed helper.

Evidence gaps

  • The stated Rust corpus result depends on a prerequisite PR and the current packet lacks a successful ripr receipt.
  • The repository's ripr sensor failed with exit code 2, so the deterministic analyzer receipt does not independently confirm this patch's behavior.
  • The ripr sensor failure and lack of heavy/local execution leave the changed resolver's runtime-independent behavior dependent on the scheduled cargo-test and focused integration proof.
  • Both new fixture goldens are marked pending, while the positive control's return-value finding remains weakly_exposed with an unconfirmed discriminator.
  • Model proof intent was rejected by deterministic validation.
  • The integration tests assert relation strength through assert_recovered and assert_refused, but do not independently execute the fixture test binaries or prove their runtime assertions pass.
  • Runtime validation is not yet evidenced in this lane because ripr failed and cargo-test was only scheduled late.

Copy link
Copy Markdown
Member Author

Review of record (source/oracle), head 4e146fe

Status: the source and oracle review is complete with no open blocking finding. This is not merge clearance. Merging still waits on #9934 landing (see Verdict corpus), then a main merge, re-bless and ceiling, and hosted qualification on that final head.

Angles. Three independent reviewer agents worked read-only against the exact commits:

  1. Correctness, edge cases and false credit.
  2. Tests, oracles, spec and contract.
  3. Performance, caller regressions and code quality.

Angle 2 then re-reviewed the repair.

Findings and resolutions

  • Blocking, fixed in 574620f. An import resolved in one inline module (mod a { use super::entry; }) credited a test in a sibling module whose bare call that import does not bind. The realistic case is an entry named like a prelude function (drop, size_of), which callee_is_unique does not see. The fix requires one matching use item to sit in the test function's own inline module. The new case import only in a sibling module kills a mutant that skips this check.
  • Refuted. Angle 2 reported that a nearer foreign alias in the test's module (use std::convert::identity as order_discount) was credited. It was not: the file-wide renamed-import veto in helper_transfer::test_call_is_shadowed already refuses it, which the re-review confirmed. Both shapes are now pinned as end-to-end cases, labelled as decided by that guard.
  • Non-blocking, applied.
    • The both case is rebuilt with a foreign re-export decoy, so the all-spellings loop decides it rather than a duplicate definition.
    • The re-exporting-module conservative loss is pinned.
    • A test fn nested inside another fn is pinned as a refusal and named in SPEC-0159.
    • Added a mod r#tests positive.
    • Guard-decided cases are labelled as such.
    • strip_prefix is used for consistency.
    • The changelog now cites feat(analysis): resolve relative super/self unit-test imports of the entry (#9971) #10128.
  • Non-blocking, accepted.
    • Cost: parses go through PARSE_CACHE. The per-call walk over Use items is a modest increase that the old refusal path mostly paid already.
    • A file where any spelling resolves elsewhere refuses every test in it. This under-credits; it never over-credits.

Proof on this head (local, Linux, CARGO_PROFILE_*_DEBUG=0 because of disk limits)


Generated by Claude Code

@github-actions github-actions 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.

Decision

  • Needs one verification check before upstream.

Verification questions

  • Confirm broader sibling-path coverage of grouped, aliased, nested, and other Rust import spellings is not established by the supplied evidence.

Refuted

  • No active-view or transfer boundary is changed: the patch contains no JS/TS, ArrayBuffer, TypedArray, resize, detach, worker handoff, or backing-store operations.
  • This PR may introduce an active-view invalidation, detached-buffer, or stale-length bug.; refuted because: The assigned surface does not exist in the changed patch: production behavior is limited to Rust AST import resolution, and there is no mutable backing store, view length, resize, detach, or transfer operation.
  • This change modifies a JS-backed worker handoff, async capture, GC, detach, or transfer boundary and therefore needs worker-memory review.; refuted because: The diff contains no JS/TS files and no worker, async, GC, detach, transfer, thread-handoff, unsafe-memory, or ownership-boundary code. Its production change is ordinary synchronous Rust AST traversal and scope resolution.
  • The change requires a broader replacement of Rust name-resolution logic across the analyzer.; refuted because: The diff keeps the decision inside the existing relative-import predicate and extends only its inline-module boundary; the caller and surrounding routes remain unchanged.
  • The change could create an unsafe-code or exploit primitive by resolving attacker-controlled module paths.; refuted because: The path consists of ordinary Rust AST analysis over repository source. The changed code introduces no unsafe operations, raw pointers, FFI, deserialization boundary, secrets, network input, or privilege transition; ambiguous paths are conservatively refused.
  • The implementation claims general Rust path resolution and therefore must support all grouped or aliased use forms.; refuted because: The changed documentation explicitly bounds the claim to the named relative import route and preserves fail-closed behavior; grouped/aliased support is not claimed by this PR.

Parked follow-ups

  • The new resolver can associate an import with the wrong test function when multiple test functions occupy the same inline module.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.
  • The PR’s strongest runtime evidence is incomplete in the supplied packet because ripr failed and cargo-test is only scheduled late.

@github-actions github-actions 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.

Confirmed findings

  • Test-scope identification is based on a token at the test’s line/column and then searches that token’s ancestors for the nearest function; the same first-line column can identify a different node when nested modules or declarations share a line.

Verification questions

  • Confirm broader import-shape coverage is not established by the supplied diff: grouped imports are tested, but aliased relative imports and other spellings are not demonstrated.
  • Confirm the new tests cover positive nested/grouped/raw-identifier cases and negative wrong-module, sibling-import, glob, cfg, nearer-binding, and nested-function cases.
  • Confirm general Rust path resolution, aliases, and import forms beyond the tested relative spellings are not established by this patch.

Refuted

  • This PR changes a JS-backed worker handoff, async capture, GC, detach, or transfer boundary.; refuted because: The changed production code only resolves Rust use-item scopes and associates a test with an entry; the diff contains no JS/TS, async, worker, GC, detach, ownership-transfer, or mutable backing-store operations.
  • The new source-offset and inline-module traversal may introduce an OOB read, UAF, or type-confusion exploit primitive.; refuted because: The changed code uses safe Rust string/syntax APIs, checked u32 conversion, and immutable AST references; no unsafe/native boundary or unchecked indexing pattern is added. unsafe-review found no new or worsened gaps.
  • The change affects worker handoff, active views, unsafe memory, or another native ownership boundary.; refuted because: The production change is synchronous Rust AST/import-scope analysis; the diff contains no worker, async, GC, detach, view, unsafe, or ownership-transfer code.
  • The wrong-module fixture could still credit a test through the changed crate-root entry because it shares the file.; refuted because: The expected result records zero exposed findings and relation_reason same_test_file only, matching the intended conservative refusal of flat::order_discount.
  • The source-line offset lookup could preserve a stale active-view length or snapshot and cause an out-of-bounds view access.; refuted because: The offset is computed from immutable source text solely to identify the enclosing Rust function. It is bounded by source length, converted with u32::try_from, and no buffer/view length or backing-store mutation is involved.
  • The changed resolver may introduce an unsafe pointer or lifetime/ownership violation.; refuted because: The diff is ordinary owned Rust syntax-tree traversal with no unsafe block, raw pointer, borrowed lifetime extension, mutable alias, or transfer boundary.

Evidence gaps

  • The fixture goldens still contain Pending changelog entries, so repository fixture validation or blessing remains a human/check-runner verification step rather than proof embedded in this diff.
  • Model proof intent was rejected by deterministic validation.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd
@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 25, 2026 13:02
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copy link
Copy Markdown
Member Author

Reply to the automated review on 550e039 (test-scope identification) and the parked follow-up on 4e146fe.

Test-scope token pick (not a false-credit path). The scope comes from the first non-whitespace token on the test's start line, then that token's nearest Fn ancestor, then its inline-module chain. If a line holds several declarations, the token can belong to a different node in two ways. If it still has a Fn ancestor in the same module chain, the scope is identical, because scope is per module and not per function. If it has no Fn ancestor, or sits under a block or another fn, inline_modules returns None and the resolver refuses. A token in an unrelated module would need that module's fn to start on the test's own start line before the test, which rustfmt never produces. Even then, the pick only selects which module's use must exist. Every spelling in the file must still resolve to the entry's module, and test_call_is_shadowed still applies. So a mis-pick can lose credit but cannot grant it.

Several tests in one inline module. They share that module's use items, which matches Rust name resolution: a module-level use binds for every fn in the module. A per-function binding (a nearer let or a fn-local use) is refused separately, and that case is pinned (nearer let binding).

Pending goldens. The fixtures are blessed. The expected CHANGELOG.md files are the bless records, and cargo xtask goldens check passes on 00d6ed0.


Generated by Claude Code

@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 potential issue.

Devin Review

A one-line module header (`#[cfg(test)] mod tests { use super::entry; #[test] fn t() {`)
put the module's tokens first on the test's line, so the scope lookup
refused a valid import. Match the test fn by name and the line of its
`fn` token, refusing anything but exactly one match.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd

Copy link
Copy Markdown
Member Author

Review of record, addendum for head 18a78a7

The review on 4e146fe still holds for everything outside the changes listed here. Those changes are:

Angle: correctness and false credit of the new test-fn lookup. An independent reviewer agent worked read-only on 18a78a7 and found nothing blocking. It checked five points:

  1. Consumer and producer parse the same FileFacts.source (ra.rs:548, 711).
  2. Both use 1-based \n-counted lines, so CRLF agrees (ra.rs:2818-2840).
  3. Both compare the same raw name.text().
  4. The producer's own ast::Fn always matches, and a second same-name fn on the same line refuses.
  5. Nested and macro-generated fns refuse.

Two items were non-blocking:

Proof on 18a78a7 (local, Linux):

  • cargo xtask precommit: exit 0.
  • cargo test -p ripr --no-fail-fast --test '*': exit 0, all targets.
  • crate_qualified_entry_reach: 41 passed. The new one-line-header positive fails on the previous resolver.
  • verdict-corpus check --language rust: exit 0, 3/662 false verdicts, measured missed credit 147, which equals the ceiling.

Disposition: REVIEW_READY on 18a78a7, pending hosted qualification. In the Rust ceiling queue, #10291 waits for #10196 and #10247 before it takes merge-ready.


Generated by Claude Code

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd

@github-actions github-actions 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.

Verification questions

  • Confirm coverage includes nested modules, grouped imports, one-line headers, wrong-module imports, sibling-only imports, globs, cfg-gated uses, and nearer bindings.
  • Confirm the patch claims a bounded resolver improvement, but the supplied evidence does not prove behavior for every Rust import spelling or general path resolution.

Refuted

  • The changed resolver could introduce an async or worker-memory handoff defect.; refuted because: Production behavior is limited to synchronous Rust AST traversal and scope resolution; no worker, async, GC, detach, transfer, thread handoff, or shared backing store is involved.
  • The claim is broader than the evidence because grouped and aliased import shapes lack oracle coverage.; refuted because: The seeded review already established that grouped imports are covered and that aliases are deliberately refused; the current diff adds scope positives/negatives without claiming general Rust path resolution.
  • The change broadly replaces Rust name resolution and therefore risks unsafe false credit.; refuted because: The implementation is intentionally bounded: it handles relative use paths in inline modules, rejects self/super/crate paths, and preserves glob, cfg, macro, path, and declaration-chain refusals.
  • The claim boundary is limited to the specified in-file relative-import layout; broader Rust path resolution is not established.
  • The ripr failure indicates a source or oracle defect.; refuted because: The failed sensor is not sufficient evidence of a defect; the PR includes focused integration coverage and the packet reports no missing planned evidence beyond the failed sensor. The seeded review of record also reports no open blocking source/oracle finding.
  • This change exposes an OOB, UAF, type-confusion, information-disclosure, DoS, or secret-material exploit primitive.; refuted because: The diff contains no unsafe/native operation, raw buffer, pointer, lifetime, secret source, network/file ingestion, or attacker-controlled allocation path. Inputs are repository Rust source parsed by the existing analyzer and failures conservatively return false.
  • The change broadens the resolver into general Rust path resolution.; refuted because: The implementation is explicitly bounded to relative use resolution and rejects unsupported forms such as globs, cfg-gated uses, macros, function-local uses, and paths outside the documented scope.
  • The changed resolver may mutate or invalidate an active view of a backing buffer.; refuted because: The changed code only reads AST syntax and source text to classify Rust test relations. No mutable buffer or view exists, so invalidation and stale-length behavior are inapplicable.

Evidence gaps

  • The failed ripr sensor leaves the changed analyzer's full corpus behavior without a completed receipt in this packet, although focused integration coverage is present and cargo-test is scheduled late.
  • Model proof intent was rejected by deterministic validation.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants