Skip to content

fix: dispatcher.reset() doesn't clear lazy registration hook, causing flaky test failures #468

@suryaiyer95

Description

@suryaiyer95

Bug

Dispatcher.reset() clears the handler map but doesn't clear _ensureRegistered (the lazy registration hook). When dbt-first-execution.test.ts runs before dispatcher.test.ts, the import side-effects call setRegistrationHook(). Then reset() clears handlers but leaves the hook alive. On the next call(), the hook fires, re-registers all handlers, and the "no handler" test passes unexpectedly.

Failing tests (flaky on main)

  • Dispatcher > call — no handler > throws when no native handler registered
  • dbt Profiles Auto-Discovery > dbt.profiles dispatcher method returns connections
  • dbt Profiles Auto-Discovery > warehouse.discover includes dbt profiles
  • dbt Fallback Behavior > when dbt not configured, falls back to native driver silently
  • dbt Fallback Behavior > explicit warehouse param bypasses dbt entirely
  • buildTraceFile — status transitions > status progression

Fix

One-line change in packages/opencode/src/altimate/native/dispatcher.ts:

export function reset(): void {
  nativeHandlers.clear()
  _ensureRegistered = null  // ← add this
}

Verified locally: all 13 tests pass, 0 fail.

Context

Found during PR #467 CI investigation. These failures are pre-existing on main and surface non-deterministically based on Bun's test file ordering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions