tool.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { describe, expect, test } from "bun:test"
  2. import { App } from "../../src/app/app"
  3. import { GlobTool } from "../../src/tool/glob"
  4. import { ListTool } from "../../src/tool/ls"
  5. const ctx = {
  6. sessionID: "test",
  7. messageID: "",
  8. abort: AbortSignal.any([]),
  9. metadata: () => {},
  10. }
  11. describe("tool.glob", () => {
  12. test("truncate", async () => {
  13. await App.provide({ cwd: process.cwd() }, async () => {
  14. let result = await GlobTool.execute(
  15. {
  16. pattern: "../../node_modules/**/*",
  17. path: undefined,
  18. },
  19. ctx,
  20. )
  21. expect(result.metadata.truncated).toBe(true)
  22. })
  23. })
  24. test("basic", async () => {
  25. await App.provide({ cwd: process.cwd() }, async () => {
  26. let result = await GlobTool.execute(
  27. {
  28. pattern: "*.json",
  29. path: undefined,
  30. },
  31. ctx,
  32. )
  33. expect(result.metadata).toMatchObject({
  34. truncated: false,
  35. count: 3,
  36. })
  37. })
  38. })
  39. })
  40. describe("tool.ls", () => {
  41. test("basic", async () => {
  42. const result = await App.provide({ cwd: process.cwd() }, async () => {
  43. return await ListTool.execute(
  44. { path: "./example", ignore: [".git"] },
  45. ctx,
  46. )
  47. })
  48. expect(result.output).toMatchSnapshot()
  49. })
  50. })