Skip to content

test: MongoDB config normalization aliases — 13 new tests#484

Closed
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260326-2013
Closed

test: MongoDB config normalization aliases — 13 new tests#484
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260326-2013

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 26, 2026

What does this PR do?

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

MongoDB was added as the 11th supported driver in PR #482 (commit abcaa1d), but the config normalization alias map (MONGODB_ALIASES) had zero unit test coverage. Every other driver (Snowflake, BigQuery, Databricks, Postgres, Redshift, MySQL, SQL Server, Oracle, DuckDB, SQLite) already had dedicated normalization tests in driver-normalize.test.ts.

Why this matters: Users providing MongoDB configs via dbt profiles, LLM-generated configs, or SDK conventions use camelCase keys (connectionString, authSource, replicaSet, directConnection). Without normalization, these keys silently pass through unresolved, causing connection failures with no clear error message. The mongo type alias (shorthand for mongodb) was also untested.

Specific scenarios covered:

  • Connection string aliases: connectionString, uri, urlconnection_string (3 tests)
  • First-value-wins precedence: canonical connection_string takes priority over uri alias (1 test)
  • MongoDB-specific aliases: authSourceauth_source, replicaSetreplica_set, directConnectiondirect_connection, connectTimeoutMSconnect_timeout, serverSelectionTimeoutMSserver_selection_timeout (5 tests)
  • Common aliases for MongoDB: usernameuser, dbnamedatabase (2 tests)
  • Type alias: mongo resolves to the same alias map as mongodb (1 test)
  • Identity: canonical MongoDB config passes through unchanged (1 test)

Test quality: All tests are pure-function unit tests with no network, timing, or filesystem dependencies. Reviewed and approved by a critic agent before committing.

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

How did you verify your code works?

bun test test/altimate/driver-normalize.test.ts    # 91 pass (78 existing + 13 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_019D8HyMGHH3Pf43PddTqUw5

Summary by CodeRabbit

  • Tests
    • Added extensive test coverage for MongoDB configuration normalization, validating proper handling of connection parameters (connection strings and URIs), authentication fields, replica set settings, timeout configurations, and connection modes to ensure consistent configuration validation.

MongoDB driver was added in PR #482 but its config alias normalization
had zero unit test coverage. These tests ensure camelCase config keys
(connectionString, uri, authSource, replicaSet, etc.) resolve correctly,
preventing silent connection failures for users providing non-canonical
config field names.

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

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

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai
Copy link

coderabbitai bot commented Mar 26, 2026

📝 Walkthrough

Walkthrough

A new MongoDB-specific configuration alias normalization test suite was added, covering field mappings such as connectionStringconnection_string, authSourceauth_source, replicaSetreplica_set, timeout fields, and username/dbname transformations, with assertions for precedence and canonical config passthrough.

Changes

Cohort / File(s) Summary
MongoDB Alias Normalization Tests
packages/opencode/test/altimate/driver-normalize.test.ts
Added 130 lines of test cases covering MongoDB configuration alias mappings, including connection string variants, authentication fields, replica set, direct connection, timeout fields, and username/database transformations, with assertions for field precedence and canonical config validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

contributor

Poem

🐰 Hops of joy through MongoDB fields so bright,
Aliases dance—connection strings unite!
authSource springs to auth_source with care,
Timeouts normalized in the testing air! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding 13 new tests for MongoDB config normalization aliases.
Description check ✅ Passed The description covers what changed, includes detailed test scenarios, and mentions local verification with test results, but lacks explicit Test Plan and Checklist sections matching the template structure.
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-20260326-2013

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)

693-709: Consider pinning alias-order behavior when both uri and url are present.

You already test canonical-over-alias precedence. Adding one case with both non-canonical aliases would lock in the current first-alias-wins order and prevent future regressions in alias-list ordering.

Proposed additional test
 describe("normalizeConfig — MongoDB", () => {
+  test("uri takes precedence over url when both aliases are present", () => {
+    const result = normalizeConfig({
+      type: "mongodb",
+      uri: "mongodb://uri-first:27017/db",
+      url: "mongodb://url-second:27017/db",
+    })
+    expect(result.connection_string).toBe("mongodb://uri-first:27017/db")
+    expect(result.uri).toBeUndefined()
+    expect(result.url).toBeUndefined()
+  })
+
   test("canonical mongodb config passes through unchanged", () => {

Also applies to: 711-719

🤖 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 693 -
709, Add a test to pin current alias-resolution order when both non-canonical
aliases are present: call normalizeConfig with both uri and url set (e.g., uri
first, url second) and assert that connection_string equals the first alias
value and the second alias is undefined; use a clear test name like "uri+url →
first-alias-wins" referencing normalizeConfig so future changes to alias
ordering will fail the test if behavior changes.
🤖 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 693-709: Add a test to pin current alias-resolution order when
both non-canonical aliases are present: call normalizeConfig with both uri and
url set (e.g., uri first, url second) and assert that connection_string equals
the first alias value and the second alias is undefined; use a clear test name
like "uri+url → first-alias-wins" referencing normalizeConfig so future changes
to alias ordering will fail the test if behavior changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a5339c36-4ff2-40a3-835f-b194ce636097

📥 Commits

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

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

anandgupta42 added a commit that referenced this pull request Mar 27, 2026
Consolidates tests from PRs #440, #441, #479, #483, #484, #485, #490, #491, #492, #495, #496.
Deduplicates overlapping MongoDB normalize tests (3 PRs → 1), `keybind` tests (2 PRs → 1),
and `connections.test.ts` additions (4 PRs → 1 merged file).

New test files:
- `sql-analyze-tool.test.ts` — `SqlAnalyzeTool` formatting (6 tests)
- `sql-analyze-format.test.ts` — `sql.analyze` success semantics + dispatcher (5 tests)
- `builtin-commands.test.ts` — altimate builtin command registration (10 tests)
- `hints-discover-mcps.test.ts` — `Command.hints()` + discover-and-add-mcps (11 tests)
- `fingerprint-detect.test.ts` — file-based project detection rules (11 tests)
- `dbt-lineage-helpers.test.ts` — dbt lineage helper functions (13 tests)
- `registry-env-loading.test.ts` — `ALTIMATE_CODE_CONN_*` env var loading (8 tests)
- `warehouse-telemetry.test.ts` — MongoDB auth detection telemetry (4 tests)
- `bus-event.test.ts` — bus event registry payloads (5 tests)
- `git.test.ts` — git utility functions (5 tests)
- `keybind.test.ts` — keybind parsing, matching, `fromParsedKey` (22 tests)

Merged into existing files:
- `connections.test.ts` — `loadFromEnv` (5), `detectAuthMethod` (14), credential stripping (1),
  `containerToConfig` (1), dbt profiles edge cases (3)
- `driver-normalize.test.ts` — MongoDB alias resolution (13 tests)

Fixes:
- `fixture.ts` — disable `commit.gpgsign` in test tmpdir to prevent CI failures
- `hints-discover-mcps.test.ts` — corrected sort order expectation
- `registry-env-loading.test.ts` — fixed flaky assertion that assumed isolated env

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

Consolidated into #498. Tests deduplicated and merged into a single PR.

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