Skip to content

test: connection registry — MongoDB auth detection and env var loading#508

Closed
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260327-1011
Closed

test: connection registry — MongoDB auth detection and env var loading#508
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260327-1011

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

@anandgupta42 anandgupta42 commented Mar 27, 2026

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 existing telemetry-safety.test.ts tests detectAuthMethod thoroughly for all other driver types but does not include any mongodb or mongo type configs.

New coverage includes:

  • mongodb with password → "password" (hits generic password check)
  • mongodb without password → "connection_string" (hits MongoDB-specific branch)
  • mongo alias with and without password
  • Priority verification: connection_string field and access_token take precedence over the MongoDB type check

2. loadFromEnv via public API — src/altimate/native/connections/registry.ts (7 new tests)

The loadFromEnv() function parses ALTIMATE_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:

  • Valid env var parsing (JSON → ConnectionConfig)
  • Connection name lowercasing from env var suffix
  • Malformed JSON is silently ignored (no crash)
  • Missing type field is rejected
  • Null JSON value is rejected
  • Empty string env var is skipped
  • Env-loaded configs appear in list() output

3. setConfigs + list round-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

  • New feature (non-breaking change which adds functionality)

Issue for this PR

N/A — proactive test coverage for recently added MongoDB support (#482)

How did you verify your code works?

bun test test/altimate/connection-registry.test.ts   # 16 pass, 0 fail

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

https://claude.ai/code/session_016v7ah9WzhYe5veNDx1hh8W

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit test coverage for the Altimate connection registry module. Tests validate authentication method detection for various database types, environment variable-based configuration loading with proper error handling for malformed data, and configuration management through public API operations.

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
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

Added 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 setConfigs and list functions.

Changes

Cohort / File(s) Summary
Connection Registry Tests
packages/opencode/test/altimate/connection-registry.test.ts
New test suite validating detectAuthMethod (password/connection_string/token detection), loadFromEnv (env var parsing with reset()/load()), and public API behavior for config management (setConfigs, getConfig, list).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 With tests now written, strong and true,
The registry's secrets all shine through!
Auth methods dance, configs align,
Each assertion a hoppy design!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main changes: adding tests for MongoDB auth detection and env var loading in the connection registry.
Description check ✅ Passed The description is comprehensive and follows the template structure with Summary, Test Plan, and Checklist sections, providing detailed context for all three test coverage areas.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/hourly-20260327-1011

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/opencode/test/altimate/connection-registry.test.ts (2)

3-11: Remove unused import categorizeConnectionError.

The categorizeConnectionError function 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 the setEnv helper for consistency.

This test directly sets process.env instead of using the setEnv helper 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

📥 Commits

Reviewing files that changed from the base of the PR and between abcaa1d and bc7c85b.

📒 Files selected for processing (1)
  • packages/opencode/test/altimate/connection-registry.test.ts

anandgupta42 added a commit that referenced this pull request Mar 27, 2026
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>
@anandgupta42
Copy link
Copy Markdown
Contributor Author

Consolidated into #514. This PR's test coverage was either already on main or has been included in the consolidated PR.

anandgupta42 added a commit that referenced this pull request Mar 27, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants