File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff 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 }
You canβt perform that action at this time.
0 commit comments