fix(webui): stop repairing completed Markdown

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-30 15:50:27 +08:00
1 parent fc3effe39d
commit 450a85fe0e
6 files changed
+48 -7

No files matched your search

@@ -516,6 +516,30 @@ describe("MarkdownTextRenderer", () => {
expect(container.querySelector("[data-nanobot-stream-unit]")).not.toBeInTheDocument();
});
it("stops repairing completed markdown without replacing the streaming layout", () => {
const source = "The old snip_history() / _legal_history_tail() path was removed.\n\nA real maintenance cost.";
const { container, rerender } = render(
<MarkdownTextRenderer streaming preserveStreamingLayout>{source}</MarkdownTextRenderer>,
);
const firstParagraph = container.querySelector("p");
expect(container.querySelector("p:last-child")?.textContent).toBe("A real maintenance cost._");
rerender(<MarkdownTextRenderer preserveStreamingLayout>{source}</MarkdownTextRenderer>);
expect(container.querySelector("p:last-child")?.textContent).toBe("A real maintenance cost.");
expect(container.querySelector("p")).toBe(firstParagraph);
});
it.each(["A literal trailing underscore_", "**unfinished emphasis", "_legal_history_tail()"])(
"preserves completed source syntax: %s",
(source) => {
const { container } = render(
<MarkdownTextRenderer preserveStreamingLayout>{source}</MarkdownTextRenderer>,
);
expect(container.textContent).toBe(source);
},
);
it("repairs incomplete streaming markdown without exposing syntax fragments", () => {
const { container, rerender } = render(
<MarkdownTextRenderer streaming>{"**partial answer"}</MarkdownTextRenderer>,
+10 -1
View File
@@ -13,10 +13,12 @@ vi.mock("@/components/MarkdownTextRenderer", () => ({
children,
highlightCode,
streaming,
preserveStreamingLayout,
}: {
children: string;
highlightCode?: boolean;
streaming?: boolean;
preserveStreamingLayout?: boolean;
}) {
useEffect(() => {
rendererMountSpy();
@@ -29,7 +31,8 @@ vi.mock("@/components/MarkdownTextRenderer", () => ({
<div
data-testid="markdown-renderer"
data-highlight-code={String(highlightCode)}
data-streaming-layout={String(streaming)}
data-streaming-layout={String(streaming || preserveStreamingLayout)}
data-streaming={String(streaming)}
>
{children}
</div>
@@ -108,6 +111,7 @@ describe("MarkdownText", () => {
});
it("can complete without replacing the streaming renderer layout", async () => {
rendererMountSpy.mockClear();
const source = "A layout-stable answer";
const { rerender } = render(
<MarkdownText streaming preserveStreamingLayout>{source}</MarkdownText>,
@@ -122,8 +126,13 @@ describe("MarkdownText", () => {
"true",
);
expect(screen.getByTestId("markdown-renderer")).toHaveAttribute("data-streaming", "true");
rerender(<MarkdownText preserveStreamingLayout>{source}</MarkdownText>);
expect(screen.getByTestId("markdown-renderer")).toHaveAttribute("data-streaming", "false");
expect(rendererMountSpy).toHaveBeenCalledTimes(1);
expect(screen.getByTestId("markdown-renderer")).toHaveAttribute(
"data-streaming-layout",
"true",