Skip to content

Commit 4df642d

Browse files
committed
fix(audit): treat *_fixture(s).rs as test paths in is_test_path
Shared test-fixture modules like src/commands/trace/test_fixture.rs are declared `#[cfg(test)] mod test_fixture;` and consumed only by sibling *_tests.rs files, but is_test_path did not recognize them — it matched _test.rs / _tests.rs / test.rs / tests.rs but not *_fixture(s).rs. As a result the fixture's setup code (fs writes, git process spawns to build scenarios) was scanned as production command code and flagged by the thin_command_adapter detector. Extend is_test_path filename detection to cover `*_fixture.rs` and `*_fixtures.rs`. This is precise: test_fixture.rs ends with _fixture.rs and is now excluded, while the existing negative case test_helpers.rs (deliberately NOT a test path) is preserved. Resolves #8335.
1 parent f9ca51b commit 4df642d

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/core/code_audit/walker.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,14 @@ pub fn is_test_path(relative_path: &str) -> bool {
132132
let file_name = relative_path.rsplit('/').next().unwrap_or(relative_path);
133133

134134
// Rust: foo_test.rs, foo_tests.rs, and bare test.rs / tests.rs modules
135-
// (conventionally wired as `#[cfg(test)] mod tests;`).
135+
// (conventionally wired as `#[cfg(test)] mod tests;`). Also cover shared
136+
// test-fixture modules — `*_fixture(s).rs` (e.g. test_fixture.rs) — which are
137+
// conventionally `#[cfg(test)] mod` fixtures consumed by sibling `*_tests.rs`
138+
// files, not production code.
136139
if file_name.ends_with("_test.rs")
137140
|| file_name.ends_with("_tests.rs")
141+
|| file_name.ends_with("_fixture.rs")
142+
|| file_name.ends_with("_fixtures.rs")
138143
|| file_name == "test.rs"
139144
|| file_name == "tests.rs"
140145
{
@@ -219,6 +224,10 @@ mod tests {
219224
// Bare `tests.rs` / `test.rs` modules (conventionally `#[cfg(test)] mod tests;`).
220225
assert!(is_test_path("src/commands/bench/tests.rs"));
221226
assert!(is_test_path("src/core/triage/test.rs"));
227+
// Shared `*_fixture(s).rs` test-support modules (conventionally
228+
// `#[cfg(test)] mod test_fixture;`), consumed by sibling `*_tests.rs`.
229+
assert!(is_test_path("src/commands/trace/test_fixture.rs"));
230+
assert!(is_test_path("src/core/runner/exec_fixtures.rs"));
222231
}
223232

224233
#[test]

0 commit comments

Comments
 (0)