Skip to content

Commit 129089d

Browse files
anandgupta42claude
authored andcommitted
fix: flaky dbt Profiles Auto-Discovery tests in CI
`dispatcher.test.ts` nullifies the lazy registration hook via `setRegistrationHook(null)` in its `beforeEach`. When Bun runs it before `dbt-first-execution.test.ts`, the hook is permanently dead and `Dispatcher.call("dbt.profiles")` throws "No native handler". Fix: replace fragile lazy-hook reliance with explicit `beforeAll` imports of the registration modules, guaranteeing handlers exist regardless of test file ordering. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a63d378 commit 129089d

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

packages/opencode/test/altimate/dbt-first-execution.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ import { homedir } from "os"
1818
import type { Connector } from "@altimateai/drivers/types"
1919
import * as Dispatcher from "../../src/altimate/native/dispatcher"
2020

21-
// Import native/index.ts to ensure the lazy registration hook is set.
22-
// In Bun's multi-file runner, test execution order is unpredictable —
23-
// if dispatcher.test.ts runs first and clears the hook, this file's
24-
// Dispatcher.call() would fail with "No native handler" errors.
25-
// Re-importing here ensures the hook is always available.
26-
import "../../src/altimate/native"
27-
2821
// Mock DuckDB driver so tests don't require the native duckdb package.
2922
// NOTE: mock.module leaks across test files in Bun — we spread the real
3023
// module exports to minimize damage to other test files.
@@ -119,6 +112,16 @@ const HAS_DBT = !!DBT_PROJECT
119112
// Tests: dbt profiles auto-discovery
120113
// ---------------------------------------------------------------------------
121114
describe("dbt Profiles Auto-Discovery", () => {
115+
// Explicitly import registration modules instead of relying on the lazy
116+
// hook from native/index.ts. dispatcher.test.ts nullifies the hook via
117+
// setRegistrationHook(null), and Bun's non-deterministic file ordering
118+
// means that file may run first — leaving _ensureRegistered permanently
119+
// null for all subsequent test files in the same process.
120+
beforeAll(async () => {
121+
await import("../../src/altimate/native/connections/register")
122+
await import("../../src/altimate/native/schema/register")
123+
})
124+
122125
test("parseDbtProfiles finds connections from ~/.dbt/profiles.yml", async () => {
123126
const { parseDbtProfiles } = await import("../../src/altimate/native/connections/dbt-profiles")
124127
const profiles = await parseDbtProfiles()

0 commit comments

Comments
 (0)