bash.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { describe, expect, test } from "bun:test"
  2. import path from "path"
  3. import { BashTool } from "../../src/tool/bash"
  4. import { Instance } from "../../src/project/instance"
  5. import { Permission } from "../../src/permission"
  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. describe("tool.bash", () => {
  17. test("basic", async () => {
  18. await Instance.provide({
  19. directory: projectRoot,
  20. fn: async () => {
  21. const result = await bash.execute(
  22. {
  23. command: "echo 'test'",
  24. description: "Echo test message",
  25. },
  26. ctx,
  27. )
  28. expect(result.metadata.exit).toBe(0)
  29. expect(result.metadata.output).toContain("test")
  30. },
  31. })
  32. })
  33. test("cd ../ should ask for permission for external directory", async () => {
  34. await Instance.provide({
  35. directory: projectRoot,
  36. fn: async () => {
  37. bash.execute(
  38. {
  39. command: "cd ../",
  40. description: "Try to cd to parent directory",
  41. },
  42. ctx,
  43. )
  44. // Give time for permission to be asked
  45. await new Promise((resolve) => setTimeout(resolve, 1000))
  46. expect(Permission.pending()[ctx.sessionID]).toBeDefined()
  47. },
  48. })
  49. })
  50. })