mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 04:32:44 +00:00
Tests: cover OpenRouter cooldown display bypass
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
markAuthProfileFailure,
|
markAuthProfileFailure,
|
||||||
resolveProfilesUnavailableReason,
|
resolveProfilesUnavailableReason,
|
||||||
resolveProfileUnusableUntil,
|
resolveProfileUnusableUntil,
|
||||||
|
resolveProfileUnusableUntilForDisplay,
|
||||||
} from "./usage.js";
|
} from "./usage.js";
|
||||||
|
|
||||||
vi.mock("./store.js", async (importOriginal) => {
|
vi.mock("./store.js", async (importOriginal) => {
|
||||||
@@ -24,6 +25,7 @@ function makeStore(usageStats: AuthProfileStore["usageStats"]): AuthProfileStore
|
|||||||
profiles: {
|
profiles: {
|
||||||
"anthropic:default": { type: "api_key", provider: "anthropic", key: "sk-test" },
|
"anthropic:default": { type: "api_key", provider: "anthropic", key: "sk-test" },
|
||||||
"openai:default": { type: "api_key", provider: "openai", key: "sk-test-2" },
|
"openai:default": { type: "api_key", provider: "openai", key: "sk-test-2" },
|
||||||
|
"openrouter:default": { type: "api_key", provider: "openrouter", key: "sk-or-test" },
|
||||||
},
|
},
|
||||||
usageStats,
|
usageStats,
|
||||||
};
|
};
|
||||||
@@ -51,6 +53,29 @@ describe("resolveProfileUnusableUntil", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("resolveProfileUnusableUntilForDisplay", () => {
|
||||||
|
it("hides cooldown markers for OpenRouter profiles", () => {
|
||||||
|
const store = makeStore({
|
||||||
|
"openrouter:default": {
|
||||||
|
cooldownUntil: Date.now() + 60_000,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(resolveProfileUnusableUntilForDisplay(store, "openrouter:default")).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps cooldown markers visible for other providers", () => {
|
||||||
|
const until = Date.now() + 60_000;
|
||||||
|
const store = makeStore({
|
||||||
|
"anthropic:default": {
|
||||||
|
cooldownUntil: until,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(resolveProfileUnusableUntilForDisplay(store, "anthropic:default")).toBe(until);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// isProfileInCooldown
|
// isProfileInCooldown
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -84,6 +109,17 @@ describe("isProfileInCooldown", () => {
|
|||||||
});
|
});
|
||||||
expect(isProfileInCooldown(store, "anthropic:default")).toBe(true);
|
expect(isProfileInCooldown(store, "anthropic:default")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns false for OpenRouter even when cooldown fields exist", () => {
|
||||||
|
const store = makeStore({
|
||||||
|
"openrouter:default": {
|
||||||
|
cooldownUntil: Date.now() + 60_000,
|
||||||
|
disabledUntil: Date.now() + 60_000,
|
||||||
|
disabledReason: "billing",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(isProfileInCooldown(store, "openrouter:default")).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("resolveProfilesUnavailableReason", () => {
|
describe("resolveProfilesUnavailableReason", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user