test: connection registry — MongoDB auth detection and env var loading#508
test: connection registry — MongoDB auth detection and env var loading#508anandgupta42 wants to merge 1 commit intomainfrom
Conversation
Cover untested pure functions in the connection registry: detectAuthMethod MongoDB paths (added in #482) and loadFromEnv parsing via public API. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> https://claude.ai/code/session_016v7ah9WzhYe5veNDx1hh8W
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.
📝 WalkthroughWalkthroughAdded a new unit test file covering Altimate's connection registry public API, with three test groups validating authentication method detection for MongoDB, environment-driven config loading behavior, and configuration management through Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes 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.
🧹 Nitpick comments (2)
packages/opencode/test/altimate/connection-registry.test.ts (2)
3-11: Remove unused importcategorizeConnectionError.The
categorizeConnectionErrorfunction is imported but never used in this test file.🧹 Proposed fix
import { detectAuthMethod, - categorizeConnectionError, reset, load, getConfig, list, setConfigs, } from "../../src/altimate/native/connections/registry"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opencode/test/altimate/connection-registry.test.ts` around lines 3 - 11, The test file imports categorizeConnectionError but never uses it; remove categorizeConnectionError from the named import list in the import statement that currently imports detectAuthMethod, categorizeConnectionError, reset, load, getConfig, list, setConfigs from "../../src/altimate/native/connections/registry". Edit that import to exclude categorizeConnectionError (leaving detectAuthMethod, reset, load, getConfig, list, setConfigs) and run the project's linter/tests to ensure no remaining references.
110-116: Consider using thesetEnvhelper for consistency.This test directly sets
process.envinstead of using thesetEnvhelper defined at line 57. While the cleanup still works (envVars is manually updated), using the helper maintains consistency across all tests in this describe block.🧹 Proposed fix
test("ignores env var with empty string value", () => { // Empty string is falsy, so the `if (!value) continue` guard should skip it - process.env["ALTIMATE_CODE_CONN_EMPTY"] = "" - envVars.push("ALTIMATE_CODE_CONN_EMPTY") + setEnv("ALTIMATE_CODE_CONN_EMPTY", "") load() expect(getConfig("empty")).toBeUndefined() })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opencode/test/altimate/connection-registry.test.ts` around lines 110 - 116, In the "ignores env var with empty string value" test replace the direct process.env assignment with the setEnv helper (call setEnv("ALTIMATE_CODE_CONN_EMPTY", "")) and remove the manual envVars.push call so the test uses the same environment setup/teardown as other tests; keep the rest of the test using load() and expect(getConfig("empty")).toBeUndefined() unchanged and reference the existing setEnv helper and envVars cleanup logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/opencode/test/altimate/connection-registry.test.ts`:
- Around line 3-11: The test file imports categorizeConnectionError but never
uses it; remove categorizeConnectionError from the named import list in the
import statement that currently imports detectAuthMethod,
categorizeConnectionError, reset, load, getConfig, list, setConfigs from
"../../src/altimate/native/connections/registry". Edit that import to exclude
categorizeConnectionError (leaving detectAuthMethod, reset, load, getConfig,
list, setConfigs) and run the project's linter/tests to ensure no remaining
references.
- Around line 110-116: In the "ignores env var with empty string value" test
replace the direct process.env assignment with the setEnv helper (call
setEnv("ALTIMATE_CODE_CONN_EMPTY", "")) and remove the manual envVars.push call
so the test uses the same environment setup/teardown as other tests; keep the
rest of the test using load() and expect(getConfig("empty")).toBeUndefined()
unchanged and reference the existing setEnv helper and envVars cleanup logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d18dd3dc-0be3-403c-a124-2c24f691f874
📒 Files selected for processing (1)
packages/opencode/test/altimate/connection-registry.test.ts
Deduplicate overlapping tests from PRs #494, #499, #502, #504, #506, #507, #508, #510, #511, #512. Most MongoDB/env-var/dbt coverage was already on main; this adds only genuinely new tests: - SSH tunnel: `extractSshConfig` validation + lifecycle safety (7 tests) - dbt profiles: spark->databricks, trino->postgres adapter mapping - `dbtConnectionsToConfigs` conversion + empty input handling - `containerToConfig` with fully-populated container - MongoDB assertions in `telemetry-safety.test.ts` - Sanity suite: branding, deny, driver, resilience expansions (#494) Closes #513 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Consolidated into #514. This PR's test coverage was either already on main or has been included in the consolidated PR. |
…514) * test: consolidate test coverage from 10 hourly PRs into single PR Deduplicate overlapping tests from PRs #494, #499, #502, #504, #506, #507, #508, #510, #511, #512. Most MongoDB/env-var/dbt coverage was already on main; this adds only genuinely new tests: - SSH tunnel: `extractSshConfig` validation + lifecycle safety (7 tests) - dbt profiles: spark->databricks, trino->postgres adapter mapping - `dbtConnectionsToConfigs` conversion + empty input handling - `containerToConfig` with fully-populated container - MongoDB assertions in `telemetry-safety.test.ts` - Sanity suite: branding, deny, driver, resilience expansions (#494) Closes #513 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address code review findings from 6-model consensus review - Use `require.resolve()` instead of `require()` for driver resolvability checks to avoid false negatives from native binding load failures - Remove unnecessary `altimate_change` markers from new ssh-tunnel test file - Add `closeAllTunnels()` cleanup in `afterEach` to prevent state leaks Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address convergence review findings — driver warns, unshare guard - Driver resolvability checks now emit warnings instead of failures since drivers are intentionally absent from sanity Docker image (#295) - `unshare --net` now tests with a dry-run before use, falling back to proxy-based network blocking when unprivileged (macOS, containers) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
What does this PR do?
1.
detectAuthMethod— MongoDB paths —src/altimate/native/connections/registry.ts(6 new tests)MongoDB driver support was added in #482, including a new branch in
detectAuthMethod(line 229) that returns"connection_string"when a MongoDB config has no password. This code path had zero test coverage. The existingtelemetry-safety.test.tstestsdetectAuthMethodthoroughly for all other driver types but does not include anymongodbormongotype configs.New coverage includes:
mongodbwith password →"password"(hits generic password check)mongodbwithout password →"connection_string"(hits MongoDB-specific branch)mongoalias with and without passwordconnection_stringfield andaccess_tokentake precedence over the MongoDB type check2.
loadFromEnvvia public API —src/altimate/native/connections/registry.ts(7 new tests)The
loadFromEnv()function parsesALTIMATE_CODE_CONN_*environment variables into connection configs. This is a primary config source for CI/CD and Docker deployments, yet had zero test coverage. Tests drive it indirectly through the public API (reset()+load()+getConfig()/list()).New coverage includes:
typefield is rejectedlist()output3.
setConfigs+listround-trip —src/altimate/native/connections/registry.ts(3 new tests)Sanity tests for the public testing API (
setConfigs,getConfig,list) to ensure they work correctly as a foundation for other tests.Type of change
Issue for this PR
N/A — proactive test coverage for recently added MongoDB support (#482)
How did you verify your code works?
Checklist
https://claude.ai/code/session_016v7ah9WzhYe5veNDx1hh8W
Summary by CodeRabbit