test(supervisor): update runner fixture mock for #2750 lock path

tryAcquireDbLock now acquires via engine.executeRaw (signal-boundable)
and releases via engine.executeRawDirect instead of the sql tagged
template. The fixture's mock engine returned [] from executeRaw, so
every spawned supervisor failed lock acquisition and exited LOCK_HELD
(2), breaking all 8 supervisor integration tests. The mock now returns
the lock row for gbrain_cycle_locks queries and stubs executeRawDirect.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-07-22 10:53:10 -07:00
co-authored by Claude Fable 5
parent 553515c82c
commit 9e044021ef
+9 -6
View File
@@ -24,15 +24,18 @@ import type { BrainEngine } from '../../src/core/engine.ts';
// Mock engine: healthCheck() calls engine.executeRaw; return empty rows so
// the query path exercises without needing Postgres.
//
// #1849: start() now acquires the queue-scoped DB singleton lock via
// tryAcquireDbLock, which uses the postgres `sql` tagged-template escape hatch.
// The stub returns a single row from every call so acquire succeeds (length 1
// → acquired) and refresh/release are no-ops. Each spawned runner is a fresh
// process, so there's no cross-test lock state to clean up.
// #1849: start() acquires the queue-scoped DB singleton lock via
// tryAcquireDbLock. #2750 routed the acquire upsert through engine.executeRaw
// (signal-boundable) and release through engine.executeRawDirect, so the
// stub returns a single row from the lock upsert (length 1 → acquired) and
// empty rows everywhere else. Each spawned runner is a fresh process, so
// there's no cross-test lock state to clean up.
const sqlStub = (..._args: unknown[]) => Promise.resolve([{ id: 'supervisor-lock' }]);
const mockEngine: Partial<BrainEngine> = {
kind: 'postgres' as const,
executeRaw: async () => [],
executeRaw: async (query: string) =>
query.includes('gbrain_cycle_locks') ? [{ id: 'supervisor-lock' }] : [],
executeRawDirect: async () => [],
sql: sqlStub,
} as unknown as BrainEngine;