22 * Copyright (c) Microsoft Corporation. All rights reserved.
33 *--------------------------------------------------------------------------------------------*/
44
5+ import { randomUUID } from "node:crypto" ;
56import { describe , expect , it } from "vitest" ;
67import { approveAll } from "../../src/index.js" ;
78import type { CustomAgentConfig } from "../../src/index.js" ;
@@ -127,6 +128,34 @@ describe("Agent Selection RPC", async () => {
127128
128129 await session . disconnect ( ) ;
129130 } ) ;
131+
132+ it ( "should call agent reload" , async ( ) => {
133+ const reloadAgent : CustomAgentConfig = {
134+ name : `reload-test-agent-${ randomUUID ( ) . replaceAll ( "-" , "" ) } ` ,
135+ displayName : "Reload Test Agent" ,
136+ description : "Used by the agent reload RPC test." ,
137+ prompt : "You are a reload test agent." ,
138+ } ;
139+
140+ const session = await client . createSession ( {
141+ onPermissionRequest : approveAll ,
142+ customAgents : [ reloadAgent ] ,
143+ } ) ;
144+
145+ const before = await session . rpc . agent . list ( ) ;
146+ const match = before . agents . find ( ( agent ) => agent . name === reloadAgent . name ) ;
147+ expect ( match ) . toBeDefined ( ) ;
148+ expect ( match ! . displayName ) . toBe ( reloadAgent . displayName ) ;
149+ expect ( match ! . description ) . toBe ( reloadAgent . description ) ;
150+
151+ const result = await session . rpc . agent . reload ( ) ;
152+ expect ( result . agents ) . toBeDefined ( ) ;
153+
154+ const current = await session . rpc . agent . list ( ) ;
155+ expect ( summarizeAgents ( result . agents ) ) . toEqual ( summarizeAgents ( current . agents ) ) ;
156+
157+ await session . disconnect ( ) ;
158+ } ) ;
130159} ) ;
131160
132161describe ( "Session Compact RPC" , async ( ) => {
@@ -147,3 +176,7 @@ describe("Session Compact RPC", async () => {
147176 await session . disconnect ( ) ;
148177 } , 60000 ) ;
149178} ) ;
179+
180+ function summarizeAgents ( agents : { name : string ; displayName : string } [ ] ) {
181+ return agents . map ( ( agent ) => `${ agent . name } \x00${ agent . displayName } ` ) . sort ( ) ;
182+ }
0 commit comments