From fd5d44162a458290f92db7b436e86e72ea6fdbfe Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Sun, 31 May 2026 16:32:45 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=8C=20fix:=20Preserve=20Ephemeral=20Ag?= =?UTF-8?q?ent=20Selections=20on=20Optimistic=20Hydration=20(#13433)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/store/__tests__/agents.spec.tsx | 48 ++++++++++++++++++++++ client/src/store/agents.ts | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 client/src/store/__tests__/agents.spec.tsx diff --git a/client/src/store/__tests__/agents.spec.tsx b/client/src/store/__tests__/agents.spec.tsx new file mode 100644 index 0000000000..0d28ccca75 --- /dev/null +++ b/client/src/store/__tests__/agents.spec.tsx @@ -0,0 +1,48 @@ +import React from 'react'; +import { RecoilRoot, useRecoilValue } from 'recoil'; +import { renderHook, act, waitFor } from '@testing-library/react'; + +import { ephemeralAgentByConvoId, useApplyNewAgentTemplate } from '../agents'; + +jest.mock('~/utils', () => ({ + logger: { + log: jest.fn(), + warn: jest.fn(), + error: jest.fn(), + }, +})); + +const Wrapper = ({ children }: { children: React.ReactNode }) => ( + {children} +); + +const useAgentTemplateHarness = (conversationId: string) => { + const applyTemplate = useApplyNewAgentTemplate(); + const ephemeralAgent = useRecoilValue(ephemeralAgentByConvoId(conversationId)); + return { applyTemplate, ephemeralAgent }; +}; + +describe('useApplyNewAgentTemplate', () => { + it('applies an explicit ephemeral agent when optimistic hydration makes source and target match', async () => { + const conversationId = 'convo-123'; + const agent = { + mcp: ['chrome-devtools'], + skills: true, + artifacts: 'default', + web_search: true, + file_search: true, + execute_code: true, + }; + const { result } = renderHook(() => useAgentTemplateHarness(conversationId), { + wrapper: Wrapper, + }); + + await act(async () => { + await result.current.applyTemplate(conversationId, conversationId, agent); + }); + + await waitFor(() => { + expect(result.current.ephemeralAgent).toEqual(agent); + }); + }); +}); diff --git a/client/src/store/agents.ts b/client/src/store/agents.ts index 13136ef34e..139a76f07d 100644 --- a/client/src/store/agents.ts +++ b/client/src/store/agents.ts @@ -43,7 +43,7 @@ export function useApplyNewAgentTemplate() { const sourceId = _sourceId || Constants.NEW_CONVO; logger.log('agents', `Attempting to apply template from "${sourceId}" to "${targetId}"`); - if (targetId === sourceId) { + if (targetId === sourceId && ephemeralAgentState == null) { logger.warn('agents', `Attempted to apply template to itself ("${sourceId}"). Skipping.`); return; }