bash.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { describe, expect, test } from "bun:test"
  2. import path from "path"
  3. import { BashTool } from "../../src/tool/bash"
  4. import { Log } from "../../src/util/log"
  5. import { Instance } from "../../src/project/instance"
  6. const ctx = {
  7. sessionID: "test",
  8. messageID: "",
  9. toolCallID: "",
  10. agent: "build",
  11. abort: AbortSignal.any([]),
  12. metadata: () => {},
  13. }
  14. const bash = await BashTool.init()
  15. const projectRoot = path.join(__dirname, "../..")
  16. Log.init({ print: false })
  17. describe("tool.bash", () => {
  18. test("basic", async () => {
  19. await Instance.provide({
  20. directory: projectRoot,
  21. fn: async () => {
  22. const result = await bash.execute(
  23. {
  24. command: "echo 'test'",
  25. description: "Echo test message",
  26. },
  27. ctx,
  28. )
  29. expect(result.metadata.exit).toBe(0)
  30. expect(result.metadata.output).toContain("test")
  31. },
  32. })
  33. })
  34. test("cd ../ should fail outside of project root", async () => {
  35. await Instance.provide({
  36. directory: projectRoot,
  37. fn: async () => {
  38. expect(
  39. bash.execute(
  40. {
  41. command: "cd ../",
  42. description: "Try to cd to parent directory",
  43. },
  44. ctx,
  45. ),
  46. ).rejects.toThrow("This command references paths outside of")
  47. },
  48. })
  49. })
  50. })