Skip to content

test: MongoDB normalization + detectAuthMethod coverage#491

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

test: MongoDB normalization + detectAuthMethod coverage#491
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260326-2315

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 (6 new tests)

MongoDB driver support was just added in #482, but the config normalization layer had zero test coverage for MongoDB-specific field aliases. This is a P0 gap: users connecting via uri, url, or connectionString (the most common MongoDB connection patterns from Atlas docs, Mongoose, and official drivers) would silently get no connection string passed to the driver. New coverage includes:

  • connectionStringconnection_string alias resolution
  • uriconnection_string alias resolution
  • urlconnection_string alias resolution (mongodb+srv URIs)
  • First-value-wins: canonical connection_string takes precedence over uri
  • mongo type alias resolves MongoDB-specific fields (authSource, uri)
  • authSourceauth_source camelCase alias

2. detectAuthMethodpackages/opencode/src/altimate/native/connections/registry.ts (14 new tests)

This function feeds the auth_method field in warehouse_connect telemetry events. It had zero test coverage. Wrong values corrupt warehouse analytics and make it impossible to debug connection issues by auth type. New coverage includes:

  • connection_string, key_pair (both snake_case and camelCase variants), sso (EXTERNALBROWSER + Okta URL), oauth, token, password detection
  • File-based auth for DuckDB and SQLite ("file")
  • MongoDB-specific default ("connection_string" when no password)
  • MongoDB with password returns "password"
  • Null/undefined guard returns "unknown"
  • Empty config with no identifiable auth returns "unknown"

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 (#482)

How did you verify your code works?

bun test test/altimate/driver-normalize.test.ts   # 84 pass (78 existing + 6 new)
bun test test/altimate/connections.test.ts         # 53 pass (39 existing + 14 new)

Marker check passed: bun run script/upstream/analyze.ts --markers --base main --strict

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
    • Enhanced test coverage for database authentication method detection across multiple connection types
    • Added validation tests for MongoDB connection configuration normalization

MongoDB driver (PR #482) had zero unit tests for config alias normalization
(uri, url, authSource, etc.) and auth method detection in telemetry. These
tests prevent silent config failures for MongoDB users using common alias
field names and ensure telemetry correctly categorizes auth methods for all
driver types including the new MongoDB and file-based drivers.

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 26, 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: 69902eab-b335-4452-a5dc-14c739c2478f

📥 Commits

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

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

📝 Walkthrough

Walkthrough

This PR adds comprehensive test coverage for authentication method detection and MongoDB connection configuration alias normalization. Tests validate proper handling of multiple authentication types (connection_string, key_pair, sso, oauth, token, password, file) and MongoDB-specific field alias mappings.

Changes

Cohort / File(s) Summary
Authentication Detection Tests
packages/opencode/test/altimate/connections.test.ts
Tests the detectAuthMethod function with assertions covering authentication method identification across multiple types: connection_string, key_pair, sso, oauth, token, password, file, and unknown for various database configs (Postgres, MongoDB, Snowflake, Databricks, DuckDB, SQLite).
MongoDB Configuration Normalization Tests
packages/opencode/test/altimate/driver-normalize.test.ts
Tests MongoDB-specific alias normalization, validating that alias fields (connectionString, uri, url) map to canonical connection_string, that canonical fields take precedence, and that auth-related aliases (authSource) are normalized to snake_case equivalents (auth_source).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Altimate AI/altimate-code#482: Introduces MongoDB normalization and connection-registry logic that these tests validate, including alias mappings and authentication method detection.

Suggested labels

contributor

Poem

🐰 Hop hop, tests compile true,
Auth methods old and new detected through,
MongoDB aliases normalized with care,
Coverage spreads—zero doubts in the air!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately and concisely summarizes the main changes: adding test coverage for MongoDB normalization and detectAuthMethod functionality.
Description check ✅ Passed The pull request description comprehensively covers all required sections: clear summary of changes with detailed rationale, test plan with verification steps, and completed checklist.
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-2315

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

anandgupta42 added a commit that referenced this pull request Mar 27, 2026
* test: consolidate 11 test PRs into single suite — 305 new tests

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>

* fix: address CodeRabbit review comments

- `bus-event.test.ts`: move `BusEvent.define` into tests instead of module scope
- `builtin-commands.test.ts`: fix misleading "lexicographic" → "numeric" sort label
- `git.test.ts`: use `tmpdir({ git: true })` fixture instead of manual `git init`
- `registry-env-loading.test.ts`: remove unused `fs`, `os`, `path` imports

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