diff --git a/src/tests/example.test.ts b/src/tests/example.test.ts index 6067fdb7..56846384 100644 --- a/src/tests/example.test.ts +++ b/src/tests/example.test.ts @@ -1,7 +1,72 @@ -import { describe, it, expect } from 'vitest'; +import { describe, it, expect, beforeAll, afterAll } from "vitest"; +import { spawn } from "child_process"; +import { + Agent, + AgentSideConnection, + Client, + ClientSideConnection, + ReadTextFileRequest, + ReadTextFileResponse, + RequestPermissionRequest, + RequestPermissionResponse, + SessionNotification, + WriteTextFileRequest, + WriteTextFileResponse, +} from "@zed-industries/agent-client-protocol"; +import { nodeToWebWritable, nodeToWebReadable } from "../utils.js"; -describe('Basic Test Example', () => { - it('should assert that false is true', () => { - expect(false).toBe(true); +describe("ACP subprocess integration", () => { + let child: ReturnType; + + beforeAll(async () => { + // Start the subprocess + child = spawn("npm", ["run", "dev"], { + stdio: ["pipe", "pipe", "pipe"], + env: process.env, + }); + }); + + afterAll(() => { + child.kill(); + }); + + class TestClient implements Client { + agent: Agent; + + constructor(agent: Agent) { + this.agent = agent; + } + requestPermission( + params: RequestPermissionRequest, + ): Promise { + throw new Error("Method not implemented."); + } + async sessionUpdate(params: SessionNotification): Promise { + console.log(params); + } + writeTextFile( + params: WriteTextFileRequest, + ): Promise { + throw new Error("Method not implemented."); + } + readTextFile(params: ReadTextFileRequest): Promise { + throw new Error("Method not implemented."); + } + } + + it("should connect to the ACP subprocess", async () => { + const connection = new ClientSideConnection( + (agent) => { + return new TestClient(agent); + }, + nodeToWebWritable(child.stdin!), + nodeToWebReadable(child.stdout!) as any, + ); + + let session = await connection.newSession({ cwd: "./", mcpServers: [] }); + await connection.prompt({ + prompt: [{ type: "text", text: "Hello Claude!" }], + sessionId: session.sessionId, + }); }); });