2025-06-01 02:41:00 +08:00
|
|
|
import { describe, expect, test } from "bun:test"
|
|
|
|
|
import { App } from "../../src/app/app"
|
2025-06-01 05:12:16 +08:00
|
|
|
import { GlobTool } from "../../src/tool/glob"
|
2025-06-02 02:46:04 +08:00
|
|
|
import { ListTool } from "../../src/tool/ls"
|
2025-05-21 22:30:39 +08:00
|
|
|
|
2025-06-19 01:40:21 +08:00
|
|
|
const ctx = {
|
|
|
|
|
sessionID: "test",
|
|
|
|
|
messageID: "",
|
|
|
|
|
abort: AbortSignal.any([]),
|
|
|
|
|
metadata: () => {},
|
|
|
|
|
}
|
2025-07-26 01:29:29 +08:00
|
|
|
const glob = await GlobTool.init()
|
|
|
|
|
const list = await ListTool.init()
|
2025-07-25 09:20:43 +08:00
|
|
|
|
2025-05-21 22:30:39 +08:00
|
|
|
describe("tool.glob", () => {
|
|
|
|
|
test("truncate", async () => {
|
2025-06-17 22:27:49 +08:00
|
|
|
await App.provide({ cwd: process.cwd() }, async () => {
|
2025-07-25 09:20:43 +08:00
|
|
|
let result = await glob.execute(
|
2025-06-17 22:27:49 +08:00
|
|
|
{
|
2025-06-23 02:25:02 +08:00
|
|
|
pattern: "../../node_modules/**/*",
|
2025-06-17 23:27:07 +08:00
|
|
|
path: undefined,
|
2025-06-17 22:27:49 +08:00
|
|
|
},
|
2025-06-19 01:40:21 +08:00
|
|
|
ctx,
|
2025-06-03 23:59:03 +08:00
|
|
|
)
|
2025-06-01 02:41:00 +08:00
|
|
|
expect(result.metadata.truncated).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-05-21 22:30:39 +08:00
|
|
|
test("basic", async () => {
|
2025-06-17 22:27:49 +08:00
|
|
|
await App.provide({ cwd: process.cwd() }, async () => {
|
2025-07-25 09:20:43 +08:00
|
|
|
let result = await glob.execute(
|
2025-06-17 22:27:49 +08:00
|
|
|
{
|
|
|
|
|
pattern: "*.json",
|
2025-06-17 23:27:07 +08:00
|
|
|
path: undefined,
|
2025-06-17 22:27:49 +08:00
|
|
|
},
|
2025-06-19 01:40:21 +08:00
|
|
|
ctx,
|
2025-06-03 23:59:03 +08:00
|
|
|
)
|
2025-05-21 22:30:39 +08:00
|
|
|
expect(result.metadata).toMatchObject({
|
|
|
|
|
truncated: false,
|
2025-06-23 02:25:02 +08:00
|
|
|
count: 3,
|
2025-06-01 02:41:00 +08:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-05-27 02:09:17 +08:00
|
|
|
|
|
|
|
|
describe("tool.ls", () => {
|
|
|
|
|
test("basic", async () => {
|
2025-06-17 22:27:49 +08:00
|
|
|
const result = await App.provide({ cwd: process.cwd() }, async () => {
|
2025-07-25 09:20:43 +08:00
|
|
|
return await list.execute({ path: "./example", ignore: [".git"] }, ctx)
|
2025-06-17 22:27:49 +08:00
|
|
|
})
|
2025-06-01 02:41:00 +08:00
|
|
|
expect(result.output).toMatchSnapshot()
|
|
|
|
|
})
|
|
|
|
|
})
|