Files
openclaw/packages/markdown-core/src/render.annotations.test.ts
snowzlmbot e8ad0466ff fix: render assistant transcript headers safely (#99404)
* fix: render assistant transcript headers safely

Co-authored-by: snowzlmbot <293528334+snowzlmbot@users.noreply.github.com>

* fix(markdown): nest crossing annotation spans

* fix(markdown): protect final transport projections

* refactor(markdown): split transcript render ownership

* test(ui): cover assistant transcript render flag

* refactor(markdown): keep transcript helpers private

* docs(changelog): note assistant transcript headers

* chore(plugin-sdk): refresh transcript annotation baseline

* fix(markdown): harden final transcript projections

* docs(changelog): defer transcript note to release

* refactor(markdown): centralize HTML tokenization

* fix(markdown): satisfy lint gates

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: snowzlmbot <293528334+snowzlmbot@users.noreply.github.com>
2026-07-14 02:25:37 -07:00

94 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { markdownToIR, sliceMarkdownIR } from "./ir.js";
import { renderMarkdownWithMarkers } from "./render.js";
describe("renderMarkdownWithMarkers semantic annotations", () => {
it("renders transcript annotations while suppressing nested marker syntax", () => {
const ir = markdownToIR("**user[Thu 2026-07-02] continue**", {
assistantTranscriptRoleHeaders: true,
});
expect(
renderMarkdownWithMarkers(ir, {
annotationMarkers: {
assistant_transcript_role: {
open: "`",
close: "`",
suppressNestedFormatting: true,
},
},
styleMarkers: { bold: { open: "*", close: "*" } },
escapeText: (text) => text,
}),
).toBe("`user[Thu 2026-07-02]`* continue*");
});
it("keeps annotations when an IR slice starts inside the marked header", () => {
const ir = markdownToIR("user[Thu 2026-07-02] continue", {
assistantTranscriptRoleHeaders: true,
});
const sliced = sliceMarkdownIR(ir, 4, ir.text.length);
expect(sliced.annotations).toEqual([
expect.objectContaining({ start: 0, end: "[Thu 2026-07-02]".length }),
]);
});
it("closes and reopens formatting that crosses an annotation boundary", () => {
const ir = markdownToIR("user[**Thu] trailing**", {
assistantTranscriptRoleHeaders: true,
});
expect(
renderMarkdownWithMarkers(ir, {
annotationMarkers: {
assistant_transcript_role: { open: "`", close: "`" },
},
styleMarkers: { bold: { open: "*", close: "*" } },
escapeText: (text) => text,
}),
).toBe("`user[*Thu]*`* trailing*");
});
it("keeps structural containers outside dominant annotations", () => {
const ir = markdownToIR("> user[Thu 2026-07-02] continue", {
assistantTranscriptRoleHeaders: true,
});
expect(
renderMarkdownWithMarkers(ir, {
annotationMarkers: {
assistant_transcript_role: {
open: "<code>",
close: "</code>",
suppressNestedFormatting: true,
},
},
styleMarkers: { blockquote: { open: "<blockquote>", close: "</blockquote>" } },
escapeText: (text) => text,
}),
).toBe("<blockquote><code>user[Thu 2026-07-02]</code> continue</blockquote>");
});
it("renders many independently styled annotations without cross-product scans", () => {
const markdown = Array.from(
{ length: 256 },
(_, index) => `**user[t${index}]** line ${index}`,
).join("\n");
const ir = markdownToIR(markdown, { assistantTranscriptRoleHeaders: true });
const rendered = renderMarkdownWithMarkers(ir, {
annotationMarkers: {
assistant_transcript_role: {
open: "`",
close: "`",
suppressNestedFormatting: true,
},
},
styleMarkers: { bold: { open: "*", close: "*" } },
escapeText: (text) => text,
});
expect(rendered.match(/`user\[t\d+\]`/gu)).toHaveLength(256);
});
});