mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-07 22:44:16 +00:00
Tests: cover OpenRouter cooldown display bypass
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
markAuthProfileFailure,
|
||||
resolveProfilesUnavailableReason,
|
||||
resolveProfileUnusableUntil,
|
||||
resolveProfileUnusableUntilForDisplay,
|
||||
} from "./usage.js";
|
||||
|
||||
vi.mock("./store.js", async (importOriginal) => {
|
||||
@@ -24,6 +25,7 @@ function makeStore(usageStats: AuthProfileStore["usageStats"]): AuthProfileStore
|
||||
profiles: {
|
||||
"anthropic:default": { type: "api_key", provider: "anthropic", key: "sk-test" },
|
||||
"openai:default": { type: "api_key", provider: "openai", key: "sk-test-2" },
|
||||
"openrouter:default": { type: "api_key", provider: "openrouter", key: "sk-or-test" },
|
||||
},
|
||||
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
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -84,6 +109,17 @@ describe("isProfileInCooldown", () => {
|
||||
});
|
||||
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", () => {
|
||||
|
||||
Reference in New Issue
Block a user