@@ -296,29 +296,29 @@ describe("subagent fallback without primary auth cooldown failure", () => {
296296 expect ( response . status ) . not . toBe ( 429 ) ;
297297 } ) ;
298298
299- test ( "final-route auth failure does not leave a primary probe lease" , async ( ) => {
299+ test ( "final-route direct auth failure does not acquire a pool probe lease" , async ( ) => {
300300 const now = 1_800_000_000_000 ;
301301 Date . now = ( ) => now ;
302302 installPoolCredential ( "pool-a" , "pool_acc" , now ) ;
303303 const cfg : OcxConfig = {
304304 port : 0 ,
305- defaultProvider : "openai " ,
305+ defaultProvider : "xai " ,
306306 activeCodexAccountId : "pool-a" ,
307307 autoSwitchThreshold : 80 ,
308- subagentModelFallback : [ "openai-direct/ gpt-5.5" ] ,
308+ subagentModelFallback : [ "gpt-5.5" ] ,
309309 providers : {
310310 openai : {
311- adapter : "openai-responses" ,
312- baseUrl : "https://chatgpt.com/backend-api/codex" ,
313- authMode : "forward" ,
314- codexAccountMode : "pool" ,
315- } ,
316- "openai-direct" : {
317311 adapter : "openai-responses" ,
318312 baseUrl : "https://chatgpt.com/backend-api/codex" ,
319313 authMode : "forward" ,
320314 codexAccountMode : "direct" ,
321315 } ,
316+ xai : {
317+ adapter : "openai-chat" ,
318+ baseUrl : "https://api.x.ai/v1" ,
319+ authMode : "key" ,
320+ apiKey : "xai-test" ,
321+ } ,
322322 } ,
323323 codexAccounts : [
324324 { id : "main" , email : "main@example.test" , isMain : true } ,
@@ -328,8 +328,16 @@ describe("subagent fallback without primary auth cooldown failure", () => {
328328 updateAccountQuota ( "pool-a" , 95 , undefined , 20 ) ;
329329 const resetAt = Math . floor ( ( now + 4 * 24 * 60 * 60_000 ) / 1000 ) ;
330330 recordCodexUpstreamOutcome ( cfg , "pool-a" , 429 , { resetAt, now } ) ;
331+ const { noteSubagentModelFailure } = await import ( "../src/codex/subagent-model-fallback" ) ;
332+ noteSubagentModelFailure ( "xai/grok-4.5" , "429" , cfg ) ;
331333
332- // Omit authorization so direct-mode final auth fails — primary never leased.
334+ let fetchCalls = 0 ;
335+ globalThis . fetch = ( async ( ) => {
336+ fetchCalls += 1 ;
337+ throw new Error ( "must not dispatch" ) ;
338+ } ) as typeof fetch ;
339+
340+ // Omit authorization so the canonical Direct final route fails before dispatch.
333341 const response = await handleResponses (
334342 new Request ( "http://localhost/v1/responses" , {
335343 method : "POST" ,
@@ -338,7 +346,7 @@ describe("subagent fallback without primary auth cooldown failure", () => {
338346 "x-openai-subagent" : "collab_spawn" ,
339347 } ,
340348 body : JSON . stringify ( {
341- model : "gpt-5.6-sol " ,
349+ model : "xai/grok-4.5 " ,
342350 input : readableAgentInput ( ) ,
343351 stream : false ,
344352 } ) ,
@@ -348,6 +356,7 @@ describe("subagent fallback without primary auth cooldown failure", () => {
348356 ) ;
349357
350358 expect ( response . status ) . toBe ( 401 ) ;
359+ expect ( fetchCalls ) . toBe ( 0 ) ;
351360 expect ( getCodexUpstreamHealth ( "pool-a" ) ?. probeLeaseId ) . toBeUndefined ( ) ;
352361 } ) ;
353362} ) ;
0 commit comments