@@ -28,6 +28,7 @@ import * as HttpClientResponse from "effect/http/HttpClientResponse";
2828import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner" ;
2929import * as EffectAcpErrors from "effect-acp/errors" ;
3030
31+ import { makeProviderFailure } from "@t3tools/provider-core/server/failure" ;
3132import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions" ;
3233import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost" ;
3334import {
@@ -468,6 +469,7 @@ describe("AcpRegistryAdapterV2", () => {
468469 readonly storedModel ?: string ;
469470 readonly storedModePick ?: string ;
470471 readonly turnModels ?: ReadonlyArray < string > ;
472+ readonly rejectedModel ?: string ;
471473 } ) {
472474 const spawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
473475 // Scope release gives the replay agent at most a second to exit, so the status
@@ -605,7 +607,19 @@ describe("AcpRegistryAdapterV2", () => {
605607 configurations . push ( published ) ;
606608 current = target ;
607609 }
608- } ) . pipe ( Effect . scoped ) ;
610+ } ) . pipe (
611+ Effect . match ( {
612+ onFailure : ( error ) => {
613+ assert . isDefined ( input . rejectedModel ) ;
614+ assert . equal (
615+ makeProviderFailure ( { cause : error } ) . message ,
616+ `The agent did not accept the model "${ input . rejectedModel } ". Choose another model for this provider, then retry.` ,
617+ ) ;
618+ } ,
619+ onSuccess : ( ) => assert . isUndefined ( input . rejectedModel ) ,
620+ } ) ,
621+ Effect . scoped ,
622+ ) ;
609623 yield * Effect . all ( agentExits , { discard : true } ) ;
610624 yield * makeAcpReplayCompletenessAssertion ( fileSystem , statusPath , transcript ) ;
611625 return { configurations } ;
@@ -772,8 +786,70 @@ describe("AcpRegistryAdapterV2", () => {
772786 } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
773787 ) ;
774788
789+ it . effect . each ( [
790+ "config" ,
791+ "legacy" ,
792+ "updated-config" ,
793+ "removed-config" ,
794+ "configuration-update" ,
795+ "unavailable-before-configuration" ,
796+ ] as const ) (
797+ "rejects an unavailable explicit model in a %s catalog before inference" ,
798+ ( catalog ) => {
799+ const duringTurn = catalog === "updated-config" || catalog === "removed-config" ;
800+ const duringConfiguration = catalog === "configuration-update" ;
801+ const changesOptions =
802+ duringConfiguration || catalog === "unavailable-before-configuration" ;
803+ const model = duringTurn || duringConfiguration ? "hermes" : "missing" ;
804+ const restrictedOption = {
805+ ...modelOption ( "model" , "other" ) ,
806+ options : [ { value : "other" , name : "Other" } ] ,
807+ } ;
808+ return openWithStoredPicks ( {
809+ setup : {
810+ ...( catalog === "legacy" || catalog === "removed-config"
811+ ? {
812+ models : {
813+ currentModelId : "other" ,
814+ availableModels : [ { modelId : "other" , name : "Other" } ] ,
815+ } ,
816+ }
817+ : { } ) ,
818+ configOptions :
819+ catalog === "legacy"
820+ ? [ ]
821+ : [
822+ {
823+ ...modelOption ( "model" , "hermes" ) ,
824+ options : [ { value : "hermes" , name : "Hermes" } ] ,
825+ } ,
826+ ...( changesOptions ? [ permissionModeOption ( "ask" ) ] : [ ] ) ,
827+ ] ,
828+ } ,
829+ storedModel : model ,
830+ ...( duringTurn ? { turnModels : [ model , model ] } : { } ) ,
831+ ...( changesOptions ? { storedModePick : "auto" } : { } ) ,
832+ rejectedModel : model ,
833+ pickFrames : duringTurn
834+ ? prompt ( configOptionUpdate ( catalog === "removed-config" ? [ ] : [ restrictedOption ] ) )
835+ : duringConfiguration
836+ ? [
837+ outbound ( "session/set_config_option" , {
838+ sessionId : "agent-session" ,
839+ configId : "permission-mode" ,
840+ value : "auto" ,
841+ } ) ,
842+ answer ( "session/set_config_option" , {
843+ configOptions : [ restrictedOption , permissionModeOption ( "auto" ) ] ,
844+ } ) ,
845+ ]
846+ : [ ] ,
847+ } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ;
848+ } ,
849+ ) ;
850+
775851 // regression: #19519 models come from session model state, not a hardcoded list
776- it . effect ( "leaves unadvertised model IDs alone in both model selection protocols " , ( ) =>
852+ it . effect ( "keeps unadvertised default and auto selections agent-controlled " , ( ) =>
777853 Effect . gen ( function * ( ) {
778854 const { configurations } = yield * openWithStoredPicks ( {
779855 setup : {
@@ -783,15 +859,7 @@ describe("AcpRegistryAdapterV2", () => {
783859 } ,
784860 } ,
785861 storedModel : "default" ,
786- turnModels : [
787- "auto" ,
788- "removed-model" ,
789- "other" ,
790- "default" ,
791- "auto" ,
792- "hermes" ,
793- "removed-model" ,
794- ] ,
862+ turnModels : [ "auto" , "default" , "other" , "default" , "auto" , "default" , "auto" ] ,
795863 pickFrames : [
796864 ...prompt ( ) ,
797865 ...prompt ( ) ,
0 commit comments