fix(parser): detect Rust #[test] attribute and emit Test-kind nodes#503
Open
TimERTy wants to merge 1 commit into
Open
fix(parser): detect Rust #[test] attribute and emit Test-kind nodes#503TimERTy wants to merge 1 commit into
TimERTy wants to merge 1 commit into
Conversation
Rust `#[test]` functions were indexed as `kind="Function"` with `is_test=False`, so `tests_for(...)` returned 0 edges, `detect_changes` flagged every test as untested code, and test-gap counts were inflated. Three compounding gaps: 1. `_extract_function` only collected decorators for Java/Kotlin/C# (via `modifiers` child) and Python (via `decorated_definition` parent). Rust attributes are preceding siblings of `function_item`, not children, so `decorators` was always empty for Rust. 2. `_TEST_ANNOTATIONS` only contained JUnit annotations — no `test`, `tokio::test`, `async_std::test`, `rstest`, or `proptest`. 3. `tests/fixtures/sample_rust.rs` had zero `#[test]` functions and `TestRustParsing` never asserted on Test-kind nodes, so this shipped invisible to the test suite. Fix: - Walk `attribute_item` preceding siblings of `function_item`, strip `#[ ]` / `#![ ]`, append the inner text to `deco_list`. - Extend `_TEST_ANNOTATIONS` with Rust built-in + common framework attributes. - Add `#[test]`, `#[tokio::test]`, and a non-test fn to `sample_rust.rs`; assert Test-kind detection and that non-test fns stay Function-kind in `TestRustParsing`. Closes tirth8205#502
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #502.
Rust
#[test]functions were indexed askind="Function"withis_test=False.tests_for(...)returned 0 edges for any Rust target,detect_changesflagged every test fn as untested, and test-gap counts were inflated by one per real test.Root cause
Three compounding gaps in
code_review_graph/parser.py:_extract_functiondoesn't read Rust attributes. Decorators are collected only for Java/Kotlin/C# (viamodifierschild) and Python (viadecorated_definitionparent). In tree-sitter-rust, attributes are preceding siblings offunction_itemin the enclosing scope, not children — sodecoratorswas always()for Rust._TEST_ANNOTATIONSmissing Rust entries. Only JUnit annotations were listed.#[test]fn.tests/fixtures/sample_rust.rshad zero#[test]functions andTestRustParsingnever asserted onkind == "Test", so the bug shipped invisible to the suite.Changes
code_review_graph/parser.py_extract_function, walkattribute_itempreceding siblings whenlanguage == "rust", strip#[ ]/#![ ]wrapping, and append the inner text todeco_list._TEST_ANNOTATIONSwithtest,tokio::test,async_std::test,rstest,rstest::rstest,proptest.tests/fixtures/sample_rust.rs— add#[cfg(test)] mod tests { ... }with#[test]and#[tokio::test]functions.tests/test_multilang.py::TestRustParsing— three new assertions:test_detects_test_attribute—#[test]fns producekind="Test".test_detects_tokio_test_attribute—#[tokio::test]likewise.test_non_test_functions_not_misclassified— non-annotated fns staykind="Function", guarding against over-broad attribute matching.Test plan
pytest tests/test_multilang.py::TestRustParsing -v— 8/8 pass (5 existing + 3 new).pytest tests/test_multilang.py tests/test_parser.py— 406 passed, no regressions.#[cfg(test)] mod testsinsrc/): before patch, 0 Test-kind nodes; after patch, every#[test]fn correctly tagged Test, every non-annotated fn (incl. afn parse(...)helper inside the test module) stays Function.Notes
#[derive(Debug, Clone)]get added to the decorator list too — they don't match any entry in_TEST_ANNOTATIONS, so no false positives.#[cfg_attr(test, test)]and other conditional wrappers are out of scope; covered by the literal#[test]path that's overwhelmingly common.