Pre-merge "Tests touched" check ignores in-file Rust test modules #29
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Slipstream/auto_review#29
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
The built-in pre-merge "Tests touched" check (
crates/ar-review/src/pre_merge.rs) reportsmissingon PRs that do add or modify tests, when those tests live inside a#[cfg(test)] mod tests { ... }block in the same.rsfile as the implementation.Root cause
is_test_file(crates/ar-review/src/pre_merge.rs:224) decides "this is a test" purely from the file path:last.contains("test")(filename basename)/tests/,/__tests__/,/spec/directory segments.spec.ts/.spec.jssuffixesThat heuristic matches
crates/foo/tests/bar.rsandtests/integration.rs, but it does not match the project's documented convention (CLAUDE.md, "Development conventions"):For a diff that touches only
crates/ar-review/src/pre_merge.rsand adds tests at the bottom of the same file, the check sees one changed file (pre_merge.rs) which is "source" but not "test" → the check fails even though tests were added.Proposed fix
For
.rsfiles where the path heuristic fails, inspect the diff hunks to see if any added/changed lines are inside (or introduce) a#[cfg(test)]/#[cfg(any(test, ...))]module — i.e. treat the file as having a test-touch when:#[cfg(test)]attribute, or#[test]/#[tokio::test]/#[rstest]etc. attribute, or#[cfg(test)] mod ...block.The simplest cut: scan added lines (
+lines, excluding+++headers) for#[cfg(test)],#[test], or#[tokio::test]/#[rstest]/#[test_case]markers and treat that as a test-touch. False positives (commenting out a test) are tolerable; false negatives (today's behaviour) are the problem.Cross-language note: the same shape exists in Python (test functions inside an implementation file via
pytest) and Go (_test.gois enforced by the toolchain so this is a Rust-specific gap in practice). Scoping the fix to.rsfiles is fine for now.Acceptance
#[test]functions inside an existing#[cfg(test)] mod testsblock insrc/foo.rsproduces[x] Tests touchedrather than[ ] Tests touched — missing.src/foo.rswith no tests (no#[cfg(test)]/#[test]marker added) still fails the check.crates/ar-review/src/pre_merge.rsthat feeds a synthetic diff containing only+ #[test]\n+ fn ...lines on asrc/*.rspath and asserts the check passes.