Skip to content

Commit 728feb2

Browse files
committed
test: MongoDB config normalization — alias resolution coverage
MongoDB was added in #482 but normalizeConfig() lacked any MongoDB-specific tests. These 11 tests verify that common field name aliases (uri, url, connectionString, authSource, replicaSet, directConnection, username, dbname, timeout fields) are correctly resolved to their canonical snake_case names, preventing silent connection failures when users provide MongoDB config from dbt profiles, MongoDB docs, or LLM-generated output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> https://claude.ai/code/session_01UtQ9rqYTKybuvdu6bM4cTj
1 parent abcaa1d commit 728feb2

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

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

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,3 +663,100 @@ describe("normalizeConfig — Snowflake private_key edge cases", () => {
663663
expect(result.private_key_path).toBeUndefined()
664664
})
665665
})
666+
667+
// ---------------------------------------------------------------------------
668+
// normalizeConfig — MongoDB aliases
669+
// ---------------------------------------------------------------------------
670+
671+
describe("normalizeConfig — MongoDB aliases", () => {
672+
test("connection_string alias: uri", () => {
673+
const config = { type: "mongodb", uri: "mongodb://localhost:27017/mydb" }
674+
const result = normalizeConfig(config)
675+
expect(result.connection_string).toBe("mongodb://localhost:27017/mydb")
676+
expect(result).not.toHaveProperty("uri")
677+
})
678+
679+
test("connection_string alias: url", () => {
680+
const config = { type: "mongodb", url: "mongodb://localhost:27017/mydb" }
681+
const result = normalizeConfig(config)
682+
expect(result.connection_string).toBe("mongodb://localhost:27017/mydb")
683+
expect(result).not.toHaveProperty("url")
684+
})
685+
686+
test("connection_string alias: connectionString (camelCase)", () => {
687+
const config = { type: "mongodb", connectionString: "mongodb://localhost:27017/mydb" }
688+
const result = normalizeConfig(config)
689+
expect(result.connection_string).toBe("mongodb://localhost:27017/mydb")
690+
expect(result).not.toHaveProperty("connectionString")
691+
})
692+
693+
test("canonical connection_string takes precedence over aliases", () => {
694+
const config = {
695+
type: "mongodb",
696+
connection_string: "mongodb://primary:27017",
697+
uri: "mongodb://secondary:27017",
698+
}
699+
const result = normalizeConfig(config)
700+
expect(result.connection_string).toBe("mongodb://primary:27017")
701+
expect(result).not.toHaveProperty("uri")
702+
})
703+
704+
test("auth_source alias: authSource", () => {
705+
const config = { type: "mongodb", host: "localhost", authSource: "admin" }
706+
const result = normalizeConfig(config)
707+
expect(result.auth_source).toBe("admin")
708+
expect(result).not.toHaveProperty("authSource")
709+
})
710+
711+
test("replica_set alias: replicaSet", () => {
712+
const config = { type: "mongodb", host: "localhost", replicaSet: "rs0" }
713+
const result = normalizeConfig(config)
714+
expect(result.replica_set).toBe("rs0")
715+
expect(result).not.toHaveProperty("replicaSet")
716+
})
717+
718+
test("direct_connection alias: directConnection", () => {
719+
const config = { type: "mongodb", host: "localhost", directConnection: true }
720+
const result = normalizeConfig(config)
721+
expect(result.direct_connection).toBe(true)
722+
expect(result).not.toHaveProperty("directConnection")
723+
})
724+
725+
test("common aliases: username → user, dbname → database", () => {
726+
const config = { type: "mongodb", host: "localhost", username: "admin", dbname: "mydb" }
727+
const result = normalizeConfig(config)
728+
expect(result.user).toBe("admin")
729+
expect(result.database).toBe("mydb")
730+
expect(result).not.toHaveProperty("username")
731+
expect(result).not.toHaveProperty("dbname")
732+
})
733+
734+
test("type alias: 'mongo' resolves same as 'mongodb'", () => {
735+
const config = { type: "mongo", uri: "mongodb://localhost:27017" }
736+
const result = normalizeConfig(config)
737+
expect(result.connection_string).toBe("mongodb://localhost:27017")
738+
expect(result).not.toHaveProperty("uri")
739+
})
740+
741+
test("timeout aliases: connectTimeoutMS → connect_timeout, serverSelectionTimeoutMS → server_selection_timeout", () => {
742+
const config = { type: "mongodb", host: "localhost", connectTimeoutMS: 5000, serverSelectionTimeoutMS: 10000 }
743+
const result = normalizeConfig(config)
744+
expect(result.connect_timeout).toBe(5000)
745+
expect(result.server_selection_timeout).toBe(10000)
746+
expect(result).not.toHaveProperty("connectTimeoutMS")
747+
expect(result).not.toHaveProperty("serverSelectionTimeoutMS")
748+
})
749+
750+
test("alias priority: connectionString beats uri when both present", () => {
751+
const config = {
752+
type: "mongodb",
753+
connectionString: "mongodb://first:27017",
754+
uri: "mongodb://second:27017",
755+
}
756+
const result = normalizeConfig(config)
757+
// connectionString is listed first in MONGODB_ALIASES, so it wins
758+
expect(result.connection_string).toBe("mongodb://first:27017")
759+
expect(result).not.toHaveProperty("connectionString")
760+
expect(result).not.toHaveProperty("uri")
761+
})
762+
})

0 commit comments

Comments
 (0)