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
test(cli): restore native resume fixture request wiring (#882)
Dee3c7789af4443
diff --git a/cli/package.json b/cli/package.jsonindex a97a32c3f..e8171caeb 100644--- a/cli/package.json+++ b/cli/package.json@@ -25,7 +25,7 @@"test:cursor-e2e": "RUN_CURSOR_E2E=1 vitest run src/engines/cursor/localE2e.spec.ts","test:tmux-real": "RUN_REAL_TMUX_DISCOVERY=1 vitest run src/lib/tmuxAgentDiscovery.real.spec.ts src/lib/engineShellStartup.spec.ts src/lib/codexUpdateRestart.real.spec.ts src/lib/restartDiscovery.real.spec.ts src/lib/terminalClose.real.spec.ts src/lib/engineStop.real.spec.ts --reporter=verbose","test:resume": "vitest run src/lib/sessionRepair.spec.ts src/lib/captureResumeIdentity.spec.ts src/lib/resumeStoppedAgent.spec.ts src/lib/resumeAgentService.spec.ts src/lib/stoppedAgents.spec.ts src/lib/stopAgentService.spec.ts --coverage --coverage.include=src/lib/captureResumeIdentity.ts --coverage.include=src/lib/resumeStoppedAgent.ts --coverage.include=src/lib/resumeAgentService.ts --coverage.include=src/lib/stoppedAgents.ts --coverage.include=src/lib/stopAgentService.ts --coverage.thresholds.lines=100 --coverage.thresholds.statements=100 --coverage.thresholds.branches=100 --coverage.thresholds.functions=100 --coverage.reporter=text --coverage.reporter=json --coverage.reportsDirectory=coverage/resume",- "test:resume-native": "tsx scripts/resume-native-e2e.ts",+ "test:resume-native": "tsc -p tsconfig.resume-native.json && tsx scripts/resume-native-e2e.ts","test:portability": "vitest run --config vitest.portability.config.ts"},"dependencies": {diff --git a/cli/scripts/resume-native-e2e.ts b/cli/scripts/resume-native-e2e.tsindex 6ba7793e6..26c5fa869 100644--- a/cli/scripts/resume-native-e2e.ts+++ b/cli/scripts/resume-native-e2e.ts@@ -13,6 +13,7 @@ import { randomUUID } from 'node:crypto'import { createServer } from 'node:http'import { cleanupFixtureGit } from './native-fixture-git.js'import assert from 'node:assert/strict'+import type { NativeResumeRequests } from '../src/testing/nativeResumeSocket.js'const exec = promisify(execCallback)const root = realpathSync(mkdtempSync(join(tmpdir(), 'harness-resume-native-')))const cliRoot = resolve('.')@@ -54,6 +55,7 @@ const { claudeProcessSession } = await import('../src/lib/sessionRepair.js')const { checkPidRuntime } = await import('../src/lib/deleteAgentFallback.js')const { startHookServer } = await import('../src/hookServer.js')const { BackendSocket } = await import('../src/backendSocket.js')+const { bindNativeResumeRequests } = await import('../src/testing/nativeResumeSocket.js')const { installCodexHooks } = await import('../src/lib/hooks.js')const backend = new TmuxBackend()const socketBackend = new BackendSocket('fixture-only')@@ -71,6 +73,7 @@ const server = await startHookServer(0, {return registry.openProcessAgent({ engine: input.engine, processIdentity: identity, runtimes: row.runtimes, primaryRuntimeKey: row.primaryRuntimeKey, cwd: row.cwd })?.entry ?? null},})+let nativeRequests: NativeResumeRequests | undefinedconst fixtures: Array<{ agentId: string; engine: string; sessionId: string; marker: string }> = []const replies = new Map<string, any>()socketBackend.registerLocalClient('local:resume-e2e', { sendFrame: frame => { const f = frame as any; if (f.payload?.requestId) replies.set(f.payload.requestId, f.payload); return true }, sendBinary: () => true })@@ -154,7 +157,6 @@ try {agentReconciler: { suppress: () => {}, holdRoute: () => {}, releaseRoute: () => {}, trigger: async () => {} },forgetSession: id => { registry.removeAgent(id); socketBackend.send({ type: 'agent_deleted', payload: { agentId: id, retained: true } }) }, markDeleted: () => {}, clearDeleted: () => {},})- socketBackend.onDeleteAgent = stopAgentsocketBackend.closeAgentService?.dispose()socketBackend.closeAgentService = new CloseAgentService({registry,@@ -178,12 +180,16 @@ try {}),stop: stopAgent, changed: row => { void agentFrame(row, { selectedModel: null, terminalAvailable: true, dsh: null }).then(agent => socketBackend.send({ type: 'agent_synced', payload: { agent } })) },})- socketBackend.onResumeAgent = createResumeAgentService({+ const resumeAgent = createResumeAgentService({registry, stoppedAgents, tmuxBackend: backend, restartJobs: jobs, stopJobs, pinnedControls: new Set(),announceSession: () => {}, relaunchOverrides: async () => ({ ok: true, overrides: { env: launchEnv, extraArgs: [], clearEnv: ['ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'CLAUDECODE'] } }),prepareSessionResume: () => {}, refreshGridWebSearch: () => {}, clearDeleted: () => {}, attachDsh: () => {},+ // This fixture checks the native TUI's history directly; it has no daemon transcript watcher.+ attachSession: async () => false,retainExitedSession: (row, alive) => { stoppedAgents.save(row); if (alive) registry.releaseEngine(row.agentId, true); else registry.removeAgent(row.agentId) },})+ nativeRequests = { resume: resumeAgent, stop: stopAgent }+ bindNativeResumeRequests(socketBackend, nativeRequests)const inventory = await rpc('agents_list', { includeStopped: true })assert(inventory.agents.some((a: any) => a.id === old.agentId && a.status === 'stopped'))const openSaved = async (creationId: string) => {@@ -366,11 +372,12 @@ try {const anchorPane = (await tmux('display-message', '-p', '-t', 'fixture-anchor', '#{pane_id}')).trim()const anchor = registry.openPendingAgent({ engine: 'terminal', runtimes: [{ backend: 'tmux', paneId: anchorPane }], cwd: root, defaultName: 'Keep this work open' })!registry.setLaunch(anchor.agentId, { state: 'ready' })- const resume = socketBackend.onResumeAgent!- socketBackend.onResumeAgent = async id => {+ assert(nativeRequests)+ const { resume, stop } = nativeRequests+ nativeRequests.resume = async (id, permissionMode) => {const fixture = fixtures.find(f => f.agentId === id); assert(fixture, 'only fixture sessions may resume')let done = false- const result = resume(id).finally(() => { done = true })+ const result = resume(id, permissionMode).finally(() => { done = true })let announced = ''while (!done) {const row = registry.byAgent(id)@@ -387,8 +394,7 @@ try {}return result}- const stop = socketBackend.onDeleteAgent!- socketBackend.onDeleteAgent = async id => {+ nativeRequests.stop = async id => {assert(fixtures.some(f => f.agentId === id), 'never stop the anchor or a non-fixture session')const before = JSON.stringify(registry.byAgent(id))try { await stop(id) }diff --git a/cli/src/testing/nativeResumeSocket.spec.ts b/cli/src/testing/nativeResumeSocket.spec.tsnew file mode 100644index 000000000..028132377--- /dev/null+++ b/cli/src/testing/nativeResumeSocket.spec.ts@@ -0,0 +1,60 @@+import { randomUUID } from 'node:crypto'+import { afterEach, beforeEach, expect, it, vi } from 'vitest'+import { BackendSocket } from '../backendSocket.js'+import type { AgentFrame } from '../lib/agentFrame.js'+import { registry, type RegisteredSession } from '../lib/registry.js'+import { stoppedAgents } from '../lib/stoppedAgents.js'+import { bindNativeResumeRequests, type NativeResumeRequests } from './nativeResumeSocket.js'++let socket: BackendSocket+let requests: NativeResumeRequests+let frames: Array<{ type: string; payload: Record<string, any> }>+beforeEach(() => {+ socket = new BackendSocket('fixture-only')+ frames = []+ socket.registerLocalClient('local:native-wiring', {+ sendFrame: frame => { frames.push(frame as typeof frames[number]); return true },+ sendBinary: () => true,+ })+ requests = { resume: vi.fn(async () => ({ ok: false as const, error: 'FIXTURE_REFUSED' })), stop: vi.fn(async () => {}) }+ bindNativeResumeRequests(socket, requests)+})+afterEach(async () => { await socket.stop(); vi.restoreAllMocks() })+async function rpc(type: string, payload: Record<string, unknown> = {}) {+ const requestId = randomUUID()+ socket.handleLocalFrame('local:native-wiring', { type, payload: { ...payload, requestId } })+ await vi.waitFor(() => expect(frames.some(frame => frame.payload?.requestId === requestId)).toBe(true))+ return frames.find(frame => frame.payload?.requestId === requestId)!.payload+}++it('lists the stopped conversation before the native engine is launched', async () => {+ vi.spyOn(registry, 'advertised').mockReturnValue([])+ vi.spyOn(stoppedAgents, 'available').mockReturnValue([{ agentId: 'saved' } as RegisteredSession])+ vi.spyOn(socket, 'toStoppedProject').mockResolvedValue({ id: 'saved', status: 'stopped' } as AgentFrame)+ expect(await rpc('agents_list', { includeStopped: true })).toMatchObject({ agents: [{ id: 'saved', status: 'stopped' }] })+})++it('dispatches resume and preserves the creation receipt across fixture handler changes', async () => {+ const creationId = randomUUID()+ expect(await rpc('agent_resume', { agentId: 'saved', creationId })).toMatchObject({ state: 'failed', failure: { code: 'FIXTURE_REFUSED' } })+ const next = vi.fn(async () => ({ ok: false as const, error: 'SECOND_FIXTURE_REFUSAL' }))+ requests.resume = next+ expect(await rpc('agent_create_status', { creationId })).toMatchObject({ state: 'failed', failure: { code: 'FIXTURE_REFUSED' } })+ expect(await rpc('agent_resume', { agentId: 'saved', permissionMode: 'auto' })).toMatchObject({ error: 'SECOND_FIXTURE_REFUSAL' })+ expect(next).toHaveBeenCalledExactlyOnceWith('saved', 'auto')+})++it('stops through the current fixture handler', async () => {+ const stopped: string[] = []+ requests.stop = async id => { stopped.push(id) }+ expect(await rpc('agent_delete', { agentId: 'saved' })).toMatchObject({ deleted: true })+ expect(stopped).toEqual(['saved'])+})++it('closes through the service installed after the socket was bound', async () => {+ const request = vi.fn(async () => ({ closed: true }))+ socket.closeAgentService = { request, dispose() {} } as unknown as NonNullable<BackendSocket['closeAgentService']>+ const payload = { agentId: 'saved', sessionId: 'history', createdAt: '2026-01-01T00:00:00.000Z', mode: 'now' }+ expect(await rpc('agent_close', payload)).toMatchObject({ closed: true })+ expect(request).toHaveBeenCalledExactlyOnceWith(payload)+})diff --git a/cli/src/testing/nativeResumeSocket.ts b/cli/src/testing/nativeResumeSocket.tsnew file mode 100644index 000000000..e8ecde39b--- /dev/null+++ b/cli/src/testing/nativeResumeSocket.ts@@ -0,0 +1,20 @@+import type { BackendSocket } from '../backendSocket.js'+import type { ResumeAgent } from '../core/agents/launches.js'+import { bindAgentList, bindCloseRequests, bindLaunchRequests, bindStopRequest } from './socketCore.js'++export interface NativeResumeRequests {+ resume: ResumeAgent+ stop: (agentId: string) => Promise<void>+}++/**+ * Found by QA on a quiet machine: the native resume fixture still assigned the removed socket+ * callbacks after requests moved into the core, so its first inventory answered UNSUPPORTED.+ * Bind the real handlers, reading the current actions so the optional UI fixture can wrap them.+ */+export function bindNativeResumeRequests(socket: BackendSocket, requests: NativeResumeRequests): void {+ bindAgentList(socket)+ bindCloseRequests(socket)+ bindLaunchRequests(socket, { resume: (id, permissionMode) => requests.resume(id, permissionMode) })+ bindStopRequest(socket, id => requests.stop(id))+}diff --git a/cli/tsconfig.resume-native.json b/cli/tsconfig.resume-native.jsonnew file mode 100644index 000000000..edf93b816--- /dev/null+++ b/cli/tsconfig.resume-native.json@@ -0,0 +1,11 @@+{+ "extends": "./tsconfig.json",+ "compilerOptions": {+ "rootDir": ".",+ "noEmit": true,+ "incremental": false+ },+ "include": [+ "scripts/resume-native-e2e.ts"+ ]+}