Skip to content

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

TypeScript

test(desktop): witness the Latest updater epoch guard and logout memo clear

Alfredo Lopezb688afdf5bc5
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx
index 47f79604a..277b57abc 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx
@@ -268,6 +268,55 @@ describe('per-Host Latest sessions publication', () => {
expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual(['remote-a'])
})
+ it('discards a page whose Host authority epoch advances after the publication check, inside its updater', async () => {
+ const pendingB = deferred<SessionsListResult>()
+ let bResolved = false
+ let armed = false
+ let bEpochReadsSinceArm = 0
+ // After B's response the loader reads B's epoch twice (post-read and
+ // pre-publication checks) before its `setLatestChatSessions` updater reads
+ // it a third time. From that third read on, B's authority has moved.
+ const getHostAuthorityEpoch = (agentRef: string) => {
+ if (!armed || agentRef !== HOST_B) return 0
+ bEpochReadsSinceArm += 1
+ return bEpochReadsSinceArm > 2 ? 1 : 0
+ }
+ clerum.chat.getIndex.mockResolvedValue(localIndex([]))
+ clerum.rpc.listSessions.mockImplementation((agentRef: string) =>
+ agentRef === HOST_B
+ ? pendingB.promise.then(page => {
+ bResolved = true
+ return page
+ })
+ : Promise.resolve(serverSessions([{ agent: HOST_A, chatId: 'remote-a' }]))
+ )
+ const controller = renderController({
+ selectedAgent: null,
+ agentNames: HOSTS,
+ getHostAuthorityEpoch,
+ })
+ await waitFor(() =>
+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual([
+ 'remote-a',
+ ])
+ )
+ expect(clerum.rpc.listSessions).toHaveBeenCalledWith(HOST_B, undefined, {
+ agent: HOST_B,
+ limit: 50,
+ })
+
+ await act(async () => {
+ armed = true
+ pendingB.resolve(serverSessions([{ agent: HOST_B, chatId: 'moved-epoch-b' }]))
+ await pendingB.promise
+ })
+
+ // Liveness: B's catalog read resolved and the updater-time check ran.
+ expect(bResolved).toBe(true)
+ expect(bEpochReadsSinceArm).toBeGreaterThan(2)
+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual(['remote-a'])
+ })
+
it('flushes only the arriving Host offline renames without spending another Host retry budget', async () => {
const pendingA = deferred<SessionsListResult>()
const pendingB = deferred<SessionsListResult>()
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.transcriptMemo.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.transcriptMemo.test.tsx
index fd1bf36b6..546d9d465 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.transcriptMemo.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.transcriptMemo.test.tsx
@@ -354,6 +354,7 @@ describe('switchToChat transcript memo (#1091 A9)', () => {
const invalidations = [
['no invalidating event (control), reopening is served from memory', 'none', false],
['a team change, reopening opens blank', 'team', true],
+ ['a logout and login, reopening opens blank', 'logout', true],
['resetChat, reopening opens blank', 'reset', true],
['a confirmed revocation of the Host, reopening opens blank', 'revoked', true],
['an uncertain hold of the Host, reopening opens blank', 'uncertain', true],
@@ -378,6 +379,9 @@ describe('switchToChat transcript memo (#1091 A9)', () => {
if (event === 'team') {
act(() => controller.rerender({ currentTeamId: 'team-2', chatAuthorityTeamId: 'team-2' }))
act(() => controller.rerender({ currentTeamId: 'team-1', chatAuthorityTeamId: 'team-1' }))
+ } else if (event === 'logout') {
+ act(() => controller.rerender({ isAuthenticated: false }))
+ act(() => controller.rerender({ isAuthenticated: true }))
} else if (event === 'reset') {
act(() => controller.result.current.resetChat())
} else if (event === 'revoked' || event === 'uncertain') {