parser: detect files under __tests__/ as tests#422
Open
Pr1ncePS2002 wants to merge 2 commits intotirth8205:mainfrom
Open
parser: detect files under __tests__/ as tests#422Pr1ncePS2002 wants to merge 2 commits intotirth8205:mainfrom
Pr1ncePS2002 wants to merge 2 commits intotirth8205:mainfrom
Conversation
flows.py and refactor.py already recognize the Jest convention of placing tests under a __tests__/ directory, but parser.py did not. This meant a file like src/__tests__/UserService.ts was treated as a test for criticality scoring and dead-code analysis but never produced Test nodes or TESTED_BY edges. Add the same regex used in flows.py and refactor.py to _TEST_FILE_PATTERNS so the three modules agree.
There was a problem hiding this comment.
Pull request overview
This PR updates the parser’s test-file detection so files located under Jest-style __tests__/ directories are treated as test files, bringing parser.py into line with the existing behavior in flow and refactor analysis. It also adds regression coverage and a fixture intended to verify that such files produce Test nodes and TESTED_BY edges.
Changes:
- Added a
__tests__/path pattern tocode_review_graph/parser.pytest-file detection. - Added a new TypeScript fixture located under
tests/fixtures/__tests__/. - Added parser regression tests for direct test-file classification and parser output from
__tests__/files.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
code_review_graph/parser.py |
Extends parser-side test-file path matching to recognize Jest __tests__/ directories. |
tests/test_parser.py |
Adds regression tests for _is_test_file() and for parser output from a file under __tests__/. |
tests/fixtures/__tests__/UserService.ts |
Adds a Vitest-style fixture used by the new parser regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| re.compile(r".*\.spec\.[jt]sx?$"), | ||
| re.compile(r".*_test\.go$"), | ||
| re.compile(r"tests?/"), | ||
| re.compile(r"[\\/]__tests__[\\/]"), |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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
Brings
parser.pytest-file detection in line withflows.pyandrefactor.py, which already recognize Jest's__tests__/directory convention. Without this fix, a file likesrc/__tests__/UserService.tswas treated as a test by criticality scoring and dead-code analysis but never producedTestnodes orTESTED_BYedges.What changed
code_review_graph/parser.py: addre.compile(r\"[\\/]__tests__[\\/]\")to_TEST_FILE_PATTERNS(same regex already used inflows.py:141andrefactor.py:203)tests/fixtures/__tests__/UserService.ts: new fixture under a__tests__/directory with no.test./.spec.marker in the filename — only the directory should trigger detectiontests/test_parser.py: two regression tests (test_jest_tests_dir_detected_as_test_file,test_jest_tests_dir_produces_test_nodes)Risk
Minimal. Adding a pattern only adds detection — it cannot make a previously-detected test stop being detected. The regex is already in production use elsewhere in the codebase.
Test plan
uv run pytest tests/test_parser.py -k jest_tests_dir -v— 2/2 passinguv run pytest tests/test_parser.py -k vitest -v— adjacent test detection unchanged (4/4 passing)mainbaseline (18 pre-existing Windows-only failures present on both)