Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(desktop-app): wait for persistent chat writes in CI

Josuébedaecc56d21
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/mockClerum.ts b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/mockClerum.ts
index 165c0edd3..1c227c209 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/mockClerum.ts
+++ b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/mockClerum.ts
@@ -1,5 +1,5 @@
import { type Mock, inject, vi } from 'vitest'
-import { mkdtempSync, rmSync } from 'node:fs'
+import { mkdtempSync } from 'node:fs'
import { join } from 'node:path'
import { ChatStore } from '../../../../../../src/chatStore'
import type { ChatDeleteFence, ChatMessage } from '../../../../../../src/types'
@@ -19,13 +19,11 @@ import type {} from './mockClerumStoreRoot'
* per-install directory under the run's temporary root, so suites observe the
* merge, delete tombstone and paging behavior the IPC handlers run in
* production. They stay `vi.fn` wrappers, so call assertions and per-test
- * overrides keep working. `uninstallMockClerum` removes the directory; the
- * global setup in `mockClerumStoreRoot.ts` removes the root after the run,
- * including any directory a late store write recreated.
+ * overrides keep working. `uninstallMockClerum` removes the bridge; the global
+ * setup in `mockClerumStoreRoot.ts` removes the store directories after the
+ * run, allowing in-flight writes to finish before cleanup.
*/
-const storeDirs = new Set<string>()
-
type Handler = (event: unknown) => void
// `ReturnType<typeof vi.fn>` resolves to `Mock<Procedure | Constructable>`, and
// that union does not satisfy `(...args: any) => any`. Callers here write
@@ -91,7 +89,6 @@ export function installMockClerum(): MockClerum {
)
}
const storeDir = mkdtempSync(join(root, 'store-'))
- storeDirs.add(storeDir)
const store = new ChatStore(storeDir)
const chat = {
@@ -194,6 +191,4 @@ export function installMockClerum(): MockClerum {
export function uninstallMockClerum(): void {
delete (window as { clerum?: unknown }).clerum
- for (const dir of storeDirs) rmSync(dir, { recursive: true, force: true })
- storeDirs.clear()
}
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/mockClerumStoreRoot.ts b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/mockClerumStoreRoot.ts
index 66c3d50aa..eb7df3763 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/mockClerumStoreRoot.ts
+++ b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/mockClerumStoreRoot.ts
@@ -22,6 +22,6 @@ export default function setup(project: TestProject): () => void {
const root = mkdtempSync(join(tmpdir(), 'mockclerum-'))
project.provide('mockClerumStoreRoot', root)
return () => {
- rmSync(root, { recursive: true, force: true })
+ rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 })
}
}
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useAgentChatController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useAgentChatController.test.tsx
index 98fd39c54..5eb002df5 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useAgentChatController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useAgentChatController.test.tsx
@@ -42,6 +42,21 @@ async function settleMount() {
await waitFor(() => expect(clerum.chat.getIndex).toHaveBeenCalled())
}
+// Sending now persists the optimistic turn through the filesystem-backed
+// ChatStore before subscribing. Under the full parallel Desktop suite, that
+// disk work can exceed Testing Library's one-second default timeout.
+const CHAT_STORE_IO_TIMEOUT_MS = 10_000
+
+async function waitForProgressHandler(taskId: string) {
+ await waitFor(() => expect(clerum.hasProgressHandler(taskId)).toBe(true), {
+ timeout: CHAT_STORE_IO_TIMEOUT_MS,
+ })
+}
+
+function waitForWithFakeTimers<T>(assertion: () => T | Promise<T>) {
+ return vi.waitFor(assertion, { timeout: CHAT_STORE_IO_TIMEOUT_MS })
+}
+
function deferred<T>() {
let resolve!: (value: T) => void
let reject!: (reason?: unknown) => void
@@ -312,7 +327,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
sendResolved = true
})
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'open',
@@ -353,7 +368,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
const sendPromise = act(async () => {
await result.current.handleSendAgentMessage('first message')
})
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'terminal',
@@ -396,7 +411,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
const firstSend = act(async () => {
await result.current.handleSendAgentMessage('m1')
})
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
// Second send while first is in flight — should be silently rejected.
await act(async () => {
@@ -422,7 +437,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
const sendPromise = act(async () => {
await result.current.handleSendAgentMessage('hola')
})
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'terminal',
@@ -459,7 +474,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await act(async () => {
await controller.result.current.handleSendAgentMessage('question')
})
- await waitFor(() => expect(clerum.hasProgressHandler('task-old-team')).toBe(true))
+ await waitForProgressHandler('task-old-team')
clerum.emitTaskProgress('task-old-team', {
type: 'terminal',
@@ -498,7 +513,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
const sendPromise = act(async () => {
await result.current.handleSendAgentMessage('hola')
})
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'terminal',
@@ -521,7 +536,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
// Start the send bare (it stays in flight until terminal); read state
// after the suspended event flushes, before resolving.
const sendPromise = result.current.handleSendAgentMessage('hola').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'open',
@@ -581,7 +596,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
// send persists the user turn to the real ChatStore first, which is disk
// I/O that fake timers do not advance: poll for the subscription instead.
await act(async () => {
- await vi.waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForWithFakeTimers(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
})
await act(async () => {
@@ -599,7 +614,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
// The failure toast follows the store write of the error reply.
await act(async () => {
- await vi.waitFor(() =>
+ await waitForWithFakeTimers(() =>
expect(spies.pushToast).toHaveBeenCalledWith(expect.stringContaining('failed'), 'error')
)
})
@@ -614,7 +629,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await settleMount()
const sendPromise = result.current.handleSendAgentMessage('hola').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'open',
@@ -657,7 +672,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
// The user turn is persisted to the real ChatStore (disk I/O fake timers do
// not advance) before the subscription is wired: poll for it.
await act(async () => {
- await vi.waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForWithFakeTimers(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
})
await act(async () => {
@@ -669,7 +684,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
// The timeout's recovery reads the store (disk I/O) before it settles the
// entry as an error: poll for the settled state.
await act(async () => {
- await vi.waitFor(() => {
+ await waitForWithFakeTimers(() => {
const progress = result.current.progressByAgentMessage['agent-x']
const entry = progress && Object.values(progress)[0]
expect(entry?.status).toBe('error')
@@ -692,7 +707,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await settleMount()
const sendPromise = result.current.handleSendAgentMessage('hola').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'open',
@@ -739,7 +754,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await settleMount()
const sendPromise = result.current.handleSendAgentMessage('hola').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'open',
@@ -783,7 +798,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await settleMount()
const sendPromise = result.current.handleSendAgentMessage('hola').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
const chatId = result.current.activeChatId!
const key = makeTaskKey('agent-x', chatId)
await act(async () => {
@@ -829,7 +844,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await settleMount()
const sendPromise = result.current.handleSendAgentMessage('hola').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'open',
@@ -858,7 +873,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await settleMount()
const sendPromise = result.current.handleSendAgentMessage('hola').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'open',
@@ -924,7 +939,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await settleMount()
const sendPromise = result.current.handleSendAgentMessage('q1').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
// First stream loss → reconcile → rejoin (re-subscribes the SSE).
await act(async () => {
@@ -1015,7 +1030,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await settleMount()
const sendPromise = result.current.handleSendAgentMessage('hola').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'open',
@@ -1083,7 +1098,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
await settleMount()
const sendPromise = result.current.handleSendAgentMessage('hola').catch(() => undefined)
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitTaskProgress('task-abc', {
type: 'open',
@@ -1141,7 +1156,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
expect(currentEntry()?.status).toBe('streaming')
// activity event is appended to the message's event list
- await waitFor(() => expect(clerum.hasProgressHandler('task-abc')).toBe(true))
+ await waitForProgressHandler('task-abc')
await act(async () => {
clerum.emitActivity('agent-x', {
type: 'activity',
@@ -1789,7 +1804,7 @@ describe('useAgentChatController — characterization (D.0)', () => {
const sendPromise = act(async () => {
await result.current.handleSendAgentMessage('persist me')
})
- await waitFor(() => expect(clerum.hasProgressHandler('task-ga')).toBe(true))
+ await waitForProgressHandler('task-ga')
await act(async () => {
clerum.emitTaskProgress('task-ga', { type: 'open', taskId: 'task-ga', hostRef: 'agent-x' })
clerum.emitTaskProgress('task-ga', {
@@ -1837,7 +1852,7 @@ describe('interrupted generated-file contract', () => {
const send = act(async () => {
await result.current.handleSendAgentMessage('Create a report')
})
- await waitFor(() => expect(clerum.hasProgressHandler('task-file')).toBe(true))
+ await waitForProgressHandler('task-file')
await act(async () => {
clerum.emitTaskProgress('task-file', {
type: 'terminal',