|
|
@@ -207,36 +207,43 @@ export function scorePathRelevance(filePath: string, query: string): number {
|
|
|
*/
|
|
|
export function isTestFile(filePath: string): boolean {
|
|
|
const lower = filePath.toLowerCase();
|
|
|
- const fileName = path.basename(lower);
|
|
|
-
|
|
|
- // Common test file patterns
|
|
|
- return (
|
|
|
- fileName.startsWith('test_') ||
|
|
|
- fileName.startsWith('test.') ||
|
|
|
- fileName.endsWith('.test.ts') ||
|
|
|
- fileName.endsWith('.test.js') ||
|
|
|
- fileName.endsWith('.test.tsx') ||
|
|
|
- fileName.endsWith('.test.jsx') ||
|
|
|
- fileName.endsWith('.spec.ts') ||
|
|
|
- fileName.endsWith('.spec.js') ||
|
|
|
- fileName.endsWith('_test.go') ||
|
|
|
- fileName.endsWith('_test.py') ||
|
|
|
- fileName.endsWith('_test.rs') ||
|
|
|
- fileName.endsWith('Tests.java') ||
|
|
|
- fileName.endsWith('Test.java') ||
|
|
|
- fileName.endsWith('Tester.java') ||
|
|
|
- fileName.endsWith('TestCase.java') ||
|
|
|
- lower.includes('/tests/') ||
|
|
|
- lower.includes('/test/') ||
|
|
|
- lower.includes('/__tests__/') ||
|
|
|
- lower.includes('/spec/') ||
|
|
|
- lower.includes('/testlib/') ||
|
|
|
+ const fileName = path.basename(filePath); // original case — needed for camelCase boundaries
|
|
|
+ const lowerName = fileName.toLowerCase();
|
|
|
+
|
|
|
+ // --- Filename patterns ---
|
|
|
+ if (
|
|
|
+ lowerName.startsWith('test_') || // python: test_foo.py
|
|
|
+ lowerName.startsWith('test.') ||
|
|
|
+ // separator-delimited: foo_test.go, foo.test.ts, foo-spec.rb, bar_spec.py
|
|
|
+ /[._-](test|tests|spec|specs)\.[a-z0-9]+$/.test(lowerName) ||
|
|
|
+ // CamelCase suffix (Java/Kotlin/Swift/C#/Scala): FooTest.kt, BarTests.swift,
|
|
|
+ // BazSpec.scala, QuxTestCase.java. Capital-led so "latest.kt"/"manifest.kt"
|
|
|
+ // (lowercase "test") are NOT matched.
|
|
|
+ /(?:Test|Tests|TestCase|Tester|Spec|Specs)\.[A-Za-z0-9]+$/.test(fileName)
|
|
|
+ ) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- Directory patterns ---
|
|
|
+ if (
|
|
|
+ lower.includes('/tests/') || lower.includes('/test/') ||
|
|
|
+ lower.includes('/__tests__/') || lower.includes('/spec/') ||
|
|
|
+ lower.includes('/specs/') || lower.includes('/testlib/') ||
|
|
|
lower.includes('/testing/') ||
|
|
|
- // Non-production directories: examples, samples, benchmarks, fixtures, demos.
|
|
|
- // Check both mid-path (/integration/) and start-of-path (integration/) since
|
|
|
- // file paths may be stored as relative paths without a leading slash.
|
|
|
- matchesNonProductionDir(lower)
|
|
|
- );
|
|
|
+ lower.startsWith('test/') || lower.startsWith('tests/') ||
|
|
|
+ lower.startsWith('spec/') || lower.startsWith('specs/') ||
|
|
|
+ // CamelCase test source-set dirs (Kotlin Multiplatform / Gradle / Xcode):
|
|
|
+ // jvmTest/, commonTest/, androidTest/, iosTest/, integrationTest/. Capital-led
|
|
|
+ // so "latest/" / "manifest/" are not matched.
|
|
|
+ /(?:^|\/)[A-Za-z0-9]*(?:Test|Tests|Spec)\//.test(filePath)
|
|
|
+ ) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Non-production directories: examples, samples, benchmarks, fixtures, demos.
|
|
|
+ // Check both mid-path (/integration/) and start-of-path (integration/) since
|
|
|
+ // file paths may be stored as relative paths without a leading slash.
|
|
|
+ return matchesNonProductionDir(lower);
|
|
|
}
|
|
|
|
|
|
/**
|