feat: scaffold OpenCode V2 toolkit with safe project installer
This commit is contained in:
commit
aac5627e98
30 files changed
+7533
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import assert from "node:assert/strict"
|
||||
import test from "node:test"
|
||||
import toolkit from "../dist/plugin.js"
|
||||
|
||||
function createContext() {
|
||||
const registered = []
|
||||
const vcs = {
|
||||
get: async () => ({ branch: { current: "feature/toolkit", default: "main" } }),
|
||||
status: async () => [{ path: "src/app.ts", status: "modified" }],
|
||||
}
|
||||
|
||||
const context = {
|
||||
location: {
|
||||
directory: "/workspace/demo",
|
||||
project: { id: "project-1", directory: "/workspace/demo", canonical: "/workspace/demo" },
|
||||
},
|
||||
vcs,
|
||||
tool: {
|
||||
transform: async (register) => {
|
||||
register({
|
||||
namespace: () => {},
|
||||
add: (definition) => registered.push(definition),
|
||||
list: () => [],
|
||||
get: () => undefined,
|
||||
update: () => {},
|
||||
remove: () => {},
|
||||
})
|
||||
return { dispose: async () => {} }
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return { context, registered, vcs }
|
||||
}
|
||||
|
||||
test("exports a stable OpenCode V2 plugin definition", () => {
|
||||
assert.equal(toolkit.id, "sargatxet.opencode-toolkit")
|
||||
assert.equal(typeof toolkit.setup, "function")
|
||||
})
|
||||
|
||||
test("registers namespaced read-only project status tool", async () => {
|
||||
const { context, registered } = createContext()
|
||||
|
||||
await toolkit.setup(context)
|
||||
|
||||
assert.equal(registered.length, 1)
|
||||
assert.equal(registered[0].name, "project_status")
|
||||
assert.equal(typeof registered[0].execute, "function")
|
||||
assert.deepEqual(registered[0].input, {
|
||||
type: "object",
|
||||
properties: {},
|
||||
additionalProperties: false,
|
||||
})
|
||||
})
|
||||
|
||||
test("status tool reports VCS context without mutating it", async () => {
|
||||
const { context, registered, vcs } = createContext()
|
||||
const originalGet = vcs.get
|
||||
const originalStatus = vcs.status
|
||||
|
||||
await toolkit.setup(context)
|
||||
const result = await registered[0].execute({}, { signal: new AbortController().signal })
|
||||
|
||||
assert.deepEqual(JSON.parse(result.content), {
|
||||
project: {
|
||||
id: "project-1",
|
||||
directory: "/workspace/demo",
|
||||
canonical: "/workspace/demo",
|
||||
},
|
||||
vcs: {
|
||||
branch: { current: "feature/toolkit", default: "main" },
|
||||
},
|
||||
changes: [{ path: "src/app.ts", status: "modified" }],
|
||||
})
|
||||
assert.equal(vcs.get, originalGet)
|
||||
assert.equal(vcs.status, originalStatus)
|
||||
})
|
||||
Reference in new issue
Block a user