2025-05-31 18:41:00 +00:00
|
|
|
import { describe, expect, test } from "bun:test"
|
|
|
|
|
import { App } from "../../src/app/app"
|
2025-05-31 21:12:16 +00:00
|
|
|
import { GlobTool } from "../../src/tool/glob"
|
2025-06-01 18:46:04 +00:00
|
|
|
import { ListTool } from "../../src/tool/ls"
|
2025-07-29 22:54:22 +00:00
|
|
|
import path from "path"
|
2025-05-21 14:30:39 +00:00
|
|
|
|
2025-06-18 17:40:21 +00:00
|
|
|
const ctx = {
|
|
|
|
|
sessionID: "test",
|
|
|
|
|
messageID: "",
|
2025-07-31 15:10:34 +00:00
|
|
|
toolCallID: "",
|
2025-08-12 15:39:39 +00:00
|
|
|
agent: "build",
|
2025-06-18 17:40:21 +00:00
|
|
|
abort: AbortSignal.any([]),
|
|
|
|
|
metadata: () => {},
|
|
|
|
|
}
|
2025-07-25 17:29:29 +00:00
|
|
|
const glob = await GlobTool.init()
|
|
|
|
|
const list = await ListTool.init()
|
2025-07-25 01:20:43 +00:00
|
|
|
|
2025-07-29 22:54:22 +00:00
|
|
|
const projectRoot = path.join(__dirname, "../..")
|
|
|
|
|
const fixturePath = path.join(__dirname, "../fixtures/example")
|
|
|
|
|
|
2025-05-21 14:30:39 +00:00
|
|
|
describe("tool.glob", () => {
|
|
|
|
|
test("truncate", async () => {
|
2025-07-29 22:54:22 +00:00
|
|
|
await App.provide({ cwd: projectRoot }, async () => {
|
2025-07-25 01:20:43 +00:00
|
|
|
let result = await glob.execute(
|
2025-06-17 14:27:49 +00:00
|
|
|
{
|
2025-07-30 20:42:13 +00:00
|
|
|
pattern: "**/*",
|
|
|
|
|
path: "../../node_modules",
|
2025-06-17 14:27:49 +00:00
|
|
|
},
|
2025-06-18 17:40:21 +00:00
|
|
|
ctx,
|
2025-06-03 15:59:03 +00:00
|
|
|
)
|
2025-05-31 18:41:00 +00:00
|
|
|
expect(result.metadata.truncated).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-05-21 14:30:39 +00:00
|
|
|
test("basic", async () => {
|
2025-07-29 22:54:22 +00:00
|
|
|
await App.provide({ cwd: projectRoot }, async () => {
|
2025-07-25 01:20:43 +00:00
|
|
|
let result = await glob.execute(
|
2025-06-17 14:27:49 +00:00
|
|
|
{
|
|
|
|
|
pattern: "*.json",
|
2025-06-17 15:27:07 +00:00
|
|
|
path: undefined,
|
2025-06-17 14:27:49 +00:00
|
|
|
},
|
2025-06-18 17:40:21 +00:00
|
|
|
ctx,
|
2025-06-03 15:59:03 +00:00
|
|
|
)
|
2025-05-21 14:30:39 +00:00
|
|
|
expect(result.metadata).toMatchObject({
|
|
|
|
|
truncated: false,
|
2025-07-30 20:13:37 +00:00
|
|
|
count: 2,
|
2025-05-31 18:41:00 +00:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-05-26 18:09:17 +00:00
|
|
|
|
|
|
|
|
describe("tool.ls", () => {
|
|
|
|
|
test("basic", async () => {
|
2025-07-29 22:54:22 +00:00
|
|
|
const result = await App.provide({ cwd: projectRoot }, async () => {
|
|
|
|
|
return await list.execute({ path: fixturePath, ignore: [".git"] }, ctx)
|
2025-06-17 14:27:49 +00:00
|
|
|
})
|
2025-07-29 22:54:22 +00:00
|
|
|
|
|
|
|
|
// Normalize absolute path to relative for consistent snapshots
|
|
|
|
|
const normalizedOutput = result.output.replace(fixturePath, "packages/opencode/test/fixtures/example")
|
|
|
|
|
expect(normalizedOutput).toMatchSnapshot()
|
2025-05-31 18:41:00 +00:00
|
|
|
})
|
|
|
|
|
})
|