The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Unit specs that failed under load: real homes, product deadlines on fake binaries, stray requests (#957)
Dee3f14f3db1753
diff --git a/cli/src/lib/codexStartupRetry.spec.ts b/cli/src/lib/codexStartupRetry.spec.tsindex b52db927f..75b4c38dd 100644--- a/cli/src/lib/codexStartupRetry.spec.ts+++ b/cli/src/lib/codexStartupRetry.spec.ts@@ -5,6 +5,13 @@ import { join } from 'node:path'import { afterEach, describe, expect, it } from 'vitest'import { CODEX_STARTUP_RETRY_PROBE } from './codexStartupRetry.js'+// The probe gives tmux 2 s, as it should in a pane. Here tmux is a /bin/sh script, and under 12 busy loops on a+// 12-core Mac (load 60) it took longer than that to start: the probe gave up and printed nothing, and a test+// read that as `Unexpected end of JSON input`. These tests are about the evidence the probe reads, so its+// deadline is lifted here; the probe is otherwise the one a pane runs.+const PROBE = CODEX_STARTUP_RETRY_PROBE.replace('timeout: 2000,', 'timeout: 120000,')+if (PROBE === CODEX_STARTUP_RETRY_PROBE) throw new Error('the probe no longer gives tmux `timeout: 2000`: update this spec')+const timeout = 'Error: account/read failed during TUI bootstrap: account/read failed: workspace routing discovery timed out (code -32603)'const updated = '🎉 Update ran successfully! Please restart Codex.'const dirs: string[] = []@@ -19,7 +26,7 @@ function fixture() {writeFileSync(tmux, '#!/bin/sh\ncat "$HARNESS_TEST_SCREEN"\n', { mode: 0o755 })const probe = (mode: string, baseline = '', pane = '%7') => {try {- return { status: 0, out: execFileSync(process.execPath, ['-e', CODEX_STARTUP_RETRY_PROBE, mode, tmux, pane, baseline], {+ return { status: 0, out: execFileSync(process.execPath, ['-e', PROBE, mode, tmux, pane, baseline], {env: { ...process.env, HARNESS_TEST_SCREEN: screen }, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'],}) }} catch (error) { return { status: (error as { status: number }).status, out: '' } }diff --git a/cli/src/lib/gridMcpUrl.spec.ts b/cli/src/lib/gridMcpUrl.spec.tsindex 7b4146115..f0510008a 100644--- a/cli/src/lib/gridMcpUrl.spec.ts+++ b/cli/src/lib/gridMcpUrl.spec.ts@@ -111,13 +111,11 @@ describe('resolveGridMcpUrl', () => {expect(warned.join('\n')).toContain('Not logged in')})- it('answers undefined when the output is not a usable address', async () => {- for (const url of ['', 'v1/grid/web-mcp/', 'file:///etc/passwd']) {- clearGridMcpUrlCache()- fake?.dispose()- install({ mcp: { stdout: JSON.stringify({ server: 'grid-web', url, authorization: 'Bearer x' }) } })- expect(await resolveGridMcpUrl(GRID, NOW), url).toBeUndefined()- }+ // One case each: every case starts the fake `grid`, a node process. Three in one test took it past its 5 s+ // under 12 busy loops on a 12-core Mac (load 60), where each start took one to two seconds.+ it.each(['', 'v1/grid/web-mcp/', 'file:///etc/passwd'])('answers undefined when the output is not a usable address: %j', async (url) => {+ install({ mcp: { stdout: JSON.stringify({ server: 'grid-web', url, authorization: 'Bearer x' }) } })+ expect(await resolveGridMcpUrl(GRID, NOW)).toBeUndefined()})it('answers undefined when there is no `grid` at all, and never throws', async () => {diff --git a/cli/src/lib/gridReads.spec.ts b/cli/src/lib/gridReads.spec.tsindex 7ac1d17b4..b9c9341f9 100644--- a/cli/src/lib/gridReads.spec.ts+++ b/cli/src/lib/gridReads.spec.ts@@ -15,6 +15,11 @@ import { join } from 'node:path'import { installFakeGrid, type FakeGrid, type FakeGridPlan, type FakeGridTurn } from './__fixtures__/fakeGrid.js'import { forgetGridModels, gridInventory, listAllGridModels, listGridModels, resetGridModels, type GridModelsService, type GridSection } from './gridModels.js'+// Every look starts the fake `grid`, a node process, for its list and each grid's info: the seam under test is+// that subprocess. The longest test here looks 13 times, about 26 starts: 2.7 s under 12 busy loops on a+// 12-core Mac (load 85), and past vitest's 5 s at load 110. Room for a loaded machine, not for a hang.+vi.setConfig({ testTimeout: 30_000 })+const OWN = 'mine', OWN_ID = 'net-own', TEAM = 'team', TEAM_ID = 'net-team'const EMAIL = '[email protected]'const OVERVIEW = '/relay/v1/grid/overview', DISCOVER = '/nodes/discover'@@ -81,6 +86,13 @@ beforeEach(async () => {seen = []answers = new Map()server = createServer((req, res) => {+ // Only what was sent to a grid's address is this test's. Under load a request with Node's own User-Agent+ // ('node', which no grid read sends) reached this port, from outside the code under test: ports are+ // reused across the suite's workers.+ if (!req.url?.startsWith('/g/')) {+ res.writeHead(404).end()+ return+ }seen.push({ method: req.method ?? '', path: req.url ?? '', headers: req.headers })const found = answers.get(req.url ?? '') ?? { status: 404, body: { detail: 'Not Found' } }setTimeout(() => {diff --git a/cli/src/lib/processRows.spec.ts b/cli/src/lib/processRows.spec.tsindex 39f1ef878..d702c8af4 100644--- a/cli/src/lib/processRows.spec.ts+++ b/cli/src/lib/processRows.spec.ts@@ -1,9 +1,14 @@import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'-import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { processArgs, processRows } from './tmux.js'+// The fake binaries below are /bin/sh scripts; their answers, not their speed, are what is tested+// (testing/patientExecWithoutDeadline.ts).+vi.mock('./patientExec.js', async (importOriginal) =>+ (await import('../testing/patientExecWithoutDeadline.js')).withoutDeadline(await importOriginal()))+/*** A `ps` on PATH that records every spawn and answers one well-formed row after a short pause — long* enough for concurrent callers to pile up behind the first read.diff --git a/cli/src/lib/sessionSearch/externals/homes.spec.ts b/cli/src/lib/sessionSearch/externals/homes.spec.tsindex d0fca1c74..d72ec66c4 100644--- a/cli/src/lib/sessionSearch/externals/homes.spec.ts+++ b/cli/src/lib/sessionSearch/externals/homes.spec.ts@@ -4,10 +4,21 @@ import { join } from 'node:path'import { afterEach, expect, it } from 'vitest'import { env } from '../../../config/env.js'import { claudeProjectsRoots, resetEngineHomes } from '../../engineHomes.js'-import { externalProviders } from './index.js'+import { externalPaths, externalProviders } from './index.js'import { scanMemo } from './support.js'let root: string | undefined++/**+ * The providers with this test's own default homes. With the process's (env.CLAUDE_PROJECTS_DIR,+ * env.CODEX_HOME) they scanned the developer's real ~/.claude and ~/.codex: on one Mac 27 GB of Codex+ * sessions, which took the Codex case past its 5 s on a loaded machine, and which a test must never read.+ */+function providers(at: string) {+ const claudeProjectsDir = join(at, 'default-claude', 'projects')+ return { claudeProjectsDir, all: externalProviders({ ...externalPaths(), claudeProjectsDir, codexHome: join(at, 'default-codex') }) }+}+afterEach(() => {rmSync(join(env.ADAPTER_DATA_DIR, 'engine-homes.json'), { force: true })resetEngineHomes()@@ -17,9 +28,9 @@ afterEach(() => {it.each(['claude', 'codex'] as const)('search discovers %s homes adopted by the core after its separate process has started', async engine => {root = mkdtempSync(join(tmpdir(), 'external-homes-'))resetEngineHomes()+ const own = providers(root)// Search starts before the core reads the login shell; its first root lookup may find no saved file.- claudeProjectsRoots(env.CLAUDE_PROJECTS_DIR)- const providers = externalProviders()+ claudeProjectsRoots(own.claudeProjectsDir)const claudeHome = join(root, 'claude'), codexHome = join(root, 'codex')const claudeId = '11111111-1111-4111-8111-111111111111', codexId = '22222222-2222-4222-8222-222222222222'const write = (path: string, value: unknown) => {@@ -35,7 +46,7 @@ it.each(['claude', 'codex'] as const)('search discovers %s homes adopted by thewrite(join(codexHome, 'session_index.jsonl'), { id: codexId, thread_name: 'Moved Codex thread' })write(join(env.ADAPTER_DATA_DIR, 'engine-homes.json'), { claude: [claudeHome], codex: [codexHome] })const ctx = scanMemo().context()- expect(await providers.find(p => p.engine === engine)!.scan(ctx)).toEqual(expect.arrayContaining([+ expect(await own.all.find(p => p.engine === engine)!.scan(ctx)).toEqual(expect.arrayContaining([expect.objectContaining(engine === 'claude' ? { sessionId: claudeId } : { sessionId: codexId, title: 'Moved Codex thread' }),]))})@@ -47,7 +58,7 @@ it('search recognizes a moved Claude conversation that is still busy in anothermkdirSync(join(home, 'sessions'), { recursive: true })writeFileSync(record, JSON.stringify({ pid: 123, sessionId: 'external-conversation', status: 'busy', startedAt: 1000 }))writeFileSync(join(env.ADAPTER_DATA_DIR, 'engine-homes.json'), JSON.stringify({ claude: [home] }))- const provider = externalProviders().find(p => p.engine === 'claude')!+ const provider = providers(root).all.find(p => p.engine === 'claude')!const claims = await provider.owners!({alive: pid => pid === 123,list: async () => [{ pid: 123, ppid: 1, executable: 'claude', args: 'claude', started: 1000 }],diff --git a/cli/src/lib/tmuxLegacySessions.spec.ts b/cli/src/lib/tmuxLegacySessions.spec.tsindex d41db483d..c546ea278 100644--- a/cli/src/lib/tmuxLegacySessions.spec.ts+++ b/cli/src/lib/tmuxLegacySessions.spec.ts@@ -1,11 +1,16 @@import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { delimiter, join } from 'node:path'-import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { isLegacyHarnessSession } from './harnessSessionLabel.js'import { adoptLegacyHarnessSessions } from './tmuxAgentDiscovery.js'import { assumeTmuxVersion, resetTmuxVersionCache } from './tmuxVersion.js'+// The fake binaries below are /bin/sh scripts; their answers, not their speed, are what is tested+// (testing/patientExecWithoutDeadline.ts).+vi.mock('./patientExec.js', async (importOriginal) =>+ (await import('../testing/patientExecWithoutDeadline.js')).withoutDeadline(await importOriginal()))+const originalPath = process.env.PATHconst dirs: string[] = []diff --git a/cli/src/lib/tmuxVersion.spec.ts b/cli/src/lib/tmuxVersion.spec.tsindex 74aef9474..50d283e64 100644--- a/cli/src/lib/tmuxVersion.spec.ts+++ b/cli/src/lib/tmuxVersion.spec.ts@@ -1,11 +1,16 @@import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { delimiter, join } from 'node:path'-import { afterEach, describe, expect, it } from 'vitest'+import { afterEach, describe, expect, it, vi } from 'vitest'import {TMUX_SESSION_ENV_MIN, parseTmuxVersion, resetTmuxVersionCache, supportsSessionEnv, tmuxFeaturesOf, tmuxVersion,} from './tmuxVersion.js'+// The fake tmux below is a /bin/sh script; whether its answer is kept, not how fast it came, is what is+// tested (testing/patientExecWithoutDeadline.ts).+vi.mock('./patientExec.js', async (importOriginal) =>+ (await import('../testing/patientExecWithoutDeadline.js')).withoutDeadline(await importOriginal()))+describe('parseTmuxVersion', () => {it('reads the shapes tmux -V actually prints', () => {expect(parseTmuxVersion('tmux 3.5a\n')).toEqual({ major: 3, minor: 5 })diff --git a/cli/src/testing/patientExecWithoutDeadline.ts b/cli/src/testing/patientExecWithoutDeadline.tsnew file mode 100644index 000000000..fa83a52c4--- /dev/null+++ b/cli/src/testing/patientExecWithoutDeadline.ts@@ -0,0 +1,26 @@+/**+ * `lib/patientExec.ts` with its deadline taken off, for a spec whose fake binary (a `/bin/sh` script on+ * PATH standing in for tmux or ps) is there to say what was asked and what came back, not how long it took.+ *+ * On a loaded machine one such script takes seconds to start. Under 12 busy loops on a 12-core Mac (load+ * 60) the product's 2 s and 3 s deadlines killed fake tmux and ps scripts before their first line ran: a+ * failed read the spec then counted as never made (processRows.spec.ts, tmuxVersion.spec.ts), and a pane+ * listing that read as no answer (tmuxLegacySessions.spec.ts). What a deadline does is patientExec.spec.ts's+ * to test. tmuxBackend.spec.ts does the same with a mock of its own, which also counts the calls in flight.+ *+ * Use it from a spec beside the module that imports patientExec:+ * vi.mock('./patientExec.js', async (importOriginal) =>+ * (await import('../testing/patientExecWithoutDeadline.js')).withoutDeadline(await importOriginal()))+ */+import type { ExecFileException } from 'node:child_process'+import type * as PatientExec from '../lib/patientExec.js'++export function withoutDeadline(actual: typeof PatientExec): typeof PatientExec {+ const patientExec: typeof actual.patientExec = (execFile) => (file, args, options, done) => {+ const { timeout: _timeout, killSignal: _killSignal, ...rest } = options+ execFile(file, [...args], { ...rest, encoding: 'utf8' }, (error: ExecFileException | null, stdout: string, stderr: string) => {+ done(error, stdout ?? '', stderr ?? '')+ })+ }+ return { ...actual, patientExec }+}