@@ -27,6 +27,7 @@ import { CodexSettings, ProviderInstanceId } from "@t3tools/contracts";
2727import * as ServerConfig from "../config.ts" ;
2828import { makeProcessProbe , processProbeSource } from "../testUtils/processProbe.ts" ;
2929import * as TextGeneration from "./TextGeneration.ts" ;
30+ import * as TextGenerators from "./TextGenerators.ts" ;
3031import { makeCodexTextGeneration } from "./CodexTextGeneration.ts" ;
3132import { writeFakeCli } from "@t3tools/provider-testing/fakeCli" ;
3233const decodeCodexSettings = Schema . decodeSync ( CodexSettings ) ;
@@ -625,6 +626,7 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
625626 [ fallback ] : { driver : ProviderDriverKind . make ( "claudeAgent" ) , config : { } } ,
626627 } ,
627628 } ) ,
629+ Layer . mock ( TextGenerators . TextGenerators ) ( { runner : ( ) => Effect . undefined } ) ,
628630 Layer . mock ( SourceControlProviderRegistry . SourceControlProviderRegistry ) ( {
629631 resolveLink : ( ) => Effect . die ( "unused" ) ,
630632 } ) ,
@@ -652,3 +654,90 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
652654 ] ) ;
653655 } ) ,
654656) ;
657+
658+ it . effect (
659+ "a review guide aimed at a text generator falls back to an agent that can read the checkout" ,
660+ ( ) =>
661+ Effect . gen ( function * ( ) {
662+ const claude = ProviderInstanceId . make ( "claudeAgent" ) ;
663+ const driver = ProviderDriverKind . make ( "claudeAgent" ) ;
664+ const calls : ModelSelection [ ] = [ ] ;
665+ const instance = {
666+ instanceId : claude ,
667+ driverKind : driver ,
668+ continuationIdentity : { driverKind : driver , continuationKey : claude } ,
669+ displayName : undefined ,
670+ enabled : true ,
671+ snapshot : {
672+ getSnapshot : Effect . succeed < ServerProvider > ( {
673+ instanceId : claude ,
674+ driver,
675+ enabled : true ,
676+ installed : true ,
677+ status : "ready" ,
678+ auth : { status : "authenticated" } ,
679+ version : null ,
680+ checkedAt : "1970-01-01T00:00:00Z" ,
681+ models : [ ] ,
682+ slashCommands : [ ] ,
683+ skills : [ ] ,
684+ } ) ,
685+ } as ProviderInstance [ "snapshot" ] ,
686+ orchestrationAdapter : { } as ProviderInstance [ "orchestrationAdapter" ] ,
687+ textGeneration : TextGeneration . TextGeneration . of ( {
688+ generateCommitMessage : ( ) => Effect . die ( "unused" ) ,
689+ generatePrContent : ( ) => Effect . die ( "unused" ) ,
690+ generateBranchName : ( ) => Effect . die ( "unused" ) ,
691+ generateThreadTitle : ( ) => Effect . die ( "unused" ) ,
692+ generateTranscriptionPostProcessing : ( ) => Effect . die ( "unused" ) ,
693+ generateReviewGuide : ( input ) =>
694+ Effect . sync ( ( ) => {
695+ calls . push ( input . modelSelection ) ;
696+ return { } as TextGeneration . ReviewGuideGenerationResult ;
697+ } ) ,
698+ } ) ,
699+ } satisfies ProviderInstance ;
700+ const serviceWith = ( instances : ReadonlyArray < ProviderInstance > ) =>
701+ TextGeneration . make . pipe (
702+ Effect . provide (
703+ Layer . mergeAll (
704+ Layer . mock ( ProviderInstanceRegistry . ProviderInstanceRegistry ) ( {
705+ listInstances : Effect . succeed ( instances ) ,
706+ getInstance : ( id ) =>
707+ Effect . succeed ( instances . find ( ( candidate ) => candidate . instanceId === id ) ) ,
708+ } ) ,
709+ ServerSettings . layerTest ( { } ) ,
710+ Layer . mock ( TextGenerators . TextGenerators ) ( {
711+ runner : ( id ) =>
712+ Effect . succeed (
713+ id === "openrouter"
714+ ? ( ) => Effect . die ( "a text generator cannot investigate" )
715+ : undefined ,
716+ ) ,
717+ } ) ,
718+ Layer . mock ( SourceControlProviderRegistry . SourceControlProviderRegistry ) ( {
719+ resolveLink : ( ) => Effect . die ( "unused" ) ,
720+ } ) ,
721+ ) ,
722+ ) ,
723+ ) ;
724+ const input = {
725+ cwd : "/tmp" ,
726+ number : 1 ,
727+ title : "Change" ,
728+ description : "" ,
729+ baseBranch : "main" ,
730+ baseCommit : "abc" ,
731+ settledReview : "" ,
732+ modelSelection : { instanceId : ProviderInstanceId . make ( "openrouter" ) , model : "some/model" } ,
733+ } ;
734+ yield * ( yield * serviceWith ( [ instance ] ) ) . generateReviewGuide ( input ) ;
735+ expect ( calls . map ( ( selection ) => selection . instanceId ) ) . toEqual ( [ claude ] ) ;
736+
737+ // With no agent ready, it says what is missing instead of looking up a provider by that id.
738+ const failure = yield * Effect . flip ( ( yield * serviceWith ( [ ] ) ) . generateReviewGuide ( input ) ) ;
739+ expect ( failure . detail ) . toMatch (
740+ / ^ R e v i e w g u i d e s n e e d a c o d i n g a g e n t t h a t c a n r e a d t h e c h e c k o u t / ,
741+ ) ;
742+ } ) ,
743+ ) ;
0 commit comments