(opts: {
scope?: "account" | "agent";
agentAddress?: string;
whoamiThrows?: boolean | "unauthorized";
})
| 341 | // requests of the same connection skip the probe, so whoami runs once. |
| 342 | |
| 343 | function makeProbeClient(opts: { |
| 344 | scope?: "account" | "agent"; |
| 345 | agentAddress?: string; |
| 346 | whoamiThrows?: boolean | "unauthorized"; |
| 347 | }): McpClient { |
| 348 | return { |
| 349 | agentEmail: "", |
| 350 | scope: opts.scope ?? "account", |
| 351 | whoami: vi.fn(async () => { |
| 352 | if (opts.whoamiThrows === "unauthorized") throw makeHttpError(401); |
| 353 | if (opts.whoamiThrows) throw new Error("upstream 500"); |
| 354 | return { |
| 355 | user: "owner@example.com", |
| 356 | scope: opts.scope ?? "account", |
| 357 | agentAddress: opts.agentAddress, |
| 358 | }; |
| 359 | }), |
| 360 | listMessages: vi.fn(async () => ({ items: [], next_cursor: undefined })), |
| 361 | listAgents: vi.fn(async () => []), |
| 362 | } as unknown as McpClient; |
| 363 | } |
| 364 | |
| 365 | async function startWithFactory( |
| 366 | factory: (bearer: string, o?: { agentEmail?: string; scope?: string }) => McpClient, |
no test coverage detected