mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-24 11:39:33 +00:00
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
// Code-span awareness tests ensure streamed thinking-tag stripping ignores
|
|
// literal examples inside inline and fenced code.
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import {
|
|
createStubSessionHarness,
|
|
emitAssistantTextDelta,
|
|
} from "./embedded-agent-subscribe.e2e-harness.js";
|
|
import { subscribeEmbeddedAgentSession } from "./embedded-agent-subscribe.js";
|
|
|
|
describe("subscribeEmbeddedAgentSession thinking tag code span awareness", () => {
|
|
function createPartialReplyHarness() {
|
|
// Partial replies are the earliest user-visible stream path, so this
|
|
// harness isolates tag stripping before terminal message handling.
|
|
const { session, emit } = createStubSessionHarness();
|
|
const onPartialReply = vi.fn();
|
|
|
|
subscribeEmbeddedAgentSession({
|
|
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 `<thinking>` tags from messages.",
|
|
});
|
|
|
|
expect(onPartialReply).toHaveBeenCalledTimes(1);
|
|
expect(onPartialReply).toHaveBeenCalledWith({
|
|
text: "The fix strips leaked `<thinking>` tags from messages.",
|
|
delta: "The fix strips leaked `<thinking>` tags from messages.",
|
|
replace: undefined,
|
|
mediaUrls: undefined,
|
|
phase: undefined,
|
|
});
|
|
});
|
|
|
|
it("does not strip thinking tags inside fenced code blocks", () => {
|
|
const { emit, onPartialReply } = createPartialReplyHarness();
|
|
|
|
emitAssistantTextDelta({
|
|
emit,
|
|
delta: "Example:\n ````\n<thinking>code example</thinking>\n ````\nDone.",
|
|
});
|
|
|
|
expect(onPartialReply).toHaveBeenCalledTimes(1);
|
|
expect(onPartialReply).toHaveBeenCalledWith({
|
|
text: "Example:\n ````\n<thinking>code example</thinking>\n ````\nDone.",
|
|
delta: "Example:\n ````\n<thinking>code example</thinking>\n ````\nDone.",
|
|
replace: undefined,
|
|
mediaUrls: undefined,
|
|
phase: undefined,
|
|
});
|
|
});
|
|
|
|
it("still strips actual thinking tags outside code spans", () => {
|
|
const { emit, onPartialReply } = createPartialReplyHarness();
|
|
|
|
emitAssistantTextDelta({
|
|
emit,
|
|
delta: "Hello <thinking>internal thought</thinking> world",
|
|
});
|
|
|
|
expect(onPartialReply).toHaveBeenCalledTimes(1);
|
|
expect(onPartialReply).toHaveBeenCalledWith({
|
|
text: "Hello world",
|
|
delta: "Hello world",
|
|
replace: undefined,
|
|
mediaUrls: undefined,
|
|
phase: undefined,
|
|
});
|
|
});
|
|
});
|