From 8aa4f8f74a03d5ca13d1194c29a6341228715cce Mon Sep 17 00:00:00 2001 From: Kevin Messiaen <114553769+kevinmessiaen@users.noreply.github.com> Date: Mon, 6 Jul 2026 16:30:56 +0700 Subject: [PATCH] fix(test): exercise mongoQuery wrong-driver guard, not assertConnection The wrong-driver test's fake createConnector ignored the requested id and always returned a mongodb connector, so the driver guard never ran; the rejection came incidentally from assertConnection deep in the connector. It also asserted KtxQueryError, but the guard throws KtxExpectedError. Dispatch the fake by id and assert the guard's own error type and message. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01BdUJSmjqGoksdc45ZZJiVY --- .../cli/test/mcp/mongo-query-tool.test.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/cli/test/mcp/mongo-query-tool.test.ts b/packages/cli/test/mcp/mongo-query-tool.test.ts index 4d316baf..ee9f788a 100644 --- a/packages/cli/test/mcp/mongo-query-tool.test.ts +++ b/packages/cli/test/mcp/mongo-query-tool.test.ts @@ -1,8 +1,9 @@ import { describe, expect, it, vi } from 'vitest'; -import { KtxQueryError } from '../../src/errors.js'; +import { KtxExpectedError } from '../../src/errors.js'; import { KtxMongoDbScanConnector } from '../../src/connectors/mongodb/connector.js'; import { createLocalProjectMcpContextPorts } from '../../src/context/mcp/local-project-ports.js'; import type { KtxLocalProject } from '../../src/context/project/project.js'; +import type { KtxScanConnector } from '../../src/context/scan/types.js'; const MONGO_DOCS = [ { _id: 'a1', city: 'Indianapolis' }, @@ -38,7 +39,18 @@ function project(): KtxLocalProject { } as unknown as KtxLocalProject; } -function portsFor(createConnector: (id: string) => KtxMongoDbScanConnector) { +function warehouseConnector(): KtxScanConnector { + return { + id: 'postgres:warehouse', + driver: 'postgres', + capabilities: { structuralIntrospection: true } as KtxScanConnector['capabilities'], + introspect: vi.fn(), + listSchemas: vi.fn(async () => []), + listTables: vi.fn(async () => []), + } as unknown as KtxScanConnector; +} + +function portsFor(createConnector: (id: string) => KtxScanConnector) { return createLocalProjectMcpContextPorts(project(), { embeddingService: null, localScan: { createConnector } as never, @@ -58,10 +70,13 @@ describe('mongoQuery MCP port', () => { expect(result.rowCount).toBe(2); }); - it('rejects a non-mongodb connection id as an expected query error', async () => { - const ports = portsFor(() => mongoConnector()); + it('rejects a non-mongodb connection id with an expected error naming the wrong driver', async () => { + const ports = portsFor((id) => (id === 'mongo' ? mongoConnector() : warehouseConnector())); await expect( ports.mongoQuery!.execute({ connectionId: 'warehouse', collection: 'x', pipeline: [], limit: 10 }), - ).rejects.toBeInstanceOf(KtxQueryError); + ).rejects.toThrow(/is not a MongoDB connection/); + await expect( + ports.mongoQuery!.execute({ connectionId: 'warehouse', collection: 'x', pipeline: [], limit: 10 }), + ).rejects.toBeInstanceOf(KtxExpectedError); }); });