test: warehouse connections — env-var loading and MongoDB auth detection#490
test: warehouse connections — env-var loading and MongoDB auth detection#490anandgupta42 wants to merge 1 commit intomainfrom
Conversation
Cover two untested code paths in the connection registry: 1. ALTIMATE_CODE_CONN_* env var parsing (CI/Docker users) 2. MongoDB-specific detectAuthMethod branches added in #482 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> https://claude.ai/code/session_015egWH6W5HdaVuMysv9tFHq
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
📝 WalkthroughWalkthroughTwo test files are enhanced with expanded unit test coverage: Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/opencode/test/altimate/connections.test.ts (1)
84-87: Capture original env value only once insetEnv.At Line 85, repeated calls with the same key in one test would overwrite the true original value and make restoration inaccurate. Consider guarding the first snapshot only.
♻️ Suggested tweak
function setEnv(key: string, value: string) { - saved[key] = process.env[key] + if (!(key in saved)) saved[key] = process.env[key] process.env[key] = value }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opencode/test/altimate/connections.test.ts` around lines 84 - 87, The setEnv helper currently overwrites saved[key] each time it's called, losing the true original environment value; modify setEnv (the function named setEnv) to only capture and store process.env[key] into saved[key] if saved[key] is undefined (i.e., guard the assignment so the original value is preserved on the first call), then set process.env[key] to the new value as before so tearDown/restore logic can accurately restore the original.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/opencode/test/altimate/warehouse-telemetry.test.ts`:
- Around line 186-188: The test for Registry.detectAuthMethod currently doesn't
distinguish the explicit connection_string branch from the MongoDB fallback
because the input lacks a password so both return "connection_string"; update
the test case used in the "prefers explicit connection_string field over mongodb
type fallback" test to include a password field (e.g., add password: "x") so
that the MongoDB fallback would produce a different result and the assertion
actually verifies precedence of the connection_string over the mongodb type
fallback.
---
Nitpick comments:
In `@packages/opencode/test/altimate/connections.test.ts`:
- Around line 84-87: The setEnv helper currently overwrites saved[key] each time
it's called, losing the true original environment value; modify setEnv (the
function named setEnv) to only capture and store process.env[key] into
saved[key] if saved[key] is undefined (i.e., guard the assignment so the
original value is preserved on the first call), then set process.env[key] to the
new value as before so tearDown/restore logic can accurately restore the
original.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 3e30099f-c815-4ddc-93b8-a4c3f23c16cf
📒 Files selected for processing (2)
packages/opencode/test/altimate/connections.test.tspackages/opencode/test/altimate/warehouse-telemetry.test.ts
| test("prefers explicit connection_string field over mongodb type fallback", () => { | ||
| expect(Registry.detectAuthMethod({ type: "mongodb", connection_string: "mongodb://localhost/test" } as any)).toBe("connection_string") | ||
| }) |
There was a problem hiding this comment.
Precedence test does not currently differentiate the fallback path.
At Line 186, the input has no password, so MongoDB fallback also returns "connection_string". This test won’t catch precedence regressions. Add password to make the fallback outcome different.
✅ Make the assertion branch-distinguishing
test("prefers explicit connection_string field over mongodb type fallback", () => {
- expect(Registry.detectAuthMethod({ type: "mongodb", connection_string: "mongodb://localhost/test" } as any)).toBe("connection_string")
+ expect(
+ Registry.detectAuthMethod({
+ type: "mongodb",
+ password: "secret",
+ connection_string: "mongodb://localhost/test",
+ } as any),
+ ).toBe("connection_string")
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| test("prefers explicit connection_string field over mongodb type fallback", () => { | |
| expect(Registry.detectAuthMethod({ type: "mongodb", connection_string: "mongodb://localhost/test" } as any)).toBe("connection_string") | |
| }) | |
| test("prefers explicit connection_string field over mongodb type fallback", () => { | |
| expect( | |
| Registry.detectAuthMethod({ | |
| type: "mongodb", | |
| password: "secret", | |
| connection_string: "mongodb://localhost/test", | |
| } as any), | |
| ).toBe("connection_string") | |
| }) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/opencode/test/altimate/warehouse-telemetry.test.ts` around lines 186
- 188, The test for Registry.detectAuthMethod currently doesn't distinguish the
explicit connection_string branch from the MongoDB fallback because the input
lacks a password so both return "connection_string"; update the test case used
in the "prefers explicit connection_string field over mongodb type fallback"
test to include a password field (e.g., add password: "x") so that the MongoDB
fallback would produce a different result and the assertion actually verifies
precedence of the connection_string over the mongodb type fallback.
Consolidates tests from PRs #440, #441, #479, #483, #484, #485, #490, #491, #492, #495, #496. Deduplicates overlapping MongoDB normalize tests (3 PRs → 1), `keybind` tests (2 PRs → 1), and `connections.test.ts` additions (4 PRs → 1 merged file). New test files: - `sql-analyze-tool.test.ts` — `SqlAnalyzeTool` formatting (6 tests) - `sql-analyze-format.test.ts` — `sql.analyze` success semantics + dispatcher (5 tests) - `builtin-commands.test.ts` — altimate builtin command registration (10 tests) - `hints-discover-mcps.test.ts` — `Command.hints()` + discover-and-add-mcps (11 tests) - `fingerprint-detect.test.ts` — file-based project detection rules (11 tests) - `dbt-lineage-helpers.test.ts` — dbt lineage helper functions (13 tests) - `registry-env-loading.test.ts` — `ALTIMATE_CODE_CONN_*` env var loading (8 tests) - `warehouse-telemetry.test.ts` — MongoDB auth detection telemetry (4 tests) - `bus-event.test.ts` — bus event registry payloads (5 tests) - `git.test.ts` — git utility functions (5 tests) - `keybind.test.ts` — keybind parsing, matching, `fromParsedKey` (22 tests) Merged into existing files: - `connections.test.ts` — `loadFromEnv` (5), `detectAuthMethod` (14), credential stripping (1), `containerToConfig` (1), dbt profiles edge cases (3) - `driver-normalize.test.ts` — MongoDB alias resolution (13 tests) Fixes: - `fixture.ts` — disable `commit.gpgsign` in test tmpdir to prevent CI failures - `hints-discover-mcps.test.ts` — corrected sort order expectation - `registry-env-loading.test.ts` — fixed flaky assertion that assumed isolated env Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Consolidated into #498. Tests deduplicated and merged into a single PR. |
What does this PR do?
1.
loadFromEnvviaRegistry.load()—src/altimate/native/connections/registry.ts(5 new tests)The
loadFromEnvfunction parsesALTIMATE_CODE_CONN_*environment variables to configure database connections. This is the primary connection method for CI/CD pipelines, Docker containers, and Codespaces users. Zero unit tests existed for this code path — a parsing regression would silently break all env-var-based connections with no test signal.New coverage includes:
ALTIMATE_CODE_CONN_*env varsPROD_DB→prod_db)typefield2.
detectAuthMethodfor MongoDB —src/altimate/native/connections/registry.ts(4 new tests)MongoDB driver support was added in #482. The
detectAuthMethodfunction has a MongoDB-specific branch (line 229) that returns"connection_string"when no password is present, or"password"when one is. This branch was completely untested. Auth method detection feeds into telemetry and provider UI — incorrect detection would cause misleading warehouse analytics.New coverage includes:
connection_stringauthpasswordauthmongotype alias (shorthand) without password →connection_stringconnection_stringfield takes precedence over MongoDB type fallbackType of change
Issue for this PR
N/A — proactive test coverage from automated test discovery
How did you verify your code works?
Marker check:
bun run script/upstream/analyze.ts --markers --base main --strict— passed (no upstream-shared files modified).Checklist
https://claude.ai/code/session_015egWH6W5HdaVuMysv9tFHq
Summary by CodeRabbit