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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: report bounded macOS Chrome startup lifecycle facts on browser-test timeouts (#12667)
[._.]/ Adam Eivy3d85be8125f4
diff --git a/server/services/htmlComposition/testBrowserCleanup.js b/server/services/htmlComposition/testBrowserCleanup.jsindex fa5b1e9e8b..b996ad3295 100644--- a/server/services/htmlComposition/testBrowserCleanup.js+++ b/server/services/htmlComposition/testBrowserCleanup.js@@ -26,7 +26,8 @@ export function _selectTestChrome(candidates) {return candidates.find(({ path }) => path && existsSync(path));}-// Failure-only Linux observations of this owned child and its current worker.+// Failure-only observations of this owned child and its current worker: Linux+// procfs samples, or bounded lifecycle categories on macOS.// Never read cmdline, environ, links, stacks, or arbitrary process output.// At most 40 prefixes of 4096 bytes (160 KiB), 17 directory entries and one// statfs call. These count/byte caps do not guarantee elapsed time. Samples@@ -113,11 +114,26 @@ function resourceFacts(child, { read, cpus, usage, disk }) {+ ` memAvailableKiB=${memory} tmpFreeBytes=${freeBytes} tmpFreeInodes=${safeInteger(fs?.ffree)}`;}+// Startup progress recorded by _waitForTestChrome. Without procfs, macOS can+// still tell a child that never spawned from one that is alive but silent.+const startupLifecycle = new WeakMap();++// Lifecycle categories only: no PID value, path, exit code or signal name.+function lifecycleFacts(proc, now) {+ const record = startupLifecycle.get(proc);+ const exit = proc.exitCode != null ? (proc.exitCode === 0 ? 'clean' : 'failed')+ : proc.signalCode != null ? 'signaled' : 'running';+ const elapsed = record ? safeInteger(Math.round(attemptObservation(now) - record.startedAt)) : 'unavailable';+ return `os=darwin spawned=${record ? (record.spawned ? 'yes' : 'no') : 'unavailable'}`+ + ` pid=${Number.isSafeInteger(proc?.pid) && proc.pid > 0 ? 'yes' : 'no'} exit=${exit} startElapsedMs=${elapsed}`;+}+export function _testChromeProcessFacts(proc, {platform = process.platform, workerPid = process.pid, read = readProcPrefix, threads = readThreadIds,- arch = process.arch,+ arch = process.arch, now = () => performance.now(),cpus = availableParallelism, usage = () => process.resourceUsage(), disk = () => statfsSync(tmpdir()),} = {}) {+ if (platform === 'darwin') return lifecycleFacts(proc, now);if (platform !== 'linux') return 'os=unsupported';if (!Number.isSafeInteger(proc?.pid) || proc.pid <= 0) return 'os=linux child=unavailable';// Once Node has reaped it, the numeric PID may belong to somebody else.@@ -257,9 +273,10 @@ export function _waitForTestChrome(proc, timeoutMs = 20000, startup, { observePrreturn new Promise((resolve, reject) => {let stderr = '';let timer;- let spawned = false;let settled = false;- const onSpawn = () => { spawned = true; };+ const lifecycle = { startedAt: performance.now(), spawned: false };+ startupLifecycle.set(proc, lifecycle);+ const onSpawn = () => { lifecycle.spawned = true; };const diagnostic = async () => {const categories = [['sandbox', /sandbox/i],@@ -272,7 +289,7 @@ export function _waitForTestChrome(proc, timeoutMs = 20000, startup, { observePrconst base = categories.length ? `; stderr: ${categories.join(', ')}` : stderr ? '; Chrome emitted stderr' : '; no stderr';const processFacts = `; process: ${describeProcess(proc, observeProcess)}`;if (!startup) return base + processFacts;- proc.spawnedSeen = spawned;+ proc.spawnedSeen = lifecycle.spawned;return `${base}; startup: ${await _describeTestChromeStartup(proc, startup, { spawnVersion })}${processFacts}`;};const cleanup = () => {diff --git a/server/services/htmlComposition/testBrowserCleanup.test.js b/server/services/htmlComposition/testBrowserCleanup.test.jsindex 665f357936..26561e7d7c 100644--- a/server/services/htmlComposition/testBrowserCleanup.test.js+++ b/server/services/htmlComposition/testBrowserCleanup.test.js@@ -152,7 +152,7 @@ describe('failure process observations', () => {const read = vi.fn();const threads = vi.fn();const resources = { cpus: vi.fn(), usage: vi.fn(), disk: vi.fn() };- expect(_testChromeProcessFacts({ pid: 123 }, { platform: 'darwin', read, threads, ...resources })).toBe('os=unsupported');+ expect(_testChromeProcessFacts({ pid: 123 }, { platform: 'win32', read, threads, ...resources })).toBe('os=unsupported');expect(_testChromeProcessFacts({}, { platform: 'linux', read, threads, ...resources })).toBe('os=linux child=unavailable');expect(_testChromeProcessFacts({ pid: 123, exitCode: 0 }, { platform: 'linux', read, threads, ...resources })).toBe('os=linux child=settled');expect(_testChromeProcessFacts({ pid: 123, signalCode: 'SIGTERM' }, { platform: 'linux', read, threads, ...resources })).toBe('os=linux child=settled');@@ -330,6 +330,31 @@ describe('test Chrome startup', () => {expectStartupClean(proc);});+ it('separates a never-spawned, early-exited and silent running macOS child without reading procfs', async () => {+ const read = vi.fn();+ const facts = owned => _testChromeProcessFacts(owned, { platform: 'darwin', read, now: () => performance.now() + 20000 });+ const outcome = async (pid, act) => {+ const proc = startingChild();+ proc.pid = pid;+ const rejected = _waitForTestChrome(proc, 20000, undefined, { observeProcess: facts }).catch(error => error.message);+ act(proc);+ await vi.advanceTimersByTimeAsync(20000);+ expectStartupClean(proc);+ return rejected;+ };+ const none = await outcome(undefined, () => {});+ const exited = await outcome(123, proc => { proc.emit('spawn'); proc.exitCode = 3; proc.emit('exit', 3, null); });+ const running = await outcome(123, proc => proc.emit('spawn'));+ expect(none).toMatch(/did not start within 20000ms; no stderr; process: os=darwin spawned=no pid=no exit=running startElapsedMs=\d+$/);+ expect(exited).toMatch(/exited before startup \(code 3, signal none; no stderr; process: os=darwin spawned=yes pid=yes exit=failed startElapsedMs=\d+\)$/);+ expect(running).toMatch(/did not start within 20000ms; no stderr; process: os=darwin spawned=yes pid=yes exit=running startElapsedMs=\d+$/);+ // A child this wait never observed has no startup record; exit categories still hold.+ expect(facts({ pid: 123, signalCode: 'SIGKILL' })).toBe('os=darwin spawned=unavailable pid=yes exit=signaled startElapsedMs=unavailable');+ expect(facts({ pid: 123, exitCode: 0 })).toContain('exit=clean');+ expect([none, running].join('\n')).not.toMatch(/123/);+ expect(read).not.toHaveBeenCalled();+ });+it('captures capped syscall categories only at failure, without leaking registers or inventing denied observations', async () => {const proc = startingChild();proc.pid = 123;