bash.test.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 projectRoot = path.join(__dirname, "../..")
  15. describe("tool.bash", () => {
  16. test("basic", async () => {
  17. await Instance.provide({
  18. directory: projectRoot,
  19. fn: async () => {
  20. const bash = await BashTool.init()
  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. // TODO: better test
  34. // test("cd ../ should ask for permission for external directory", async () => {
  35. // await Instance.provide({
  36. // directory: projectRoot,
  37. // fn: async () => {
  38. // bash.execute(
  39. // {
  40. // command: "cd ../",
  41. // description: "Try to cd to parent directory",
  42. // },
  43. // ctx,
  44. // )
  45. // // Give time for permission to be asked
  46. // await new Promise((resolve) => setTimeout(resolve, 1000))
  47. // expect(Permission.pending()[ctx.sessionID]).toBeDefined()
  48. // },
  49. // })
  50. // })
  51. })