






























@@ -39,7 +39,11 @@ import {
3939resolveCodexPluginAppCacheEndpoint,
4040} from "./plugin-app-cache-key.js";
4141import type { CodexServerNotification } from "./protocol.js";
42-import { rememberCodexRateLimits, resetCodexRateLimitCacheForTests } from "./rate-limit-cache.js";
42+import {
43+readRecentCodexRateLimits,
44+rememberCodexRateLimits,
45+resetCodexRateLimitCacheForTests,
46+} from "./rate-limit-cache.js";
4347import {
4448runCodexAppServerAttempt as runCodexAppServerAttemptImpl,
4549__testing,
@@ -1982,6 +1986,29 @@ describe("runCodexAppServerAttempt", () => {
19821986);
19831987});
198419881989+it("yields a macrotask before processing queued app-server notifications", async () => {
1990+const harness = createStartedThreadHarness();
1991+const params = createParams(
1992+path.join(tempDir, "session.jsonl"),
1993+path.join(tempDir, "workspace"),
1994+);
1995+params.timeoutMs = 1_000;
1996+1997+const run = runCodexAppServerAttempt(params);
1998+await harness.waitForMethod("turn/start");
1999+2000+const notification = rateLimitsUpdated(Date.now() + 60_000);
2001+const processing = harness.notify(notification);
2002+await Promise.resolve();
2003+2004+expect(readRecentCodexRateLimits()).toBeUndefined();
2005+await processing;
2006+expect(readRecentCodexRateLimits()).toEqual(notification.params);
2007+2008+await harness.completeTurn({ threadId: "thread-1", turnId: "turn-1" });
2009+await expect(run).resolves.toMatchObject({ aborted: false, timedOut: false });
2010+});
2011+19852012it("releases the session when a completed agent message item goes quiet", async () => {
19862013let notify: (notification: CodexServerNotification) => Promise<void> = async () => undefined;
19872014const request = vi.fn(async (method: string) => {
@@ -3250,7 +3277,7 @@ describe("runCodexAppServerAttempt", () => {
32503277if (!harnessRef.current) {
32513278throw new Error("Expected Codex app-server harness to be initialized");
32523279}
3253-await harnessRef.current.notify(rateLimitsUpdated(resetsAt));
3280+void harnessRef.current.notify(rateLimitsUpdated(resetsAt));
32543281throw Object.assign(new Error("You've reached your usage limit."), {
32553282data: { codexErrorInfo: "usageLimitExceeded" },
32563283});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。