import assert from "node:assert/strict"; import { execFile } from "node:child_process"; import { mkdir, mkdtemp } from "node:fs/promises"; import { promisify } from "node:util"; import { tmpdir } from "node:os"; import { join } from "node:path"; import test from "node:test"; import { startBridgeService } from "../src/bridge/service.js"; const execFileAsync = promisify(execFile); test("executes an approved bridge request through the local client CLI", async () => { const root = await mkdtemp(join(tmpdir(), "pi-status-bridge-cli-")); const home = join(root, "home"); await mkdir(home); const service = await startBridgeService({ homeWorktree: home, runtimeDir: join(root, "runtime"), sessionRoot: join(root, "sessions"), startAdapter: () => ({ send: async () => ({ type: "response", success: true }), respondToExtension: () => {}, stop: async () => {}, }), }); try { const { stdout } = await execFileAsync( process.execPath, [ "src/client/cli.js", "--socket", service.socketPath, "request", '{"op":"list_agents"}', ], { cwd: process.cwd() }, ); const result = JSON.parse(stdout); assert.equal(result.agents.length, 1); assert.equal(result.agents[0].worktreePath, home); } finally { await service.close(); } });