@@ -135,14 +135,21 @@ async function callToolRaw(
135135 } ;
136136}
137137
138+ function parseFleetJson ( content : string ) : Record < string , unknown > {
139+ expect ( content ) . toContain ( "\n" ) ;
140+ const parsed = JSON . parse ( content ) as Record < string , unknown > ;
141+ expect ( JSON . stringify ( parsed , null , 2 ) ) . toBe ( content ) ;
142+ return parsed ;
143+ }
144+
138145async function callTool (
139146 tool :
140147 | ReturnType < typeof createSpawnAgentTool >
141148 | ReturnType < typeof createWaitAgentsTool > ,
142149 args : Record < string , unknown > ,
143150) : Promise < Record < string , unknown > > {
144151 const { content } = await callToolRaw ( tool , args ) ;
145- return JSON . parse ( content ) ;
152+ return parseFleetJson ( content ) ;
146153}
147154
148155describe ( "spawn_agent" , ( ) => {
@@ -196,6 +203,7 @@ describe("spawn_agent", () => {
196203 } ) ;
197204
198205 expect ( result . isError ) . toBe ( true ) ;
206+ expect ( result . content . startsWith ( "Error:" ) ) . toBe ( true ) ;
199207 expect ( result . content ) . toContain ( "profile orchestrators are not supported" ) ;
200208 expect ( runCalled ) . toBe ( false ) ;
201209 expect ( deps . sessions . list ( ) ) . toEqual ( [ ] ) ;
@@ -291,6 +299,17 @@ describe("spawn_agent + wait_agents", () => {
291299 defined ( gates [ 2 ] ) . resolve ( { report : "third" } ) ;
292300 } ) ;
293301
302+ test ( "wait_agents with no uncollected agents returns empty pretty-printed results" , async ( ) => {
303+ const deps = makeDeps ( async ( ) => ( { report : "unused" } ) ) ;
304+ const wait = createWaitAgentsTool ( {
305+ sessions : deps . sessions ,
306+ fleetRecords : deps . fleetRecords ,
307+ } ) ;
308+ const { content } = await callToolRaw ( wait , { timeout_ms : 50 } ) ;
309+ const parsed = parseFleetJson ( content ) ;
310+ expect ( parsed ) . toEqual ( { results : [ ] , timed_out : false } ) ;
311+ } ) ;
312+
294313 test ( "wait_agents times out on a still-running agent without cancelling it, and can be called again" , async ( ) => {
295314 const gate = deferred < RunSubAgentResult > ( ) ;
296315 const deps = makeDeps ( async ( ) => gate . promise ) ;
@@ -1975,7 +1994,7 @@ describe("list_agents", () => {
19751994 typeof raw . content === "string"
19761995 ? raw . content
19771996 : JSON . stringify ( raw . content ) ;
1978- const parsed = JSON . parse ( content ) as {
1997+ const parsed = parseFleetJson ( content ) as {
19791998 agents : {
19801999 agent_id : string ;
19812000 status : string ;
@@ -2893,7 +2912,15 @@ describe("admission queue", () => {
28932912 } ,
28942913 new AbortController ( ) . signal ,
28952914 ) ;
2896- expect ( raw . content ) . toContain ( '"status":"interrupted"' ) ;
2915+ const interrupted = parseFleetJson (
2916+ typeof raw . content === "string"
2917+ ? raw . content
2918+ : JSON . stringify ( raw . content ) ,
2919+ ) ;
2920+ expect ( interrupted ) . toEqual ( {
2921+ agent_id : result . agent_id ,
2922+ status : "interrupted" ,
2923+ } ) ;
28972924 expect ( deps . sessions . get ( result . agent_id as string ) ?. lifecycleStatus ) . toBe (
28982925 "interrupted" ,
28992926 ) ;
0 commit comments