@@ -94,7 +94,10 @@ describe('Spawn Agents Permissions', () => {
9494 ...options . agentState ,
9595 messageHistory : [ assistantMessage ( 'Mock agent response' ) ] ,
9696 } ,
97- output : { type : 'lastMessage' , value : [ assistantMessage ( 'Mock agent response' ) ] } ,
97+ output : {
98+ type : 'lastMessage' ,
99+ value : [ assistantMessage ( 'Mock agent response' ) ] ,
100+ } ,
98101 }
99102 } )
100103 } )
@@ -189,12 +192,33 @@ describe('Spawn Agents Permissions', () => {
189192 expect ( result ) . toBe ( 'thinker' )
190193 } )
191194
195+ it ( 'should match underscored agent name to hyphenated spawnable agent' , ( ) => {
196+ const spawnableAgents = [ 'thinker' , 'reviewer' , 'file-picker' ]
197+ const result = getMatchingSpawn ( spawnableAgents , 'file_picker' )
198+ expect ( result ) . toBe ( 'file-picker' )
199+ } )
200+
192201 it ( 'should match simple agent name when spawnable has publisher' , ( ) => {
193202 const spawnableAgents = [ 'codebuff/thinker@1.0.0' , 'reviewer' ]
194203 const result = getMatchingSpawn ( spawnableAgents , 'thinker' )
195204 expect ( result ) . toBe ( 'codebuff/thinker@1.0.0' )
196205 } )
197206
207+ it ( 'should match underscored agent name when spawnable has publisher and version' , ( ) => {
208+ const spawnableAgents = [ 'codebuff/file-picker@1.0.0' , 'reviewer' ]
209+ const result = getMatchingSpawn ( spawnableAgents , 'file_picker' )
210+ expect ( result ) . toBe ( 'codebuff/file-picker@1.0.0' )
211+ } )
212+
213+ it ( 'should match underscored published agent ID to hyphenated spawnable agent' , ( ) => {
214+ const spawnableAgents = [ 'codebuff/file-picker@1.0.0' ]
215+ const result = getMatchingSpawn (
216+ spawnableAgents ,
217+ 'codebuff/file_picker@1.0.0' ,
218+ )
219+ expect ( result ) . toBe ( 'codebuff/file-picker@1.0.0' )
220+ } )
221+
198222 it ( 'should match simple agent name when spawnable has version' , ( ) => {
199223 const spawnableAgents = [ 'thinker@1.0.0' , 'reviewer' ]
200224 const result = getMatchingSpawn ( spawnableAgents , 'thinker' )
@@ -274,6 +298,50 @@ describe('Spawn Agents Permissions', () => {
274298 expect ( mockLoopAgentSteps ) . toHaveBeenCalledTimes ( 1 )
275299 } )
276300
301+ it ( 'should allow underscored agent_type when hyphenated agent is spawnable' , async ( ) => {
302+ const parentAgent = createMockAgent ( 'parent' , [ 'file-picker' ] )
303+ const childAgent = createMockAgent ( 'file-picker' )
304+ const sessionState = getInitialSessionState ( mockFileContext )
305+ const toolCall = createSpawnToolCall ( 'file_picker' )
306+
307+ const { output } = await handleSpawnAgents ( {
308+ ...handleSpawnAgentsBaseParams ,
309+ agentState : sessionState . mainAgentState ,
310+ agentTemplate : parentAgent ,
311+ localAgentTemplates : { 'file-picker' : childAgent } ,
312+ toolCall,
313+ } )
314+
315+ expect ( JSON . stringify ( output ) ) . toContain ( 'Mock agent response' )
316+ expect ( mockLoopAgentSteps ) . toHaveBeenCalledTimes ( 1 )
317+ expect ( mockLoopAgentSteps . mock . calls [ 0 ] [ 0 ] . agentState . agentType ) . toBe (
318+ 'file-picker' ,
319+ )
320+ } )
321+
322+ it ( 'should allow underscored published agent_type when hyphenated agent is spawnable' , async ( ) => {
323+ const parentAgent = createMockAgent ( 'parent' , [
324+ 'codebuff/file-picker@1.0.0' ,
325+ ] )
326+ const childAgent = createMockAgent ( 'codebuff/file-picker@1.0.0' )
327+ const sessionState = getInitialSessionState ( mockFileContext )
328+ const toolCall = createSpawnToolCall ( 'codebuff/file_picker@1.0.0' )
329+
330+ const { output } = await handleSpawnAgents ( {
331+ ...handleSpawnAgentsBaseParams ,
332+ agentState : sessionState . mainAgentState ,
333+ agentTemplate : parentAgent ,
334+ localAgentTemplates : { 'codebuff/file-picker@1.0.0' : childAgent } ,
335+ toolCall,
336+ } )
337+
338+ expect ( JSON . stringify ( output ) ) . toContain ( 'Mock agent response' )
339+ expect ( mockLoopAgentSteps ) . toHaveBeenCalledTimes ( 1 )
340+ expect ( mockLoopAgentSteps . mock . calls [ 0 ] [ 0 ] . agentState . agentType ) . toBe (
341+ 'codebuff/file-picker@1.0.0' ,
342+ )
343+ } )
344+
277345 it ( 'should reject spawning when agent is not in spawnableAgents list' , async ( ) => {
278346 const parentAgent = createMockAgent ( 'parent' , [ 'thinker' ] ) // Only allows thinker
279347 const childAgent = createMockAgent ( 'reviewer' )
0 commit comments