mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-18 16:34:18 +01:00
This release has a bunch of minor breaking changes if you are using opencode plugins or sdk 1. storage events have been removed (we might bring this back but had some issues) 2. concept of `app` is gone - there is a new concept called `project` and endpoints to list projects and get the current project 3. plugin receives `directory` which is cwd and `worktree` which is where the root of the project is if it's a git repo 4. the session.chat function has been renamed to session.prompt in sdk. it no longer requires model to be passed in (model is now an object) 5. every endpoint takes an optional `directory` parameter to operate as though opencode is running in that directory
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import path from "path"
|
|
import { BashTool } from "../../src/tool/bash"
|
|
import { Log } from "../../src/util/log"
|
|
import { Instance } from "../../src/project/instance"
|
|
|
|
const ctx = {
|
|
sessionID: "test",
|
|
messageID: "",
|
|
toolCallID: "",
|
|
agent: "build",
|
|
abort: AbortSignal.any([]),
|
|
metadata: () => {},
|
|
}
|
|
|
|
const bash = await BashTool.init()
|
|
const projectRoot = path.join(__dirname, "../..")
|
|
Log.init({ print: false })
|
|
|
|
describe("tool.bash", () => {
|
|
test("basic", async () => {
|
|
await Instance.provide(projectRoot, async () => {
|
|
const result = await bash.execute(
|
|
{
|
|
command: "echo 'test'",
|
|
description: "Echo test message",
|
|
},
|
|
ctx,
|
|
)
|
|
expect(result.metadata.exit).toBe(0)
|
|
expect(result.metadata.output).toContain("test")
|
|
})
|
|
})
|
|
|
|
test("cd ../ should fail outside of project root", async () => {
|
|
await Instance.provide(projectRoot, async () => {
|
|
expect(
|
|
bash.execute(
|
|
{
|
|
command: "cd ../",
|
|
description: "Try to cd to parent directory",
|
|
},
|
|
ctx,
|
|
),
|
|
).rejects.toThrow("This command references paths outside of")
|
|
})
|
|
})
|
|
})
|