Skip to content

test: connections — env-var loading and MongoDB auth detection#507

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

test: connections — env-var loading and MongoDB auth detection#507
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260327-0821

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

@anandgupta42 anandgupta42 commented Mar 27, 2026

What does this PR do?

1. loadFromEnvsrc/altimate/native/connections/registry.ts (5 new tests)

The ALTIMATE_CODE_CONN_* env-var connection loading path had zero unit test coverage. CI/CD users rely on this to inject warehouse connections without config files on disk. If JSON parsing or name normalization (uppercase prefix → lowercase key) broke, connections would silently fail to load with no indication why.

New coverage includes:

  • Valid env var parsing with name lowercasing
  • Malformed JSON is silently ignored (no crash)
  • Config objects missing the type field are rejected
  • Empty env var values are ignored
  • Multiple env var connections are parsed correctly

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

PR #482 added MongoDB driver support with a new branch in detectAuthMethod (line 229) that returns "connection_string" for MongoDB connections without a password. This branch had zero test coverage. Wrong auth detection means incorrect telemetry for MongoDB users.

New coverage includes:

  • type: "mongodb" without password → "connection_string"
  • type: "mongo" (alias) without password → "connection_string"
  • type: "mongodb" with password → "password" (exercises the generic password check path)

Type of change

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

Issue for this PR

N/A — proactive test coverage

How did you verify your code works?

bun test test/altimate/registry-env.test.ts          # 5 pass
bun test test/altimate/warehouse-telemetry.test.ts   # 44 pass (41 existing + 3 new)

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_01Uf1H6t7768cFYAT9AbKSzr

Summary by CodeRabbit

  • Tests
    • Added test coverage for configuration loading from environment variables and MongoDB authentication detection.

Cover untested CI/CD code path (ALTIMATE_CODE_CONN_* env vars) and new MongoDB
detectAuthMethod branches added in PR #482.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

https://claude.ai/code/session_01Uf1H6t7768cFYAT9AbKSzr
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: d3d1ed25-0f2e-4567-affd-89f1fcbe518b

📥 Commits

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

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

📝 Walkthrough

Walkthrough

Added two test files to expand test coverage: one for ConnectionRegistry.loadFromEnv behavior testing environment variable parsing scenarios (valid JSON, malformed JSON, missing fields, empty values, and multiple variables), and another for Registry.detectAuthMethod testing MongoDB authentication detection paths directly.

Changes

Cohort / File(s) Summary
Registry Environment Loading Tests
packages/opencode/test/altimate/registry-env.test.ts
New test suite covering Registry.load() via ConnectionRegistry.loadFromEnv, verifying JSON parsing from ALTIMATE_CODE_CONN_* env vars, connection name lowercasing, malformed JSON handling, missing type field handling, empty values, and multiple variable registration.
MongoDB Authentication Tests
packages/opencode/test/altimate/warehouse-telemetry.test.ts
New direct unit tests for Registry.detectAuthMethod covering MongoDB authentication detection with connection strings vs. passwords, bypassing telemetry-driven connection attempts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

contributor

Poem

🐰 A rabbit hops through test files new,
Parsing env vars, MongoDB too,
JSON and passwords, all checked with care,
Robust connections everywhere! 🌳

🚥 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 summarizes the main changes: adding tests for env-var loading and MongoDB auth detection, which are the two primary focuses of the changeset.
Description check ✅ Passed The description covers the required sections: Summary (with detailed explanation of what changed and why), Test Plan (verification steps with concrete test results), and Checklist (all relevant items checked). All critical information is present and complete.

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

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