test: connections — dbt-profiles, Docker, MongoDB auth#511
test: connections — dbt-profiles, Docker, MongoDB auth#511anandgupta42 wants to merge 1 commit intomainfrom
Conversation
…, MongoDB auth detection Cover untested code paths in the connection subsystem: dbt env_var defaults, adapter type aliases (spark→databricks, trino→postgres), config key skipping, multi-profile parsing, Docker container-to-config conversion, and the new MongoDB auth method detection added in #482. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
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.
📝 WalkthroughWalkthroughExpands test coverage for DBT profile parsing edge cases, Docker container connection conversion via Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/opencode/test/altimate/connections.test.ts (1)
272-303: Test logic is correct; consider usingtmpdirfixture for consistency with guidelines.The env_var default resolution test correctly validates the fallback behavior. However, the coding guidelines recommend using
tmpdirfromfixture/fixture.tswithawait usingsyntax for automatic cleanup.While the current pattern matches existing tests in this file, consider refactoring to align with the guidelines:
♻️ Optional refactor using tmpdir fixture
test("env_var with default value resolves to default when env var is missing", async () => { await using tmp = await tmpdir() delete process.env.DBT_TEST_NONEXISTENT_VAR const profilesPath = path.join(tmp.path, "profiles.yml") fs.writeFileSync(profilesPath, ` myproject: outputs: dev: type: postgres host: localhost password: "{{ env_var('DBT_TEST_NONEXISTENT_VAR', 'fallback_pw') }}" dbname: testdb `) const connections = await parseDbtProfiles(profilesPath) expect(connections).toHaveLength(1) expect(connections[0].config.password).toBe("fallback_pw") })As per coding guidelines: "Use the
tmpdirfunction fromfixture/fixture.tsto create temporary directories for tests with automatic cleanup" and "Always useawait usingsyntax withtmpdir()for automatic cleanup".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opencode/test/altimate/connections.test.ts` around lines 272 - 303, The test "env_var with default value resolves to default when env var is missing" correctly asserts fallback behavior but should use the tmpdir fixture for automatic cleanup; replace the manual fs.mkdtempSync/fs.rmSync pattern with the tmpdir fixture from fixture/fixture.ts using "await using tmp = await tmpdir()", build profilesPath from tmp.path, write the file (keep parseDbtProfiles and process.env deletion unchanged), and remove the try/finally cleanup block so the fixture handles teardown.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/opencode/test/altimate/connections.test.ts`:
- Line 16: The import list in the test currently includes
categorizeConnectionError which is unused; either remove
categorizeConnectionError from the import statement (leaving detectAuthMethod)
or add tests that exercise the categorizeConnectionError function (call
categorizeConnectionError with representative error inputs and assert expected
categories), ensuring the test actually references the function so the import is
used.
---
Nitpick comments:
In `@packages/opencode/test/altimate/connections.test.ts`:
- Around line 272-303: The test "env_var with default value resolves to default
when env var is missing" correctly asserts fallback behavior but should use the
tmpdir fixture for automatic cleanup; replace the manual
fs.mkdtempSync/fs.rmSync pattern with the tmpdir fixture from fixture/fixture.ts
using "await using tmp = await tmpdir()", build profilesPath from tmp.path,
write the file (keep parseDbtProfiles and process.env deletion unchanged), and
remove the try/finally cleanup block so the fixture handles teardown.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: eb84ec21-cd2a-433c-834e-3aa2a739b88e
📒 Files selected for processing (1)
packages/opencode/test/altimate/connections.test.ts
| import { discoverContainers } from "../../src/altimate/native/connections/docker-discovery" | ||
| import { parseDbtProfiles, dbtConnectionsToConfigs } from "../../src/altimate/native/connections/dbt-profiles" | ||
| import { discoverContainers, containerToConfig } from "../../src/altimate/native/connections/docker-discovery" | ||
| import { detectAuthMethod, categorizeConnectionError } from "../../src/altimate/native/connections/registry" |
There was a problem hiding this comment.
Unused import: categorizeConnectionError
This function is imported but never used in any test. Either add tests for it or remove the import.
-import { detectAuthMethod, categorizeConnectionError } from "../../src/altimate/native/connections/registry"
+import { detectAuthMethod } from "../../src/altimate/native/connections/registry"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { detectAuthMethod, categorizeConnectionError } from "../../src/altimate/native/connections/registry" | |
| import { detectAuthMethod } from "../../src/altimate/native/connections/registry" |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/opencode/test/altimate/connections.test.ts` at line 16, The import
list in the test currently includes categorizeConnectionError which is unused;
either remove categorizeConnectionError from the import statement (leaving
detectAuthMethod) or add tests that exercise the categorizeConnectionError
function (call categorizeConnectionError with representative error inputs and
assert expected categories), ensuring the test actually references the function
so the import is used.
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>
|
Consolidated into #514. This PR's test coverage was either already on main or has been included in the consolidated PR. |
…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>
What does this PR do?
Adds 12 new tests to the connection subsystem covering previously untested code paths identified during proactive test discovery. All tests are pure/deterministic with no external dependencies.
1.
parseDbtProfiles—src/altimate/native/connections/dbt-profiles.ts(5 new tests)The dbt profiles parser had basic coverage (env_var resolution, single profile parsing) but missed several real-world edge cases. New coverage includes:
env_var()with default values: Users commonly write{{ env_var('SECRET', 'dev_fallback') }}in profiles.yml. The regex captures the optional second group, but this was untested — a refactor could silently break default resolution, causing empty strings instead of fallback values.ADAPTER_TYPE_MAPmapssparktodatabricks. Users with Spark-flavored dbt projects would get "unsupported type" errors if this alias were removed.trinomaps topostgres(wire-compatible). Untested non-trivial alias.configkey skipping: Realprofiles.ymlfiles often have a top-levelconfig:key for global dbt settings. The parser explicitly skips it (profileName === "config"), but this guard had no test — removing it would create phantom warehouse entries.2.
dbtConnectionsToConfigs—src/altimate/native/connections/dbt-profiles.ts(2 new tests)This function converts the parsed connection array into a keyed
Recordused by the auto-discovery pipeline. Zero tests existed. Coverage includes basic conversion and empty-input handling.3.
containerToConfig—src/altimate/native/connections/docker-discovery.ts(2 new tests)This exported function converts Docker-discovered containers into
ConnectionConfigobjects. Previously onlydiscoverContainers(which returns[]without dockerode) was tested. New coverage includes:user,password,database) are omitted from the object (not set toundefined) when the container doesn't provide them — the distinction matters for driver serialization4.
detectAuthMethodMongoDB branch —src/altimate/native/connections/registry.ts(2 new tests)MongoDB support was added in #482 but the
detectAuthMethodtelemetry helper had no MongoDB-specific tests. The MongoDB branch at line 229 is only reachable whenpasswordis falsy (the generic password check at line 227 fires first). New tests cover:{ type: "mongodb" }→"connection_string"{ type: "mongo" }→"connection_string"(alias)Critic review note: A test for
detectAuthMethod({ type: "mongodb", password: "secret" })was proposed but rejected by the critic agent — the MongoDB-specific branch is unreachable in that case (the genericpasswordcheck returns first). Only the actually-reachable branch is tested.Type of change
Issue for this PR
N/A — proactive test coverage from automated test discovery
How did you verify your code works?
Marker check passes (
bun run script/upstream/analyze.ts --markers --base main --strict).Checklist
Summary by CodeRabbit