opencode_offline/packages/opencode/test/tool/tool.test.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

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"
import { ListTool } from "../../src/tool/ls"
2025-05-21 22:30:39 +08:00
describe("tool.glob", () => {
test("truncate", async () => {
await App.provide({ cwd: process.cwd(), version: "test" }, async () => {
let result = await GlobTool.execute(
{ pattern: "./node_modules/**/*" },
{ sessionID: "test" },
)
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 () => {
await App.provide({ cwd: process.cwd(), version: "test" }, async () => {
let result = await GlobTool.execute(
{ pattern: "*.json" },
{ sessionID: "test" },
)
2025-05-21 22:30:39 +08:00
expect(result.metadata).toMatchObject({
truncated: false,
2025-05-27 02:18:07 +08:00
count: 2,
2025-06-01 02:41:00 +08:00
})
})
})
})
2025-05-27 02:09:17 +08:00
describe("tool.ls", () => {
test("basic", async () => {
2025-06-02 03:01:57 +08:00
const result = await App.provide(
{ cwd: process.cwd(), version: "test" },
async () => {
return await ListTool.execute(
{ path: "./example" },
{ sessionID: "test" },
)
2025-06-02 03:01:57 +08:00
},
)
2025-06-01 02:41:00 +08:00
expect(result.output).toMatchSnapshot()
})
})