Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(tests): every test runs on a private machine, not the host [C7]
Corey Olson3bbaa7d25535
diff --git a/bin/run-tests.js b/bin/run-tests.jsindex 98b9d5bd..062d70c5 100644--- a/bin/run-tests.js+++ b/bin/run-tests.js@@ -14,6 +14,7 @@ import { Worker } from 'node:worker_threads';import { randomUUID } from 'node:crypto';import { channel } from 'node:diagnostics_channel';import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';+import { foreignNodeOptions, isolateTestMachine } from '../src/test-isolation.js';const runner = fileURLToPath(import.meta.url);const LANDING_RUN_ENV = 'PULLBOARD_LANDING_RUN';const LANDING_WORKER_STARTS_ENV = 'PULLBOARD_LANDING_WORKER_STARTS';@@ -221,6 +222,7 @@ function testEnvironment(sandbox, gateMarkers = {}) {env.PULLBOARD_HOME = home;env.PULLBOARD_MODEL = 'Test Model';env.PULLBOARD_MACHINE_HOME = join(sandbox, 'machine');+ isolateTestMachine(env, sandbox); // #1068: no settings, resources, runners or host markers of the real machine.// init and resume start a background view by default; a test opts back in by deleting this.env.PULLBOARD_VIEW_BACKGROUND = '0';env.TMPDIR = sandbox;@@ -463,7 +465,7 @@ function parseLandingProcessTable(output) {/** Snapshot process identities on POSIX hosts, where the runner can verify process ancestry. */function landingProcessTable() {if (process.platform === 'win32') return [];- const output = execFileSync('ps', ['-axo', 'pid=,ppid=,pgid=,stat=,lstart=,command='], { encoding: 'utf8', timeout: 2000 });+ const output = execFileSync('ps', ['-axo', 'pid=,ppid=,pgid=,stat=,lstart=,command='], { encoding: 'utf8', timeout: 2000, maxBuffer: 64 << 20 });return parseLandingProcessTable(output);}@@ -495,7 +497,7 @@ async function landingWorkerIdentity(pid, timeoutMs = LANDING_WORKER_IDENTITY_TItry {const output = await new Promise((resolveOutput, rejectOutput) => {const child = execFile('ps', ['-axo', 'pid=,ppid=,pgid=,stat=,lstart=,command='], {- encoding: 'utf8', timeout: Math.min(2000, Math.max(1, remaining)),+ encoding: 'utf8', timeout: Math.min(2000, Math.max(1, remaining)), maxBuffer: 64 << 20,}, (error, stdout) => {if (snapshotChild === child) snapshotChild = null;error ? rejectOutput(error) : resolveOutput(stdout);@@ -1308,7 +1310,7 @@ function namesOnlyTestFiles(args) {if (!knownNodeOptions.has(option)) return false;if (!argument.includes('=')) takesValue = requiresValue;}- if (takesValue || process.env.NODE_OPTIONS) return false;+ if (takesValue || foreignNodeOptions(process.env.NODE_OPTIONS)) return false;const files = explicitTestFiles(args);if (!files.length) return false;try {diff --git a/src/browser-admission.js b/src/browser-admission.jsindex f344a0b6..57fba1a1 100644--- a/src/browser-admission.js+++ b/src/browser-admission.js@@ -23,6 +23,7 @@ import {cleanGitEnvironment,git,} from './git.js';+import { foreignNodeOptions } from './test-isolation.js';const MODULE_SUFFIXES = ['.js', '.mjs', '.cjs', '.cts', '.json'];const CHROME_FIXTURE = 'test/chrome-fixture.js';@@ -286,23 +287,9 @@ function browserFallback(onFallback, file, reason) {return true;}-/** The runner's launch guard preload for browser-free test files (gate.browserByLaunch): it loads only src/browser-slot-guard.js. */-const SLOT_GUARD_IMPORT = `--import=${new URL('./browser-slot-guard.js', import.meta.url).href}`;--/**- * Whether NODE_OPTIONS may load a module the classifier has not seen. The one exception is this checkout's- * own launch guard, which a browser-free test file passes to its children; anything else is unclassified.- *- * @param {string | undefined} value- * @returns {boolean}- */-function unclassifiedNodeOptions(value) {- return String(value ?? '').split(/\s+/u).filter(Boolean).some(token => token !== SLOT_GUARD_IMPORT);-}-/** Parse the frozen check and classify its explicit test files, failing closed on unknown shell. */export async function checkNeedsBrowser(root, command, { commit, env = process.env, onFallback } = {}) {- if (unclassifiedNodeOptions(env.NODE_OPTIONS)) return browserFallback(onFallback, '<frozen check>', 'NODE_OPTIONS may load an unclassified module');+ if (foreignNodeOptions(env.NODE_OPTIONS, env)) return browserFallback(onFallback, '<frozen check>', 'NODE_OPTIONS may load an unclassified module');let words = literalShellWords(command);if (!words) {const inner = capturedRunner(command);@@ -345,7 +332,7 @@ export async function checkNeedsBrowser(root, command, { commit, env = process.e* @returns {Promise<string[] | null>}*/export async function explicitCheckFiles(root, command, { commit, env = process.env } = {}) {- if (unclassifiedNodeOptions(env.NODE_OPTIONS)) return null;+ if (foreignNodeOptions(env.NODE_OPTIONS, env)) return null;let words = literalShellWords(command);if (!words) {const inner = capturedRunner(command);diff --git a/src/machine-home.js b/src/machine-home.jsindex f8dfcd8a..b7d7e903 100644--- a/src/machine-home.js+++ b/src/machine-home.js@@ -6,10 +6,14 @@ import {} from 'node:path';import { Refused } from './refused.js';-/** Use the OS account home unless a caller explicitly selects a private machine pool. */+/**+ * Use the OS account home unless a caller explicitly selects a private machine pool. A test run substitutes its own+ * account home (PULLBOARD_ACCOUNT_HOME, src/test-isolation.js) so a test never reads the machine it runs on.+ */export function machineHome() {const override = process.env.PULLBOARD_MACHINE_HOME;- return override ? resolve(override) : join(userInfo().homedir, '.pullboard');+ if (override) return resolve(override);+ return join(resolve(process.env.PULLBOARD_ACCOUNT_HOME || userInfo().homedir), '.pullboard');}/** Name inaccessible machine storage without disguising corruption or other database failures. */diff --git a/src/runner-worker.js b/src/runner-worker.jsindex 083898fc..8dcc770f 100644--- a/src/runner-worker.js+++ b/src/runner-worker.js@@ -241,7 +241,8 @@ function childEnvironment(home, temporary, machineHomePath = '', nodeOptions = 'GIT_OPTIONAL_LOCKS: '0',NPM_CONFIG_USERCONFIG: join(home, 'npm-userconfig'),NPM_CONFIG_GLOBALCONFIG: join(home, 'npm-globalconfig'),- ...(nodeOptions ? { NODE_OPTIONS: nodeOptions } : {}),+ // The spawn-journal preload is declared so a test's NODE_OPTIONS classifier knows it is the runner's own.+ ...(nodeOptions ? { NODE_OPTIONS: nodeOptions, PULLBOARD_RUNNER_PRELOAD: nodeOptions } : {}),...(machineHomePath ? { PULLBOARD_MACHINE_HOME: machineHomePath } : {}),};}diff --git a/src/test-isolation.js b/src/test-isolation.jsnew file mode 100644index 00000000..5a0e0c19--- /dev/null+++ b/src/test-isolation.js@@ -0,0 +1,54 @@+/**+ * Every test process sees its own private machine, never the one it runs on [C7].+ *+ * A test's verdict must not depend on where it runs: the person's ~/.pullboard settings (gateSlots, browserSlots,+ * gate.shortSlots, registered runners), the account's resources.sqlite, a CI marker a runner sets, or the+ * instrumentation an SSH runner loads into every Node process. bin/run-tests.js applies this to each test run.+ */+import { mkdirSync } from 'node:fs';+import { join } from 'node:path';++/** Stands in for the OS account home when machine state falls back to it (src/machine-home.js). */+export const ACCOUNT_HOME_ENV = 'PULLBOARD_ACCOUNT_HOME';++/** An SSH runner names the spawn-journal preload it puts in NODE_OPTIONS, so classifiers can tell it from a foreign one. */+export const RUNNER_PRELOAD_ENV = 'PULLBOARD_RUNNER_PRELOAD';++/** The launch guard a browser-free test file passes to its Node children (gate.browserByLaunch). */+const SLOT_GUARD_IMPORT = `--import=${new URL('./browser-slot-guard.js', import.meta.url).href}`;++/** The shape of the runner's own journal preload; a declared value of any other shape is not trusted. */+const RUNNER_PRELOAD = /^--import=file:\/\/\S+\/child-spawn-preload\.mjs$/u;++/**+ * Point every machine-state fallback of a test run at its sandbox and drop host markers tests model explicitly.+ * A test that wants a hostile machine builds one in its own fixture; it never inherits the real one.+ *+ * @param {NodeJS.ProcessEnv} env the test environment, changed in place+ * @param {string} sandbox the run's private directory+ * @returns {NodeJS.ProcessEnv}+ */+export function isolateTestMachine(env, sandbox) {+ const account = join(sandbox, 'account');+ mkdirSync(account, { recursive: true });+ env[ACCOUNT_HOME_ENV] = account;+ // A runner sets CI=1 and a person may pin their view port; tests that care set either explicitly.+ delete env.CI;+ delete env.PULLBOARD_VIEW_PORT;+ return env;+}++/**+ * Whether NODE_OPTIONS may load a module the classifier has not seen. This checkout's launch guard and the preload+ * an SSH runner declares are known; anything else is foreign, so the run is not classified as short or browser-free.+ *+ * @param {string | undefined} value NODE_OPTIONS+ * @param {NodeJS.ProcessEnv} [env] where a runner's declared preload is read+ * @returns {boolean}+ */+export function foreignNodeOptions(value, env = process.env) {+ const declared = env[RUNNER_PRELOAD_ENV];+ const known = new Set([SLOT_GUARD_IMPORT]);+ if (declared && RUNNER_PRELOAD.test(declared)) known.add(declared);+ return String(value ?? '').split(/\s+/u).filter(Boolean).some(token => !known.has(token));+}diff --git a/test/background-view.test.js b/test/background-view.test.jsindex 755b50af..0938e077 100644--- a/test/background-view.test.js+++ b/test/background-view.test.js@@ -51,7 +51,7 @@ async function stopView(pid) {/** The pids of view processes on this test's leased port, listed (never killed) from ps. */function viewProcesses(port) {- const listed = spawnSync('ps', ['-A', '-o', 'pid=,command='], { encoding: 'utf8' });+ const listed = spawnSync('ps', ['-A', '-o', 'pid=,command='], { encoding: 'utf8', maxBuffer: 64 << 20 });return listed.stdout.split('\n').filter((line) => line.includes('pullboard.js view --no-open') && line.includes(`--port ${port}`)).map((line) => Number(line.trim().split(/\s+/u)[0]));diff --git a/test/runners.test.js b/test/runners.test.jsindex d09eb06d..2fe80738 100644--- a/test/runners.test.js+++ b/test/runners.test.js@@ -731,7 +731,7 @@ console.log('RUNNER_JOURNAL_FILES ' + readdirSync(journal).filter(name => /^chil/** List live processes whose command line mentions a fixture directory. */function processesUnder(dir) {- const listed = runFixtureChild('/bin/ps', ['-axo', 'pid=,command='], { encoding: 'utf8' });+ const listed = runFixtureChild('/bin/ps', ['-axo', 'pid=,command='], { encoding: 'utf8', maxBuffer: 64 << 20 });assert.equal(listed.status, 0, listed.context);return listed.stdout.split('\n').filter(line => line.includes(dir) && !line.includes('/bin/ps'));}diff --git a/test/settings.test.js b/test/settings.test.jsindex fb3b6887..46392b84 100644--- a/test/settings.test.js+++ b/test/settings.test.js@@ -49,9 +49,12 @@ test('[Q4] the machine pool ignores board and HOME overrides unless explicitly sconst script = `import { machineHome } from ${JSON.stringify(MACHINE_HOME_MODULE)}; process.stdout.write(machineHome());`;const env = { ...process.env, HOME: '/private/home', PULLBOARD_HOME: '/private/board' };delete env.PULLBOARD_MACHINE_HOME;+ delete env.PULLBOARD_ACCOUNT_HOME;const defaultHome = spawnSync(process.execPath, ['--input-type=module', '-e', script], { encoding: 'utf8', env });assert.equal(defaultHome.status, 0, defaultHome.stderr);assert.equal(defaultHome.stdout, join(userInfo().homedir, '.pullboard'));+ const account = spawnSync(process.execPath, ['--input-type=module', '-e', script], { encoding: 'utf8', env: { ...env, PULLBOARD_ACCOUNT_HOME: '/private/account' } });+ assert.equal(account.stdout, join('/private/account', '.pullboard'), 'a test run substitutes its own account home [C7]');const override = join(tmpdir(), 'pullboard-private-machine-home');const privateHome = spawnSync(process.execPath, ['--input-type=module', '-e', script], {diff --git a/test/test-isolation.test.js b/test/test-isolation.test.jsnew file mode 100644index 00000000..1faa0c5d--- /dev/null+++ b/test/test-isolation.test.js@@ -0,0 +1,111 @@+/** @pullboard-test-loads bin/run-tests.js src/test-isolation.js src/machine-home.js src/settings.js src/resources.js src/view-port.js */+/** A test's verdict never depends on the machine it runs on: settings, resources, runners, host markers, ports [C7]. */+import assert from 'node:assert/strict';+import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';+import { createServer } from 'node:net';+import { tmpdir } from 'node:os';+import { join, resolve } from 'node:path';+import { test } from 'node:test';+import { pathToFileURL } from 'node:url';+import { runFixtureChildAsync } from './fixture-child.js';+import { takeResource } from '../src/resources.js';+import { DEFAULT_VIEW_PORT } from '../src/view-port.js';+import { GATE_SLOT_HELD_ENV, GATE_SLOT_POOL_ENV, GATE_SLOT_TOKEN_ENV } from '../src/resources.js';++const RUNNER = resolve(import.meta.dirname, '../bin/run-tests.js');+const HOSTILE_LEASE = 'isolation-hostile-machine';+const PROBES = ['probe machine settings are the defaults', 'probe the resource pool is private',+ 'probe no host marker reaches the test', 'probe the default view port is never chosen'];++/** Build a probe suite outside the repository that reads every kind of machine state a test could reach. */+function probeSuite(dir) {+ const module = (path) => JSON.stringify(pathToFileURL(resolve(import.meta.dirname, '..', path)).href);+ const root = join(dir, 'probe');+ mkdirSync(join(root, 'test'), { recursive: true });+ writeFileSync(join(root, 'test', 'probe.test.js'), `import assert from 'node:assert/strict';+import { userInfo } from 'node:os';+import { join } from 'node:path';+import { test } from 'node:test';+import { machineHome } from ${module('src/machine-home.js')};+import { loadMachineSettings } from ${module('src/settings.js')};+import { listResources } from ${module('src/resources.js')};+import { foreignNodeOptions } from ${module('src/test-isolation.js')};+import { defaultViewPort } from ${module('src/view-port.js')};+import { chooseViewPort } from ${module('test/view-port-fixture.js')};+// A test that drops its machine home falls back to the account home, as view-port-fixture.js does.+delete process.env.PULLBOARD_MACHINE_HOME;+test(${JSON.stringify(PROBES[0])}, () => {+ assert.notEqual(machineHome(), join(userInfo().homedir, '.pullboard'), 'the OS account home is never read');+ assert.ok(!machineHome().startsWith(process.env.ISOLATION_HOSTILE_HOME + '/'), 'the hostile machine is never read');+ assert.deepEqual(loadMachineSettings(), { gateSlots: 2, browserSlots: 1 });+});+test(${JSON.stringify(PROBES[1])}, () => {+ assert.equal(listResources({ scope: 'machine' }).some((resource) => resource.name === ${JSON.stringify(HOSTILE_LEASE)}), false);+});+test(${JSON.stringify(PROBES[2])}, () => {+ assert.equal(process.env.CI, undefined);+ assert.equal(foreignNodeOptions(process.env.NODE_OPTIONS), false);+});+test(${JSON.stringify(PROBES[3])}, async () => {+ assert.equal(defaultViewPort(), ${DEFAULT_VIEW_PORT});+ assert.notEqual(await chooseViewPort(), ${DEFAULT_VIEW_PORT});+});+`);+ return root;+}++/** The verdict line of each probe, in order, so two runs compare test by test. */+function verdicts(stdout) {+ return PROBES.map((name) => stdout.split('\n').find((line) => /^(?:not )?ok \d+ - /u.test(line) && line.endsWith(name)) ?? `missing: ${name}`);+}++test('a test reads no machine state outside its own private home [C7]', async (t) => {+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-test-isolation-')));+ // Cleanups run last-registered first, so the hostile lease is released before its directory goes.+ const cleanups = [() => rmSync(dir, { recursive: true, force: true })];+ t.after(async () => { for (const cleanup of cleanups.reverse()) await cleanup(); });+ // The hostile machine: what the coordinator set on the MacBook on 23 Oct, plus a registered runner and a held lease.+ const hostile = join(dir, 'hostile-account');+ mkdirSync(join(hostile, '.pullboard'), { recursive: true });+ writeFileSync(join(hostile, '.pullboard', 'settings.json'), `${JSON.stringify({+ gateSlots: 3, browserSlots: 3, gate: { shortSlots: 2, browserByLaunch: true },+ runners: [{ host: '[email protected]', slots: 4, browser: 4 }],+ })}\n`);+ const machineHome = process.env.PULLBOARD_MACHINE_HOME;+ process.env.PULLBOARD_MACHINE_HOME = join(hostile, '.pullboard');+ let leased;+ try { leased = takeResource({ name: HOSTILE_LEASE, capacity: 1, scope: 'machine', root: dir }); }+ finally { process.env.PULLBOARD_MACHINE_HOME = machineHome; }+ const lease = await leased;+ cleanups.push(() => lease.release());+ // The default view port is busy, as the person's own view keeps it; an existing listener is left alone.+ const holder = createServer();+ await new Promise((done) => { holder.once('error', done); holder.listen(DEFAULT_VIEW_PORT, '127.0.0.1', done); });+ cleanups.push(() => holder.listening ? new Promise((done) => holder.close(done)) : undefined);+ const preload = join(dir, 'runner', 'child-spawn-preload.mjs');+ mkdirSync(join(dir, 'runner'));+ writeFileSync(preload, 'export {};\n');+ const root = probeSuite(dir);++ const base = { ...process.env, PULLBOARD_MACHINE_HOME: join(dir, 'outer-machine'), ISOLATION_HOSTILE_HOME: hostile };+ for (const key of [GATE_SLOT_HELD_ENV, GATE_SLOT_POOL_ENV, GATE_SLOT_TOKEN_ENV, 'CI', 'NODE_OPTIONS', 'NODE_TEST_CONTEXT',+ 'PULLBOARD_RUNNER_PRELOAD', 'PULLBOARD_VIEW_PORT']) delete base[key];+ const plainAccount = join(dir, 'plain-account');+ mkdirSync(plainAccount);+ const plain = { ...base, PULLBOARD_ACCOUNT_HOME: plainAccount };+ const runnerImport = `--import=${pathToFileURL(preload).href}`;+ const machine = { ...base, PULLBOARD_ACCOUNT_HOME: hostile, CI: '1', NODE_OPTIONS: runnerImport,+ PULLBOARD_RUNNER_PRELOAD: runnerImport, PULLBOARD_VIEW_PORT: '4891' };++ const calm = await runFixtureChildAsync(process.execPath, [RUNNER, 'test/probe.test.js'], { cwd: root, env: plain });+ const busy = await runFixtureChildAsync(process.execPath, [RUNNER, 'test/probe.test.js'], { cwd: root, env: machine });+ assert.deepEqual(verdicts(calm.stdout), PROBES.map((name, index) => `ok ${index + 1} - ${name}`), calm.stdout + calm.stderr);+ assert.deepEqual(verdicts(busy.stdout), verdicts(calm.stdout), `hostile machine settings changed a verdict:\n${busy.stdout}${busy.stderr}`);+ assert.equal(busy.status, 0, busy.stderr);++ // The probes are a real guard: run without the private home, the same suite reads the hostile machine and fails.+ const exposed = await runFixtureChildAsync(process.execPath, ['--test', 'test/probe.test.js'], { cwd: root, env: machine });+ assert.notEqual(exposed.status, 0, 'a test that reads the machine home fails the guard');+ const seen = verdicts(exposed.stdout);+ for (const index of [0, 1, 2]) assert.match(seen[index], /^not ok /u, `${PROBES[index]} catches the machine it reads`);+});diff --git a/test/view-port.test.js b/test/view-port.test.jsindex 71381ae6..9244f9ab 100644--- a/test/view-port.test.js+++ b/test/view-port.test.js@@ -418,7 +418,7 @@ function readFixtureViewIdentity(pid) {/** Run one bounded process inspection while suppressing stderr and never dumping command output. */function runFixtureProcessTool(command, args) {- return execFileSync(command, args, { encoding: 'utf8', timeout: 1_500, stdio: ['ignore', 'pipe', 'ignore'] });+ return execFileSync(command, args, { encoding: 'utf8', timeout: 1_500, maxBuffer: 64 << 20, stdio: ['ignore', 'pipe', 'ignore'] });}/** Run a bounded ps query for the test's own process identity checks. */