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
fix(cos): isolate spawn failure test data root (#13381)
[._.]/ Adam Eivy9470d1f0a0e4
diff --git a/server/cos-runner/spawnFailure.test.js b/server/cos-runner/spawnFailure.test.jsindex d0b2cbd7d3..af42b34db5 100644--- a/server/cos-runner/spawnFailure.test.js+++ b/server/cos-runner/spawnFailure.test.js@@ -1,11 +1,12 @@import { afterAll, beforeAll, describe, expect, it } from 'vitest';import { spawn } from 'child_process';import { createServer } from 'net';-import { mkdtempSync, rmSync } from 'fs';+import { existsSync, lstatSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs';import { tmpdir } from 'os';import { dirname, join } from 'path';import { fileURLToPath } from 'url';import { io as connect } from 'socket.io-client';+import { DISPOSABLE_ROOT_MARKER } from '../lib/dataRoot.js';// index.js binds its server at import, so the only faithful way to exercise the// real /spawn ordering is to boot it as a child process. #11761: Node reports a@@ -14,6 +15,27 @@ import { io as connect } from 'socket.io-client';// 'error' threw, the runner's uncaughtException handler exited the process, and// every other agent it supervised lost its owner.const RUNNER = join(dirname(fileURLToPath(import.meta.url)), 'index.js');+const CHECKOUT_ROOT = join(dirname(fileURLToPath(import.meta.url)), '../..');++const snapshotTree = (root) => {+ if (!existsSync(root)) return null;+ const entries = [];+ const visit = (directory) => {+ for (const name of readdirSync(directory).sort()) {+ const path = join(directory, name);+ const stat = lstatSync(path);+ entries.push({+ path: path.slice(root.length),+ size: stat.size,+ modified: stat.mtimeMs,+ isDirectory: stat.isDirectory(),+ });+ if (stat.isDirectory()) visit(path);+ }+ };+ visit(root);+ return entries;+};const freePort = () => new Promise((resolve, reject) => {const probe = createServer();@@ -30,9 +52,15 @@ describe('cos-runner /spawn survives a failed CLI launch (#11761)', () => {let base;let socket;let exited = false;+ let checkoutFixtureBefore;beforeAll(async () => {dataRoot = mkdtempSync(join(tmpdir(), 'portos-runner-spawn-'));+ // A CoS worktree rejects unmarked PORTOS_DATA_ROOT overrides. Mark this+ // throwaway root so the real runner's failed-spawn recording stays inside+ // the fixture and is removed by afterAll.+ writeFileSync(join(dataRoot, DISPOSABLE_ROOT_MARKER), '');+ checkoutFixtureBefore = snapshotTree(join(CHECKOUT_ROOT, 'data/cos/agents/agent-spawn-failure'));const port = await freePort();base = `http://127.0.0.1:${port}`;// The runner is a standalone service: drop the runner-under-test markers so its@@ -69,6 +97,10 @@ describe('cos-runner /spawn survives a failed CLI launch (#11761)', () => {socket.once('agent:error', resolve);runner.once('exit', () => reject(new Error('the runner process died on a failed spawn')));});+ const completed = new Promise((resolve, reject) => {+ socket.once('agent:completed', resolve);+ runner.once('exit', () => reject(new Error('the runner exited before recording the failed spawn')));+ });// A removed cwd makes the launch fail with ENOENT regardless of whether the// CLI is installed, so this is deterministic on any machine.const response = await fetch(`${base}/spawn`, {@@ -85,7 +117,18 @@ describe('cos-runner /spawn survives a failed CLI launch (#11761)', () => {});expect(response.status, await response.clone().text()).toBe(200);expect(await errored).toMatchObject({ agentId: 'agent-spawn-failure' });+ expect(await completed).toMatchObject({ agentId: 'agent-spawn-failure', taskId: 'task-spawn-failure' });expect(exited, 'the runner process must not die on a failed spawn').toBe(false);+ const disposableAgentDir = join(dataRoot, 'data/cos/agents/agent-spawn-failure');+ expect(readdirSync(disposableAgentDir).sort()).toEqual(['metadata.json', 'output.txt']);+ expect(JSON.parse(readFileSync(join(disposableAgentDir, 'metadata.json'), 'utf8')))+ .toMatchObject({+ agentId: 'agent-spawn-failure',+ taskId: 'task-spawn-failure',+ success: false,+ });+ expect(snapshotTree(join(CHECKOUT_ROOT, 'data/cos/agents/agent-spawn-failure')))+ .toEqual(checkoutFixtureBefore);const health = await fetch(`${base}/health`).then((res) => res.json());expect(health).toMatchObject({ status: 'ok', activeAgents: 0 });}, 20_000);