Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: keep database observers outside phase deadlines (#13369)
[._.]/ Adam Eivyf91466835e3a
diff --git a/server/test/dbPhaseDiagnostics.js b/server/test/dbPhaseDiagnostics.jsindex 943207ec75..3031b93898 100644--- a/server/test/dbPhaseDiagnostics.js+++ b/server/test/dbPhaseDiagnostics.js@@ -15,7 +15,7 @@ const SNAPSHOT_SQL = `SELECT a.pid = $1 AS fixture, count(*) OVER ()::int AS sesORDER BY fixture DESC, run_lock DESC, a.pid LIMIT 16`;const fields = ['fixture', 'session_count', 'state', 'wait_event_type', 'wait_event', 'transaction_ms', 'blockers', 'waiting_locks', 'run_lock'];-/** Opt-in observation; the caller owns the observer connection and its query deadline. */+/** Opt-in observation; after its test bodies settle, the caller drains before closing the observer. */export function createDbPhaseDiagnostics({ onTestFailed, observer, fixturePid, enabled = false,write = line => process.stdout.write(`${line}\n`), intervalMs = 1000 } = {}) {const track = createTestPhaseDiagnostics(onTestFailed);@@ -59,9 +59,9 @@ export function createDbPhaseDiagnostics({ onTestFailed, observer, fixturePid, eclearInterval(timer);record({ phase: name, state: 'settled', ...metrics() });active = undefined;- await pending;}}),+ // Sampling must not extend the timed operation; teardown owns observer settlement.drain: () => pending,};}diff --git a/server/test/dbPhaseDiagnostics.test.js b/server/test/dbPhaseDiagnostics.test.jsindex 8b477596b5..5106de15e6 100644--- a/server/test/dbPhaseDiagnostics.test.js+++ b/server/test/dbPhaseDiagnostics.test.js@@ -3,10 +3,10 @@ import { createDbPhaseDiagnostics } from './dbPhaseDiagnostics.js';afterEach(() => vi.useRealTimers());-// Pins the observer's privacy boundary and prevents a slow observer from-// spawning overlapping work or surviving the operation's settlement.-it('bounds test-only snapshots and drains the observer without exposing query text', async () => {- vi.useFakeTimers();+// A slow observer must not spend a later phase's test budget. Teardown+// still owns its completion before closing the diagnostic connection.+it('settles the operation independently and drains bounded private observations before teardown', async () => {+ vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval', 'performance'] });const snapshot = Promise.withResolvers();const operation = Promise.withResolvers();const observer = { query: vi.fn(() => snapshot.promise) };@@ -24,11 +24,22 @@ it('bounds test-only snapshots and drains the observer without exposing query telet settled = false;void run.then(() => { settled = true; });await vi.advanceTimersByTimeAsync(5000);- expect(settled).toBe(false);+ const settledEvidence = lines.map(line => JSON.parse(line.slice('DB phases: '.length))).find(event => event.state === 'settled');+ expect(settledEvidence.elapsedMs).toBe(5000);+ expect(settled).toBe(true);+ expect(await run).toBe('original result');+ expect(await diagnostics.phase('compact-public-query', () => 'next result')).toBe('next result');+ const failure = new Error('original operation failure');+ await expect(diagnostics.phase('compact-explain', () => { throw failure; })).rejects.toBe(failure);+ expect(observer.query).toHaveBeenCalledOnce();+ let drained = false;+ const drain = diagnostics.drain().then(() => { drained = true; });+ await vi.advanceTimersByTimeAsync(5000);+ expect(drained).toBe(false);snapshot.resolve({ rows: [{ fixture: true, state: 'active', wait_event: 'DataFileRead',query: 'private query', client_addr: 'private address' }] });- expect(await run).toBe('original result');- await diagnostics.drain();+ await drain;+ expect(drained).toBe(true);await vi.advanceTimersByTimeAsync(5000);expect(observer.query).toHaveBeenCalledOnce();expect(lines.join('\n')).toContain('DataFileRead');