📌 fix: Preserve Ephemeral Agent Selections on Optimistic Hydration (#13433)

This commit is contained in:
Danny Avila 2026-05-31 16:32:45 -04:00 committed by GitHub
parent e3cc2a9c62
commit fd5d44162a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 1 deletions

View file

@ -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 }) => (
<RecoilRoot>{children}</RecoilRoot>
);
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);
});
});
});

View file

@ -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;
}