11import * as NodeServices from "@effect/platform-node/NodeServices" ;
22import { assert , describe , it } from "@effect/vitest" ;
3+ import * as Deferred from "effect/Deferred" ;
34import * as Effect from "effect/Effect" ;
5+ import * as Queue from "effect/Queue" ;
46import * as Sink from "effect/Sink" ;
57import * as Stream from "effect/Stream" ;
68import { ChildProcess , ChildProcessSpawner } from "effect/unstable/process" ;
@@ -44,6 +46,56 @@ function piProbeSpawner(version: string) {
4446 } ) ;
4547}
4648
49+ function piDiscoverySpawner ( ) {
50+ return ChildProcessSpawner . make ( ( command ) => {
51+ const args = ChildProcess . isStandardCommand ( command ) ? command . args : [ ] ;
52+ if ( args . includes ( "--version" ) ) {
53+ return Effect . succeed ( processHandle ( { stdout : "pi 1.0.0\n" } ) ) ;
54+ }
55+ return Effect . gen ( function * ( ) {
56+ const output = yield * Queue . unbounded < Uint8Array > ( ) ;
57+ const exited = yield * Deferred . make < ChildProcessSpawner . ExitCode > ( ) ;
58+ return ChildProcessSpawner . makeHandle ( {
59+ pid : ChildProcessSpawner . ProcessId ( 900_000_002 ) ,
60+ exitCode : Deferred . await ( exited ) ,
61+ isRunning : Effect . succeed ( true ) ,
62+ kill : ( ) => Deferred . succeed ( exited , ChildProcessSpawner . ExitCode ( 0 ) ) . pipe ( Effect . asVoid ) ,
63+ unref : Effect . succeed ( Effect . void ) ,
64+ stdin : Sink . forEach ( ( bytes : Uint8Array ) => {
65+ const request = JSON . parse ( new TextDecoder ( ) . decode ( bytes ) ) ;
66+ const data =
67+ request . type === "get_available_models"
68+ ? {
69+ models : [
70+ { provider : "openai-codex-work" , id : "gpt-6-luna" , name : "GPT-6 Luna" } ,
71+ { provider : "openai-codex-personal" , id : "gpt-6-luna" , name : "GPT-6 Luna" } ,
72+ ] ,
73+ }
74+ : request . type === "get_commands"
75+ ? { commands : [ ] }
76+ : { } ;
77+ return Queue . offer (
78+ output ,
79+ encoder . encode (
80+ JSON . stringify ( {
81+ type : "response" ,
82+ id : request . id ,
83+ success : true ,
84+ data,
85+ } ) + "\n" ,
86+ ) ,
87+ ) ;
88+ } ) ,
89+ stdout : Stream . fromQueue ( output ) ,
90+ stderr : Stream . empty ,
91+ all : Stream . empty ,
92+ getInputFd : ( ) => Sink . drain ,
93+ getOutputFd : ( ) => Stream . empty ,
94+ } ) ;
95+ } ) ;
96+ } ) ;
97+ }
98+
4799const settings = {
48100 enabled : true ,
49101 binaryPath : "pi" ,
@@ -52,6 +104,27 @@ const settings = {
52104} as const ;
53105
54106describe ( "PiProvider" , ( ) => {
107+ it . effect ( "preserves native provider labels for identically named Pi models" , ( ) =>
108+ Effect . gen ( function * ( ) {
109+ const snapshot = yield * checkPiProviderStatus ( settings ) . pipe (
110+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , piDiscoverySpawner ( ) ) ,
111+ ) ;
112+ assert . equal ( snapshot . status , "ready" ) ;
113+ assert . deepEqual (
114+ snapshot . models
115+ . filter ( ( model ) => model . name === "GPT-6 Luna" )
116+ . map ( ( model ) => ( {
117+ slug : model . slug ,
118+ subProvider : model . subProvider ,
119+ } ) ) ,
120+ [
121+ { slug : "openai-codex-work/gpt-6-luna" , subProvider : "openai-codex-work" } ,
122+ { slug : "openai-codex-personal/gpt-6-luna" , subProvider : "openai-codex-personal" } ,
123+ ] ,
124+ ) ;
125+ } ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
126+ ) ;
127+
55128 it . effect ( "requires the first published Pi version with entries and settlement hooks" , ( ) =>
56129 Effect . gen ( function * ( ) {
57130 const snapshot = yield * checkPiProviderStatus ( settings ) . pipe (
0 commit comments