/** * TestEnvironment - Core test setup and lifecycle management for O-Network nodes * * Provides automatic cleanup, node factories, and common test utilities * to eliminate boilerplate in O-Network package tests. * * @example * ```typescript * describe('MyTool', () => { * const env = new TestEnvironment(); * * afterEach(async () => { * await env.cleanup(); * }); * * it('should work', async () => { * const { leader, tool } = await env.createToolWithLeader(MyTool); * expect(tool.state).to.equal(NodeState.RUNNING); * }); * }); * ``` */ import type { oNode, oNodeAddress } from '@olane/o-node'; /** * Node configuration for test environment */ export interface TestNodeConfig { address?: oNodeAddress; leader?: oNodeAddress | null; parent?: oNodeAddress | null; description?: string; [key: string]: any; } /** * Options for creating leader nodes */ export interface LeaderNodeOptions { address?: oNodeAddress; description?: string; autoStart?: boolean; } /** * Result of creating a tool with leader */ export interface ToolWithLeaderResult { leader: any; tool: T; } /** * Core test environment class for O-Network testing * * Manages node lifecycle, automatic cleanup, and provides * factory methods for common test scenarios. */ export declare class TestEnvironment { private nodes; private cleanupCallbacks; /** * Create a leader node for testing * * @param LeaderClass - Leader node class (e.g., oLeaderNode) * @param options - Configuration options * @returns Started leader node instance * * @example * ```typescript * const leader = await env.createLeader(oLeaderNode); * ``` */ createLeader(LeaderClass: new (config: any) => T, options?: LeaderNodeOptions): Promise; /** * Create a tool with a leader node * * Automatically handles: * - Leader creation and startup * - Tool creation with parent/leader references * - Hook injection for child registration * - Lifecycle tracking for cleanup * * @param ToolClass - Tool class to instantiate * @param config - Tool configuration * @param LeaderClass - Leader class (defaults to oLeaderNode if available) * @returns Object with leader and tool instances * * @example * ```typescript * const { leader, tool } = await env.createToolWithLeader(MyTool, { * apiKey: 'test-key' * }); * ``` */ createToolWithLeader(ToolClass: new (config: any) => T, config?: TestNodeConfig, LeaderClass?: new (config: any) => any): Promise>; /** * Create a simple node without leader * * @param NodeClass - Node class to instantiate * @param config - Node configuration * @param autoStart - Whether to start node automatically (default: true) * @returns Node instance * * @example * ```typescript * const node = await env.createNode(MyTool, { * address: new oNodeAddress('o://test') * }); * ``` */ createNode(NodeClass: new (config: any) => T, config?: TestNodeConfig, autoStart?: boolean): Promise; /** * Track a node for automatic cleanup * * @param node - Node instance to track * * @example * ```typescript * const node = new MyNode({}); * env.track(node); * await node.start(); * ``` */ track(node: oNode): void; /** * Register a cleanup callback * * Useful for cleaning up external resources (databases, files, etc.) * * @param callback - Async cleanup function * * @example * ```typescript * const db = await createTestDB(); * env.onCleanup(async () => { * await db.close(); * }); * ``` */ onCleanup(callback: () => Promise): void; /** * Stop all tracked nodes and execute cleanup callbacks * * Stops nodes in reverse order (children before parents) * Call this in afterEach hooks. * * @example * ```typescript * afterEach(async () => { * await env.cleanup(); * }); * ``` */ cleanup(): Promise; /** * Get all tracked nodes * * @returns Array of tracked node instances */ getNodes(): oNode[]; /** * Get count of tracked nodes * * @returns Number of tracked nodes */ getNodeCount(): number; /** * Check if all tracked nodes are stopped * * @returns True if all nodes are stopped */ allNodesStopped(): boolean; /** * Wait for a condition to be true * * @param condition - Function that returns true when condition is met * @param timeoutMs - Maximum time to wait in milliseconds (default: 5000) * @param intervalMs - Check interval in milliseconds (default: 100) * @returns Promise that resolves when condition is met or rejects on timeout * * @example * ```typescript * await env.waitFor(() => tool.isReady, 10000); * ``` */ waitFor(condition: () => boolean, timeoutMs?: number, intervalMs?: number): Promise; } //# sourceMappingURL=test-environment.d.ts.map