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
Bundle command test fixtures once per suite (#637)
Dee78a43ba1b051
diff --git a/cli/src/__fixtures__/bundledCli.ts b/cli/src/__fixtures__/bundledCli.tsnew file mode 100644index 000000000..ed14aef2e--- /dev/null+++ b/cli/src/__fixtures__/bundledCli.ts@@ -0,0 +1,52 @@+import { mkdtemp, rm } from 'node:fs/promises'+import { readFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'+import { fileURLToPath } from 'node:url'+import { build } from 'esbuild'+import { afterAll, beforeAll } from 'vitest'++const CLI_ROOT = fileURLToPath(new URL('../..', import.meta.url))++/** Build the real CLI once per test file, then start a fresh Node process for each command.+ * This avoids reloading the entire TypeScript graph through tsx on every invocation. Each suite+ * owns its temporary bundle, so concurrent suites/watch runs cannot reuse stale dist output.+ * Auth, devices and Grid command fixtures do not need embedded release assets; release bundle+ * integration remains responsible for the registry, built-in harnesses, workers and hook payload.+ */+export function useBundledCli(): () => string {+ let directory: string | undefined+ let executable: string | undefined++ beforeAll(async () => {+ directory = await mkdtemp(join(tmpdir(), 'harness-command-bundle-'))+ const output = join(directory, 'cli.mjs')+ const { version } = JSON.parse(readFileSync(join(CLI_ROOT, 'package.json'), 'utf8')) as { version: string }+ await build({+ entryPoints: [join(CLI_ROOT, 'src', 'cli.ts')],+ outfile: output,+ bundle: true,+ platform: 'node',+ format: 'esm',+ target: 'node20',+ external: ['bufferutil', 'utf-8-validate'],+ define: { __ADAPTER_VERSION__: JSON.stringify(version) },+ banner: { js: 'import { createRequire as ___cr } from "node:module"; const require = ___cr(import.meta.url);' },+ minify: true,+ keepNames: true,+ legalComments: 'eof',+ logLevel: 'silent',+ })+ executable = output+ }, 30_000)++ afterAll(async () => {+ executable = undefined+ if (directory) await rm(directory, { recursive: true, force: true })+ })++ return () => {+ if (!executable) throw new Error('CLI fixture must finish building before it can run')+ return executable+ }+}diff --git a/cli/src/authCommand.spec.ts b/cli/src/authCommand.spec.tsindex 24907eae1..25f746ade 100644--- a/cli/src/authCommand.spec.ts+++ b/cli/src/authCommand.spec.ts@@ -5,12 +5,12 @@ import { hostname, tmpdir } from 'os'import { join } from 'path'import { fileURLToPath } from 'url'import { afterEach, describe, expect, it } from 'vitest'+import { useBundledCli } from './__fixtures__/bundledCli.js'import { b64d, b64e, fingerprint, newIdentity } from './lib/e2ee/core.js'import { listenLocalSocket, localSocketPath } from './lib/localSocket.js'const CLI_ROOT = fileURLToPath(new URL('..', import.meta.url))-const CLI_SOURCE = join(CLI_ROOT, 'src', 'cli.ts')-const TSX = join(CLI_ROOT, 'node_modules', 'tsx', 'dist', 'cli.mjs')+const cli = useBundledCli()const FP = /^[0-9A-F]{4}(·[0-9A-F]{4}){3}$/const dirs: string[] = []const servers: Server[] = []@@ -72,7 +72,7 @@ function recordingGrid(root: string): string {}function runSync(root: string, args: string[], backendUrl?: string) {- return spawnSync(process.execPath, [TSX, CLI_SOURCE, ...args], {+ return spawnSync(process.execPath, [cli(), ...args], {cwd: CLI_ROOT,encoding: 'utf8',env: envFor(root, backendUrl),@@ -84,7 +84,7 @@ function runSync(root: string, args: string[], backendUrl?: string) {* so a fake server living here could never answer the child's request and the pair would deadlock. */function runAsync(root: string, args: string[], backendUrl?: string): Promise<{ status: number | null; stdout: string; stderr: string }> {return new Promise((resolve) => {- const child = spawn(process.execPath, [TSX, CLI_SOURCE, ...args], { cwd: CLI_ROOT, env: envFor(root, backendUrl) })+ const child = spawn(process.execPath, [cli(), ...args], { cwd: CLI_ROOT, env: envFor(root, backendUrl) })let stdout = ''let stderr = ''child.stdout.on('data', (c: Buffer) => { stdout += c.toString() })@@ -361,7 +361,7 @@ describe('harness status — device row', () => {/** A `harness … --json` child driven the way the desktop app drives it: stdin left open (closing it is* the app going away), stdout read one JSON line at a time. */function jsonChild(root: string, backendUrl: string, args: string[]) {- const child = spawn(process.execPath, [TSX, CLI_SOURCE, ...args], { cwd: CLI_ROOT, env: envFor(root, backendUrl) })+ const child = spawn(process.execPath, [cli(), ...args], { cwd: CLI_ROOT, env: envFor(root, backendUrl) })const lines: Record<string, unknown>[] = []const waiters: Array<(line: Record<string, unknown>) => void> = []let buffer = ''@@ -567,7 +567,7 @@ describe('harness login --json', () => {})const gridCalls = recordingGrid(root)- const child = spawn(process.execPath, [TSX, CLI_SOURCE, 'login', '--json'], {+ const child = spawn(process.execPath, [cli(), 'login', '--json'], {cwd: CLI_ROOT,env: envFor(root, base),})diff --git a/cli/src/devicesCommand.spec.ts b/cli/src/devicesCommand.spec.tsindex bf2af27ca..3305de38b 100644--- a/cli/src/devicesCommand.spec.ts+++ b/cli/src/devicesCommand.spec.ts@@ -5,10 +5,10 @@ import { tmpdir } from 'os'import { join } from 'path'import { fileURLToPath } from 'url'import { afterEach, describe, expect, it } from 'vitest'+import { useBundledCli } from './__fixtures__/bundledCli.js'const CLI_ROOT = fileURLToPath(new URL('..', import.meta.url))-const CLI_SOURCE = join(CLI_ROOT, 'src', 'cli.ts')-const TSX = join(CLI_ROOT, 'node_modules', 'tsx', 'dist', 'cli.mjs')+const cli = useBundledCli()const DAY = 86_400_000const dirs: string[] = []let rebaseConflict = false@@ -95,7 +95,7 @@ function cliEnv(port: number): NodeJS.ProcessEnv {function run(port: number, args: string[]): Promise<{ status: number | null; stdout: string; stderr: string }> {return new Promise((resolve) => {- const child = spawn(process.execPath, [TSX, CLI_SOURCE, 'devices', ...args], { cwd: CLI_ROOT, env: cliEnv(port) })+ const child = spawn(process.execPath, [cli(), 'devices', ...args], { cwd: CLI_ROOT, env: cliEnv(port) })let stdout = ''let stderr = ''child.stdout.on('data', (c: Buffer) => { stdout += c.toString() })@@ -113,7 +113,7 @@ const HAS_SCRIPT = (process.platform === 'darwin' || process.platform === 'linux* question, as a person would. `pipeOut` sends its stdout to a pipe, so only stdin is a terminal.* Returns everything the terminal showed. */function runAtTerminal(port: number, args: string[], answer: string, pipeOut = false): Promise<{ status: number | null; screen: string }> {- const cmd = [process.execPath, TSX, CLI_SOURCE, 'devices', ...args].map(quote).join(' ') + (pipeOut ? ' | cat; exit "${PIPESTATUS[0]:-$?}"' : '')+ const cmd = [process.execPath, cli(), 'devices', ...args].map(quote).join(' ') + (pipeOut ? ' | cat; exit "${PIPESTATUS[0]:-$?}"' : '')const shell = pipeOut ? `bash -c ${quote(cmd)}` : cmd// The keyboard is a FIFO piped in by cat: BSD script refuses a socket or a FIFO as stdin, not a pipe.const dir = mkdtempSync(join(tmpdir(), 'harness-cli-tty-'))diff --git a/cli/src/gridCommand.spec.ts b/cli/src/gridCommand.spec.tsindex 372f29178..56fa2bc32 100644--- a/cli/src/gridCommand.spec.ts+++ b/cli/src/gridCommand.spec.ts@@ -17,10 +17,10 @@ import { tmpdir } from 'os'import { delimiter, join } from 'path'import { fileURLToPath } from 'url'import { afterEach, describe, expect, it } from 'vitest'+import { useBundledCli } from './__fixtures__/bundledCli.js'const CLI_ROOT = fileURLToPath(new URL('..', import.meta.url))-const CLI_SOURCE = join(CLI_ROOT, 'src', 'cli.ts')-const TSX = join(CLI_ROOT, 'node_modules', 'tsx', 'dist', 'cli.mjs')+const cli = useBundledCli()const dirs: string[] = []const servers: Server[] = []@@ -166,7 +166,7 @@ type Run = { status: number | null; stdout: string; stderr: string }* would produce the same shorter stdout, so the flake would make the real failure look like noise. */function run(root: string, args: string[], backendUrl?: string, extra: NodeJS.ProcessEnv = {}, grid: GridOnPath = 'runnable'): Promise<Run> {return new Promise((resolve) => {- const child = spawn(process.execPath, [TSX, CLI_SOURCE, ...args], {+ const child = spawn(process.execPath, [cli(), ...args], {cwd: CLI_ROOT,env: envFor(root, backendUrl, extra, grid),})@@ -353,7 +353,7 @@ describe('harness grid login — a signed-out computer', () => {resolveComputer: () => ({ machine: { machineId: 'm_new' } }),})- const child = spawn(process.execPath, [TSX, CLI_SOURCE, 'grid', 'login', '--json'], {+ const child = spawn(process.execPath, [cli(), 'grid', 'login', '--json'], {cwd: CLI_ROOT,env: envFor(root, base),})@@ -581,7 +581,7 @@ describe('harness grid login — the sign-in half it inherits', () => {resolveComputer: () => ({ machine: { machineId: 'm_seeded' } }),})- const child = spawn(process.execPath, [TSX, CLI_SOURCE, 'grid', 'login', '--force', '--json'], {+ const child = spawn(process.execPath, [cli(), 'grid', 'login', '--force', '--json'], {cwd: CLI_ROOT,env: envFor(root, base),})