Skip to content

parser: detect files under __tests__/ as tests#422

Open
Pr1ncePS2002 wants to merge 2 commits intotirth8205:mainfrom
Pr1ncePS2002:feature/tests-dir-recognition
Open

parser: detect files under __tests__/ as tests#422
Pr1ncePS2002 wants to merge 2 commits intotirth8205:mainfrom
Pr1ncePS2002:feature/tests-dir-recognition

Conversation

@Pr1ncePS2002
Copy link
Copy Markdown

Summary

Brings parser.py test-file detection in line with flows.py and refactor.py, which already recognize Jest's __tests__/ directory convention. Without this fix, a file like src/__tests__/UserService.ts was treated as a test by criticality scoring and dead-code analysis but never produced Test nodes or TESTED_BY edges.

What changed

  • code_review_graph/parser.py: add re.compile(r\"[\\/]__tests__[\\/]\") to _TEST_FILE_PATTERNS (same regex already used in flows.py:141 and refactor.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 detection
  • tests/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 passing
  • uv run pytest tests/test_parser.py -k vitest -v — adjacent test detection unchanged (4/4 passing)
  • Verified no new failures vs. main baseline (18 pre-existing Windows-only failures present on both)

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.
Copilot AI review requested due to automatic review settings May 3, 2026 10:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to code_review_graph/parser.py test-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__[\\/]"),
Comment thread tests/test_parser.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

2 participants