惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
博客园 - 司徒正美
C
Check Point Blog
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
IT之家
IT之家
B
Blog
博客园_首页
量子位
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
J
Java Code Geeks
H
Help Net Security
A
About on SuperTechFans
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
D
DataBreaches.Net
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(channels): contain draft stream flush failures (#8271...
steipete · 2026-05-17 · via Recent Commits to openclaw:main

@@ -0,0 +1,176 @@

1+

import { describe, expect, it, vi } from "vitest";

2+

import { createDraftStreamLoop } from "./draft-stream-loop.js";

3+4+

const flushMicrotasks = async () => {

5+

await Promise.resolve();

6+

await Promise.resolve();

7+

};

8+9+

const flushMacrotask = async () => {

10+

await new Promise((resolve) => setTimeout(resolve, 0));

11+

};

12+13+

async function captureUnhandledRejections(

14+

run: (rejections: unknown[]) => Promise<void>,

15+

settle: () => Promise<void> = flushMacrotask,

16+

) {

17+

const rejections: unknown[] = [];

18+

const onUnhandledRejection = (reason: unknown) => {

19+

rejections.push(reason);

20+

};

21+

process.on("unhandledRejection", onUnhandledRejection);

22+

try {

23+

await run(rejections);

24+

await settle();

25+

} finally {

26+

process.off("unhandledRejection", onUnhandledRejection);

27+

}

28+

}

29+30+

describe("createDraftStreamLoop", () => {

31+

it("contains immediate background flush rejections and preserves pending text", async () => {

32+

await captureUnhandledRejections(async (rejections) => {

33+

const error = new Error("send failed");

34+

const onBackgroundFlushError = vi.fn<(err: unknown) => void>();

35+

const sendOrEditStreamMessage = vi

36+

.fn<(text: string) => Promise<boolean>>()

37+

.mockRejectedValueOnce(error)

38+

.mockResolvedValueOnce(true);

39+40+

const loop = createDraftStreamLoop({

41+

throttleMs: 0,

42+

isStopped: () => false,

43+

sendOrEditStreamMessage,

44+

onBackgroundFlushError,

45+

});

46+47+

loop.update("hello");

48+

await flushMicrotasks();

49+

await flushMacrotask();

50+

await loop.flush();

51+52+

expect(rejections).toStrictEqual([]);

53+

expect(onBackgroundFlushError).toHaveBeenCalledWith(error);

54+

expect(sendOrEditStreamMessage).toHaveBeenNthCalledWith(1, "hello");

55+

expect(sendOrEditStreamMessage).toHaveBeenNthCalledWith(2, "hello");

56+

});

57+

});

58+59+

it("contains scheduled background flush rejections and preserves pending text", async () => {

60+

vi.useFakeTimers();

61+

try {

62+

await captureUnhandledRejections(

63+

async (rejections) => {

64+

const error = new Error("send failed");

65+

const onBackgroundFlushError = vi.fn<(err: unknown) => void>();

66+

const sendOrEditStreamMessage = vi

67+

.fn<(text: string) => Promise<boolean>>()

68+

.mockRejectedValueOnce(error)

69+

.mockResolvedValueOnce(true);

70+71+

const loop = createDraftStreamLoop({

72+

throttleMs: 100,

73+

isStopped: () => false,

74+

sendOrEditStreamMessage,

75+

onBackgroundFlushError,

76+

});

77+78+

loop.update("scheduled");

79+

await vi.advanceTimersByTimeAsync(100);

80+

await flushMicrotasks();

81+

await loop.flush();

82+83+

expect(rejections).toStrictEqual([]);

84+

expect(onBackgroundFlushError).toHaveBeenCalledWith(error);

85+

expect(sendOrEditStreamMessage).toHaveBeenNthCalledWith(1, "scheduled");

86+

expect(sendOrEditStreamMessage).toHaveBeenNthCalledWith(2, "scheduled");

87+

},

88+

async () => {

89+

await vi.advanceTimersByTimeAsync(0);

90+

},

91+

);

92+

} finally {

93+

vi.useRealTimers();

94+

}

95+

});

96+97+

it("contains synchronous sender failures from background flushes", async () => {

98+

await captureUnhandledRejections(async (rejections) => {

99+

const error = new Error("send failed");

100+

const onBackgroundFlushError = vi.fn<(err: unknown) => void>();

101+

const sendOrEditStreamMessage = vi

102+

.fn<(text: string) => Promise<boolean>>()

103+

.mockImplementationOnce(() => {

104+

throw error;

105+

})

106+

.mockResolvedValueOnce(true);

107+108+

const loop = createDraftStreamLoop({

109+

throttleMs: 0,

110+

isStopped: () => false,

111+

sendOrEditStreamMessage,

112+

onBackgroundFlushError,

113+

});

114+115+

loop.update("hello");

116+

await flushMicrotasks();

117+

await flushMacrotask();

118+

await loop.flush();

119+120+

expect(rejections).toStrictEqual([]);

121+

expect(onBackgroundFlushError).toHaveBeenCalledWith(error);

122+

expect(sendOrEditStreamMessage).toHaveBeenNthCalledWith(1, "hello");

123+

expect(sendOrEditStreamMessage).toHaveBeenNthCalledWith(2, "hello");

124+

});

125+

});

126+127+

it("contains background flush error reporter failures", async () => {

128+

await captureUnhandledRejections(async (rejections) => {

129+

const error = new Error("send failed");

130+

const onBackgroundFlushError = vi.fn<(err: unknown) => void>(() => {

131+

throw new Error("report failed");

132+

});

133+

const sendOrEditStreamMessage = vi

134+

.fn<(text: string) => Promise<boolean>>()

135+

.mockRejectedValueOnce(error)

136+

.mockResolvedValueOnce(true);

137+138+

const loop = createDraftStreamLoop({

139+

throttleMs: 0,

140+

isStopped: () => false,

141+

sendOrEditStreamMessage,

142+

onBackgroundFlushError,

143+

});

144+145+

loop.update("hello");

146+

await flushMicrotasks();

147+

await flushMacrotask();

148+

await loop.flush();

149+150+

expect(rejections).toStrictEqual([]);

151+

expect(onBackgroundFlushError).toHaveBeenCalledWith(error);

152+

expect(sendOrEditStreamMessage).toHaveBeenNthCalledWith(2, "hello");

153+

});

154+

});

155+156+

it("keeps explicit flush rejections visible and preserves pending text", async () => {

157+

const error = new Error("send failed");

158+

const sendOrEditStreamMessage = vi

159+

.fn<(text: string) => Promise<boolean>>()

160+

.mockRejectedValueOnce(error)

161+

.mockResolvedValueOnce(true);

162+163+

const loop = createDraftStreamLoop({

164+

throttleMs: 100,

165+

isStopped: () => false,

166+

sendOrEditStreamMessage,

167+

});

168+169+

loop.update("hello");

170+

await expect(loop.flush()).rejects.toThrow(error);

171+

await loop.flush();

172+173+

expect(sendOrEditStreamMessage).toHaveBeenNthCalledWith(1, "hello");

174+

expect(sendOrEditStreamMessage).toHaveBeenNthCalledWith(2, "hello");

175+

});

176+

});