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

Resolve Chrome like the suites, key python bound from resolveTestPython, and walk every directory Vitest collects

[._.]/ Adam Eivy8a2b2cf78378
diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.md
index 5a583a5f77..73828b4bbf 100644
--- a/docs/GITHUB_ACTIONS.md
+++ b/docs/GITHUB_ACTIONS.md
@@ -817,8 +817,11 @@ added for the test itself); the installed version of every package the
members reach (so a lockfile bump invalidates exactly the suites that reach
the bumped packages); a Python sidecar's resolvable sibling imports; the
version of an external program a member reaches (`TEST_MEMO_TOOLS`: the
-python the sidecar tests spawn, ffmpeg/ffprobe, and Chrome for the browser
-suites); the workspace Vitest config closure, setup files,
+python the sidecar tests spawn — a literal, `PORTOS_TEST_PYTHON`, or an
+interpreter bound from `resolveTestPython()`; ffmpeg/ffprobe; and Chrome for
+the browser suites, found with the suites' own candidate list,
+`resolveTestChrome` in `server/lib/browserSuiteGate.js`); an unknown program
+handed a `.py` file fails closed; the workspace Vitest config closure, setup files,
`scripts/vitestCiPool.js`, `package.json` and lockfile; the full Node
version, `process.platform`, `process.arch`; and `TEST_MEMO_ENV` (`CI`,
`NODE_ENV`, `PORTOS_BROWSER_TEST_PROFILE`, `PORTOS_CI_BROWSER_OWNER`,
diff --git a/scripts/lib/testMemo.js b/scripts/lib/testMemo.js
index 95ce337b63..5654de617f 100644
--- a/scripts/lib/testMemo.js
+++ b/scripts/lib/testMemo.js
@@ -114,6 +114,8 @@ export const TEST_MEMO_NEVER = Object.freeze({
'client/src/hooks/index.test.js': 'enumerates the client/src/hooks directory against its README and barrel',
'client/src/utils/index.test.js': 'enumerates the client/src/utils directory against its README and barrel',
'client/src/services/index.test.js': 'enumerates the client/src/services directory against its catalog',
+ 'scripts/lib/workspaceTests.test.js': 'enumerates the server workspace against vitest list',
+ 'client/src/test/workspaceTests.test.js': 'enumerates the client workspace against vitest list',
});
/**
@@ -707,6 +709,12 @@ export function extractFileFacts(src, { fileRel, cwdRel }) {
const match = matchBrackets(tokens);
const ctx = { fileRel, cwdRel, tokens, match, bindings: collectBindings(tokens), bindingValues: new Map(), resolving: new Set() };
for (const spec of staticEdges(tokens, match)) facts.edges.push({ spec, kind: 'static' });
+ // `const load = createRequire(import.meta.url)` makes `load(...)` a native require;
+ // `const pyBin = resolveTestPython()` makes `pyBin` the python interpreter.
+ const boundTo = (callee) => new Set([...ctx.bindings].filter(([, at]) => tokens[at]?.t === 'id' && tokens[at].v === callee && tokens[at + 1]?.v === '(').map(([name]) => name));
+ const requireNames = new Set(['require', ...boundTo('createRequire')]);
+ const pythonNames = boundTo('resolveTestPython');
+ const PYTHON_NAME = /^(?:py|python3?|py(?:thon)?(?:Bin|Path|Cmd|Exe))$/i;
const code = tokens.map((t) => (t.t === 's' ? `'${t.v}'` : t.t === 'tpl' ? `\`${t.quasis.join('${}')}\`` : t.t === 'id' || t.t === 'p' ? t.v : '0')).join(' ');
if (GIT_SPAWN.test(code)) facts.git = true;
@@ -769,7 +777,7 @@ export function extractFileFacts(src, { fileRel, cwdRel }) {
const receiver = isMember ? tokens[i - 2] : null;
// Module edges that the static pass cannot see.
- if ((token.v === 'import' || token.v === 'require') && open !== null && !isMember) {
+ if ((token.v === 'import' || requireNames.has(token.v)) && open !== null && !isMember) {
const kind = token.v === 'import' ? 'dynamic' : 'require';
const arg = literalArg(open);
if (arg.kind === 'literal') { facts.edges.push({ spec: arg.value, kind }); continue; }
@@ -799,9 +807,20 @@ export function extractFileFacts(src, { fileRel, cwdRel }) {
} else if (arg.kind === 'expr') {
const { value } = evaluate(tokens, match, arg.index, ctx);
if (value.k === 'path') record(value, { walk: true, consumer: token.v });
- // `spawn(process.env.PORTOS_TEST_PYTHON || 'python3', …)`: the program expression names python.
+ // `spawn(process.env.PORTOS_TEST_PYTHON || 'python3', …)`, `spawn(pyBin, …)` with
+ // `const pyBin = resolveTestPython()`: the program expression names python.
+ let python = false;
for (let j = arg.index; j < match[open] && !(tokens[j].t === 'p' && tokens[j].v === ','); j += 1) {
- if ((tokens[j].t === 'id' && tokens[j].v === 'PORTOS_TEST_PYTHON') || (tokens[j].t === 's' && /^python3?$/.test(tokens[j].v))) facts.tools.add('python');
+ const t = tokens[j];
+ if ((t.t === 'id' && (t.v === 'PORTOS_TEST_PYTHON' || pythonNames.has(t.v) || PYTHON_NAME.test(t.v))) || (t.t === 's' && /^python3?$/.test(t.v))) python = true;
+ }
+ if (python) facts.tools.add('python');
+ else if (value.k === 'unknown' || value.k === 'ext') {
+ // An unknown program handed a .py file is an interpreter the key cannot name.
+ for (let j = open + 1; j < match[open]; j += 1) {
+ const literal = tokens[j].t === 's' ? tokens[j].v : tokens[j].t === 'tpl' ? tokens[j].quasis.join('') : '';
+ if (/\.py$/.test(literal)) { facts.unresolvedInputs.push('spawns an unknown program with a python sidecar'); break; }
+ }
}
}
const close = match[open];
@@ -986,14 +1005,15 @@ export function createTestMemoAnalyzer({ fs, workspaceRel, env = {}, platform =
const text = fs.read(target)?.toString('utf8') ?? '';
const dir = posix.dirname(target);
for (const line of text.split('\n')) {
- const m = /^\s*(?:from\s+(\.*[\w.]*)\s+import\b|import\s+([\w.]+))/.exec(line);
+ const m = /^\s*(?:from\s+(\.*[\w.]*)\s+import\b|import\s+([\w.]+(?:\s*,\s*[\w.]+)*))/.exec(line);
if (!m) continue;
- const name = m[1] ?? m[2];
- const relative = name.startsWith('.');
- const head = name.replace(/^\.+/, '').split('.')[0];
- const candidate = [`${dir}/${head}.py`, `${dir}/${head}/__init__.py`].find((rel) => fs.kind(rel) === 'file');
- if (candidate) addPython(candidate, seen);
- else if (relative) resolved.unresolvedInputs.push(`python import ${name} in ${target} does not resolve`);
+ for (const name of (m[1] !== undefined ? [m[1]] : m[2].split(',')).map((part) => part.trim()).filter(Boolean)) {
+ const relative = name.startsWith('.');
+ const head = name.replace(/^\.+/, '').split('.')[0];
+ const candidate = [`${dir}/${head}.py`, `${dir}/${head}/__init__.py`].find((rel) => fs.kind(rel) === 'file');
+ if (candidate) addPython(candidate, seen);
+ else if (relative) resolved.unresolvedInputs.push(`python import ${name} in ${target} does not resolve`);
+ }
}
};
const addFile = (target, { edge = false } = {}) => {
diff --git a/scripts/lib/testMemo.test.js b/scripts/lib/testMemo.test.js
index 247dd799db..af5cb3604c 100644
--- a/scripts/lib/testMemo.test.js
+++ b/scripts/lib/testMemo.test.js
@@ -171,6 +171,10 @@ describe('recorded key', () => {
test: ["import { it } from 'vitest';", "import { createRequire } from 'node:module';", "const require = createRequire(import.meta.url);", "const legacy = require('../routes/legacy.cjs');", 'it(\'u\', () => {});'],
mutate: 'server/routes/legacy.cjs',
},
+ 'createRequire under another name': {
+ test: ["import { it } from 'vitest';", "import { createRequire } from 'node:module';", "const load = createRequire(import.meta.url);", "const legacy = load('../routes/legacy.cjs');", 'it(\'u\', () => {});'],
+ mutate: 'server/routes/legacy.cjs',
+ },
'shared source reader': {
test: ["import { it } from 'vitest';", "import { readServerSource } from './testHelper.js';", "it('r', () => readServerSource('routes/x.js'));"],
mutate: 'server/routes/x.js',
@@ -220,8 +224,16 @@ describe('python sidecars, external tools and machine-local state', () => {
expect(key({ ...files, 'scripts/_pins.py': 'PINS = 2\n' }).key).not.toBe(base.key);
expect(key(files, { toolVersion: () => 'Python 3.13.0' }).key).not.toBe(base.key);
expect(key({ ...files, 'scripts/tool.py': 'from .missing import x\n' }).memoizable).toBe(false);
+ // `import a, b` names two siblings.
+ expect(key({ ...files, 'scripts/tool.py': 'import _common, _pins\n', 'scripts/_pins.py': 'PINS = 3\n' }).key).not.toBe(key({ ...files, 'scripts/tool.py': 'import _common, _pins\n' }).key);
// A test that never reaches python does not carry its version.
expect(keyOf(TREE, 'server/lib/a.test.js', { toolVersion: () => 'Python 3.13.0' }).floor.key).toBe(keyOf(TREE).floor.key);
+ // The interpreter resolved through the shared helper is python too; an unknown program given a .py file is not memoizable.
+ const viaHelper = { ...files, 'server/lib/testHelper.js': "export const resolveTestPython = () => 'python3';\n",
+ 'scripts/tool.test.js': ["import { it } from 'vitest';", "import { spawnSync } from 'node:child_process';", "import { resolveTestPython } from '../server/lib/testHelper.js';", 'const pyBin = resolveTestPython();', "it('p', () => spawnSync(pyBin, [new URL('./tool.py', import.meta.url).pathname]));"].join('\n') };
+ expect(key(viaHelper).key).not.toBe(key(viaHelper, { toolVersion: () => 'Python 3.13.0' }).key);
+ const unknownProgram = { ...files, 'scripts/tool.test.js': ["import { it } from 'vitest';", "import { spawnSync } from 'node:child_process';", "it('p', () => spawnSync(process.env.INTERPRETER, [new URL('./tool.py', import.meta.url).pathname]));"].join('\n') };
+ expect(key(unknownProgram)).toMatchObject({ memoizable: false, reason: expect.stringContaining('unknown program') });
});
it('fails closed when the test or repository tooling reads the install data tree or the home directory, and ignores a product module doing so', () => {
diff --git a/scripts/lib/testMemoRunner.js b/scripts/lib/testMemoRunner.js
index 18c145e34e..27b1679790 100644
--- a/scripts/lib/testMemoRunner.js
+++ b/scripts/lib/testMemoRunner.js
@@ -28,10 +28,10 @@ import { spawnSync } from 'node:child_process';
import { createHash } from 'node:crypto';
import * as nodeFs from 'node:fs';
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, relative, sep } from 'node:path';
+import { resolveTestChrome } from '../../server/lib/browserSuiteGate.js';
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';
@@ -237,10 +237,11 @@ export function clearVitestDependencies(repoRoot, scope) {
/**
* Version strings for `TEST_MEMO_TOOLS`, resolved once per process the way
* the suites find the programs: `PORTOS_TEST_PYTHON` or `python3`, `ffmpeg`
- * on PATH, and Chrome through `CHROME_PATH` or playwright-core's bundled
- * Chromium. Null (keyed as `absent`) when the program cannot be run.
+ * on PATH, and Chrome through the suites' own candidate list
+ * (`resolveTestChrome`). Null (keyed as `absent`) when the program cannot
+ * be run.
*/
-export function createToolVersionResolver({ repoRoot, env = process.env } = {}) {
+export function createToolVersionResolver({ env = process.env } = {}) {
const cache = new Map();
const firstLine = (command, args) => {
if (!command) return null;
@@ -248,15 +249,11 @@ export function createToolVersionResolver({ repoRoot, env = process.env } = {})
if (result.error || result.status !== 0) return null;
return `${result.stdout}${result.stderr}`.trim().split('\n')[0] || null;
};
- const chromeBinary = () => {
- if (env.CHROME_PATH) return env.CHROME_PATH;
- try { return createRequire(join(repoRoot, 'server', 'package.json'))('playwright-core').chromium.executablePath(); } catch { return null; }
- };
return (tool) => {
if (cache.has(tool)) return cache.get(tool);
const version = tool === 'python' ? firstLine(env.PORTOS_TEST_PYTHON || 'python3', ['--version'])
: tool === 'ffmpeg' ? firstLine('ffmpeg', ['-version'])
- : tool === 'chrome' ? firstLine(chromeBinary(), ['--version'])
+ : tool === 'chrome' ? firstLine(resolveTestChrome(env), ['--version'])
: null;
cache.set(tool, version);
return version;
diff --git a/scripts/lib/workspaceTests.js b/scripts/lib/workspaceTests.js
index f03692ec98..ed9a3b25f6 100644
--- a/scripts/lib/workspaceTests.js
+++ b/scripts/lib/workspaceTests.js
@@ -17,8 +17,14 @@ 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']);
+/**
+ * Directories never walked: exactly what both Vitest configs exclude at any
+ * depth (`**\/node_modules/**`, `**\/.git/**`). Anything else — a `data`,
+ * `dist` or `.cache` directory with a test file in it — Vitest would
+ * collect, so the walker must see it too; the `vitest list` parity tests
+ * pin that.
+ */
+const SKIP_DIRS = new Set(['node_modules', '.git']);
/**
* The server runner covers server, scripts/migrations, lib, autofixer and the
diff --git a/scripts/run-ci-tests.js b/scripts/run-ci-tests.js
index 6e66733f26..7f8c8cdaa9 100644
--- a/scripts/run-ci-tests.js
+++ b/scripts/run-ci-tests.js
@@ -462,7 +462,7 @@ async function main() {
// run already verified, and the list reaches Vitest as a file because a
// related set can exceed the Windows command-line limit.
if (memoDir) clearVitestDependencies(repoRoot, scope);
- const plan = planTestMemo({ scope, mode, repoFiles, repoSources, memoDir, repoRoot, shard, toolVersion: createToolVersionResolver({ repoRoot }) });
+ const plan = planTestMemo({ scope, mode, repoFiles, repoSources, memoDir, repoRoot, shard, toolVersion: createToolVersionResolver() });
if (memoDir) {
console.log(memoSummaryLine(plan));
if (process.env.PORTOS_TEST_MEMO_VERBOSE === '1') {
diff --git a/server/lib/README.md b/server/lib/README.md
index 2da096b270..aa74d56c3f 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -776,7 +776,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| Module | Purpose |
|---|---|
-| `browserSuiteGate.js` | `probeChromeH264(path)` runs the H.264 probe as an owned, deadline-bound child (own process group, SIGTERM→SIGKILL ladder awaiting `close`) and resolves `{ ok }` or `{ ok:false, cause }` — `missing-executable`, `codec-unavailable`, `probe-timeout`, `teardown-failed` (answered, then exited nonzero: never trusted, never a missing codec), `no-answer`; `describeH264Probe` is its path/PID-free one-liner; `chromeWithH264(path)` (async) returns the path only when that Chrome decodes H.264, null when the executable or codec is genuinely absent, and `{ probeFailure }` when the probe itself failed (reported by `browserSuiteCanRun` as a lifecycle failure, not a missing prerequisite); `browserSuiteCanRun(label, prerequisites)` is the `canRun` guard for the cross-workspace `*.browser.test.js` suites (Chrome + ffmpeg + the client bundler). Pass `{ name: discoveredValue }`; a falsy value is missing. Returns `false` with a visible skip log locally, but throws naming the missing prerequisites when `PORTOS_REQUIRE_BROWSER_SUITES` is set; `browserSuiteBlockReason(prerequisites)` is that verdict alone (the same wording, or `null`) for a caller that only reports, such as `scripts/pregate.js` — the flag the CI `database` job sets for the browser suites the planner selected (#10312). |
+| `browserSuiteGate.js` | `probeChromeH264(path)` runs the H.264 probe as an owned, deadline-bound child (own process group, SIGTERM→SIGKILL ladder awaiting `close`) and resolves `{ ok }` or `{ ok:false, cause }` — `missing-executable`, `codec-unavailable`, `probe-timeout`, `teardown-failed` (answered, then exited nonzero: never trusted, never a missing codec), `no-answer`; `describeH264Probe` is its path/PID-free one-liner; `chromeWithH264(path)` (async) returns the path only when that Chrome decodes H.264, null when the executable or codec is genuinely absent, and `{ probeFailure }` when the probe itself failed (reported by `browserSuiteCanRun` as a lifecycle failure, not a missing prerequisite); `browserSuiteCanRun(label, prerequisites)` is the `canRun` guard for the cross-workspace `*.browser.test.js` suites (Chrome + ffmpeg + the client bundler). Pass `{ name: discoveredValue }`; a falsy value is missing. Returns `false` with a visible skip log locally, but throws naming the missing prerequisites when `PORTOS_REQUIRE_BROWSER_SUITES` is set; `browserSuiteBlockReason(prerequisites)` is that verdict alone (the same wording, or `null`) for a caller that only reports, such as `scripts/pregate.js` — the flag the CI `database` job sets for the browser suites the planner selected (#10312). `resolveTestChrome(env)` is the one Chrome candidate list (`CHROME_PATH`, Playwright's bundled Chromium, then the macOS app and the Linux package paths) shared by the suites, the pregate probe and the test memo's tool keying (#12293). |
| `dbTestGate.js` | `requireDbOrSkip(label, dbReady, reason)` keeps a missing local test database as a visible skipped suite, but throws when `PORTOS_REQUIRE_DB` is set so CI cannot pass after DB-backed suites disappear. |
| `gitTestRepo.js` | Shared real-git sandbox for integration tests (#4394): one initialized template (working tree + bare origin) per worker, then `fs.cp` into a fresh temp dir. `makeGitSandbox({ origin })`, `attachBareOrigin(scratch, repo)`, `materializeGitRepo(dest)`, `destroyGitSandbox`, plus `SKIP_HEAVY_INTEGRATION` (`VITEST_FAST=1`). `resetGitSandbox({ scratch, repo, initialHead })` / `resetGitWorktreeSandbox(repo, initialHead)` restore a sandbox in place (branches, worktrees, remote) so a `describe` can build one sandbox in `beforeAll` and reset between tests instead of paying the fs.cp/rm cycle per test (#5902). Every entry point runs `assertTempPath` first, so a path outside `os.tmpdir()` throws instead of `git init`-ing or `rm -rf`-ing a real checkout (#4554). Fixture-local maintenance/GC detachment is disabled so awaited Git operations retain their writers through teardown. Still real git — just not rebuilt from `init`+`commit`+`push` in every `beforeEach`. |
| `mirrorParity.js` | Source-extraction and comparison primitives for declaration-level contract tests: the vendored `aiToolkit/` copy of `TOOL_USE_RE` (`localModelHeuristics.mirror.test.js`), and the bootstrap sequence's body assertions (`bootstrap*.test.js`). A pure module the browser needs is imported by the client rather than mirrored, so no client↔server copy test should need these: `stripCommentsAndNormalize` (so per-side commentary may diverge but logic may not), `extractDeclaration(src, name)` (balanced `{}`/`()`/`[]` walk over `function` / `async function` / `const`), and `compareDeclaration(serverSrc, clientSrc, name)`. Use these instead of hand-rolling a brace-walker per mirror. Pure — no `vitest` import — so callers own the assertions. |
diff --git a/server/lib/browserSuiteGate.js b/server/lib/browserSuiteGate.js
index 308971af45..877e0a64b7 100644
--- a/server/lib/browserSuiteGate.js
+++ b/server/lib/browserSuiteGate.js
@@ -1,8 +1,35 @@
import { spawn } from './childProcess.js';
-import { mkdtempSync, rmSync } from 'node:fs';
+import { existsSync, mkdtempSync, rmSync } from 'node:fs';
+import { createRequire } from 'node:module';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
+/**
+ * Where the browser suites look for a Chrome after `CHROME_PATH` and
+ * Playwright's bundled Chromium: the macOS app and the Linux package paths.
+ * One list for the suites, the pregate probe and the test memo (#12293).
+ */
+const TEST_CHROME_CANDIDATES = Object.freeze([
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
+ '/usr/bin/google-chrome',
+ '/usr/bin/chromium',
+ '/usr/bin/chromium-browser',
+]);
+
+/** Playwright's bundled Chromium, when playwright-core is installed and a browser was downloaded; null otherwise. */
+function bundledChromium() {
+ try { return createRequire(import.meta.url)('playwright-core').chromium.executablePath(); } catch { return null; }
+}
+
+/**
+ * The Chrome binary a browser suite would launch on this machine, or null:
+ * `env.CHROME_PATH`, then Playwright's bundled Chromium, then the macOS app
+ * and the Linux package paths, the first that exists.
+ */
+export function resolveTestChrome(env = process.env, { exists = existsSync, bundled = bundledChromium } = {}) {
+ return [env.CHROME_PATH, bundled(), ...TEST_CHROME_CANDIDATES].find((path) => path && exists(path)) ?? null;
+}
+
/**
* Keep cross-workspace browser suites as visible skips on machines without
* Chrome, ffmpeg or the client workspace, while letting the one CI job that
diff --git a/server/lib/browserSuiteGate.test.js b/server/lib/browserSuiteGate.test.js
index 2e4d337420..191075f935 100644
--- a/server/lib/browserSuiteGate.test.js
+++ b/server/lib/browserSuiteGate.test.js
@@ -2,7 +2,17 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
-import { browserSuiteCanRun, chromeWithH264, describeH264Probe, probeChromeH264 } from './browserSuiteGate.js';
+import { browserSuiteCanRun, chromeWithH264, describeH264Probe, probeChromeH264, resolveTestChrome } from './browserSuiteGate.js';
+
+describe('resolveTestChrome', () => {
+ it('prefers CHROME_PATH, then the bundled Chromium, then the first installed package path, and reports none', () => {
+ const exists = (path) => ['/usr/bin/chromium', '/opt/chrome', '/pw/chrome'].includes(path);
+ expect(resolveTestChrome({ CHROME_PATH: '/opt/chrome' }, { exists, bundled: () => '/pw/chrome' })).toBe('/opt/chrome');
+ expect(resolveTestChrome({ CHROME_PATH: '/missing/chrome' }, { exists, bundled: () => '/pw/chrome' })).toBe('/pw/chrome');
+ expect(resolveTestChrome({}, { exists, bundled: () => null })).toBe('/usr/bin/chromium');
+ expect(resolveTestChrome({}, { exists: () => false, bundled: () => null })).toBeNull();
+ });
+});
const original = process.env.PORTOS_REQUIRE_BROWSER_SUITES;