/** * Gateway Testing Utilities * * Provides helpers for testing gateway interactions. * * @example * ```typescript * import { createTestGateway, createMockApp } from '@agentick/gateway/testing'; * * test('gateway handles messages', async () => { * const mockApp = createMockApp({ * response: 'Hello!', * }); * * const { gateway, client, cleanup } = await createTestGateway({ * agents: { chat: mockApp }, * defaultAgent: 'chat', * }); * * try { * const response = await client.send('main', 'Hi there'); * expect(response.payload.messageId).toBeDefined(); * } finally { * await cleanup(); * } * }); * ``` * * @module @agentick/gateway/testing */ import WebSocket from "ws"; import type { Gateway } from "./gateway.js"; import type { GatewayConfig, GatewayEvents, PluginContext } from "./types.js"; import type { ConfigStore } from "./config.js"; export { createMockApp, createMockSession, createMockExecutionHandle, createTestProcedure, type MockAppOptions, type MockSessionOptions, type MockSession, type MockApp, type MockSessionExecutionHandle, type MockExecutionHandleOptions, type TestProcedure, type TestProcedureOptions, } from "@agentick/core/testing"; export interface RegisteredMethod { handler: Function; roles?: string[]; } export interface MockPluginContextResult { ctx: PluginContext; /** Methods registered via ctx.registerMethod */ methods: Map; /** Event handlers registered via ctx.on */ events: Map; /** All registerMethod calls as [path, handlerOrDef] */ _registerMethodCalls: Array<[string, unknown]>; /** All invoke calls as [method, params] */ _invokeCalls: Array<[string, unknown]>; /** All broadcast calls as [event, data] */ _broadcastCalls: Array<[string, unknown]>; /** All registerRoute calls as [path, handler] */ _registerRouteCalls: Array<[string, Function]>; } export interface MockPluginContextOptions { gatewayId?: string; config?: Partial; } /** * Create a mock PluginContext for testing gateway plugins. * * Framework-agnostic — no vitest/jest dependency. Tracks calls via arrays * and populates methods/events maps for easy assertions. */ export declare function createMockPluginContext(options?: MockPluginContextOptions): MockPluginContextResult; export interface TestGatewayOptions extends Omit { /** Custom port (default: random available port) */ port?: number; } export interface TestGatewayClient { /** Send a request to the gateway */ request(method: string, params?: Record): Promise<{ ok: boolean; payload?: T; error?: { code: string; message: string; }; }>; /** Send a message to a session */ send(sessionId: string, message: string): Promise<{ ok: boolean; payload?: { messageId: string; }; error?: { code: string; message: string; }; }>; /** Collect events for a session */ collectEvents(sessionId: string, timeout?: number): Promise>; /** Close the client connection */ close(): void; /** The raw WebSocket */ ws: WebSocket; } export interface TestGatewayResult { /** The gateway instance */ gateway: Gateway; /** A connected test client */ client: TestGatewayClient; /** Gateway URL */ url: string; /** Port the gateway is running on */ port: number; /** Clean up resources */ cleanup: () => Promise; } /** * Create a test gateway with a connected client. * * Automatically handles port allocation, client connection, and cleanup. */ export declare function createTestGateway(options: TestGatewayOptions): Promise; /** * Wait for a specific gateway event. */ export declare function waitForGatewayEvent(gateway: Gateway, event: K, timeout?: number): Promise; //# sourceMappingURL=testing.d.ts.map