Skip to content

Handle discovery of test-only modules correctly - #41

Merged
Calsign merged 1 commit into
mainfrom
calsignlabs/revup/main/test-only-modules
Aug 24, 2026
Merged

Handle discovery of test-only modules correctly#41
Calsign merged 1 commit into
mainfrom
calsignlabs/revup/main/test-only-modules

Conversation

@Calsign

@Calsign Calsign commented Aug 24, 2026

Copy link
Copy Markdown
Owner

This is a valid way to declare that a module is test-only:

  #[cfg(test)]
  mod foobar;

Previously gazelle_rust ignored the #[cfg(test)] on the module
and treated everything inside it as normal dependencies. This is
only relevant for generate_from_cargo because we don't do module
discovery in pure_bazel mode.

This PR changes gazelle_rust_parser to return test-only extern
mods separately and updates the language plugin to handle
test-only mods correctly. Beyond propagating the test-only status
of each module, we also need to walk modules in two passes because
a module could be reachable through normal and test-only paths, in
which case it should be treated as normal.

Credit to @wolfd for discovering this issue and proposing the
initial fix.

This change was made with the assistance of LLM tooling.

Topic: test-only-modules

@Calsign

Calsign commented Aug 24, 2026

Copy link
Copy Markdown
Owner Author

Reviews in this chain:
#41 Handle discovery of test-only modules correctly

@Calsign

Calsign commented Aug 24, 2026

Copy link
Copy Markdown
Owner Author
# head base diff date summary
0 6b3aadac bed49c78 diff Aug 24 13:26 PM 20 files changed, 232 insertions(+), 70 deletions(-)
1 bef228a6 bed49c78 diff Aug 24 13:27 PM 0 files changed

This is a valid way to declare that a module is test-only:
```
  #[cfg(test)]
  mod foobar;
```

Previously gazelle_rust ignored the `#[cfg(test)]` on the module
and treated everything inside it as normal dependencies. This is
only relevant for `generate_from_cargo` because we don't do module
discovery in `pure_bazel` mode.

This PR changes gazelle_rust_parser to return test-only extern
mods separately and updates the language plugin to handle
test-only mods correctly. Beyond propagating the test-only status
of each module, we also need to walk modules in two passes because
a module could be reachable through normal and test-only paths, in
which case it should be treated as normal.

Credit to @wolfd for discovering this issue and proposing the
initial fix.

This change was made with the assistance of LLM tooling.

Topic: test-only-modules
@Calsign
Calsign force-pushed the calsignlabs/revup/main/test-only-modules branch from 6b3aada to bef228a Compare August 24, 2026 20:27
@Calsign
Calsign merged commit 747482b into main Aug 24, 2026
1 check passed
@Calsign
Calsign deleted the calsignlabs/revup/main/test-only-modules branch August 24, 2026 21:18
jason-rl pushed a commit to runloopai/gazelle_rust that referenced this pull request Sep 2, 2026
…t-only-modules

Handle discovery of test-only modules correctly
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.

1 participant