bash.test.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { describe, expect, test } from "bun:test"
  2. import { App } from "../../src/app/app"
  3. import path from "path"
  4. import { BashTool } from "../../src/tool/bash"
  5. import { Log } from "../../src/util/log"
  6. const ctx = {
  7. sessionID: "test",
  8. messageID: "",
  9. abort: AbortSignal.any([]),
  10. metadata: () => {},
  11. }
  12. const bash = await BashTool.init()
  13. const projectRoot = path.join(__dirname, "../..")
  14. Log.init({ print: false })
  15. describe("tool.bash", () => {
  16. test("basic", async () => {
  17. await App.provide({ cwd: projectRoot }, async () => {
  18. await bash.execute(
  19. {
  20. command: "cd foo/bar && ls",
  21. description: "List files in foo/bar",
  22. },
  23. ctx,
  24. )
  25. })
  26. })
  27. test("cd ../ should fail", async () => {
  28. await App.provide({ cwd: projectRoot }, async () => {
  29. expect(
  30. bash.execute(
  31. {
  32. command: "cd ../",
  33. description: "Try to cd to parent directory",
  34. },
  35. ctx,
  36. ),
  37. ).rejects.toThrow()
  38. })
  39. })
  40. })