system.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { describe, expect, test } from "bun:test"
  2. import path from "path"
  3. import { Agent } from "../../src/agent/agent"
  4. import { Instance } from "../../src/project/instance"
  5. import { SystemPrompt } from "../../src/session/system"
  6. import { tmpdir } from "../fixture/fixture"
  7. describe("session.system", () => {
  8. test("skills output is sorted by name and stable across calls", async () => {
  9. await using tmp = await tmpdir({
  10. git: true,
  11. init: async (dir) => {
  12. for (const [name, description] of [
  13. ["zeta-skill", "Zeta skill."],
  14. ["alpha-skill", "Alpha skill."],
  15. ["middle-skill", "Middle skill."],
  16. ]) {
  17. const skillDir = path.join(dir, ".opencode", "skill", name)
  18. await Bun.write(
  19. path.join(skillDir, "SKILL.md"),
  20. `---
  21. name: ${name}
  22. description: ${description}
  23. ---
  24. # ${name}
  25. `,
  26. )
  27. }
  28. },
  29. })
  30. const home = process.env.KILO_TEST_HOME
  31. process.env.KILO_TEST_HOME = tmp.path
  32. try {
  33. await Instance.provide({
  34. directory: tmp.path,
  35. fn: async () => {
  36. const build = await Agent.get("build")
  37. const first = await SystemPrompt.skills(build!)
  38. const second = await SystemPrompt.skills(build!)
  39. expect(first).toBe(second)
  40. const alpha = first!.indexOf("<name>alpha-skill</name>")
  41. const middle = first!.indexOf("<name>middle-skill</name>")
  42. const zeta = first!.indexOf("<name>zeta-skill</name>")
  43. expect(alpha).toBeGreaterThan(-1)
  44. expect(middle).toBeGreaterThan(alpha)
  45. expect(zeta).toBeGreaterThan(middle)
  46. },
  47. })
  48. } finally {
  49. process.env.KILO_TEST_HOME = home
  50. }
  51. })
  52. })