cloudaxe-opencode/packages/opencode/test/tool/tool.test.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

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"
import { ListTool } from "../../src/tool/ls"
2025-05-21 14:30:39 +00:00
2025-06-18 17:40:21 +00:00
const ctx = {
sessionID: "test",
messageID: "",
abort: AbortSignal.any([]),
metadata: () => {},
}
const glob = await GlobTool.init()
const list = await ListTool.init()
2025-05-21 14:30:39 +00:00
describe("tool.glob", () => {
test("truncate", async () => {
await App.provide({ cwd: process.cwd() }, async () => {
let result = await glob.execute(
{
pattern: "../../node_modules/**/*",
2025-06-17 15:27:07 +00:00
path: undefined,
},
2025-06-18 17:40:21 +00:00
ctx,
)
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 () => {
await App.provide({ cwd: process.cwd() }, async () => {
let result = await glob.execute(
{
pattern: "*.json",
2025-06-17 15:27:07 +00:00
path: undefined,
},
2025-06-18 17:40:21 +00:00
ctx,
)
2025-05-21 14:30:39 +00:00
expect(result.metadata).toMatchObject({
truncated: false,
count: 3,
2025-05-31 18:41:00 +00:00
})
})
})
})
2025-05-26 18:09:17 +00:00
describe("tool.ls", () => {
test("basic", async () => {
const result = await App.provide({ cwd: process.cwd() }, async () => {
return await list.execute({ path: "./example", ignore: [".git"] }, ctx)
})
2025-05-31 18:41:00 +00:00
expect(result.output).toMatchSnapshot()
})
})