Skip to content

test: MongoDB driver — normalization aliases + auth method detection#499

Open
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260327-0309
Open

test: MongoDB driver — normalization aliases + auth method detection#499
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260327-0309

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 27, 2026

What does this PR do?

Adds missing test coverage for the MongoDB driver support introduced in #482. The existing driver-normalize.test.ts covered every warehouse driver's aliases except MongoDB, and warehouse-telemetry.test.ts tested detectAuthMethod for every driver type except MongoDB.

1. normalizeConfig — MongoDB aliases — packages/drivers/src/normalize.ts (12 new tests)

The normalize module resolves camelCase and SDK-style field names to canonical snake_case before configs reach the driver. MongoDB was added to the alias map in #482 but had zero test coverage. If an LLM or dbt profile passes connectionString, authSource, replicaSet, etc., normalization must work correctly or the user silently fails to connect. New coverage includes:

  • Canonical MongoDB config passes through unchanged
  • connectionStringconnection_string
  • uriconnection_string
  • urlconnection_string
  • authSourceauth_source
  • replicaSetreplica_set
  • directConnectiondirect_connection
  • connectTimeoutMSconnect_timeout
  • serverSelectionTimeoutMSserver_selection_timeout
  • "mongo" type alias resolves MongoDB aliases correctly
  • connection_string takes precedence over uri alias (first-value-wins)

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

The MongoDB-specific auth detection branch (line 229) defaults to "connection_string" when no password is present — the typical MongoDB auth pattern. This branch was unreachable by existing tests which all used unsupported_db_type. Coverage includes:

  • { type: "mongodb", host: "localhost" }"connection_string" (not "unknown")
  • { type: "mongo", host: "localhost" }"connection_string" (type alias)

Type of change

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

Issue for this PR

N/A — proactive test coverage for new MongoDB driver (#482)

How did you verify your code works?

bun test test/altimate/driver-normalize.test.ts       # 89 pass (77 existing + 12 new)
bun test test/altimate/warehouse-telemetry.test.ts     # 43 pass (41 existing + 2 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

Summary by CodeRabbit

  • Tests
    • Added test coverage for MongoDB configuration field normalization and authentication method detection.

Note: This release contains internal test improvements with no user-visible changes.

Cover the MongoDB aliases added in #482 and the MongoDB-specific branch
in detectAuthMethod. Without these tests, camelCase config field names
from LLMs or dbt profiles (connectionString, authSource, replicaSet)
could silently fail to normalize, preventing MongoDB connections.

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

@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

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

Two test files were enhanced with new MongoDB-specific test cases. The first covers alias normalization for various camelCase and alternative field names mapping to snake_case canonical forms, plus type alias resolution and field precedence. The second verifies auth method detection for MongoDB driver types without passwords.

Changes

Cohort / File(s) Summary
MongoDB Alias Normalization Tests
packages/opencode/test/altimate/driver-normalize.test.ts
Added comprehensive test suite for MongoDB config alias normalization, verifying camelCase field names (connectionString, authSource, replicaSet, directConnection, connectTimeoutMS, serverSelectionTimeoutMS) map to canonical snake_case forms, plus tests for type alias resolution and field precedence.
MongoDB Auth Method Detection Tests
packages/opencode/test/altimate/warehouse-telemetry.test.ts
Added tests directly invoking Registry.detectAuthMethod to verify MongoDB driver types without passwords are classified as connection_string auth method.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

contributor

Poem

🐰 Hop, hop! The tests now dance,
MongoDB aliases in their enhanced trance,
Field names aligned, camelCase to snake,
Auth methods detected for goodness' sake! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding MongoDB driver tests for normalization aliases and auth method detection.
Description check ✅ Passed The description is comprehensive and well-structured, covering what changed, why it matters, specific test cases, and verification steps. It follows the template structure with Summary and Test Plan sections.
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-0309

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

@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 (1)
packages/opencode/test/altimate/driver-normalize.test.ts (1)

773-776: Consider removing the orphaned section header above the MongoDB block.

The insertion of the MongoDB test section left an orphaned "Snowflake private_key edge cases" comment block at lines 651-654 (the original header). This new header at lines 773-775 correctly labels the Snowflake test block at line 777, making the original header at 651-654 redundant and potentially confusing since it now appears directly before the MongoDB section.

🔧 Remove orphaned header (outside this line range)

Remove lines 651-654 to eliminate the duplicate/orphaned section header:

 })
 
-// ---------------------------------------------------------------------------
-// normalizeConfig — Snowflake private_key edge cases
-// ---------------------------------------------------------------------------
-
 // ---------------------------------------------------------------------------
 // normalizeConfig — MongoDB aliases
 // ---------------------------------------------------------------------------
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/altimate/driver-normalize.test.ts` around lines 773 -
776, Remove the orphaned section header "normalizeConfig — Snowflake private_key
edge cases" that was left before the MongoDB tests; locate the duplicate comment
block with that exact text and delete it so only the correct Snowflake header
(the one immediately before the Snowflake tests) remains, preventing confusion
between the MongoDB and Snowflake sections.
🤖 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/driver-normalize.test.ts`:
- Around line 773-776: Remove the orphaned section header "normalizeConfig —
Snowflake private_key edge cases" that was left before the MongoDB tests; locate
the duplicate comment block with that exact text and delete it so only the
correct Snowflake header (the one immediately before the Snowflake tests)
remains, preventing confusion between the MongoDB and Snowflake sections.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 134cc591-36f0-476d-994f-5bed196f3804

📥 Commits

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

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

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