Files
archie/ui/test/chat-markdown.test.ts
T
samandCopilot 7673e3a135 feat(ui/chat): render Markdown with remark and rehype; remove the React reference
Chat replies, approvals, plans and agent transcripts now parse GitHub
flavoured Markdown with unified (remark-parse, remark-gfm, remark-rehype)
and render the HTML tree as Vue nodes. Raw HTML is dropped, links and
images keep only safe URLs, and #N task references stay linked.

The Astryx React prototype, its dependencies, scripts, theme file and
agent notes are removed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-19 23:35:31 +11:00

37 lines
1.4 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import type { Element, Root } from "hast";
import { parseMarkdown } from "../src/chat/markdown.ts";
function elements(tree: Root | Element, tag: string): Element[] {
const found: Element[] = [];
for (const child of tree.children) {
if (child.type !== "element") continue;
if (child.tagName === tag) found.push(child);
found.push(...elements(child, tag));
}
return found;
}
// Guards the chat renderer against script URLs and against #N task links
// appearing inside code or existing links.
test("parseMarkdown keeps only safe URLs and links task references in prose", () => {
const cases = [
{ md: "[x](javascript:alert(1))", tag: "a", count: 0 },
{ md: "[x](https://example.com)", tag: "a", count: 1 },
{ md: "[x](//evil.example)", tag: "a", count: 0 },
{ md: "![x](javascript:alert(1))", tag: "img", count: 0 },
{ md: "![x](data:image/png;base64,AA==)", tag: "img", count: 1 },
{ md: "<script>alert(1)</script>", tag: "script", count: 0 },
{ md: "See #12 and #13.", tag: "task-ref", count: 2 },
{ md: "`#12` and [#13](https://example.com)", tag: "task-ref", count: 0 },
{ md: "```\n#12\n```", tag: "task-ref", count: 0 },
{ md: "issue#12 and a/#12", tag: "task-ref", count: 0 },
];
for (const { md, tag, count } of cases) {
assert.equal(elements(parseMarkdown(md), tag).length, count, md);
}
});