





















@@ -9,6 +9,21 @@ import {
99} from "./pi-embedded-subscribe.e2e-harness.js";
1010import { subscribeEmbeddedPiSession } from "./pi-embedded-subscribe.js";
111112+type ReplyMock = ReturnType<typeof vi.fn>;
13+type ReplyPayload = { text?: string };
14+15+function requireFirstReplyPayload(mock: ReplyMock): ReplyPayload {
16+const call = mock.mock.calls[0];
17+if (!call) {
18+throw new Error("expected first reply call");
19+}
20+const payload = call[0];
21+if (!payload || typeof payload !== "object") {
22+throw new Error("expected first reply payload");
23+}
24+return payload as ReplyPayload;
25+}
26+1227describe("subscribeEmbeddedPiSession", () => {
1328it("filters to <final> and suppresses output without a start tag", () => {
1429const { session, emit } = createStubSessionHarness();
@@ -28,7 +43,7 @@ describe("subscribeEmbeddedPiSession", () => {
2843emitAssistantTextDelta({ emit, delta: "<final>Hi there</final>" });
29443045expect(onPartialReply).toHaveBeenCalledTimes(1);
31-const firstPayload = onPartialReply.mock.calls.at(0)?.[0];
46+const firstPayload = requireFirstReplyPayload(onPartialReply);
3247expect(firstPayload?.text).toBe("Hi there");
33483449onPartialReply.mockClear();
@@ -77,7 +92,7 @@ describe("subscribeEmbeddedPiSession", () => {
7792emitAssistantTextDelta({ emit, delta: "<final>Hello world</final>" });
78937994expect(onPartialReply).toHaveBeenCalledTimes(1);
80-expect(onPartialReply.mock.calls.at(0)?.[0]?.text).toBe("Hello world");
95+expect(requireFirstReplyPayload(onPartialReply).text).toBe("Hello world");
8196});
82978398it("strips final tags split across streamed deltas without emitting tag remnants", () => {
@@ -183,7 +198,7 @@ describe("subscribeEmbeddedPiSession", () => {
183198await Promise.resolve();
184199185200expect(onBlockReply).toHaveBeenCalledTimes(1);
186-expect(onBlockReply.mock.calls.at(0)?.[0]?.text).toBe("Answer ends with <fi");
201+expect(requireFirstReplyPayload(onBlockReply).text).toBe("Answer ends with <fi");
187202});
188203189204it("keeps a trailing final-tag prefix when synchronous message_end drains chunked text_end replies", async () => {
@@ -246,7 +261,7 @@ describe("subscribeEmbeddedPiSession", () => {
246261247262emitAssistantTextDelta({ emit, delta: "Hello world" });
248263249-const payload = onPartialReply.mock.calls.at(0)?.[0];
264+const payload = requireFirstReplyPayload(onPartialReply);
250265expect(payload?.text).toBe("Hello world");
251266});
252267it("emits block replies on message_end", async () => {
@@ -270,7 +285,7 @@ describe("subscribeEmbeddedPiSession", () => {
270285await Promise.resolve();
271286272287expect(onBlockReply).toHaveBeenCalledTimes(1);
273-const payload = onBlockReply.mock.calls.at(0)?.[0];
288+const payload = requireFirstReplyPayload(onBlockReply);
274289expect(payload?.text).toBe("Hello block");
275290});
276291});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。