|
| 1 | +import { describe, expect, test } from "bun:test" |
| 2 | +import { ACP } from "../../src/acp/agent" |
| 3 | +import type { Agent as ACPAgent } from "@agentclientprotocol/sdk" |
| 4 | + |
| 5 | +/** |
| 6 | + * Type-level test: This line will fail to compile if ACP.Agent |
| 7 | + * doesn't properly implement the ACPAgent interface. |
| 8 | + * |
| 9 | + * The SDK checks for methods like `agent.unstable_setSessionModel` at runtime |
| 10 | + * and throws "Method not found" if they're missing. TypeScript allows optional |
| 11 | + * interface methods to be omitted, but the SDK still expects them. |
| 12 | + * |
| 13 | + * @see https://github.com/agentclientprotocol/typescript-sdk/commit/7072d3f |
| 14 | + */ |
| 15 | +type _AssertAgentImplementsACPAgent = ACP.Agent extends ACPAgent ? true : never |
| 16 | +const _typeCheck: _AssertAgentImplementsACPAgent = true |
| 17 | + |
| 18 | +/** |
| 19 | + * Runtime verification that optional methods the SDK expects are actually implemented. |
| 20 | + * The SDK's router checks `if (!agent.methodName)` and throws MethodNotFound if missing. |
| 21 | + */ |
| 22 | +describe("acp.agent interface compliance", () => { |
| 23 | + // Extract method names from the ACPAgent interface type |
| 24 | + type ACPAgentMethods = keyof ACPAgent |
| 25 | + |
| 26 | + // Methods that the SDK's router explicitly checks for at runtime |
| 27 | + const sdkCheckedMethods: ACPAgentMethods[] = [ |
| 28 | + // Required |
| 29 | + "initialize", |
| 30 | + "newSession", |
| 31 | + "prompt", |
| 32 | + "cancel", |
| 33 | + // Optional but checked by SDK router |
| 34 | + "loadSession", |
| 35 | + "setSessionMode", |
| 36 | + "authenticate", |
| 37 | + // Unstable - SDK checks these with unstable_ prefix |
| 38 | + "unstable_listSessions", |
| 39 | + "unstable_forkSession", |
| 40 | + "unstable_resumeSession", |
| 41 | + "unstable_setSessionModel", |
| 42 | + ] |
| 43 | + |
| 44 | + test("Agent implements all SDK-checked methods", () => { |
| 45 | + for (const method of sdkCheckedMethods) { |
| 46 | + expect(typeof ACP.Agent.prototype[method as keyof typeof ACP.Agent.prototype], `Missing method: ${method}`).toBe( |
| 47 | + "function", |
| 48 | + ) |
| 49 | + } |
| 50 | + }) |
| 51 | +}) |
0 commit comments