Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions packages/opencode/test/altimate/connections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,55 @@ describe("ConnectionRegistry", () => {
})
})

// ---------------------------------------------------------------------------
// loadFromEnv — env var connection parsing (ALTIMATE_CODE_CONN_*)
// ---------------------------------------------------------------------------

describe("ConnectionRegistry: loadFromEnv", () => {
beforeEach(() => {
Registry.reset()
})

test("loads connection from ALTIMATE_CODE_CONN_* env var", () => {
process.env.ALTIMATE_CODE_CONN_TESTPG = JSON.stringify({
type: "postgres",
host: "localhost",
database: "ci_db",
})
try {
Registry.load()
// Env var suffix is lowercased: TESTPG → "testpg"
const config = Registry.getConfig("testpg")
expect(config).toBeDefined()
expect(config?.type).toBe("postgres")
expect(config?.host).toBe("localhost")
expect(config?.database).toBe("ci_db")
} finally {
delete process.env.ALTIMATE_CODE_CONN_TESTPG
}
})

test("ignores env var with invalid JSON", () => {
process.env.ALTIMATE_CODE_CONN_BAD = "not-valid-json"
try {
Registry.load()
expect(Registry.getConfig("bad")).toBeUndefined()
} finally {
delete process.env.ALTIMATE_CODE_CONN_BAD
}
})

test("ignores env var with missing type field", () => {
process.env.ALTIMATE_CODE_CONN_NOTYPE = JSON.stringify({ host: "localhost" })
try {
Registry.load()
expect(Registry.getConfig("notype")).toBeUndefined()
} finally {
delete process.env.ALTIMATE_CODE_CONN_NOTYPE
}
})
})

// ---------------------------------------------------------------------------
// CredentialStore (keytar not available in test environment)
// ---------------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions packages/opencode/test/altimate/warehouse-telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ describe("warehouse telemetry: detectAuthMethod", () => {
expect(connectEvent).toBeDefined()
expect(connectEvent.auth_method).toBe("unknown")
})

// MongoDB-specific branch (added with MongoDB driver support).
// Without this branch, { type: "mongodb" } with no password would return
// "unknown" instead of "connection_string".
test("detects MongoDB connection_string fallback (no password)", () => {
// Direct call — no password, no connection_string field, so only the
// type-specific branch at line 229 can produce "connection_string".
expect(Registry.detectAuthMethod({ type: "mongodb", host: "localhost" } as any)).toBe("connection_string")
})

test("detects mongo alias connection_string fallback", () => {
// Verifies the `|| t === "mongo"` half of the OR condition.
expect(Registry.detectAuthMethod({ type: "mongo", host: "localhost" } as any)).toBe("connection_string")
})
})

// ---------------------------------------------------------------------------
Expand Down
Loading