11// Tests agent runner execution setup, command args, and model fallback routing.
22import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
33import { OAuthRefreshFailureError } from "../../agents/auth-profiles/oauth-refresh-failure.js" ;
4+ import { testing as cliBackendsTesting } from "../../agents/cli-backends.js" ;
45import { FailoverError } from "../../agents/failover-error.js" ;
56import { LiveSessionModelSwitchError } from "../../agents/live-model-switch-error.js" ;
67import { MissingProviderAuthError } from "../../agents/model-auth.js" ;
@@ -48,6 +49,10 @@ const GENERIC_RUN_FAILURE_TEXT =
4849 "⚠️ Something went wrong while processing your request. Please try again, or use /new to start a fresh session." ;
4950
5051describe ( "resolveSessionRuntimeOverrideForProvider" , ( ) => {
52+ afterEach ( ( ) => {
53+ cliBackendsTesting . resetDepsForTest ( ) ;
54+ } ) ;
55+
5156 it ( "ignores unsupported session runtime pins" , ( ) => {
5257 expect (
5358 resolveSessionRuntimeOverrideForProvider ( {
@@ -56,6 +61,48 @@ describe("resolveSessionRuntimeOverrideForProvider", () => {
5661 } ) ,
5762 ) . toBeUndefined ( ) ;
5863 } ) ;
64+
65+ it ( "keeps CLI runtime pins only when the runtime serves the selected provider" , ( ) => {
66+ cliBackendsTesting . setDepsForTest ( {
67+ resolveRuntimeCliBackends : ( ) => [ ] ,
68+ resolvePluginSetupCliBackend : ( { backend, config } ) =>
69+ backend === "claude-cli" && config
70+ ? {
71+ pluginId : "anthropic" ,
72+ backend : {
73+ id : "claude-cli" ,
74+ modelProvider : "anthropic" ,
75+ config : { command : "claude" } ,
76+ bundleMcp : false ,
77+ } ,
78+ }
79+ : undefined ,
80+ } ) ;
81+ const cfg = {
82+ agents : {
83+ defaults : {
84+ cliBackends : {
85+ "claude-cli" : { command : "claude" } ,
86+ } ,
87+ } ,
88+ } ,
89+ } ;
90+
91+ expect (
92+ resolveSessionRuntimeOverrideForProvider ( {
93+ provider : "anthropic" ,
94+ entry : { agentRuntimeOverride : "claude-cli" } ,
95+ cfg,
96+ } ) ,
97+ ) . toBe ( "claude-cli" ) ;
98+ expect (
99+ resolveSessionRuntimeOverrideForProvider ( {
100+ provider : "openai" ,
101+ entry : { agentRuntimeOverride : "claude-cli" } ,
102+ cfg,
103+ } ) ,
104+ ) . toBeUndefined ( ) ;
105+ } ) ;
59106} ) ;
60107
61108function makeTestModel ( id : string , contextTokens : number ) : ModelDefinitionConfig {
0 commit comments