From ff293fd7f26c1477e2388839bb210a7302437152 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Mar 2026 04:14:01 +0000 Subject: [PATCH] =?UTF-8?q?test:=20warehouse=20connections=20=E2=80=94=20M?= =?UTF-8?q?ongoDB=20auth=20detection=20+=20env=20var=20loading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cover two untested registry paths: the new MongoDB/mongo detectAuthMethod branch (added this week with MongoDB driver support) and the ALTIMATE_CODE_CONN_* env var loading path used by CI/CD pipelines. Co-Authored-By: Claude Opus 4.6 (1M context) https://claude.ai/code/session_01QvuBUD1uLcEPSu6EugNcyf --- .../test/altimate/connections.test.ts | 49 +++++++++++++++++++ .../test/altimate/warehouse-telemetry.test.ts | 14 ++++++ 2 files changed, 63 insertions(+) diff --git a/packages/opencode/test/altimate/connections.test.ts b/packages/opencode/test/altimate/connections.test.ts index e5facc6db0..cd66ac828a 100644 --- a/packages/opencode/test/altimate/connections.test.ts +++ b/packages/opencode/test/altimate/connections.test.ts @@ -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) // --------------------------------------------------------------------------- diff --git a/packages/opencode/test/altimate/warehouse-telemetry.test.ts b/packages/opencode/test/altimate/warehouse-telemetry.test.ts index ccc7a4c13d..132dc11804 100644 --- a/packages/opencode/test/altimate/warehouse-telemetry.test.ts +++ b/packages/opencode/test/altimate/warehouse-telemetry.test.ts @@ -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") + }) }) // ---------------------------------------------------------------------------