Skip to content

Commit 3cab4a7

Browse files
authored
test(anthropic): await the admitted provider quota cache write (#8004)
#7998 made the provider account quota cache write wait for config-root ACL admission, so the deferred-persistence test read the file before it existed on Windows (ENOENT, windows 9/11 of lane=all run 41068188012). Expose the admitted write like settleQuotaPersistenceForTests and await it. Co-authored-by: JUN <[email protected]>
1 parent 8e58c96 commit 3cab4a7

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/providers/account-quota-disk.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ let persistTimer: ReturnType<typeof setTimeout> | null = null;
4444
let persistStartedAt: number | null = null;
4545
/** Bumped by cancellation so a fired callback still waiting for ACL admission writes nothing. */
4646
let persistGeneration = 0;
47+
let persistWrite: Promise<void> = Promise.resolve();
48+
/** Test seam: wait for a fired persistence callback's admitted write (as settleQuotaPersistenceForTests). */
49+
export function settleAccountQuotaPersistForTests(): Promise<void> { return persistWrite; }
4750

4851
/** Read the snapshot. Returns an empty map for a missing, corrupt or stale file. */
4952
export function readPersistedAccountQuotas(now = Date.now()): Map<string, ProviderQuota> {
@@ -111,7 +114,7 @@ export function schedulePersistAccountQuotas(
111114
// skips this best-effort write.
112115
const dir = getConfigDir();
113116
const generation = persistGeneration;
114-
void withConfigDirHardeningSettled(dir, () => {
117+
persistWrite = withConfigDirHardeningSettled(dir, () => {
115118
if (generation !== persistGeneration) return;
116119
const out: Record<string, ProviderQuota> = {};
117120
for (const [key, quota] of rows()) out[key] = quota;

‎tests/adapters/anthropic/anthropic-ratelimit-headers.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { getAccountSet, saveCredential, setActiveAccount } from "../../../src/oauth/store";
2929
import { clearPoolRotationState } from "../../../src/codex/pool-rotation";
3030
import { removeTreeWithRetry } from "../../helpers/remove-tree";
31+
import { settleAccountQuotaPersistForTests } from "../../../src/providers/account-quota-disk";
3132
import type { OcxConfig } from "../../../src/types";
3233

3334
const originalHome = process.env.OPENCODEX_HOME;
@@ -810,6 +811,8 @@ describe("Anthropic known-reset expiry", () => {
810811
try { observe(id!); } finally { timer.mockRestore(); }
811812
now += 60_000;
812813
flush();
814+
// The fired callback admits its write after any overlapping config-root ACL flight (#7815).
815+
await settleAccountQuotaPersistForTests();
813816
const disk = JSON.parse(readFileSync(join(home, "provider-account-quota-cache.json"), "utf8"));
814817
expect(disk.rows[`anthropic\u0000${id}`]).toEqual({ fiveHourPercent: 41, updatedAt: start });
815818
expect(disk.rows["zai\u0000untouched"]).toEqual(saved);

0 commit comments

Comments
 (0)