Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-ui): r5-l2 normalize pending selection decisions
Josuébbc9b0460967
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/pendingSelectionMode.r12.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/pendingSelectionMode.r12.test.tsxnew file mode 100644index 000000000..75fbd3891--- /dev/null+++ b/desktop-app/ui/src/hooks/domain/__tests__/pendingSelectionMode.r12.test.tsx@@ -0,0 +1,60 @@+// @vitest-environment jsdom+import { afterEach, expect, it, vi } from 'vitest'+import { act, cleanup, waitFor } from '@testing-library/react'+import { DESKTOP_ROUTES } from '@constants/navigation'+import { deferred } from './__fixtures__/catalogFixtures'+import { renderController } from './__fixtures__/controllerHarness'+import { installMockClerum, uninstallMockClerum } from './__fixtures__/mockClerum'++afterEach(() => {+ cleanup()+ vi.restoreAllMocks()+ uninstallMockClerum()+})++it.each(['notification', 'explicit clear', 'latest', 'suppressed target'] as const)(+ '%s owns its declared selection mode without conflating no-chat intent',+ async producer => {+ const clerum = installMockClerum()+ await clerum.chat.create('agent-x', 'visible')+ await clerum.chat.upsertMessages('agent-x', 'visible', [+ { id: 'actual-history', role: 'user', content: 'visible real history', timestamp: 1 },+ ])+ const controller = renderController({ navItem: DESKTOP_ROUTES.chat, loadMenuData: false })+ await waitFor(() => expect(controller.result.current.chatListLoading).toBe(false))+ const gate = deferred<void>()+ clerum.chat.setLastActive.mockImplementationOnce(() => gate.promise)+ let request!: Promise<void>+ act(() => {+ request = controller.result.current.switchToChat('agent-x', 'visible')+ })+ expect(controller.result.current.chatMessagesLoading).toBe(true)+ act(() => {+ if (producer === 'latest') {+ controller.result.current.setPendingChatSelection('agent-x', null, { selectLatest: true })+ } else if (producer === 'suppressed target') {+ // Supported public API combination: suppressing a named target records+ // none but is not the no-chat notification's view-preserving intent.+ controller.result.current.setPendingChatSelection('agent-x', 'other', {+ suppressAutoSelect: true,+ })+ } else {+ controller.result.current.setPendingChatSelection('agent-x', null)+ if (producer === 'explicit clear') controller.result.current.clearActiveChat()+ }+ })+ expect(controller.result.current.chatMessagesLoading).toBe(producer === 'notification')+ await act(async () => {+ gate.resolve()+ await request+ })+ expect(controller.result.current.activeChatId).toBe(+ producer === 'explicit clear' ? null : 'visible'+ )+ expect(controller.result.current.chatMessages).toEqual(+ producer === 'notification' ? [expect.objectContaining({ id: 'actual-history' })] : []+ )+ expect(controller.result.current.chatMessagesLoading).toBe(false)+ expect(controller.spies.pushToast).not.toHaveBeenCalled()+ }+)diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.tsindex cc1223b37..a78920ea5 100644--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts@@ -3974,12 +3974,15 @@ export function useAgentChatController({} = {}) => {if (isHostAccessBlocked(agentName) || (chatId && isChatDeleted(agentName, chatId))) return- const selectsSpecificChat = Boolean(- chatId && !options.selectLatest && !options.suppressAutoSelect- )+ const selectionMode = options.selectLatest+ ? 'latest'+ : options.suppressAutoSelect || !chatId+ ? 'none'+ : 'specific'+ const selectsSpecificChat = selectionMode === 'specific'const preservesCurrentChatRoute = Boolean(!chatId &&- !options.selectLatest &&+ selectionMode === 'none' &&selectedAgent === agentName &&navItem === DESKTOP_ROUTES.chat)@@ -4009,17 +4012,17 @@ export function useAgentChatController({// history completion here. Route/agent changes and specific/latest// selections still advance selection ownership before their effects run.if (!preservesCurrentChatRoute) beginSelectionIntent(selectsSpecificChat)- if (options.selectLatest) {+ if (selectionMode === 'latest') {writePendingSelection(agentName, { mode: 'latest', chatId: null })return}- if (options.suppressAutoSelect || !chatId) {+ if (selectionMode === 'none') {writePendingSelection(agentName, { mode: 'none', chatId: null })return}const specificSelection: Extract<PendingChatSelection, { mode: 'specific' }> = {mode: 'specific',- chatId,+ chatId: chatId!,}if (options.title) specificSelection.title = options.titleif (options.isRemote !== undefined) specificSelection.isRemote = options.isRemote@@ -4038,7 +4041,7 @@ export function useAgentChatController({cancelOlderMessagesLoad()loadedLocalMessageCountRef.current = 0if (options.title) {- upsertProvisionalEntry(chatId, options.title, options.isRemote === true)+ upsertProvisionalEntry(chatId!, options.title, options.isRemote === true)}},[