Skip to content

fix(mcp): count Rust #[cfg(test)] and tests.rs callers as tests in blast radius (#3265) - #3269

Open
maxmilian wants to merge 1 commit into
colbymchenry:mainfrom
maxmilian:fix/3265-rust-test-blast-radius
Open

maxmilian wants to merge 1 commit into
colbymchenry:mainfrom
maxmilian:fix/3265-rust-test-blast-radius

Conversation

@maxmilian

Copy link
Copy Markdown
Contributor

Fixes #3265.

Problem

In Rust, codegraph_explore's blast radius reported no tests found within 3 caller hops for functions that unit tests call directly. The callers were found; they just weren't counted as tests.

Cause

The blast radius classified callers with isTestFile(path), which only reads the path. Rust unit tests live where no path rule reaches: an inline #[cfg(test)] mod tests { … } next to production code, or a tests.rs (or tests/mod.rs) that the parent loads with #[cfg(test)] mod tests;. The repo already has isTestCode (path + qualified name + inline #[cfg(test)] module) for codegraph implementations, but the blast radius didn't use it, and it didn't know the out-of-line layout either.

Fix

  • isTestCode now takes a source reader instead of one file's source. For Rust it also checks whether the file is a module that its parent (dir.rs, dir/mod.rs, or a crate root in dir/) declares at the top level under a test cfg, following plain mod x; declarations down from such a file. #[cfg(not(test))] and declarations inside inline blocks don't count.
  • The blast radius (direct callers and the 2–3 hop walk) classifies each caller with isTestCode, per caller rather than per file, since an inline test module shares its file with the code it tests. Each file is read at most once per section, and only for Rust callers.
  • codegraph implementations passes the reader through, so a mock in tests.rs is marked as test code too.

One behavior to be aware of: because the blast radius now uses isTestCode rather than isTestFile, a caller in any language whose qualified name has a test scope (the same rule codegraph implementations already applies) is also counted as a test.

Tests

  • explore-blast-radius.test.ts: a Rust crate with both layouts, plus controls (a production caller, a #[cfg(not(test))] module). The two layout cases fail on main (f72c9d2e) and pass here.
  • rust-cfg-test-file.test.ts: unit cases for the parent-declaration reading (tests.rs / tests/mod.rs, mod.rs and crate-root parents, nesting, plain / not(test) / nested declarations).
  • npm run build passes. npm test: the only failures are 30 in installer-targets.test.ts (local installs for bob/droid/kimi/pi/qoder/qwen), with identical assertions on a clean main checkout, so they're pre-existing in this environment.
  • Ran on macOS with Node 22; nothing here is platform-specific, but I haven't run it on Linux or Windows.

🤖 Generated with Claude Code

…ast radius (colbymchenry#3265)

The blast radius told test callers apart by file path alone, so Rust unit
tests -- an inline `#[cfg(test)] mod tests { ... }`, or a `tests.rs` that a
`#[cfg(test)] mod tests;` loads -- read as production callers and the entry
said "no tests found". It now uses the shared test-code reading per caller,
which also learns the out-of-line `tests.rs` / `tests/mod.rs` layout from the
parent module's declaration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maxmilian
maxmilian marked this pull request as ready for review November 11, 2026 01:40

This branch has not been deployed

No deployments
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.

Rust: blast radius reports "no tests found" for unit tests in tests.rs files and #[cfg(test)] modules

1 participant