Skip to content

Commit ea0194e

Browse files
anandgupta42claude
andcommitted
fix: re-register dispatcher handlers in dbt test to survive cross-file reset()
The `beforeAll` block relied on ES module import caching to register handlers, but cached imports are no-ops — if `dispatcher.test.ts` runs first and calls `Dispatcher.reset()`, handlers stay cleared. Call `registerAll()` explicitly instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent dcd044d commit ea0194e

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,16 @@ const HAS_DBT = !!DBT_PROJECT
112112
// Tests: dbt profiles auto-discovery
113113
// ---------------------------------------------------------------------------
114114
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.
115+
// Explicitly call registerAll() instead of relying on import side-effects.
116+
// ES module imports are cached, so if dispatcher.test.ts runs first and
117+
// calls Dispatcher.reset() (clearing all handlers + the lazy hook),
118+
// re-importing the register modules is a no-op — handlers stay cleared.
119+
// Calling registerAll() directly re-registers them every time.
120120
beforeAll(async () => {
121-
await import("../../src/altimate/native/connections/register")
122-
await import("../../src/altimate/native/schema/register")
121+
const { registerAll: registerConnections } = await import("../../src/altimate/native/connections/register")
122+
const { registerAll: registerSchema } = await import("../../src/altimate/native/schema/register")
123+
registerConnections()
124+
registerSchema()
123125
})
124126

125127
test("parseDbtProfiles finds connections from ~/.dbt/profiles.yml", async () => {
@@ -253,6 +255,15 @@ describe.skipIf(!HAS_DBT)("Direct dbt Adapter Execution", () => {
253255
// Tests: fallback behavior
254256
// ---------------------------------------------------------------------------
255257
describe("dbt Fallback Behavior", () => {
258+
// Re-register dispatcher handlers in case Dispatcher.reset() was called
259+
// by another test file (e.g., dispatcher.test.ts, tool-error-propagation.test.ts).
260+
beforeAll(async () => {
261+
const { registerAll: registerConnections } = await import("../../src/altimate/native/connections/register")
262+
const { registerAll: registerSchema } = await import("../../src/altimate/native/schema/register")
263+
registerConnections()
264+
registerSchema()
265+
})
266+
256267
test("when dbt not configured, falls back to native driver silently", async () => {
257268
const Registry = await import("../../src/altimate/native/connections/registry")
258269
Registry.reset()

0 commit comments

Comments
 (0)