mirror of https://github.com/openclaw/openclaw.git
refactor: share fallback skip assertions
This commit is contained in:
parent
0652b885df
commit
ad52724d9a
|
|
@ -46,6 +46,20 @@ function expectFallbackUsed(
|
||||||
expect(result.attempts[0]?.reason).toBe("rate_limit");
|
expect(result.attempts[0]?.reason).toBe("rate_limit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function expectPrimarySkippedForReason(
|
||||||
|
result: { result: unknown; attempts: Array<{ reason?: string }> },
|
||||||
|
run: {
|
||||||
|
(...args: unknown[]): unknown;
|
||||||
|
mock: { calls: unknown[][] };
|
||||||
|
},
|
||||||
|
reason: string,
|
||||||
|
) {
|
||||||
|
expect(result.result).toBe("ok");
|
||||||
|
expect(run).toHaveBeenCalledTimes(1);
|
||||||
|
expect(run).toHaveBeenCalledWith("anthropic", "claude-haiku-3-5");
|
||||||
|
expect(result.attempts[0]?.reason).toBe(reason);
|
||||||
|
}
|
||||||
|
|
||||||
function expectPrimaryProbeSuccess(
|
function expectPrimaryProbeSuccess(
|
||||||
result: { result: unknown },
|
result: { result: unknown },
|
||||||
run: {
|
run: {
|
||||||
|
|
@ -183,11 +197,7 @@ describe("runWithModelFallback – probe logic", () => {
|
||||||
const run = vi.fn().mockResolvedValue("ok");
|
const run = vi.fn().mockResolvedValue("ok");
|
||||||
|
|
||||||
const result = await runPrimaryCandidate(cfg, run);
|
const result = await runPrimaryCandidate(cfg, run);
|
||||||
|
expectPrimarySkippedForReason(result, run, "billing");
|
||||||
expect(result.result).toBe("ok");
|
|
||||||
expect(run).toHaveBeenCalledTimes(1);
|
|
||||||
expect(run).toHaveBeenCalledWith("anthropic", "claude-haiku-3-5");
|
|
||||||
expect(result.attempts[0]?.reason).toBe("billing");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("probes primary model when within 2-min margin of cooldown expiry", async () => {
|
it("probes primary model when within 2-min margin of cooldown expiry", async () => {
|
||||||
|
|
@ -540,10 +550,6 @@ describe("runWithModelFallback – probe logic", () => {
|
||||||
const run = vi.fn().mockResolvedValue("ok");
|
const run = vi.fn().mockResolvedValue("ok");
|
||||||
|
|
||||||
const result = await runPrimaryCandidate(cfg, run);
|
const result = await runPrimaryCandidate(cfg, run);
|
||||||
|
expectPrimarySkippedForReason(result, run, "billing");
|
||||||
expect(result.result).toBe("ok");
|
|
||||||
expect(run).toHaveBeenCalledTimes(1);
|
|
||||||
expect(run).toHaveBeenCalledWith("anthropic", "claude-haiku-3-5");
|
|
||||||
expect(result.attempts[0]?.reason).toBe("billing");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue