Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions server/comms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
// session/new mcpServers → agents-proxy → /api/internal/ask-bot →
// askBotAndWait → bus fold. The internal endpoints' auth is pinned too.
//
// The fake CLI is a shebang script, so the e2e half is POSIX-only (same
// gating as acp.test.ts); the mention-resolution unit tests run everywhere.
// The fake CLI is a shebang script — POSIX-only until resolveCliSpawn
// turned it into `node <script>` on Windows too, so the e2e half now runs
// everywhere alongside the mention-resolution units.
import { spawn, type ChildProcess } from "node:child_process";
import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
Expand All @@ -21,7 +22,6 @@ const SERVER_DIR = dirname(fileURLToPath(import.meta.url));
const FAKE_CLI = join(SERVER_DIR, "testing", "fake-acp-cli.ts");
const PORT = 18800 + Math.floor(Math.random() * 10_000);
const BASE = `http://127.0.0.1:${PORT}`;
const posixOnly = describe.skipIf(process.platform === "win32");

describe("mentionedBots", () => {
const peers = [
Expand All @@ -46,7 +46,7 @@ describe("mentionedBots", () => {
});
});

posixOnly("comms e2e (fake ACP fleet)", () => {
describe("comms e2e (fake ACP fleet)", () => {
let child: ChildProcess;
let home: string;
let stderr = "";
Expand Down Expand Up @@ -81,6 +81,8 @@ posixOnly("comms e2e (fake ACP fleet)", () => {
cwd: join(SERVER_DIR, ".."),
env: {
...(process.env.PATH ? { PATH: process.env.PATH } : {}),
// without SystemRoot, winsock fails to initialize in the child
...(process.env.SystemRoot ? { SystemRoot: process.env.SystemRoot } : {}),
HOME: home,
USERPROFILE: home,
OMB_PORT: String(PORT),
Expand Down
9 changes: 4 additions & 5 deletions server/drivers/acp/acp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// normalize the ACP handshake into canonical events, keep argv/env hygiene,
// broker permission asks, and settle interrupts/crashes cleanly.
//
// Spawn-based tests are POSIX-only until Windows CLI spawning lands (the fake
// CLI is a shebang script Windows cannot exec directly).
// The fake CLI is a shebang script Windows cannot exec directly —
// resolveCliSpawn turns it into `node <script>`, so these run everywhere.
import { chmodSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
Expand All @@ -19,7 +19,6 @@ import { GrokAgentDriver } from "./grok.ts";
import { GeminiAgentDriver } from "./gemini.ts";

const FAKE_CLI = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "testing", "fake-acp-cli.ts");
const posixOnly = describe.skipIf(process.platform === "win32");

describe("ACP decodeConfig", () => {
it("grok defaults to the grok binary", () => {
Expand All @@ -34,7 +33,7 @@ describe("ACP decodeConfig", () => {
});
});

posixOnly("ACP turns (fake CLI)", () => {
describe("ACP turns (fake CLI)", () => {
let instance: ProviderInstance;
let recorder: EventRecorder;
let scratch: string;
Expand Down Expand Up @@ -165,7 +164,7 @@ posixOnly("ACP turns (fake CLI)", () => {
});
});

describe.skipIf(process.platform === "win32")("ACP snapshot", () => {
describe("ACP snapshot", () => {
it("a missing binary is unavailable", async () => {
const instance = await GrokAgentDriver.create({
instanceId: "grok-missing",
Expand Down
14 changes: 10 additions & 4 deletions server/drivers/acp/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
SendTurnInput,
} from "../../contracts.ts";
import { newEventId, newId } from "../../contracts.ts";
import { augmentedPath } from "../../env-path.ts";
import { augmentedPath, resolveCliSpawn } from "../../env-path.ts";
import { appendNative } from "../native.ts";

export interface AcpConfig {
Expand Down Expand Up @@ -150,10 +150,12 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
const env = childEnv();
const mcpServers = acpMcpServers(turn);

const child = spawn(config.cli, support.spawnArgs(config, turn), {
const cli = resolveCliSpawn(config.cli, support.spawnArgs(config, turn));
const child = spawn(cli.command, cli.args, {
cwd,
env,
stdio: ["pipe", "pipe", "pipe"],
windowsVerbatimArguments: cli.windowsVerbatimArguments,
detached: true,
});

Expand Down Expand Up @@ -469,8 +471,12 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
const snapshot = async (): Promise<ProviderSnapshot> => {
const env = childEnv();
const version = await new Promise<string | null>((resolve) => {
execFile(config.cli, ["--version"], { timeout: 8000, env }, (err, stdout) =>
resolve(err ? null : stdout.trim()),
const cli = resolveCliSpawn(config.cli, ["--version"]);
execFile(
cli.command,
cli.args,
{ timeout: 8000, env, windowsVerbatimArguments: cli.windowsVerbatimArguments },
(err, stdout) => resolve(err ? null : stdout.trim()),
);
});
if (!version) return { state: "unavailable", reason: `\`${config.cli}\` CLI not found` };
Expand Down
30 changes: 23 additions & 7 deletions server/drivers/claude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";

import { DATA_DIR } from "../config.ts";
import { augmentedPath } from "../env-path.ts";
import { augmentedPath, resolveCliSpawn } from "../env-path.ts";

import type {
DriverCreateInput,
Expand Down Expand Up @@ -322,10 +322,13 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
delete env.CLAUDECODE;
delete env.CLAUDE_CODE_ENTRYPOINT;

const child = spawn(config.cli, args, {
// resolve npm shims / shebang scripts to a real spawn
const cli = resolveCliSpawn(config.cli, args);
const child = spawn(cli.command, cli.args, {
cwd: turn.cwd ?? homedir(),
env,
stdio: ["pipe", "pipe", "pipe"],
windowsVerbatimArguments: cli.windowsVerbatimArguments,
detached: true, // own process group: killing -pid reaps child MCP servers
});

Expand Down Expand Up @@ -469,8 +472,16 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {

const snapshot = async (): Promise<ProviderSnapshot> => {
const version = await new Promise<string | null>((resolve) => {
execFile(config.cli, ["--version"], { timeout: 8000, env: { ...process.env, PATH: augmentedPath() } }, (err, stdout) =>
resolve(err ? null : stdout.trim()),
const cli = resolveCliSpawn(config.cli, ["--version"]);
execFile(
cli.command,
cli.args,
{
timeout: 8000,
env: { ...process.env, PATH: augmentedPath() },
windowsVerbatimArguments: cli.windowsVerbatimArguments,
},
(err, stdout) => resolve(err ? null : stdout.trim()),
);
});
if (!version) return { state: "unavailable", reason: `\`${config.cli}\` CLI not found` };
Expand Down Expand Up @@ -509,10 +520,15 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
},
generateText: (prompt: string) =>
new Promise((resolve, reject) => {
const cli = resolveCliSpawn(config.cli, ["-p", prompt, "--model", "claude-haiku-4-5", "--output-format", "text"]);
execFile(
config.cli,
["-p", prompt, "--model", "claude-haiku-4-5", "--output-format", "text"],
{ timeout: 60_000, env: { ...process.env, PATH: augmentedPath() } },
cli.command,
cli.args,
{
timeout: 60_000,
env: { ...process.env, PATH: augmentedPath() },
windowsVerbatimArguments: cli.windowsVerbatimArguments,
},
(err, stdout) => (err ? reject(err) : resolve(stdout.trim())),
);
}),
Expand Down
7 changes: 3 additions & 4 deletions server/drivers/codex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// JSON-RPC handshake, normalize notifications into canonical events, and
// surface server->client approval requests as request.opened.
//
// Spawn-based tests are POSIX-only until Windows CLI spawning lands (the
// fake is a shebang script — same constraint as codex.cmd itself).
// The fake is a shebang script — the same constraint codex.cmd itself
// hits on Windows. resolveCliSpawn covers both, so these run everywhere.
import { chmodSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
Expand All @@ -16,7 +16,6 @@ import { recordEvents, type EventRecorder } from "../testing/events.ts";
import { CodexDriver } from "./codex.ts";

const FAKE_CLI = join(dirname(fileURLToPath(import.meta.url)), "..", "testing", "fake-codex-app-server.ts");
const posixOnly = describe.skipIf(process.platform === "win32");

describe("CodexDriver.decodeConfig", () => {
it("defaults to the codex binary with fullAuto off", () => {
Expand All @@ -28,7 +27,7 @@ describe("CodexDriver.decodeConfig", () => {
});
});

posixOnly("CodexDriver turns (fake app-server)", () => {
describe("CodexDriver turns (fake app-server)", () => {
let instance: ProviderInstance;
let recorder: EventRecorder;
let scratch: string;
Expand Down
18 changes: 14 additions & 4 deletions server/drivers/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
SendTurnInput,
} from "../contracts.ts";
import { newEventId, newId } from "../contracts.ts";
import { augmentedPath } from "../env-path.ts";
import { augmentedPath, resolveCliSpawn } from "../env-path.ts";
import { appendNative } from "./native.ts";

const DRIVER_KIND = "codex";
Expand Down Expand Up @@ -92,10 +92,12 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {
// billing to pay-as-you-go (agentcal)
delete env.OPENAI_API_KEY;

const child = spawn(config.cli, ["app-server"], {
const cli = resolveCliSpawn(config.cli, ["app-server"]);
const child = spawn(cli.command, cli.args, {
cwd: turn.cwd ?? homedir(),
env,
stdio: ["pipe", "pipe", "pipe"],
windowsVerbatimArguments: cli.windowsVerbatimArguments,
detached: true,
});

Expand Down Expand Up @@ -378,8 +380,16 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {

const snapshot = async (): Promise<ProviderSnapshot> => {
const version = await new Promise<string | null>((resolve) => {
execFile(config.cli, ["--version"], { timeout: 8000, env: { ...process.env, PATH: augmentedPath() } }, (err, stdout) =>
resolve(err ? null : stdout.trim()),
const cli = resolveCliSpawn(config.cli, ["--version"]);
execFile(
cli.command,
cli.args,
{
timeout: 8000,
env: { ...process.env, PATH: augmentedPath() },
windowsVerbatimArguments: cli.windowsVerbatimArguments,
},
(err, stdout) => resolve(err ? null : stdout.trim()),
);
});
if (!version) return { state: "unavailable", reason: `\`${config.cli}\` CLI not found` };
Expand Down
Loading