pi-mono/packages/coding-agent/test/export-html-skill-block.test.ts
Aliou Diallo 88619669e2
Some checks are pending
CI / build-check-test (push) Waiting to run
fix(coding-agent): strip skill wrapper XML from HTML export user messages (#4234)
Skill slash commands store a structural <skill>...</skill> wrapper in raw
user messages. The TUI uses parseSkillBlock() to split this into separate
SkillInvocationMessageComponent and UserMessageComponent siblings, but the
HTML export renderer passed the full raw text through markdown, causing
broken/dangling XML tags to appear in exported HTML.

Add parseSkillBlock() to the export template and render skill-invocation
and user-message as separate sibling blocks:
- Sidebar tree shows skill name + user prompt separately
- Content area shows a clickable skill-invocation block (collapsed by
  default, markdown content on expand) followed by the user message
- Copy-link button preserved on the wrapper element
- Toggle tools (O key) expands/collapses skill invocations alongside
  compaction and tool output blocks
2026-05-06 18:06:37 +02:00

40 lines
1.9 KiB
TypeScript

import { readFileSync } from "fs";
import { describe, expect, it } from "vitest";
describe("export HTML skill block rendering", () => {
const templateJs = readFileSync(new URL("../src/core/export-html/template.js", import.meta.url), "utf-8");
it("strips skill wrapper XML from user message rendering", () => {
// Skill commands store a structural wrapper in the raw user message:
// <skill name="..." location="...">\n...\n</skill>\n\nactual prompt
// The export renderer must detect that wrapper and render only the user-visible prompt,
// not the Pi-generated <skill>...</skill> XML tags.
expect(templateJs).toMatch(/parseSkillBlock/);
expect(templateJs).toMatch(/skillBlock\.userMessage/);
});
it("renders skill invocation and user message as separate sibling blocks", () => {
// The skill block and user message should render as separate entry-level elements,
// matching the TUI layout where SkillInvocationMessageComponent and
// UserMessageComponent are siblings, not nested.
expect(templateJs).toMatch(/skill-invocation/);
// When a skill block has a userMessage, the user-message div must be emitted
// as a separate block after the skill-invocation div, containing the user-authored text.
// Verify the code checks hasUserContent so the user-message div is only omitted
// when the skill block has no user prompt and no images.
expect(templateJs).toMatch(/hasUserContent/);
});
it("renders skill content as markdown, not raw text", () => {
// The skill block body is markdown (from the SKILL.md file).
// It should be rendered through safeMarkedParse, not escaped as raw text.
expect(templateJs).toMatch(/safeMarkedParse\(skillBlock\.content\)/);
});
it("shows skill name and user message in the sidebar tree", () => {
// The sidebar tree should display both the skill name and the user prompt,
// not just one or the other.
expect(templateJs).toMatch(/tree-role-skill/);
});
});