test: dedupe embedded subscribe flush mock reads · openclaw/openclaw@f6d093e
steipete
·
2026-05-13
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,14 @@ import {
|
5 | 5 | } from "./pi-embedded-subscribe.e2e-harness.js"; |
6 | 6 | import { subscribeEmbeddedPiSession } from "./pi-embedded-subscribe.js"; |
7 | 7 | |
| 8 | +function firstBlockReplyText(onBlockReply: ReturnType<typeof vi.fn>): string | undefined { |
| 9 | +const firstCall = onBlockReply.mock.calls[0]; |
| 10 | +if (!firstCall) { |
| 11 | +throw new Error("expected onBlockReply to be called"); |
| 12 | +} |
| 13 | +return firstCall[0]?.text; |
| 14 | +} |
| 15 | + |
8 | 16 | describe("subscribeEmbeddedPiSession", () => { |
9 | 17 | it("calls onBlockReplyFlush before tool_execution_start to preserve message boundaries", () => { |
10 | 18 | const { session, emit } = createStubSessionHarness(); |
@@ -83,7 +91,7 @@ describe("subscribeEmbeddedPiSession", () => {
|
83 | 91 | await Promise.resolve(); |
84 | 92 | |
85 | 93 | expect(onBlockReply).toHaveBeenCalledTimes(1); |
86 | | -expect(onBlockReply.mock.calls.at(0)?.[0]?.text).toBe("Short chunk."); |
| 94 | +expect(firstBlockReplyText(onBlockReply)).toBe("Short chunk."); |
87 | 95 | expect(onBlockReplyFlush).toHaveBeenCalledTimes(1); |
88 | 96 | }); |
89 | 97 | |
@@ -157,7 +165,7 @@ describe("subscribeEmbeddedPiSession", () => {
|
157 | 165 | await Promise.resolve(); |
158 | 166 | |
159 | 167 | expect(onBlockReply).toHaveBeenCalledTimes(1); |
160 | | -expect(onBlockReply.mock.calls.at(0)?.[0]?.text).toBe("Final reply before lifecycle end."); |
| 168 | +expect(firstBlockReplyText(onBlockReply)).toBe("Final reply before lifecycle end."); |
161 | 169 | expect(onBlockReplyFlush).toHaveBeenCalledTimes(1); |
162 | 170 | }); |
163 | 171 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。