altimate-code icon indicating copy to clipboard operation
altimate-code copied to clipboard

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

Open suryaiyer95 opened this issue 8 months ago • 1 comments

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.

suryaiyer95 avatar Mar 26 '26 03:03 suryaiyer95

Closing — this was fixed in commit 33c331b (#529): "fix: three simple bugs — locale duration, dispatcher reset, impact test count". The dispatcher.reset() now properly clears the lazy registration hook.

kulvirgit avatar Apr 06 '26 22:04 kulvirgit