Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions tests/routing/anthropic-quorum-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
resetAnthropicRoutingForManualSelection,
rotateAnthropicAccountOn429,
} from "../../src/oauth/anthropic-routing";
import { getAccountSet, markAccountNeedsReauth, saveCredential } from "../../src/oauth/store";
import { getAccountSet, markAccountNeedsReauth, removeAccount, saveCredential } from "../../src/oauth/store";
import { removeTreeWithRetry } from "../helpers/remove-tree";

const originalHome = process.env.OPENCODEX_HOME;
Expand Down Expand Up @@ -158,15 +158,17 @@ describe("Anthropic failover quorum cache", () => {
});

test("removing an account invalidates immediately, not after the TTL", async () => {
// The management DELETE route calls clearAnthropicSessionAffinityForAccount for Anthropic.
// Without invalidation there, deleting the second account would leave quorum true for up to
// 2s -- long enough for a request to record an id whose credential is already gone.
// Mirror the real DELETE route (src/server/management/oauth-account-routes.ts): the
// credential is removed FIRST, and only then is routing state cleared. Clearing affinity
// alone leaves the roster at 2, so the predicate could never observe the transition this
// test is named for -- it could only assert that the store was re-read.
const start = Date.now();
const ids = await seed(2);
expect(hasAnthropicFailoverQuorum(start)).toBe(true);
expect(await removeAccount("anthropic", ids[1]!)).toBe(true);
clearAnthropicSessionAffinityForAccount(ids[1]!);
Comment on lines +168 to 169

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Route the test through the DELETE handler

If the Anthropic branch in oauth-account-routes.ts stops calling clearAnthropicSessionAffinityForAccount, this test still passes because it manually performs both the store removal and cache invalidation. The existing DELETE API test only verifies that the roster shrinks, so the production regression—completed account deletion leaving the cached quorum true for the TTL—would remain undetected. Invoke the DELETE handler/endpoint here, or add the quorum assertion to the API test, rather than duplicating its implementation.

Useful? React with 👍 / 👎.

markStoreUnread();
hasAnthropicFailoverQuorum(start + 1);
expect(hasAnthropicFailoverQuorum(start + 1)).toBe(false);
expect(storeWasRead()).toBe(true);
});

Expand Down
Loading