test: tighten auth profile assertions

This commit is contained in:
Peter Steinberger
2026-05-08 14:47:55 +01:00
parent 164714d36a
commit 1b9986952c
2 changed files with 10 additions and 4 deletions

View File

@@ -170,7 +170,11 @@ describe("saveAuthProfileStore", () => {
lastGood?: unknown;
usageStats?: unknown;
};
expect(authProfiles.profiles["anthropic:default"]).toEqual(expect.any(Object));
expect(authProfiles.profiles["anthropic:default"]).toEqual({
type: "api_key",
provider: "anthropic",
key: "sk-anthropic-plain",
});
expect(authProfiles.order).toBeUndefined();
expect(authProfiles.lastGood).toBeUndefined();
expect(authProfiles.usageStats).toBeUndefined();

View File

@@ -364,12 +364,13 @@ describe("clearExpiredCooldowns", () => {
});
it("clears expired cooldownUntil and resets errorCount", () => {
const lastFailureAt = Date.now() - 120_000;
const store = makeStore({
"anthropic:default": {
cooldownUntil: Date.now() - 1_000,
errorCount: 4,
failureCounts: { rate_limit: 3, timeout: 1 },
lastFailureAt: Date.now() - 120_000,
lastFailureAt,
},
});
@@ -380,7 +381,7 @@ describe("clearExpiredCooldowns", () => {
expect(stats?.errorCount).toBe(0);
expect(stats?.failureCounts).toBeUndefined();
// lastFailureAt preserved for failureWindowMs decay
expect(stats?.lastFailureAt).toEqual(expect.any(Number));
expect(stats?.lastFailureAt).toBe(lastFailureAt);
});
it("clears expired disabledUntil and disabledReason", () => {
@@ -610,6 +611,7 @@ describe("markAuthProfileUsed", () => {
storeMocks.updateAuthProfileStoreWithLock.mockResolvedValue(null);
const beforeUsed = Date.now();
await markAuthProfileUsed({
store,
profileId: "anthropic:default",
@@ -622,7 +624,7 @@ describe("markAuthProfileUsed", () => {
);
expect(store.usageStats?.["anthropic:default"]?.errorCount).toBe(0);
expect(store.usageStats?.["anthropic:default"]?.cooldownUntil).toBeUndefined();
expect(store.usageStats?.["anthropic:default"]?.lastUsed).toEqual(expect.any(Number));
expect(store.usageStats?.["anthropic:default"]?.lastUsed).toBeGreaterThanOrEqual(beforeUsed);
});
it("adopts locked store usage stats without saving locally when lock update succeeds", async () => {