Skip to content

test: warehouse connections — MongoDB auth + env var loading#502

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

test: warehouse connections — MongoDB auth + env var loading#502
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260327-0413

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

@anandgupta42 anandgupta42 commented Mar 27, 2026

What does this PR do?

1. detectAuthMethod — MongoDB branch (src/altimate/native/connections/registry.ts) (2 new tests)

MongoDB driver support was added this week (commit abcaa1d, PR #482). The detectAuthMethod function gained a new mongodb/mongo branch that returns "connection_string" as the fallback auth method for MongoDB configs without a password — distinct from other driver types which fall through to "unknown". Zero tests existed for this new branch. Without these tests, the MongoDB-specific line could be deleted and no test would fail, silently mislabeling telemetry for all MongoDB users.

New coverage includes:

  • { type: "mongodb", host: "..." } (no password) returns "connection_string" not "unknown"
  • { type: "mongo", host: "..." } (alias) returns "connection_string" — verifies the || t === "mongo" half of the OR condition

2. loadFromEnvALTIMATE_CODE_CONN_* env var parsing (src/altimate/native/connections/registry.ts) (3 new tests)

CI/CD users configure warehouse connections via ALTIMATE_CODE_CONN_* environment variables. The loadFromEnv() function (lines 64–82) parses these into connection configs during load(). This code path had zero direct test coverage. If JSON parsing broke silently or the type field guard were removed, CI connections would vanish with no error.

New coverage includes:

  • Valid JSON env var is parsed and available via getConfig() (includes lowercase name conversion)
  • Invalid JSON env var is silently skipped (no crash, no config entry)
  • JSON missing the required type field is rejected

Type of change

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

Issue for this PR

N/A — proactive test coverage for newly added MongoDB driver support and untested CI/CD configuration path.

How did you verify your code works?

bun test test/altimate/connections.test.ts           # 42 pass
bun test test/altimate/warehouse-telemetry.test.ts   # 43 pass

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_01QvuBUD1uLcEPSu6EugNcyf

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for environment variable-based configuration loading and authentication method detection logic.

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) <noreply@anthropic.com>

https://claude.ai/code/session_01QvuBUD1uLcEPSu6EugNcyf
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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: adb2ddd9-0902-42b5-b3ee-edb2d2c6aa9b

📥 Commits

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

📒 Files selected for processing (2)
  • packages/opencode/test/altimate/connections.test.ts
  • packages/opencode/test/altimate/warehouse-telemetry.test.ts

📝 Walkthrough

Walkthrough

New test suites added to verify connection registry functionality: one tests environment variable loading into the registry with valid/invalid payloads, another tests MongoDB authentication method detection for fallback behavior. Both use proper isolation via beforeEach resets and finally cleanup blocks.

Changes

Cohort / File(s) Summary
Connection Registry Tests
packages/opencode/test/altimate/connections.test.ts
Added ConnectionRegistry: loadFromEnv test suite validating Registry.load() behavior with ALTIMATE_CODE_CONN_* environment variables, including positive paths (valid JSON parsing, field preservation) and negative paths (invalid JSON, missing required type field).
Warehouse Telemetry Tests
packages/opencode/test/altimate/warehouse-telemetry.test.ts
Added two tests to warehouse telemetry: detectAuthMethod suite verifying Registry.detectAuthMethod returns "connection_string" for MongoDB driver types when both password and connection_string fields are absent.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • feat: add MongoDB driver support #482: The added tests for Registry.detectAuthMethod verify behavior changes made to packages/opencode/src/altimate/native/connections/registry.ts in that PR.

Suggested labels

contributor

Poem

🐰 Through environments and registries deep,
These tests hop paths both steep and neat,
MongoDB's auth finds its way,
With fallbacks sure to save the day! 🔐

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly reflects the primary changes: adding tests for MongoDB authentication detection and environment variable loading for warehouse connections.
Description check ✅ Passed The description provides comprehensive context, rationale, and test coverage for both changes, though it deviates from the template structure by not using the specified section headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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-0413

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.

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