tool.test.ts 1.3 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. const glob = await GlobTool.init()
  12. const list = await ListTool.init()
  13. describe("tool.glob", () => {
  14. test("truncate", async () => {
  15. await App.provide({ cwd: process.cwd() }, async () => {
  16. let result = await glob.execute(
  17. {
  18. pattern: "../../node_modules/**/*",
  19. path: undefined,
  20. },
  21. ctx,
  22. )
  23. expect(result.metadata.truncated).toBe(true)
  24. })
  25. })
  26. test("basic", async () => {
  27. await App.provide({ cwd: process.cwd() }, async () => {
  28. let result = await glob.execute(
  29. {
  30. pattern: "*.json",
  31. path: undefined,
  32. },
  33. ctx,
  34. )
  35. expect(result.metadata).toMatchObject({
  36. truncated: false,
  37. count: 3,
  38. })
  39. })
  40. })
  41. })
  42. describe("tool.ls", () => {
  43. test("basic", async () => {
  44. const result = await App.provide({ cwd: process.cwd() }, async () => {
  45. return await list.execute({ path: "./example", ignore: [".git"] }, ctx)
  46. })
  47. expect(result.output).toMatchSnapshot()
  48. })
  49. })