fix(opencode): make the declined-hooks plugin stub satisfy the V2 loader schema

The inert stub written when hook consent is not granted was
`export default async () => ({})`. OpenCode v2 validates every plugin
module before running it and requires the default export to be a definition
object with an `id` and an `effect` or `setup` function, so a declined or
runtime-less home install printed the same startup error as the V1 hook
plugin:

  PluginModule.LoadError: Plugin must export a default definition with an id
  and an effect or setup function.
  (cause: SchemaError(Expected object at ["default"]))

Write `export default { id: "ecc-hooks", setup() {} }` instead. It keeps the
inert behaviour (no imports, no module initialization of the replaced
plugin) and satisfies the loader.

Tests that pinned the generated bytes now compare against
getDisabledOpenCodePluginContent() rather than a duplicated literal, and
tests/opencode-plugin-loader-contract.test.js asserts the loader contract on
the generated payload. That test fails on the previous stub
("default export must be an object, got function").

Refs #3537. The same assertion should cover .opencode/plugins/*.ts once a V2
entrypoint lands (#3536, #3224); those plugins are scanned independently in
home installs, so both the barrel and the implementation are loaded.
This commit is contained in:
Ali Arslan committed 2026-10-28 22:32:41 +05:00
1 parent 25278e7d7b
commit 73f61801db
6 files changed
+123 -13

No files matched your search

+6 -1
View File
@@ -183,7 +183,12 @@ function isOpenCodePluginEntrypoint(operation = {}) {
function getDisabledOpenCodePluginContent() {
// OpenCode discovers plugins independently of opencode.json registration.
// Do not import the original module: even module initialization has effects.
return 'export default async () => ({});\n';
// The stub must still satisfy the V2 loader schema: the default export has to
// be a definition object with an id and an effect or setup function. A factory
// (`export default async () => ({})`) is rejected at startup with
// PluginModule.LoadError / SchemaError(Expected object at ["default"]), which
// is the same failure reported for the V1 hook plugin in issue #3537.
return 'export default { id: "ecc-hooks", setup() {} };\n';
}
function isOpenCodeHookActivationOperation(operation = {}) {