Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

Share the workspace test globs and let the CI runner hand Vitest a selection file

[._.]/ Adam Eivyc50b95ddecb0
diff --git a/client/vitest.config.js b/client/vitest.config.js
index a7590850c4..36d8402429 100644
--- a/client/vitest.config.js
+++ b/client/vitest.config.js
@@ -2,13 +2,14 @@ import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import { fileURLToPath } from 'node:url';
import { bootstrapVitestTempRoot } from '../scripts/lib/vitestTempRoot.js';
+import { CLIENT_TEST_EXCLUDE, CLIENT_TEST_INCLUDE } from '../scripts/lib/workspaceTests.js';
-import { vitestCiPool } from '../scripts/vitestCiPool.js';
+import { applyRunnerSelection, vitestCiPool, vitestRunnerSelection } from '../scripts/vitestCiPool.js';
import { TEST_TIMEOUT_MS } from './src/test/timeouts.js';
const RUN_TEMP_ROOT = bootstrapVitestTempRoot();
-export default defineConfig({
+const config = defineConfig({
// Anchor to the config, even when --root or the caller cwd differs.
cacheDir: fileURLToPath(new URL('./.cache/vitest', import.meta.url)),
plugins: [react()],
@@ -26,6 +27,9 @@ export default defineConfig({
// Keeps spawned npm from writing debug logs into the developer's ~/.npm/_logs.
npm_config_logs_max: '0',
NODE_DISABLE_COMPILE_CACHE: '1',
+ // The runner's selection is for THIS Vitest process only: a suite that
+ // spawns a nested Vitest on a fixture must not inherit it.
+ PORTOS_CI_TEST_SELECTION: '',
},
// Four DOM workers exhausted Testing Library's async budget on the public
// runner before ChiefOfStaff's config panel settled. Keep the proven
@@ -52,6 +56,15 @@ export default defineConfig({
globals: true,
setupFiles: ['./src/test/setup.js'],
css: false,
- include: ['src/**/*.{test,spec}.{js,jsx}'],
+ // Shared with the CI runner, which enumerates the same set before Vitest
+ // starts (scripts/lib/workspaceTests.js). The exclude is Vitest's own
+ // default, spelled out so a runner selection can extend it.
+ include: [...CLIENT_TEST_INCLUDE],
+ exclude: [...CLIENT_TEST_EXCLUDE],
},
});
+
+// The CI runner's explicit selection (closure-related files, minus the ones
+// the test memo already verified) arrives as a file, not as CLI selectors.
+config.test = applyRunnerSelection(config.test, vitestRunnerSelection());
+export default config;
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index cd1523aa9a..41e6fc6ca5 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -523,9 +523,12 @@ const DOCUMENTATION_RULES = [
// Text snapshots are executable test inputs, but their extension is deliberately
// outside EXECUTABLE_RE. Keep this mapping explicit rather than treating every
// `.txt` file as a test fixture: an unmapped text artifact must still widen CI.
-const FIXTURE_OWNERS = [
+// `dir` names the directory the pattern covers so the test memo
+// (scripts/lib/testMemo.js) can hash every fixture an owning test reads.
+export const FIXTURE_OWNERS = [
{
re: /^server\/services\/promptSections\/__snapshots__\/reviewLoopMatrix\/[^/]+\.txt$/,
+ dir: 'server/services/promptSections/__snapshots__/reviewLoopMatrix',
tests: ['server/services/promptSections/reviewLifecycleMatrix.test.js'],
},
];
@@ -721,7 +724,7 @@ const featureDirectory = (path) => {
const WORKSPACE_CACHE_COMMON_INPUTS = new Set([
'.github/workflows/ci.yml', 'package.json', 'scripts/lib/workspaceCacheFixture.js',
'scripts/lib/vitestTempRootFixture.js', 'scripts/lib/vitestTempRoot.js',
- 'scripts/lib/vitestStaleRunRoots.js', 'scripts/lib/dbTestFiles.js',
+ 'scripts/lib/vitestStaleRunRoots.js', 'scripts/lib/dbTestFiles.js', 'scripts/lib/workspaceTests.js',
'scripts/vitestCiPool.js', 'scripts/vitestTempRootSetup.js', 'server/lib/killWithEscalation.js',
'server/test/ownedBrowserDiagnostics.js', 'server/lib/mockPathsDataRoot.js',
]);
diff --git a/scripts/ci-test-plan.test.js b/scripts/ci-test-plan.test.js
index 4abc585ba3..877bd9c1d1 100644
--- a/scripts/ci-test-plan.test.js
+++ b/scripts/ci-test-plan.test.js
@@ -82,7 +82,7 @@ it('selects checkout-cache contracts only in their installed-dependency runners'
const shared = [
'.github/workflows/ci.yml', 'package.json', 'scripts/lib/workspaceCacheFixture.js',
'scripts/lib/vitestTempRootFixture.js', 'scripts/lib/vitestTempRoot.js',
- 'scripts/lib/vitestStaleRunRoots.js', 'scripts/lib/dbTestFiles.js',
+ 'scripts/lib/vitestStaleRunRoots.js', 'scripts/lib/dbTestFiles.js', 'scripts/lib/workspaceTests.js',
'scripts/vitestCiPool.js', 'scripts/vitestTempRootSetup.js', 'server/lib/killWithEscalation.js',
'server/test/ownedBrowserDiagnostics.js', 'server/lib/mockPathsDataRoot.js',
];
diff --git a/scripts/lib/workspaceCacheFixture.js b/scripts/lib/workspaceCacheFixture.js
index 1b89a38df8..a2c5334eaa 100644
--- a/scripts/lib/workspaceCacheFixture.js
+++ b/scripts/lib/workspaceCacheFixture.js
@@ -55,7 +55,7 @@ function checkout(host, name, workspace, configName, dependencies) {
// Copy the real config so import.meta.url names THIS checkout; its existing
// helpers stay shared read-only, just like dependencies in an ordinary worktree.
copyFileSync(join(REPO, workspace, configName), join(root, configName));
- for (const file of ['lib/vitestTempRoot.js', 'lib/dbTestFiles.js', 'lib/browserSuites.js', 'vitestCiPool.js', 'vitestTempRootSetup.js']) {
+ for (const file of ['lib/vitestTempRoot.js', 'lib/dbTestFiles.js', 'lib/browserSuites.js', 'lib/workspaceTests.js', 'vitestCiPool.js', 'vitestTempRootSetup.js']) {
link(join(REPO, 'scripts', file), join(parent, 'scripts', file));
}
if (workspace === 'server') {
diff --git a/scripts/lib/workspaceTests.js b/scripts/lib/workspaceTests.js
new file mode 100644
index 0000000000..f03692ec98
--- /dev/null
+++ b/scripts/lib/workspaceTests.js
@@ -0,0 +1,130 @@
+/**
+ * The test files each Vitest workspace collects, enumerated without Vitest.
+ *
+ * `scripts/run-ci-tests.js` needs the explicit set a `full` plan runs and the
+ * candidate set a `related` plan selects from, before Vitest starts. The
+ * globs live here and the workspace configs import them, so the runner and
+ * the config cannot disagree; `workspaceTests.test.js` pins the enumeration
+ * against `vitest list` as well.
+ *
+ * Paths are workspace-relative posix (`lib/x.test.js`, `../scripts/x.test.js`),
+ * the form the configs and the runner selection file use. `toRepoPath` /
+ * `toWorkspacePath` convert to and from repo-relative paths.
+ */
+
+import { readdirSync, statSync } from 'node:fs';
+import { join, posix, sep } from 'node:path';
+import { BROWSER_SUITES } from './browserSuites.js';
+import { DB_TEST_INCLUDE } from './dbTestFiles.js';
+
+/** Directories never walked: installs, caches, build output, machine-local state, the bundled submodule. */
+const SKIP_DIRS = new Set(['node_modules', '.git', '.cache', 'coverage', 'dist', '.vite', 'data']);
+
+/**
+ * The server runner covers server, scripts/migrations, lib, autofixer and the
+ * doc-parity guards. The client owns `client/src` (see each config for why).
+ */
+export const SERVER_TEST_INCLUDE = Object.freeze([
+ '**/*.test.js',
+ '../scripts/**/*.test.js',
+ '../lib/**/*.test.js',
+ '../autofixer/**/*.test.js',
+ '../docs/**/*.test.js',
+]);
+
+/** The slashdo submodule ships node:test suites; DB suites run only under vitest.config.db.js. */
+export const SERVER_TEST_EXCLUDE = Object.freeze([
+ '**/node_modules/**',
+ '../lib/slashdo/**',
+ ...DB_TEST_INCLUDE,
+]);
+
+export const CLIENT_TEST_INCLUDE = Object.freeze(['src/**/*.{test,spec}.{js,jsx}']);
+export const CLIENT_TEST_EXCLUDE = Object.freeze(['**/node_modules/**', '**/.git/**']);
+
+/**
+ * Linux CI gives the registered browser contracts one browser-owner job; only
+ * the explicitly opted-in unit profile excludes them from the server runner.
+ */
+export function browserOwnerExcludes({ platform = process.platform, env = process.env } = {}) {
+ return platform === 'linux' && env.PORTOS_CI_BROWSER_OWNER === 'unit'
+ ? BROWSER_SUITES.map(path => path.slice('server/'.length)) : [];
+}
+
+export function workspaceTestGlobs(workspace, options = {}) {
+ if (workspace === 'server') return { include: [...SERVER_TEST_INCLUDE], exclude: [...SERVER_TEST_EXCLUDE, ...browserOwnerExcludes(options)] };
+ if (workspace === 'client') return { include: [...CLIENT_TEST_INCLUDE], exclude: [...CLIENT_TEST_EXCLUDE] };
+ throw new Error(`Unknown workspace: ${workspace}`);
+}
+
+/** The subset of glob syntax the workspace configs use: `**`, `*`, `?`, `{a,b}`. */
+export function globToRegExp(glob) {
+ let out = '^';
+ for (let i = 0; i < glob.length; i += 1) {
+ const c = glob[i];
+ if (c === '*' && glob[i + 1] === '*') {
+ const slash = glob[i + 2] === '/';
+ out += slash ? '(?:.*/)?' : '.*';
+ i += slash ? 2 : 1;
+ } else if (c === '*') out += '[^/]*';
+ else if (c === '?') out += '[^/]';
+ else if (c === '{') {
+ const close = glob.indexOf('}', i);
+ out += `(?:${glob.slice(i + 1, close).split(',').map(escape).join('|')})`;
+ i = close;
+ } else out += escape(c);
+ }
+ return new RegExp(`${out}$`);
+}
+
+const escape = (text) => text.replace(/[.+^$()|[\]\\]/g, '\\$&');
+
+/** Walk from the literal prefix of each include glob; a walk never leaves the repository. */
+function walkRoots(include) {
+ return [...new Set(include.map((glob) => {
+ const literal = glob.split('/').filter((part) => !/[*?{]/.test(part));
+ const stop = glob.split('/').findIndex((part) => /[*?{]/.test(part));
+ return (stop === -1 ? literal.slice(0, -1) : literal.slice(0, stop)).join('/') || '.';
+ }))];
+}
+
+/**
+ * Every test file the workspace config collects, workspace-relative, sorted.
+ * `repoRoot` locates the workspace on disk; `workspaceDir` is the vitest
+ * root (`server` or `client`).
+ */
+export function listWorkspaceTests(workspace, { repoRoot, platform, env } = {}) {
+ const { include, exclude } = workspaceTestGlobs(workspace, { platform, env });
+ const includes = include.map(globToRegExp);
+ const excludes = exclude.map(globToRegExp);
+ const workspaceAbs = join(repoRoot, workspace);
+ const found = [];
+ const walk = (relDir) => {
+ const absDir = relDir === '.' ? workspaceAbs : join(workspaceAbs, ...relDir.split('/'));
+ let entries;
+ try { entries = readdirSync(absDir, { withFileTypes: true }); } catch { return; }
+ for (const entry of entries) {
+ if (SKIP_DIRS.has(entry.name)) continue;
+ const rel = relDir === '.' ? entry.name : `${relDir}/${entry.name}`;
+ let isDirectory = entry.isDirectory();
+ if (entry.isSymbolicLink()) {
+ try { isDirectory = statSync(join(absDir, entry.name)).isDirectory(); } catch { continue; }
+ }
+ if (isDirectory) { walk(rel); continue; }
+ if (includes.some((re) => re.test(rel)) && !excludes.some((re) => re.test(rel))) found.push(rel);
+ }
+ };
+ for (const root of walkRoots(include)) walk(root);
+ return found.sort();
+}
+
+/** `lib/x.test.js` in `server` -> `server/lib/x.test.js`; `../scripts/x.test.js` -> `scripts/x.test.js`. */
+export function toRepoPath(workspace, workspaceRel) {
+ return posix.normalize(posix.join(workspace, workspaceRel.split(sep).join('/')));
+}
+
+/** The inverse of `toRepoPath`. */
+export function toWorkspacePath(workspace, repoRel) {
+ const normalized = repoRel.split(sep).join('/');
+ return normalized.startsWith(`${workspace}/`) ? normalized.slice(workspace.length + 1) : `../${normalized}`;
+}
diff --git a/scripts/lib/workspaceTests.test.js b/scripts/lib/workspaceTests.test.js
new file mode 100644
index 0000000000..205d4130b3
--- /dev/null
+++ b/scripts/lib/workspaceTests.test.js
@@ -0,0 +1,53 @@
+/**
+ * The runner's enumeration must collect exactly what each Vitest config
+ * collects: a file the runner cannot see is a file the memo can never skip
+ * and a full plan would silently drop.
+ */
+
+import { execFileSync } from 'node:child_process';
+import { join } from 'node:path';
+import { describe, expect, it } from 'vitest';
+import { globToRegExp, listWorkspaceTests, toRepoPath, toWorkspacePath } from './workspaceTests.js';
+
+const REPO_ROOT = join(import.meta.dirname, '..', '..');
+
+describe('workspace test enumeration', () => {
+ it('matches the subset of glob syntax the configs use', () => {
+ expect(globToRegExp('**/*.test.js').test('lib/x.test.js')).toBe(true);
+ expect(globToRegExp('**/*.test.js').test('x.test.js')).toBe(true);
+ expect(globToRegExp('**/*.test.js').test('lib/x.spec.js')).toBe(false);
+ expect(globToRegExp('../scripts/**/*.test.js').test('../scripts/lib/x.test.js')).toBe(true);
+ expect(globToRegExp('src/**/*.{test,spec}.{js,jsx}').test('src/a/b.spec.jsx')).toBe(true);
+ expect(globToRegExp('**/db.test.js').test('lib/db.test.js')).toBe(true);
+ expect(globToRegExp('**/db.test.js').test('lib/x.db.test.js')).toBe(false);
+ expect(globToRegExp('../lib/slashdo/**').test('../lib/slashdo/a/b.test.js')).toBe(true);
+ });
+
+ it('converts between workspace and repository paths', () => {
+ expect(toRepoPath('server', 'lib/x.test.js')).toBe('server/lib/x.test.js');
+ expect(toRepoPath('server', '../scripts/x.test.js')).toBe('scripts/x.test.js');
+ expect(toWorkspacePath('server', 'scripts/x.test.js')).toBe('../scripts/x.test.js');
+ expect(toWorkspacePath('client', 'client/src/x.test.jsx')).toBe('src/x.test.jsx');
+ });
+
+ for (const workspace of ['server', 'client']) {
+ it(`collects the same files as \`vitest list\` for ${workspace}`, () => {
+ const listed = execFileSync(join(REPO_ROOT, workspace, 'node_modules', '.bin', 'vitest'),
+ ['list', '--filesOnly', '--configLoader', 'runner'], {
+ cwd: join(REPO_ROOT, workspace), encoding: 'utf8', maxBuffer: 16 * 1024 * 1024,
+ env: { ...process.env, PORTOS_CI_TEST_SELECTION: '', PORTOS_CI_BROWSER_OWNER: '' },
+ })
+ .split('\n').map((line) => line.trim().replace(/^\[[^\]]+\] /, '')).filter(Boolean).sort();
+ expect(listed.length).toBeGreaterThan(100);
+ expect(listWorkspaceTests(workspace, { repoRoot: REPO_ROOT, env: {} })).toEqual([...new Set(listed)].sort());
+ }, 120_000);
+ }
+
+ it('drops the registered browser suites only for the Linux unit owner', () => {
+ const all = listWorkspaceTests('server', { repoRoot: REPO_ROOT, platform: 'linux', env: {} });
+ const owned = listWorkspaceTests('server', { repoRoot: REPO_ROOT, platform: 'linux', env: { PORTOS_CI_BROWSER_OWNER: 'unit' } });
+ expect(all).toContain('lib/filmLook.browser.test.js');
+ expect(owned).not.toContain('lib/filmLook.browser.test.js');
+ expect(listWorkspaceTests('server', { repoRoot: REPO_ROOT, platform: 'win32', env: { PORTOS_CI_BROWSER_OWNER: 'unit' } })).toEqual(all);
+ });
+});
diff --git a/scripts/vitestCiPool.js b/scripts/vitestCiPool.js
index 06a3472f2e..97cc8219fd 100644
--- a/scripts/vitestCiPool.js
+++ b/scripts/vitestCiPool.js
@@ -20,6 +20,8 @@
*
* Vitest 5 exposes `maxWorkers` only — there is no `minWorkers` / `minThreads`.
*/
+import { readFileSync } from 'node:fs';
+
export function vitestCiPool({ maxWorkers = 4 } = {}) {
if (process.env.CI) {
// The Windows server job lowers the cap (#10114): one process per test file
@@ -73,8 +75,46 @@ const EXCLUSIVE_TESTS = [
'../scripts/writersRoomPromotionCleanup.test.js',
];
-export function vitestCaptureProjects(test, { cacheDir } = {}) {
+/**
+ * The runner's explicit file selection, when `scripts/run-ci-tests.js` wrote
+ * one. `PORTOS_CI_TEST_SELECTION` names a JSON file
+ * `{ include: string[]|null, exclude: string[] }` of workspace-relative posix
+ * paths: `include` replaces the config's globs (null keeps them), `exclude`
+ * is appended. A file rather than CLI selectors because a closure-selected
+ * related set or a memo-trimmed full run can name thousands of files, past
+ * the Windows command-line limit. A malformed file throws: a selection the
+ * config cannot read must never silently widen to the whole suite.
+ */
+export function vitestRunnerSelection(env = process.env) {
+ const path = env.PORTOS_CI_TEST_SELECTION;
+ if (!path) return { include: null, exclude: [] };
+ const parsed = JSON.parse(readFileSync(path, 'utf8'));
+ const list = (value, name) => {
+ if (!Array.isArray(value) || !value.every(entry => typeof entry === 'string' && entry.length > 0)) {
+ throw new Error(`PORTOS_CI_TEST_SELECTION ${name} must be a list of workspace-relative paths`);
+ }
+ return value;
+ };
+ return {
+ include: parsed.include === null || parsed.include === undefined ? null : list(parsed.include, 'include'),
+ exclude: parsed.exclude === undefined ? [] : list(parsed.exclude, 'exclude'),
+ };
+}
+
+/** `test` with the runner selection applied to its include/exclude globs. */
+export function applyRunnerSelection(test, selection) {
+ const applied = { ...test, include: selection.include ?? test.include };
+ // Leave an absent `exclude` absent: setting it to [] would drop Vitest's own defaults.
+ if (test.exclude !== undefined || selection.exclude.length > 0) applied.exclude = [...(test.exclude ?? []), ...selection.exclude];
+ return applied;
+}
+
+export function vitestCaptureProjects(test, { cacheDir, selection = { include: null, exclude: [] } } = {}) {
const { include, exclude, ...shared } = test;
+ // An explicit selection narrows the capture group too; its fixed include
+ // would otherwise run every exclusive suite on every scoped plan.
+ const captureInclude = selection.include === null
+ ? EXCLUSIVE_TESTS : EXCLUSIVE_TESTS.filter(file => selection.include.includes(file));
// Vite concatenates inherited include arrays: extending the broad root
// glob would also run EVERY unit file in the capture project. Copy shared
// worker settings explicitly and leave run-wide ownership at the root.
@@ -100,7 +140,7 @@ export function vitestCaptureProjects(test, { cacheDir } = {}) {
test: {
...shared,
name: 'capture',
- include: EXCLUSIVE_TESTS,
+ include: captureInclude,
exclude,
fileParallelism: false,
sequence: { groupOrder: 1 },
diff --git a/scripts/vitestCiPool.test.js b/scripts/vitestCiPool.test.js
index 1b59a90189..d6a1415541 100644
--- a/scripts/vitestCiPool.test.js
+++ b/scripts/vitestCiPool.test.js
@@ -5,7 +5,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
-import { vitestCiPool } from './vitestCiPool.js';
+import { EXCLUSIVE_CAPTURE_TESTS, applyRunnerSelection, vitestCaptureProjects, vitestCiPool, vitestRunnerSelection } from './vitestCiPool.js';
describe('vitestCiPool', () => {
const original = process.env.CI;
@@ -157,3 +157,39 @@ it('runs parallel units before exclusive, nonduplicated captures and cutover pro
rmSync(scratch, { recursive: true, force: true });
}
}, 35000);
+
+describe('vitestRunnerSelection', () => {
+ let dir;
+ afterEach(() => { if (dir) rmSync(dir, { recursive: true, force: true }); dir = undefined; });
+
+ it('keeps the config globs without a selection and applies a file selection on top of them', () => {
+ expect(vitestRunnerSelection({})).toEqual({ include: null, exclude: [] });
+ dir = mkdtempSync(join(tmpdir(), 'portos-selection-'));
+ const path = join(dir, 'selection.json');
+ writeFileSync(path, JSON.stringify({ include: ['lib/a.test.js', '../scripts/b.test.js'], exclude: ['lib/c.test.js'] }));
+ const selection = vitestRunnerSelection({ PORTOS_CI_TEST_SELECTION: path });
+ expect(applyRunnerSelection({ include: ['**/*.test.js'], exclude: ['**/node_modules/**'] }, selection))
+ .toEqual({ include: ['lib/a.test.js', '../scripts/b.test.js'], exclude: ['**/node_modules/**', 'lib/c.test.js'] });
+ // An exclude-only selection (a memo-trimmed full run) keeps the globs; an absent exclude stays absent.
+ writeFileSync(path, JSON.stringify({ include: null, exclude: ['lib/c.test.js'] }));
+ expect(applyRunnerSelection({ include: ['**/*.test.js'] }, vitestRunnerSelection({ PORTOS_CI_TEST_SELECTION: path })))
+ .toEqual({ include: ['**/*.test.js'], exclude: ['lib/c.test.js'] });
+ expect(applyRunnerSelection({ include: ['x'] }, { include: null, exclude: [] })).toEqual({ include: ['x'] });
+ // The capture project narrows to the selection too, instead of running every exclusive suite.
+ const [parallel, capture] = vitestCaptureProjects({ include: ['lib/a.test.js', EXCLUSIVE_CAPTURE_TESTS[0]], exclude: [] },
+ { selection: { include: ['lib/a.test.js', EXCLUSIVE_CAPTURE_TESTS[0]], exclude: [] } });
+ expect(capture.test.include).toEqual([EXCLUSIVE_CAPTURE_TESTS[0]]);
+ expect(parallel.test.exclude).toContain(EXCLUSIVE_CAPTURE_TESTS[0]);
+ expect(vitestCaptureProjects({ include: ['**/*.test.js'], exclude: [] })[1].test.include.length).toBeGreaterThan(1);
+ });
+
+ it('refuses a selection it cannot read rather than widening to the whole suite', () => {
+ dir = mkdtempSync(join(tmpdir(), 'portos-selection-'));
+ const path = join(dir, 'selection.json');
+ writeFileSync(path, '{ not json');
+ expect(() => vitestRunnerSelection({ PORTOS_CI_TEST_SELECTION: path })).toThrow();
+ writeFileSync(path, JSON.stringify({ include: ['ok', 42] }));
+ expect(() => vitestRunnerSelection({ PORTOS_CI_TEST_SELECTION: path })).toThrow(/include/);
+ expect(() => vitestRunnerSelection({ PORTOS_CI_TEST_SELECTION: join(dir, 'missing.json') })).toThrow();
+ });
+});
diff --git a/server/vitest.config.js b/server/vitest.config.js
index 61d92757cc..029a18d7f1 100644
--- a/server/vitest.config.js
+++ b/server/vitest.config.js
@@ -1,9 +1,8 @@
import { defineConfig } from 'vitest/config';
import { fileURLToPath } from 'node:url';
-import { vitestCaptureProjects, vitestCiPool } from '../scripts/vitestCiPool.js';
-import { DB_TEST_INCLUDE } from '../scripts/lib/dbTestFiles.js';
-import { BROWSER_SUITES } from '../scripts/lib/browserSuites.js';
+import { applyRunnerSelection, vitestCaptureProjects, vitestCiPool, vitestRunnerSelection } from '../scripts/vitestCiPool.js';
import { bootstrapVitestTempRoot } from '../scripts/lib/vitestTempRoot.js';
+import { SERVER_TEST_EXCLUDE, SERVER_TEST_INCLUDE, browserOwnerExcludes } from '../scripts/lib/workspaceTests.js';
// `npm run test:fast` is the Windows-safe way to set the flag (a
// `VITEST_FAST=1 vitest` script is parsed as an executable name on cmd.exe).
@@ -40,11 +39,9 @@ process.env.NODE_ENV = 'test';
// engines), so every supported Node build respects it.
process.env.NODE_DISABLE_COMPILE_CACHE = '1';
-// Linux CI gives these registered contracts one browser-owner job. Only the
-// explicitly opted-in unit profile excludes them; local and Windows defaults
-// retain their current collection, including browser suites outside the registry.
-const browserOwnerExcludes = process.platform === 'linux' && process.env.PORTOS_CI_BROWSER_OWNER === 'unit'
- ? BROWSER_SUITES.map(path => path.slice('server/'.length)) : [];
+// The CI runner's explicit selection (closure-related files, minus the ones
+// the test memo already verified) arrives as a file, not as CLI selectors.
+const runnerSelection = vitestRunnerSelection();
const config = defineConfig({
// Anchor to the config, even when --root or the caller cwd differs.
@@ -63,6 +60,9 @@ const config = defineConfig({
MAC_CHROMIUM_TMPDIR: RUN_TEMP_ROOT,
// Keeps spawned npm from writing debug logs into the developer's ~/.npm/_logs.
npm_config_logs_max: '0',
+ // The runner's selection is for THIS Vitest process only: a suite that
+ // spawns a nested Vitest on a fixture must not inherit it.
+ PORTOS_CI_TEST_SELECTION: '',
},
// 30s on every platform (#7951). This WAS 10s off Windows, and the split
// has always been a fiction: the cost it budgets for is vitest's transform
@@ -117,18 +117,13 @@ const config = defineConfig({
// environment has no DOM, so DOM-dependent client tests would fail here).
// The scripts/migrations glob lets each one-shot migration be verified
// against synthetic fixtures.
- include: [
- '**/*.test.js',
- '../scripts/**/*.test.js',
- '../lib/**/*.test.js',
- // The standalone autofixer package ships pure, node-builtin-only helpers
- // (sandbox.js isolation/promotion primitives) whose adversarial tests run
- // under this node runner.
- '../autofixer/**/*.test.js',
- // docs/deps-doc.test.js guards DEPS.md against dependency drift; it lives
- // next to the document it checks rather than in server/.
- '../docs/**/*.test.js',
- ],
+ // The standalone autofixer package ships pure, node-builtin-only helpers
+ // (sandbox.js isolation/promotion primitives) whose adversarial tests run
+ // under this node runner. docs/deps-doc.test.js guards DEPS.md against
+ // dependency drift; it lives next to the document it checks rather than
+ // in server/. The globs are shared with the CI runner, which enumerates
+ // the same set before Vitest starts (scripts/lib/workspaceTests.js).
+ include: [...SERVER_TEST_INCLUDE],
// The slashdo submodule ships its own node:test suites; vitest can't
// parse them and the broad `../lib/**` glob would otherwise pick them up
// as "no test suite found" failures that break --bail=1 CI runs.
@@ -144,10 +139,8 @@ const config = defineConfig({
// their real-git describes honor SKIP_HEAVY_INTEGRATION, and the leftover
// pure-logic cases still run under --fast.
exclude: [
- '**/node_modules/**',
- '../lib/slashdo/**',
- ...DB_TEST_INCLUDE,
- ...browserOwnerExcludes,
+ ...SERVER_TEST_EXCLUDE,
+ ...browserOwnerExcludes(),
...(process.env.VITEST_FAST ? [
'services/worktreeReap.test.js',
'services/sprites/atlas.test.js',
@@ -209,5 +202,6 @@ const config = defineConfig({
// Both projects share the safety env, setup files and time budgets. The
// root globalSetup owns one temp root across BOTH groups; project teardown
// must not remove it while another group still needs it.
-config.test.projects = vitestCaptureProjects(config.test, { cacheDir: config.cacheDir });
+config.test = applyRunnerSelection(config.test, runnerSelection);
+config.test.projects = vitestCaptureProjects(config.test, { cacheDir: config.cacheDir, selection: runnerSelection });
export default config;