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

Run the client enumeration parity in the client workspace and hash shard paths with the platform separator

[._.]/ Adam Eivy46b1fd573609
diff --git a/client/src/test/workspaceTests.test.js b/client/src/test/workspaceTests.test.js
new file mode 100644
index 0000000000..f21e62d984
--- /dev/null
+++ b/client/src/test/workspaceTests.test.js
@@ -0,0 +1,25 @@
+// @vitest-environment node
+/**
+ * The CI runner's enumeration of the client workspace must collect exactly
+ * what client/vitest.config.js collects. The server half of this contract is
+ * scripts/lib/workspaceTests.test.js; this half runs where the client
+ * workspace is installed, which the server CI job is not.
+ */
+import { execFileSync } from 'node:child_process';
+import { join } from 'node:path';
+import { expect, it } from 'vitest';
+import { listWorkspaceTests } from '../../../scripts/lib/workspaceTests.js';
+
+const REPO_ROOT = join(import.meta.dirname, '..', '..', '..');
+
+it('collects the same files as `vitest list` for client', () => {
+ // Through node, not the .bin shim: the shim is a shell script (.cmd on Windows) execFileSync cannot start there.
+ const listed = execFileSync(process.execPath, [join(REPO_ROOT, 'client', 'node_modules', 'vitest', 'vitest.mjs'),
+ 'list', '--filesOnly', '--configLoader', 'runner'], {
+ cwd: join(REPO_ROOT, 'client'), encoding: 'utf8', maxBuffer: 16 * 1024 * 1024,
+ env: { ...process.env, PORTOS_CI_TEST_SELECTION: '' },
+ })
+ .split('\n').map((line) => line.trim().replace(/^\[[^\]]+\] /, '')).filter(Boolean);
+ expect(listed.length).toBeGreaterThan(100);
+ expect(listWorkspaceTests('client', { repoRoot: REPO_ROOT, env: {} })).toEqual([...new Set(listed)].sort());
+}, 120_000);
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index 41e6fc6ca5..fa7a1e4394 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -754,6 +754,8 @@ export const structuralTestsFor = (changedFiles, trackedSet) => {
}
if (sharedCacheInputChanged || changedFiles.some((path) => WORKSPACE_CACHE_CLIENT_INPUTS.has(path))) {
add('client/src/test/workspaceCaches.test.js');
+ // The runner's client enumeration is pinned against `vitest list` from the client workspace, where the client job runs it.
+ add('client/src/test/workspaceTests.test.js');
}
if (changedFiles.some((path) => /^server\/lib\//.test(path))) {
add('server/lib/index.test.js');
diff --git a/scripts/lib/testMemoRunner.js b/scripts/lib/testMemoRunner.js
index cc98e19da9..18c145e34e 100644
--- a/scripts/lib/testMemoRunner.js
+++ b/scripts/lib/testMemoRunner.js
@@ -31,7 +31,7 @@ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { tmpdir } from 'node:os';
import * as nodePath from 'node:path';
-import { join, posix, relative, sep } from 'node:path';
+import { join, relative, sep } from 'node:path';
import { WORKSPACE_BASE_INPUTS, createDiskFs, createTestMemoAnalyzer, relatedTests } from './testMemo.js';
import { readMemoEntry, readMemoRecord, writeMemoEntry, writeMemoRecord } from './testMemoStore.js';
import { listWorkspaceTests, toRepoPath, toWorkspacePath } from './workspaceTests.js';
@@ -109,19 +109,30 @@ export function vitestShardRange(count, index, total) {
return [start, start + base];
}
+/**
+ * The string Vitest hashes for a test file when sharding:
+ * `resolve(slash(root), slash(moduleId)).slice(root.length)` — the absolute
+ * path as the platform's `path.resolve` builds it (backslashes on Windows)
+ * with the root prefix sliced off, so an in-workspace file hashes as
+ * `/lib/x.test.js` or `\\lib\\x.test.js` and a file outside the workspace
+ * hashes its remaining absolute tail. `path` is injectable so both
+ * separators are pinned in the tests.
+ */
+export function vitestShardHashInput(rel, { repoRoot, scope, path = nodePath }) {
+ const root = path.resolve(repoRoot, scope);
+ return path.resolve(repoRoot, ...rel.split('/')).slice(root.length);
+}
+
/**
* The files shard `index` of `count` runs, mirroring Vitest's
- * `BaseSequencer.shard`: sort by the sha1 of each file's path relative to
- * the Vitest root (the absolute path with the root prefix sliced off, so a
- * file outside the workspace hashes its remaining absolute tail), then take
- * the range. Pinned against a real `vitest run --shard` in the tests.
+ * `BaseSequencer.shard`: sort by the sha1 of `vitestShardHashInput`, then
+ * take `vitestShardRange`. Pinned against a real `vitest run --shard` in
+ * the tests.
*/
-export function vitestShardSlice(files, { repoRoot, scope, index, count }) {
- const repoPosix = repoRoot.split(sep).join('/');
- const rootPosix = posix.join(repoPosix, scope);
+export function vitestShardSlice(files, { repoRoot, scope, index, count, path = nodePath }) {
const hashed = files.map((rel) => ({
rel,
- hash: createHash('sha1').update(posix.join(repoPosix, rel).slice(rootPosix.length)).digest('hex'),
+ hash: createHash('sha1').update(vitestShardHashInput(rel, { repoRoot, scope, path })).digest('hex'),
})).sort((a, b) => (a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0));
const [start, end] = vitestShardRange(hashed.length, index, count);
return hashed.slice(start, end).map(({ rel }) => rel);
diff --git a/scripts/lib/testMemoRunner.test.js b/scripts/lib/testMemoRunner.test.js
index 32c92aad67..206fa62fe4 100644
--- a/scripts/lib/testMemoRunner.test.js
+++ b/scripts/lib/testMemoRunner.test.js
@@ -7,11 +7,11 @@
import { execFileSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { join } from 'node:path';
+import { join, posix, win32 } from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import {
clearVitestDependencies, fileResultsFromReport, findVitestDependenciesFile, passedTestFiles, planTestMemo, readVitestDependencies,
- recordTestMemo, vitestShardRange, vitestShardSlice, writeSelectionFile,
+ recordTestMemo, vitestShardHashInput, vitestShardRange, vitestShardSlice, writeSelectionFile,
} from './testMemoRunner.js';
import { readMemoEntry, readMemoRecord, writeMemoEntry } from './testMemoStore.js';
@@ -140,6 +140,18 @@ describe('planTestMemo and recordTestMemo', () => {
expect(plan({ memoDir: null }).skipped).toEqual([]);
});
+ it('hashes the root-relative path with the platform\'s own separator, like Vitest', () => {
+ // POSIX: `/lib/x.test.js`; Windows: `\\lib\\x.test.js` (path.resolve builds a backslash path).
+ expect(vitestShardHashInput('server/lib/x.test.js', { repoRoot: '/repo', scope: 'server', path: posix })).toBe('/lib/x.test.js');
+ expect(vitestShardHashInput('scripts/x.test.js', { repoRoot: '/repo', scope: 'server', path: posix })).toBe('s/x.test.js');
+ expect(vitestShardHashInput('server/lib/x.test.js', { repoRoot: 'D:\\a\\repo', scope: 'server', path: win32 })).toBe('\\lib\\x.test.js');
+ expect(vitestShardHashInput('scripts/x.test.js', { repoRoot: 'D:\\a\\repo', scope: 'server', path: win32 })).toBe('s\\x.test.js');
+ // The two separators hash differently, so a slice computed for the other platform is not this platform's slice.
+ const files = ['server/lib/a.test.js', 'server/lib/b.test.js', 'server/lib/c.test.js', 'scripts/d.test.js', 'scripts/e.test.js'];
+ const slices = (path, repoRoot) => [1, 2].map((index) => vitestShardSlice(files, { repoRoot, scope: 'server', index, count: 2, path }));
+ for (const [a, b] of [slices(posix, '/repo'), slices(win32, 'D:\\a\\repo')]) expect([...a, ...b].sort()).toEqual([...files].sort());
+ });
+
it('slices shards exactly like Vitest\'s sequencer', () => {
expect([1, 2, 3].map((index) => vitestShardRange(7, index, 3))).toEqual([[0, 3], [3, 5], [5, 7]]);
expect([1, 2].map((index) => vitestShardRange(1, index, 2))).toEqual([[0, 1], [1, 1]]);
@@ -150,12 +162,13 @@ describe('planTestMemo and recordTestMemo', () => {
const files = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta'].map((name) => `${name}.test.js`);
for (const file of files) writeFileSync(join(fixture, file), "import { it } from 'vitest';\nit('x', () => {});\n");
writeFileSync(join(fixture, 'vitest.config.mjs'), 'export default { test: { include: ["*.test.js"], maxWorkers: 1 } };');
- const vitest = join(import.meta.dirname, '..', '..', 'server', 'node_modules', '.bin', 'vitest');
+ // Vitest's JS entry through node: the .bin shim cannot be started by execFileSync on Windows.
+ const vitest = join(import.meta.dirname, '..', '..', 'server', 'node_modules', 'vitest', 'vitest.mjs');
const env = { ...process.env, NODE_ENV: 'test', TMPDIR: host, TMP: host, TEMP: host, NODE_DISABLE_COMPILE_CACHE: '1', PORTOS_CI_TEST_SELECTION: '' };
delete env.PORTOS_TEST_TEMP_ROOT;
for (const index of [1, 2, 3]) {
const report = join(fixture, `shard${index}.json`);
- execFileSync(vitest, ['run', `--shard=${index}/3`, '--config', join(fixture, 'vitest.config.mjs'), '--root', fixture, '--reporter=json', `--outputFile=${report}`], { cwd: fixture, env, encoding: 'utf8', timeout: 60_000 });
+ execFileSync(process.execPath, [vitest, 'run', `--shard=${index}/3`, '--config', join(fixture, 'vitest.config.mjs'), '--root', fixture, '--reporter=json', `--outputFile=${report}`], { cwd: fixture, env, encoding: 'utf8', timeout: 60_000 });
const ran = JSON.parse(readFileSync(report, 'utf8')).testResults.map((suite) => suite.name.replace(/\\/g, '/').split('/').pop()).sort();
expect(ran, `shard ${index}`).toEqual(vitestShardSlice(files, { repoRoot: fixture, scope: '.', index, count: 3 }).sort());
}
diff --git a/scripts/lib/workspaceTests.test.js b/scripts/lib/workspaceTests.test.js
index 205d4130b3..7e1e0aa1b9 100644
--- a/scripts/lib/workspaceTests.test.js
+++ b/scripts/lib/workspaceTests.test.js
@@ -11,6 +11,19 @@ import { globToRegExp, listWorkspaceTests, toRepoPath, toWorkspacePath } from '.
const REPO_ROOT = join(import.meta.dirname, '..', '..');
+/** What `vitest list --filesOnly` collects for a workspace, sorted and project-prefix free. */
+function vitestListedFiles(repoRoot, workspace) {
+ // Through node, not the .bin shim: the shim is a shell script (.cmd on Windows) execFileSync cannot start there.
+ const listed = execFileSync(process.execPath, [join(repoRoot, workspace, 'node_modules', 'vitest', 'vitest.mjs'),
+ 'list', '--filesOnly', '--configLoader', 'runner'], {
+ cwd: join(repoRoot, 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);
+ if (listed.length < 100) throw new Error(`vitest list returned only ${listed.length} ${workspace} files`);
+ return [...new Set(listed)].sort();
+}
+
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);
@@ -30,18 +43,11 @@ describe('workspace test enumeration', () => {
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);
- }
+ // The client half lives in client/src/test/workspaceTests.test.js: the server
+ // CI job installs no client workspace, so a client `vitest list` cannot run here.
+ it('collects the same files as `vitest list` for server', () => {
+ expect(listWorkspaceTests('server', { repoRoot: REPO_ROOT, env: {} })).toEqual(vitestListedFiles(REPO_ROOT, 'server'));
+ }, 120_000);
it('drops the registered browser suites only for the Linux unit owner', () => {
const all = listWorkspaceTests('server', { repoRoot: REPO_ROOT, platform: 'linux', env: {} });
diff --git a/scripts/run-ci-tests.test.js b/scripts/run-ci-tests.test.js
index bbf3712eb2..d24417e2b9 100644
--- a/scripts/run-ci-tests.test.js
+++ b/scripts/run-ci-tests.test.js
@@ -177,12 +177,13 @@ describe('test memo through the real runner', () => {
writeFileSync(join(fixture, 'a.test.js'), "import { a } from './a.js';\ntest('a', () => { expect(a).toBe(1); });\n");
writeFileSync(join(fixture, 'b.test.js'), "import { load } from './b.js';\ntest('b', async () => { expect((await load()).c).toBe(1); });\n");
writeFileSync(join(fixture, 'plain.test.js'), "test('plain', () => { expect(1).toBe(1); });\n");
- const vitest = join(import.meta.dirname, '..', 'server', 'node_modules', '.bin', 'vitest');
+ // Vitest's JS entry through node: the .bin shim cannot be started by spawnSync on Windows.
+ const vitest = join(import.meta.dirname, '..', 'server', 'node_modules', 'vitest', 'vitest.mjs');
const env = { ...process.env, NODE_ENV: 'test', TMPDIR: host, TMP: host, TEMP: host, NODE_DISABLE_COMPILE_CACHE: '1', PORTOS_CI_TEST_SELECTION: '' };
delete env.PORTOS_TEST_TEMP_ROOT;
const viaVitest = (source) => {
const report = join(fixture, `${source}.json`);
- const result = spawnSync(vitest, ['related', `./${source}`, '--run', '--config', join(fixture, 'vitest.config.mjs'), '--root', fixture,
+ const result = spawnSync(process.execPath, [vitest, 'related', `./${source}`, '--run', '--config', join(fixture, 'vitest.config.mjs'), '--root', fixture,
'--reporter=json', `--outputFile=${report}`, '--passWithNoTests'], { cwd: fixture, encoding: 'utf8', env, timeout: 60000 });
expect(result.error).toBeUndefined();
return JSON.parse(readFileSync(report, 'utf8')).testResults.map(suite => suite.name.replace(/\\/g, '/').split('/').pop()).sort();