Skip to content

test: MongoDB normalizeConfig aliases — close coverage gap from #482#506

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

test: MongoDB normalizeConfig aliases — close coverage gap from #482#506
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260327-0608

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

@anandgupta42 anandgupta42 commented Mar 27, 2026

What does this PR do?

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

MongoDB driver support was added in #482, but driver-normalize.test.ts had zero tests for the MONGODB_ALIASES map. Every other driver (Postgres, Snowflake, BigQuery, Databricks, SQL Server, Oracle, MySQL) had alias normalization tests — MongoDB was the only gap.

Why it matters: Users configure MongoDB connections using field names from the MongoDB Node.js driver docs (connectionString), mongosh docs (uri), or the native driver options (authSource, replicaSet, directConnection, connectTimeoutMS). Without normalization working correctly, these camelCase/alternative names silently fail — the driver doesn't see the connection string and falls back to constructing a URI from host/port, causing connection failures or connecting to the wrong database.

Specific scenarios covered:

  • connectionStringconnection_string (MongoDB Node.js driver convention)
  • uriconnection_string (mongosh / pymongo convention)
  • authSourceauth_source (driver option)
  • replicaSetreplica_set (driver option)
  • directConnectiondirect_connection (driver option, boolean)
  • connectTimeoutMSconnect_timeout (driver option, number)
  • mongo type alias routes to MongoDB alias map (not just mongodb)
  • Canonical MongoDB config passes through unchanged (regression guard)

What was intentionally excluded (critic review):

  • Common aliases (usernameuser, dbnamedatabase) — already tested for other drivers via the shared COMMON_ALIASES object
  • urlconnection_string — same code path as uri, no additional coverage
  • detectAuthMethod MongoDB branch — critic analysis showed the branch is shadowed by prior guards; proposed tests would pass for wrong reasons

Type of change

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

Issue for this PR

N/A — proactive test coverage for #482

How did you verify your code works?

bun test test/altimate/driver-normalize.test.ts    # 86 pass (78 existing + 8 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_01AhNUh22SS3cRR9GVNiTcit

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for MongoDB configuration normalization, including field alias mapping and type alias routing verification.

The MongoDB driver was added in #482 but driver-normalize.test.ts had zero
tests for the MONGODB_ALIASES map. These 8 tests cover all MongoDB-specific
alias normalization paths (connectionString, uri, authSource, replicaSet,
directConnection, connectTimeoutMS, mongo type alias, and canonical passthrough).

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

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

A new test suite for MongoDB config normalization was added, covering alias conversion for MongoDB-specific fields (connectionString, authSource, replicaSet, directConnection, connectTimeoutMS) to their snake_case equivalents, and verifying that pre-normalized canonical configs remain unchanged.

Changes

Cohort / File(s) Summary
MongoDB Config Normalization Tests
packages/opencode/test/altimate/driver-normalize.test.ts
Added comprehensive test suite verifying MongoDB field alias normalization (camelCase → snake_case), "mongo" type alias registration, and idempotent handling of already-normalized configurations.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through test cases true,
MongoDB fields in snake_case hue,
Aliases dance from camel to snake,
No mutations left in its wake,
Config normalized—perfect and bright!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding MongoDB normalizeConfig alias tests to close a coverage gap from issue #482.
Description check ✅ Passed The description comprehensively covers all required template sections: Summary (what changed and why), Test Plan (verification with bun test output), and Checklist (tests added and unit tests passing).
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-0608

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

667-747: Consider adding a test for serverSelectionTimeoutMS → server_selection_timeout.

MONGODB_ALIASES also defines serverSelectionTimeoutMS, and this one is a distinct mapping (not a duplicate-path alias like uri/url). Adding one test would close the remaining MongoDB-specific alias gap.

🤖 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 667 -
747, Add a test exercising the serverSelectionTimeoutMS →
server_selection_timeout alias: call normalizeConfig with { type: "mongodb",
serverSelectionTimeoutMS: 30000 } and assert the returned object has
server_selection_timeout === 30000 and serverSelectionTimeoutMS is undefined;
place this alongside the other MongoDB alias tests in the
describe("normalizeConfig — MongoDB") block so the mapping defined in
MONGODB_ALIASES is covered.
🤖 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 667-747: Add a test exercising the serverSelectionTimeoutMS →
server_selection_timeout alias: call normalizeConfig with { type: "mongodb",
serverSelectionTimeoutMS: 30000 } and assert the returned object has
server_selection_timeout === 30000 and serverSelectionTimeoutMS is undefined;
place this alongside the other MongoDB alias tests in the
describe("normalizeConfig — MongoDB") block so the mapping defined in
MONGODB_ALIASES is covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 85cc108b-3e3f-4ac5-bcd0-4dabc3e13ba1

📥 Commits

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

📒 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
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