@@ -35,11 +35,23 @@ import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderS
3535import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers" ;
3636import * as ProviderMaintenance from "@t3tools/provider-core/server/maintenanceResolver" ;
3737import * as OpenCodeRuntime from "./OpenCodeRuntime.ts" ;
38+ import { OpenCodeDriver , isLocalOpenCodeServerUrl , openCodeUpdateFor } from "./driver.ts" ;
3839import * as OpenCodeServerLedger from "./OpenCodeServerLedger.ts" ;
3940import { OPENCODE_2_RESPONSES , replayOpenCodeServer } from "./probeResponses.fixture.ts" ;
40- import { OpenCodeDriver , openCodeUpdateFor } from "./driver.ts" ;
4141import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost" ;
4242
43+ it ( "only probes a locally configured OpenCode server's installed CLI" , ( ) => {
44+ assert . isTrue ( isLocalOpenCodeServerUrl ( "http://127.0.0.1:35768" ) ) ;
45+ assert . isTrue ( isLocalOpenCodeServerUrl ( "http://127.255.255.254:4096" ) ) ;
46+ assert . isFalse ( isLocalOpenCodeServerUrl ( "http://127.example.com:4096" ) ) ;
47+ assert . isFalse ( isLocalOpenCodeServerUrl ( "http://128.0.0.1:4096" ) ) ;
48+ assert . isTrue ( isLocalOpenCodeServerUrl ( "http://localhost:4096" ) ) ;
49+ assert . isTrue ( isLocalOpenCodeServerUrl ( "http://[::1]:4096" ) ) ;
50+ assert . isFalse ( isLocalOpenCodeServerUrl ( "https://remote.example.com:4096" ) ) ;
51+ assert . isFalse ( isLocalOpenCodeServerUrl ( "" ) ) ;
52+ assert . isFalse ( isLocalOpenCodeServerUrl ( "file:///tmp/opencode" ) ) ;
53+ } ) ;
54+
4355const serverStarts : Array < string > = [ ] ;
4456const reachedServer = ( operation : string ) =>
4557 Effect . sync ( ( ) => serverStarts . push ( operation ) ) . pipe (
@@ -70,12 +82,12 @@ const layer = Layer.mergeAll(
7082 Layer . succeed ( OpenCodeRuntime . OpenCodeRuntime , openCode2Runtime ) ,
7183) . pipe ( Layer . provideMerge ( Layer . mergeAll ( NodeServices . layer , NodeCrypto . layer ) ) ) ;
7284
73- const create = ( config : Partial < OpenCodeSettings > , http : HttpClient . HttpClient ) =>
85+ const create = ( config : Partial < OpenCodeSettings > , http : HttpClient . HttpClient , enabled = true ) =>
7486 OpenCodeDriver . create ( {
7587 instanceId : ProviderInstanceId . make ( "opencode-test" ) ,
7688 displayName : undefined ,
7789 environment : [ ] ,
78- enabled : true ,
90+ enabled,
7991 config : { ...OpenCodeDriver . defaultConfig ( ) , ...config } ,
8092 } ) . pipe ( Effect . provideService ( HttpClient . HttpClient , http ) ) ;
8193
@@ -187,6 +199,60 @@ it.layer(layer)("OpenCodeDriver runtime selection", (it) => {
187199 } ) . pipe ( Effect . scoped ) ,
188200 ) ;
189201
202+ it . effect . each ( [ "2.1.2" , null ] ) (
203+ "reports the installed CLI version independently of the loopback server (%s)" ,
204+ ( installedVersion ) =>
205+ Effect . gen ( function * ( ) {
206+ const probeOffline : Array < string | undefined > = [ ] ;
207+ const runtime = {
208+ ...openCode2Runtime ,
209+ runOpenCodeCommand : ( input ) =>
210+ Effect . sync ( ( ) => {
211+ probeOffline . push ( input . environment ?. MISE_OFFLINE ) ;
212+ return {
213+ stdout :
214+ installedVersion === null ? "unrecognized" : `opencode v${ installedVersion } \n` ,
215+ stderr : "" ,
216+ code : 0 ,
217+ } ;
218+ } ) ,
219+ } as OpenCodeRuntime . OpenCodeRuntime [ "Service" ] ;
220+ const instance = yield * create (
221+ { serverUrl : "http://127.0.0.1:4096" } ,
222+ replayOpenCodeServer ( OPENCODE_2_RESPONSES , "" ) ,
223+ ) . pipe ( Effect . provideService ( OpenCodeRuntime . OpenCodeRuntime , runtime ) ) ;
224+
225+ const snapshot = yield * instance . snapshot . refresh ;
226+ assert . strictEqual ( snapshot . version , "2.0.18" ) ;
227+ assert . strictEqual ( snapshot . installedVersion , installedVersion ?? undefined ) ;
228+ const maintenance = yield * instance . snapshot . resolveMaintenance ( { fresh : true } ) ;
229+ assert . strictEqual ( maintenance . packageName , "@opencode/cli" ) ;
230+ assert . isNotEmpty ( probeOffline ) ;
231+ assert . isTrue ( probeOffline . every ( ( offline ) => offline === "1" ) ) ;
232+ } ) . pipe ( Effect . scoped ) ,
233+ ) ;
234+
235+ it . effect ( "skips the installed CLI probe when a localhost provider is disabled" , ( ) =>
236+ Effect . gen ( function * ( ) {
237+ const probed : string [ ] = [ ] ;
238+ const runtime = {
239+ ...openCode2Runtime ,
240+ runOpenCodeCommand : ( ) =>
241+ Effect . sync ( ( ) => {
242+ probed . push ( "--version" ) ;
243+ return { stdout : "opencode v2.1.2\n" , stderr : "" , code : 0 } ;
244+ } ) ,
245+ } as OpenCodeRuntime . OpenCodeRuntime [ "Service" ] ;
246+ const instance = yield * create ( { serverUrl : "http://127.0.0.1:4096" } , noHttp , false ) . pipe (
247+ Effect . provideService ( OpenCodeRuntime . OpenCodeRuntime , runtime ) ,
248+ ) ;
249+
250+ const snapshot = yield * instance . snapshot . refresh ;
251+ assert . isFalse ( snapshot . enabled ) ;
252+ assert . deepStrictEqual ( probed , [ ] ) ;
253+ } ) . pipe ( Effect . scoped ) ,
254+ ) ;
255+
190256 it . effect ( "opens a session through OpenCode 2 that a lazy mise shim installs on first use" , ( ) =>
191257 Effect . gen ( function * ( ) {
192258 serverStarts . length = 0 ;
0 commit comments