system-prompt.test.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { describe, expect, it } from "vitest";
  2. import { formatSkillsForSystemPrompt } from "../../src/harness/system-prompt.ts";
  3. const visibleSkill = {
  4. name: "visible",
  5. description: "Use <this> & that",
  6. content: "visible content",
  7. filePath: "/skills/visible/SKILL.md",
  8. };
  9. const secondSkill = {
  10. name: "second",
  11. description: "Second skill",
  12. content: "second content",
  13. filePath: "/skills/second/SKILL.md",
  14. };
  15. const disabledSkill = {
  16. name: "hidden",
  17. description: "Hidden",
  18. content: "hidden content",
  19. filePath: "/skills/hidden/SKILL.md",
  20. disableModelInvocation: true,
  21. };
  22. describe("formatSkillsForSystemPrompt", () => {
  23. it("formats visible skills in order and skips model-disabled skills", () => {
  24. expect(formatSkillsForSystemPrompt([visibleSkill, disabledSkill, secondSkill])).toBe(
  25. `The following skills provide specialized instructions for specific tasks.
  26. Read the full skill file when the task matches its description.
  27. When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.
  28. <available_skills>
  29. <skill>
  30. <name>visible</name>
  31. <description>Use &lt;this&gt; &amp; that</description>
  32. <location>/skills/visible/SKILL.md</location>
  33. </skill>
  34. <skill>
  35. <name>second</name>
  36. <description>Second skill</description>
  37. <location>/skills/second/SKILL.md</location>
  38. </skill>
  39. </available_skills>`,
  40. );
  41. });
  42. it("returns an empty string when no skills are model-visible", () => {
  43. expect(formatSkillsForSystemPrompt([disabledSkill])).toBe("");
  44. });
  45. it("escapes XML in all model-visible skill fields", () => {
  46. expect(
  47. formatSkillsForSystemPrompt([
  48. {
  49. name: "a&b",
  50. description: `Quote "double" and 'single'`,
  51. content: "content",
  52. filePath: '/skills/<bad>&"quote"/SKILL.md',
  53. },
  54. ]),
  55. ).toContain(
  56. "<name>a&amp;b</name>\n <description>Quote &quot;double&quot; and &apos;single&apos;</description>\n <location>/skills/&lt;bad&gt;&amp;&quot;quote&quot;/SKILL.md</location>",
  57. );
  58. });
  59. });