fix(resolution): production code never names a test suite's symbol (#2209)

A test suite is not linked into the program, so a name match from
production code into one is coincidence - but only Strategy 3's receiver
guess (#2171) ruled it out. Now no strategy's name match reaches a symbol
in a test suite from a non-test file: a test source set (`src/test/`,
`jvmTest/`), a `tests/` / `__tests__/` / `spec/` / `e2e/` directory, a
`FooTest.kt` / `test_foo.py` / `foo.test.ts` / `foo_spec.rb` file.
Test-support code a project ships - `testing/`, `fakes/`, `mocks/`, a
`*-test` module - stays in reach, and `…Spec.java` (halo's `IndexSpecs`,
okhttp's `ConnectionSpec`), `post-spec.ts` models and `useTests.ts` hooks
are not test suites.

typeorm -64 (`Record<K, V>` -> a test entity), okhttp -164 (117 sample
`@Override` -> a test's nested `Override`), kotlinx.coroutines -318
(`import kotlinx.coroutines.*` onto one test file's package node), sttp -62,
Exposed -92, halo 0, element-plus -36 (`isClient` -> a test's vueuse mock),
excalidraw -10 (`actionManager.executeAction` -> the test `API` helper),
tokio -30, trpc -36, AutoMapper -37, netbox -22, cats -21, mealie -10,
pytest -8, Alamofire -7; zod, eShop, react-native-reusables unchanged.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-09-30 21:52:10 +00:00
committed by GitHub
parent b8f2bd513e
commit de9f346ceb
3 changed files with 108 additions and 0 deletions
+21
View File
@@ -933,6 +933,24 @@ function isLuaLocal(candidate: Node, context: ResolutionContext): boolean {
const JVM_CALLABLE_KINDS: ReadonlySet<string> = new Set(['method', 'function']);
const JVM_TYPE_KINDS: ReadonlySet<string> = new Set(['class', 'interface', 'enum', 'struct', 'trait', 'type_alias', 'annotation']);
/**
* A test suite — a test source set, a `tests/` / `__tests__/` / `spec/`
* directory, a `FooTest.kt` / `test_foo.py` / `foo.test.ts` file — as opposed
* to test-support code a project ships (`testing/`, `fakes/`, a `*-test`
* module like kotlinx-coroutines-test), which its own code may use.
*/
function isTestSuitePath(filePath: string): boolean {
if (!isTestPath(filePath)) return false;
const lower = filePath.toLowerCase();
const name = lower.slice(lower.lastIndexOf('/') + 1);
const original = filePath.slice(filePath.lastIndexOf('/') + 1);
// (`…Spec.java` alone is no test: halo's `IndexSpecs`, okhttp's `ConnectionSpec`.)
if (name.startsWith('test_') || /[._-](?:test|tests)\.[a-z0-9]+$|[._](?:spec|specs)\.[a-z0-9]+$/.test(name) ||
// CamelCase suffixes where the language names tests so: not `useTests.ts`, a React hook.
/(?:Test|Tests|TestCase)\.(?:java|kt|kts|swift|cs|scala|groovy|m|mm|vb|fs)$/.test(original) || name === 'conftest.py') return true;
return /(?:^|\/)(?:tests?|__tests__|specs?|e2e)\//.test(lower) || /(?:^|\/)[A-Za-z0-9]*(?:Test|Tests|Spec)\//.test(filePath);
}
const MINIFIED_SCRIPTS = new WeakMap<ResolutionContext, Map<string, boolean>>();
/** A minified / bundled script, by name (`jquery.min.js`) or by its text. */
@@ -1295,6 +1313,9 @@ export function isVisibleAcrossFiles(candidate: Node, ref: UnresolvedRef, contex
// A vendored minified bundle's names are mangled: healthchecks' 369 `$(…)`
// (jQuery, a global) went to a one-letter helper inside bootstrap-native.min.js.
if (isMinifiedScript(candidate.filePath, context)) return false;
// A test suite is not linked into the program: typeorm's `Record<K, V>` is
// not a test entity `Record`, tokio's `Output` not a `runtime/tests` type.
if (isTestSuitePath(candidate.filePath) && !isTestPath(ref.filePath)) return false;
const lang = candidate.language as string;
if (lang === 'c' || lang === 'cpp') {
return (