From f932e63b0a317b43a55f344e6f0a0498bcf3794b Mon Sep 17 00:00:00 2001 From: van3hardy Date: Tue, 11 Aug 2026 22:03:01 -0400 Subject: [PATCH] test(opencode): assert built entry is a working plugin, not just an export shape --- tests/scripts/build-opencode.test.js | 39 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/scripts/build-opencode.test.js b/tests/scripts/build-opencode.test.js index abc55a275..b05fa8d1c 100644 --- a/tests/scripts/build-opencode.test.js +++ b/tests/scripts/build-opencode.test.js @@ -50,11 +50,44 @@ function main() { const check = ` const assert = require("assert") const { pathToFileURL } = require("url") - const file = process.argv[1] - import(pathToFileURL(file).href).then((mod) => { + + async function main() { + let mod + try { + mod = await import(pathToFileURL(process.argv[1]).href) + } catch (error) { + console.error(error) + process.exit(1) + } assert.deepStrictEqual(Object.keys(mod).sort(), ["default"]) assert.strictEqual(typeof mod.default, "function") - }).catch((error) => { + + const plugin = await mod.default({ + client: { app: { log: () => {} } }, + $: async () => { throw new Error("$ must not be called during plugin init") }, + directory: process.cwd(), + worktree: process.cwd(), + }) + assert.ok(plugin && typeof plugin === "object", "default export must return a plugin record") + const expectedHooks = [ + "file.edited", + "tool.execute.after", + "tool.execute.before", + "session.created", + "session.idle", + "session.deleted", + "file.watcher.updated", + "todo.updated", + "shell.env", + "experimental.session.compacting", + "permission.ask", + ] + for (const hook of expectedHooks) { + assert.strictEqual(typeof plugin[hook], "function", "missing hook: " + hook) + } + } + + main().catch((error) => { console.error(error) process.exit(1) })