fix(search): a __tests__/ folder at the repository root counts as a test
A file in a __tests__/ folder at the top of a repository is now treated as a test, as one below src/ or any other folder already was.
Before, isTestPath matched /__tests__/ only with a directory above it, so __tests__/foo.ts was taken for production code while src/__tests__/foo.ts was not. Until upstream #2557 (merged in #499) this did not matter for the dominant-file and explore filters, which matched __tests__/ at the start of a path with their own pattern; #2557 moved them onto isTestFile and dropped that match. cubic flagged the gap on #499. The fix adds lower.startsWith('__tests__/') beside the existing tests/, spec/ and e2e/ start-of-path checks.
Verification, on head 2994ecc4d4d32f38053e82765552277da6a84023:
- The new case in
__tests__/is-test-file.test.tsfails without the change (isTestFile('__tests__/foo.ts')was false) and passes with it, including a negative case (my__tests__/foo.tsstays production). tsc --noEmitandnpm run check:agent-docspass; the 25 test files that mentionisTestFile,isTestPath,scorePathRelevanceor__tests__/pass (576 passed, 1 skipped).- The kernel has its own test-path function (
is_test_path), unchanged here; this PR covers the TypeScript side only.
README rows checked: none mention test-path detection, so none changed. The changelog entry is under [Unreleased] and says to re-index projects with a top-level __tests__/ folder, because index-time synthesizers also read this function (unmeasured).
Summary by cubic
A file in a __tests__/ folder at the repository root now counts as a test, matching the behavior of such folders below src/ or any other directory.
Previously isTestPath matched /__tests__/ only when preceded by a directory, so __tests__/foo.ts was treated as production code. The fix adds lower.startsWith('__tests__/') beside the existing tests/, spec/, and e2e/ checks.
- Adds a test case covering the new behavior and the negative case where
my__tests__/foo.tsstays production. - Notes in the CHANGELOG that projects with a top-level
__tests__/folder should be re-indexed, since index-time synthesizers also read this function.
Summary by CodeRabbit
- Bug Fixes
- Root-level
__tests__/files are now recognized as tests, matching nested test directories. They are excluded from production-code search and ranking and from main-routes file selection. - Re-index projects with a top-level
__tests__/folder for the updated classification to take effect.
- Root-level