Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Classify test-only source files through one shared predicate (#5172)

Nick Gomez26574f7c88d0
diff --git a/lint-plugins/ok-rules/README.md b/lint-plugins/ok-rules/README.md
index d6a31c4a6..d58dc09a3 100644
--- a/lint-plugins/ok-rules/README.md
+++ b/lint-plugins/ok-rules/README.md
@@ -666,6 +666,22 @@ The rule does NOT catch:
Rule: [`lint-plugins/ok-rules/rules/no-sentinel-signal-target.mjs`](rules/no-sentinel-signal-target.mjs). Fixture: [`lint-plugins/ok-rules/__fixtures__/no-sentinel-signal-target.fixture.tsx`](__fixtures__/no-sentinel-signal-target.fixture.tsx). Test: [`lint-plugins/ok-rules/tests/no-sentinel-signal-target.uncached.test.mjs`](tests/no-sentinel-signal-target.uncached.test.mjs). See [PRECEDENTS.md #42](../../PRECEDENTS.md#custom-lint-enforcement-precedent-42) for the custom-rule convention.
+### `no-hand-rolled-test-file-suffix`
+
+Scanners classify test-only TypeScript through [`isTestOnlySourceFile`](../../test-support/test-only-source-file.mjs). Its [predicate tests](../../test-support/test-only-source-file.uncached.test.mjs) pin the supported naming families and direct Node import. Local suffix checks omitted helpers and type checks and caused false production-code findings. This section is the canonical scanner rule; keep it and the implementation aligned when either changes.
+
+The default predicate includes Vitest tests, test helpers, type checks and Playwright files. Pass `vitest`, `helper`, `typecheck` or `playwright` when selecting one kind. A scanner selecting runnable tests must retain its runner and extension limits; test-only does not mean runnable by Vitest. The `.uncached.test.ts` form is already covered by `.test.ts`. TSX variants share their TS family.
+
+The rule flags literal suffix checks with `endsWith` or `includes`, test-kind infix checks with `includes`, and direct literal suffix regexes used by `test`, `exec`, `match` or `search`. It recognizes static templates and computed method names. It leaves extension checks, full basenames, glob declarations, source-text extraction, regex replacement, and mixed JavaScript/TypeScript runner-discovery regexes alone. It does not trace aliases, computed suffixes, hoisted regexes or arbitrary equivalent regex expressions.
+
+Included: `**/*.ts`, `**/*.tsx`, `**/*.mts`, `**/*.cts`, `**/*.js`, `**/*.jsx`, `**/*.mjs`, `**/*.cjs`. Excluded: `test-support/test-only-source-file.mjs`, `lint-plugins/no-comments/portability.test.mjs`.
+
+The shared module owns the definition. The portability test inventories only the sibling dependency-free `.mjs` implementation modules; it does not classify TypeScript, and its test-file exclusion remains local. Scanners that deliberately inspect test helpers retain that scope rather than inheriting the production default.
+
+The fixture pairs 15 violations with adjacent negatives. The self-test also plants a check under `scripts/` and invokes the real lint configuration, verifies the shared-predicate replacement passes, and removes the planted file. The rule and its self-test run in the existing lint and uncached test jobs.
+
+Rule: [`no-hand-rolled-test-file-suffix.mjs`](rules/no-hand-rolled-test-file-suffix.mjs). Fixture: [`no-hand-rolled-test-file-suffix.fixture.tsx`](__fixtures__/no-hand-rolled-test-file-suffix.fixture.tsx). Test: [`no-hand-rolled-test-file-suffix.uncached.test.mjs`](tests/no-hand-rolled-test-file-suffix.uncached.test.mjs).
+
## Suppression
Inline `// oxlint-disable-next-line` comments silence individual diagnostics. The form names the plugin, the rule and the reason:
diff --git a/lint-plugins/ok-rules/__fixtures__/no-hand-rolled-test-file-suffix.fixture.tsx b/lint-plugins/ok-rules/__fixtures__/no-hand-rolled-test-file-suffix.fixture.tsx
new file mode 100644
index 000000000..43609d24c
--- /dev/null
+++ b/lint-plugins/ok-rules/__fixtures__/no-hand-rolled-test-file-suffix.fixture.tsx
@@ -0,0 +1,35 @@
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
+
+declare const path: string;
+declare const suffix: string;
+
+export const p01 = path.endsWith('.test.ts');
+export const p02 = !path.endsWith('.test.tsx');
+export const p03 = path.endsWith('.test-helper.ts');
+export const p04 = path.endsWith('.type-tests.ts');
+// biome-ignore lint/complexity/useLiteralKeys: the fixture exercises a computed method name
+export const p05 = path['endsWith'](`.test.ts`);
+export const p06 = path?.endsWith('.test.ts');
+export const p07 = path.includes('.test.');
+export const p08 = path.includes('.test-helper.');
+export const p09 = path.includes('.type-tests.');
+export const p10 = /\.test\.tsx?$/.test(path);
+export const p11 = /\.type-tests\.ts$/.exec(path);
+export const p12 = path.match(/\.test-helper\.ts$/);
+export const p13 = path.search(/\.test\.(?:ts|tsx)$/);
+export const p14 = path.endsWith('.e2e.ts');
+export const p15 = path.includes('.e2e.');
+
+export const n01 = isTestOnlySourceFile(path);
+export const n02 = isTestOnlySourceFile(path, 'vitest');
+export const n03 = path.endsWith('.ts');
+export const n04 = path.endsWith('.d.ts');
+export const n05 = path.endsWith('named.test.ts');
+export const n06 = path.includes('tests/');
+export const n07 = path.endsWith(suffix);
+export const n08 = /\.tsx?$/.test(path);
+export const n09 = path.replace(/\.test\.ts$/, '');
+export const n10 = "path.endsWith('.test.ts')";
+export const n11 = /named\.test\.ts$/.test(path);
+export const n12 = path.endsWith('.test.ts.bak');
+export const n13 = /\.test\.[cm]?[jt]sx?$/.test(path);
diff --git a/lint-plugins/ok-rules/__fixtures__/oxlint.fixtures.json b/lint-plugins/ok-rules/__fixtures__/oxlint.fixtures.json
index 80d86c37e..8e65d2025 100644
--- a/lint-plugins/ok-rules/__fixtures__/oxlint.fixtures.json
+++ b/lint-plugins/ok-rules/__fixtures__/oxlint.fixtures.json
@@ -7,6 +7,7 @@
"ok/no-blind-agent-host-fanout": "error",
"ok/no-demoted-dialog-confirm": "error",
"ok/no-hand-rolled-branch-validation": "error",
+ "ok/no-hand-rolled-test-file-suffix": "error",
"ok/no-hand-rolled-spinner": "error",
"ok/no-inline-tolerance-class": "error",
"ok/no-loosely-typed-webcontents-ipc": "error",
diff --git a/lint-plugins/ok-rules/index.mjs b/lint-plugins/ok-rules/index.mjs
index 94054fd0e..302a04d90 100644
--- a/lint-plugins/ok-rules/index.mjs
+++ b/lint-plugins/ok-rules/index.mjs
@@ -7,6 +7,7 @@ import { noBlindAgentHostFanout } from './rules/no-blind-agent-host-fanout.mjs';
import { noDemotedDialogConfirm } from './rules/no-demoted-dialog-confirm.mjs';
import { noHandRolledBranchValidation } from './rules/no-hand-rolled-branch-validation.mjs';
import { noHandRolledSpinner } from './rules/no-hand-rolled-spinner.mjs';
+import { noHandRolledTestFileSuffix } from './rules/no-hand-rolled-test-file-suffix.mjs';
import { noInlineToleranceClass } from './rules/no-inline-tolerance-class.mjs';
import { noLooselyTypedWebcontentsIpc } from './rules/no-loosely-typed-webcontents-ipc.mjs';
import { noPhysicalDirectionUtility } from './rules/no-physical-direction-utility.mjs';
@@ -38,6 +39,7 @@ const declared = {
'no-blind-agent-host-fanout': noBlindAgentHostFanout,
'no-demoted-dialog-confirm': noDemotedDialogConfirm,
'no-hand-rolled-branch-validation': noHandRolledBranchValidation,
+ 'no-hand-rolled-test-file-suffix': noHandRolledTestFileSuffix,
'no-hand-rolled-spinner': noHandRolledSpinner,
'no-inline-tolerance-class': noInlineToleranceClass,
'no-loosely-typed-webcontents-ipc': noLooselyTypedWebcontentsIpc,
diff --git a/lint-plugins/ok-rules/rules/no-hand-rolled-test-file-suffix.mjs b/lint-plugins/ok-rules/rules/no-hand-rolled-test-file-suffix.mjs
new file mode 100644
index 000000000..3c6618902
--- /dev/null
+++ b/lint-plugins/ok-rules/rules/no-hand-rolled-test-file-suffix.mjs
@@ -0,0 +1,60 @@
+import { TEST_ONLY_SOURCE_SUFFIXES } from '../../../test-support/test-only-source-file.mjs';
+import { docsUrl } from '../docs.mjs';
+
+const URL = docsUrl('no-hand-rolled-test-file-suffix');
+const MESSAGE = `Hand-rolled test-file classification can mistake helpers and type checks for production. Use isTestOnlySourceFile from test-support/test-only-source-file.mjs; select a kind when discovering runnable tests. See ${URL}`;
+const SUFFIXES = new Set(TEST_ONLY_SOURCE_SUFFIXES);
+const INFIXES = new Set(
+ TEST_ONLY_SOURCE_SUFFIXES.map((suffix) => suffix.slice(0, suffix.lastIndexOf('.') + 1)),
+);
+
+function stringValue(node) {
+ if (node?.type === 'Literal' && typeof node.value === 'string') return node.value;
+ if (node?.type === 'TemplateLiteral' && node.expressions.length === 0)
+ return node.quasis[0]?.value.cooked;
+ return undefined;
+}
+
+function isSuffixRegex(node) {
+ if (node?.type !== 'Literal' || !node.regex) return false;
+ const pattern = node.regex.pattern;
+ if (!pattern.endsWith('$')) return false;
+ const suffix = pattern
+ .slice(0, -1)
+ .replaceAll('\\.', '.')
+ .replace(/\((?:\?:)?ts\|tsx\)/g, 'tsx?')
+ .replace(/\.tsx\?$/, '.ts');
+ return SUFFIXES.has(suffix);
+}
+
+export const noHandRolledTestFileSuffix = {
+ meta: {
+ type: 'problem',
+ docs: {
+ description: 'Use the canonical test-only source-file predicate in scanners.',
+ url: URL,
+ },
+ },
+ create(context) {
+ return {
+ CallExpression(node) {
+ const callee = node.callee;
+ if (callee?.type !== 'MemberExpression') return;
+ const method = callee.computed ? stringValue(callee.property) : callee.property?.name;
+ const argument = node.arguments[0];
+ if (method === 'endsWith' || method === 'includes') {
+ const value = stringValue(argument);
+ if (SUFFIXES.has(value) || (method === 'includes' && INFIXES.has(value)))
+ context.report({ node, message: MESSAGE });
+ return;
+ }
+ if (
+ ((method === 'test' || method === 'exec') && isSuffixRegex(callee.object)) ||
+ ((method === 'match' || method === 'search') && isSuffixRegex(argument))
+ ) {
+ context.report({ node, message: MESSAGE });
+ }
+ },
+ };
+ },
+};
diff --git a/lint-plugins/ok-rules/scope.mjs b/lint-plugins/ok-rules/scope.mjs
index 1a1244930..f45c227d1 100644
--- a/lint-plugins/ok-rules/scope.mjs
+++ b/lint-plugins/ok-rules/scope.mjs
@@ -23,6 +23,19 @@ export const UNSCOPED_RULES = new Set([
]);
export const RULE_SCOPES = {
+ 'no-hand-rolled-test-file-suffix': [
+ '**/*.ts',
+ '**/*.tsx',
+ '**/*.mts',
+ '**/*.cts',
+ '**/*.js',
+ '**/*.jsx',
+ '**/*.mjs',
+ '**/*.cjs',
+ '!test-support/test-only-source-file.mjs',
+ '!lint-plugins/no-comments/portability.test.mjs',
+ 'lint-plugins/ok-rules/__fixtures__/no-hand-rolled-test-file-suffix.fixture.tsx',
+ ],
'no-raw-route-hash-construction': [
'packages/app/src/**/*.ts',
'packages/app/src/**/*.tsx',
diff --git a/lint-plugins/ok-rules/tests/no-hand-rolled-test-file-suffix.uncached.test.mjs b/lint-plugins/ok-rules/tests/no-hand-rolled-test-file-suffix.uncached.test.mjs
new file mode 100644
index 000000000..e1d06a452
--- /dev/null
+++ b/lint-plugins/ok-rules/tests/no-hand-rolled-test-file-suffix.uncached.test.mjs
@@ -0,0 +1,100 @@
+import { spawnSync } from 'node:child_process';
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { describe, expect, test } from 'vitest';
+import {
+ readEnabledRuleIds,
+ readRegisteredRuleNames,
+ readRuleScope,
+} from '../../../test-support/read-ok-rules-config.test-helper.ts';
+
+const ROOT = fileURLToPath(new URL('../../..', import.meta.url));
+const RULE = 'no-hand-rolled-test-file-suffix';
+const FIXTURE = `lint-plugins/ok-rules/__fixtures__/${RULE}.fixture.tsx`;
+const README = 'lint-plugins/ok-rules/README.md';
+
+function lint(args) {
+ const result = spawnSync(join(ROOT, 'node_modules/.bin/oxlint'), ['-f', 'json', ...args], {
+ cwd: ROOT,
+ encoding: 'utf8',
+ windowsHide: true,
+ maxBuffer: 64 * 1024 * 1024,
+ });
+ expect(result.error).toBeUndefined();
+ expect(typeof result.status).toBe('number');
+ const output = JSON.parse(result.stdout);
+ expect(output.number_of_files).toBe(1);
+ expect(output.number_of_rules).toBeGreaterThan(0);
+ return {
+ status: result.status,
+ diagnostics: output.diagnostics.filter((diagnostic) => diagnostic.code === `ok(${RULE})`),
+ };
+}
+
+describe('shared test-file predicate enforcement', () => {
+ test('fires on all 15 positives and none of the adjacent negatives', () => {
+ const source = readFileSync(join(ROOT, FIXTURE), 'utf8').split('\n');
+ const expectedLines = source.flatMap((line, index) =>
+ /^export const p\d+ =/.test(line) ? [index + 1] : [],
+ );
+ expect(expectedLines).toHaveLength(15);
+ const { status, diagnostics } = lint([
+ '-c',
+ 'lint-plugins/ok-rules/__fixtures__/oxlint.fixtures.json',
+ FIXTURE,
+ ]);
+ expect(status).toBe(1);
+ expect(diagnostics).toHaveLength(15);
+ expect(diagnostics.map((diagnostic) => diagnostic.labels[0].span.line)).toEqual(expectedLines);
+ for (const diagnostic of diagnostics) {
+ expect(diagnostic.message).toContain('Use isTestOnlySourceFile');
+ expect(diagnostic.message).toContain(`${README}#${RULE}`);
+ }
+ });
+
+ test('the real lint configuration rejects a planted check and accepts the shared predicate', () => {
+ const dir = mkdtempSync(join(ROOT, 'scripts/test-file-predicate-'));
+ const file = join(dir, 'probe.ts');
+ try {
+ writeFileSync(file, "export const probe = (path: string) => path.endsWith('.test.ts');\n");
+ const positive = lint(['--max-warnings', '0', file]);
+ expect(positive.status).toBe(1);
+ expect(positive.diagnostics).toHaveLength(1);
+ writeFileSync(
+ file,
+ "import { isTestOnlySourceFile } from '../../test-support/test-only-source-file.mjs';\nexport const probe = (path: string) => isTestOnlySourceFile(path);\n",
+ );
+ const negative = lint(['--max-warnings', '0', file]);
+ expect(negative.status).toBe(0);
+ expect(negative.diagnostics).toEqual([]);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+
+ test('registration, narrow exemptions, and both prose links remain live', async () => {
+ expect(await readRegisteredRuleNames(ROOT)).toContain(RULE);
+ expect(await readEnabledRuleIds(ROOT)).toContain(`ok/${RULE}`);
+ expect(readRuleScope(ROOT, RULE)).toEqual([
+ '**/*.ts',
+ '**/*.tsx',
+ '**/*.mts',
+ '**/*.cts',
+ '**/*.js',
+ '**/*.jsx',
+ '**/*.mjs',
+ '**/*.cjs',
+ '!test-support/test-only-source-file.mjs',
+ '!lint-plugins/no-comments/portability.test.mjs',
+ 'lint-plugins/ok-rules/__fixtures__/no-hand-rolled-test-file-suffix.fixture.tsx',
+ ]);
+ const prose = readFileSync(join(ROOT, README), 'utf8');
+ expect(prose).toContain(`### \`${RULE}\``);
+ expect(prose).toContain(`rules/${RULE}.mjs`);
+ expect(prose).toContain('Scanners classify test-only TypeScript through');
+ const excluded = lint(['--max-warnings', '0', 'lint-plugins/no-comments/portability.test.mjs']);
+ expect(excluded.status).toBe(0);
+ expect(excluded.diagnostics).toEqual([]);
+ });
+});
diff --git a/oxlint.config.ts b/oxlint.config.ts
index 9aa60d0b6..b52de61ab 100644
--- a/oxlint.config.ts
+++ b/oxlint.config.ts
@@ -55,6 +55,7 @@ export default defineConfig({
'ok/no-blind-agent-host-fanout': 'error',
'ok/no-demoted-dialog-confirm': 'error',
'ok/no-hand-rolled-branch-validation': 'error',
+ 'ok/no-hand-rolled-test-file-suffix': 'error',
'ok/no-hand-rolled-spinner': 'error',
'ok/no-inline-tolerance-class': 'error',
'ok/no-loosely-typed-webcontents-ipc': 'error',
diff --git a/packages/app/src/components/handoff/dispatch-single-entry-point.test.ts b/packages/app/src/components/handoff/dispatch-single-entry-point.test.ts
index aa0da1214..d92215352 100644
--- a/packages/app/src/components/handoff/dispatch-single-entry-point.test.ts
+++ b/packages/app/src/components/handoff/dispatch-single-entry-point.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join, relative } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../../test-support/test-only-source-file.mjs';
const SRC_DIR = new URL('../..', import.meta.url).pathname;
@@ -29,7 +30,7 @@ function listSourceFilesRecursive(dir: string): string[] {
out.push(...listSourceFilesRecursive(full));
} else {
if (!entry.name.endsWith('.tsx') && !entry.name.endsWith('.ts')) continue;
- if (entry.name.endsWith('.test.ts') || entry.name.endsWith('.test.tsx')) continue;
+ if (isTestOnlySourceFile(entry.name)) continue;
out.push(full);
}
}
@@ -68,7 +69,7 @@ describe('AC9: single outbound dispatch entry point — every src directory exce
const dir = join(SRC_DIR, 'components/handoff');
expect(statSync(dir).isDirectory()).toBe(true);
const files = readdirSync(dir).filter(
- (n) => (n.endsWith('.ts') || n.endsWith('.tsx')) && !n.includes('.test.'),
+ (n) => (n.endsWith('.ts') || n.endsWith('.tsx')) && !isTestOnlySourceFile(n),
);
const importFound = files.some((name) => {
const text = readFileSync(join(dir, name), 'utf-8');
@@ -81,7 +82,7 @@ describe('AC9: single outbound dispatch entry point — every src directory exce
const dir = join(SRC_DIR, 'lib/handoff');
expect(statSync(dir).isDirectory()).toBe(true);
const files = readdirSync(dir).filter(
- (n) => (n.endsWith('.ts') || n.endsWith('.tsx')) && !n.includes('.test.'),
+ (n) => (n.endsWith('.ts') || n.endsWith('.tsx')) && !isTestOnlySourceFile(n),
);
expect(files.length).toBeGreaterThan(0);
});
diff --git a/packages/app/src/editor/source-polish/engine-invariants.test.ts b/packages/app/src/editor/source-polish/engine-invariants.test.ts
index 19188ae2b..1fa2129a4 100644
--- a/packages/app/src/editor/source-polish/engine-invariants.test.ts
+++ b/packages/app/src/editor/source-polish/engine-invariants.test.ts
@@ -1,12 +1,13 @@
import { readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../../test-support/test-only-source-file.mjs';
const SOURCE_POLISH_DIR = import.meta.dirname;
describe('engine invariants (D2 LOCKED primitive-set enforcement)', () => {
const tsFiles = readdirSync(SOURCE_POLISH_DIR).filter(
- (f) => (f.endsWith('.ts') || f.endsWith('.tsx')) && !f.endsWith('.test.ts'),
+ (f) => (f.endsWith('.ts') || f.endsWith('.tsx')) && !isTestOnlySourceFile(f),
);
test('no Decoration.replace in source-polish submodule', () => {
diff --git a/packages/app/tests/integration/conflict-resolver-deletion-coverage.test.ts b/packages/app/tests/integration/conflict-resolver-deletion-coverage.test.ts
index 15555d9e7..d7dededbb 100644
--- a/packages/app/tests/integration/conflict-resolver-deletion-coverage.test.ts
+++ b/packages/app/tests/integration/conflict-resolver-deletion-coverage.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const APP_SRC = join(import.meta.dir, '..', '..', 'src');
const RESOLVER_PATH = join(APP_SRC, 'components', 'ConflictResolver.tsx');
@@ -12,12 +13,7 @@ function* walkTsx(dir: string): Generator<string> {
const stat = statSync(full);
if (stat.isDirectory()) {
yield* walkTsx(full);
- } else if (
- (entry.endsWith('.ts') || entry.endsWith('.tsx')) &&
- !entry.endsWith('.test.ts') &&
- !entry.endsWith('.test.tsx') &&
- !entry.endsWith('.dom.test.tsx')
- ) {
+ } else if ((entry.endsWith('.ts') || entry.endsWith('.tsx')) && !isTestOnlySourceFile(entry)) {
yield full;
}
}
diff --git a/packages/app/tests/integration/e2e-stop-rules.test.ts b/packages/app/tests/integration/e2e-stop-rules.test.ts
index 956de79ff..86bb69369 100644
--- a/packages/app/tests/integration/e2e-stop-rules.test.ts
+++ b/packages/app/tests/integration/e2e-stop-rules.test.ts
@@ -1,3 +1,4 @@
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
/**
* Selection-halo chrome comes from plugin state and never from the `:has()` cascade, and this
* suite is the mechanical guard for that ban (precedent #34).
@@ -78,7 +79,7 @@ function listAppSrcTsFiles(): FileLines[] {
}
if (!name.isFile()) continue;
if (!name.name.endsWith('.ts') && !name.name.endsWith('.tsx')) continue;
- if (name.name.endsWith('.test.ts') || name.name.endsWith('.test.tsx')) continue;
+ if (isTestOnlySourceFile(name.name)) continue;
if (name.name.endsWith('.spec.ts') || name.name.endsWith('.spec.tsx')) continue;
const source = readFileSync(abs, 'utf-8');
out.push({
@@ -500,7 +501,7 @@ function collectMatches(
describe('E2E STOP rule — zero allowlist', () => {
const e2eTsFiles = listE2eTsFiles();
- const e2eFiles = e2eTsFiles.filter((file) => file.path.endsWith('.e2e.ts'));
+ const e2eFiles = e2eTsFiles.filter((file) => isTestOnlySourceFile(file.path, 'playwright'));
test('there are E2E files to check (sanity)', () => {
expect(
diff --git a/packages/app/tests/integration/exhaustiveness-coverage.test.ts b/packages/app/tests/integration/exhaustiveness-coverage.test.ts
index f631a8c31..09ab54f91 100644
--- a/packages/app/tests/integration/exhaustiveness-coverage.test.ts
+++ b/packages/app/tests/integration/exhaustiveness-coverage.test.ts
@@ -10,6 +10,7 @@ import {
SyntaxKind,
} from 'ts-morph';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const PROBLEM_TYPE_LABELS: ReadonlySet<string> = new Set(ProblemTypeSchema.options);
@@ -58,8 +59,7 @@ const SCAN_ROOTS = [
function isExcludedPath(absPath: string): boolean {
if (absPath.endsWith('.d.ts')) return true;
- if (/\.test\.tsx?$/.test(absPath)) return true;
- if (/\.type-tests\.tsx?$/.test(absPath)) return true;
+ if (isTestOnlySourceFile(absPath)) return true;
if (absPath.includes('/node_modules/')) return true;
if (absPath.includes('/dist/')) return true;
return false;
diff --git a/packages/app/tests/integration/fullscreen-overlay-safe-area-coverage.test.ts b/packages/app/tests/integration/fullscreen-overlay-safe-area-coverage.test.ts
index cec0a26e5..4febfe553 100644
--- a/packages/app/tests/integration/fullscreen-overlay-safe-area-coverage.test.ts
+++ b/packages/app/tests/integration/fullscreen-overlay-safe-area-coverage.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const APP_SRC = join(import.meta.dir, '..', '..', 'src');
const REPO_RELATIVE_PREFIX = 'packages/app/src';
@@ -79,11 +80,7 @@ function* walkSourceFiles(dir: string): Generator<string> {
const stat = statSync(full);
if (stat.isDirectory()) {
yield* walkSourceFiles(full);
- } else if (
- entry.endsWith('.tsx') &&
- !entry.endsWith('.test.tsx') &&
- !entry.endsWith('.dom.test.tsx')
- ) {
+ } else if (entry.endsWith('.tsx') && !isTestOnlySourceFile(entry)) {
yield full;
}
}
diff --git a/packages/app/tests/integration/hook-timeout-stop-rules.test.ts b/packages/app/tests/integration/hook-timeout-stop-rules.test.ts
index 895eb4d5c..217ddd0a0 100644
--- a/packages/app/tests/integration/hook-timeout-stop-rules.test.ts
+++ b/packages/app/tests/integration/hook-timeout-stop-rules.test.ts
@@ -2,6 +2,7 @@ import { type Dirent, readdirSync, readFileSync } from 'node:fs';
import { join, relative } from 'node:path';
import { ts } from 'ts-morph';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const REPO_ROOT = join(import.meta.dirname, '..', '..', '..', '..');
const SCANNED_DIRS = [import.meta.dirname, join(import.meta.dirname, '..', 'conversion')];
@@ -27,7 +28,11 @@ function listScannedTestFiles(): ScannedFile[] {
walk(abs);
continue;
}
- if (!entry.isFile() || !entry.name.endsWith('.test.ts')) continue;
+ if (
+ !entry.isFile() ||
+ !(isTestOnlySourceFile(entry.name, 'vitest') && entry.name.endsWith('.ts'))
+ )
+ continue;
out.push({ path: relative(REPO_ROOT, abs), source: readFileSync(abs, 'utf-8') });
}
}
diff --git a/packages/app/tests/integration/ipc-exhaustiveness-coverage.test.ts b/packages/app/tests/integration/ipc-exhaustiveness-coverage.test.ts
index b09d45568..6a25959be 100644
--- a/packages/app/tests/integration/ipc-exhaustiveness-coverage.test.ts
+++ b/packages/app/tests/integration/ipc-exhaustiveness-coverage.test.ts
@@ -10,6 +10,7 @@ import {
SyntaxKind,
} from 'ts-morph';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const REPO_ROOT = resolve(import.meta.dirname, '../../../..');
const SCAN_ROOTS = [join(REPO_ROOT, 'packages/core/src'), join(REPO_ROOT, 'packages/app/src')];
@@ -54,8 +55,7 @@ const OPT_OUT_MARKER = /\/\/\s*ipc-exhaustiveness-check:\s*opt-out\s*—/;
function isExcludedPath(absPath: string): boolean {
if (absPath.endsWith('.d.ts')) return true;
- if (/\.test\.tsx?$/.test(absPath)) return true;
- if (/\.type-tests\.tsx?$/.test(absPath)) return true;
+ if (isTestOnlySourceFile(absPath)) return true;
if (absPath.includes('/node_modules/')) return true;
if (absPath.includes('/dist/')) return true;
return false;
diff --git a/packages/app/tests/integration/ipc-log-coverage.test.ts b/packages/app/tests/integration/ipc-log-coverage.test.ts
index 9ec0f267e..a24390856 100644
--- a/packages/app/tests/integration/ipc-log-coverage.test.ts
+++ b/packages/app/tests/integration/ipc-log-coverage.test.ts
@@ -9,6 +9,7 @@ import {
SyntaxKind,
} from 'ts-morph';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const REPO_ROOT = resolve(import.meta.dirname, '../../../..');
const MAIN_ROOT = join(REPO_ROOT, 'packages/desktop/src/main');
@@ -17,7 +18,7 @@ export const IPC_LOG_ADJACENCY_MAX_STATEMENTS = 5;
function isExcludedPath(absPath: string): boolean {
if (absPath.endsWith('.d.ts')) return true;
- if (/\.test\.tsx?$/.test(absPath)) return true;
+ if (isTestOnlySourceFile(absPath)) return true;
if (absPath.includes('/node_modules/')) return true;
if (absPath.includes('/dist/')) return true;
if (absPath.endsWith('/ipc-log.ts')) return true;
diff --git a/packages/app/tests/integration/loopback-bind-discipline.test.ts b/packages/app/tests/integration/loopback-bind-discipline.test.ts
index ef4f61881..50c9c624f 100644
--- a/packages/app/tests/integration/loopback-bind-discipline.test.ts
+++ b/packages/app/tests/integration/loopback-bind-discipline.test.ts
@@ -2,6 +2,7 @@ import { readdirSync, readFileSync } from 'node:fs';
import { basename, dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PACKAGE_ROOT = join(__dirname, '..', '..');
@@ -85,7 +86,7 @@ describe('loopback bind discipline (app test sources)', () => {
expect(files.length).toBeGreaterThan(0);
expect(files.some((f) => f.path.endsWith('integration/test-harness.ts'))).toBe(true);
expect(files.some((f) => f.path.endsWith('_helpers/server-process.ts'))).toBe(true);
- expect(files.some((f) => f.path.endsWith('.e2e.ts'))).toBe(true);
+ expect(files.some((f) => isTestOnlySourceFile(f.path, 'playwright'))).toBe(true);
});
test('every .listen( call binds an explicit loopback host literal', () => {
diff --git a/packages/app/tests/integration/no-sync-set-enabled-references.test.ts b/packages/app/tests/integration/no-sync-set-enabled-references.test.ts
index 2e53feaa0..35629c9fa 100644
--- a/packages/app/tests/integration/no-sync-set-enabled-references.test.ts
+++ b/packages/app/tests/integration/no-sync-set-enabled-references.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const APP_SRC = join(import.meta.dir, '..', '..', 'src');
@@ -16,8 +17,7 @@ function* walkSourceFiles(dir: string): Generator<string> {
entry.endsWith('.tsx') ||
entry.endsWith('.js') ||
entry.endsWith('.mjs')) &&
- !entry.endsWith('.test.ts') &&
- !entry.endsWith('.test.tsx')
+ !isTestOnlySourceFile(entry)
) {
yield full;
}
diff --git a/packages/app/tests/integration/origin-undoability-sweep.test.ts b/packages/app/tests/integration/origin-undoability-sweep.test.ts
index 07450204f..2bc65ec82 100644
--- a/packages/app/tests/integration/origin-undoability-sweep.test.ts
+++ b/packages/app/tests/integration/origin-undoability-sweep.test.ts
@@ -1,6 +1,7 @@
import { globSync, readdirSync, readFileSync, statSync } from 'node:fs';
import { basename, join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
type UndoClass =
| 'agent-session-um'
@@ -157,9 +158,7 @@ const CONTRACT_TEST_FILE = /[\w./-]+\.test\.tsx?\b/g;
function isScannedSource(fileName: string): boolean {
if (!fileName.endsWith('.ts') && !fileName.endsWith('.tsx')) return false;
return !(
- fileName.endsWith('.test.ts') ||
- fileName.endsWith('.test.tsx') ||
- fileName.endsWith('.test-helper.ts') ||
+ isTestOnlySourceFile(fileName) ||
fileName.endsWith('-test-harness.ts') ||
fileName.endsWith('.d.ts')
);
diff --git a/packages/app/tests/lint-plugins/ok-rules-vocabulary.test.ts b/packages/app/tests/lint-plugins/ok-rules-vocabulary.test.ts
index 3a4542260..65e9e69be 100644
--- a/packages/app/tests/lint-plugins/ok-rules-vocabulary.test.ts
+++ b/packages/app/tests/lint-plugins/ok-rules-vocabulary.test.ts
@@ -1,3 +1,4 @@
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
/**
* The rule corpus precedent #42 names carries no vocabulary from the retired GritQL plugin or
* the Bun runner; the corpus is `CORPUS_DIRS` and `TEST_DIRS`, read from the constants.
@@ -148,7 +149,7 @@ function testDirFiles(): string[] {
const abs = join(REPO_ROOT, dir);
if (!existsSync(abs)) continue;
for (const entry of readdirSync(abs)) {
- if (!entry.endsWith('.test.ts')) continue;
+ if (!(isTestOnlySourceFile(entry, 'vitest') && entry.endsWith('.ts'))) continue;
if (stems.has(entry.replace(/\.test\.ts$/, ''))) found.push(join(abs, entry));
}
}
diff --git a/packages/app/tests/meta/e2e-ci-membership.test.ts b/packages/app/tests/meta/e2e-ci-membership.test.ts
index ab669bb29..e5d55aef8 100644
--- a/packages/app/tests/meta/e2e-ci-membership.test.ts
+++ b/packages/app/tests/meta/e2e-ci-membership.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
import { E2E_CI_EXCLUSIONS } from '../stress/e2e-ci-ledger';
const APP_ROOT = join(import.meta.dirname, '..', '..');
@@ -12,13 +13,13 @@ const LEDGER_HINT =
function listStressE2eFiles(): string[] {
return readdirSync(STRESS_DIR)
- .filter((name) => name.endsWith('.e2e.ts'))
+ .filter((name) => isTestOnlySourceFile(name, 'playwright'))
.sort();
}
function nestedE2ePaths(relPaths: readonly string[]): string[] {
return relPaths
- .filter((p) => p.endsWith('.e2e.ts') && /[/\\]/.test(p))
+ .filter((p) => isTestOnlySourceFile(p, 'playwright') && /[/\\]/.test(p))
.map((p) => p.replace(/\\/g, '/'))
.sort();
}
@@ -26,7 +27,9 @@ function nestedE2ePaths(relPaths: readonly string[]): string[] {
function parseEnumeratedFiles(script: string): string[] {
return script
.split(/\s+/)
- .filter((token) => token.startsWith('tests/stress/') && token.endsWith('.e2e.ts'))
+ .filter(
+ (token) => token.startsWith('tests/stress/') && isTestOnlySourceFile(token, 'playwright'),
+ )
.map((token) => token.slice('tests/stress/'.length));
}
diff --git a/packages/app/tests/meta/getfileindex-allfiles-coverage.test.ts b/packages/app/tests/meta/getfileindex-allfiles-coverage.test.ts
index 457c7e3e9..fd23ffbbd 100644
--- a/packages/app/tests/meta/getfileindex-allfiles-coverage.test.ts
+++ b/packages/app/tests/meta/getfileindex-allfiles-coverage.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const SERVER_SRC_ROOT = join(import.meta.dirname, '../../../server/src');
const API_EXT_PATH = join(SERVER_SRC_ROOT, 'api-extension.ts');
@@ -63,7 +64,7 @@ function listProductionTsFiles(dir: string): string[] {
const st = statSync(full);
if (st.isDirectory()) {
out.push(...listProductionTsFiles(full));
- } else if (st.isFile() && entry.endsWith('.ts') && !entry.endsWith('.test.ts')) {
+ } else if (st.isFile() && entry.endsWith('.ts') && !isTestOnlySourceFile(entry)) {
out.push(full);
}
}
diff --git a/packages/app/tests/meta/native-route-unit-reachability.test.ts b/packages/app/tests/meta/native-route-unit-reachability.test.ts
index 3d23093b6..239398ccd 100644
--- a/packages/app/tests/meta/native-route-unit-reachability.test.ts
+++ b/packages/app/tests/meta/native-route-unit-reachability.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
import {
extractRouteHandlerNames,
listNativeRouteFiles,
@@ -43,7 +44,8 @@ function listServerTestFiles(): string[] {
const full = join(dir, entry);
const st = statSync(full);
if (st.isDirectory()) walk(full);
- else if (st.isFile() && entry.endsWith('.test.ts')) out.push(full);
+ else if (st.isFile() && isTestOnlySourceFile(entry, 'vitest') && entry.endsWith('.ts'))
+ out.push(full);
}
};
walk(SERVER_SRC_ROOT);
diff --git a/packages/app/tests/meta/showok-caller-coverage.test.ts b/packages/app/tests/meta/showok-caller-coverage.test.ts
index 36532b1c0..102a81e0e 100644
--- a/packages/app/tests/meta/showok-caller-coverage.test.ts
+++ b/packages/app/tests/meta/showok-caller-coverage.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const SERVER_SRC_ROOT = join(import.meta.dirname, '../../../server/src');
const CLI_SRC_ROOT = join(import.meta.dirname, '../../../cli/src');
@@ -16,7 +17,7 @@ function listProductionTsFiles(dir: string): string[] {
const st = statSync(full);
if (st.isDirectory()) {
out.push(...listProductionTsFiles(full));
- } else if (st.isFile() && entry.endsWith('.ts') && !entry.endsWith('.test.ts')) {
+ } else if (st.isFile() && entry.endsWith('.ts') && !isTestOnlySourceFile(entry)) {
out.push(full);
}
}
diff --git a/packages/app/tests/meta/substrate-vocabulary-drift.test.ts b/packages/app/tests/meta/substrate-vocabulary-drift.test.ts
index 0a506c449..27b00029b 100644
--- a/packages/app/tests/meta/substrate-vocabulary-drift.test.ts
+++ b/packages/app/tests/meta/substrate-vocabulary-drift.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, type Stats, statSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
import { getRegisteredDescriptors } from '../../src/editor/registry/index.ts';
const APP_ROOT = resolve(import.meta.dirname, '../..');
@@ -28,9 +29,7 @@ function* walkTestFiles(dir: string): Generator<string> {
yield* walkTestFiles(full);
} else if (
entry.isFile() &&
- (entry.name.endsWith('.test.ts') ||
- entry.name.endsWith('.test.tsx') ||
- entry.name.endsWith('.e2e.ts'))
+ (isTestOnlySourceFile(entry.name, 'vitest') || isTestOnlySourceFile(entry.name, 'playwright'))
) {
yield full;
}
diff --git a/packages/app/tests/meta/syncscope-caller-coverage.test.ts b/packages/app/tests/meta/syncscope-caller-coverage.test.ts
index 052718233..acf4dab81 100644
--- a/packages/app/tests/meta/syncscope-caller-coverage.test.ts
+++ b/packages/app/tests/meta/syncscope-caller-coverage.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const SERVER_SRC_ROOT = join(import.meta.dirname, '../../../server/src');
const CLI_SRC_ROOT = join(import.meta.dirname, '../../../cli/src');
@@ -18,10 +19,7 @@ function listProductionTsFiles(dir: string): string[] {
} else if (
st.isFile() &&
(entry.endsWith('.ts') || entry.endsWith('.tsx')) &&
- !entry.endsWith('.test.ts') &&
- !entry.endsWith('.test.tsx') &&
- !entry.endsWith('.test-helper.ts') &&
- !entry.endsWith('.type-tests.ts')
+ !isTestOnlySourceFile(entry)
) {
out.push(full);
}
diff --git a/packages/app/tests/native-route-files.test-helper.ts b/packages/app/tests/native-route-files.test-helper.ts
index fbc759600..6cadd4f6e 100644
--- a/packages/app/tests/native-route-files.test-helper.ts
+++ b/packages/app/tests/native-route-files.test-helper.ts
@@ -1,5 +1,6 @@
import { readdirSync } from 'node:fs';
import { join } from 'node:path';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
export const HANDLER_RUN_END_NEEDLES = [
'\n const routes:',
@@ -13,7 +14,7 @@ export function extractRouteHandlerNames(text: string): string[] {
export function listNativeRouteFiles(serverSrcRoot: string): string[] {
return readdirSync(join(serverSrcRoot, 'http'))
- .filter((entry) => entry.endsWith('-routes.ts') && !entry.endsWith('.test.ts'))
+ .filter((entry) => entry.endsWith('-routes.ts') && !isTestOnlySourceFile(entry))
.sort()
.map((entry) => `http/${entry}`);
}
diff --git a/packages/cli/src/loopback-bind-discipline.test.ts b/packages/cli/src/loopback-bind-discipline.test.ts
index 693463d74..ad80ccdab 100644
--- a/packages/cli/src/loopback-bind-discipline.test.ts
+++ b/packages/cli/src/loopback-bind-discipline.test.ts
@@ -2,6 +2,7 @@ import { readdirSync, readFileSync } from 'node:fs';
import { basename, dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PACKAGE_ROOT = join(__dirname, '..');
@@ -23,7 +24,11 @@ function listScannedTestFiles(): FileLines[] {
walk(abs);
continue;
}
- if (!entry.isFile() || !entry.name.endsWith('.test.ts')) continue;
+ if (
+ !entry.isFile() ||
+ !(isTestOnlySourceFile(entry.name, 'vitest') && entry.name.endsWith('.ts'))
+ )
+ continue;
if (entry.name === SELF_BASENAME) continue;
out.push({
path: relative(PACKAGE_ROOT, abs),
diff --git a/packages/core/src/config/auto-sync-mode-confinement.test.ts b/packages/core/src/config/auto-sync-mode-confinement.test.ts
index e35498eb4..b749fec41 100644
--- a/packages/core/src/config/auto-sync-mode-confinement.test.ts
+++ b/packages/core/src/config/auto-sync-mode-confinement.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join, relative, resolve } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../test-support/test-only-source-file.mjs';
const ALLOWED_READERS = new Set([
'packages/core/src/config/auto-sync-mode.ts',
@@ -32,7 +33,7 @@ function* sourceFiles(dir: string): Generator<string> {
yield* sourceFiles(full);
} else if (
(entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) &&
- !entry.name.includes('.test.') &&
+ !isTestOnlySourceFile(entry.name) &&
!entry.name.includes('test-helper')
) {
yield full;
diff --git a/packages/desktop/tests/smoke/_helpers/launch-desktop.test.ts b/packages/desktop/tests/smoke/_helpers/launch-desktop.test.ts
index 58216d8ee..d7ed28418 100644
--- a/packages/desktop/tests/smoke/_helpers/launch-desktop.test.ts
+++ b/packages/desktop/tests/smoke/_helpers/launch-desktop.test.ts
@@ -9,6 +9,7 @@ import {
resolveServerRuntimeConfig,
} from '@inkeep/open-knowledge-core';
import { afterEach, describe, expect, it, vi } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../../test-support/test-only-source-file.mjs';
import { SPAWN_STARTUP_DEADLINE_MS } from '../../../src/shared/boot-narration.ts';
import {
DEFAULT_LAUNCH_TIMEOUT_MS,
@@ -204,7 +205,7 @@ describe("desktopLaunchOptions — a packaged launch bounds its detached server'
describe('no smoke file references __dirname without defining it', () => {
const SMOKE_DIR = join(dirname(fileURLToPath(import.meta.url)), '..');
const files = readdirSync(SMOKE_DIR)
- .filter((file) => file.endsWith('.e2e.ts'))
+ .filter((file) => isTestOnlySourceFile(file, 'playwright'))
.map((file) => ({ file, src: readFileSync(join(SMOKE_DIR, file), 'utf8') }))
.filter(({ src }) => src.includes('__dirname'));
diff --git a/packages/desktop/tests/smoke/_helpers/no-unbounded-app-close.test.ts b/packages/desktop/tests/smoke/_helpers/no-unbounded-app-close.test.ts
index 2ab697246..26fdf9d2a 100644
--- a/packages/desktop/tests/smoke/_helpers/no-unbounded-app-close.test.ts
+++ b/packages/desktop/tests/smoke/_helpers/no-unbounded-app-close.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../../test-support/test-only-source-file.mjs';
import { stripCommentsAndStrings } from './parse-timeouts';
const SMOKE_DIR = join(__dirname, '..');
@@ -21,7 +22,7 @@ interface SmokeFile {
function listSmokeFiles(): SmokeFile[] {
return readdirSync(SMOKE_DIR)
- .filter((f) => f.endsWith('.e2e.ts'))
+ .filter((f) => isTestOnlySourceFile(f, 'playwright'))
.sort()
.map((f) => ({ abs: join(SMOKE_DIR, f), rel: f }));
}
diff --git a/packages/desktop/tests/smoke/_helpers/parse-timeouts.test.ts b/packages/desktop/tests/smoke/_helpers/parse-timeouts.test.ts
index a9da0a290..0ae821d36 100644
--- a/packages/desktop/tests/smoke/_helpers/parse-timeouts.test.ts
+++ b/packages/desktop/tests/smoke/_helpers/parse-timeouts.test.ts
@@ -2,6 +2,7 @@ import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'n
import { tmpdir } from 'node:os';
import { basename, join } from 'node:path';
import { afterAll, afterEach, assert, beforeAll, describe, expect, test, vi } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../../test-support/test-only-source-file.mjs';
import { ONE_LAUNCH_AND_ITS_READINESS_VERDICT_MS, PACKAGED_APP_ENV } from './launch-desktop';
import { BOOT_LOG_POLL_MS, readinessGiveUpBoundMs } from './launch-readiness';
import {
@@ -696,7 +697,9 @@ describe('a test title holding another quote kind is audited once, and whole', (
test('every smoke test whose title holds another quote kind is audited', () => {
const quoteTitled: DeclaredTest[] = [];
- for (const name of readdirSync(SMOKE_SPEC_DIR).filter((file) => file.endsWith('.e2e.ts'))) {
+ for (const name of readdirSync(SMOKE_SPEC_DIR).filter((file) =>
+ isTestOnlySourceFile(file, 'playwright'),
+ )) {
const file = join(SMOKE_SPEC_DIR, name);
const src = readFileSync(file, 'utf8');
const stripped = stripCommentsAndStrings(src);
diff --git a/packages/desktop/tests/smoke/_helpers/platform-gate.test.ts b/packages/desktop/tests/smoke/_helpers/platform-gate.test.ts
index bc8953bd6..46dc152ad 100644
--- a/packages/desktop/tests/smoke/_helpers/platform-gate.test.ts
+++ b/packages/desktop/tests/smoke/_helpers/platform-gate.test.ts
@@ -3,6 +3,7 @@ import { tmpdir } from 'node:os';
import { join, sep } from 'node:path';
import { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../../../test-support/test-only-source-file.mjs';
import { isTerminalPlatform } from '../../../src/shared/terminal-platform.ts';
import { SPEC_PLATFORM_GATES, SUPPORTED_PLATFORMS } from './platform-gate';
@@ -197,7 +198,7 @@ function deriveGates(
function listSpecFiles(dir: string): string[] {
return readdirSync(dir, { recursive: true })
.map((entry) => String(entry).split(sep).join('/'))
- .filter((name) => name.endsWith('.e2e.ts'))
+ .filter((name) => isTestOnlySourceFile(name, 'playwright'))
.sort();
}
diff --git a/packages/server/src/agent-write-spine-files.test-helper.ts b/packages/server/src/agent-write-spine-files.test-helper.ts
index 959dfa114..f5d4f7267 100644
--- a/packages/server/src/agent-write-spine-files.test-helper.ts
+++ b/packages/server/src/agent-write-spine-files.test-helper.ts
@@ -1,5 +1,6 @@
import { readdirSync, readFileSync } from 'node:fs';
import { join, relative } from 'node:path';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
export function listAgentWriteSpineFiles(serverSrcRoot: string): string[] {
return readdirSync(serverSrcRoot, { recursive: true, withFileTypes: true })
@@ -7,10 +8,7 @@ export function listAgentWriteSpineFiles(serverSrcRoot: string): string[] {
(entry) =>
entry.isFile() &&
(entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) &&
- !entry.name.endsWith('.test.ts') &&
- !entry.name.endsWith('.test.tsx') &&
- !entry.name.endsWith('.test-helper.ts') &&
- !entry.name.endsWith('.test-helper.tsx'),
+ !isTestOnlySourceFile(entry.name),
)
.map((entry) => join(entry.parentPath, entry.name))
.filter((path) => readFileSync(path, 'utf8').includes('applyAgentMarkdownWrite'))
diff --git a/packages/server/src/bridge-loss-suppression.test.ts b/packages/server/src/bridge-loss-suppression.test.ts
index 011101c29..be3bf7683 100644
--- a/packages/server/src/bridge-loss-suppression.test.ts
+++ b/packages/server/src/bridge-loss-suppression.test.ts
@@ -3,6 +3,7 @@ import { tmpdir } from 'node:os';
import { dirname, join, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import { afterEach, describe, expect, it } from 'vitest';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
import {
PAIRED_INTAKE_DETECTION,
pairedIntakeDetectionMode,
@@ -13,12 +14,7 @@ import {
const SRC_DIR = dirname(fileURLToPath(import.meta.url));
function isProductionSource(name: string): boolean {
- return (
- name.endsWith('.ts') &&
- !name.endsWith('.test.ts') &&
- !name.endsWith('.test-helper.ts') &&
- !name.endsWith('.d.ts')
- );
+ return name.endsWith('.ts') && !isTestOnlySourceFile(name) && !name.endsWith('.d.ts');
}
function stripCommentLines(text: string): string {
diff --git a/packages/server/src/child-process-windows-hide.test.ts b/packages/server/src/child-process-windows-hide.test.ts
index 18219bd8a..fbda01066 100644
--- a/packages/server/src/child-process-windows-hide.test.ts
+++ b/packages/server/src/child-process-windows-hide.test.ts
@@ -9,6 +9,7 @@ import {
type SourceFile,
} from 'ts-morph';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
import { withHiddenWindowsConsole } from './child-process-windows-hide.ts';
const SERVER_SRC_DIR = import.meta.dir;
@@ -25,11 +26,7 @@ function collectSourceFiles(dir: string): string[] {
out.push(...collectSourceFiles(abs));
continue;
}
- if (
- entry.name.endsWith('.ts') &&
- !entry.name.endsWith('.test.ts') &&
- !entry.name.endsWith('.test-helper.ts')
- ) {
+ if (entry.name.endsWith('.ts') && !isTestOnlySourceFile(entry.name)) {
out.push(abs);
}
}
diff --git a/packages/server/src/console-discipline.test.ts b/packages/server/src/console-discipline.test.ts
index 2d764391c..13e920b1f 100644
--- a/packages/server/src/console-discipline.test.ts
+++ b/packages/server/src/console-discipline.test.ts
@@ -2,6 +2,7 @@ import { readdirSync, readFileSync } from 'node:fs';
import { basename, dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const SCAN_ROOT = __dirname;
@@ -50,7 +51,7 @@ function listScannedSourceFiles(): FileLines[] {
continue;
}
if (!entry.isFile() || !entry.name.endsWith('.ts')) continue;
- if (entry.name.endsWith('.test.ts') || entry.name.endsWith('.test-helper.ts')) continue;
+ if (isTestOnlySourceFile(entry.name)) continue;
if (entry.name === SELF_BASENAME) continue;
out.push({
path: relative(SCAN_ROOT, abs),
diff --git a/packages/server/src/error-log-discipline.uncached.test.ts b/packages/server/src/error-log-discipline.uncached.test.ts
index 351329d84..ffe489252 100644
--- a/packages/server/src/error-log-discipline.uncached.test.ts
+++ b/packages/server/src/error-log-discipline.uncached.test.ts
@@ -2,6 +2,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
import { basename, dirname, join, relative, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -33,7 +34,7 @@ function listScannedSourceFiles(): FileLines[] {
continue;
}
if (!entry.isFile() || !entry.name.endsWith('.ts')) continue;
- if (entry.name.endsWith('.test.ts') || entry.name.endsWith('.test-helper.ts')) continue;
+ if (isTestOnlySourceFile(entry.name)) continue;
if (entry.name === SELF_BASENAME) continue;
out.push({
path: relative(WORKSPACE_ROOT, abs),
diff --git a/packages/server/src/loopback-bind-discipline.test.ts b/packages/server/src/loopback-bind-discipline.test.ts
index 95f2a8689..2c1961240 100644
--- a/packages/server/src/loopback-bind-discipline.test.ts
+++ b/packages/server/src/loopback-bind-discipline.test.ts
@@ -2,6 +2,7 @@ import { readdirSync, readFileSync } from 'node:fs';
import { basename, dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PACKAGE_ROOT = join(__dirname, '..');
@@ -23,7 +24,11 @@ function listScannedTestFiles(): FileLines[] {
walk(abs);
continue;
}
- if (!entry.isFile() || !entry.name.endsWith('.test.ts')) continue;
+ if (
+ !entry.isFile() ||
+ !(isTestOnlySourceFile(entry.name, 'vitest') && entry.name.endsWith('.ts'))
+ )
+ continue;
if (entry.name === SELF_BASENAME) continue;
out.push({
path: relative(PACKAGE_ROOT, abs),
diff --git a/packages/server/src/normalize-write-sink-gate.uncached.test.ts b/packages/server/src/normalize-write-sink-gate.uncached.test.ts
index daf8291fa..f729d790c 100644
--- a/packages/server/src/normalize-write-sink-gate.uncached.test.ts
+++ b/packages/server/src/normalize-write-sink-gate.uncached.test.ts
@@ -8,6 +8,7 @@ import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';
import { describe, expect, it } from 'vitest';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
const here = dirname(fileURLToPath(import.meta.url));
const packagesDir = join(here, '..', '..');
@@ -96,8 +97,8 @@ function analyzeSourceFile(rel: string, sf: SourceFile): Violation[] {
function isScannableFile(name: string): boolean {
if (!name.endsWith('.ts') && !name.endsWith('.tsx')) return false;
if (name.endsWith('.d.ts')) return false;
- if (name.includes('.test-helper.')) return false;
- if (/\.(test|spec|e2e)\./.test(name)) return false;
+ if (isTestOnlySourceFile(name)) return false;
+ if (/\.spec\./.test(name)) return false;
return true;
}
diff --git a/packages/server/src/paired-write-enforcement.test.ts b/packages/server/src/paired-write-enforcement.test.ts
index a6191afc8..19de0da5a 100644
--- a/packages/server/src/paired-write-enforcement.test.ts
+++ b/packages/server/src/paired-write-enforcement.test.ts
@@ -1,3 +1,4 @@
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
/** Structural enforcement of the paired-write contract (precedent #38). */
import { join, relative } from 'node:path';
@@ -70,8 +71,7 @@ function loadServerSourceFiles(): ReadonlyArray<readonly [string, SourceFile]> {
const out: Array<readonly [string, SourceFile]> = [];
const glob = new Bun.Glob('**/*.ts');
for (const rel of glob.scanSync({ cwd: SERVER_SRC_DIR, absolute: false, onlyFiles: true })) {
- if (rel.endsWith('.test.ts') || rel.endsWith('.test-helper.ts') || rel.endsWith('.d.ts'))
- continue;
+ if (isTestOnlySourceFile(rel) || rel.endsWith('.d.ts')) continue;
const abs = join(SERVER_SRC_DIR, rel);
const sf = project.addSourceFileAtPath(abs);
out.push([abs, sf] as const);
diff --git a/packages/server/src/producer-origin-gate.uncached.test.ts b/packages/server/src/producer-origin-gate.uncached.test.ts
index 2cecccccd..eb4235e1e 100644
--- a/packages/server/src/producer-origin-gate.uncached.test.ts
+++ b/packages/server/src/producer-origin-gate.uncached.test.ts
@@ -3,6 +3,7 @@ import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';
import { describe, expect, it } from 'vitest';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
const here = dirname(fileURLToPath(import.meta.url));
const packagesDir = join(here, '..', '..');
@@ -179,8 +180,8 @@ function analyzeSourceFile(rel: string, sf: SourceFile): Violation[] {
function isScannableFile(name: string): boolean {
if (!name.endsWith('.ts') && !name.endsWith('.tsx')) return false;
if (name.endsWith('.d.ts')) return false;
- if (name.includes('.test-helper.')) return false;
- if (/\.(test|spec|e2e)\./.test(name)) return false;
+ if (isTestOnlySourceFile(name)) return false;
+ if (/\.spec\./.test(name)) return false;
return true;
}
diff --git a/packages/server/src/symlink-leaf-guard-enforcement.test.ts b/packages/server/src/symlink-leaf-guard-enforcement.test.ts
index ada1d966f..b4eafe5f5 100644
--- a/packages/server/src/symlink-leaf-guard-enforcement.test.ts
+++ b/packages/server/src/symlink-leaf-guard-enforcement.test.ts
@@ -11,6 +11,7 @@ import { tmpdir } from 'node:os';
import { dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from '../../../test-support/test-only-source-file.mjs';
import { checkSymlinkLeaf } from './fs-safety.ts';
const SERVER_SRC = dirname(fileURLToPath(import.meta.url));
@@ -57,12 +58,7 @@ function listServerSourceFiles(root: string): string[] {
const abs = join(root, entry.name);
if (entry.isDirectory()) {
out.push(...listServerSourceFiles(abs));
- } else if (
- entry.isFile() &&
- entry.name.endsWith('.ts') &&
- !entry.name.endsWith('.test.ts') &&
- !entry.name.endsWith('.test-helper.ts')
- ) {
+ } else if (entry.isFile() && entry.name.endsWith('.ts') && !isTestOnlySourceFile(entry.name)) {
out.push(abs);
}
}
diff --git a/scripts/check-server-test-inputs.mjs b/scripts/check-server-test-inputs.mjs
index 050050283..38984ff26 100644
--- a/scripts/check-server-test-inputs.mjs
+++ b/scripts/check-server-test-inputs.mjs
@@ -2,6 +2,7 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join, relative, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
+import { isTestOnlySourceFile } from '../test-support/test-only-source-file.mjs';
import { isUncachedTestFile } from '../test-support/uncached-tier.ts';
const OK_ROOT = fileURLToPath(new URL('..', import.meta.url));
@@ -25,7 +26,12 @@ function walkTestFiles(dir, out = []) {
if (entry.name === 'node_modules' || entry.name === 'dist') continue;
const full = join(dir, entry.name);
if (entry.isDirectory()) walkTestFiles(full, out);
- else if (entry.name.endsWith('.test.ts') && !isUncachedTestFile(entry.name)) out.push(full);
+ else if (
+ isTestOnlySourceFile(entry.name, 'vitest') &&
+ entry.name.endsWith('.ts') &&
+ !isUncachedTestFile(entry.name)
+ )
+ out.push(full);
}
return out;
}
diff --git a/test-support/test-only-source-file.d.mts b/test-support/test-only-source-file.d.mts
new file mode 100644
index 000000000..f42dbecfe
--- /dev/null
+++ b/test-support/test-only-source-file.d.mts
@@ -0,0 +1,6 @@
+export const TEST_ONLY_SOURCE_SUFFIXES: readonly string[];
+
+export function isTestOnlySourceFile(
+ path: string,
+ kind?: 'vitest' | 'helper' | 'typecheck' | 'playwright',
+): boolean;
diff --git a/test-support/test-only-source-file.mjs b/test-support/test-only-source-file.mjs
new file mode 100644
index 000000000..6b0c10053
--- /dev/null
+++ b/test-support/test-only-source-file.mjs
@@ -0,0 +1,13 @@
+const SUFFIXES_BY_KIND = {
+ vitest: ['.test.ts', '.test.tsx'],
+ helper: ['.test-helper.ts', '.test-helper.tsx'],
+ typecheck: ['.type-tests.ts', '.type-tests.tsx'],
+ playwright: ['.e2e.ts'],
+};
+
+export const TEST_ONLY_SOURCE_SUFFIXES = Object.freeze(Object.values(SUFFIXES_BY_KIND).flat());
+
+export function isTestOnlySourceFile(path, kind) {
+ const suffixes = kind === undefined ? TEST_ONLY_SOURCE_SUFFIXES : SUFFIXES_BY_KIND[kind];
+ return suffixes.some((suffix) => path.endsWith(suffix));
+}
diff --git a/test-support/test-only-source-file.uncached.test.mjs b/test-support/test-only-source-file.uncached.test.mjs
new file mode 100644
index 000000000..ce00eb3fb
--- /dev/null
+++ b/test-support/test-only-source-file.uncached.test.mjs
@@ -0,0 +1,63 @@
+import { spawnSync } from 'node:child_process';
+import { fileURLToPath } from 'node:url';
+import { describe, expect, test } from 'vitest';
+import { isTestOnlySourceFile } from './test-only-source-file.mjs';
+
+const ROOT = fileURLToPath(new URL('../', import.meta.url));
+
+describe('test-only source files', () => {
+ test.each([
+ 'module.test.ts',
+ 'module.test.tsx',
+ 'module.dom.test.tsx',
+ 'module.uncached.test.ts',
+ 'module.test-helper.ts',
+ 'module.test-helper.tsx',
+ 'module.type-tests.ts',
+ 'module.type-tests.tsx',
+ 'module.e2e.ts',
+ '/project/src/module.type-tests.ts',
+ 'C:\\project\\src\\module.test-helper.ts',
+ ])('recognizes %s', (path) => {
+ expect(isTestOnlySourceFile(path)).toBe(true);
+ });
+
+ test.each([
+ '',
+ 'module.ts',
+ 'module.tsx',
+ 'module.d.ts',
+ 'module.spec.ts',
+ 'module.test.ts.bak',
+ 'module.type-tests.ts/production.ts',
+ 'module.test-helper.ts/production.ts',
+ 'module.test.backup.ts',
+ 'module-test-helper.ts',
+ ])('keeps %s outside the test-only set', (path) => {
+ expect(isTestOnlySourceFile(path)).toBe(false);
+ });
+
+ test('runner selection does not admit helpers or type checks', () => {
+ expect(isTestOnlySourceFile('module.uncached.test.ts', 'vitest')).toBe(true);
+ expect(isTestOnlySourceFile('module.test.tsx', 'vitest')).toBe(true);
+ expect(isTestOnlySourceFile('module.test-helper.ts', 'vitest')).toBe(false);
+ expect(isTestOnlySourceFile('module.type-tests.ts', 'vitest')).toBe(false);
+ expect(isTestOnlySourceFile('module.e2e.ts', 'vitest')).toBe(false);
+ expect(isTestOnlySourceFile('module.e2e.ts', 'playwright')).toBe(true);
+ });
+
+ test('Node imports the ESM module directly without a loader', () => {
+ const result = spawnSync(
+ process.execPath,
+ [
+ '--input-type=module',
+ '--eval',
+ "import { isTestOnlySourceFile } from './test-support/test-only-source-file.mjs'; process.stdout.write(JSON.stringify([isTestOnlySourceFile('a.type-tests.ts'), isTestOnlySourceFile('a.ts')]));",
+ ],
+ { cwd: ROOT, encoding: 'utf8', windowsHide: true },
+ );
+ expect(result.error).toBeUndefined();
+ expect(result.status).toBe(0);
+ expect(JSON.parse(result.stdout)).toEqual([true, false]);
+ });
+});
diff --git a/turbo.json b/turbo.json
index b9439ce33..8c5f46742 100644
--- a/turbo.json
+++ b/turbo.json
@@ -47,6 +47,7 @@
"//#typecheck:no-net-connect": {
"inputs": [
"test-support/*.ts",
+ "test-support/*.mts",
"test-support/fixtures/no-net-connect/**/*.ts",
"test-support/tsconfig.no-net-connect.json",
"tsconfig.json"
@@ -111,6 +112,7 @@
"!CHANGELOG.md",
"!README.md",
"../../test-support/*.ts",
+ "../../test-support/test-only-source-file.mjs",
"../app/src/editor/observers.ts"
]
},