Skip to content

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.

test(chrome): compare clone prevention with a native control [C7]

Corey Olson15fa0f255e49
diff --git a/src/chrome-clone-check.js b/src/chrome-clone-check.js
new file mode 100644
index 00000000..140300dd
--- /dev/null
+++ b/src/chrome-clone-check.js
@@ -0,0 +1,33 @@
+/** Observe macOS Chrome clone growth without deleting or attributing directories [C7]. */
+import { execFileSync } from 'node:child_process';
+import { lstatSync, readdirSync, realpathSync } from 'node:fs';
+import { dirname, join } from 'node:path';
+
+/** Snapshot directory identities so concurrent old-clone removal cannot conceal a newly created clone. */
+export function chromeCloneSnapshot() {
+ if (process.platform !== 'darwin') return [];
+ const user = execFileSync('/usr/bin/getconf', ['DARWIN_USER_DIR'], { encoding: 'utf8', timeout: 2_000 }).trim();
+ const root = join(dirname(user.replace(/\/$/u, '')), 'X');
+ const result = [];
+ for (const bundle of ['com.google.Chrome', 'org.chromium.Chromium']) {
+ const directory = join(root, `${bundle}.code_sign_clone`);
+ let names;
+ let canonical;
+ try { names = readdirSync(directory); canonical = realpathSync(directory); }
+ catch (error) { if (error.code === 'ENOENT') continue; throw error; }
+ for (const name of names.filter(name => /^code_sign_clone\.[A-Za-z0-9._-]{6}$/u.test(name))) {
+ try {
+ const path = join(directory, name);
+ const stat = lstatSync(path);
+ if (stat.isDirectory() && !stat.isSymbolicLink()) result.push(`${join(canonical, name)}:${stat.dev}:${stat.ino}`);
+ } catch (error) { if (error.code !== 'ENOENT') throw error; }
+ }
+ }
+ return result.sort();
+}
+
+/** Report new identities only; this is a growth check, never evidence authorizing cleanup. */
+export function newChromeClones(before, after = chromeCloneSnapshot()) {
+ const known = new Set(before);
+ return after.filter(identity => !known.has(identity));
+}
diff --git a/test/chrome-clone-observer.js b/test/chrome-clone-observer.js
deleted file mode 100644
index 8f6f9344..00000000
--- a/test/chrome-clone-observer.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/** Read only code-sign clones mapped by this launch's live process group [C7]. */
-import { execFileSync } from 'node:child_process';
-import { lstatSync, realpathSync } from 'node:fs';
-import { dirname, join } from 'node:path';
-
-/** Resolve Apple's per-user cleanup-on-boot directory without trusting a supplied environment path. */
-function cloneRoot() {
- const user = execFileSync('/usr/bin/getconf', ['DARWIN_USER_DIR'], { encoding: 'utf8', timeout: 2_000 }).trim();
- return realpathSync(join(dirname(user.replace(/\/$/u, '')), 'X'));
-}
-
-/** Capture directory identities only while the direct owned leader still reserves its group. */
-export function observedChromeClones(child) {
- if (process.platform !== 'darwin' || !child?.pid || child.exitCode !== null || child.signalCode !== null) return [];
- const output = execFileSync('/bin/ps', ['-ww', '-axo', 'pid=,ppid=,pgid=,comm='], {
- encoding: 'utf8', timeout: 2_000, maxBuffer: 8 * 1024 * 1024,
- });
- const rows = output.split('\n').flatMap(line => {
- const match = /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.+)$/u.exec(line);
- return match ? [{ pid: Number(match[1]), ppid: Number(match[2]), pgid: Number(match[3]), executable: match[4] }] : [];
- });
- if (!rows.some(row => row.pid === child.pid && row.ppid === process.pid && row.pgid === child.pid)) return [];
- const root = cloneRoot();
- const found = new Map();
- for (const row of rows.filter(row => row.pgid === child.pid)) {
- const directory = /^(.*\/(?:com\.google\.Chrome|org\.chromium\.Chromium)\.code_sign_clone\/code_sign_clone\.[A-Za-z0-9]{6})(?:\/|$)/u.exec(row.executable)?.[1];
- if (!directory) continue;
- try {
- const canonical = realpathSync(directory);
- if (canonical !== directory || dirname(dirname(canonical)) !== root) continue;
- const stat = lstatSync(canonical);
- if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid()) continue;
- found.set(canonical, { path: canonical, dev: stat.dev, ino: stat.ino });
- } catch (error) { if (error.code !== 'ENOENT') throw error; }
- }
- return [...found.values()];
-}
diff --git a/test/chrome-clone-proof.js b/test/chrome-clone-proof.js
new file mode 100644
index 00000000..880939c4
--- /dev/null
+++ b/test/chrome-clone-proof.js
@@ -0,0 +1,66 @@
+/** Compare a native unflagged control with the actual test harness arguments [C7]. */
+import assert from 'node:assert/strict';
+import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
+import { hostname, loadavg, tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { chromeCloneSnapshot, newChromeClones } from '../src/chrome-clone-check.js';
+import { findChromeExecutable, launchChromeProcess } from './chrome-fixture.js';
+import { chromeLaunchArgs } from './chrome-launch-args.js';
+
+/** Poll one bounded native handshake; never extend a declared browser deadline. */
+async function waitUntil(predicate, timeoutMs, message) {
+ const deadline = Date.now() + timeoutMs;
+ while (Date.now() < deadline) {
+ if (predicate()) return;
+ await new Promise(resolve => setTimeout(resolve, 100));
+ }
+ assert.fail(message);
+}
+
+/** Ask only this private profile's browser to exit gracefully, preserving Chromium's own cleanup. */
+async function gracefulClose(profile, launched) {
+ if (launched.child.exitCode !== null || launched.child.signalCode !== null) return;
+ const port = readFileSync(join(profile, 'DevToolsActivePort'), 'utf8').split('\n')[0].trim();
+ assert.match(port, /^\d+$/u);
+ const response = await fetch(`http://127.0.0.1:${port}/json/version`, { signal: AbortSignal.timeout(2_000) });
+ const info = await response.json();
+ const socket = new WebSocket(info.webSocketDebuggerUrl);
+ await new Promise((resolve, reject) => {
+ const timer = setTimeout(() => { socket.close(); reject(new Error('private Chrome graceful close timed out')); }, 3_000);
+ socket.addEventListener('open', () => socket.send(JSON.stringify({ id: 1, method: 'Browser.close' })), { once: true });
+ socket.addEventListener('error', () => { clearTimeout(timer); reject(new Error('private Chrome close connection failed')); }, { once: true });
+ socket.addEventListener('close', () => { clearTimeout(timer); resolve(); }, { once: true });
+ });
+ await waitUntil(() => launched.child.exitCode !== null || launched.child.signalCode !== null, 3_000, 'native Chrome did not exit after Browser.close');
+}
+
+/** Run a real control and SIGKILL the test launch; no code deletes any clone directory. */
+export async function assertNoKilledChromeClone(t) {
+ t.diagnostic(JSON.stringify({ host: hostname(), node: process.version, load: loadavg(), chrome: findChromeExecutable() }));
+ const initial = chromeCloneSnapshot();
+ for (const control of [true, false]) {
+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-clone-proof-'));
+ const before = chromeCloneSnapshot();
+ const args = chromeLaunchArgs(profile).filter(arg => !control || arg !== '--disable-features=MacAppCodeSignClone');
+ const launched = launchChromeProcess({ executable: findChromeExecutable(), args });
+ try {
+ await waitUntil(() => existsSync(join(profile, 'DevToolsActivePort')), 15_000, 'real Chrome did not publish its private DevTools port');
+ if (control) {
+ await waitUntil(() => newChromeClones(before).length > 0, 5_000, 'unflagged native Chrome must create a clone for the control');
+ t.diagnostic(JSON.stringify({ phase: 'unflagged-control', newClones: newChromeClones(before).length }));
+ await gracefulClose(profile, launched);
+ await waitUntil(() => newChromeClones(before).length === 0, 5_000, 'Chromium must clean its own control clone after graceful shutdown');
+ } else {
+ // Give the same native startup path time to create the clone that the positive control demonstrated.
+ await new Promise(resolve => setTimeout(resolve, 1_000)); // budget: observe the native clone after DevTools readiness, before deliberate SIGKILL.
+ launched.child.kill('SIGKILL');
+ await launched.close();
+ assert.deepEqual(newChromeClones(before), [], 'the harness must prevent clones even when its Chrome is SIGKILLed');
+ }
+ } finally {
+ try { await gracefulClose(profile, launched); }
+ finally { await launched.close(); rmSync(profile, { recursive: true, force: true }); }
+ }
+ }
+ assert.deepEqual(newChromeClones(initial), [], 'the native control and killed test launch leave no new clone');
+}
diff --git a/test/chrome-fixture.js b/test/chrome-fixture.js
index b3aec42b..8d0ce890 100644
--- a/test/chrome-fixture.js
+++ b/test/chrome-fixture.js
@@ -1,3 +1,4 @@
+import { chromeLaunchArgs } from './chrome-launch-args.js';
/** Shared isolated Chrome launcher with bounded startup and complete process-group cleanup [C7]. */
import { execFileSync, spawn as spawnGuardian } from 'node:child_process';
import { startFixtureChild as spawn } from './fixture-child.js';
@@ -270,9 +271,7 @@ export async function startChrome({
const profile = resolve(profileDirectory ?? mkdtempSync(join(tmpdir(), 'pullboard-chrome-')));
mkdirSync(profile, { recursive: true, mode: 0o700 });
chmodSync(profile, 0o700);
- const args = ['--headless=new', '--disable-gpu', '--no-first-run', '--no-default-browser-check',
- '--disable-background-networking', '--disable-sync', '--disable-extensions', '--no-proxy-server',
- '--use-mock-keychain', '--password-store=basic', '--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank'];
+ const args = chromeLaunchArgs(profile);
let launched;
let socket;
let loopDelay;
diff --git a/test/chrome-fixture.test.js b/test/chrome-fixture.test.js
index d4971655..579dc1d4 100644
--- a/test/chrome-fixture.test.js
+++ b/test/chrome-fixture.test.js
@@ -1,44 +1,17 @@
/** The shared Chrome fixture bounds startup and removes profiles only after the owned process group exits [C7]. */
import assert from 'node:assert/strict';
import { once } from 'node:events';
-import { chmodSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { createServer } from 'node:http';
import { loadavg, tmpdir } from 'node:os';
import { join } from 'node:path';
import { monitorEventLoopDelay } from 'node:perf_hooks';
import { test } from 'node:test';
import { createEvaluator, createSender, createWaiter, findChromeExecutable, launchChromeProcess, startChrome, waitForTargetAbsent } from './chrome-fixture.js';
-import { observedChromeClones } from './chrome-clone-observer.js';
+import { assertNoKilledChromeClone } from './chrome-clone-proof.js';
test('a killed test Chrome leaves no code-sign clone [C7]', { skip: process.platform !== 'darwin' || !findChromeExecutable() }, async t => {
- const profile = mkdtempSync(join(tmpdir(), 'pullboard-clone-proof-'));
- let launched;
- let clones = [];
- t.after(async () => {
- await launched?.close();
- // Retain a genuine leak assertion while removing only this fixture's captured directory identities.
- for (const clone of clones) {
- try {
- const stat = lstatSync(clone.path);
- if (stat.isDirectory() && !stat.isSymbolicLink() && stat.dev === clone.dev && stat.ino === clone.ino) rmSync(clone.path, { recursive: true });
- } catch (error) { if (error.code !== 'ENOENT') throw error; }
- }
- rmSync(profile, { recursive: true, force: true });
- });
- launched = launchChromeProcess({ executable: findChromeExecutable(), args: ['--headless=new', '--disable-gpu',
- '--no-first-run', '--no-default-browser-check', '--disable-background-networking', '--disable-sync',
- '--disable-extensions', '--no-proxy-server', '--use-mock-keychain', '--password-store=basic',
- '--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank'] });
- const deadline = Date.now() + 15_000; // budget: observe the owned launch's native clone before deliberately killing it.
- while (!clones.length && Date.now() < deadline) {
- clones = observedChromeClones(launched.child);
- if (!clones.length) await pause(100);
- }
- assert.ok(clones.length, 'the real owned Chrome must expose a native clone before the kill proof');
- t.diagnostic(JSON.stringify({ ownedCloneCount: clones.length, paths: clones.map(clone => clone.path) }));
- launched.child.kill('SIGKILL');
- await launched.close();
- assert.deepEqual(clones.filter(clone => existsSync(clone.path)), [], 'teardown removes this killed launch\'s actual code-sign clones');
+ await assertNoKilledChromeClone(t);
});
/** Pause between checks while waiting for a fixture helper's readiness marker. */
diff --git a/test/chrome-launch-args.js b/test/chrome-launch-args.js
new file mode 100644
index 00000000..5a71ebea
--- /dev/null
+++ b/test/chrome-launch-args.js
@@ -0,0 +1,6 @@
+/** Shared real Chrome arguments, separate from generic Node process stand-ins [C7]. */
+export function chromeLaunchArgs(profile) {
+ return ['--headless=new', '--disable-gpu', '--no-first-run', '--no-default-browser-check',
+ '--disable-background-networking', '--disable-sync', '--disable-extensions', '--no-proxy-server',
+ '--use-mock-keychain', '--password-store=basic', '--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank'];
+}
diff --git a/test/cockpit/fixture.js b/test/cockpit/fixture.js
index 93cd5720..87cb5172 100644
--- a/test/cockpit/fixture.js
+++ b/test/cockpit/fixture.js
@@ -1,3 +1,4 @@
+import { chromeLaunchArgs } from '../chrome-launch-args.js';
/** Shared real-board, VM and Chrome fixtures for the cockpit checks [N26]. */
import assert from 'node:assert/strict';
import { execFileSync, spawn, spawnSync } from 'node:child_process';
@@ -645,9 +646,7 @@ function browserPause(ms) {
/** Start Chrome, retry once, and wait for its DevTools port before giving up. */
async function startSnapshotChrome(executable, profile, { timeoutMs = 30_000, signal, onOwned } = {}) {
throwIfFixtureAborted(signal);
- const args = ['--headless=new', '--disable-gpu', '--no-first-run', '--no-default-browser-check',
- '--disable-background-networking', '--disable-sync', '--disable-extensions', '--no-proxy-server',
- '--use-mock-keychain', '--password-store=basic', '--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank'];
+ const args = chromeLaunchArgs(profile);
let lastFailure = '';
let lastFailureKind = '';
const firstLaunchStartedAt = Date.now();