@@ -512,3 +512,118 @@ test("explicit Truncate.DIR deny is respected", async () => {
512512 } ,
513513 } )
514514} )
515+
516+ // Tests for Agent.defaultAgent()
517+
518+ test ( "defaultAgent returns build when no default_agent config" , async ( ) => {
519+ await using tmp = await tmpdir ( )
520+ await Instance . provide ( {
521+ directory : tmp . path ,
522+ fn : async ( ) => {
523+ const agent = await Agent . defaultAgent ( )
524+ expect ( agent ) . toBe ( "build" )
525+ } ,
526+ } )
527+ } )
528+
529+ test ( "defaultAgent respects default_agent config set to plan" , async ( ) => {
530+ await using tmp = await tmpdir ( {
531+ config : {
532+ default_agent : "plan" ,
533+ } ,
534+ } )
535+ await Instance . provide ( {
536+ directory : tmp . path ,
537+ fn : async ( ) => {
538+ const agent = await Agent . defaultAgent ( )
539+ expect ( agent ) . toBe ( "plan" )
540+ } ,
541+ } )
542+ } )
543+
544+ test ( "defaultAgent respects default_agent config set to custom agent with mode all" , async ( ) => {
545+ await using tmp = await tmpdir ( {
546+ config : {
547+ default_agent : "my_custom" ,
548+ agent : {
549+ my_custom : {
550+ description : "My custom agent" ,
551+ } ,
552+ } ,
553+ } ,
554+ } )
555+ await Instance . provide ( {
556+ directory : tmp . path ,
557+ fn : async ( ) => {
558+ const agent = await Agent . defaultAgent ( )
559+ expect ( agent ) . toBe ( "my_custom" )
560+ } ,
561+ } )
562+ } )
563+
564+ test ( "defaultAgent falls back when default_agent points to subagent" , async ( ) => {
565+ await using tmp = await tmpdir ( {
566+ config : {
567+ default_agent : "explore" ,
568+ } ,
569+ } )
570+ await Instance . provide ( {
571+ directory : tmp . path ,
572+ fn : async ( ) => {
573+ const agent = await Agent . defaultAgent ( )
574+ // explore is a subagent, so it should fall back to first primary-capable agent
575+ expect ( agent ) . not . toBe ( "explore" )
576+ expect ( agent ) . toBe ( "build" )
577+ } ,
578+ } )
579+ } )
580+
581+ test ( "defaultAgent falls back when default_agent points to hidden agent" , async ( ) => {
582+ await using tmp = await tmpdir ( {
583+ config : {
584+ default_agent : "compaction" ,
585+ } ,
586+ } )
587+ await Instance . provide ( {
588+ directory : tmp . path ,
589+ fn : async ( ) => {
590+ const agent = await Agent . defaultAgent ( )
591+ // compaction is hidden, so it should fall back to first primary-capable agent
592+ expect ( agent ) . not . toBe ( "compaction" )
593+ expect ( agent ) . toBe ( "build" )
594+ } ,
595+ } )
596+ } )
597+
598+ test ( "defaultAgent falls back when default_agent points to non-existent agent" , async ( ) => {
599+ await using tmp = await tmpdir ( {
600+ config : {
601+ default_agent : "does_not_exist" ,
602+ } ,
603+ } )
604+ await Instance . provide ( {
605+ directory : tmp . path ,
606+ fn : async ( ) => {
607+ const agent = await Agent . defaultAgent ( )
608+ expect ( agent ) . toBe ( "build" )
609+ } ,
610+ } )
611+ } )
612+
613+ test ( "defaultAgent returns plan when build is disabled and default_agent not set" , async ( ) => {
614+ await using tmp = await tmpdir ( {
615+ config : {
616+ agent : {
617+ build : { disable : true } ,
618+ } ,
619+ } ,
620+ } )
621+ await Instance . provide ( {
622+ directory : tmp . path ,
623+ fn : async ( ) => {
624+ const agent = await Agent . defaultAgent ( )
625+ // build is disabled, so it should return plan (next primary agent)
626+ expect ( agent ) . toBe ( "plan" )
627+ } ,
628+ } )
629+ } )
0 commit comments