From 1697954b4f7b767f6d4fdea176494008585e20b5 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Mar 2026 11:11:22 +0000 Subject: [PATCH] =?UTF-8?q?test:=20MongoDB=20driver=20=E2=80=94=20normaliz?= =?UTF-8?q?eConfig=20aliases=20and=20detectAuthMethod=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MongoDB support was added in v0.5.13 (commit abcaa1d) but the normalize alias map and auth detection had zero test coverage, risking silent connection failures for users configuring MongoDB with dbt/SDK-style field names. Co-Authored-By: Claude Opus 4.6 (1M context) https://claude.ai/code/session_01U7mUcNzrnXfdtJSJxVTuQv --- .../test/altimate/driver-normalize.test.ts | 120 ++++++++++++++++++ .../test/altimate/telemetry-safety.test.ts | 5 + 2 files changed, 125 insertions(+) diff --git a/packages/opencode/test/altimate/driver-normalize.test.ts b/packages/opencode/test/altimate/driver-normalize.test.ts index f437e1187c..caf7b20679 100644 --- a/packages/opencode/test/altimate/driver-normalize.test.ts +++ b/packages/opencode/test/altimate/driver-normalize.test.ts @@ -648,6 +648,126 @@ describe("normalizeConfig — DuckDB/SQLite passthrough", () => { }) }) +// --------------------------------------------------------------------------- +// normalizeConfig — MongoDB +// --------------------------------------------------------------------------- + +describe("normalizeConfig — MongoDB", () => { + test("connectionString → connection_string for mongodb", () => { + const result = normalizeConfig({ + type: "mongodb", + connectionString: "mongodb://localhost:27017/mydb", + }) + expect(result.connection_string).toBe("mongodb://localhost:27017/mydb") + expect(result.connectionString).toBeUndefined() + }) + + test("uri → connection_string for mongodb", () => { + const result = normalizeConfig({ + type: "mongodb", + uri: "mongodb://localhost:27017/mydb", + }) + expect(result.connection_string).toBe("mongodb://localhost:27017/mydb") + expect(result.uri).toBeUndefined() + }) + + test("url → connection_string for mongodb", () => { + const result = normalizeConfig({ + type: "mongodb", + url: "mongodb+srv://cluster0.example.net/mydb", + }) + expect(result.connection_string).toBe("mongodb+srv://cluster0.example.net/mydb") + expect(result.url).toBeUndefined() + }) + + test("authSource → auth_source for mongodb", () => { + const result = normalizeConfig({ + type: "mongodb", + host: "localhost", + authSource: "admin", + }) + expect(result.auth_source).toBe("admin") + expect(result.authSource).toBeUndefined() + }) + + test("replicaSet → replica_set for mongodb", () => { + const result = normalizeConfig({ + type: "mongodb", + host: "localhost", + replicaSet: "rs0", + }) + expect(result.replica_set).toBe("rs0") + expect(result.replicaSet).toBeUndefined() + }) + + test("directConnection → direct_connection for mongodb", () => { + const result = normalizeConfig({ + type: "mongodb", + host: "localhost", + directConnection: true, + }) + expect(result.direct_connection).toBe(true) + expect(result.directConnection).toBeUndefined() + }) + + test("connectTimeoutMS → connect_timeout for mongodb", () => { + const result = normalizeConfig({ + type: "mongodb", + host: "localhost", + connectTimeoutMS: 5000, + }) + expect(result.connect_timeout).toBe(5000) + expect(result.connectTimeoutMS).toBeUndefined() + }) + + test("serverSelectionTimeoutMS → server_selection_timeout for mongodb", () => { + const result = normalizeConfig({ + type: "mongodb", + host: "localhost", + serverSelectionTimeoutMS: 15000, + }) + expect(result.server_selection_timeout).toBe(15000) + expect(result.serverSelectionTimeoutMS).toBeUndefined() + }) + + test("mongo type alias works", () => { + const result = normalizeConfig({ + type: "mongo", + uri: "mongodb://localhost:27017", + authSource: "admin", + }) + expect(result.connection_string).toBe("mongodb://localhost:27017") + expect(result.auth_source).toBe("admin") + expect(result.uri).toBeUndefined() + expect(result.authSource).toBeUndefined() + }) + + test("resolves multiple aliases in a single config", () => { + const result = normalizeConfig({ + type: "mongodb", + uri: "mongodb://localhost:27017/mydb", + authSource: "admin", + replicaSet: "rs0", + directConnection: false, + connectTimeoutMS: 5000, + serverSelectionTimeoutMS: 15000, + }) + expect(result.connection_string).toBe("mongodb://localhost:27017/mydb") + expect(result.auth_source).toBe("admin") + expect(result.replica_set).toBe("rs0") + expect(result.direct_connection).toBe(false) + expect(result.connect_timeout).toBe(5000) + expect(result.server_selection_timeout).toBe(15000) + // All aliases removed + expect(result.uri).toBeUndefined() + expect(result.authSource).toBeUndefined() + expect(result.replicaSet).toBeUndefined() + expect(result.directConnection).toBeUndefined() + expect(result.connectTimeoutMS).toBeUndefined() + expect(result.serverSelectionTimeoutMS).toBeUndefined() + }) +}) + // --------------------------------------------------------------------------- // normalizeConfig — Snowflake private_key edge cases // --------------------------------------------------------------------------- diff --git a/packages/opencode/test/altimate/telemetry-safety.test.ts b/packages/opencode/test/altimate/telemetry-safety.test.ts index c268047ed0..a4fd78ba3f 100644 --- a/packages/opencode/test/altimate/telemetry-safety.test.ts +++ b/packages/opencode/test/altimate/telemetry-safety.test.ts @@ -59,6 +59,11 @@ describe("Telemetry Safety: Helper functions never throw", () => { expect(detectAuthMethod({ type: "duckdb" })).toBe("file") expect(detectAuthMethod({ type: "sqlite" })).toBe("file") expect(detectAuthMethod({ type: "postgres" })).toBe("unknown") + // MongoDB auth detection + expect(detectAuthMethod({ type: "mongodb", connection_string: "mongodb://localhost" })).toBe("connection_string") + expect(detectAuthMethod({ type: "mongodb", password: "secret" })).toBe("password") + expect(detectAuthMethod({ type: "mongodb" })).toBe("connection_string") + expect(detectAuthMethod({ type: "mongo" })).toBe("connection_string") // Edge cases expect(detectAuthMethod({} as any)).toBe("unknown") expect(detectAuthMethod({ type: "" })).toBe("unknown")