test(opencode): assert init does not call shell and root plugin tools

This commit is contained in:
van3hardy
2026-08-29 13:40:56 -04:00
committed by haelyra
parent f932e63b0a
commit e72f1e6824
+18 -1
View File
@@ -62,12 +62,17 @@ function main() {
assert.deepStrictEqual(Object.keys(mod).sort(), ["default"])
assert.strictEqual(typeof mod.default, "function")
let shellCalls = 0
const plugin = await mod.default({
client: { app: { log: () => {} } },
$: async () => { throw new Error("$ must not be called during plugin init") },
$: async () => {
shellCalls += 1
throw new Error("$ must not be called during plugin init")
},
directory: process.cwd(),
worktree: process.cwd(),
})
assert.strictEqual(shellCalls, 0, "$ must not be called during plugin init")
assert.ok(plugin && typeof plugin === "object", "default export must return a plugin record")
const expectedHooks = [
"file.edited",
@@ -85,6 +90,18 @@ function main() {
for (const hook of expectedHooks) {
assert.strictEqual(typeof plugin[hook], "function", "missing hook: " + hook)
}
assert.deepStrictEqual(
Object.keys(plugin.tool).sort(),
["changed-files", "dependency-analyzer"],
"plugin.tool must expose exactly the custom tools"
)
for (const toolName of ["changed-files", "dependency-analyzer"]) {
const toolDefinition = plugin.tool[toolName]
assert.ok(toolDefinition && typeof toolDefinition === "object", "missing tool: " + toolName)
assert.strictEqual(typeof toolDefinition.description, "string", toolName + " must declare a description")
assert.ok(toolDefinition.args && typeof toolDefinition.args === "object", toolName + " must declare args")
assert.strictEqual(typeof toolDefinition.execute, "function", toolName + " must declare an execute function")
}
}
main().catch((error) => {