Skip to content

Commit fd5d441

Browse files
authored
πŸ“Œ fix: Preserve Ephemeral Agent Selections on Optimistic Hydration (danny-avila#13433)
1 parent e3cc2a9 commit fd5d441

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import { RecoilRoot, useRecoilValue } from 'recoil';
3+
import { renderHook, act, waitFor } from '@testing-library/react';
4+
5+
import { ephemeralAgentByConvoId, useApplyNewAgentTemplate } from '../agents';
6+
7+
jest.mock('~/utils', () => ({
8+
logger: {
9+
log: jest.fn(),
10+
warn: jest.fn(),
11+
error: jest.fn(),
12+
},
13+
}));
14+
15+
const Wrapper = ({ children }: { children: React.ReactNode }) => (
16+
<RecoilRoot>{children}</RecoilRoot>
17+
);
18+
19+
const useAgentTemplateHarness = (conversationId: string) => {
20+
const applyTemplate = useApplyNewAgentTemplate();
21+
const ephemeralAgent = useRecoilValue(ephemeralAgentByConvoId(conversationId));
22+
return { applyTemplate, ephemeralAgent };
23+
};
24+
25+
describe('useApplyNewAgentTemplate', () => {
26+
it('applies an explicit ephemeral agent when optimistic hydration makes source and target match', async () => {
27+
const conversationId = 'convo-123';
28+
const agent = {
29+
mcp: ['chrome-devtools'],
30+
skills: true,
31+
artifacts: 'default',
32+
web_search: true,
33+
file_search: true,
34+
execute_code: true,
35+
};
36+
const { result } = renderHook(() => useAgentTemplateHarness(conversationId), {
37+
wrapper: Wrapper,
38+
});
39+
40+
await act(async () => {
41+
await result.current.applyTemplate(conversationId, conversationId, agent);
42+
});
43+
44+
await waitFor(() => {
45+
expect(result.current.ephemeralAgent).toEqual(agent);
46+
});
47+
});
48+
});

β€Žclient/src/store/agents.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function useApplyNewAgentTemplate() {
4343
const sourceId = _sourceId || Constants.NEW_CONVO;
4444
logger.log('agents', `Attempting to apply template from "${sourceId}" to "${targetId}"`);
4545

46-
if (targetId === sourceId) {
46+
if (targetId === sourceId && ephemeralAgentState == null) {
4747
logger.warn('agents', `Attempted to apply template to itself ("${sourceId}"). Skipping.`);
4848
return;
4949
}

0 commit comments

Comments
Β (0)