@@ -7,6 +7,7 @@ import * as Queue from "effect/Queue";
77import * as Schema from "effect/Schema" ;
88import * as Sink from "effect/Sink" ;
99import * as Stream from "effect/Stream" ;
10+ import * as ChildProcess from "effect/process/ChildProcess" ;
1011import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner" ;
1112
1213import { makePiTextGeneration } from "./textGeneration.ts" ;
@@ -68,6 +69,35 @@ const makeFakePi = (
6869 return { spawner, received } ;
6970 } ) ;
7071
72+ it . effect ( "runs Pi offline, since the process is stopped as soon as it answers" , ( ) =>
73+ Effect . gen ( function * ( ) {
74+ const pi = yield * makeFakePi ( JSON . stringify ( { subject : "Update README" , body : "" } ) ) ;
75+ const launches : Array < ReadonlyArray < string > > = [ ] ;
76+ const spawner = ChildProcessSpawner . make ( ( command ) => {
77+ if ( ChildProcess . isStandardCommand ( command ) ) launches . push ( command . args . map ( String ) ) ;
78+ return pi . spawner . spawn ( command ) ;
79+ } ) ;
80+ const textGeneration = yield * makePiTextGeneration (
81+ { enabled : true , binaryPath : "pi" , launchArgs : "" , customModels : [ ] } ,
82+ { } ,
83+ ) . pipe ( Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ) ;
84+
85+ const result = yield * textGeneration . generateCommitMessage ( {
86+ cwd : process . cwd ( ) ,
87+ branch : "main" ,
88+ stagedSummary : "M README.md" ,
89+ stagedPatch : "diff --git a/README.md b/README.md" ,
90+ modelSelection : createModelSelection ( ProviderInstanceId . make ( "pi" ) , "default" ) ,
91+ } ) ;
92+
93+ assert . equal ( result . subject , "Update README" ) ;
94+ assert . deepEqual (
95+ launches . map ( ( args ) => args . filter ( ( arg ) => arg === "--offline" ) ) ,
96+ [ [ "--offline" ] ] ,
97+ ) ;
98+ } ) ,
99+ ) ;
100+
71101it . effect ( "names the model and the disabled extensions when Pi cannot load it" , ( ) =>
72102 Effect . gen ( function * ( ) {
73103 const pi = yield * makeFakePi ( "" , "Model not found: demo/demo-model" ) ;
0 commit comments