|
1 | 1 | import { describe, expect, it } from "vitest"; |
| 2 | +import { stripToolCallXmlTags } from "../../../src/shared/text/assistant-visible-text.js"; |
2 | 3 | import { scanXmlishToolCall } from "./grammar.js"; |
3 | 4 | import { scanPlainTextJsonToolCall, stripPlainTextToolCallBlocks } from "./payload.js"; |
4 | 5 |
|
@@ -257,19 +258,73 @@ describe("stripPlainTextToolCallBlocks: degraded invoke dialect (#97750)", () => |
257 | 258 | .split("\n") |
258 | 259 | .map((line) => pad + line) |
259 | 260 | .join("\n"); |
| 261 | + const expectPreservedByScrubbers = (raw: string) => { |
| 262 | + expect(stripPlainTextToolCallBlocks(raw)).toBe(raw); |
| 263 | + expect(stripToolCallXmlTags(raw, { stripFunctionCallsXmlPayloads: true })).toBe(raw); |
| 264 | + }; |
| 265 | + const expectScrubbedByScrubbers = (raw: string, expectedPlain: string, expectedXml: string) => { |
| 266 | + expect(stripPlainTextToolCallBlocks(raw)).toBe(expectedPlain); |
| 267 | + expect(stripToolCallXmlTags(raw, { stripFunctionCallsXmlPayloads: true })).toBe(expectedXml); |
| 268 | + }; |
260 | 269 |
|
261 | 270 | it("preserves an indented namespaced invoke example after a blank line (#97750)", () => { |
262 | 271 | // A 4-space indented block after a blank line is a CommonMark indented code |
263 | 272 | // block, so the qualified invoke example inside it is documentation, not a leak. |
264 | 273 | const raw = `Here you go.\n\n${indentLines(block("antml:"), " ")}`; |
265 | | - expect(stripPlainTextToolCallBlocks(raw)).toBe(raw); |
| 274 | + expectPreservedByScrubbers(raw); |
| 275 | + }); |
| 276 | + |
| 277 | + it("preserves a namespaced invoke example in indented code under a nested list (#97750)", () => { |
| 278 | + const raw = [ |
| 279 | + "- outer", |
| 280 | + " - middle", |
| 281 | + " - inner", |
| 282 | + "", |
| 283 | + indentLines(block("antml:"), " "), |
| 284 | + ].join("\n"); |
| 285 | + expectPreservedByScrubbers(raw); |
| 286 | + }); |
| 287 | + |
| 288 | + it("preserves a function_calls invoke example in indented code under a blockquote list (#97750)", () => { |
| 289 | + const raw = [ |
| 290 | + "> - quoted item", |
| 291 | + ">", |
| 292 | + ...indentLines( |
| 293 | + `${LT}function_calls>\n${block("mm:")}\n${LT}/function_calls>`, |
| 294 | + "> ", |
| 295 | + ).split("\n"), |
| 296 | + ].join("\n"); |
| 297 | + expectPreservedByScrubbers(raw); |
| 298 | + }); |
| 299 | + |
| 300 | + it("preserves a namespaced invoke example in single-level list indented code (#97750)", () => { |
| 301 | + const raw = ["- item", "", indentLines(block("antml:"), " ")].join("\n"); |
| 302 | + expectPreservedByScrubbers(raw); |
| 303 | + }); |
| 304 | + |
| 305 | + it("preserves blockquote-prefixed indented code examples (#97750)", () => { |
| 306 | + // The plain-text scrubber requires `<` at line start: skipLineIndentation in |
| 307 | + // grammar.ts skips only spaces/tabs, not `>`. If a future scrubber starts |
| 308 | + // consuming `>`, re-check blockquote code detection before changing this. |
| 309 | + const raw = indentLines(block("antml:"), "> "); |
| 310 | + expectPreservedByScrubbers(raw); |
266 | 311 | }); |
267 | 312 |
|
268 | 313 | it("scrubs an indented namespaced invoke on a paragraph-continuation line (#97750)", () => { |
269 | 314 | // A 4-space indented invoke directly under prose is a lazy paragraph |
270 | 315 | // continuation, not indented code, so a genuine leak there is still removed. |
271 | 316 | const raw = `Some prose paragraph.\n${indentLines(block("antml:"), " ")}`; |
272 | | - expect(stripPlainTextToolCallBlocks(raw)).toBe("Some prose paragraph.\n"); |
| 317 | + expectScrubbedByScrubbers(raw, "Some prose paragraph.\n", "Some prose paragraph.\n "); |
| 318 | + }); |
| 319 | + |
| 320 | + it("scrubs a tight-list namespaced invoke continuation (#97750)", () => { |
| 321 | + const raw = ["- item", indentLines(block("antml:"), " ")].join("\n"); |
| 322 | + expectScrubbedByScrubbers(raw, "- item\n", "- item\n "); |
| 323 | + }); |
| 324 | + |
| 325 | + it("scrubs a loose-list non-code namespaced invoke continuation (#97750)", () => { |
| 326 | + const raw = ["- item", "", indentLines(block("mm:"), " ")].join("\n"); |
| 327 | + expectScrubbedByScrubbers(raw, "- item\n\n", "- item\n\n "); |
273 | 328 | }); |
274 | 329 |
|
275 | 330 | it("scrubs a fenced namespaced invoke when the predicate never preserves (strict)", () => { |
|
0 commit comments