Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-ui): r10-l3 bind shared switch execution to scope
Josuébf9bd9b6ed30
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/pendingSwitchScope.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/pendingSwitchScope.test.tsxnew file mode 100644index 000000000..55a92ed3b--- /dev/null+++ b/desktop-app/ui/src/hooks/domain/__tests__/pendingSwitchScope.test.tsx@@ -0,0 +1,59 @@+// @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('starts new scoped history instead of joining the old-team pending switch', async () => {+ const clerum = installMockClerum()+ await clerum.chat.create('agent-x', 'chat-b')+ await clerum.chat.upsertMessages('agent-x', 'chat-b', [+ { id: 'real-history', role: 'user', content: 'real chat-b history', timestamp: 1 },+ ])+ const controller = renderController({ loadMenuData: false })+ await waitFor(() => expect(controller.result.current.chatListLoading).toBe(false))+ const gate = deferred<void>()+ const entered = deferred<void>()+ const setLastActive = clerum.chat.setLastActive.getMockImplementation()!+ clerum.chat.setLastActive.mockImplementationOnce(async () => {+ entered.resolve()+ await gate.promise+ })+ clerum.chat.setLastActive.mockImplementation(setLastActive)+ let request!: Promise<void>+ act(() => {+ controller.result.current.setPendingChatSelection('agent-x', 'chat-b', { deferSwitch: true })+ request = controller.result.current.switchToChat('agent-x', 'chat-b', {+ onCurrentError: () => undefined,+ })+ })+ const observed = request.catch(error => error)+ await entered.promise+ act(() =>+ controller.rerender({+ navItem: DESKTOP_ROUTES.chat,+ currentTeamId: 'team-2',+ chatAuthorityTeamId: 'team-2',+ })+ )+ const error = new Error('old-team switch failed')+ await act(async () => {+ gate.reject(error)+ expect(await observed).toBe(error)+ })+ await waitFor(() => {+ expect(controller.result.current.chatMessagesLoading).toBe(false)+ expect(controller.result.current.activeChatId).toBe('chat-b')+ expect(controller.result.current.chatMessages).toEqual([+ expect.objectContaining({ id: 'real-history' }),+ ])+ })+})diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.tsindex 20b3c65ad..e4f7d9968 100644--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts@@ -1219,7 +1219,13 @@ export function useAgentChatController({})pendingChatSwitchRequestRef.current =readPendingSelection(agentRef)?.mode === 'specific'- ? { agentRef, chatId, revision: selectionIntentRevision, promise }+ ? {+ agentRef,+ chatId,+ revision: selectionIntentRevision,+ scope: currentAuthScopeRef.current,+ promise,+ }: nullawait promise},@@ -1458,6 +1464,7 @@ export function useAgentChatController({const sharesPendingSwitch = Boolean(requestedSelection?.mode === 'specific' &&pendingSwitch?.revision === selectionIntentRevision &&+ pendingSwitch.scope === currentAuthScopeRef.current &&pendingSwitch.agentRef === selectedAgent &&pendingSwitch.chatId === requestedSelection.chatId)diff --git a/desktop-app/ui/src/lib/chatSwitchRequest.types.ts b/desktop-app/ui/src/lib/chatSwitchRequest.types.tsindex 33ed4a2a2..4df9c9ff3 100644--- a/desktop-app/ui/src/lib/chatSwitchRequest.types.ts+++ b/desktop-app/ui/src/lib/chatSwitchRequest.types.ts@@ -2,5 +2,6 @@ export interface PendingChatSwitchRequest {agentRef: stringchatId: stringrevision: number+ scope: stringpromise: Promise<void>}