@@ -325,6 +325,60 @@ describe("CodexCliSubagent", () => {
325325 expect ( codexcliSubagent . getBody ( ) ) . not . toContain ( "description" ) ;
326326 expect ( codexcliSubagent . getBody ( ) ) . not . toContain ( "developer_instructions" ) ;
327327 } ) ;
328+
329+ it ( "should use same relative path when global is true" , ( ) => {
330+ const rulesyncSubagent = new RulesyncSubagent ( {
331+ baseDir : testDir ,
332+ relativeDirPath : RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH ,
333+ relativeFilePath : "global-agent.md" ,
334+ frontmatter : {
335+ targets : [ "codexcli" ] ,
336+ name : "global-agent" ,
337+ description : "A global agent" ,
338+ } ,
339+ body : "Global agent content" ,
340+ validate : true ,
341+ } ) ;
342+
343+ const codexcliSubagent = CodexCliSubagent . fromRulesyncSubagent ( {
344+ baseDir : testDir ,
345+ relativeDirPath : RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH ,
346+ rulesyncSubagent,
347+ validate : true ,
348+ global : true ,
349+ } ) as CodexCliSubagent ;
350+
351+ expect ( codexcliSubagent ) . toBeInstanceOf ( CodexCliSubagent ) ;
352+ expect ( codexcliSubagent . getRelativeDirPath ( ) ) . toBe ( join ( ".codex" , "agents" ) ) ;
353+ expect ( codexcliSubagent . getBody ( ) ) . toContain ( 'name = "global-agent"' ) ;
354+ } ) ;
355+
356+ it ( "should use same relative path when global is false" , ( ) => {
357+ const rulesyncSubagent = new RulesyncSubagent ( {
358+ baseDir : testDir ,
359+ relativeDirPath : RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH ,
360+ relativeFilePath : "local-agent.md" ,
361+ frontmatter : {
362+ targets : [ "codexcli" ] ,
363+ name : "local-agent" ,
364+ description : "A local agent" ,
365+ } ,
366+ body : "Local agent content" ,
367+ validate : true ,
368+ } ) ;
369+
370+ const codexcliSubagent = CodexCliSubagent . fromRulesyncSubagent ( {
371+ baseDir : testDir ,
372+ relativeDirPath : RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH ,
373+ rulesyncSubagent,
374+ validate : true ,
375+ global : false ,
376+ } ) as CodexCliSubagent ;
377+
378+ expect ( codexcliSubagent ) . toBeInstanceOf ( CodexCliSubagent ) ;
379+ expect ( codexcliSubagent . getRelativeDirPath ( ) ) . toBe ( join ( ".codex" , "agents" ) ) ;
380+ expect ( codexcliSubagent . getBody ( ) ) . toContain ( 'name = "local-agent"' ) ;
381+ } ) ;
328382 } ) ;
329383
330384 describe ( "fromFile" , ( ) => {
@@ -372,6 +426,28 @@ describe("CodexCliSubagent", () => {
372426 } ) ,
373427 ) . rejects . toThrow ( ) ;
374428 } ) ;
429+
430+ it ( "should load with same relative path when global is true" , async ( ) => {
431+ const agentsDir = join ( testDir , ".codex" , "agents" ) ;
432+ const tomlContent = [
433+ 'name = "global-test-agent"' ,
434+ 'description = "A global test agent"' ,
435+ 'developer_instructions = "Global agent body"' ,
436+ ] . join ( "\n" ) ;
437+
438+ await writeFileContent ( join ( agentsDir , "global-test-agent.toml" ) , tomlContent ) ;
439+
440+ const subagent = await CodexCliSubagent . fromFile ( {
441+ baseDir : testDir ,
442+ relativeFilePath : "global-test-agent.toml" ,
443+ validate : true ,
444+ global : true ,
445+ } ) ;
446+
447+ expect ( subagent ) . toBeInstanceOf ( CodexCliSubagent ) ;
448+ expect ( subagent . getRelativeDirPath ( ) ) . toBe ( join ( ".codex" , "agents" ) ) ;
449+ expect ( subagent . getBody ( ) ) . toContain ( 'name = "global-test-agent"' ) ;
450+ } ) ;
375451 } ) ;
376452
377453 describe ( "validate" , ( ) => {
0 commit comments