@@ -2248,6 +2248,46 @@ describe("runWithModelFallback", () => {
22482248 expect ( onFallbackStep ) . not . toHaveBeenCalled ( ) ;
22492249 } ) ;
22502250
2251+ it . each ( [
2252+ [
2253+ "direct" ,
2254+ ( ) =>
2255+ Object . assign ( new Error ( "device worker capacity remained full" ) , {
2256+ name : "WorkerRunnerCapacityError" ,
2257+ } ) ,
2258+ ] ,
2259+ [
2260+ "wrapped" ,
2261+ ( ) =>
2262+ new Error ( "worker turn failed" , {
2263+ cause : Object . assign ( new Error ( "device worker capacity remained full" ) , {
2264+ name : "WorkerRunnerCapacityError" ,
2265+ } ) ,
2266+ } ) ,
2267+ ] ,
2268+ ] ) ( "aborts fallback on %s device capacity failures" , async ( _label , makeError ) => {
2269+ const error = makeError ( ) ;
2270+ const run = vi . fn ( ) . mockRejectedValueOnce ( error ) . mockResolvedValueOnce ( "too late" ) ;
2271+ const onError = vi . fn ( ) ;
2272+ const onFallbackStep = vi . fn ( ) ;
2273+
2274+ await expect (
2275+ runWithModelFallback ( {
2276+ cfg : undefined ,
2277+ provider : "openai" ,
2278+ model : "gpt-5.6-sol" ,
2279+ fallbacksOverride : [ "openai/gpt-5.4-mini" ] ,
2280+ skipAuthProfileRuntime : true ,
2281+ run,
2282+ onError,
2283+ onFallbackStep,
2284+ } ) ,
2285+ ) . rejects . toBe ( error ) ;
2286+ expect ( run ) . toHaveBeenCalledTimes ( 1 ) ;
2287+ expect ( onError ) . not . toHaveBeenCalled ( ) ;
2288+ expect ( onFallbackStep ) . not . toHaveBeenCalled ( ) ;
2289+ } ) ;
2290+
22512291 it ( "still advances after a genuine provider rate limit" , async ( ) => {
22522292 const rateLimit = Object . assign ( new Error ( "rate limit exceeded" ) , { status : 429 } ) ;
22532293 const run = vi . fn ( ) . mockRejectedValueOnce ( rateLimit ) . mockResolvedValueOnce ( "fallback ok" ) ;
0 commit comments