instruction.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { describe, expect, test } from "bun:test"
  2. import path from "path"
  3. import { InstructionPrompt } from "../../src/session/instruction"
  4. import { Instance } from "../../src/project/instance"
  5. import { tmpdir } from "../fixture/fixture"
  6. describe("InstructionPrompt.resolve", () => {
  7. test("returns empty when AGENTS.md is at project root (already in systemPaths)", async () => {
  8. await using tmp = await tmpdir({
  9. init: async (dir) => {
  10. await Bun.write(path.join(dir, "AGENTS.md"), "# Root Instructions")
  11. await Bun.write(path.join(dir, "src", "file.ts"), "const x = 1")
  12. },
  13. })
  14. await Instance.provide({
  15. directory: tmp.path,
  16. fn: async () => {
  17. const system = await InstructionPrompt.systemPaths()
  18. expect(system.has(path.join(tmp.path, "AGENTS.md"))).toBe(true)
  19. const results = await InstructionPrompt.resolve([], path.join(tmp.path, "src", "file.ts"), "test-message-1")
  20. expect(results).toEqual([])
  21. },
  22. })
  23. })
  24. test("returns AGENTS.md from subdirectory (not in systemPaths)", async () => {
  25. await using tmp = await tmpdir({
  26. init: async (dir) => {
  27. await Bun.write(path.join(dir, "subdir", "AGENTS.md"), "# Subdir Instructions")
  28. await Bun.write(path.join(dir, "subdir", "nested", "file.ts"), "const x = 1")
  29. },
  30. })
  31. await Instance.provide({
  32. directory: tmp.path,
  33. fn: async () => {
  34. const system = await InstructionPrompt.systemPaths()
  35. expect(system.has(path.join(tmp.path, "subdir", "AGENTS.md"))).toBe(false)
  36. const results = await InstructionPrompt.resolve(
  37. [],
  38. path.join(tmp.path, "subdir", "nested", "file.ts"),
  39. "test-message-2",
  40. )
  41. expect(results.length).toBe(1)
  42. expect(results[0].filepath).toBe(path.join(tmp.path, "subdir", "AGENTS.md"))
  43. },
  44. })
  45. })
  46. })