11import * as NodeServices from "@effect/platform-node/NodeServices" ;
2- import { describe , it } from "@effect/vitest" ;
2+ import { assert , describe , it } from "@effect/vitest" ;
33import {
44 MessageId ,
55 NodeId ,
@@ -20,7 +20,9 @@ import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/Pr
2020import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost" ;
2121import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime" ;
2222import * as DateTime from "effect/DateTime" ;
23+ import * as Cause from "effect/Cause" ;
2324import * as Effect from "effect/Effect" ;
25+ import * as Exit from "effect/Exit" ;
2426import * as FileSystem from "effect/FileSystem" ;
2527import * as Layer from "effect/Layer" ;
2628import * as Path from "effect/Path" ;
@@ -339,36 +341,62 @@ describe("FxAdapterV2", () => {
339341 // `fx status` names a gateway model, but this loaded session runs on Codex,
340342 // whose catalog lacks it: the backend goes back first.
341343 it . effect ( "moves a loaded session on another backend back to fx's default backend" , ( ) =>
342- openFxSession ( {
343- scenario : "default-other-backend" ,
344- runtimeMode : "approval-required" ,
345- model : "default" ,
346- loadSessionId : SESSION_ID ,
347- frames : [
348- ...initialize ,
349- outbound ( "session/load" ) ,
350- answer (
351- "session/load" ,
352- fxSession ( {
353- model : CODEX_MODEL ,
354- backend : "codex" ,
355- models : [ CODEX_MODEL ] ,
356- modes : FX_0_0_13_MODES ,
357- } ) ,
358- ) ,
359- // fx then runs the gateway model it saved for that backend.
360- ...setConfig (
361- "provider" ,
362- "gateway" ,
363- fxConfig ( { model : NAMED_MODEL , modes : FX_0_0_13_MODES } ) ,
364- ) ,
365- ...setConfig (
366- "model" ,
367- FX_DEFAULT_MODEL ,
368- fxConfig ( { model : FX_DEFAULT_MODEL , modes : FX_0_0_13_MODES } ) ,
369- ) ,
370- ...setConfig ( "mode" , "ask" , fxConfig ( { model : FX_DEFAULT_MODEL , modes : FX_0_0_13_MODES } ) ) ,
371- ] ,
344+ Effect . gen ( function * ( ) {
345+ for ( const modelAvailable of [ true , false ] ) {
346+ const result = yield * openFxSession ( {
347+ scenario : `default-other-backend-${ modelAvailable } ` ,
348+ runtimeMode : "approval-required" ,
349+ model : "default" ,
350+ loadSessionId : SESSION_ID ,
351+ frames : [
352+ ...initialize ,
353+ outbound ( "session/load" ) ,
354+ answer (
355+ "session/load" ,
356+ fxSession ( {
357+ model : CODEX_MODEL ,
358+ backend : "codex" ,
359+ models : [ CODEX_MODEL ] ,
360+ modes : FX_0_0_13_MODES ,
361+ } ) ,
362+ ) ,
363+ // fx then runs the gateway model it saved for that backend.
364+ ...setConfig (
365+ "provider" ,
366+ "gateway" ,
367+ fxConfig ( {
368+ model : NAMED_MODEL ,
369+ ...( modelAvailable ? { } : { models : [ NAMED_MODEL ] } ) ,
370+ modes : FX_0_0_13_MODES ,
371+ } ) ,
372+ ) ,
373+ ...( modelAvailable
374+ ? [
375+ ...setConfig (
376+ "model" ,
377+ FX_DEFAULT_MODEL ,
378+ fxConfig ( { model : FX_DEFAULT_MODEL , modes : FX_0_0_13_MODES } ) ,
379+ ) ,
380+ ...setConfig (
381+ "mode" ,
382+ "ask" ,
383+ fxConfig ( { model : FX_DEFAULT_MODEL , modes : FX_0_0_13_MODES } ) ,
384+ ) ,
385+ ]
386+ : [ ] ) ,
387+ ] ,
388+ } ) . pipe ( Effect . exit ) ;
389+ if ( modelAvailable ) {
390+ assert . isTrue ( Exit . isSuccess ( result ) ) ;
391+ } else if ( Exit . isFailure ( result ) ) {
392+ assert . include (
393+ Cause . pretty ( result . cause ) ,
394+ "The default fx model is unavailable on its configured backend." ,
395+ ) ;
396+ } else {
397+ assert . fail ( "Expected Default selection to reject the unavailable model" ) ;
398+ }
399+ }
372400 } ) . pipe ( Effect . provide ( testLayer ) , Effect . scoped ) ,
373401 ) ;
374402
0 commit comments