
























@@ -39,6 +39,22 @@ function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean)
3939return count;
4040}
414142+async function withTimeout<T>(promise: Promise<T>, timeoutMs: number, message: string): Promise<T> {
43+let timer: ReturnType<typeof setTimeout> | undefined;
44+try {
45+return await Promise.race([
46+promise,
47+new Promise<never>((_, reject) => {
48+timer = setTimeout(() => reject(new Error(message)), timeoutMs);
49+}),
50+]);
51+} finally {
52+if (timer) {
53+clearTimeout(timer);
54+}
55+}
56+}
57+4258// ─────────────────────────────────────────────────────────────────────────────
4359// Mock OpenAIWebSocketManager
4460// ─────────────────────────────────────────────────────────────────────────────
@@ -2722,16 +2738,15 @@ describe("createOpenAIWebSocketStreamFn", () => {
27222738);
2723273927242740await expect(
2725-Promise.race([
2741+withTimeout(
27262742(
27272743stream as unknown as {
27282744result: () => Promise<{ content?: Array<{ text?: string }> }>;
27292745}
27302746).result(),
2731-new Promise((_, reject) =>
2732-setTimeout(() => reject(new Error("SSE fallback result timed out")), 100),
2733-),
2734-]),
2747+100,
2748+"SSE fallback result timed out",
2749+),
27352750).resolves.toMatchObject({
27362751content: [{ text: "http fallback response" }],
27372752});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。