Skip to content

test(opencode): pin the installed OpenCode plugin to a v2-loadable default export - #22389

Merged
nwparker merged 1 commit into
mainfrom
nwparker/opencode2-plugin-load-22234
Sep 23, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/opencode2-plugin-load-22234

Conversation

@nwparker

@nwparker nwparker commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24
Prod 0 0 0 0

ELI5

Orca writes a small plugin file into OpenCode so it can tell when the agent is working, idle, or waiting on you. OpenCode 2 changed the rules for what that file has to look like, and for a while Orca was writing the old shape — so OpenCode refused to load it and Orca's status indicators went dead. That was already fixed a few days ago. This PR adds a test so it can't quietly break again.

What Changed

Test only — no production code changes.

src/main/opencode/hook-service.test.ts gains one test that runs the real plugin install path (buildPtyEnv), takes the file Orca actually wrote to OpenCode's config directory, imports it as an ES module, and asserts its default export satisfies both plugin loaders:

  • default.id + default.server — what OpenCode 1's loader requires
  • default.setup — what OpenCode 2's loader requires

Why

#22234 reported OpenCode 2.0.12 rejecting orca-opencode-status.js with:

Plugin must export a default definition with an id and an effect or setup function.
SchemaError: Missing key at ["default"]["effect"] / Missing key at ["default"]["setup"]

This no longer reproduces on main. It was fixed by 1a3f4e88c0f (fix(opencode): support v2 plugins under plain executable name, Sep 21), which landed after the reporter's Orca 1.4.206.

Root cause of the original bug: setup is appended to the plugin's default export only when the generator is called with emitNextEvents: true. getOpenCodePluginSource() — the source installed for the plain opencode executable — did not pass it, so it emitted export default { id, server }. Because OpenCode 2.0.12 installs as opencode, the v2 loader received the v1-only shape. 1a3f4e88c0f flipped that generator to { emitSessionStart: true, emitNextEvents: true, expectedAgent: 'opencode' }.

Why a test rather than a fix: the escape route is still open. hook-plugin-opencode2-setup.test.ts already asserts setup exists on the generated source, but nothing asserted it on the installed file. Every source-level test would have stayed green if hook-service.ts picked the wrong generator — which is exactly how #22234 escaped. Asserting against the installed artifact closes that gap; asserting against the generator again would not.

Alternative considered: also hardening src/main/mimo/hook-service.ts:75, the last remaining caller still emitting the v1-only shape. Left alone — it is correct today because MiMo Code tracks OpenCode v1, and changing it would be an unrelated behavior change. Flagged here so it is on the record if MiMo rebases onto OpenCode 2.

Linked Issue

Fixes #22234

Visual Proof

N/A — test-only change; no user-visible surface is touched. The behavioral proof is a real opencode serve (v2.0.12, macOS) pointed at each plugin shape via OPENCODE_CONFIG_DIR:

Pre-fix shape (export default { id, server }, byte-identical to 1a3f4e88c0f^):

level=INFO  msg="loading plugin" id=<cfg>/plugins/orca-opencode-status.js
level=WARN  message="failed to load plugin" target=<cfg>/plugins/orca-opencode-status.js ref=err_08e966c0
  cause="Cause([Fail(PluginModule.LoadError: Plugin must export a default definition with an id and an
  effect or setup function. (cause: SchemaError(Missing key\n  at [\"default\"][\"effect\"]\nMissing key\n
  at [\"default\"][\"setup\"])))])"

Byte-for-byte the reporter's error.

Current main (export default { id, server, setup }):

level=INFO  msg="loading plugin" id=<cfg>/plugins/orca-opencode-status.js
(no "failed to load plugin" line)

Same clean load for orca-opencode2-status.js. End-to-end, with a hook receiver on ORCA_AGENT_HOOK_PORT, creating a session over the v2 API delivered a real event through the v2 setup() bridge:

HOOK POST /hook/opencode {"paneKey":"tab-…:leaf-…","tabId":"…","worktreeId":"…",
"payload":{"hook_event_name":"SessionStart","sessionID":"se…

Testing

Platforms: macOS, against a real OpenCode v2.0.12 binary.

Reviewer steps:

  1. pnpm test src/main/opencode/hook-service.test.ts — passes.
  2. Revert getOpenCodePluginSource() in src/main/opencode/status-plugin-factory-source.ts to the v1-only options (drop emitNextEvents/expectedAgent).
  3. Re-run — the new test fails with expected undefined to be type of 'function', i.e. it catches exactly the [Bug]: orca-opencode-status.js hook is incompatible with OpenCode V2 and fails to load #22234 regression.

Suite results:

  • pnpm test src/main/opencode src/main/opencode2 — 16 files, 192 tests passed
  • pnpm tc — clean
  • pnpm run check:code-quality:changed — 0 new findings

Not verified on a live OpenCode 1 server: only v2.0.12 is obtainable locally (opencode2 there is a 47-byte shim to the same v2 binary). The v1 half rests on the pre-existing hook-plugin-module-contract.test.ts, which asserts server is present and callable.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Backwards compatibility: the asserted shape carries server and setup, so both the OpenCode 1 and OpenCode 2 loaders accept the same installed file. No user on either version changes behavior.
  • Cross-platform: the test drives the same buildPtyEnv install path used on all platforms and does no path-separator assertions of its own.
  • Security, SSH/remote, mobile, performance: unaffected — no production code runs differently.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test pass locally

…fault export

OpenCode 2 installs under the plain `opencode` executable name and its plugin
loader requires the default export to carry `setup` (or `effect`) alongside an
`id`; the v1 loader requires `server`. The emitted plugin source already carries
both, but nothing asserted it on the file Orca actually installs into OpenCode's
config directory — the exact surface that regressed in #22234.

Load the installed file as an ES module and assert its default export satisfies
both loaders. Reverting getOpenCodePluginSource() to the v1-only options makes
this test fail with "expected undefined to be type of 'function'".
@coderabbitai

coderabbitai Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d32fd371-48c5-4567-a2a0-e3ab5a0a8fde

📥 Commits

Reviewing files that changed from the base of the PR and between bf3f952 and 46b668f.

📒 Files selected for processing (1)
  • src/main/opencode/hook-service.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

Adds an integration test that installs the generated OpenCode plugin, imports the installed source as ESM, and checks that its default export has the expected ID and function-valued server and setup properties.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 46b66

The added test covers the installed plugin’s loader-facing exports. No issue identified here needs resolution before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive For [#22234], the added test installs and imports the plugin file, then checks its id, server, and setup exports. hook-service.ts assembles the installed plugin from status-plugin source modul… Need evidence from the generated plugin factory and relevant event-delivery or lifecycle tests at the reviewed head to confirm that the V2 setup path preserves #22234's status, HTTP-post, and cleanup behavior.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the change as a test that verifies the installed OpenCode plugin has a V2-loadable default export.
Description check ✅ Passed The description covers the change, reason, linked issue, testing, and the required N/A visual proof. It also addresses compatibility and cross-platform impact. The Review and AI Disclosure sections ar…
Out of Scope Changes check ✅ Passed The only change is an installed-plugin export-shape test and its pathToFileURL import. Both support [#22234]'s OpenCode loader-compatibility objective. No unrelated changes are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Full details: Linked Issues check

Explanation

For [#22234], the added test installs and imports the plugin file, then checks its id, server, and setup exports. hook-service.ts assembles the installed plugin from status-plugin source modules. The available evidence does not establish that the V2 setup path preserves status-event delivery, HTTP posts, and cleanup, which #22234 requires. The PR summary also states that this test does not verify event delivery.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Installed-artifact plugin contract test — adds one test to src/main/opencode/hook-service.test.ts that drives the real buildPtyEnv install path, copies the file Orca wrote into OpenCode's config plugins/ directory to a temporary .mjs, imports it as an ES module, and asserts its default export exposes id, server (v1 loader), and setup (v2 loader).

I confirmed the test can actually fail: reverting getOpenCodePluginSource() in src/main/opencode/hook-service.ts to the pre-1a3f4e88c0f v1-only options makes the new assertion at src/main/opencode/hook-service.test.ts:312 fail with expected undefined to be type of 'function'. The whole file passes on the PR head (33/33) and pnpm run check:code-quality:changed reports zero new findings. Note the regression is also caught by the pre-existing digest test and by hook-plugin-opencode2-setup.test.ts; this test's distinct value is exercising the install-path wiring (buildPtyEnv → writePluginToConfigDir → default variant) rather than the generator directly, which is the seam the source-level tests don't cover.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: orca-opencode-status.js hook is incompatible with OpenCode V2 and fails to load

1 participant