From d787cbf4341c060683a8a1b5e611b46fdbb3a186 Mon Sep 17 00:00:00 2001 From: Ramez Gaberiel Date: Sun, 22 Feb 2026 13:25:49 -0600 Subject: [PATCH] fix: remove non-existent 'fail' import from vitest Replace try/catch with fail() pattern with expect().rejects.toThrow() which is the standard vitest/Jest pattern for async error expectations. - Remove 'fail' from vitest imports (not exported in this version) - Convert auth/billing cooldown tests to use expect().rejects.toThrow() - All 34 tests still passing with proper async error handling --- src/agents/model-fallback.test.ts | 32 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/agents/model-fallback.test.ts b/src/agents/model-fallback.test.ts index e767e481bc9..76649602bc7 100644 --- a/src/agents/model-fallback.test.ts +++ b/src/agents/model-fallback.test.ts @@ -2,7 +2,7 @@ import crypto from "node:crypto"; import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; -import { describe, expect, it, vi, fail } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import type { AuthProfileStore } from "./auth-profiles.js"; import { saveAuthProfileStore } from "./auth-profiles.js"; @@ -993,19 +993,18 @@ describe("runWithModelFallback", () => { const run = vi.fn().mockResolvedValueOnce("should not be called"); - try { - await runWithModelFallback({ + await expect( + runWithModelFallback({ cfg, provider: "anthropic", model: "claude-opus-4-6", run, agentDir: dir, - }); - fail("Should have thrown error"); - } catch { - // Auth cooldown should skip both primary and same-provider fallbacks - expect(run).toHaveBeenCalledTimes(0); // No attempts made - } + }), + ).rejects.toThrow("All models failed"); + + // Auth cooldown should skip both primary and same-provider fallbacks + expect(run).toHaveBeenCalledTimes(0); // No attempts made }); it("does NOT attempt fallbacks during billing cooldown", async () => { @@ -1023,19 +1022,18 @@ describe("runWithModelFallback", () => { const run = vi.fn().mockResolvedValueOnce("should not be called"); - try { - await runWithModelFallback({ + await expect( + runWithModelFallback({ cfg, provider: "anthropic", model: "claude-opus-4-6", run, agentDir: dir, - }); - fail("Should have thrown error"); - } catch { - // Billing cooldown should skip both primary and same-provider fallbacks - expect(run).toHaveBeenCalledTimes(0); // No attempts made - } + }), + ).rejects.toThrow("All models failed"); + + // Billing cooldown should skip both primary and same-provider fallbacks + expect(run).toHaveBeenCalledTimes(0); // No attempts made }); it("tries cross-provider fallbacks when same provider has rate limit", async () => {