import { describe, expect, it, vi } from "vitest"; import { createStubSessionHarness, emitAssistantTextDelta, } from "./pi-embedded-subscribe.e2e-harness.js"; import { subscribeEmbeddedPiSession } from "./pi-embedded-subscribe.js"; describe("subscribeEmbeddedPiSession thinking tag code span awareness", () => { function createPartialReplyHarness() { const { session, emit } = createStubSessionHarness(); const onPartialReply = vi.fn(); subscribeEmbeddedPiSession({ session, runId: "run", onPartialReply, }); return { emit, onPartialReply }; } it("does not strip thinking tags inside inline code backticks", () => { const { emit, onPartialReply } = createPartialReplyHarness(); emitAssistantTextDelta({ emit, delta: "The fix strips leaked `` tags from messages.", }); expect(onPartialReply).toHaveBeenCalled(); const lastCall = onPartialReply.mock.calls[onPartialReply.mock.calls.length - 1]; expect(lastCall[0].text).toContain("``"); }); it("does not strip thinking tags inside fenced code blocks", () => { const { emit, onPartialReply } = createPartialReplyHarness(); emitAssistantTextDelta({ emit, delta: "Example:\n ````\ncode example\n ````\nDone.", }); expect(onPartialReply).toHaveBeenCalled(); const lastCall = onPartialReply.mock.calls[onPartialReply.mock.calls.length - 1]; expect(lastCall[0].text).toContain("code example"); }); it("still strips actual thinking tags outside code spans", () => { const { emit, onPartialReply } = createPartialReplyHarness(); emitAssistantTextDelta({ emit, delta: "Hello internal thought world", }); expect(onPartialReply).toHaveBeenCalled(); const lastCall = onPartialReply.mock.calls[onPartialReply.mock.calls.length - 1]; expect(lastCall[0].text).not.toContain("internal thought"); expect(lastCall[0].text).toContain("Hello"); expect(lastCall[0].text).toContain("world"); }); });