Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(maker-core): 用 fake timers 固化 app-server 总超时语义 (#1419)

Chris Zhang8c6c7dc977cb
diff --git a/packages/maker-core/src/agents/codex/app-server/host.test.ts b/packages/maker-core/src/agents/codex/app-server/host.test.ts
index b1ae25a391..d2042822c7 100644
--- a/packages/maker-core/src/agents/codex/app-server/host.test.ts
+++ b/packages/maker-core/src/agents/codex/app-server/host.test.ts
@@ -163,27 +163,36 @@ describe('AppServerHost.request startup timeout', () => {
});
it('treats timeoutMs as an overall deadline across startup + request (copilot R9)', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] });
// timeoutMs 不是「startup 一次 + request 再一次」的双重施加: startup 用掉
// 的预算要从 request 里扣, 最坏等待仍是 1× timeoutMs — 否则 60s 关键 RPC
// 在冷启动路径上最坏拖到 ~120s, UI 长时间卡 generating。
- // DelayedTransport(40): startup ~40ms, 预算 50ms → request 只剩 ~10ms。
- // 1× 语义 ~50ms 超时; 2× 语义要 ~90ms (40 + 50) 才超时。
+ // fake clock 下 DelayedTransport(40): startup 精确用掉 40ms,
+ // 50ms overall deadline 只剩 10ms 给 request; 若误变成 2× 语义则要到 90ms。
const host = new AppServerHost({
createTransport: () => new DelayedTransport(40),
logger,
clientInfo: { name: 'cindy-test', version: '0.0.0' },
});
- const startedAt = Date.now();
- await expect(host.request('turn/start', {}, { timeoutMs: 50 })).rejects.toThrow(
- /timed out after \d+ms|consumed the entire/,
- );
- // 1× 语义 ~50ms vs 2× 语义 ~90ms 的判别线。原值 70 在慢 CI(Windows runner)
- // 上恰好压线(实测 elapsed===70 被 < 判挂):50ms 定时器 + 调度抖动可到
- // 70–80ms。放宽到 <80 仍与 2× 语义的 ~90ms 保持 ≥10ms 判别余量。
- expect(Date.now() - startedAt).toBeLessThan(80);
-
- await host.shutdown();
+ try {
+ const request = host.request('turn/start', {}, { timeoutMs: 50 });
+ const settled = vi.fn();
+ void request.then(settled, settled);
+ const rejection = expect(request).rejects.toThrow(
+ 'codex app-server turn/start timed out after 10ms',
+ );
+
+ await vi.advanceTimersByTimeAsync(49);
+ expect(settled).not.toHaveBeenCalled();
+
+ await vi.advanceTimersByTimeAsync(1);
+ await rejection;
+ expect(settled).toHaveBeenCalledTimes(1);
+ } finally {
+ await host.shutdown();
+ vi.useRealTimers();
+ }
});
});