@@ -9,6 +9,7 @@ import * as Duration from "effect/Duration";
99import * as Effect from "effect/Effect" ;
1010import * as Exit from "effect/Exit" ;
1111import * as Fiber from "effect/Fiber" ;
12+ import * as FileSystem from "effect/FileSystem" ;
1213import * as Layer from "effect/Layer" ;
1314import * as Schema from "effect/Schema" ;
1415import * as TestClock from "effect/testing/TestClock" ;
@@ -282,20 +283,21 @@ function withOpenCodeTextGeneration<A, E, R>(
282283 settings : OpenCodeSettings ,
283284 effectFn : ( textGeneration : ProviderTextGenerationRuntime ) => Effect . Effect < A , E , R > ,
284285 environment ?: NodeJS . ProcessEnv ,
286+ directory = process . cwd ( ) ,
285287) {
286288 return Effect . gen ( function * ( ) {
287289 const serverOwner = yield * OpenCodeServerOwner . make ( {
288290 binaryPath : settings . binaryPath ,
289- directory : process . cwd ( ) ,
291+ directory,
290292 ...( settingsSecretLiteral ( settings . serverPassword )
291293 ? { serverPassword : settingsSecretLiteral ( settings . serverPassword ) }
292294 : { } ) ,
293295 ...( environment ? { environment } : { } ) ,
294296 } ) ;
295- const textGeneration = yield * OpenCodeTextGeneration . makeOpenCodeTextGeneration (
296- settings ,
297- environment ? { environment } : { } ,
298- ) . pipe ( Effect . provideService ( OpenCodeServerOwner . OpenCodeServerOwner , serverOwner ) ) ;
297+ const textGeneration = yield * OpenCodeTextGeneration . makeOpenCodeTextGeneration ( settings , {
298+ directory ,
299+ ... ( environment ? { environment } : { } ) ,
300+ } ) . pipe ( Effect . provideService ( OpenCodeServerOwner . OpenCodeServerOwner , serverOwner ) ) ;
299301 return yield * effectFn ( textGeneration ) ;
300302 } ) . pipe ( Effect . scoped ) ;
301303}
@@ -470,66 +472,134 @@ it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
470472 ) ,
471473 ) ;
472474
473- it . effect ( "isolates blind evaluation from shared servers, tools, and custom instructions" , ( ) =>
474- withOpenCodeTextGeneration (
475- DEFAULT_OPENCODE_SETTINGS ,
476- ( textGeneration ) =>
477- Effect . gen ( function * ( ) {
478- runtimeMock . state . promptResult = {
479- data : {
480- info : { providerID : "openai" , modelID : "gpt-5" , variant : "high" } ,
481- parts : [
482- { type : "step-start" } ,
483- { type : "reasoning" , text : "Check the evidence." } ,
484- { type : "text" , text : JSON . stringify ( VALID_EVALUATION ) } ,
485- { type : "step-finish" , reason : "stop" } ,
486- { type : "snapshot" , snapshot : "unchanged" } ,
487- ] ,
488- } ,
489- } ;
475+ it . effect . each ( [
476+ "configured overrides" ,
477+ "empty file override" ,
478+ "empty directory override" ,
479+ "empty inline override" ,
480+ ] ) (
481+ "isolates blind evaluation from shared servers, tools, and custom instructions (%s)" ,
482+ ( overrides ) =>
483+ Effect . gen ( function * ( ) {
484+ const fs = yield * FileSystem . FileSystem ;
485+ const directory = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-opencode-routing-" } ) ;
486+ const configHome = `${ directory } /global` ;
487+ const configDirectory = `${ directory } /override` ;
488+ const configFile = `${ directory } /explicit.json` ;
489+ yield * fs . makeDirectory ( `${ configHome } /opencode` , { recursive : true } ) ;
490+ yield * fs . makeDirectory ( configDirectory ) ;
491+ yield * fs . writeFileString (
492+ `${ configHome } /opencode/config.json` ,
493+ JSON . stringify ( {
494+ provider : { openai : { options : { apiKey : "global-key" } } } ,
495+ enabled_providers : [ "openai" ] ,
496+ disabled_providers : [ "global-disabled" ] ,
497+ } ) ,
498+ ) ;
499+ yield * fs . writeFileString (
500+ `${ directory } /opencode.json` ,
501+ JSON . stringify ( {
502+ provider : { openai : { options : { baseURL : "http://ignored-cwd.internal" } } } ,
503+ } ) ,
504+ ) ;
505+ yield * fs . writeFileString (
506+ configFile ,
507+ JSON . stringify ( {
508+ provider : { openai : { options : { baseURL : "http://explicit.internal" } } } ,
509+ } ) ,
510+ ) ;
511+ yield * fs . writeFileString (
512+ `${ configDirectory } /config.json` ,
513+ JSON . stringify ( { disabled_providers : [ "ignored-directory-file" ] } ) ,
514+ ) ;
515+ yield * fs . writeFileString (
516+ `${ configDirectory } /opencode.json` ,
517+ JSON . stringify ( {
518+ provider : { openai : { options : { baseURL : "http://directory-json.internal" } } } ,
519+ } ) ,
520+ ) ;
521+ yield * fs . writeFileString (
522+ `${ configDirectory } /opencode.jsonc` ,
523+ JSON . stringify ( {
524+ provider : { openai : { options : { baseURL : "http://directory-jsonc.internal" } } } ,
525+ } ) ,
526+ ) ;
527+ return yield * withOpenCodeTextGeneration (
528+ DEFAULT_OPENCODE_SETTINGS ,
529+ ( textGeneration ) =>
530+ Effect . gen ( function * ( ) {
531+ runtimeMock . state . promptResult = {
532+ data : {
533+ info : { providerID : "openai" , modelID : "gpt-5" , variant : "high" } ,
534+ parts : [
535+ { type : "step-start" } ,
536+ { type : "reasoning" , text : "Check the evidence." } ,
537+ { type : "text" , text : JSON . stringify ( VALID_EVALUATION ) } ,
538+ { type : "step-finish" , reason : "stop" } ,
539+ { type : "snapshot" , snapshot : "unchanged" } ,
540+ ] ,
541+ } ,
542+ } ;
490543
491- const verdict = yield * textGeneration . generateModelEvaluation ( {
492- ...DEFAULT_EVALUATION_INPUT ,
493- modelSelection : {
494- ...DEFAULT_TEST_MODEL_SELECTION ,
495- options : [ { id : "variant" , value : "high" } ] ,
496- } ,
497- } ) ;
544+ const verdict = yield * textGeneration . generateModelEvaluation ( {
545+ ...DEFAULT_EVALUATION_INPUT ,
546+ modelSelection : {
547+ ...DEFAULT_TEST_MODEL_SELECTION ,
548+ options : [ { id : "variant" , value : "high" } ] ,
549+ } ,
550+ } ) ;
498551
499- expect ( verdict ) . toEqual ( VALID_EVALUATION ) ;
500- expect ( textGeneration . supportedOperations ) . toContain ( "generateModelEvaluation" ) ;
501- expect ( runtimeMock . state . promptUrls ) . toEqual ( [ "http://127.0.0.1:4301" ] ) ;
502- expect ( runtimeMock . state . promptInputs [ 0 ] ) . toMatchObject ( {
503- model : { providerID : "openai" , modelID : "gpt-5" } ,
504- variant : "high" ,
505- } ) ;
506- expect ( runtimeMock . state . sessionCreateInputs [ 0 ] ?. permission ) . toEqual ( [
507- { permission : "*" , pattern : "*" , action : "deny" } ,
508- ] ) ;
509- const environment = runtimeMock . state . startEnvironments [ 0 ] ;
510- expect ( environment ?. XDG_CONFIG_HOME ) . not . toBe ( "/user-config" ) ;
511- expect ( environment ?. OPENCODE_CONFIG ) . toBeUndefined ( ) ;
512- expect ( environment ?. OPENCODE_DISABLE_PROJECT_CONFIG ) . toBe ( "1" ) ;
513- expect ( environment ?. OPENCODE_DISABLE_CLAUDE_CODE ) . toBe ( "1" ) ;
514- expect ( JSON . parse ( environment ?. OPENCODE_CONFIG_CONTENT ?? "null" ) ) . toEqual ( {
515- provider : { custom : { options : { baseURL : "http://model.internal" } } } ,
516- enabled_providers : [ "custom" ] ,
517- } ) ;
518- expect ( runtimeMock . state . closeCalls ) . toEqual ( [ "http://127.0.0.1:4301" ] ) ;
519- } ) ,
520- {
521- XDG_CONFIG_HOME : "/user-config" ,
522- OPENCODE_CONFIG : "/user-config/opencode.json" ,
523- OPENCODE_CONFIG_CONTENT : `{
552+ expect ( verdict ) . toEqual ( VALID_EVALUATION ) ;
553+ expect ( textGeneration . supportedOperations ) . toContain ( "generateModelEvaluation" ) ;
554+ expect ( runtimeMock . state . promptUrls ) . toEqual ( [ "http://127.0.0.1:4301" ] ) ;
555+ expect ( runtimeMock . state . promptInputs [ 0 ] ) . toMatchObject ( {
556+ model : { providerID : "openai" , modelID : "gpt-5" } ,
557+ variant : "high" ,
558+ } ) ;
559+ expect ( runtimeMock . state . sessionCreateInputs [ 0 ] ?. permission ) . toEqual ( [
560+ { permission : "*" , pattern : "*" , action : "deny" } ,
561+ ] ) ;
562+ const environment = runtimeMock . state . startEnvironments [ 0 ] ;
563+ expect ( environment ?. XDG_CONFIG_HOME ) . not . toBe ( configHome ) ;
564+ expect ( environment ?. OPENCODE_CONFIG ) . toBeUndefined ( ) ;
565+ expect ( environment ?. OPENCODE_DISABLE_PROJECT_CONFIG ) . toBe ( "1" ) ;
566+ expect ( environment ?. OPENCODE_DISABLE_CLAUDE_CODE ) . toBe ( "1" ) ;
567+ expect ( JSON . parse ( environment ?. OPENCODE_CONFIG_CONTENT ?? "null" ) ) . toEqual ( {
568+ provider : {
569+ openai : {
570+ options : {
571+ baseURL :
572+ overrides === "empty directory override"
573+ ? "http://explicit.internal"
574+ : "http://directory-jsonc.internal" ,
575+ apiKey : overrides === "empty inline override" ? "global-key" : "inline-key" ,
576+ } ,
577+ } ,
578+ } ,
579+ enabled_providers : [ "openai" ] ,
580+ disabled_providers : [ "global-disabled" ] ,
581+ } ) ;
582+ expect ( runtimeMock . state . closeCalls ) . toEqual ( [ "http://127.0.0.1:4301" ] ) ;
583+ } ) ,
584+ {
585+ XDG_CONFIG_HOME : configHome ,
586+ OPENCODE_CONFIG : overrides === "empty file override" ? "" : configFile ,
587+ OPENCODE_CONFIG_DIR : overrides === "empty directory override" ? "" : configDirectory ,
588+ OPENCODE_CONFIG_CONTENT :
589+ overrides === "empty inline override"
590+ ? ""
591+ : `{
524592 // Routing survives, but customization does not.
525- "provider": { "custom ": { "options": { "baseURL ": "http://model.internal " } } },
526- "enabled_providers": ["custom "],
593+ "provider": { "openai ": { "options": { "apiKey ": "inline-key " } } },
594+ "enabled_providers": ["openai "],
527595 "instructions": ["/secret/instructions.md"],
528596 "plugin": ["secret-plugin"],
529597 "mcp": { "private": { "type": "remote", "url": "http://private" } }
530598 }` ,
531- } ,
532- ) ,
599+ } ,
600+ directory ,
601+ ) ;
602+ } ) . pipe ( Effect . scoped ) ,
533603 ) ;
534604
535605 it . effect ( "fails blind evaluation instead of dropping an unavailable or invalid variant" , ( ) =>
0 commit comments