fix: centralize Windows exec handling and async migrations (#318)

* Add Windows exec foundation helpers

* server: centralize windows exec handling phase 2

* migrate cli daemon status to execCommand

* refactor: complete phase 4 async exec migrations

* test: cover windows exec helpers

* fix: use beforeEach for context.skip in test setup
This commit is contained in:
Mohamed Boudra
2026-04-13 16:20:59 +08:00
committed by GitHub
parent f0c59ec534
commit bf76915884
44 changed files with 3048 additions and 2781 deletions
@@ -1,5 +1,5 @@
import { spawnSync } from "node:child_process";
import { platform } from "node:os"; import { platform } from "node:os";
import { execCommand } from "@getpaseo/server";
export interface NodePathFromPidResult { export interface NodePathFromPidResult {
nodePath: string | null; nodePath: string | null;
@@ -13,63 +13,37 @@ function normalizeError(error: unknown): string {
return String(error); return String(error);
} }
function resolveNodePathFromPidUnix(pid: number): NodePathFromPidResult { async function resolveNodePathFromPidUnix(pid: number): Promise<NodePathFromPidResult> {
const result = spawnSync("ps", ["-o", "comm=", "-p", String(pid)], { try {
encoding: "utf8", const { stdout } = await execCommand("ps", ["-o", "comm=", "-p", String(pid)]);
stdio: ["ignore", "pipe", "pipe"], const resolved = stdout.trim();
}); return resolved
? { nodePath: resolved }
if (result.error) { : { nodePath: null, error: "ps returned an empty command path" };
return { nodePath: null, error: `ps failed: ${normalizeError(result.error)}` }; } catch (error) {
return { nodePath: null, error: `ps failed: ${normalizeError(error)}` };
} }
if ((result.status ?? 1) !== 0) {
const details = result.stderr?.trim();
return {
nodePath: null,
error: details ? `ps failed: ${details}` : `ps exited with code ${result.status ?? 1}`,
};
}
const resolved = result.stdout.trim();
return resolved
? { nodePath: resolved }
: { nodePath: null, error: "ps returned an empty command path" };
} }
function runProcessProbe( async function runProcessProbe(
command: string, command: string,
args: string[], args: string[],
): { ): Promise<{
resolved: string | null; resolved: string | null;
error?: string; error?: string;
} { }> {
const result = spawnSync(command, args, { try {
encoding: "utf8", const { stdout } = await execCommand(command, args);
stdio: ["ignore", "pipe", "pipe"], const resolved = stdout.trim();
}); return resolved
? { resolved }
if (result.error) { : { resolved: null, error: `${command} returned no executable path` };
return { resolved: null, error: `${command} failed: ${normalizeError(result.error)}` }; } catch (error) {
return { resolved: null, error: `${command} failed: ${normalizeError(error)}` };
} }
if ((result.status ?? 1) !== 0) {
const details = result.stderr?.trim();
return {
resolved: null,
error: details
? `${command} failed: ${details}`
: `${command} exited with code ${result.status ?? 1}`,
};
}
const resolved = result.stdout.trim();
return resolved
? { resolved }
: { resolved: null, error: `${command} returned no executable path` };
} }
function resolveNodePathFromPidWindows(pid: number): NodePathFromPidResult { async function resolveNodePathFromPidWindows(pid: number): Promise<NodePathFromPidResult> {
const probes: Array<{ const probes: Array<{
label: string; label: string;
command: string; command: string;
@@ -103,7 +77,7 @@ function resolveNodePathFromPidWindows(pid: number): NodePathFromPidResult {
const errors: string[] = []; const errors: string[] = [];
for (const probe of probes) { for (const probe of probes) {
const result = runProcessProbe(probe.command, probe.args); const result = await runProcessProbe(probe.command, probe.args);
if (result.resolved) { if (result.resolved) {
const resolved = probe.parseValue ? probe.parseValue(result.resolved) : result.resolved; const resolved = probe.parseValue ? probe.parseValue(result.resolved) : result.resolved;
if (resolved) { if (resolved) {
@@ -123,8 +97,8 @@ function resolveNodePathFromPidWindows(pid: number): NodePathFromPidResult {
}; };
} }
export function resolveNodePathFromPid(pid: number): NodePathFromPidResult { export async function resolveNodePathFromPid(pid: number): Promise<NodePathFromPidResult> {
return platform() === "win32" return platform() === "win32"
? resolveNodePathFromPidWindows(pid) ? await resolveNodePathFromPidWindows(pid)
: resolveNodePathFromPidUnix(pid); : await resolveNodePathFromPidUnix(pid);
} }
+8 -9
View File
@@ -1,10 +1,11 @@
import type { Command } from "commander"; import type { Command } from "commander";
import { execFile } from "node:child_process";
import { createRequire } from "node:module"; import { createRequire } from "node:module";
import { promisify } from "node:util"; import {
import { getOrCreateServerId, findExecutable, applyProviderEnv } from "@getpaseo/server"; getOrCreateServerId,
findExecutable,
const execFileAsync = promisify(execFile); applyProviderEnv,
execCommand,
} from "@getpaseo/server";
import { tryConnectToDaemon } from "../../utils/client.js"; import { tryConnectToDaemon } from "../../utils/client.js";
import type { CommandOptions, ListResult, OutputSchema } from "../../output/index.js"; import type { CommandOptions, ListResult, OutputSchema } from "../../output/index.js";
import { resolveLocalDaemonState, resolveTcpHostFromListen } from "./local-daemon.js"; import { resolveLocalDaemonState, resolveTcpHostFromListen } from "./local-daemon.js";
@@ -178,11 +179,9 @@ async function checkProviderBinary(
} }
const env = applyProviderEnv(process.env); const env = applyProviderEnv(process.env);
try { try {
const { stdout } = await execFileAsync(binaryPath, ["--version"], { const { stdout } = await execCommand(binaryPath, ["--version"], {
encoding: "utf8",
timeout: 5000, timeout: 5000,
env, env,
windowsHide: true,
}); });
return { path: binaryPath, version: stdout.trim() || null }; return { path: binaryPath, version: stdout.trim() || null };
} catch { } catch {
@@ -224,7 +223,7 @@ export async function runStatusCommand(
if (!state.running) { if (!state.running) {
daemonNode = "-"; daemonNode = "-";
} else if (state.pidInfo?.pid) { } else if (state.pidInfo?.pid) {
const fromPid = resolveNodePathFromPid(state.pidInfo.pid); const fromPid = await resolveNodePathFromPid(state.pidInfo.pid);
daemonNode = fromPid.nodePath ?? `unknown (${fromPid.error ?? "could not resolve from PID"})`; daemonNode = fromPid.nodePath ?? `unknown (${fromPid.error ?? "could not resolve from PID"})`;
} else { } else {
daemonNode = "unknown (no PID available)"; daemonNode = "unknown (no PID available)";
+5 -3
View File
@@ -123,11 +123,13 @@ async function verifyInjectedMcpForProvider(
} }
async function main(): Promise<void> { async function main(): Promise<void> {
if (!isProviderAvailable("claude")) { const claudeAvailable = await isProviderAvailable("claude");
if (!claudeAvailable) {
throw new Error( throw new Error(
"Claude is not available in this environment. Ensure the `claude` binary and credentials are configured.", "Claude is not available in this environment. Ensure the `claude` binary and credentials are configured.",
); );
} }
const codexAvailable = await isProviderAvailable("codex");
const logger = pino({ level: "silent" }); const logger = pino({ level: "silent" });
const rootCwd = await mkdtemp(path.join(os.tmpdir(), "paseo-mcp-inject-real-")); const rootCwd = await mkdtemp(path.join(os.tmpdir(), "paseo-mcp-inject-real-"));
@@ -136,7 +138,7 @@ async function main(): Promise<void> {
const daemon = await createTestPaseoDaemon({ const daemon = await createTestPaseoDaemon({
agentClients: { agentClients: {
claude: new ClaudeAgentClient({ logger }), claude: new ClaudeAgentClient({ logger }),
...(isProviderAvailable("codex") ? { codex: new CodexAppServerAgentClient(logger) } : {}), ...(codexAvailable ? { codex: new CodexAppServerAgentClient(logger) } : {}),
}, },
logger, logger,
}); });
@@ -159,7 +161,7 @@ async function main(): Promise<void> {
results.push(claudeResult); results.push(claudeResult);
console.log(`[PASS] Claude MCP injection verified for agent ${claudeResult.agentId}`); console.log(`[PASS] Claude MCP injection verified for agent ${claudeResult.agentId}`);
if (isProviderAvailable("codex")) { if (codexAvailable) {
const codexResult = await verifyInjectedMcpForProvider(client, "codex", codexCwd); const codexResult = await verifyInjectedMcpForProvider(client, "codex", codexCwd);
createdAgentIds.push(codexResult.agentId); createdAgentIds.push(codexResult.agentId);
results.push(codexResult); results.push(codexResult);
@@ -15,13 +15,12 @@
* This pattern is used in claude-agent.ts listModels(). * This pattern is used in claude-agent.ts listModels().
*/ */
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { query, type SDKUserMessage } from "@anthropic-ai/claude-agent-sdk"; import { query, type SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
import { isCommandAvailableSync } from "../utils/executable.js"; import { isCommandAvailable } from "../utils/executable.js";
const hasClaudeCredentials = const hasClaudeCredentials =
!!process.env.CLAUDE_CODE_OAUTH_TOKEN || !!process.env.ANTHROPIC_API_KEY; !!process.env.CLAUDE_CODE_OAUTH_TOKEN || !!process.env.ANTHROPIC_API_KEY;
const canRunClaudeIntegration = isCommandAvailableSync("claude") && hasClaudeCredentials;
// Pattern from claude-agent.ts listModels(): // Pattern from claude-agent.ts listModels():
// Use an empty async generator when you just need control methods // Use an empty async generator when you just need control methods
@@ -30,88 +29,92 @@ function createEmptyPrompt(): AsyncGenerator<SDKUserMessage, void, undefined> {
} }
describe("Claude Agent SDK Commands POC", () => { describe("Claude Agent SDK Commands POC", () => {
let canRunClaudeIntegration = false;
beforeAll(async () => {
canRunClaudeIntegration = (await isCommandAvailable("claude")) && hasClaudeCredentials;
});
beforeEach((context) => {
if (!canRunClaudeIntegration) {
context.skip();
}
});
describe("supportedCommands() API", () => { describe("supportedCommands() API", () => {
test.runIf(canRunClaudeIntegration)( test("should return an array of SlashCommand objects", async () => {
"should return an array of SlashCommand objects", // Use the pattern from claude-agent.ts:
async () => { // Create a query with empty prompt generator for control methods
// Use the pattern from claude-agent.ts: const emptyPrompt = createEmptyPrompt();
// Create a query with empty prompt generator for control methods
const emptyPrompt = createEmptyPrompt();
const claudeQuery = query({ const claudeQuery = query({
prompt: emptyPrompt, prompt: emptyPrompt,
options: { options: {
cwd: process.cwd(), cwd: process.cwd(),
permissionMode: "plan", permissionMode: "plan",
includePartialMessages: false, includePartialMessages: false,
settingSources: ["user", "project"], // Required to load skills settingSources: ["user", "project"], // Required to load skills
}, },
}); });
try { try {
// supportedCommands() is a control method - works without iterating // supportedCommands() is a control method - works without iterating
const commands = await claudeQuery.supportedCommands(); const commands = await claudeQuery.supportedCommands();
// Should be an array // Should be an array
expect(Array.isArray(commands)).toBe(true); expect(Array.isArray(commands)).toBe(true);
// Verify structure // Verify structure
if (commands.length > 0) { if (commands.length > 0) {
const firstCommand = commands[0]; const firstCommand = commands[0];
expect(typeof firstCommand.name).toBe("string"); expect(typeof firstCommand.name).toBe("string");
expect(typeof firstCommand.description).toBe("string"); expect(typeof firstCommand.description).toBe("string");
expect(typeof firstCommand.argumentHint).toBe("string"); expect(typeof firstCommand.argumentHint).toBe("string");
expect(firstCommand.name.startsWith("/")).toBe(false); expect(firstCommand.name.startsWith("/")).toBe(false);
} }
} finally { } finally {
if (typeof claudeQuery.return === "function") { if (typeof claudeQuery.return === "function") {
try { try {
await claudeQuery.return(); await claudeQuery.return();
} catch { } catch {
// ignore shutdown errors // ignore shutdown errors
}
} }
} }
}, }
30000, }, 30000);
);
test.runIf(canRunClaudeIntegration)( test("should have valid SlashCommand structure for all commands", async () => {
"should have valid SlashCommand structure for all commands", const emptyPrompt = createEmptyPrompt();
async () => {
const emptyPrompt = createEmptyPrompt();
const claudeQuery = query({ const claudeQuery = query({
prompt: emptyPrompt, prompt: emptyPrompt,
options: { options: {
cwd: process.cwd(), cwd: process.cwd(),
permissionMode: "plan", permissionMode: "plan",
settingSources: ["user", "project"], settingSources: ["user", "project"],
}, },
}); });
try { try {
const commands = await claudeQuery.supportedCommands(); const commands = await claudeQuery.supportedCommands();
expect(commands.length).toBeGreaterThan(0); expect(commands.length).toBeGreaterThan(0);
// Verify all commands have valid structure // Verify all commands have valid structure
for (const cmd of commands) { for (const cmd of commands) {
expect(cmd).toHaveProperty("name"); expect(cmd).toHaveProperty("name");
expect(cmd).toHaveProperty("description"); expect(cmd).toHaveProperty("description");
expect(cmd).toHaveProperty("argumentHint"); expect(cmd).toHaveProperty("argumentHint");
expect(typeof cmd.name).toBe("string"); expect(typeof cmd.name).toBe("string");
expect(typeof cmd.description).toBe("string"); expect(typeof cmd.description).toBe("string");
expect(typeof cmd.argumentHint).toBe("string"); expect(typeof cmd.argumentHint).toBe("string");
expect(cmd.name.length).toBeGreaterThan(0); expect(cmd.name.length).toBeGreaterThan(0);
expect(cmd.name.startsWith("/")).toBe(false); expect(cmd.name.startsWith("/")).toBe(false);
}
} finally {
await claudeQuery.return?.();
} }
}, } finally {
30000, await claudeQuery.return?.();
); }
}, 30000);
}); });
describe("Command Execution", () => { describe("Command Execution", () => {
@@ -10,14 +10,14 @@
* CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY in the environment. * CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY in the environment.
* They are skipped automatically when credentials are unavailable. * They are skipped automatically when credentials are unavailable.
*/ */
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
import pino from "pino"; import pino from "pino";
import type { AgentSession, AgentStreamEvent } from "../../agent-sdk-types.js"; import type { AgentSession, AgentStreamEvent } from "../../agent-sdk-types.js";
import { isCommandAvailableSync } from "../../../../utils/executable.js"; import { isCommandAvailable } from "../../../../utils/executable.js";
import { ClaudeAgentClient } from "../claude-agent.js"; import { ClaudeAgentClient } from "../claude-agent.js";
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -28,7 +28,6 @@ const logger = pino({ level: "silent" });
const client = new ClaudeAgentClient({ logger }); const client = new ClaudeAgentClient({ logger });
const hasClaudeCredentials = const hasClaudeCredentials =
!!process.env.CLAUDE_CODE_OAUTH_TOKEN || !!process.env.ANTHROPIC_API_KEY; !!process.env.CLAUDE_CODE_OAUTH_TOKEN || !!process.env.ANTHROPIC_API_KEY;
const canRun = isCommandAvailableSync("claude") && hasClaudeCredentials;
function tmpCwd(prefix: string): string { function tmpCwd(prefix: string): string {
return mkdtempSync(path.join(tmpdir(), prefix)); return mkdtempSync(path.join(tmpdir(), prefix));
@@ -194,332 +193,308 @@ function assertInvariants(events: AgentStreamEvent[], foregroundTurnIds: string[
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
describe("Agent event stream redesign — integration", () => { describe("Agent event stream redesign — integration", () => {
test.skipIf(!canRun)( let canRun = false;
"Test 1: Basic foreground turn",
async () => {
const handle = await createSession({ cwdPrefix: "event-stream-basic-" });
try { beforeAll(async () => {
const { turnId, events } = await startTurnAndCollectEvents( canRun = (await isCommandAvailable("claude")) && hasClaudeCredentials;
handle.session, });
"respond with just the word hello",
);
const turnStarted = events.find( beforeEach((context) => {
if (!canRun) {
context.skip();
}
});
test("Test 1: Basic foreground turn", async () => {
const handle = await createSession({ cwdPrefix: "event-stream-basic-" });
try {
const { turnId, events } = await startTurnAndCollectEvents(
handle.session,
"respond with just the word hello",
);
const turnStarted = events.find(
(e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId,
);
expect(turnStarted).toBeDefined();
const terminal = events.find(
(e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === turnId,
);
expect(terminal).toBeDefined();
assertInvariants(events, [turnId]);
} finally {
await cleanupSession(handle);
}
}, 60_000);
test("Test 2: No duplicate user_messages — THE BUG", async () => {
const handle = await createSession({ cwdPrefix: "event-stream-dedup-" });
try {
const { turnId, events } = await startTurnAndCollectEvents(handle.session, "say hi", {
extraMs: 3_000,
});
expect(userMessagesWithText(events, "say hi").length).toBeLessThanOrEqual(1);
// No turn_started after terminal for the same turnId
const terminalIdx = events.findIndex(
(e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === turnId,
);
const staleTurnStarted = events
.slice(terminalIdx + 1)
.filter((e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId);
expect(staleTurnStarted.length).toBe(0);
assertInvariants(events, [turnId]);
} finally {
await cleanupSession(handle);
}
}, 60_000);
test("Test 3: Lifecycle doesn't get stuck in running", async () => {
const handle = await createSession({ cwdPrefix: "event-stream-lifecycle-" });
try {
const { turnId, events } = await startTurnAndCollectEvents(handle.session, "say hi", {
extraMs: 3_000,
});
const terminalIdx = events.findIndex(
(e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === turnId,
);
const afterTerminal = events.slice(terminalIdx + 1);
// No subsequent turn_started for same turnId
expect(
afterTerminal.filter(
(e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId, (e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId,
); ).length,
expect(turnStarted).toBeDefined(); ).toBe(0);
const terminal = events.find( // Any turn_started after terminal must have a different turnId
(e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === turnId, for (const ts of afterTerminal.filter((e) => e.type === "turn_started" && hasTurnId(e))) {
); expect((ts as EventWithTurnId).turnId).not.toBe(turnId);
expect(terminal).toBeDefined();
assertInvariants(events, [turnId]);
} finally {
await cleanupSession(handle);
} }
},
60_000,
);
test.skipIf(!canRun)( assertInvariants(events, [turnId]);
"Test 2: No duplicate user_messages — THE BUG", } finally {
async () => { await cleanupSession(handle);
const handle = await createSession({ cwdPrefix: "event-stream-dedup-" }); }
}, 60_000);
try { test("Test 4: Autonomous run", async () => {
const { turnId, events } = await startTurnAndCollectEvents(handle.session, "say hi", { const handle = await createSession({ cwdPrefix: "event-stream-autonomous-" });
extraMs: 3_000, const autonomousWakeToken = `AUTONOMOUS_WAKE_${Date.now().toString(36)}`;
});
expect(userMessagesWithText(events, "say hi").length).toBeLessThanOrEqual(1); try {
const { turnId: fgTurnId, events } = await startTurnAndCollectEvents(
handle.session,
[
"Use the Task tool to start a background sub-agent.",
"In that task, run the Bash command exactly: sleep 3 && echo BACKGROUND_DONE",
"Do not wait for task completion.",
"Reply immediately with exactly: SPAWNED",
`When the background task completes later, reply with exactly: ${autonomousWakeToken}`,
].join(" "),
{
extraMs: 10_000,
timeoutMs: 60_000,
},
);
// No turn_started after terminal for the same turnId const fgTerminalIdx = events.findIndex(
const terminalIdx = events.findIndex( (e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === fgTurnId,
(e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === turnId, );
); const afterForeground = events.slice(fgTerminalIdx + 1);
const staleTurnStarted = events
.slice(terminalIdx + 1)
.filter((e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId);
expect(staleTurnStarted.length).toBe(0);
assertInvariants(events, [turnId]);
} finally {
await cleanupSession(handle);
}
},
60_000,
);
test.skipIf(!canRun)(
"Test 3: Lifecycle doesn't get stuck in running",
async () => {
const handle = await createSession({ cwdPrefix: "event-stream-lifecycle-" });
try {
const { turnId, events } = await startTurnAndCollectEvents(handle.session, "say hi", {
extraMs: 3_000,
});
const terminalIdx = events.findIndex(
(e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === turnId,
);
const afterTerminal = events.slice(terminalIdx + 1);
// No subsequent turn_started for same turnId
expect(
afterTerminal.filter(
(e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId,
).length,
).toBe(0);
// Any turn_started after terminal must have a different turnId
for (const ts of afterTerminal.filter((e) => e.type === "turn_started" && hasTurnId(e))) {
expect((ts as EventWithTurnId).turnId).not.toBe(turnId);
}
assertInvariants(events, [turnId]);
} finally {
await cleanupSession(handle);
}
},
60_000,
);
test.skipIf(!canRun)(
"Test 4: Autonomous run",
async () => {
const handle = await createSession({ cwdPrefix: "event-stream-autonomous-" });
const autonomousWakeToken = `AUTONOMOUS_WAKE_${Date.now().toString(36)}`;
try {
const { turnId: fgTurnId, events } = await startTurnAndCollectEvents(
handle.session,
[
"Use the Task tool to start a background sub-agent.",
"In that task, run the Bash command exactly: sleep 3 && echo BACKGROUND_DONE",
"Do not wait for task completion.",
"Reply immediately with exactly: SPAWNED",
`When the background task completes later, reply with exactly: ${autonomousWakeToken}`,
].join(" "),
{
extraMs: 10_000,
timeoutMs: 60_000,
},
);
const fgTerminalIdx = events.findIndex(
(e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === fgTurnId,
);
const afterForeground = events.slice(fgTerminalIdx + 1);
// Autonomous turn_started with a different turnId
const autoStarts = afterForeground.filter(
(e) => e.type === "turn_started" && hasTurnId(e) && e.turnId !== fgTurnId,
) as EventWithTurnId[];
if (autoStarts.length === 0) {
assertInvariants(events, [fgTurnId]);
return;
}
const autoTurnId = autoStarts[0]!.turnId;
expect(fgTurnId).not.toBe(autoTurnId);
// Autonomous turn reaches terminal
expect(
afterForeground.find(
(e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === autoTurnId,
),
).toBeDefined();
// Autonomous turn_started with a different turnId
const autoStarts = afterForeground.filter(
(e) => e.type === "turn_started" && hasTurnId(e) && e.turnId !== fgTurnId,
) as EventWithTurnId[];
if (autoStarts.length === 0) {
assertInvariants(events, [fgTurnId]); assertInvariants(events, [fgTurnId]);
} finally { return;
await cleanupSession(handle);
} }
},
90_000,
);
test.skipIf(!canRun)( const autoTurnId = autoStarts[0]!.turnId;
"Test 5: Interruption", expect(fgTurnId).not.toBe(autoTurnId);
async () => {
const handle = await createSession({ cwdPrefix: "event-stream-interrupt-" });
try { // Autonomous turn reaches terminal
let turnId: string | null = null; expect(
const events = await new Promise<AgentStreamEvent[]>((resolve, reject) => { afterForeground.find((e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === autoTurnId),
const collected: AgentStreamEvent[] = []; ).toBeDefined();
let interrupted = false;
const timeout = setTimeout(() => { assertInvariants(events, [fgTurnId]);
} finally {
await cleanupSession(handle);
}
}, 90_000);
test("Test 5: Interruption", async () => {
const handle = await createSession({ cwdPrefix: "event-stream-interrupt-" });
try {
let turnId: string | null = null;
const events = await new Promise<AgentStreamEvent[]>((resolve, reject) => {
const collected: AgentStreamEvent[] = [];
let interrupted = false;
const timeout = setTimeout(() => {
unsubscribe();
reject(new Error("Timed out after 45000ms waiting for terminal event"));
}, 45_000);
const unsubscribe = handle.session.subscribe((event) => {
collected.push(event);
if (!turnId && event.type === "turn_started" && hasTurnId(event)) {
turnId = event.turnId;
}
// Once we see turn_started, fire the interrupt
if (
!interrupted &&
turnId &&
event.type === "turn_started" &&
hasTurnId(event) &&
event.turnId === turnId
) {
interrupted = true;
handle.session.interrupt().catch(() => undefined);
}
// Resolve when we get a terminal event for this turn
if (turnId && isTerminalEvent(event) && hasTurnId(event) && event.turnId === turnId) {
clearTimeout(timeout);
unsubscribe(); unsubscribe();
reject(new Error("Timed out after 45000ms waiting for terminal event")); resolve(collected);
}, 45_000); }
});
const unsubscribe = handle.session.subscribe((event) => { void handle.session
collected.push(event); .startTurn("write a very long essay about the history of computing")
if (!turnId && event.type === "turn_started" && hasTurnId(event)) { .then((result) => {
turnId = event.turnId; if (turnId && turnId !== result.turnId) {
}
// Once we see turn_started, fire the interrupt
if (
!interrupted &&
turnId &&
event.type === "turn_started" &&
hasTurnId(event) &&
event.turnId === turnId
) {
interrupted = true;
handle.session.interrupt().catch(() => undefined);
}
// Resolve when we get a terminal event for this turn
if (turnId && isTerminalEvent(event) && hasTurnId(event) && event.turnId === turnId) {
clearTimeout(timeout); clearTimeout(timeout);
unsubscribe(); unsubscribe();
resolve(collected); reject(
new Error(
`Observed turn_started for ${turnId} but startTurn returned ${result.turnId}`,
),
);
return;
} }
turnId = result.turnId;
})
.catch((error) => {
clearTimeout(timeout);
unsubscribe();
reject(error);
}); });
});
void handle.session expect(turnId).toBeDefined();
.startTurn("write a very long essay about the history of computing")
.then((result) => {
if (turnId && turnId !== result.turnId) {
clearTimeout(timeout);
unsubscribe();
reject(
new Error(
`Observed turn_started for ${turnId} but startTurn returned ${result.turnId}`,
),
);
return;
}
turnId = result.turnId;
})
.catch((error) => {
clearTimeout(timeout);
unsubscribe();
reject(error);
});
});
expect(turnId).toBeDefined(); // turn_canceled or turn_failed arrives for that turnId
const terminal = events.find(
(e) =>
(e.type === "turn_canceled" || e.type === "turn_failed") &&
hasTurnId(e) &&
e.turnId === turnId,
);
expect(terminal).toBeDefined();
// turn_canceled or turn_failed arrives for that turnId // No further events for that turnId after terminal
const terminal = events.find( const terminalIdx = events.indexOf(terminal!);
(e) => expect(
(e.type === "turn_canceled" || e.type === "turn_failed") && events.slice(terminalIdx + 1).filter((e) => hasTurnId(e) && e.turnId === turnId).length,
hasTurnId(e) && ).toBe(0);
e.turnId === turnId,
);
expect(terminal).toBeDefined();
// No further events for that turnId after terminal assertInvariants(events, [turnId]);
const terminalIdx = events.indexOf(terminal!); } finally {
expect( await cleanupSession(handle);
events.slice(terminalIdx + 1).filter((e) => hasTurnId(e) && e.turnId === turnId).length, }
).toBe(0); }, 60_000);
assertInvariants(events, [turnId]); test("Test 6: Sequential foreground turns", async () => {
} finally { const handle = await createSession({ cwdPrefix: "event-stream-sequential-" });
await cleanupSession(handle);
}
},
60_000,
);
test.skipIf(!canRun)( try {
"Test 6: Sequential foreground turns", const { turnId: turnId1, events: events1 } = await startTurnAndCollectEvents(
async () => { handle.session,
const handle = await createSession({ cwdPrefix: "event-stream-sequential-" }); "say first",
);
try { const { turnId: turnId2, events: events2 } = await startTurnAndCollectEvents(
const { turnId: turnId1, events: events1 } = await startTurnAndCollectEvents( handle.session,
handle.session, "say second",
"say first", );
);
const { turnId: turnId2, events: events2 } = await startTurnAndCollectEvents( const allEvents = [...events1, ...events2];
handle.session,
"say second",
);
const allEvents = [...events1, ...events2]; expect(turnId1).not.toBe(turnId2);
expect(turnId1).not.toBe(turnId2); // No events from turn 1 after turn 2 starts
const turn2StartIdx = allEvents.findIndex(
(e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId2,
);
expect(
allEvents.slice(turn2StartIdx + 1).filter((e) => hasTurnId(e) && e.turnId === turnId1)
.length,
).toBe(0);
// No events from turn 1 after turn 2 starts assertInvariants(allEvents, [turnId1, turnId2]);
const turn2StartIdx = allEvents.findIndex( } finally {
(e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId2, await cleanupSession(handle);
); }
expect( }, 90_000);
allEvents.slice(turn2StartIdx + 1).filter((e) => hasTurnId(e) && e.turnId === turnId1)
.length,
).toBe(0);
assertInvariants(allEvents, [turnId1, turnId2]); test("Test 7: Fast-fail", async () => {
} finally { const handle = await createSession({ cwdPrefix: "event-stream-fast-fail-" });
await cleanupSession(handle);
}
},
90_000,
);
test.skipIf(!canRun)( try {
"Test 7: Fast-fail", const { turnId, events } = await startTurnAndCollectEvents(handle.session, "", {
async () => { extraMs: 3_000,
const handle = await createSession({ cwdPrefix: "event-stream-fast-fail-" }); });
try { // At most one turn_started
const { turnId, events } = await startTurnAndCollectEvents(handle.session, "", { expect(
extraMs: 3_000, events.filter((e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId)
}); .length,
).toBeLessThanOrEqual(1);
// At most one turn_started // Terminal present
expect( const terminal = events.find(
events.filter((e) => e.type === "turn_started" && hasTurnId(e) && e.turnId === turnId) (e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === turnId,
.length, );
).toBeLessThanOrEqual(1); expect(terminal).toBeDefined();
// Terminal present // No stale turn_started after terminal
const terminal = events.find( const terminalIdx = events.indexOf(terminal!);
(e) => isTerminalEvent(e) && hasTurnId(e) && e.turnId === turnId, expect(events.slice(terminalIdx + 1).filter((e) => e.type === "turn_started").length).toBe(0);
);
expect(terminal).toBeDefined();
// No stale turn_started after terminal assertInvariants(events, [turnId]);
const terminalIdx = events.indexOf(terminal!); } finally {
expect(events.slice(terminalIdx + 1).filter((e) => e.type === "turn_started").length).toBe( await cleanupSession(handle);
0, }
); }, 60_000);
assertInvariants(events, [turnId]); test("Test 8: User message dedup by text", async () => {
} finally { const handle = await createSession({ cwdPrefix: "event-stream-user-dedup-" });
await cleanupSession(handle);
}
},
60_000,
);
test.skipIf(!canRun)( try {
"Test 8: User message dedup by text", const { turnId, events } = await startTurnAndCollectEvents(handle.session, "hello world", {
async () => { extraMs: 3_000,
const handle = await createSession({ cwdPrefix: "event-stream-user-dedup-" }); });
try { expect(userMessagesWithText(events, "hello world").length).toBeLessThanOrEqual(1);
const { turnId, events } = await startTurnAndCollectEvents(handle.session, "hello world", {
extraMs: 3_000,
});
expect(userMessagesWithText(events, "hello world").length).toBeLessThanOrEqual(1); assertInvariants(events, [turnId]);
} finally {
assertInvariants(events, [turnId]); await cleanupSession(handle);
} finally { }
await cleanupSession(handle); }, 60_000);
}
},
60_000,
);
}); });
@@ -1,14 +1,26 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import pino from "pino"; import pino from "pino";
import type { AgentSlashCommand } from "../agent-sdk-types.js"; import type { AgentSlashCommand } from "../agent-sdk-types.js";
import { isCommandAvailableSync } from "../../../utils/executable.js"; import { isCommandAvailable } from "../../../utils/executable.js";
import { ClaudeAgentClient } from "./claude-agent.js"; import { ClaudeAgentClient } from "./claude-agent.js";
// Real-Claude contract coverage: validates slash command shape from a live Claude CLI session. // Real-Claude contract coverage: validates slash command shape from a live Claude CLI session.
describe("claude agent commands contract (real)", () => { describe("claude agent commands contract (real)", () => {
let canRun = false;
beforeAll(async () => {
canRun = await isCommandAvailable("claude");
});
beforeEach((context) => {
if (!canRun) {
context.skip();
}
});
test("lists slash commands with the expected contract", async () => { test("lists slash commands with the expected contract", async () => {
expect(isCommandAvailableSync("claude")).toBe(true); expect(await isCommandAvailable("claude")).toBe(true);
const client = new ClaudeAgentClient({ const client = new ClaudeAgentClient({
logger: pino({ level: "silent" }), logger: pino({ level: "silent" }),
@@ -1,4 +1,4 @@
import { describe, expect, test, beforeAll } from "vitest"; import { describe, expect, test, beforeAll, beforeEach } from "vitest";
import { mkdtempSync, readFileSync, rmSync } from "node:fs"; import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -6,7 +6,7 @@ import pino from "pino";
import { query, type SDKUserMessage } from "@anthropic-ai/claude-agent-sdk"; import { query, type SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
import type { AgentSession, AgentStreamEvent, ToolCallTimelineItem } from "../agent-sdk-types.js"; import type { AgentSession, AgentStreamEvent, ToolCallTimelineItem } from "../agent-sdk-types.js";
import { isCommandAvailableSync } from "../../../utils/executable.js"; import { isCommandAvailable } from "../../../utils/executable.js";
import { ClaudeAgentClient } from "./claude-agent.js"; import { ClaudeAgentClient } from "./claude-agent.js";
import { streamSession } from "./test-utils/session-stream-adapter.js"; import { streamSession } from "./test-utils/session-stream-adapter.js";
@@ -174,111 +174,106 @@ async function cleanupSession(handle: { cwd: string; session: AgentSession }): P
} }
describe("ClaudeAgentSession integration", () => { describe("ClaudeAgentSession integration", () => {
const canRunClaudeIntegration = isCommandAvailableSync("claude") && hasClaudeCredentials; let canRunClaudeIntegration = false;
beforeAll(() => { beforeAll(async () => {
canRunClaudeIntegration = (await isCommandAvailable("claude")) && hasClaudeCredentials;
if (canRunClaudeIntegration) { if (canRunClaudeIntegration) {
expect(isCommandAvailableSync("claude")).toBe(true); expect(await isCommandAvailable("claude")).toBe(true);
} }
}); });
test.runIf(canRunClaudeIntegration)( beforeEach((context) => {
"streams a basic response turn end-to-end", if (!canRunClaudeIntegration) {
async () => { context.skip();
const handle = await createSession({ }
cwdPrefix: "claude-agent-basic-response-", });
test("streams a basic response turn end-to-end", async () => {
const handle = await createSession({
cwdPrefix: "claude-agent-basic-response-",
});
try {
const events = await collectUntilTerminal(
streamSession(handle.session, "Respond with exactly: HELLO_WORLD"),
);
expect(events[0]).toMatchObject({
type: "turn_started",
provider: "claude",
}); });
expect(
try { events.some(
const events = await collectUntilTerminal( (event) =>
streamSession(handle.session, "Respond with exactly: HELLO_WORLD"), event.type === "timeline" &&
); event.item.type === "assistant_message" &&
compactText(event.item.text).includes("hello_world"),
expect(events[0]).toMatchObject({ ),
type: "turn_started", ).toBe(true);
provider: "claude", expect(events.at(-1)).toMatchObject({
}); type: "turn_completed",
expect( provider: "claude",
events.some(
(event) =>
event.type === "timeline" &&
event.item.type === "assistant_message" &&
compactText(event.item.text).includes("hello_world"),
),
).toBe(true);
expect(events.at(-1)).toMatchObject({
type: "turn_completed",
provider: "claude",
});
} finally {
await cleanupSession(handle);
}
},
60_000,
);
test.runIf(canRunClaudeIntegration)(
"keeps bypassPermissions available after a thinking-option restart",
async () => {
const handle = await createSession({
cwdPrefix: "claude-agent-bypass-restart-",
modeId: "bypassPermissions",
}); });
} finally {
await cleanupSession(handle);
}
}, 60_000);
try { test("keeps bypassPermissions available after a thinking-option restart", async () => {
await handle.session.setMode("acceptEdits"); const handle = await createSession({
await handle.session.setThinkingOption("high"); cwdPrefix: "claude-agent-bypass-restart-",
await expect(handle.session.setMode("bypassPermissions")).resolves.toBeUndefined(); modeId: "bypassPermissions",
} finally { });
await cleanupSession(handle);
}
},
60_000,
);
test.runIf(canRunClaudeIntegration)( try {
"supportedModels returns the current abstract Claude SDK model shape", await handle.session.setMode("acceptEdits");
async () => { await handle.session.setThinkingOption("high");
const claudeQuery = query({ await expect(handle.session.setMode("bypassPermissions")).resolves.toBeUndefined();
prompt: createEmptyPrompt(), } finally {
options: { await cleanupSession(handle);
cwd: process.cwd(), }
permissionMode: "plan", }, 60_000);
includePartialMessages: false,
settingSources: ["user", "project"],
},
});
try { test("supportedModels returns the current abstract Claude SDK model shape", async () => {
const models = await claudeQuery.supportedModels(); const claudeQuery = query({
prompt: createEmptyPrompt(),
options: {
cwd: process.cwd(),
permissionMode: "plan",
includePartialMessages: false,
settingSources: ["user", "project"],
},
});
expect(models.length).toBeGreaterThanOrEqual(3); try {
expect(models).toContainEqual( const models = await claudeQuery.supportedModels();
expect.objectContaining({
value: "default", expect(models.length).toBeGreaterThanOrEqual(3);
displayName: "Default (recommended)", expect(models).toContainEqual(
supportedEffortLevels: ["low", "medium", "high", "max"], expect.objectContaining({
}), value: "default",
); displayName: "Default (recommended)",
expect(models).toContainEqual( supportedEffortLevels: ["low", "medium", "high", "max"],
expect.objectContaining({ }),
value: "haiku", );
displayName: "Haiku", expect(models).toContainEqual(
description: expect.stringContaining("Haiku 4.5"), expect.objectContaining({
}), value: "haiku",
); displayName: "Haiku",
expect( description: expect.stringContaining("Haiku 4.5"),
models.some( }),
(model) => );
model.description.includes("Opus 4.6") || model.description.includes("Sonnet 4.6"), expect(
), models.some(
).toBe(true); (model) =>
} finally { model.description.includes("Opus 4.6") || model.description.includes("Sonnet 4.6"),
await claudeQuery.return?.(); ),
} ).toBe(true);
}, } finally {
60_000, await claudeQuery.return?.();
); }
}, 60_000);
test.runIf(canRunClaudeIntegration)( test.runIf(canRunClaudeIntegration)(
"runs a real Bash tool call and completes it", "runs a real Bash tool call and completes it",
@@ -1,8 +1,8 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import pino from "pino"; import pino from "pino";
import type { AgentStreamEvent, AgentSession } from "../agent-sdk-types.js"; import type { AgentStreamEvent, AgentSession } from "../agent-sdk-types.js";
import { isCommandAvailableSync } from "../../../utils/executable.js"; import { isCommandAvailable } from "../../../utils/executable.js";
import { ClaudeAgentClient } from "./claude-agent.js"; import { ClaudeAgentClient } from "./claude-agent.js";
import { streamSession } from "./test-utils/session-stream-adapter.js"; import { streamSession } from "./test-utils/session-stream-adapter.js";
@@ -29,35 +29,43 @@ async function collectUntilTerminal(session: AgentSession): Promise<AgentStreamE
} }
describe("Claude max effort availability (real)", () => { describe("Claude max effort availability (real)", () => {
test.runIf(isCommandAvailableSync("claude") && hasClaudeCredentials)( let canRun = false;
"surfaces the Claude stderr diagnostic when bypassPermissions + max effort is unavailable",
async () => {
const client = new ClaudeAgentClient({
logger: pino({ level: "silent" }),
});
const session = await client.createSession({
provider: "claude",
cwd: process.cwd(),
modeId: "bypassPermissions",
model: "claude-opus-4-6",
thinkingOptionId: "max",
});
try { beforeAll(async () => {
const events = await collectUntilTerminal(session); canRun = (await isCommandAvailable("claude")) && hasClaudeCredentials;
const failure = events.find( });
(event): event is Extract<AgentStreamEvent, { type: "turn_failed" }> =>
event.type === "turn_failed",
);
expect(failure).toBeDefined(); beforeEach((context) => {
expect(failure?.error).toContain("Claude Code process exited with code 1"); if (!canRun) {
expect(failure?.code).toBe("1"); context.skip();
expect(failure?.diagnostic).toContain('Effort level "max" is not available'); }
} finally { });
await session.close().catch(() => undefined);
} test("surfaces the Claude stderr diagnostic when bypassPermissions + max effort is unavailable", async () => {
}, const client = new ClaudeAgentClient({
30_000, logger: pino({ level: "silent" }),
); });
const session = await client.createSession({
provider: "claude",
cwd: process.cwd(),
modeId: "bypassPermissions",
model: "claude-opus-4-6",
thinkingOptionId: "max",
});
try {
const events = await collectUntilTerminal(session);
const failure = events.find(
(event): event is Extract<AgentStreamEvent, { type: "turn_failed" }> =>
event.type === "turn_failed",
);
expect(failure).toBeDefined();
expect(failure?.error).toContain("Claude Code process exited with code 1");
expect(failure?.code).toBe("1");
expect(failure?.diagnostic).toContain('Effort level "max" is not available');
} finally {
await session.close().catch(() => undefined);
}
}, 30_000);
}); });
@@ -1,5 +1,4 @@
import { execFile, type ChildProcessWithoutNullStreams } from "node:child_process"; import { type ChildProcessWithoutNullStreams } from "node:child_process";
import { promisify } from "node:util";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
import fs from "node:fs"; import fs from "node:fs";
import { promises } from "node:fs"; import { promises } from "node:fs";
@@ -73,12 +72,11 @@ import type {
PersistedAgentDescriptor, PersistedAgentDescriptor,
} from "../agent-sdk-types.js"; } from "../agent-sdk-types.js";
import { applyProviderEnv, type ProviderRuntimeSettings } from "../provider-launch-config.js"; import { applyProviderEnv, type ProviderRuntimeSettings } from "../provider-launch-config.js";
import { findExecutable } from "../../../utils/executable.js"; import { executableExists, findExecutable } from "../../../utils/executable.js";
import { spawnProcess } from "../../../utils/spawn.js"; import { execCommand, spawnProcess } from "../../../utils/spawn.js";
import { getOrchestratorModeInstructions } from "../orchestrator-instructions.js"; import { getOrchestratorModeInstructions } from "../orchestrator-instructions.js";
const fsPromises = promises; const fsPromises = promises;
const execFileAsync = promisify(execFile);
const CLAUDE_SETTING_SOURCES: NonNullable<Options["settingSources"]> = ["user", "project"]; const CLAUDE_SETTING_SOURCES: NonNullable<Options["settingSources"]> = ["user", "project"];
type TurnState = "idle" | "foreground" | "autonomous"; type TurnState = "idle" | "foreground" | "autonomous";
@@ -1130,7 +1128,7 @@ export class ClaudeAgentClient implements AgentClient {
async isAvailable(): Promise<boolean> { async isAvailable(): Promise<boolean> {
const command = this.runtimeSettings?.command; const command = this.runtimeSettings?.command;
if (command?.mode === "replace") { if (command?.mode === "replace") {
return fs.existsSync(command.argv[0]); return executableExists(command.argv[0]) !== null;
} }
return true; return true;
} }
@@ -1186,14 +1184,10 @@ async function resolveClaudeVersion(
try { try {
if (command?.mode === "replace") { if (command?.mode === "replace") {
const { stdout } = await execFileAsync( const { stdout } = await execCommand(
command.argv[0]!, command.argv[0]!,
[...command.argv.slice(1), "--version"], [...command.argv.slice(1), "--version"],
{ { timeout: 5_000 },
encoding: "utf8",
timeout: 5_000,
windowsHide: true,
},
); );
return stdout.trim() || null; return stdout.trim() || null;
} }
@@ -1203,11 +1197,7 @@ async function resolveClaudeVersion(
return null; return null;
} }
const { stdout } = await execFileAsync(executable, ["--version"], { const { stdout } = await execCommand(executable, ["--version"], { timeout: 5_000 });
encoding: "utf8",
timeout: 5_000,
windowsHide: true,
});
return stdout.trim() || null; return stdout.trim() || null;
} catch { } catch {
return null; return null;
@@ -4,9 +4,9 @@
import { mkdtempSync, rmSync, realpathSync } from "node:fs"; import { mkdtempSync, rmSync, realpathSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
import { beforeAll, describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { query, type SDKMessage, type SDKUserMessage } from "@anthropic-ai/claude-agent-sdk"; import { query, type SDKMessage, type SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
import { findExecutable, isCommandAvailableSync } from "../../../utils/executable.js"; import { findExecutable, isCommandAvailable } from "../../../utils/executable.js";
class Pushable<T> implements AsyncIterable<T> { class Pushable<T> implements AsyncIterable<T> {
private queue: T[] = []; private queue: T[] = [];
@@ -57,100 +57,103 @@ const hasClaudeCredentials =
!!process.env.CLAUDE_CODE_OAUTH_TOKEN || !!process.env.ANTHROPIC_API_KEY; !!process.env.CLAUDE_CODE_OAUTH_TOKEN || !!process.env.ANTHROPIC_API_KEY;
describe("Claude SDK direct behavior", () => { describe("Claude SDK direct behavior", () => {
const canRunClaudeIntegration = isCommandAvailableSync("claude") && hasClaudeCredentials; let canRunClaudeIntegration = false;
beforeAll(() => { beforeAll(async () => {
canRunClaudeIntegration = (await isCommandAvailable("claude")) && hasClaudeCredentials;
if (canRunClaudeIntegration) { if (canRunClaudeIntegration) {
expect(isCommandAvailableSync("claude")).toBe(true); expect(await isCommandAvailable("claude")).toBe(true);
} }
}); });
test.runIf(canRunClaudeIntegration)( beforeEach((context) => {
"shows what happens after interrupt()", if (!canRunClaudeIntegration) {
async () => { context.skip();
const cwd = tmpCwd(); }
const input = new Pushable<SDKUserMessage>(); });
const claudeBinary = await findExecutable("claude");
// Use same options as claude-agent.ts test("shows what happens after interrupt()", async () => {
const q = query({ const cwd = tmpCwd();
prompt: input, const input = new Pushable<SDKUserMessage>();
options: { const claudeBinary = await findExecutable("claude");
cwd,
includePartialMessages: true, // Use same options as claude-agent.ts
permissionMode: "bypassPermissions", const q = query({
...(claudeBinary ? { pathToClaudeCodeExecutable: claudeBinary } : {}), prompt: input,
systemPrompt: { options: {
type: "preset", cwd,
preset: "claude_code", includePartialMessages: true,
}, permissionMode: "bypassPermissions",
settingSources: ["user", "project"], ...(claudeBinary ? { pathToClaudeCodeExecutable: claudeBinary } : {}),
systemPrompt: {
type: "preset",
preset: "claude_code",
}, },
settingSources: ["user", "project"],
},
});
try {
// Send first message
input.push({
type: "user",
message: { role: "user", content: "Say exactly: MESSAGE_ONE" },
parent_tool_use_id: null,
session_id: "",
}); });
try { // Collect events until we see assistant, then interrupt
// Send first message const msg1Events: SDKMessage[] = [];
input.push({ for await (const event of q) {
type: "user", msg1Events.push(event);
message: { role: "user", content: "Say exactly: MESSAGE_ONE" },
parent_tool_use_id: null,
session_id: "",
});
// Collect events until we see assistant, then interrupt if (event.type === "assistant") {
const msg1Events: SDKMessage[] = []; // Push MSG2 BEFORE interrupt (like our wrapper does when a new message comes in)
for await (const event of q) { input.push({
msg1Events.push(event); type: "user",
message: { role: "user", content: "Say exactly: MESSAGE_TWO" },
if (event.type === "assistant") { parent_tool_use_id: null,
// Push MSG2 BEFORE interrupt (like our wrapper does when a new message comes in) session_id: "",
input.push({ });
type: "user", await q.interrupt();
message: { role: "user", content: "Say exactly: MESSAGE_TWO" }, break;
parent_tool_use_id: null,
session_id: "",
});
await q.interrupt();
break;
}
if (event.type === "result") {
break;
}
} }
if (event.type === "result") {
// MSG2 was already pushed before interrupt break;
const msg2Events: SDKMessage[] = [];
for await (const event of q) {
msg2Events.push(event);
if (event.type === "result") {
break;
}
} }
}
// Analyze response // MSG2 was already pushed before interrupt
let responseText = ""; const msg2Events: SDKMessage[] = [];
for (const event of msg2Events) { for await (const event of q) {
if (event.type === "assistant" && "message" in event && event.message?.content) { msg2Events.push(event);
const content = event.message.content;
if (Array.isArray(content)) { if (event.type === "result") {
for (const block of content) { break;
if (block.type === "text" && block.text) { }
responseText += block.text; }
}
// Analyze response
let responseText = "";
for (const event of msg2Events) {
if (event.type === "assistant" && "message" in event && event.message?.content) {
const content = event.message.content;
if (Array.isArray(content)) {
for (const block of content) {
if (block.type === "text" && block.text) {
responseText += block.text;
} }
} }
} }
} }
const sawResult = msg2Events.some((event) => event.type === "result");
// The SDK may short-circuit after interrupt without a result event.
expect(sawResult || responseText.length === 0).toBe(true);
} finally {
input.end();
rmSync(cwd, { recursive: true, force: true });
} }
},
120000, const sawResult = msg2Events.some((event) => event.type === "result");
); // The SDK may short-circuit after interrupt without a result event.
expect(sawResult || responseText.length === 0).toBe(true);
} finally {
input.end();
rmSync(cwd, { recursive: true, force: true });
}
}, 120000);
}); });
@@ -31,7 +31,7 @@ import type { Logger } from "pino";
import { execSync } from "node:child_process"; import { execSync } from "node:child_process";
import type { ChildProcessWithoutNullStreams } from "node:child_process"; import type { ChildProcessWithoutNullStreams } from "node:child_process";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
import { existsSync, Dirent } from "node:fs"; import { Dirent } from "node:fs";
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
@@ -47,7 +47,7 @@ import {
resolveProviderCommandPrefix, resolveProviderCommandPrefix,
type ProviderRuntimeSettings, type ProviderRuntimeSettings,
} from "../provider-launch-config.js"; } from "../provider-launch-config.js";
import { findExecutable } from "../../../utils/executable.js"; import { executableExists, findExecutable } from "../../../utils/executable.js";
import { spawnProcess } from "../../../utils/spawn.js"; import { spawnProcess } from "../../../utils/spawn.js";
import { extractCodexTerminalSessionId, nonEmptyString } from "./tool-call-mapper-utils.js"; import { extractCodexTerminalSessionId, nonEmptyString } from "./tool-call-mapper-utils.js";
import { buildCodexFeatures, codexModelSupportsFastMode } from "./codex-feature-definitions.js"; import { buildCodexFeatures, codexModelSupportsFastMode } from "./codex-feature-definitions.js";
@@ -4203,7 +4203,7 @@ export class CodexAppServerAgentClient implements AgentClient {
async isAvailable(): Promise<boolean> { async isAvailable(): Promise<boolean> {
const command = this.runtimeSettings?.command; const command = this.runtimeSettings?.command;
if (command?.mode === "replace") { if (command?.mode === "replace") {
return existsSync(command.argv[0]); return executableExists(command.argv[0]) !== null;
} }
return true; return true;
} }
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -12,53 +12,61 @@ function tmpCwd(): string {
} }
describe("Codex app-server provider (real) plan mode", () => { describe("Codex app-server provider (real) plan mode", () => {
test.runIf(isProviderAvailable("codex"))( let canRun = false;
"maps gpt-5.4 markdown plans to a plan tool call instead of todo items",
async () => { beforeAll(async () => {
const cwd = tmpCwd(); canRun = await isProviderAvailable("codex");
const client = new CodexAppServerAgentClient(createTestLogger()); });
beforeEach((context) => {
if (!canRun) {
context.skip();
}
});
test("maps gpt-5.4 markdown plans to a plan tool call instead of todo items", async () => {
const cwd = tmpCwd();
const client = new CodexAppServerAgentClient(createTestLogger());
try {
const session = await client.createSession({
provider: "codex",
cwd,
modeId: "auto",
model: "gpt-5.4",
thinkingOptionId: "medium",
});
try { try {
const session = await client.createSession({ await session.setFeature?.("plan_mode", true);
provider: "codex",
cwd,
modeId: "auto",
model: "gpt-5.4",
thinkingOptionId: "medium",
});
try { const result = await session.run(
await session.setFeature?.("plan_mode", true); "You are in plan mode. Produce a markdown plan with a short heading and exactly 3 bullets for implementing a login screen. Do not ask questions.",
);
const result = await session.run( expect(result.timeline).not.toContainEqual(
"You are in plan mode. Produce a markdown plan with a short heading and exactly 3 bullets for implementing a login screen. Do not ask questions.", expect.objectContaining({
); type: "todo",
}),
);
expect(result.timeline).not.toContainEqual( const planCall = result.timeline.find(
expect.objectContaining({ (item) => item.type === "tool_call" && item.detail.type === "plan",
type: "todo", );
}),
);
const planCall = result.timeline.find( expect(planCall).toBeDefined();
(item) => item.type === "tool_call" && item.detail.type === "plan", if (!planCall || planCall.type !== "tool_call" || planCall.detail.type !== "plan") {
); throw new Error("Expected a plan tool call");
expect(planCall).toBeDefined();
if (!planCall || planCall.type !== "tool_call" || planCall.detail.type !== "plan") {
throw new Error("Expected a plan tool call");
}
expect(planCall.detail.text).toContain("Login");
expect(planCall.detail.text).toContain("- ");
expect(result.finalText).toBe(planCall.detail.text);
} finally {
await session.close();
} }
expect(planCall.detail.text).toContain("Login");
expect(planCall.detail.text).toContain("- ");
expect(result.finalText).toBe(planCall.detail.text);
} finally { } finally {
rmSync(cwd, { recursive: true, force: true }); await session.close();
} }
}, } finally {
240_000, rmSync(cwd, { recursive: true, force: true });
); }
}, 240_000);
}); });
@@ -1,9 +1,5 @@
import { execFile } from "node:child_process";
import { promisify } from "node:util";
import type { ProviderRuntimeSettings } from "../provider-launch-config.js"; import type { ProviderRuntimeSettings } from "../provider-launch-config.js";
import { execCommand } from "../../../utils/spawn.js";
const execFileAsync = promisify(execFile);
type DiagnosticEntry = { type DiagnosticEntry = {
label: string; label: string;
@@ -49,11 +45,7 @@ export function toDiagnosticErrorMessage(error: unknown): string {
export async function resolveBinaryVersion(binaryPath: string): Promise<string> { export async function resolveBinaryVersion(binaryPath: string): Promise<string> {
try { try {
const { stdout } = await execFileAsync(binaryPath, ["--version"], { const { stdout } = await execCommand(binaryPath, ["--version"], { timeout: 5_000 });
encoding: "utf8",
timeout: 5_000,
windowsHide: true,
});
return stdout.trim() || "unknown"; return stdout.trim() || "unknown";
} catch { } catch {
return "unknown"; return "unknown";
@@ -1,13 +1,25 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import pino from "pino"; import pino from "pino";
import type { AgentSlashCommand } from "../agent-sdk-types.js"; import type { AgentSlashCommand } from "../agent-sdk-types.js";
import { isCommandAvailableSync } from "../../../utils/executable.js"; import { isCommandAvailable } from "../../../utils/executable.js";
import { OpenCodeAgentClient } from "./opencode-agent.js"; import { OpenCodeAgentClient } from "./opencode-agent.js";
describe("opencode agent commands contract (real)", () => { describe("opencode agent commands contract (real)", () => {
let canRun = false;
beforeAll(async () => {
canRun = await isCommandAvailable("opencode");
});
beforeEach((context) => {
if (!canRun) {
context.skip();
}
});
test("lists slash commands with the expected contract", async () => { test("lists slash commands with the expected contract", async () => {
expect(isCommandAvailableSync("opencode")).toBe(true); expect(await isCommandAvailable("opencode")).toBe(true);
const client = new OpenCodeAgentClient(pino({ level: "silent" })); const client = new OpenCodeAgentClient(pino({ level: "silent" }));
const session = await client.createSession({ const session = await client.createSession({
@@ -37,7 +49,7 @@ describe("opencode agent commands contract (real)", () => {
}, 60_000); }, 60_000);
test("executes a slash command without arguments", async () => { test("executes a slash command without arguments", async () => {
expect(isCommandAvailableSync("opencode")).toBe(true); expect(await isCommandAvailable("opencode")).toBe(true);
const client = new OpenCodeAgentClient(pino({ level: "silent" })); const client = new OpenCodeAgentClient(pino({ level: "silent" }));
const session = await client.createSession({ const session = await client.createSession({
@@ -1,8 +1,8 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import pino from "pino"; import pino from "pino";
import type { AgentStreamEvent } from "../agent-sdk-types.js"; import type { AgentStreamEvent } from "../agent-sdk-types.js";
import { isCommandAvailableSync } from "../../../utils/executable.js"; import { isCommandAvailable } from "../../../utils/executable.js";
import { OpenCodeAgentClient } from "./opencode-agent.js"; import { OpenCodeAgentClient } from "./opencode-agent.js";
import { streamSession } from "./test-utils/session-stream-adapter.js"; import { streamSession } from "./test-utils/session-stream-adapter.js";
@@ -21,166 +21,158 @@ function isTerminalEvent(event: AgentStreamEvent): boolean {
* when models are invalid, auth fails, or provider API calls fail. * when models are invalid, auth fails, or provider API calls fail.
*/ */
describe("opencode agent error handling (real)", () => { describe("opencode agent error handling (real)", () => {
test.runIf(isCommandAvailableSync("opencode"))( let canRun = false;
"surfaces error for the exact opencode/<bad-model> path used by paseo run",
async () => {
const client = new OpenCodeAgentClient(pino({ level: "silent" }));
const session = await client.createSession({
provider: "opencode",
cwd: process.cwd(),
modeId: "build",
});
try { beforeAll(async () => {
await session.setModel("opencode/adklasldkdas"); canRun = await isCommandAvailable("opencode");
});
const events: AgentStreamEvent[] = []; beforeEach((context) => {
for await (const event of streamSession(session, "hello")) { if (!canRun) {
events.push(event); context.skip();
if (isTerminalEvent(event)) break; }
} });
const terminal = events.find(isTerminalEvent); test("surfaces error for the exact opencode/<bad-model> path used by paseo run", async () => {
expect(terminal).toBeDefined(); const client = new OpenCodeAgentClient(pino({ level: "silent" }));
expect(terminal!.type).toBe("turn_failed"); const session = await client.createSession({
} finally { provider: "opencode",
await session.close().catch(() => undefined); cwd: process.cwd(),
} modeId: "build",
}, });
45_000,
);
test.runIf(isCommandAvailableSync("opencode"))( try {
"surfaces error for unknown provider model (fast path)", await session.setModel("opencode/adklasldkdas");
async () => {
const client = new OpenCodeAgentClient(pino({ level: "silent" }));
const session = await client.createSession({
provider: "opencode",
cwd: process.cwd(),
modeId: "build",
});
try {
await session.setModel("bogus-provider/totally-fake-model-12345");
const events: AgentStreamEvent[] = [];
for await (const event of streamSession(session, "Say hello")) {
events.push(event);
if (isTerminalEvent(event)) break;
}
const terminal = events.find(isTerminalEvent);
expect(terminal).toBeDefined();
expect(terminal!.type).toBe("turn_failed");
} finally {
await session.close().catch(() => undefined);
}
},
30_000,
);
test.runIf(isCommandAvailableSync("opencode"))(
"sequential sessions: second session works after first errors",
async () => {
const client = new OpenCodeAgentClient(pino({ level: "silent" }));
// Session 1: bogus model, will error quickly
const s1 = await client.createSession({
provider: "opencode",
cwd: process.cwd(),
modeId: "build",
});
await s1.setModel("bogus-provider/fake-model-12345");
for await (const event of streamSession(s1, "Say hello")) {
if (isTerminalEvent(event)) break;
}
await s1.close();
// Session 2: different bogus model, should also work
const s2 = await client.createSession({
provider: "opencode",
cwd: process.cwd(),
modeId: "build",
});
await s2.setModel("bogus-provider/fake-model-67890");
const events: AgentStreamEvent[] = []; const events: AgentStreamEvent[] = [];
for await (const event of streamSession(s2, "Say hello")) { for await (const event of streamSession(session, "hello")) {
events.push(event); events.push(event);
if (isTerminalEvent(event)) break; if (isTerminalEvent(event)) break;
} }
await s2.close().catch(() => undefined);
const terminal = events.find(isTerminalEvent); const terminal = events.find(isTerminalEvent);
expect(terminal).toBeDefined(); expect(terminal).toBeDefined();
expect(terminal!.type).toBe("turn_failed"); expect(terminal!.type).toBe("turn_failed");
}, } finally {
30_000, await session.close().catch(() => undefined);
); }
}, 45_000);
test.runIf(isCommandAvailableSync("opencode"))( test("surfaces error for unknown provider model (fast path)", async () => {
"surfaces error for known provider with nonexistent model (retry path)", const client = new OpenCodeAgentClient(pino({ level: "silent" }));
async () => { const session = await client.createSession({
// When the provider is recognized (anthropic) but the model doesn't exist, provider: "opencode",
// OpenCode retries before surfacing the error. This must not hang. cwd: process.cwd(),
const client = new OpenCodeAgentClient(pino({ level: "silent" })); modeId: "build",
const session = await client.createSession({ });
provider: "opencode",
cwd: process.cwd(),
modeId: "build",
});
try { try {
await session.setModel("anthropic/claude-nonexistent-99"); await session.setModel("bogus-provider/totally-fake-model-12345");
const events: AgentStreamEvent[] = []; const events: AgentStreamEvent[] = [];
const start = Date.now(); for await (const event of streamSession(session, "Say hello")) {
for await (const event of streamSession(session, "Say hello")) { events.push(event);
events.push(event); if (isTerminalEvent(event)) break;
if (isTerminalEvent(event)) break;
}
const elapsed = Date.now() - start;
const terminal = events.find(isTerminalEvent);
expect(terminal).toBeDefined();
expect(elapsed).toBeLessThan(30_000);
console.log(`[nonexistent model] elapsed=${elapsed}ms terminal=${terminal!.type}`);
} finally {
await session.close().catch(() => undefined);
} }
},
45_000,
);
test.runIf(isCommandAvailableSync("opencode"))( const terminal = events.find(isTerminalEvent);
"surfaces fatal retry status from zai/glm-5.1 instead of hanging forever", expect(terminal).toBeDefined();
async () => { expect(terminal!.type).toBe("turn_failed");
const client = new OpenCodeAgentClient(pino({ level: "silent" })); } finally {
const session = await client.createSession({ await session.close().catch(() => undefined);
provider: "opencode", }
cwd: process.cwd(), }, 30_000);
modeId: "build",
});
try { test("sequential sessions: second session works after first errors", async () => {
await session.setModel("zai/glm-5.1"); const client = new OpenCodeAgentClient(pino({ level: "silent" }));
const events: AgentStreamEvent[] = []; // Session 1: bogus model, will error quickly
for await (const event of streamSession(session, "Say hello")) { const s1 = await client.createSession({
events.push(event); provider: "opencode",
if (isTerminalEvent(event)) break; cwd: process.cwd(),
} modeId: "build",
});
await s1.setModel("bogus-provider/fake-model-12345");
for await (const event of streamSession(s1, "Say hello")) {
if (isTerminalEvent(event)) break;
}
await s1.close();
const terminal = events.find(isTerminalEvent); // Session 2: different bogus model, should also work
expect(terminal).toBeDefined(); const s2 = await client.createSession({
expect(terminal!.type).toBe("turn_failed"); provider: "opencode",
expect((terminal!.type === "turn_failed" ? terminal!.error : "").toLowerCase()).toMatch( cwd: process.cwd(),
/insufficient balance|resource package|recharge/, modeId: "build",
); });
} finally { await s2.setModel("bogus-provider/fake-model-67890");
await session.close().catch(() => undefined);
const events: AgentStreamEvent[] = [];
for await (const event of streamSession(s2, "Say hello")) {
events.push(event);
if (isTerminalEvent(event)) break;
}
await s2.close().catch(() => undefined);
const terminal = events.find(isTerminalEvent);
expect(terminal).toBeDefined();
expect(terminal!.type).toBe("turn_failed");
}, 30_000);
test("surfaces error for known provider with nonexistent model (retry path)", async () => {
// When the provider is recognized (anthropic) but the model doesn't exist,
// OpenCode retries before surfacing the error. This must not hang.
const client = new OpenCodeAgentClient(pino({ level: "silent" }));
const session = await client.createSession({
provider: "opencode",
cwd: process.cwd(),
modeId: "build",
});
try {
await session.setModel("anthropic/claude-nonexistent-99");
const events: AgentStreamEvent[] = [];
const start = Date.now();
for await (const event of streamSession(session, "Say hello")) {
events.push(event);
if (isTerminalEvent(event)) break;
} }
}, const elapsed = Date.now() - start;
45_000,
); const terminal = events.find(isTerminalEvent);
expect(terminal).toBeDefined();
expect(elapsed).toBeLessThan(30_000);
console.log(`[nonexistent model] elapsed=${elapsed}ms terminal=${terminal!.type}`);
} finally {
await session.close().catch(() => undefined);
}
}, 45_000);
test("surfaces fatal retry status from zai/glm-5.1 instead of hanging forever", async () => {
const client = new OpenCodeAgentClient(pino({ level: "silent" }));
const session = await client.createSession({
provider: "opencode",
cwd: process.cwd(),
modeId: "build",
});
try {
await session.setModel("zai/glm-5.1");
const events: AgentStreamEvent[] = [];
for await (const event of streamSession(session, "Say hello")) {
events.push(event);
if (isTerminalEvent(event)) break;
}
const terminal = events.find(isTerminalEvent);
expect(terminal).toBeDefined();
expect(terminal!.type).toBe("turn_failed");
expect((terminal!.type === "turn_failed" ? terminal!.error : "").toLowerCase()).toMatch(
/insufficient balance|resource package|recharge/,
);
} finally {
await session.close().catch(() => undefined);
}
}, 45_000);
}); });
@@ -1,5 +1,4 @@
import type { ChildProcess } from "node:child_process"; import type { ChildProcess } from "node:child_process";
import { existsSync } from "node:fs";
import { import {
createOpencodeClient, createOpencodeClient,
type AssistantMessage as OpenCodeAssistantMessage, type AssistantMessage as OpenCodeAssistantMessage,
@@ -44,7 +43,7 @@ import {
resolveProviderCommandPrefix, resolveProviderCommandPrefix,
type ProviderRuntimeSettings, type ProviderRuntimeSettings,
} from "../provider-launch-config.js"; } from "../provider-launch-config.js";
import { findExecutable } from "../../../utils/executable.js"; import { executableExists, findExecutable } from "../../../utils/executable.js";
import { spawnProcess } from "../../../utils/spawn.js"; import { spawnProcess } from "../../../utils/spawn.js";
import { mapOpencodeToolCall } from "./opencode/tool-call-mapper.js"; import { mapOpencodeToolCall } from "./opencode/tool-call-mapper.js";
import { import {
@@ -917,7 +916,7 @@ export class OpenCodeAgentClient implements AgentClient {
async isAvailable(): Promise<boolean> { async isAvailable(): Promise<boolean> {
const command = this.runtimeSettings?.command; const command = this.runtimeSettings?.command;
if (command?.mode === "replace") { if (command?.mode === "replace") {
return existsSync(command.argv[0]); return executableExists(command.argv[0]) !== null;
} }
return true; return true;
} }
@@ -1,4 +1,4 @@
import { describe, test, expect } from "vitest"; import { beforeAll, beforeEach, describe, test, expect } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -9,62 +9,66 @@ import { isProviderAvailable } from "../../daemon-e2e/agent-configs.js";
import type { AgentStreamEvent } from "../agent-sdk-types.js"; import type { AgentStreamEvent } from "../agent-sdk-types.js";
describe("OpenCode assistant message", () => { describe("OpenCode assistant message", () => {
test.runIf(isProviderAvailable("opencode"))( let canRun = false;
"assistant_message appears in live stream with opencode/big-pickle",
async () => {
const cwd = mkdtempSync(path.join(tmpdir(), "opencode-msg-"));
const logger = pino({ level: "silent" });
const client = new OpenCodeAgentClient(logger);
try { beforeAll(async () => {
const session = await client.createSession({ canRun = await isProviderAvailable("opencode");
provider: "opencode", });
cwd,
model: "opencode/big-pickle",
modeId: "build",
});
const result = await session.run("Say hello back in one sentence."); beforeEach((context) => {
if (!canRun) {
context.skip();
}
});
const assistantItems = result.timeline.filter((item) => item.type === "assistant_message"); test("assistant_message appears in live stream with opencode/big-pickle", async () => {
expect(assistantItems.length).toBeGreaterThan(0); const cwd = mkdtempSync(path.join(tmpdir(), "opencode-msg-"));
expect(result.finalText.length).toBeGreaterThan(0); const logger = pino({ level: "silent" });
} finally { const client = new OpenCodeAgentClient(logger);
rmSync(cwd, { recursive: true, force: true });
try {
const session = await client.createSession({
provider: "opencode",
cwd,
model: "opencode/big-pickle",
modeId: "build",
});
const result = await session.run("Say hello back in one sentence.");
const assistantItems = result.timeline.filter((item) => item.type === "assistant_message");
expect(assistantItems.length).toBeGreaterThan(0);
expect(result.finalText.length).toBeGreaterThan(0);
} finally {
rmSync(cwd, { recursive: true, force: true });
}
}, 60_000);
test("streamHistory returns assistant_message after a completed turn", async () => {
const cwd = mkdtempSync(path.join(tmpdir(), "opencode-history-"));
const logger = pino({ level: "silent" });
const client = new OpenCodeAgentClient(logger);
try {
const session = await client.createSession({
provider: "opencode",
cwd,
});
const result = await session.run("Say hello back in one sentence.");
expect(result.timeline.some((item) => item.type === "assistant_message")).toBe(true);
const historyEvents: AgentStreamEvent[] = [];
for await (const event of session.streamHistory()) {
historyEvents.push(event);
} }
},
60_000,
);
test.runIf(isProviderAvailable("opencode"))( const historyAssistant = historyEvents.filter(
"streamHistory returns assistant_message after a completed turn", (e) => e.type === "timeline" && e.item.type === "assistant_message",
async () => { );
const cwd = mkdtempSync(path.join(tmpdir(), "opencode-history-")); expect(historyAssistant.length).toBeGreaterThan(0);
const logger = pino({ level: "silent" }); } finally {
const client = new OpenCodeAgentClient(logger); rmSync(cwd, { recursive: true, force: true });
}
try { }, 60_000);
const session = await client.createSession({
provider: "opencode",
cwd,
});
const result = await session.run("Say hello back in one sentence.");
expect(result.timeline.some((item) => item.type === "assistant_message")).toBe(true);
const historyEvents: AgentStreamEvent[] = [];
for await (const event of session.streamHistory()) {
historyEvents.push(event);
}
const historyAssistant = historyEvents.filter(
(e) => e.type === "timeline" && e.item.type === "assistant_message",
);
expect(historyAssistant.length).toBeGreaterThan(0);
} finally {
rmSync(cwd, { recursive: true, force: true });
}
},
60_000,
);
}); });
@@ -1,4 +1,4 @@
import { describe, test, expect } from "vitest"; import { beforeAll, beforeEach, describe, test, expect } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -9,60 +9,68 @@ import { isProviderAvailable } from "../../daemon-e2e/agent-configs.js";
import type { AgentStreamEvent } from "../agent-sdk-types.js"; import type { AgentStreamEvent } from "../agent-sdk-types.js";
describe("OpenCode reasoning dedup", () => { describe("OpenCode reasoning dedup", () => {
test.runIf(isProviderAvailable("opencode"))( let canRun = false;
"reasoning content is not duplicated as assistant_message",
async () => {
const cwd = mkdtempSync(path.join(tmpdir(), "opencode-reasoning-dedup-"));
const logger = pino({ level: "silent" });
const client = new OpenCodeAgentClient(logger);
try { beforeAll(async () => {
const session = await client.createSession({ canRun = await isProviderAvailable("opencode");
provider: "opencode", });
cwd,
model: "opencode/gpt-5-nano",
modeId: "build",
});
const streamedEvents: AgentStreamEvent[] = []; beforeEach((context) => {
session.subscribe((event) => { if (!canRun) {
streamedEvents.push(event); context.skip();
}); }
});
const result = await session.run("What is 2+2? Think step by step."); test("reasoning content is not duplicated as assistant_message", async () => {
const cwd = mkdtempSync(path.join(tmpdir(), "opencode-reasoning-dedup-"));
const logger = pino({ level: "silent" });
const client = new OpenCodeAgentClient(logger);
const reasoningTexts: string[] = []; try {
const assistantTexts: string[] = []; const session = await client.createSession({
provider: "opencode",
cwd,
model: "opencode/gpt-5-nano",
modeId: "build",
});
for (const event of streamedEvents) { const streamedEvents: AgentStreamEvent[] = [];
if (event.type === "timeline") { session.subscribe((event) => {
if (event.item.type === "reasoning") { streamedEvents.push(event);
reasoningTexts.push(event.item.text); });
} else if (event.item.type === "assistant_message") {
assistantTexts.push(event.item.text); const result = await session.run("What is 2+2? Think step by step.");
}
const reasoningTexts: string[] = [];
const assistantTexts: string[] = [];
for (const event of streamedEvents) {
if (event.type === "timeline") {
if (event.item.type === "reasoning") {
reasoningTexts.push(event.item.text);
} else if (event.item.type === "assistant_message") {
assistantTexts.push(event.item.text);
} }
} }
const fullReasoningText = reasoningTexts.join("");
const fullAssistantText = assistantTexts.join("");
// The model should produce reasoning
expect(reasoningTexts.length).toBeGreaterThan(0);
expect(fullReasoningText.length).toBeGreaterThan(0);
// The assistant text should be the response, not the reasoning
expect(assistantTexts.length).toBeGreaterThan(0);
// Reasoning text must NOT appear in the assistant text
const reasoningPrefix = fullReasoningText.slice(0, 50);
if (reasoningPrefix.length > 10) {
expect(fullAssistantText).not.toContain(reasoningPrefix);
}
} finally {
rmSync(cwd, { recursive: true, force: true });
} }
},
120_000, const fullReasoningText = reasoningTexts.join("");
); const fullAssistantText = assistantTexts.join("");
// The model should produce reasoning
expect(reasoningTexts.length).toBeGreaterThan(0);
expect(fullReasoningText.length).toBeGreaterThan(0);
// The assistant text should be the response, not the reasoning
expect(assistantTexts.length).toBeGreaterThan(0);
// Reasoning text must NOT appear in the assistant text
const reasoningPrefix = fullReasoningText.slice(0, 50);
if (reasoningPrefix.length > 10) {
expect(fullAssistantText).not.toContain(reasoningPrefix);
}
} finally {
rmSync(cwd, { recursive: true, force: true });
}
}, 120_000);
}); });
@@ -7,9 +7,8 @@ import { join, dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import { homedir } from "node:os"; import { homedir } from "node:os";
import dotenv from "dotenv"; import dotenv from "dotenv";
import { isCommandAvailableSync } from "../../utils/executable.js"; import { isCommandAvailable } from "../../utils/executable.js";
// Load .env.test eagerly so isProviderAvailable() has credentials at collection time.
const serverRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../.."); const serverRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
dotenv.config({ path: resolve(serverRoot, ".env.test"), override: true }); dotenv.config({ path: resolve(serverRoot, ".env.test"), override: true });
@@ -64,6 +63,7 @@ export const agentConfigs = {
} as const satisfies Record<string, AgentTestConfig>; } as const satisfies Record<string, AgentTestConfig>;
export type AgentProvider = keyof typeof agentConfigs; export type AgentProvider = keyof typeof agentConfigs;
const providerAvailabilityCache = new Map<AgentProvider, Promise<boolean>>();
/** /**
* Get test config for creating an agent with full permissions (no prompts). * Get test config for creating an agent with full permissions (no prompts).
@@ -101,31 +101,42 @@ export function getAskModeConfig(provider: AgentProvider) {
* This MUST be a function (not a const) so process.env is read at call time, * This MUST be a function (not a const) so process.env is read at call time,
* after dotenv has injected the test credentials. * after dotenv has injected the test credentials.
*/ */
export function isProviderAvailable(provider: AgentProvider): boolean { export function isProviderAvailable(provider: AgentProvider): Promise<boolean> {
switch (provider) { const cached = providerAvailabilityCache.get(provider);
case "claude": if (cached) {
return ( return cached;
isCommandAvailableSync("claude") &&
(Boolean(process.env.CLAUDE_CODE_OAUTH_TOKEN) || Boolean(process.env.ANTHROPIC_API_KEY))
);
case "codex":
return (
isCommandAvailableSync("codex") &&
(existsSync(join(homedir(), ".codex", "auth.json")) || Boolean(process.env.OPENAI_API_KEY))
);
case "copilot":
return isCommandAvailableSync("copilot");
case "opencode":
return isCommandAvailableSync("opencode");
case "pi":
return (
isCommandAvailableSync(process.env.PI_ACP_PI_COMMAND ?? "pi") &&
(Boolean(process.env.OPENAI_API_KEY) ||
Boolean(process.env.ANTHROPIC_API_KEY) ||
Boolean(process.env.OPENROUTER_API_KEY) ||
existsSync(join(homedir(), ".pi", "agent", "auth.json")))
);
} }
const availability = (async (): Promise<boolean> => {
switch (provider) {
case "claude":
return (
(await isCommandAvailable("claude")) &&
(Boolean(process.env.CLAUDE_CODE_OAUTH_TOKEN) || Boolean(process.env.ANTHROPIC_API_KEY))
);
case "codex":
return (
(await isCommandAvailable("codex")) &&
(existsSync(join(homedir(), ".codex", "auth.json")) ||
Boolean(process.env.OPENAI_API_KEY))
);
case "copilot":
return await isCommandAvailable("copilot");
case "opencode":
return await isCommandAvailable("opencode");
case "pi":
return (
(await isCommandAvailable(process.env.PI_ACP_PI_COMMAND ?? "pi")) &&
(Boolean(process.env.OPENAI_API_KEY) ||
Boolean(process.env.ANTHROPIC_API_KEY) ||
Boolean(process.env.OPENROUTER_API_KEY) ||
existsSync(join(homedir(), ".pi", "agent", "auth.json")))
);
}
})();
providerAvailabilityCache.set(provider, availability);
return availability;
} }
/** /**
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -18,98 +18,106 @@ function compactText(value: string): string {
} }
describe("daemon E2E (real claude) - autonomous wake simple", () => { describe("daemon E2E (real claude) - autonomous wake simple", () => {
test.runIf(isProviderAvailable("claude"))( let canRun = false;
"hello + background sleep returns idle, then wakes once on completion",
async () => { beforeAll(async () => {
const logger = pino({ level: "silent" }); canRun = await isProviderAvailable("claude");
const cwd = tmpCwd(); });
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) }, beforeEach((context) => {
logger, if (!canRun) {
context.skip();
}
});
test("hello + background sleep returns idle, then wakes once on completion", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) },
logger,
});
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await client.connect();
await client.fetchAgents({
subscribe: { subscriptionId: "claude-autonomous-simple-real" },
}); });
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try { const agent = await client.createAgent({
await client.connect(); cwd,
await client.fetchAgents({ title: "claude-autonomous-simple-real",
subscribe: { subscriptionId: "claude-autonomous-simple-real" }, ...getFullAccessConfig("claude"),
}); });
const agent = await client.createAgent({ const autonomousWakeToken = `AUTONOMOUS_SIMPLE_${Date.now().toString(36)}`;
cwd, await client.sendMessage(
title: "claude-autonomous-simple-real", agent.id,
...getFullAccessConfig("claude"), [
}); "Hello.",
"Use the Bash tool with run_in_background.",
"Run exactly: sleep 5",
"Do not wait for the task result.",
"Reply immediately with exactly: SPAWNED",
`When the background task completes later, reply with exactly: ${autonomousWakeToken}`,
].join(" "),
);
const autonomousWakeToken = `AUTONOMOUS_SIMPLE_${Date.now().toString(36)}`; const firstFinish = await client.waitForFinish(agent.id, 240_000);
await client.sendMessage( expect(firstFinish.status).toBe("idle");
agent.id,
[
"Hello.",
"Use the Bash tool with run_in_background.",
"Run exactly: sleep 5",
"Do not wait for the task result.",
"Reply immediately with exactly: SPAWNED",
`When the background task completes later, reply with exactly: ${autonomousWakeToken}`,
].join(" "),
);
const firstFinish = await client.waitForFinish(agent.id, 240_000); const timelineAtIdle = await client.fetchAgentTimeline(agent.id, {
expect(firstFinish.status).toBe("idle"); direction: "tail",
limit: 0,
projection: "canonical",
});
const idleAssistantText = timelineAtIdle.entries
.filter(
(
entry,
): entry is typeof entry & {
item: { type: "assistant_message"; text: string };
} => entry.item.type === "assistant_message",
)
.map((entry) => entry.item.text)
.join("\n");
expect(compactText(idleAssistantText)).toContain("spawned");
expect(
timelineAtIdle.entries.some(
(entry) => entry.item.type === "tool_call" && entry.item.name === "Bash",
),
).toBe(true);
const timelineAtIdle = await client.fetchAgentTimeline(agent.id, { await client.waitForAgentUpsert(
direction: "tail", agent.id,
limit: 0, (snapshot) => snapshot.status === "running",
projection: "canonical", 30_000,
}); );
const idleAssistantText = timelineAtIdle.entries
.filter(
(
entry,
): entry is typeof entry & {
item: { type: "assistant_message"; text: string };
} => entry.item.type === "assistant_message",
)
.map((entry) => entry.item.text)
.join("\n");
expect(compactText(idleAssistantText)).toContain("spawned");
expect(
timelineAtIdle.entries.some(
(entry) => entry.item.type === "tool_call" && entry.item.name === "Bash",
),
).toBe(true);
await client.waitForAgentUpsert( const autonomousFinish = await client.waitForFinish(agent.id, 120_000);
agent.id, expect(autonomousFinish.status).toBe("idle");
(snapshot) => snapshot.status === "running",
30_000,
);
const autonomousFinish = await client.waitForFinish(agent.id, 120_000); const finalTimeline = await client.fetchAgentTimeline(agent.id, {
expect(autonomousFinish.status).toBe("idle"); direction: "tail",
limit: 0,
const finalTimeline = await client.fetchAgentTimeline(agent.id, { projection: "canonical",
direction: "tail", });
limit: 0, const finalAssistantText = finalTimeline.entries
projection: "canonical", .filter(
}); (
const finalAssistantText = finalTimeline.entries entry,
.filter( ): entry is typeof entry & {
( item: { type: "assistant_message"; text: string };
entry, } => entry.item.type === "assistant_message",
): entry is typeof entry & { )
item: { type: "assistant_message"; text: string }; .map((entry) => entry.item.text)
} => entry.item.type === "assistant_message", .join("\n");
) expect(compactText(finalAssistantText)).toContain(autonomousWakeToken.toLowerCase());
.map((entry) => entry.item.text) } finally {
.join("\n"); await client.close().catch(() => undefined);
expect(compactText(finalAssistantText)).toContain(autonomousWakeToken.toLowerCase()); await daemon.close().catch(() => undefined);
} finally { rmSync(cwd, { recursive: true, force: true });
await client.close().catch(() => undefined); }
await daemon.close().catch(() => undefined); }, 420_000);
rmSync(cwd, { recursive: true, force: true });
}
},
420_000,
);
}); });
File diff suppressed because it is too large Load Diff
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -14,52 +14,60 @@ function tmpCwd(): string {
} }
describe("daemon E2E (real claude) - model resolution on init", () => { describe("daemon E2E (real claude) - model resolution on init", () => {
test.runIf(isProviderAvailable("claude"))( let canRun = false;
"runtimeInfo.model is set as soon as the agent starts running, not after turn completes",
async () => { beforeAll(async () => {
const logger = pino({ level: "silent" }); canRun = await isProviderAvailable("claude");
const cwd = tmpCwd(); });
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) }, beforeEach((context) => {
logger, if (!canRun) {
context.skip();
}
});
test("runtimeInfo.model is set as soon as the agent starts running, not after turn completes", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) },
logger,
});
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await client.connect();
await client.fetchAgents({
subscribe: { subscriptionId: "model-init-test" },
}); });
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try { const modelsResult = await client.listProviderModels("claude", { cwd });
await client.connect(); const catalogModelIds = new Set(modelsResult.models.map((m) => m.id));
await client.fetchAgents({
subscribe: { subscriptionId: "model-init-test" },
});
const modelsResult = await client.listProviderModels("claude", { cwd }); const agent = await client.createAgent({
const catalogModelIds = new Set(modelsResult.models.map((m) => m.id)); provider: "claude",
cwd,
model: "haiku",
title: "model-init-test",
});
const agent = await client.createAgent({ await client.sendMessage(agent.id, "Reply with exactly: OK");
provider: "claude",
cwd,
model: "haiku",
title: "model-init-test",
});
await client.sendMessage(agent.id, "Reply with exactly: OK"); const snapshot = await client.waitForAgentUpsert(
agent.id,
(s) => s.runtimeInfo?.model != null,
60_000,
);
const snapshot = await client.waitForAgentUpsert( expect(snapshot.runtimeInfo?.model).toBeTruthy();
agent.id, expect(catalogModelIds.has(snapshot.runtimeInfo!.model!)).toBe(true);
(s) => s.runtimeInfo?.model != null, expect(snapshot.status).toBe("running");
60_000,
);
expect(snapshot.runtimeInfo?.model).toBeTruthy(); await client.waitForFinish(agent.id, 60_000);
expect(catalogModelIds.has(snapshot.runtimeInfo!.model!)).toBe(true); } finally {
expect(snapshot.status).toBe("running"); await client.close();
await daemon.close();
await client.waitForFinish(agent.id, 60_000); rmSync(cwd, { recursive: true, force: true });
} finally { }
await client.close(); }, 120_000);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
},
120_000,
);
}); });
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -14,50 +14,58 @@ function tmpCwd(): string {
} }
describe("daemon E2E (real claude) - runtime model reconciliation", () => { describe("daemon E2E (real claude) - runtime model reconciliation", () => {
test.runIf(isProviderAvailable("claude"))( let canRun = false;
"normalizes runtime model to a model ID exposed by the provider catalog",
async () => { beforeAll(async () => {
const logger = pino({ level: "silent" }); canRun = await isProviderAvailable("claude");
const cwd = tmpCwd(); });
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) }, beforeEach((context) => {
logger, if (!canRun) {
context.skip();
}
});
test("normalizes runtime model to a model ID exposed by the provider catalog", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) },
logger,
});
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await client.connect();
await client.fetchAgents({
subscribe: { subscriptionId: "claude-runtime-model-reconcile" },
}); });
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try { const modelsResult = await client.listProviderModels("claude", { cwd });
await client.connect(); expect(modelsResult.error).toBeNull();
await client.fetchAgents({ expect(modelsResult.models.length).toBeGreaterThan(0);
subscribe: { subscriptionId: "claude-runtime-model-reconcile" }, const modelIds = new Set(modelsResult.models.map((model) => model.id));
});
const modelsResult = await client.listProviderModels("claude", { cwd }); const agent = await client.createAgent({
expect(modelsResult.error).toBeNull(); provider: "claude",
expect(modelsResult.models.length).toBeGreaterThan(0); cwd,
const modelIds = new Set(modelsResult.models.map((model) => model.id)); title: "claude-runtime-model-reconcile",
});
const agent = await client.createAgent({ await client.sendMessage(agent.id, "Reply with exactly: OK");
provider: "claude", const finish = await client.waitForFinish(agent.id, 180_000);
cwd, expect(finish.status).toBe("idle");
title: "claude-runtime-model-reconcile",
});
await client.sendMessage(agent.id, "Reply with exactly: OK"); const snapshot = await client.fetchAgent(agent.id);
const finish = await client.waitForFinish(agent.id, 180_000); expect(snapshot).not.toBeNull();
expect(finish.status).toBe("idle"); const runtimeModelId = snapshot?.agent.runtimeInfo?.model ?? null;
expect(typeof runtimeModelId).toBe("string");
const snapshot = await client.fetchAgent(agent.id); expect(runtimeModelId).not.toBe("");
expect(snapshot).not.toBeNull(); expect(modelIds.has(runtimeModelId as string)).toBe(true);
const runtimeModelId = snapshot?.agent.runtimeInfo?.model ?? null; } finally {
expect(typeof runtimeModelId).toBe("string"); await client.close();
expect(runtimeModelId).not.toBe(""); await daemon.close();
expect(modelIds.has(runtimeModelId as string)).toBe(true); rmSync(cwd, { recursive: true, force: true });
} finally { }
await client.close(); }, 300_000);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
},
300_000,
);
}); });
@@ -1,4 +1,4 @@
import { describe, test, expect } from "vitest"; import { beforeAll, beforeEach, describe, test, expect } from "vitest";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -29,55 +29,63 @@ async function createHarness(): Promise<{
} }
describe("daemon E2E (real opencode) - custom agent discovery", () => { describe("daemon E2E (real opencode) - custom agent discovery", () => {
test.runIf(isProviderAvailable("opencode"))( let canRun = false;
"custom agents defined in opencode.json appear in availableModes",
async () => { beforeAll(async () => {
const cwd = tmpCwd(); canRun = await isProviderAvailable("opencode");
writeFileSync( });
path.join(cwd, "opencode.json"),
JSON.stringify({ beforeEach((context) => {
agent: { if (!canRun) {
"paseo-e2e-custom": { context.skip();
description: "Custom agent for Paseo daemon E2E test", }
mode: "primary", });
},
test("custom agents defined in opencode.json appear in availableModes", async () => {
const cwd = tmpCwd();
writeFileSync(
path.join(cwd, "opencode.json"),
JSON.stringify({
agent: {
"paseo-e2e-custom": {
description: "Custom agent for Paseo daemon E2E test",
mode: "primary",
}, },
}), },
}),
);
const { client, daemon } = await createHarness();
try {
const agent = await client.createAgent({
provider: "opencode",
cwd,
title: "OpenCode custom agent discovery",
});
// Wait for modes to be populated (they arrive after session init)
const snapshot = await client.waitForAgentUpsert(
agent.id,
(s) => s.availableModes.length > 0,
30_000,
); );
const { client, daemon } = await createHarness(); expect(snapshot.availableModes.some((m) => m.id === "build")).toBe(true);
expect(snapshot.availableModes.some((m) => m.id === "plan")).toBe(true);
try { const custom = snapshot.availableModes.find((m) => m.id === "paseo-e2e-custom");
const agent = await client.createAgent({ expect(custom).toBeDefined();
provider: "opencode", expect(custom!.description).toBe("Custom agent for Paseo daemon E2E test");
cwd,
title: "OpenCode custom agent discovery",
});
// Wait for modes to be populated (they arrive after session init) // System agents should not leak through
const snapshot = await client.waitForAgentUpsert( expect(snapshot.availableModes.some((m) => m.id === "compaction")).toBe(false);
agent.id, expect(snapshot.availableModes.some((m) => m.id === "summary")).toBe(false);
(s) => s.availableModes.length > 0, expect(snapshot.availableModes.some((m) => m.id === "title")).toBe(false);
30_000, } finally {
); await client.close().catch(() => undefined);
await daemon.close();
expect(snapshot.availableModes.some((m) => m.id === "build")).toBe(true); rmSync(cwd, { recursive: true, force: true });
expect(snapshot.availableModes.some((m) => m.id === "plan")).toBe(true); }
}, 60_000);
const custom = snapshot.availableModes.find((m) => m.id === "paseo-e2e-custom");
expect(custom).toBeDefined();
expect(custom!.description).toBe("Custom agent for Paseo daemon E2E test");
// System agents should not leak through
expect(snapshot.availableModes.some((m) => m.id === "compaction")).toBe(false);
expect(snapshot.availableModes.some((m) => m.id === "summary")).toBe(false);
expect(snapshot.availableModes.some((m) => m.id === "title")).toBe(false);
} finally {
await client.close().catch(() => undefined);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
},
60_000,
);
}); });
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -29,85 +29,89 @@ async function createHarness(): Promise<{
} }
describe("daemon E2E (real opencode) - initial prompt wait", () => { describe("daemon E2E (real opencode) - initial prompt wait", () => {
test.runIf(isProviderAvailable("opencode"))( let canRun = false;
"waitForFinish does not resolve before an initial prompt using opencode/big-pickle actually completes",
async () => {
const cwd = tmpCwd();
const { client, daemon } = await createHarness();
try { beforeAll(async () => {
const models = await client.listProviderModels("opencode"); canRun = await isProviderAvailable("opencode");
expect(models.models.some((model) => model.id === "zai/glm-5.1")).toBe(true); });
const agent = await client.createAgent({ beforeEach((context) => {
provider: "opencode", if (!canRun) {
cwd, context.skip();
title: "OpenCode initial prompt wait regression", }
model: "opencode/big-pickle", });
initialPrompt: "Reply with exactly: BIG_PICKLE_OK",
});
const finish = await client.waitForFinish(agent.id, 60_000); test("waitForFinish does not resolve before an initial prompt using opencode/big-pickle actually completes", async () => {
expect(finish.status).toBe("idle"); const cwd = tmpCwd();
expect(finish.lastMessage).toContain("BIG_PICKLE_OK"); const { client, daemon } = await createHarness();
const snapshot = await client.fetchAgent(agent.id); try {
expect(snapshot.agent?.status).toBe("idle"); const models = await client.listProviderModels("opencode");
expect(models.models.some((model) => model.id === "zai/glm-5.1")).toBe(true);
const timeline = await client.fetchAgentTimeline(agent.id, { const agent = await client.createAgent({
direction: "tail", provider: "opencode",
limit: 0, cwd,
projection: "projected", title: "OpenCode initial prompt wait regression",
}); model: "opencode/big-pickle",
const assistantMessages = timeline.entries.filter( initialPrompt: "Reply with exactly: BIG_PICKLE_OK",
(entry) => entry.item.type === "assistant_message", });
);
expect(assistantMessages.length).toBeGreaterThan(0); const finish = await client.waitForFinish(agent.id, 60_000);
expect(assistantMessages.some((entry) => entry.item.text.includes("BIG_PICKLE_OK"))).toBe( expect(finish.status).toBe("idle");
true, expect(finish.lastMessage).toContain("BIG_PICKLE_OK");
);
} finally {
await client.close().catch(() => undefined);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
},
90_000,
);
test.runIf(isProviderAvailable("opencode"))( const snapshot = await client.fetchAgent(agent.id);
"waitForFinish surfaces a terminal error when zai/glm-5.1 enters a fatal retry loop", expect(snapshot.agent?.status).toBe("idle");
async () => {
const cwd = tmpCwd();
const { client, daemon } = await createHarness();
try { const timeline = await client.fetchAgentTimeline(agent.id, {
const models = await client.listProviderModels("opencode"); direction: "tail",
expect(models.models.some((model) => model.id === "zai/glm-5.1")).toBe(true); limit: 0,
projection: "projected",
});
const assistantMessages = timeline.entries.filter(
(entry) => entry.item.type === "assistant_message",
);
const agent = await client.createAgent({ expect(assistantMessages.length).toBeGreaterThan(0);
provider: "opencode", expect(assistantMessages.some((entry) => entry.item.text.includes("BIG_PICKLE_OK"))).toBe(
cwd, true,
title: "OpenCode zai fatal retry regression", );
model: "zai/glm-5.1", } finally {
initialPrompt: "Reply with exactly: GLM_51_OK", await client.close().catch(() => undefined);
}); await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
}, 90_000);
const finish = await client.waitForFinish(agent.id, 60_000); test("waitForFinish surfaces a terminal error when zai/glm-5.1 enters a fatal retry loop", async () => {
expect(finish.status).toBe("error"); const cwd = tmpCwd();
expect((finish.error ?? "").toLowerCase()).toMatch( const { client, daemon } = await createHarness();
/insufficient balance|resource package|recharge/,
);
const snapshot = await client.fetchAgent(agent.id); try {
expect(snapshot.agent?.status).toBe("error"); const models = await client.listProviderModels("opencode");
} finally { expect(models.models.some((model) => model.id === "zai/glm-5.1")).toBe(true);
await client.close().catch(() => undefined);
await daemon.close(); const agent = await client.createAgent({
rmSync(cwd, { recursive: true, force: true }); provider: "opencode",
} cwd,
}, title: "OpenCode zai fatal retry regression",
90_000, model: "zai/glm-5.1",
); initialPrompt: "Reply with exactly: GLM_51_OK",
});
const finish = await client.waitForFinish(agent.id, 60_000);
expect(finish.status).toBe("error");
expect((finish.error ?? "").toLowerCase()).toMatch(
/insufficient balance|resource package|recharge/,
);
const snapshot = await client.fetchAgent(agent.id);
expect(snapshot.agent?.status).toBe("error");
} finally {
await client.close().catch(() => undefined);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
}, 90_000);
}); });
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -29,33 +29,41 @@ async function createHarness(): Promise<{
} }
describe("daemon E2E (real opencode) - invalid model handling", () => { describe("daemon E2E (real opencode) - invalid model handling", () => {
test.runIf(isProviderAvailable("opencode"))( let canRun = false;
"initial prompt with a nonexistent OpenCode model fails instead of hanging forever",
async () => {
const cwd = tmpCwd();
const { client, daemon } = await createHarness();
try { beforeAll(async () => {
const agent = await client.createAgent({ canRun = await isProviderAvailable("opencode");
provider: "opencode", });
cwd,
title: "OpenCode invalid model regression",
model: "opencode/adklasldkdas",
initialPrompt: "hello",
});
const finish = await client.waitForFinish(agent.id, 30_000); beforeEach((context) => {
expect(finish.status).toBe("error"); if (!canRun) {
expect(finish.error).toBeTruthy(); context.skip();
}
});
const snapshot = await client.fetchAgent(agent.id); test("initial prompt with a nonexistent OpenCode model fails instead of hanging forever", async () => {
expect(snapshot.agent?.status).toBe("error"); const cwd = tmpCwd();
} finally { const { client, daemon } = await createHarness();
await client.close().catch(() => undefined);
await daemon.close(); try {
rmSync(cwd, { recursive: true, force: true }); const agent = await client.createAgent({
} provider: "opencode",
}, cwd,
60_000, title: "OpenCode invalid model regression",
); model: "opencode/adklasldkdas",
initialPrompt: "hello",
});
const finish = await client.waitForFinish(agent.id, 30_000);
expect(finish.status).toBe("error");
expect(finish.error).toBeTruthy();
const snapshot = await client.fetchAgent(agent.id);
expect(snapshot.agent?.status).toBe("error");
} finally {
await client.close().catch(() => undefined);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
}, 60_000);
}); });
@@ -1,4 +1,4 @@
import { describe, test, expect } from "vitest"; import { beforeAll, beforeEach, describe, test, expect } from "vitest";
import { existsSync, mkdtempSync, rmSync } from "node:fs"; import { existsSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -39,102 +39,106 @@ async function createHarness(): Promise<{
} }
describe("daemon E2E (real opencode) - plan mode and clarifying questions", () => { describe("daemon E2E (real opencode) - plan mode and clarifying questions", () => {
test.runIf(isProviderAvailable("opencode"))( let canRun = false;
"surfaces clarifying questions as pending permissions",
async () => {
const cwd = tmpCwd();
const { client, daemon } = await createHarness();
try { beforeAll(async () => {
const modelList = await client.listProviderModels("opencode"); canRun = await isProviderAvailable("opencode");
expect(modelList.models.length).toBeGreaterThan(0); });
const agent = await client.createAgent({ beforeEach((context) => {
provider: "opencode", if (!canRun) {
cwd, context.skip();
title: "OpenCode question regression", }
model: pickOpenCodeModel(modelList.models, ["minimax-m2.5-free", "minimax", "free"]), });
modeId: "plan",
});
await client.sendMessage( test("surfaces clarifying questions as pending permissions", async () => {
agent.id, const cwd = tmpCwd();
[ const { client, daemon } = await createHarness();
"Use the question tool/feature to ask me exactly one clarifying question.",
"Ask this exact question: What kind of project should the plan cover?",
"Wait for my answer before doing anything else.",
].join(" "),
);
const snapshotWithQuestion = await client.waitForAgentUpsert( try {
agent.id, const modelList = await client.listProviderModels("opencode");
(snapshot) => (snapshot.pendingPermissions?.[0]?.kind ?? null) === "question", expect(modelList.models.length).toBeGreaterThan(0);
30_000,
);
expect(snapshotWithQuestion.pendingPermissions?.length).toBeGreaterThan(0); const agent = await client.createAgent({
provider: "opencode",
cwd,
title: "OpenCode question regression",
model: pickOpenCodeModel(modelList.models, ["minimax-m2.5-free", "minimax", "free"]),
modeId: "plan",
});
const permission = snapshotWithQuestion.pendingPermissions?.[0]; await client.sendMessage(
expect(permission).toBeTruthy(); agent.id,
expect(permission?.kind).toBe("question"); [
expect(Array.isArray(permission?.input?.questions)).toBe(true); "Use the question tool/feature to ask me exactly one clarifying question.",
"Ask this exact question: What kind of project should the plan cover?",
"Wait for my answer before doing anything else.",
].join(" "),
);
const firstQuestion = permission?.input?.questions?.[0] as { header?: string } | undefined; const snapshotWithQuestion = await client.waitForAgentUpsert(
expect(firstQuestion?.header).toBeTruthy(); agent.id,
} finally { (snapshot) => (snapshot.pendingPermissions?.[0]?.kind ?? null) === "question",
await client.close().catch(() => undefined); 30_000,
await daemon.close(); );
rmSync(cwd, { recursive: true, force: true });
}
},
180_000,
);
test.runIf(isProviderAvailable("opencode"))( expect(snapshotWithQuestion.pendingPermissions?.length).toBeGreaterThan(0);
"plan mode stays read-only through the daemon path",
async () => {
const cwd = tmpCwd();
const filePath = path.join(cwd, "plan-mode-output.txt");
const { client, daemon } = await createHarness();
try { const permission = snapshotWithQuestion.pendingPermissions?.[0];
const modelList = await client.listProviderModels("opencode"); expect(permission).toBeTruthy();
expect(modelList.models.length).toBeGreaterThan(0); expect(permission?.kind).toBe("question");
expect(Array.isArray(permission?.input?.questions)).toBe(true);
const agent = await client.createAgent({ const firstQuestion = permission?.input?.questions?.[0] as { header?: string } | undefined;
provider: "opencode", expect(firstQuestion?.header).toBeTruthy();
cwd, } finally {
title: "OpenCode plan mode regression", await client.close().catch(() => undefined);
model: pickOpenCodeModel(modelList.models), await daemon.close();
modeId: "plan", rmSync(cwd, { recursive: true, force: true });
}); }
}, 180_000);
await client.sendMessage( test("plan mode stays read-only through the daemon path", async () => {
agent.id, const cwd = tmpCwd();
"Create a file named plan-mode-output.txt in the current directory containing exactly hello.", const filePath = path.join(cwd, "plan-mode-output.txt");
); const { client, daemon } = await createHarness();
const state = await client.waitForFinish(agent.id, 180_000); try {
expect(state.status).toBe("idle"); const modelList = await client.listProviderModels("opencode");
expect(existsSync(filePath)).toBe(false); expect(modelList.models.length).toBeGreaterThan(0);
const timeline = await client.fetchAgentTimeline(agent.id, { const agent = await client.createAgent({
direction: "tail", provider: "opencode",
limit: 0, cwd,
projection: "projected", title: "OpenCode plan mode regression",
}); model: pickOpenCodeModel(modelList.models),
const assistantText = timeline.entries modeId: "plan",
.filter((entry) => entry.item.type === "assistant_message") });
.map((entry) => entry.item.text)
.join(" ");
expect(assistantText.toLowerCase()).toContain("plan"); await client.sendMessage(
} finally { agent.id,
await client.close().catch(() => undefined); "Create a file named plan-mode-output.txt in the current directory containing exactly hello.",
await daemon.close(); );
rmSync(cwd, { recursive: true, force: true });
} const state = await client.waitForFinish(agent.id, 180_000);
}, expect(state.status).toBe("idle");
240_000, expect(existsSync(filePath)).toBe(false);
);
const timeline = await client.fetchAgentTimeline(agent.id, {
direction: "tail",
limit: 0,
projection: "projected",
});
const assistantText = timeline.entries
.filter((entry) => entry.item.type === "assistant_message")
.map((entry) => entry.item.text)
.join(" ");
expect(assistantText.toLowerCase()).toContain("plan");
} finally {
await client.close().catch(() => undefined);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
}, 240_000);
}); });
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -281,142 +281,146 @@ async function createHarness(): Promise<{
} }
describe("daemon E2E (real opencode) - send while working and interrupt", () => { describe("daemon E2E (real opencode) - send while working and interrupt", () => {
test.runIf(isProviderAvailable("opencode"))( let canRun = false;
"send_message while sleep tool call is running starts a clean replacement turn",
async () => {
const cwd = tmpCwd();
const { client, daemon } = await createHarness();
const collector = createMessageCollector(client);
const followUpToken = "OPENCODE_SEND_WHILE_WORKING_OK";
try { beforeAll(async () => {
const modelList = await client.listProviderModels("opencode"); canRun = await isProviderAvailable("opencode");
expect(modelList.models.length).toBeGreaterThan(0); });
const agent = await client.createAgent({ beforeEach((context) => {
provider: "opencode", if (!canRun) {
cwd, context.skip();
title: "OpenCode send while working", }
model: pickOpenCodeModel(modelList.models), });
modeId: "default",
});
await client.sendMessage( test("send_message while sleep tool call is running starts a clean replacement turn", async () => {
agent.id, const cwd = tmpCwd();
[ const { client, daemon } = await createHarness();
"Use the Bash tool.", const collector = createMessageCollector(client);
"Run exactly: sleep 60", const followUpToken = "OPENCODE_SEND_WHILE_WORKING_OK";
"Do not run it in the background.",
"Do not do anything after starting the command.",
].join(" "),
);
await client.waitForAgentUpsert( try {
agent.id, const modelList = await client.listProviderModels("opencode");
(snapshot) => snapshot.status === "running", expect(modelList.models.length).toBeGreaterThan(0);
90_000,
);
await waitForRunningBashToolCall(client, collector, agent.id);
collector.clear(); const agent = await client.createAgent({
await client.sendMessage(agent.id, `Reply with exactly: ${followUpToken}`); provider: "opencode",
cwd,
title: "OpenCode send while working",
model: pickOpenCodeModel(modelList.models),
modeId: "default",
});
const finish = await waitForIdleResolvingPermissions(client, agent.id, 240_000); await client.sendMessage(
expect(finish.status).toBe("idle"); agent.id,
[
"Use the Bash tool.",
"Run exactly: sleep 60",
"Do not run it in the background.",
"Do not do anything after starting the command.",
].join(" "),
);
const postSendAssistantTexts = getAssistantTexts(collector.messages, agent.id); await client.waitForAgentUpsert(
expect(postSendAssistantTexts.some((text) => text.includes("[System Error]"))).toBe(false); agent.id,
expect(postSendAssistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe( (snapshot) => snapshot.status === "running",
false, 90_000,
); );
await waitForRunningBashToolCall(client, collector, agent.id);
const timeline = await client.fetchAgentTimeline(agent.id, { limit: 160 }); collector.clear();
const assistantTexts = getTimelineAssistantTexts(timeline); await client.sendMessage(agent.id, `Reply with exactly: ${followUpToken}`);
expect(assistantTexts.some((text) => text.includes(followUpToken))).toBe(true);
expect(assistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
expect(assistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(false);
} finally {
collector.unsubscribe();
await client.close().catch(() => undefined);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
},
360_000,
);
test.runIf(isProviderAvailable("opencode"))( const finish = await waitForIdleResolvingPermissions(client, agent.id, 240_000);
"explicit interrupt during sleep tool call still allows the next turn to complete", expect(finish.status).toBe("idle");
async () => {
const cwd = tmpCwd();
const { client, daemon } = await createHarness();
const collector = createMessageCollector(client);
const followUpToken = "OPENCODE_INTERRUPT_FOLLOWUP_OK";
try { const postSendAssistantTexts = getAssistantTexts(collector.messages, agent.id);
const modelList = await client.listProviderModels("opencode"); expect(postSendAssistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
expect(modelList.models.length).toBeGreaterThan(0); expect(postSendAssistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(
false,
);
const agent = await client.createAgent({ const timeline = await client.fetchAgentTimeline(agent.id, { limit: 160 });
provider: "opencode", const assistantTexts = getTimelineAssistantTexts(timeline);
cwd, expect(assistantTexts.some((text) => text.includes(followUpToken))).toBe(true);
title: "OpenCode explicit interrupt", expect(assistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
model: pickOpenCodeModel(modelList.models), expect(assistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(false);
modeId: "default", } finally {
}); collector.unsubscribe();
await client.close().catch(() => undefined);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
}, 360_000);
await client.sendMessage( test("explicit interrupt during sleep tool call still allows the next turn to complete", async () => {
agent.id, const cwd = tmpCwd();
[ const { client, daemon } = await createHarness();
"Use the Bash tool.", const collector = createMessageCollector(client);
"Run exactly: sleep 60", const followUpToken = "OPENCODE_INTERRUPT_FOLLOWUP_OK";
"Do not run it in the background.",
"Do not do anything after starting the command.",
].join(" "),
);
await client.waitForAgentUpsert( try {
agent.id, const modelList = await client.listProviderModels("opencode");
(snapshot) => snapshot.status === "running", expect(modelList.models.length).toBeGreaterThan(0);
90_000,
);
await waitForRunningBashToolCall(client, collector, agent.id);
await client.cancelAgent(agent.id); const agent = await client.createAgent({
await client.waitForAgentUpsert( provider: "opencode",
agent.id, cwd,
(snapshot) => snapshot.status === "idle" || snapshot.status === "error", title: "OpenCode explicit interrupt",
90_000, model: pickOpenCodeModel(modelList.models),
); modeId: "default",
const interruptedToolCall = await waitForSleepToolCallTerminal(client, agent.id, 45_000); });
expect(interruptedToolCall.status).toBe("failed");
collector.clear(); await client.sendMessage(
await client.sendMessage(agent.id, `Reply with exactly: ${followUpToken}`); agent.id,
[
"Use the Bash tool.",
"Run exactly: sleep 60",
"Do not run it in the background.",
"Do not do anything after starting the command.",
].join(" "),
);
const finish = await waitForIdleResolvingPermissions(client, agent.id, 240_000); await client.waitForAgentUpsert(
expect(finish.status).toBe("idle"); agent.id,
(snapshot) => snapshot.status === "running",
90_000,
);
await waitForRunningBashToolCall(client, collector, agent.id);
const postInterruptAssistantTexts = getAssistantTexts(collector.messages, agent.id); await client.cancelAgent(agent.id);
expect(postInterruptAssistantTexts.some((text) => text.includes("[System Error]"))).toBe( await client.waitForAgentUpsert(
false, agent.id,
); (snapshot) => snapshot.status === "idle" || snapshot.status === "error",
expect( 90_000,
postInterruptAssistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET)), );
).toBe(false); const interruptedToolCall = await waitForSleepToolCallTerminal(client, agent.id, 45_000);
expect(interruptedToolCall.status).toBe("failed");
const timeline = await client.fetchAgentTimeline(agent.id, { limit: 200 }); collector.clear();
const assistantTexts = getTimelineAssistantTexts(timeline); await client.sendMessage(agent.id, `Reply with exactly: ${followUpToken}`);
expect(assistantTexts.some((text) => text.includes(followUpToken))).toBe(true);
expect(assistantTexts.some((text) => text.includes("[System Error]"))).toBe(false); const finish = await waitForIdleResolvingPermissions(client, agent.id, 240_000);
expect(assistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(false); expect(finish.status).toBe("idle");
} finally {
collector.unsubscribe(); const postInterruptAssistantTexts = getAssistantTexts(collector.messages, agent.id);
await client.close().catch(() => undefined); expect(postInterruptAssistantTexts.some((text) => text.includes("[System Error]"))).toBe(
await daemon.close(); false,
rmSync(cwd, { recursive: true, force: true }); );
} expect(postInterruptAssistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(
}, false,
360_000, );
);
const timeline = await client.fetchAgentTimeline(agent.id, { limit: 200 });
const assistantTexts = getTimelineAssistantTexts(timeline);
expect(assistantTexts.some((text) => text.includes(followUpToken))).toBe(true);
expect(assistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
expect(assistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(false);
} finally {
collector.unsubscribe();
await client.close().catch(() => undefined);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
}, 360_000);
}); });
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -16,61 +16,69 @@ function tmpCwd(): string {
} }
describe("daemon E2E (real pi)", () => { describe("daemon E2E (real pi)", () => {
test.runIf(isProviderAvailable("pi"))( let canRun = false;
"smoke test with thinking option configured separately from modes",
async () => { beforeAll(async () => {
const logger = pino({ level: "silent" }); canRun = await isProviderAvailable("pi");
const cwd = tmpCwd(); });
const daemon = await createTestPaseoDaemon({
agentClients: { pi: new PiACPAgentClient({ logger }) }, beforeEach((context) => {
logger, if (!canRun) {
context.skip();
}
});
test("smoke test with thinking option configured separately from modes", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: { pi: new PiACPAgentClient({ logger }) },
logger,
});
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await client.connect();
await client.fetchAgents({
subscribe: { subscriptionId: "pi-real-smoke" },
}); });
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try { const agent = await client.createAgent({
await client.connect(); cwd,
await client.fetchAgents({ title: "pi-real-smoke",
subscribe: { subscriptionId: "pi-real-smoke" }, provider: "pi",
}); thinkingOptionId: "medium",
});
const agent = await client.createAgent({ await client.sendMessage(agent.id, "Reply with exactly: PINEAPPLE");
cwd,
title: "pi-real-smoke",
provider: "pi",
thinkingOptionId: "medium",
});
await client.sendMessage(agent.id, "Reply with exactly: PINEAPPLE"); const finish = await client.waitForFinish(agent.id, 240_000);
expect(finish.status).toBe("idle");
expect(finish.final?.persistence).toBeTruthy();
expect(finish.final?.persistence?.provider).toBe("pi");
expect(finish.final?.persistence?.sessionId).toBeTruthy();
const finish = await client.waitForFinish(agent.id, 240_000); const timeline = await client.fetchAgentTimeline(agent.id, {
expect(finish.status).toBe("idle"); direction: "tail",
expect(finish.final?.persistence).toBeTruthy(); limit: 0,
expect(finish.final?.persistence?.provider).toBe("pi"); projection: "canonical",
expect(finish.final?.persistence?.sessionId).toBeTruthy(); });
const assistantText = timeline.entries
.filter(
(
entry,
): entry is typeof entry & {
item: { type: "assistant_message"; text: string };
} => entry.item.type === "assistant_message",
)
.map((entry) => entry.item.text)
.join("\n");
const timeline = await client.fetchAgentTimeline(agent.id, { expect(assistantText.replace(/\s+/g, "")).toContain("PINEAPPLE");
direction: "tail", } finally {
limit: 0, await client.close().catch(() => undefined);
projection: "canonical", await daemon.close().catch(() => undefined);
}); rmSync(cwd, { recursive: true, force: true });
const assistantText = timeline.entries }
.filter( }, 420_000);
(
entry,
): entry is typeof entry & {
item: { type: "assistant_message"; text: string };
} => entry.item.type === "assistant_message",
)
.map((entry) => entry.item.text)
.join("\n");
expect(assistantText.replace(/\s+/g, "")).toContain("PINEAPPLE");
} finally {
await client.close().catch(() => undefined);
await daemon.close().catch(() => undefined);
rmSync(cwd, { recursive: true, force: true });
}
},
420_000,
);
}); });
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -14,54 +14,62 @@ function tmpCwd(): string {
} }
describe("daemon E2E (real claude) - rewind user message dedupe", () => { describe("daemon E2E (real claude) - rewind user message dedupe", () => {
test.runIf(isProviderAvailable("claude"))( let canRun = false;
"emits /rewind user message once in persisted timeline",
async () => { beforeAll(async () => {
const logger = pino({ level: "silent" }); canRun = await isProviderAvailable("claude");
const cwd = tmpCwd(); });
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) }, beforeEach((context) => {
logger, if (!canRun) {
context.skip();
}
});
test("emits /rewind user message once in persisted timeline", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) },
logger,
});
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await client.connect();
await client.fetchAgents({
subscribe: { subscriptionId: "rewind-user-message-dedupe" },
}); });
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try { const agent = await client.createAgent({
await client.connect(); cwd,
await client.fetchAgents({ title: "rewind-user-message-dedupe-real-claude",
subscribe: { subscriptionId: "rewind-user-message-dedupe" }, ...getFullAccessConfig("claude"),
}); });
const agent = await client.createAgent({ await client.sendMessage(agent.id, "Reply with exactly: READY");
cwd, const initialResult = await client.waitForFinish(agent.id, 180_000);
title: "rewind-user-message-dedupe-real-claude", expect(initialResult.status).toBe("idle");
...getFullAccessConfig("claude"),
});
await client.sendMessage(agent.id, "Reply with exactly: READY"); await client.sendMessage(agent.id, "/rewind");
const initialResult = await client.waitForFinish(agent.id, 180_000); const rewindResult = await client.waitForFinish(agent.id, 180_000);
expect(initialResult.status).toBe("idle"); expect(rewindResult.status).not.toBe("timeout");
await client.sendMessage(agent.id, "/rewind"); const timeline = await client.fetchAgentTimeline(agent.id, {
const rewindResult = await client.waitForFinish(agent.id, 180_000); direction: "tail",
expect(rewindResult.status).not.toBe("timeout"); limit: 0,
projection: "canonical",
});
const timeline = await client.fetchAgentTimeline(agent.id, { const rewindUserMessages = timeline.entries.filter(
direction: "tail", (entry) => entry.item.type === "user_message" && entry.item.text.trim() === "/rewind",
limit: 0, );
projection: "canonical",
});
const rewindUserMessages = timeline.entries.filter( expect(rewindUserMessages).toHaveLength(1);
(entry) => entry.item.type === "user_message" && entry.item.text.trim() === "/rewind", } finally {
); await client.close();
await daemon.close();
expect(rewindUserMessages).toHaveLength(1); rmSync(cwd, { recursive: true, force: true });
} finally { }
await client.close(); }, 300_000);
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
},
300_000,
);
}); });
@@ -1,4 +1,4 @@
import { describe, test, expect } from "vitest"; import { beforeAll, beforeEach, describe, test, expect } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -168,111 +168,119 @@ async function waitForRunningToolCall(
} }
describe("daemon E2E (real claude) - send message during tool call", () => { describe("daemon E2E (real claude) - send message during tool call", () => {
test.runIf(isProviderAvailable("claude"))( let canRun = false;
"sending a message while a tool call is running replaces the turn without error, idle flash, or autonomous fallback",
async () => { beforeAll(async () => {
const logger = pino({ level: "silent" }); canRun = await isProviderAvailable("claude");
const cwd = tmpCwd(); });
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) }, beforeEach((context) => {
logger, if (!canRun) {
context.skip();
}
});
test("sending a message while a tool call is running replaces the turn without error, idle flash, or autonomous fallback", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) },
logger,
});
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await client.connect();
await client.fetchAgents({ subscribe: { subscriptionId: "primary" } });
const agent = await client.createAgent({
cwd,
title: "tool-interrupt-repro",
...getFullAccessConfig("claude"),
}); });
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` }); const collector = createMessageCollector(client);
try { // Step 1: Ask Claude to run sleep 60 in the foreground
await client.connect(); await client.sendMessage(
await client.fetchAgents({ subscribe: { subscriptionId: "primary" } }); agent.id,
[
"Use the Bash tool.",
"Run exactly: sleep 60",
"Do not use a background task.",
"Do not do anything after starting the command.",
].join(" "),
);
const agent = await client.createAgent({ // Step 2: Wait for the agent to be running
cwd, await client.waitForAgentUpsert(
title: "tool-interrupt-repro", agent.id,
...getFullAccessConfig("claude"), (snapshot) => snapshot.status === "running",
60_000,
);
// Step 3: Wait for a tool call to appear as "running" in the stream
await waitForRunningToolCall(client, collector, agent.id);
collector.clear();
// Step 4: Send a second message while the tool call is still running
await client.sendMessage(agent.id, "Reply with exactly: INTERRUPT_RECEIVED");
// Step 5: Wait for the agent to finish — this is the critical assertion.
// If the bug is present, the agent will stop and never start a new turn.
const finish = await client.waitForFinish(agent.id, 120_000);
const postSendMessages = [...collector.messages];
const postSendAssistantTexts = getAssistantTexts(postSendMessages, agent.id);
const postSendStatuses = getAgentStatuses(postSendMessages, agent.id);
const statusesBeforeFirstAssistant = getStatusesBeforeFirstAssistant(
postSendMessages,
agent.id,
);
const timeline = await client.fetchAgentTimeline(agent.id, { limit: 100 });
if (finish.status !== "idle") {
const snapshot = await client.fetchAgent(agent.id);
throw new Error(
`Expected idle after replacement, got ${finish.status}. postSendStatuses=${JSON.stringify(postSendStatuses)} statusesBeforeFirstAssistant=${JSON.stringify(statusesBeforeFirstAssistant)} postSendAssistantTexts=${JSON.stringify(postSendAssistantTexts)} turnStarted=${countTurnStarted(postSendMessages, agent.id)} agentStatus=${snapshot?.agent.status ?? null} recentTimeline=${JSON.stringify(summarizeTimelineItems(timeline))}`,
);
}
// Replacement should create exactly one new turn. A second turn_started here
// means the reply got displaced onto a later autonomous wake.
expect(countTurnStarted(postSendMessages, agent.id)).toBe(1);
// The replacement path should not surface as agent error state.
expect(postSendStatuses).not.toContain("error");
// The agent should not flash idle before the replacement produces visible output.
expect(statusesBeforeFirstAssistant).not.toContain("idle");
expect(statusesBeforeFirstAssistant).not.toContain("error");
// Step 6: Verify the agent actually responded to our second message
const assistantTexts = timeline.entries
.filter((entry) => entry.item.type === "assistant_message")
.map((entry) => {
const item = entry.item as Extract<AgentTimelineItem, { type: "assistant_message" }>;
return item.text;
}); });
const collector = createMessageCollector(client); // No system error messages should leak into the timeline
const hasSystemError = assistantTexts.some((text) => text.includes("[System Error]"));
expect(hasSystemError).toBe(false);
expect(postSendAssistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
// Step 1: Ask Claude to run sleep 60 in the foreground const responded = assistantTexts.some((text) =>
await client.sendMessage( text.toUpperCase().includes("INTERRUPT_RECEIVED"),
agent.id, );
[ expect(responded).toBe(true);
"Use the Bash tool.",
"Run exactly: sleep 60",
"Do not use a background task.",
"Do not do anything after starting the command.",
].join(" "),
);
// Step 2: Wait for the agent to be running collector.unsubscribe();
await client.waitForAgentUpsert( } finally {
agent.id, await client.close();
(snapshot) => snapshot.status === "running", await daemon.close();
60_000, rmSync(cwd, { recursive: true, force: true });
); }
}, 300_000);
// Step 3: Wait for a tool call to appear as "running" in the stream
await waitForRunningToolCall(client, collector, agent.id);
collector.clear();
// Step 4: Send a second message while the tool call is still running
await client.sendMessage(agent.id, "Reply with exactly: INTERRUPT_RECEIVED");
// Step 5: Wait for the agent to finish — this is the critical assertion.
// If the bug is present, the agent will stop and never start a new turn.
const finish = await client.waitForFinish(agent.id, 120_000);
const postSendMessages = [...collector.messages];
const postSendAssistantTexts = getAssistantTexts(postSendMessages, agent.id);
const postSendStatuses = getAgentStatuses(postSendMessages, agent.id);
const statusesBeforeFirstAssistant = getStatusesBeforeFirstAssistant(
postSendMessages,
agent.id,
);
const timeline = await client.fetchAgentTimeline(agent.id, { limit: 100 });
if (finish.status !== "idle") {
const snapshot = await client.fetchAgent(agent.id);
throw new Error(
`Expected idle after replacement, got ${finish.status}. postSendStatuses=${JSON.stringify(postSendStatuses)} statusesBeforeFirstAssistant=${JSON.stringify(statusesBeforeFirstAssistant)} postSendAssistantTexts=${JSON.stringify(postSendAssistantTexts)} turnStarted=${countTurnStarted(postSendMessages, agent.id)} agentStatus=${snapshot?.agent.status ?? null} recentTimeline=${JSON.stringify(summarizeTimelineItems(timeline))}`,
);
}
// Replacement should create exactly one new turn. A second turn_started here
// means the reply got displaced onto a later autonomous wake.
expect(countTurnStarted(postSendMessages, agent.id)).toBe(1);
// The replacement path should not surface as agent error state.
expect(postSendStatuses).not.toContain("error");
// The agent should not flash idle before the replacement produces visible output.
expect(statusesBeforeFirstAssistant).not.toContain("idle");
expect(statusesBeforeFirstAssistant).not.toContain("error");
// Step 6: Verify the agent actually responded to our second message
const assistantTexts = timeline.entries
.filter((entry) => entry.item.type === "assistant_message")
.map((entry) => {
const item = entry.item as Extract<AgentTimelineItem, { type: "assistant_message" }>;
return item.text;
});
// No system error messages should leak into the timeline
const hasSystemError = assistantTexts.some((text) => text.includes("[System Error]"));
expect(hasSystemError).toBe(false);
expect(postSendAssistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
const responded = assistantTexts.some((text) =>
text.toUpperCase().includes("INTERRUPT_RECEIVED"),
);
expect(responded).toBe(true);
collector.unsubscribe();
} finally {
await client.close();
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
},
300_000,
);
}); });
@@ -1,4 +1,4 @@
import { describe, test, expect } from "vitest"; import { beforeAll, beforeEach, describe, test, expect } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -15,109 +15,117 @@ function tmpCwd(): string {
} }
describe("daemon E2E (real claude) - send while running recovery", () => { describe("daemon E2E (real claude) - send while running recovery", () => {
test.runIf(isProviderAvailable("claude"))( let canRun = false;
"clears input processing when the interrupt transition is missed",
async () => { beforeAll(async () => {
const logger = pino({ level: "silent" }); canRun = await isProviderAvailable("claude");
const cwd = tmpCwd(); });
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) }, beforeEach((context) => {
logger, if (!canRun) {
context.skip();
}
});
test("clears input processing when the interrupt transition is missed", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: { claude: new ClaudeAgentClient({ logger }) },
logger,
});
const primary = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
const secondary = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await primary.connect();
await secondary.connect();
await primary.fetchAgents({ subscribe: { subscriptionId: "primary" } });
await secondary.fetchAgents({ subscribe: { subscriptionId: "secondary" } });
const agent = await primary.createAgent({
cwd,
title: "stuck-repro-real-claude",
...getFullAccessConfig("claude"),
}); });
const primary = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` }); await primary.sendMessage(
const secondary = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` }); agent.id,
"Run bash command sleep 30, wait for completion, then reply done.",
);
await primary.waitForAgentUpsert(
agent.id,
(snapshot) => snapshot.status === "running",
60_000,
);
let isProcessing = true;
let previousIsRunning = true;
let latestUpdatedAt = Date.now();
await primary.close();
await secondary.sendMessage(agent.id, "Reply with exactly: state saved");
await secondary.waitForAgentUpsert(
agent.id,
(snapshot) => snapshot.status === "running",
60_000,
);
const reconnected = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try { try {
await primary.connect(); await reconnected.connect();
await secondary.connect(); const applySnapshot = (
await primary.fetchAgents({ subscribe: { subscriptionId: "primary" } }); snapshot: Parameters<typeof applyAgentInputProcessingTransition>[0]["snapshot"],
await secondary.fetchAgents({ subscribe: { subscriptionId: "secondary" } }); ) => {
const next = applyAgentInputProcessingTransition({
snapshot,
currentIsProcessing: isProcessing,
previousIsRunning,
latestUpdatedAt,
});
isProcessing = next.isProcessing;
previousIsRunning = next.previousIsRunning;
latestUpdatedAt = next.latestUpdatedAt;
};
const agent = await primary.createAgent({ reconnected.on("agent_update", (message) => {
cwd, if (message.type !== "agent_update" || message.payload.kind !== "upsert") {
title: "stuck-repro-real-claude", return;
...getFullAccessConfig("claude"), }
if (message.payload.agent.id !== agent.id) {
return;
}
applySnapshot(message.payload.agent);
}); });
await primary.sendMessage( const initial = await reconnected.fetchAgents({
agent.id, subscribe: { subscriptionId: "reconnected" },
"Run bash command sleep 30, wait for completion, then reply done.", });
); const hydratedSnapshot = initial.entries.find(
await primary.waitForAgentUpsert( (candidate) => candidate.agent.id === agent.id,
agent.id, )?.agent;
(snapshot) => snapshot.status === "running", if (hydratedSnapshot) {
60_000, applySnapshot(hydratedSnapshot);
);
let isProcessing = true;
let previousIsRunning = true;
let latestUpdatedAt = Date.now();
await primary.close();
await secondary.sendMessage(agent.id, "Reply with exactly: state saved");
await secondary.waitForAgentUpsert(
agent.id,
(snapshot) => snapshot.status === "running",
60_000,
);
const reconnected = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await reconnected.connect();
const applySnapshot = (
snapshot: Parameters<typeof applyAgentInputProcessingTransition>[0]["snapshot"],
) => {
const next = applyAgentInputProcessingTransition({
snapshot,
currentIsProcessing: isProcessing,
previousIsRunning,
latestUpdatedAt,
});
isProcessing = next.isProcessing;
previousIsRunning = next.previousIsRunning;
latestUpdatedAt = next.latestUpdatedAt;
};
reconnected.on("agent_update", (message) => {
if (message.type !== "agent_update" || message.payload.kind !== "upsert") {
return;
}
if (message.payload.agent.id !== agent.id) {
return;
}
applySnapshot(message.payload.agent);
});
const initial = await reconnected.fetchAgents({
subscribe: { subscriptionId: "reconnected" },
});
const hydratedSnapshot = initial.entries.find(
(candidate) => candidate.agent.id === agent.id,
)?.agent;
if (hydratedSnapshot) {
applySnapshot(hydratedSnapshot);
}
await secondary.waitForFinish(agent.id, 180_000);
const finalResult = await secondary.fetchAgent(agent.id);
if (finalResult) {
applySnapshot(finalResult.agent);
}
// Sending while running should clear processing even if reconnect misses the
// not-running -> running transition.
expect(isProcessing).toBe(false);
} finally {
await reconnected.close();
} }
await secondary.waitForFinish(agent.id, 180_000);
const finalResult = await secondary.fetchAgent(agent.id);
if (finalResult) {
applySnapshot(finalResult.agent);
}
// Sending while running should clear processing even if reconnect misses the
// not-running -> running transition.
expect(isProcessing).toBe(false);
} finally { } finally {
await secondary.close(); await reconnected.close();
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
} }
}, } finally {
300_000, await secondary.close();
); await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
}, 300_000);
}); });
@@ -1,4 +1,4 @@
import { describe, test, expect } from "vitest"; import { beforeAll, beforeEach, describe, test, expect } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -15,106 +15,114 @@ function tmpCwd(): string {
} }
describe("daemon E2E (real codex) - send while running recovery", () => { describe("daemon E2E (real codex) - send while running recovery", () => {
test.runIf(isProviderAvailable("codex"))( let canRun = false;
"clears input processing when the interrupt transition is missed",
async () => { beforeAll(async () => {
const logger = pino({ level: "silent" }); canRun = await isProviderAvailable("codex");
const cwd = tmpCwd(); });
const daemon = await createTestPaseoDaemon({
agentClients: { codex: new CodexAppServerAgentClient(logger) }, beforeEach((context) => {
logger, if (!canRun) {
context.skip();
}
});
test("clears input processing when the interrupt transition is missed", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: { codex: new CodexAppServerAgentClient(logger) },
logger,
});
const primary = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
const secondary = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await primary.connect();
await secondary.connect();
await primary.fetchAgents({ subscribe: { subscriptionId: "primary" } });
await secondary.fetchAgents({ subscribe: { subscriptionId: "secondary" } });
const agent = await primary.createAgent({
cwd,
title: "stuck-repro-real-codex",
...getFullAccessConfig("codex"),
}); });
const primary = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` }); await primary.sendMessage(agent.id, "Run: sleep 5");
const secondary = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` }); await primary.waitForAgentUpsert(
agent.id,
(snapshot) => snapshot.status === "running",
30_000,
);
let isProcessing = true;
let previousIsRunning = true;
let latestUpdatedAt = Date.now();
await primary.close();
await secondary.sendMessage(agent.id, "Reply with exactly: state saved");
await secondary.waitForAgentUpsert(
agent.id,
(snapshot) => snapshot.status === "running",
30_000,
);
const reconnected = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try { try {
await primary.connect(); await reconnected.connect();
await secondary.connect(); const applySnapshot = (
await primary.fetchAgents({ subscribe: { subscriptionId: "primary" } }); snapshot: Parameters<typeof applyAgentInputProcessingTransition>[0]["snapshot"],
await secondary.fetchAgents({ subscribe: { subscriptionId: "secondary" } }); ) => {
const next = applyAgentInputProcessingTransition({
snapshot,
currentIsProcessing: isProcessing,
previousIsRunning,
latestUpdatedAt,
});
isProcessing = next.isProcessing;
previousIsRunning = next.previousIsRunning;
latestUpdatedAt = next.latestUpdatedAt;
};
const agent = await primary.createAgent({ reconnected.on("agent_update", (message) => {
cwd, if (message.type !== "agent_update" || message.payload.kind !== "upsert") {
title: "stuck-repro-real-codex", return;
...getFullAccessConfig("codex"), }
if (message.payload.agent.id !== agent.id) {
return;
}
applySnapshot(message.payload.agent);
}); });
await primary.sendMessage(agent.id, "Run: sleep 5"); const initial = await reconnected.fetchAgents({
await primary.waitForAgentUpsert( subscribe: { subscriptionId: "reconnected" },
agent.id, });
(snapshot) => snapshot.status === "running", const hydratedSnapshot = initial.entries.find(
30_000, (candidate) => candidate.agent.id === agent.id,
); )?.agent;
if (hydratedSnapshot) {
let isProcessing = true; applySnapshot(hydratedSnapshot);
let previousIsRunning = true;
let latestUpdatedAt = Date.now();
await primary.close();
await secondary.sendMessage(agent.id, "Reply with exactly: state saved");
await secondary.waitForAgentUpsert(
agent.id,
(snapshot) => snapshot.status === "running",
30_000,
);
const reconnected = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await reconnected.connect();
const applySnapshot = (
snapshot: Parameters<typeof applyAgentInputProcessingTransition>[0]["snapshot"],
) => {
const next = applyAgentInputProcessingTransition({
snapshot,
currentIsProcessing: isProcessing,
previousIsRunning,
latestUpdatedAt,
});
isProcessing = next.isProcessing;
previousIsRunning = next.previousIsRunning;
latestUpdatedAt = next.latestUpdatedAt;
};
reconnected.on("agent_update", (message) => {
if (message.type !== "agent_update" || message.payload.kind !== "upsert") {
return;
}
if (message.payload.agent.id !== agent.id) {
return;
}
applySnapshot(message.payload.agent);
});
const initial = await reconnected.fetchAgents({
subscribe: { subscriptionId: "reconnected" },
});
const hydratedSnapshot = initial.entries.find(
(candidate) => candidate.agent.id === agent.id,
)?.agent;
if (hydratedSnapshot) {
applySnapshot(hydratedSnapshot);
}
await secondary.waitForFinish(agent.id, 120_000);
const finalResult = await secondary.fetchAgent(agent.id);
if (finalResult) {
applySnapshot(finalResult.agent);
}
// Sending while running should clear processing even if reconnect misses the
// not-running -> running transition.
expect(isProcessing).toBe(false);
} finally {
await reconnected.close();
} }
await secondary.waitForFinish(agent.id, 120_000);
const finalResult = await secondary.fetchAgent(agent.id);
if (finalResult) {
applySnapshot(finalResult.agent);
}
// Sending while running should clear processing even if reconnect misses the
// not-running -> running transition.
expect(isProcessing).toBe(false);
} finally { } finally {
await secondary.close(); await reconnected.close();
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
} }
}, } finally {
240_000, await secondary.close();
); await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
}, 240_000);
}); });
@@ -1,4 +1,4 @@
import { describe, expect, test } from "vitest"; import { beforeAll, beforeEach, describe, expect, test } from "vitest";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
@@ -456,92 +456,94 @@ function createRealAgentClient(provider: AgentProvider, logger: pino.Logger): Ag
} }
describe.each(allProviders)("daemon E2E (real %s) - UI action stress", (provider) => { describe.each(allProviders)("daemon E2E (real %s) - UI action stress", (provider) => {
const shouldRun = isProviderAvailable(provider); let shouldRun = false;
test.runIf(shouldRun)( beforeAll(async () => {
"normal UI submit path (idle sends) stays correct", shouldRun = await isProviderAvailable(provider);
async () => { });
const logger = pino({ level: "silent" });
const cwd = tmpCwd(); beforeEach((context) => {
const daemon = await createTestPaseoDaemon({ if (!shouldRun) {
agentClients: { context.skip();
[provider]: createRealAgentClient(provider, logger), }
} as Partial<Record<AgentProvider, AgentClient>>, });
logger,
test("normal UI submit path (idle sends) stays correct", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: {
[provider]: createRealAgentClient(provider, logger),
} as Partial<Record<AgentProvider, AgentClient>>,
logger,
});
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try {
await client.connect();
await client.fetchAgents({
subscribe: { subscriptionId: `ui-stress-normal-${provider}` },
});
const agent = await client.createAgent({
cwd,
title: `uist-n-${provider}`,
...getFullAccessConfig(provider),
}); });
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
try { await runUiScenario({
await client.connect(); client,
await client.fetchAgents({ agentId: agent.id,
subscribe: { subscriptionId: `ui-stress-normal-${provider}` }, scenario: buildNormalUsageScenario(provider, 7),
}); });
await client.deleteAgent(agent.id);
} finally {
await client.close();
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
}, 420_000);
test("queued-send-now path is stable under overlap", async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: {
[provider]: createRealAgentClient(provider, logger),
} as Partial<Record<AgentProvider, AgentClient>>,
logger,
});
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
const scenarios = [
buildOverlapScenario(provider, 17, "last"),
buildOverlapScenario(provider, 31, "first"),
];
try {
await client.connect();
await client.fetchAgents({
subscribe: { subscriptionId: `ui-stress-overlap-${provider}` },
});
for (const scenario of scenarios) {
const agent = await client.createAgent({ const agent = await client.createAgent({
cwd, cwd,
title: `uist-n-${provider}`, title: `uist-o-${provider}`,
...getFullAccessConfig(provider), ...getFullAccessConfig(provider),
}); });
await runUiScenario({ await runUiScenario({
client, client,
agentId: agent.id, agentId: agent.id,
scenario: buildNormalUsageScenario(provider, 7), scenario,
}); });
await client.deleteAgent(agent.id); await client.deleteAgent(agent.id);
} finally {
await client.close();
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
} }
}, } finally {
420_000, await client.close();
); await daemon.close();
rmSync(cwd, { recursive: true, force: true });
test.runIf(shouldRun)( }
"queued-send-now path is stable under overlap", }, 600_000);
async () => {
const logger = pino({ level: "silent" });
const cwd = tmpCwd();
const daemon = await createTestPaseoDaemon({
agentClients: {
[provider]: createRealAgentClient(provider, logger),
} as Partial<Record<AgentProvider, AgentClient>>,
logger,
});
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
const scenarios = [
buildOverlapScenario(provider, 17, "last"),
buildOverlapScenario(provider, 31, "first"),
];
try {
await client.connect();
await client.fetchAgents({
subscribe: { subscriptionId: `ui-stress-overlap-${provider}` },
});
for (const scenario of scenarios) {
const agent = await client.createAgent({
cwd,
title: `uist-o-${provider}`,
...getFullAccessConfig(provider),
});
await runUiScenario({
client,
agentId: agent.id,
scenario,
});
await client.deleteAgent(agent.id);
}
} finally {
await client.close();
await daemon.close();
rmSync(cwd, { recursive: true, force: true });
}
},
600_000,
);
}); });
+2 -2
View File
@@ -33,11 +33,11 @@ export {
export { applyProviderEnv } from "./agent/provider-launch-config.js"; export { applyProviderEnv } from "./agent/provider-launch-config.js";
export { export {
findExecutable, findExecutable,
findExecutableSync, executableExists,
quoteWindowsArgument, quoteWindowsArgument,
quoteWindowsCommand, quoteWindowsCommand,
} from "../utils/executable.js"; } from "../utils/executable.js";
export { spawnProcess } from "../utils/spawn.js"; export { execCommand, spawnProcess } from "../utils/spawn.js";
// Provider manifest (source of truth for provider definitions) // Provider manifest (source of truth for provider definitions)
export { export {
+3 -4
View File
@@ -1,8 +1,6 @@
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
import { execFile } from "node:child_process";
import { promises as fs } from "node:fs"; import { promises as fs } from "node:fs";
import path from "node:path"; import path from "node:path";
import { promisify } from "node:util";
import { z } from "zod"; import { z } from "zod";
import type { Logger } from "pino"; import type { Logger } from "pino";
import { curateAgentActivity } from "./agent/activity-curator.js"; import { curateAgentActivity } from "./agent/activity-curator.js";
@@ -15,8 +13,8 @@ import type {
AgentTimelineItem, AgentTimelineItem,
AgentProvider, AgentProvider,
} from "./agent/agent-sdk-types.js"; } from "./agent/agent-sdk-types.js";
import { execCommand, platformShell } from "../utils/spawn.js";
const execFileAsync = promisify(execFile);
const LOOP_ID_LENGTH = 8; const LOOP_ID_LENGTH = 8;
const DEFAULT_LOOP_PROVIDER: AgentProvider = "claude"; const DEFAULT_LOOP_PROVIDER: AgentProvider = "claude";
const MAX_VERIFY_OUTPUT_BYTES = 64 * 1024; const MAX_VERIFY_OUTPUT_BYTES = 64 * 1024;
@@ -256,7 +254,8 @@ async function runVerifyCheck(options: {
}): Promise<LoopVerifyCheckResult> { }): Promise<LoopVerifyCheckResult> {
const startedAt = nowIso(); const startedAt = nowIso();
try { try {
const result = await execFileAsync("/bin/sh", ["-lc", options.command], { const shell = platformShell();
const result = await execCommand(shell.command, [...shell.flag, options.command], {
cwd: options.cwd, cwd: options.cwd,
maxBuffer: MAX_VERIFY_OUTPUT_BYTES, maxBuffer: MAX_VERIFY_OUTPUT_BYTES,
}); });
+11 -11
View File
@@ -1,7 +1,7 @@
import equal from "fast-deep-equal"; import equal from "fast-deep-equal";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { stat } from "fs/promises"; import { stat } from "fs/promises";
import { exec, execFile } from "node:child_process"; import { exec } from "node:child_process";
import { promisify } from "util"; import { promisify } from "util";
import { resolve, sep } from "path"; import { resolve, sep } from "path";
import { homedir } from "node:os"; import { homedir } from "node:os";
@@ -170,6 +170,7 @@ import { ChatServiceError, FileBackedChatService } from "./chat/chat-service.js"
import { notifyChatMentions } from "./chat/chat-mentions.js"; import { notifyChatMentions } from "./chat/chat-mentions.js";
import { LoopService } from "./loop-service.js"; import { LoopService } from "./loop-service.js";
import { ScheduleService } from "./schedule/service.js"; import { ScheduleService } from "./schedule/service.js";
import { execCommand } from "../utils/spawn.js";
import { import {
assertSafeGitRef as assertWorktreeSafeGitRef, assertSafeGitRef as assertWorktreeSafeGitRef,
buildAgentSessionConfig as buildWorktreeAgentSessionConfig, buildAgentSessionConfig as buildWorktreeAgentSessionConfig,
@@ -182,7 +183,6 @@ import {
} from "./worktree-session.js"; } from "./worktree-session.js";
const execAsync = promisify(exec); const execAsync = promisify(exec);
const execFileAsync = promisify(execFile);
const MAX_INITIAL_AGENT_TITLE_CHARS = Math.min(60, MAX_EXPLICIT_AGENT_TITLE_CHARS); const MAX_INITIAL_AGENT_TITLE_CHARS = Math.min(60, MAX_EXPLICIT_AGENT_TITLE_CHARS);
const pendingAgentInitializations = new Map<string, Promise<ManagedAgent>>(); const pendingAgentInitializations = new Map<string, Promise<ManagedAgent>>();
const DEFAULT_AGENT_PROVIDER = AGENT_PROVIDER_IDS[0]; const DEFAULT_AGENT_PROVIDER = AGENT_PROVIDER_IDS[0];
@@ -3531,7 +3531,7 @@ export class Session {
private async checkoutExistingBranch(cwd: string, branch: string): Promise<void> { private async checkoutExistingBranch(cwd: string, branch: string): Promise<void> {
this.assertSafeGitRef(branch, "branch"); this.assertSafeGitRef(branch, "branch");
try { try {
await execFileAsync("git", ["rev-parse", "--verify", branch], { cwd }); await execCommand("git", ["rev-parse", "--verify", branch], { cwd });
} catch (error) { } catch (error) {
throw new Error(`Branch not found: ${branch}`); throw new Error(`Branch not found: ${branch}`);
} }
@@ -3545,7 +3545,7 @@ export class Session {
} }
await this.ensureCleanWorkingTree(cwd); await this.ensureCleanWorkingTree(cwd);
await execFileAsync("git", ["checkout", branch], { cwd }); await execCommand("git", ["checkout", branch], { cwd });
} }
private async createBranchFromBase(params: { private async createBranchFromBase(params: {
@@ -3558,7 +3558,7 @@ export class Session {
this.assertSafeGitRef(newBranchName, "new branch"); this.assertSafeGitRef(newBranchName, "new branch");
try { try {
await execFileAsync("git", ["rev-parse", "--verify", baseBranch], { cwd }); await execCommand("git", ["rev-parse", "--verify", baseBranch], { cwd });
} catch (error) { } catch (error) {
throw new Error(`Base branch not found: ${baseBranch}`); throw new Error(`Base branch not found: ${baseBranch}`);
} }
@@ -3569,7 +3569,7 @@ export class Session {
} }
await this.ensureCleanWorkingTree(cwd); await this.ensureCleanWorkingTree(cwd);
await execFileAsync("git", ["checkout", "-b", newBranchName, baseBranch], { await execCommand("git", ["checkout", "-b", newBranchName, baseBranch], {
cwd, cwd,
}); });
} }
@@ -3577,7 +3577,7 @@ export class Session {
private async doesLocalBranchExist(cwd: string, branch: string): Promise<boolean> { private async doesLocalBranchExist(cwd: string, branch: string): Promise<boolean> {
this.assertSafeGitRef(branch, "branch"); this.assertSafeGitRef(branch, "branch");
try { try {
await execFileAsync("git", ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`], { await execCommand("git", ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`], {
cwd, cwd,
}); });
return true; return true;
@@ -4030,7 +4030,7 @@ export class Session {
// Try local branch first // Try local branch first
try { try {
await execFileAsync("git", ["rev-parse", "--verify", branchName], { await execCommand("git", ["rev-parse", "--verify", branchName], {
cwd: resolvedCwd, cwd: resolvedCwd,
env: READ_ONLY_GIT_ENV, env: READ_ONLY_GIT_ENV,
}); });
@@ -4051,7 +4051,7 @@ export class Session {
// Try remote branch (origin/{branchName}) // Try remote branch (origin/{branchName})
try { try {
await execFileAsync("git", ["rev-parse", "--verify", `origin/${branchName}`], { await execCommand("git", ["rev-parse", "--verify", `origin/${branchName}`], {
cwd: resolvedCwd, cwd: resolvedCwd,
env: READ_ONLY_GIT_ENV, env: READ_ONLY_GIT_ENV,
}); });
@@ -4281,7 +4281,7 @@ export class Session {
const message = branchLabel const message = branchLabel
? `${Session.PASEO_STASH_PREFIX} ${branchLabel}` ? `${Session.PASEO_STASH_PREFIX} ${branchLabel}`
: `${Session.PASEO_STASH_PREFIX} unnamed`; : `${Session.PASEO_STASH_PREFIX} unnamed`;
await execFileAsync("git", ["stash", "push", "--include-untracked", "-m", message], { cwd }); await execCommand("git", ["stash", "push", "--include-untracked", "-m", message], { cwd });
this.checkoutDiffManager.scheduleRefreshForCwd(cwd); this.checkoutDiffManager.scheduleRefreshForCwd(cwd);
this.emit({ this.emit({
type: "stash_save_response", type: "stash_save_response",
@@ -4300,7 +4300,7 @@ export class Session {
): Promise<void> { ): Promise<void> {
const { cwd, stashIndex, requestId } = msg; const { cwd, stashIndex, requestId } = msg;
try { try {
await execFileAsync("git", ["stash", "pop", `stash@{${stashIndex}}`], { cwd }); await execCommand("git", ["stash", "pop", `stash@{${stashIndex}}`], { cwd });
this.checkoutDiffManager.scheduleRefreshForCwd(cwd); this.checkoutDiffManager.scheduleRefreshForCwd(cwd);
this.emit({ this.emit({
type: "stash_pop_response", type: "stash_pop_response",
+28 -14
View File
@@ -1,11 +1,11 @@
#!/usr/bin/env node #!/usr/bin/env node
import { Command } from "commander"; import { Command } from "commander";
import { spawnSync } from "node:child_process";
import { appendFileSync, existsSync, openSync, readFileSync } from "node:fs"; import { appendFileSync, existsSync, openSync, readFileSync } from "node:fs";
import { resolve } from "node:path"; import { resolve } from "node:path";
import { FileTaskStore } from "./task-store.js"; import { FileTaskStore } from "./task-store.js";
import { computeExecutionOrder, buildSortedChildrenMap } from "./execution-order.js"; import { computeExecutionOrder, buildSortedChildrenMap } from "./execution-order.js";
import { resolvePackageVersion } from "../server/package-version.js"; import { resolvePackageVersion } from "../server/package-version.js";
import { spawnProcess } from "../utils/spawn.js";
import type { AgentType, ModelName, Task } from "./types.js"; import type { AgentType, ModelName, Task } from "./types.js";
const TASKS_DIR = resolve(process.cwd(), ".tasks"); const TASKS_DIR = resolve(process.cwd(), ".tasks");
@@ -638,11 +638,11 @@ function getAgentConfig(modelStr: string): AgentConfig {
return { cli: "claude", model }; return { cli: "claude", model };
} }
function runAgentWithModel( async function runAgentWithModel(
prompt: string, prompt: string,
modelStr: string, modelStr: string,
logFile: string, logFile: string,
): { success: boolean; output: string } { ): Promise<{ success: boolean; output: string }> {
const config = getAgentConfig(modelStr); const config = getAgentConfig(modelStr);
let args: string[]; let args: string[];
@@ -667,20 +667,34 @@ function runAgentWithModel(
args.push(prompt); args.push(prompt);
} }
const result = spawnSync(config.cli, args, { const { stdout, stderr, exitCode } = await new Promise<{
stdio: ["inherit", "pipe", "pipe"], stdout: string;
cwd: process.cwd(), stderr: string;
maxBuffer: 50 * 1024 * 1024, exitCode: number | null;
}>((resolve, reject) => {
const child = spawnProcess(config.cli, args, {
stdio: ["inherit", "pipe", "pipe"],
cwd: process.cwd(),
});
const stdoutChunks: Buffer[] = [];
const stderrChunks: Buffer[] = [];
child.stdout?.on("data", (chunk: Buffer) => stdoutChunks.push(chunk));
child.stderr?.on("data", (chunk: Buffer) => stderrChunks.push(chunk));
child.on("error", reject);
child.on("close", (code) => {
resolve({
stdout: Buffer.concat(stdoutChunks).toString("utf8"),
stderr: Buffer.concat(stderrChunks).toString("utf8"),
exitCode: code,
});
});
}); });
const stdout = result.stdout?.toString() ?? "";
const stderr = result.stderr?.toString() ?? "";
const output = stdout + stderr; const output = stdout + stderr;
// Append to log file for history // Append to log file for history
appendFileSync(logFile, output); appendFileSync(logFile, output);
return { success: result.status === 0, output }; return { success: exitCode === 0, output };
} }
async function buildTaskContext(task: Task, scopeId?: string): Promise<string> { async function buildTaskContext(task: Task, scopeId?: string): Promise<string> {
@@ -1102,7 +1116,7 @@ program
log(logFile, `[PLANNER] Running ${plannerModel} (${reason})...`); log(logFile, `[PLANNER] Running ${plannerModel} (${reason})...`);
const context = await buildTaskContext(task, scopeId); const context = await buildTaskContext(task, scopeId);
const plannerPrompt = makePlannerPrompt(task, context, reason); const plannerPrompt = makePlannerPrompt(task, context, reason);
runAgentWithModel(plannerPrompt, plannerModel, logFile); await runAgentWithModel(plannerPrompt, plannerModel, logFile);
// Check if planner created subtasks for this task // Check if planner created subtasks for this task
const children = await store.getChildren(task.id); const children = await store.getChildren(task.id);
@@ -1221,7 +1235,7 @@ program
const freshContext = await buildTaskContext(freshTask, scopeId); const freshContext = await buildTaskContext(freshTask, scopeId);
const workerPrompt = makeWorkerPrompt(freshTask, freshContext, iteration); const workerPrompt = makeWorkerPrompt(freshTask, freshContext, iteration);
runAgentWithModel(workerPrompt, workerModel, logFile); await runAgentWithModel(workerPrompt, workerModel, logFile);
// Step 3: Judge // Step 3: Judge
log(logFile, `[JUDGE] Verifying with ${judgeModel}...`); log(logFile, `[JUDGE] Verifying with ${judgeModel}...`);
@@ -1229,7 +1243,7 @@ program
if (!judgeTask) break; if (!judgeTask) break;
const judgePrompt = makeJudgePrompt(judgeTask); const judgePrompt = makeJudgePrompt(judgeTask);
const judgeResult = runAgentWithModel(judgePrompt, judgeModel, logFile); const judgeResult = await runAgentWithModel(judgePrompt, judgeModel, logFile);
const verdict = parseJudgeVerdict(judgeResult.output); const verdict = parseJudgeVerdict(judgeResult.output);
log(logFile, `[JUDGE] Verdict: ${verdict || "UNKNOWN"}`); log(logFile, `[JUDGE] Verdict: ${verdict || "UNKNOWN"}`);
+3 -6
View File
@@ -1,5 +1,3 @@
import { execFile } from "child_process";
import { promisify } from "util";
import { resolve, dirname, basename } from "path"; import { resolve, dirname, basename } from "path";
import { existsSync, realpathSync } from "fs"; import { existsSync, realpathSync } from "fs";
import { open as openFile, stat as statFile } from "fs/promises"; import { open as openFile, stat as statFile } from "fs/promises";
@@ -8,10 +6,9 @@ import type { ParsedDiffFile } from "../server/utils/diff-highlighter.js";
import { parseAndHighlightDiff } from "../server/utils/diff-highlighter.js"; import { parseAndHighlightDiff } from "../server/utils/diff-highlighter.js";
import { findExecutable } from "./executable.js"; import { findExecutable } from "./executable.js";
import { runGitCommand } from "./run-git-command.js"; import { runGitCommand } from "./run-git-command.js";
import { execCommand } from "./spawn.js";
import { isPaseoOwnedWorktreeCwd } from "./worktree.js"; import { isPaseoOwnedWorktreeCwd } from "./worktree.js";
import { requirePaseoWorktreeBaseRefName } from "./worktree-metadata.js"; import { requirePaseoWorktreeBaseRefName } from "./worktree-metadata.js";
const execFileAsync = promisify(execFile);
const READ_ONLY_GIT_ENV: NodeJS.ProcessEnv = { const READ_ONLY_GIT_ENV: NodeJS.ProcessEnv = {
...process.env, ...process.env,
GIT_OPTIONAL_LOCKS: "0", GIT_OPTIONAL_LOCKS: "0",
@@ -1899,7 +1896,7 @@ export async function createPullRequest(
if (options.body) { if (options.body) {
args.push("-f", `body=${options.body}`); args.push("-f", `body=${options.body}`);
} }
const { stdout } = await execFileAsync(ghPath, args, { cwd, env: ghEnv }); const { stdout } = await execCommand(ghPath, args, { cwd, env: ghEnv });
const parsed = JSON.parse(stdout.trim()); const parsed = JSON.parse(stdout.trim());
if (!parsed?.url || !parsed?.number) { if (!parsed?.url || !parsed?.number) {
throw new Error("GitHub CLI did not return PR url/number"); throw new Error("GitHub CLI did not return PR url/number");
@@ -1951,7 +1948,7 @@ async function getPullRequestStatusUncached(cwd: string): Promise<PullRequestSta
}; };
} }
try { try {
const { stdout } = await execFileAsync( const { stdout } = await execCommand(
ghPath, ghPath,
["pr", "view", "--json", "url,title,state,baseRefName,headRefName,mergedAt"], ["pr", "view", "--json", "url,title,state,baseRefName,headRefName,mergedAt"],
{ cwd, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } }, { cwd, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } },
+197 -58
View File
@@ -1,78 +1,209 @@
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; import { promisify } from "node:util";
import { afterEach, describe, expect, test, vi } from "vitest";
import { findExecutableSync, quoteWindowsArgument, quoteWindowsCommand } from "./executable.js"; type ExecFileCallback = (error: Error | null, stdout: string, stderr: string) => void;
type FindExecutableDependencies = NonNullable<Parameters<typeof findExecutableSync>[1]>; async function loadExecutableModule(params?: {
execFileImpl?: (
command: string,
args: string[],
options: unknown,
callback: ExecFileCallback,
) => void;
}) {
vi.resetModules();
function createFindExecutableDependencies(): FindExecutableDependencies { const execFileMock = vi.fn(
params?.execFileImpl ??
((_command: string, _args: string[], _options: unknown, callback: ExecFileCallback) => {
callback(new Error("execFile not mocked"), "", "");
}),
);
Object.assign(execFileMock, {
[promisify.custom]: (command: string, args: string[], options: unknown) =>
new Promise<{ stdout: string; stderr: string }>((resolve, reject) => {
execFileMock(
command,
args,
options,
(error: Error | null, stdout: string, stderr: string) => {
if (error) {
reject(error);
return;
}
resolve({ stdout, stderr });
},
);
}),
});
vi.doMock("node:child_process", () => ({
execFile: execFileMock,
}));
const module = await import("./executable.js");
return { return {
execFileSync: vi.fn(), ...module,
existsSync: vi.fn(), execFileMock,
platform: vi.fn(() => "darwin"),
}; };
} }
let findExecutableDependencies: FindExecutableDependencies; describe("findExecutable", () => {
const originalPlatform = process.platform;
beforeEach(() => { function setPlatform(value: string) {
findExecutableDependencies = createFindExecutableDependencies(); Object.defineProperty(process, "platform", { value, writable: true });
}); }
describe("findExecutableSync", () => { afterEach(() => {
test("on Windows, resolves executables using where.exe with inherited PATH", () => { setPlatform(originalPlatform);
findExecutableDependencies.platform = vi.fn(() => "win32"); });
findExecutableDependencies.execFileSync.mockReturnValue(
"C:\\Users\\boudr\\.local\\bin\\claude.exe\r\n",
);
expect(findExecutableSync("claude", findExecutableDependencies)).toBe( test("on Windows, resolves executables using where.exe with inherited PATH", async () => {
setPlatform("win32");
const { execFileMock, findExecutable } = await loadExecutableModule({
execFileImpl: (_command, _args, _options, callback) => {
callback(null, "C:\\Users\\boudr\\.local\\bin\\claude.exe\r\n", "");
},
});
await expect(findExecutable("claude")).resolves.toBe(
"C:\\Users\\boudr\\.local\\bin\\claude.exe", "C:\\Users\\boudr\\.local\\bin\\claude.exe",
); );
expect(findExecutableDependencies.execFileSync).toHaveBeenCalledOnce(); expect(execFileMock).toHaveBeenCalledOnce();
const call = findExecutableDependencies.execFileSync.mock.calls[0]; const call = execFileMock.mock.calls[0];
expect(call?.[0]).toBe("where.exe"); expect(call?.[0]).toBe("where.exe");
expect(call?.[1]).toEqual(["claude"]); expect(call?.[1]).toEqual(["claude"]);
expect(call?.[2]?.encoding).toBe("utf8"); expect(call?.[2]).toMatchObject({
expect(call?.[2]?.windowsHide).toBe(true);
});
test("on Windows, preserves the first where.exe match", () => {
findExecutableDependencies.platform = vi.fn(() => "win32");
findExecutableDependencies.execFileSync.mockReturnValue(
"C:\\nvm4w\\nodejs\\codex\r\nC:\\nvm4w\\nodejs\\codex.cmd\r\n",
);
expect(findExecutableSync("codex", findExecutableDependencies)).toBe(
"C:\\nvm4w\\nodejs\\codex",
);
});
test("on Unix, uses the last line from which output", () => {
findExecutableDependencies.execFileSync.mockReturnValue("/usr/local/bin/codex\n");
expect(findExecutableSync("codex", findExecutableDependencies)).toBe("/usr/local/bin/codex");
expect(findExecutableDependencies.execFileSync).toHaveBeenCalledWith("which", ["codex"], {
encoding: "utf8", encoding: "utf8",
windowsHide: true,
}); });
}); });
test("warns and returns null when the final which line is not an absolute path", () => { test("on Windows, prefers an executable match from where.exe output", async () => {
findExecutableDependencies.execFileSync.mockReturnValue("codex\n"); setPlatform("win32");
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {}); const { findExecutable } = await loadExecutableModule({
execFileImpl: (_command, _args, _options, callback) => {
callback(null, "C:\\nvm4w\\nodejs\\codex\r\nC:\\nvm4w\\nodejs\\codex.cmd\r\n", "");
},
});
expect(findExecutableSync("codex", findExecutableDependencies)).toBeNull(); await expect(findExecutable("codex")).resolves.toBe("C:\\nvm4w\\nodejs\\codex.cmd");
});
test("on Windows, prefers .exe over .cmd, .ps1, and extensionless candidates", async () => {
setPlatform("win32");
const { findExecutable } = await loadExecutableModule({
execFileImpl: (_command, _args, _options, callback) => {
callback(
null,
[
"C:\\nvm4w\\nodejs\\codex",
"C:\\nvm4w\\nodejs\\codex.ps1",
"C:\\nvm4w\\nodejs\\codex.cmd",
"C:\\nvm4w\\nodejs\\codex.exe",
].join("\r\n"),
"",
);
},
});
await expect(findExecutable("codex")).resolves.toBe("C:\\nvm4w\\nodejs\\codex.exe");
});
test("on Windows, returns null when where.exe output is empty", async () => {
setPlatform("win32");
const { findExecutable } = await loadExecutableModule({
execFileImpl: (_command, _args, _options, callback) => {
callback(null, "\r\n", "");
},
});
await expect(findExecutable("codex")).resolves.toBeNull();
});
test("on Windows, falls back to the first extensionless candidate when needed", async () => {
setPlatform("win32");
const { findExecutable } = await loadExecutableModule({
execFileImpl: (_command, _args, _options, callback) => {
callback(null, "C:\\nvm4w\\nodejs\\codex\r\n", "");
},
});
await expect(findExecutable("codex")).resolves.toBe("C:\\nvm4w\\nodejs\\codex");
});
test("on Unix, uses the last line from which output", async () => {
const { execFileMock, findExecutable } = await loadExecutableModule({
execFileImpl: (_command, _args, _options, callback) => {
callback(null, "/usr/local/bin/codex\n", "");
},
});
await expect(findExecutable("codex")).resolves.toBe("/usr/local/bin/codex");
expect(execFileMock).toHaveBeenCalledWith(
"which",
["codex"],
{ encoding: "utf8" },
expect.any(Function),
);
});
test("warns and returns null when the final which line is not an absolute path", async () => {
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
const { findExecutable } = await loadExecutableModule({
execFileImpl: (_command, _args, _options, callback) => {
callback(null, "codex\n", "");
},
});
await expect(findExecutable("codex")).resolves.toBeNull();
expect(warnSpy).toHaveBeenCalledOnce(); expect(warnSpy).toHaveBeenCalledOnce();
warnSpy.mockRestore(); warnSpy.mockRestore();
}); });
test("returns direct paths when they exist", () => { test("returns null when which lookup fails", async () => {
findExecutableDependencies.existsSync.mockReturnValue(true); const { findExecutable } = await loadExecutableModule({
execFileImpl: (_command, _args, _options, callback) => {
callback(new Error("which failed"), "", "");
},
});
expect(findExecutableSync("/usr/local/bin/codex", findExecutableDependencies)).toBe( await expect(findExecutable("codex")).resolves.toBeNull();
"/usr/local/bin/codex", });
); });
expect(findExecutableDependencies.existsSync).toHaveBeenCalledWith("/usr/local/bin/codex");
describe("executableExists", () => {
const originalPlatform = process.platform;
function setPlatform(value: string) {
Object.defineProperty(process, "platform", { value, writable: true });
}
afterEach(() => {
setPlatform(originalPlatform);
});
test("returns the path when it already exists", async () => {
const { executableExists } = await loadExecutableModule();
const exists = vi.fn((candidate: string) => candidate === "/usr/local/bin/codex");
expect(executableExists("/usr/local/bin/codex", exists)).toBe("/usr/local/bin/codex");
});
test("on Windows, falls back to .exe, .cmd, then .ps1 for extensionless paths", async () => {
setPlatform("win32");
const { executableExists } = await loadExecutableModule();
const exists = vi.fn((candidate: string) => candidate === "C:\\tools\\codex.cmd");
expect(executableExists("C:\\tools\\codex", exists)).toBe("C:\\tools\\codex.cmd");
});
test("returns null when no matching path exists", async () => {
const { executableExists } = await loadExecutableModule();
const exists = vi.fn(() => false);
expect(executableExists("/missing/codex", exists)).toBeNull();
}); });
}); });
@@ -87,27 +218,31 @@ describe("quoteWindowsCommand", () => {
setPlatform(originalPlatform); setPlatform(originalPlatform);
}); });
test("quotes a Windows path with spaces", () => { test("quotes a Windows path with spaces", async () => {
setPlatform("win32"); setPlatform("win32");
const { quoteWindowsCommand } = await loadExecutableModule();
expect(quoteWindowsCommand("C:\\Program Files\\Anthropic\\claude.exe")).toBe( expect(quoteWindowsCommand("C:\\Program Files\\Anthropic\\claude.exe")).toBe(
'"C:\\Program Files\\Anthropic\\claude.exe"', '"C:\\Program Files\\Anthropic\\claude.exe"',
); );
}); });
test("does not double-quote an already-quoted path", () => { test("does not double-quote an already-quoted path", async () => {
setPlatform("win32"); setPlatform("win32");
const { quoteWindowsCommand } = await loadExecutableModule();
expect(quoteWindowsCommand('"C:\\Program Files\\Anthropic\\claude.exe"')).toBe( expect(quoteWindowsCommand('"C:\\Program Files\\Anthropic\\claude.exe"')).toBe(
'"C:\\Program Files\\Anthropic\\claude.exe"', '"C:\\Program Files\\Anthropic\\claude.exe"',
); );
}); });
test("returns the command unchanged when there are no spaces", () => { test("returns the command unchanged when there are no spaces", async () => {
setPlatform("win32"); setPlatform("win32");
const { quoteWindowsCommand } = await loadExecutableModule();
expect(quoteWindowsCommand("C:\\nvm4w\\nodejs\\codex")).toBe("C:\\nvm4w\\nodejs\\codex"); expect(quoteWindowsCommand("C:\\nvm4w\\nodejs\\codex")).toBe("C:\\nvm4w\\nodejs\\codex");
}); });
test("returns the command unchanged on non-Windows platforms", () => { test("returns the command unchanged on non-Windows platforms", async () => {
setPlatform("darwin"); setPlatform("darwin");
const { quoteWindowsCommand } = await loadExecutableModule();
expect(quoteWindowsCommand("/usr/local/bin/claude code")).toBe("/usr/local/bin/claude code"); expect(quoteWindowsCommand("/usr/local/bin/claude code")).toBe("/usr/local/bin/claude code");
}); });
}); });
@@ -123,27 +258,31 @@ describe("quoteWindowsArgument", () => {
setPlatform(originalPlatform); setPlatform(originalPlatform);
}); });
test("quotes a Windows argument with spaces", () => { test("quotes a Windows argument with spaces", async () => {
setPlatform("win32"); setPlatform("win32");
const { quoteWindowsArgument } = await loadExecutableModule();
expect(quoteWindowsArgument("C:\\Program Files\\Anthropic\\cli.js")).toBe( expect(quoteWindowsArgument("C:\\Program Files\\Anthropic\\cli.js")).toBe(
'"C:\\Program Files\\Anthropic\\cli.js"', '"C:\\Program Files\\Anthropic\\cli.js"',
); );
}); });
test("does not double-quote an already-quoted argument", () => { test("does not double-quote an already-quoted argument", async () => {
setPlatform("win32"); setPlatform("win32");
const { quoteWindowsArgument } = await loadExecutableModule();
expect(quoteWindowsArgument('"C:\\Program Files\\Anthropic\\cli.js"')).toBe( expect(quoteWindowsArgument('"C:\\Program Files\\Anthropic\\cli.js"')).toBe(
'"C:\\Program Files\\Anthropic\\cli.js"', '"C:\\Program Files\\Anthropic\\cli.js"',
); );
}); });
test("returns the argument unchanged when there are no spaces", () => { test("returns the argument unchanged when there are no spaces", async () => {
setPlatform("win32"); setPlatform("win32");
const { quoteWindowsArgument } = await loadExecutableModule();
expect(quoteWindowsArgument("--version")).toBe("--version"); expect(quoteWindowsArgument("--version")).toBe("--version");
}); });
test("returns the argument unchanged on non-Windows platforms", () => { test("returns the argument unchanged on non-Windows platforms", async () => {
setPlatform("darwin"); setPlatform("darwin");
const { quoteWindowsArgument } = await loadExecutableModule();
expect(quoteWindowsArgument("/usr/local/bin/claude code")).toBe("/usr/local/bin/claude code"); expect(quoteWindowsArgument("/usr/local/bin/claude code")).toBe("/usr/local/bin/claude code");
}); });
}); });
+30 -63
View File
@@ -1,15 +1,21 @@
import { execFile, execFileSync } from "node:child_process"; import { execFile } from "node:child_process";
import { existsSync } from "node:fs"; import { existsSync } from "node:fs";
import { platform } from "node:os"; import path, { extname } from "node:path";
import path from "node:path";
import { promisify } from "node:util"; import { promisify } from "node:util";
const execFileAsync = promisify(execFile); const execFileAsync = promisify(execFile);
export interface FindExecutableDependencies { function pickBestWindowsCandidate(lines: string[]): string | null {
execFileSync: typeof execFileSync; const candidates = lines.filter((line) => line.length > 0);
existsSync: typeof existsSync; if (candidates.length === 0) return null;
platform: typeof platform;
const extPriority = [".exe", ".cmd", ".ps1"];
for (const ext of extPriority) {
const match = candidates.find((candidate) => candidate.toLowerCase().endsWith(ext));
if (match) return match;
}
return candidates[0] ?? null;
} }
function resolveExecutableFromWhichOutput( function resolveExecutableFromWhichOutput(
@@ -44,58 +50,18 @@ function resolveExecutableFromWhichOutput(
* enriches it at startup via inheritLoginShellEnv(); on Windows, Electron * enriches it at startup via inheritLoginShellEnv(); on Windows, Electron
* inherits the full user environment from Explorer. * inherits the full user environment from Explorer.
*/ */
export function findExecutableSync( export function executableExists(
name: string, executablePath: string,
dependencies?: FindExecutableDependencies, exists: typeof existsSync = existsSync,
): string | null { ): string | null {
const trimmed = name.trim(); if (exists(executablePath)) return executablePath;
if (!trimmed) { if (process.platform === "win32" && !extname(executablePath)) {
return null; for (const ext of [".exe", ".cmd", ".ps1"]) {
} const candidate = executablePath + ext;
if (exists(candidate)) return candidate;
const deps: FindExecutableDependencies = {
execFileSync,
existsSync,
platform,
...dependencies,
};
if (trimmed.includes("/") || trimmed.includes("\\")) {
return deps.existsSync(trimmed) ? trimmed : null;
}
if (deps.platform() === "win32") {
try {
const out = deps
.execFileSync("where.exe", [trimmed], {
encoding: "utf8",
windowsHide: true,
})
.trim();
return (
out
.split(/\r?\n/)
.map((line) => line.trim())
.find((line) => line.length > 0) ?? null
);
} catch {
return null;
} }
} }
return null;
try {
return resolveExecutableFromWhichOutput(
trimmed,
deps.execFileSync("which", [trimmed], { encoding: "utf8" }).trim(),
"which",
);
} catch {
return null;
}
}
export function isCommandAvailableSync(command: string): boolean {
return findExecutableSync(command) !== null;
} }
export async function findExecutable(name: string): Promise<string | null> { export async function findExecutable(name: string): Promise<string | null> {
@@ -105,21 +71,22 @@ export async function findExecutable(name: string): Promise<string | null> {
} }
if (trimmed.includes("/") || trimmed.includes("\\")) { if (trimmed.includes("/") || trimmed.includes("\\")) {
return existsSync(trimmed) ? trimmed : null; return executableExists(trimmed);
} }
if (platform() === "win32") { if (process.platform === "win32") {
try { try {
const { stdout } = await execFileAsync("where.exe", [trimmed], { const { stdout } = await execFileAsync("where.exe", [trimmed], {
encoding: "utf8", encoding: "utf8",
windowsHide: true, windowsHide: true,
}); });
return ( return (
stdout pickBestWindowsCandidate(
.trim() stdout
.split(/\r?\n/) .trim()
.map((line) => line.trim()) .split(/\r?\n/)
.find((line) => line.length > 0) ?? null .map((line) => line.trim()),
) ?? null
); );
} catch { } catch {
return null; return null;
+54
View File
@@ -0,0 +1,54 @@
import { mkdtempSync, realpathSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, test } from "vitest";
import { execCommand } from "./spawn.js";
describe("execCommand", () => {
const tempDirs: string[] = [];
afterEach(() => {
for (const tempDir of tempDirs) {
rmSync(tempDir, { recursive: true, force: true });
}
tempDirs.length = 0;
});
test("returns stdout and stderr for a successful command", async () => {
await expect(execCommand("echo", ["hello"])).resolves.toEqual({
stdout: "hello\n",
stderr: "",
});
});
test("rejects when the command times out", async () => {
const command =
process.platform === "win32"
? {
command: process.execPath,
args: ["-e", "setTimeout(() => {}, 10_000)"],
}
: { command: "sleep", args: ["10"] };
await expect(execCommand(command.command, command.args, { timeout: 100 })).rejects.toThrow();
});
test("runs the command in the provided cwd", async () => {
const cwd = realpathSync(mkdtempSync(path.join(tmpdir(), "spawn-test-")));
tempDirs.push(cwd);
const command =
process.platform === "win32"
? {
command: process.execPath,
args: ["-e", "console.log(process.cwd())"],
}
: { command: "pwd", args: [] };
await expect(execCommand(command.command, command.args, { cwd })).resolves.toEqual({
stdout: `${cwd}\n`,
stderr: "",
});
});
});
+57 -19
View File
@@ -1,15 +1,27 @@
import { spawn, type ChildProcess, type SpawnOptions } from "node:child_process"; import { execFile, spawn, type ChildProcess, type SpawnOptions } from "node:child_process";
import { promisify } from "node:util";
const execFileAsync = promisify(execFile);
interface ExecCommandOptions {
cwd?: string;
env?: NodeJS.ProcessEnv;
encoding?: BufferEncoding;
timeout?: number;
maxBuffer?: number;
}
interface ExecCommandResult {
stdout: string;
stderr: string;
}
function quoteForCmd(value: string): string {
if (!value.includes(" ")) return value;
if (value.startsWith('"') && value.endsWith('"')) return value;
return `"${value}"`;
}
/**
* Platform-aware spawn that centralizes Windows shell and quoting concerns.
*
* On Windows:
* - Enables `shell: true` (routes through cmd.exe) unless the caller explicitly sets `shell`
* - Quotes the command and arguments so paths with spaces survive cmd.exe parsing
* - Always sets `windowsHide: true` to prevent console window flashes
*
* On other platforms the call is passed through to `spawn` unchanged (with `windowsHide: true`).
*/
export function spawnProcess( export function spawnProcess(
command: string, command: string,
args: string[], args: string[],
@@ -27,12 +39,38 @@ export function spawnProcess(
}); });
} }
/** export async function execCommand(
* Quote a string for cmd.exe if it contains spaces and isn't already quoted. command: string,
* No-op for strings without spaces or strings that are already double-quoted. args: string[],
*/ options?: ExecCommandOptions,
function quoteForCmd(value: string): string { ): Promise<ExecCommandResult> {
if (!value.includes(" ")) return value; const isWindows = process.platform === "win32";
if (value.startsWith('"') && value.endsWith('"')) return value; const resolvedCommand = isWindows ? quoteForCmd(command) : command;
return `"${value}"`; const resolvedArgs = isWindows ? args.map(quoteForCmd) : args;
return execFileAsync(resolvedCommand, resolvedArgs, {
cwd: options?.cwd,
env: options?.env,
encoding: options?.encoding ?? "utf8",
timeout: options?.timeout,
maxBuffer: options?.maxBuffer,
shell: isWindows,
windowsHide: true,
}) as Promise<ExecCommandResult>;
}
export function platformShell(): { command: string; flag: string[] } {
if (process.platform === "win32") {
return { command: "cmd.exe", flag: ["/c"] };
}
return { command: "/bin/sh", flag: ["-lc"] };
}
export function platformBash(): { command: string; flag: string[] } {
if (process.platform === "win32") {
return { command: "cmd.exe", flag: ["/c"] };
}
return { command: "/bin/bash", flag: ["-lc"] };
} }
+5 -3
View File
@@ -1,4 +1,4 @@
import { exec, spawn } from "child_process"; import { exec } from "child_process";
import { promisify } from "util"; import { promisify } from "util";
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync } from "fs"; import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync } from "fs";
import { join, basename, dirname, resolve, sep } from "path"; import { join, basename, dirname, resolve, sep } from "path";
@@ -13,6 +13,7 @@ import {
writePaseoWorktreeRuntimeMetadata, writePaseoWorktreeRuntimeMetadata,
} from "./worktree-metadata.js"; } from "./worktree-metadata.js";
import { runGitCommand } from "./run-git-command.js"; import { runGitCommand } from "./run-git-command.js";
import { platformBash, spawnProcess } from "./spawn.js";
import { resolvePaseoHome } from "../server/paseo-home.js"; import { resolvePaseoHome } from "../server/paseo-home.js";
interface PaseoConfig { interface PaseoConfig {
@@ -204,7 +205,7 @@ async function execSetupCommand(
const { stdout, stderr } = await execAsync(command, { const { stdout, stderr } = await execAsync(command, {
cwd: options.cwd, cwd: options.cwd,
env: options.env, env: options.env,
shell: "/bin/bash", ...(process.platform === "win32" ? {} : { shell: "/bin/bash" }),
}); });
return { return {
command, command,
@@ -275,7 +276,8 @@ async function execSetupCommandStreamed(options: {
cwd: options.cwd, cwd: options.cwd,
}); });
const child = spawn("/bin/bash", ["-lc", options.command], { const shell = platformBash();
const child = spawnProcess(shell.command, [...shell.flag, options.command], {
cwd: options.cwd, cwd: options.cwd,
env: options.env, env: options.env,
stdio: ["ignore", "pipe", "pipe"], stdio: ["ignore", "pipe", "pipe"],