From 6a87d6e81426b7fa77ad4f959de94ef146f21186 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 19 Apr 2026 03:52:57 +0100 Subject: [PATCH] test: share model fallback probe assertions --- src/agents/model-fallback.probe.test.ts | 38 ++++++++++--------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/agents/model-fallback.probe.test.ts b/src/agents/model-fallback.probe.test.ts index b60cf2e96b0..a9e8a878233 100644 --- a/src/agents/model-fallback.probe.test.ts +++ b/src/agents/model-fallback.probe.test.ts @@ -187,6 +187,18 @@ describe("runWithModelFallback – probe logic", () => { run, }); + async function expectPrimarySkippedAfterLongCooldown(reason: "billing" | "rate_limit") { + const cfg = makeCfg(); + const expiresIn30Min = NOW + 30 * 60 * 1000; + mockedGetSoonestCooldownExpiry.mockReturnValue(expiresIn30Min); + mockedResolveProfilesUnavailableReason.mockReturnValue(reason); + + const run = vi.fn().mockResolvedValue("ok"); + + const result = await runPrimaryCandidate(cfg, run); + expectPrimarySkippedForReason(result, run, reason); + } + beforeEach(() => { realDateNow = Date.now; Date.now = vi.fn(() => NOW); @@ -246,15 +258,7 @@ describe("runWithModelFallback – probe logic", () => { }); it("uses inferred unavailable reason when skipping a cooldowned primary model", async () => { - const cfg = makeCfg(); - const expiresIn30Min = NOW + 30 * 60 * 1000; - mockedGetSoonestCooldownExpiry.mockReturnValue(expiresIn30Min); - mockedResolveProfilesUnavailableReason.mockReturnValue("billing"); - - const run = vi.fn().mockResolvedValue("ok"); - - const result = await runPrimaryCandidate(cfg, run); - expectPrimarySkippedForReason(result, run, "billing"); + await expectPrimarySkippedAfterLongCooldown("billing"); }); it("probes primary model when within 2-min margin of cooldown expiry", async () => { @@ -662,22 +666,10 @@ describe("runWithModelFallback – probe logic", () => { const result = await runPrimaryCandidate(cfg, run); - expect(result.result).toBe("billing-probe-ok"); - expect(run).toHaveBeenCalledTimes(1); - expect(run).toHaveBeenCalledWith("openai", "gpt-4.1-mini", { - allowTransientCooldownProbe: true, - }); + expectPrimaryProbeSuccess(result, run, "billing-probe-ok"); }); it("skips billing-cooldowned primary with fallbacks when far from cooldown expiry", async () => { - const cfg = makeCfg(); - const expiresIn30Min = NOW + 30 * 60 * 1000; - mockedGetSoonestCooldownExpiry.mockReturnValue(expiresIn30Min); - mockedResolveProfilesUnavailableReason.mockReturnValue("billing"); - - const run = vi.fn().mockResolvedValue("ok"); - - const result = await runPrimaryCandidate(cfg, run); - expectPrimarySkippedForReason(result, run, "billing"); + await expectPrimarySkippedAfterLongCooldown("billing"); }); });