test: dedupe agent tests and session helpers

This commit is contained in:
Peter Steinberger
2026-02-22 17:11:17 +00:00
parent 415686244a
commit ad1072842e
31 changed files with 1021 additions and 1109 deletions

View File

@@ -37,6 +37,19 @@ function makeCfg(overrides: Partial<OpenClawConfig> = {}): OpenClawConfig {
} as OpenClawConfig;
}
function expectFallbackUsed(
result: { result: unknown; attempts: Array<{ reason?: string }> },
run: {
(...args: unknown[]): unknown;
mock: { calls: unknown[][] };
},
) {
expect(result.result).toBe("ok");
expect(run).toHaveBeenCalledTimes(1);
expect(run).toHaveBeenCalledWith("anthropic", "claude-haiku-3-5");
expect(result.attempts[0]?.reason).toBe("rate_limit");
}
describe("runWithModelFallback probe logic", () => {
let realDateNow: () => number;
const NOW = 1_700_000_000_000;
@@ -95,10 +108,7 @@ describe("runWithModelFallback probe logic", () => {
});
// Should skip primary and use fallback
expect(result.result).toBe("ok");
expect(run).toHaveBeenCalledTimes(1);
expect(run).toHaveBeenCalledWith("anthropic", "claude-haiku-3-5");
expect(result.attempts[0]?.reason).toBe("rate_limit");
expectFallbackUsed(result, run);
});
it("probes primary model when within 2-min margin of cooldown expiry", async () => {
@@ -201,10 +211,7 @@ describe("runWithModelFallback probe logic", () => {
});
// Should be throttled → skip primary, use fallback
expect(result.result).toBe("ok");
expect(run).toHaveBeenCalledTimes(1);
expect(run).toHaveBeenCalledWith("anthropic", "claude-haiku-3-5");
expect(result.attempts[0]?.reason).toBe("rate_limit");
expectFallbackUsed(result, run);
});
it("allows probe when 30s have passed since last probe", async () => {