Files
oh-my-pi/packages/coding-agent/test/mcp-test-utils.ts
T
can1357 6357b245a5 fix: corrected resource tracking and context cleanup across MCP and virtualization layers
- Fixed resource refresh tracking by storing connection references alongside promises to prevent stale deduplication.
- Fixed update target resolution to explicitly handle missing ompPath and use path.resolve() for consistent normalization.
- Added error handling and logging in Smithery registry detail fetching to gracefully handle failures and track issues.
- Fixed virtualization context cleanup in error paths to prevent partially-started instances from remaining active.
- Fixed API key retrieval to use dynamic provider configuration instead of hardcoded provider string.
- Enhanced test utilities to capture and verify request parameters for improved test coverage and debugging.
2026-03-03 06:07:22 +01:00

37 lines
1.1 KiB
TypeScript

import type { MCPServerCapabilities, MCPServerConnection, MCPTransport } from "../src/mcp/types";
export function createMockTransport(
responses: Map<string, unknown[]>,
onRequest?: (method: string, params: Record<string, unknown> | undefined) => void,
): MCPTransport {
const callCounts = new Map<string, number>();
return {
connected: true,
async request<T>(method: string, params?: Record<string, unknown>): Promise<T> {
onRequest?.(method, params);
const count = callCounts.get(method) ?? 0;
callCounts.set(method, count + 1);
const queue = responses.get(method);
if (!queue || count >= queue.length) {
throw new Error(`No mock response for ${method} call #${count}`);
}
return queue[count] as T;
},
async notify() {},
async close() {},
};
}
export function createMockConnection(
capabilities: MCPServerCapabilities,
transport: MCPTransport,
): MCPServerConnection {
return {
name: "test-server",
config: { type: "stdio" as const, command: "echo" },
transport,
serverInfo: { name: "test", version: "1.0" },
capabilities,
};
}