export-html-skill-block.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { readFileSync } from "fs";
  2. import { describe, expect, it } from "vitest";
  3. describe("export HTML skill block rendering", () => {
  4. const templateJs = readFileSync(new URL("../src/core/export-html/template.js", import.meta.url), "utf-8");
  5. it("strips skill wrapper XML from user message rendering", () => {
  6. // Skill commands store a structural wrapper in the raw user message:
  7. // <skill name="..." location="...">\n...\n</skill>\n\nactual prompt
  8. // The export renderer must detect that wrapper and render only the user-visible prompt,
  9. // not the Pi-generated <skill>...</skill> XML tags.
  10. expect(templateJs).toMatch(/parseSkillBlock/);
  11. expect(templateJs).toMatch(/skillBlock\.userMessage/);
  12. });
  13. it("renders skill invocation and user message as separate sibling blocks", () => {
  14. // The skill block and user message should render as separate entry-level elements,
  15. // matching the TUI layout where SkillInvocationMessageComponent and
  16. // UserMessageComponent are siblings, not nested.
  17. expect(templateJs).toMatch(/skill-invocation/);
  18. // When a skill block has a userMessage, the user-message div must be emitted
  19. // as a separate block after the skill-invocation div, containing the user-authored text.
  20. // Verify the code checks hasUserContent so the user-message div is only omitted
  21. // when the skill block has no user prompt and no images.
  22. expect(templateJs).toMatch(/hasUserContent/);
  23. });
  24. it("renders skill content as markdown, not raw text", () => {
  25. // The skill block body is markdown (from the SKILL.md file).
  26. // It should be rendered through safeMarkedParse, not escaped as raw text.
  27. expect(templateJs).toMatch(/safeMarkedParse\(skillBlock\.content\)/);
  28. });
  29. it("shows skill name and user message in the sidebar tree", () => {
  30. // The sidebar tree should display both the skill name and the user prompt,
  31. // not just one or the other.
  32. expect(templateJs).toMatch(/tree-role-skill/);
  33. });
  34. });