Skip to content

Commit 7a7e5d1

Browse files
committed
test: MongoDB normalization + detectAuthMethod coverage
MongoDB driver (PR #482) had zero unit tests for config alias normalization (uri, url, authSource, etc.) and auth method detection in telemetry. These tests prevent silent config failures for MongoDB users using common alias field names and ensure telemetry correctly categorizes auth methods for all driver types including the new MongoDB and file-based drivers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent abcaa1d commit 7a7e5d1

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

packages/opencode/test/altimate/connections.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ afterAll(() => { delete process.env.ALTIMATE_TELEMETRY_DISABLED })
1010
// ---------------------------------------------------------------------------
1111

1212
import * as Registry from "../../src/altimate/native/connections/registry"
13+
import { detectAuthMethod } from "../../src/altimate/native/connections/registry"
1314
import * as CredentialStore from "../../src/altimate/native/connections/credential-store"
1415
import { parseDbtProfiles } from "../../src/altimate/native/connections/dbt-profiles"
1516
import { discoverContainers } from "../../src/altimate/native/connections/docker-discovery"
@@ -137,6 +138,69 @@ describe("CredentialStore", () => {
137138
})
138139
})
139140

141+
// ---------------------------------------------------------------------------
142+
// detectAuthMethod
143+
// ---------------------------------------------------------------------------
144+
145+
describe("detectAuthMethod", () => {
146+
test("returns 'connection_string' for config with connection_string", () => {
147+
expect(detectAuthMethod({ type: "postgres", connection_string: "postgresql://..." } as any)).toBe("connection_string")
148+
})
149+
150+
test("returns 'key_pair' for Snowflake private_key_path", () => {
151+
expect(detectAuthMethod({ type: "snowflake", private_key_path: "/path/to/key.p8" } as any)).toBe("key_pair")
152+
})
153+
154+
test("returns 'key_pair' for camelCase privateKeyPath", () => {
155+
expect(detectAuthMethod({ type: "snowflake", privateKeyPath: "/path/to/key.p8" } as any)).toBe("key_pair")
156+
})
157+
158+
test("returns 'sso' for Snowflake externalbrowser", () => {
159+
expect(detectAuthMethod({ type: "snowflake", authenticator: "EXTERNALBROWSER" } as any)).toBe("sso")
160+
})
161+
162+
test("returns 'sso' for Okta URL authenticator", () => {
163+
expect(detectAuthMethod({ type: "snowflake", authenticator: "https://myorg.okta.com" } as any)).toBe("sso")
164+
})
165+
166+
test("returns 'oauth' for OAuth authenticator", () => {
167+
expect(detectAuthMethod({ type: "snowflake", authenticator: "OAUTH" } as any)).toBe("oauth")
168+
})
169+
170+
test("returns 'token' for access_token", () => {
171+
expect(detectAuthMethod({ type: "databricks", access_token: "dapi..." } as any)).toBe("token")
172+
})
173+
174+
test("returns 'password' for config with password", () => {
175+
expect(detectAuthMethod({ type: "postgres", password: "secret" } as any)).toBe("password")
176+
})
177+
178+
test("returns 'file' for duckdb", () => {
179+
expect(detectAuthMethod({ type: "duckdb", path: "/data/my.db" } as any)).toBe("file")
180+
})
181+
182+
test("returns 'file' for sqlite", () => {
183+
expect(detectAuthMethod({ type: "sqlite", path: "/data/my.sqlite" } as any)).toBe("file")
184+
})
185+
186+
test("returns 'connection_string' for mongodb without password", () => {
187+
expect(detectAuthMethod({ type: "mongodb" } as any)).toBe("connection_string")
188+
})
189+
190+
test("returns 'password' for mongo with password", () => {
191+
expect(detectAuthMethod({ type: "mongo", password: "secret" } as any)).toBe("password")
192+
})
193+
194+
test("returns 'unknown' for null/undefined", () => {
195+
expect(detectAuthMethod(null)).toBe("unknown")
196+
expect(detectAuthMethod(undefined)).toBe("unknown")
197+
})
198+
199+
test("returns 'unknown' for empty config with no identifiable auth", () => {
200+
expect(detectAuthMethod({ type: "postgres" } as any)).toBe("unknown")
201+
})
202+
})
203+
140204
// ---------------------------------------------------------------------------
141205
// dbt profiles parser
142206
// ---------------------------------------------------------------------------

packages/opencode/test/altimate/driver-normalize.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,55 @@ describe("normalizeConfig — DuckDB/SQLite passthrough", () => {
652652
// normalizeConfig — Snowflake private_key edge cases
653653
// ---------------------------------------------------------------------------
654654

655+
// ---------------------------------------------------------------------------
656+
// normalizeConfig — MongoDB aliases
657+
// ---------------------------------------------------------------------------
658+
659+
describe("normalizeConfig — MongoDB", () => {
660+
test("connectionString → connection_string", () => {
661+
const config = { type: "mongodb", connectionString: "mongodb://localhost:27017/mydb" }
662+
const result = normalizeConfig(config)
663+
expect(result.connection_string).toBe("mongodb://localhost:27017/mydb")
664+
expect(result.connectionString).toBeUndefined()
665+
})
666+
667+
test("uri → connection_string", () => {
668+
const config = { type: "mongodb", uri: "mongodb://localhost:27017/mydb" }
669+
const result = normalizeConfig(config)
670+
expect(result.connection_string).toBe("mongodb://localhost:27017/mydb")
671+
expect(result.uri).toBeUndefined()
672+
})
673+
674+
test("url → connection_string", () => {
675+
const config = { type: "mongodb", url: "mongodb+srv://user:pass@cluster.mongodb.net/db" }
676+
const result = normalizeConfig(config)
677+
expect(result.connection_string).toBe("mongodb+srv://user:pass@cluster.mongodb.net/db")
678+
expect(result.url).toBeUndefined()
679+
})
680+
681+
test("canonical connection_string takes precedence over uri alias", () => {
682+
const config = { type: "mongodb", connection_string: "mongodb://primary", uri: "mongodb://fallback" }
683+
const result = normalizeConfig(config)
684+
expect(result.connection_string).toBe("mongodb://primary")
685+
expect(result.uri).toBeUndefined()
686+
})
687+
688+
test("mongo type alias resolves MongoDB-specific aliases", () => {
689+
const config = { type: "mongo", uri: "mongodb://localhost:27017/test", authSource: "admin" }
690+
const result = normalizeConfig(config)
691+
expect(result.connection_string).toBe("mongodb://localhost:27017/test")
692+
expect(result.auth_source).toBe("admin")
693+
expect(result.authSource).toBeUndefined()
694+
})
695+
696+
test("authSource → auth_source", () => {
697+
const config = { type: "mongodb", host: "localhost", authSource: "admin" }
698+
const result = normalizeConfig(config)
699+
expect(result.auth_source).toBe("admin")
700+
expect(result.authSource).toBeUndefined()
701+
})
702+
})
703+
655704
describe("normalizeConfig — Snowflake private_key edge cases", () => {
656705
test("opaque string without path indicators stays as private_key", () => {
657706
const result = normalizeConfig({

0 commit comments

Comments
 (0)