Repository navigation
test(opencode): cover the opencode2 host-env branch and stop inheriting ORCA_OPENCODE_AGENT - #22547
Conversation
|
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 configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe changes add tests for variant-specific plugin overlays and WSL guest overlay directories. A parameterized daemon test checks that the selected agent determines the overlay and environment values. IPC test mocks now provide a separate OpenCode 2 environment mock, and contract tests clear the agent environment variable before each test. Merge Risk: ⚪ Minimal · up to The added tests and environment cleanup are ready to merge after normal checks; no actionable issue remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
ℹ️ Two minor suggestions inline — no correctness issues, the added tests are sound.
Reviewed changes
- v2 host-env mock —
pty-ipc-mock-registry.ts/pty-ipc-suite-environment.tsadd a distinctopenCode2HookServicemock, so an opencode2 launch no longer dereferencesundefinedinassembly.tsand the v2 branch is reachable at all. - WSL overlay selection —
pty-daemon-spawn-agent-home-env.test.tspinsgetOpenCodeOverlayDir(distro, openCodeAgent)per major, asserting the recorded variant argument and the resultingORCA_OPENCODE_AGENT/OPENCODE_CONFIG_DIR/ORCA_OPENCODE_CONFIG_DIR. - Guest overlay independence —
wsl-guest-plugin-install.test.tspins independentdir/dir2propagation, including the v2-only case. - Cross-major mirror skip —
plugin-overlay.test.tsasserts the other major's stale Orca plugin is not mirrored into the overlay. - Test-env isolation —
hook-plugin-module-contract.test.tsclearsORCA_OPENCODE_AGENTinbeforeEachso an inherited value can't self-disable the plugin.
I read the full diff and ran the four changed files plus the pty-daemon suite (66 tests pass). The assertions are exact rather than loose — the WSL test compares spy.mock.calls.map(([, agent]) => agent) with toEqual([expectedAgent]), so dropping the variant argument produces [undefined] and fails, matching the mutation check described in the PR body. The mirror test binds both OPENCODE_PLUGIN_FILE/OPENCODE2_PLUGIN_FILE in the skip list, so removing either constant fails the relevant case.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // Why: the generated plugin self-disables when this names a different major, | ||
| // so an inherited value from the developer's own Orca pane would leave | ||
| // `hooks.event` undefined and fail the contract for the wrong reason. | ||
| delete process.env.ORCA_OPENCODE_AGENT |
There was a problem hiding this comment.
Minor: ORCA_OPENCODE_AGENT is deleted here but is not in ENV_KEYS, so afterEach never restores the value it captured. The sibling hook-plugin-opencode2-setup.test.ts includes it in ENV_KEYS and restores it; adding it here keeps the save/restore symmetric and avoids leaking the deletion to any test that runs later in the same worker. Not blocking — the deletes re-run per test within this file.
| ...(launchAgent ? { launchAgent } : {}) | ||
| }) | ||
| expect(spy.mock.calls.map(([, agent]) => agent)).toEqual([expectedAgent]) | ||
| expect(env.ORCA_OPENCODE_AGENT).toBe(expectedAgent) |
There was a problem hiding this comment.
Optional: this test pins the guest-overlay variant argument, but the other v2 variant selection in assembly.ts:93 (openCodeAgent === 'opencode2' ? openCode2HookService : openCodeHookService) is still unasserted — a regression that always picked the v1 service would pass, because the WSL branch overwrites OPENCODE_CONFIG_DIR from the guest dir. Since openCode2BuildPtyEnvMock exists specifically to distinguish this, a single assertion that the matching service mock was called would realize the registry comment's stated intent.
…he relay OpenCode 2 dies with "Duplicate plugin ID" when two plugin files share an id, so which overlay a guest or remote pane is pointed at decides whether the agent starts. Nothing failed if that selection regressed: - the WSL spawn path never asserted which major it asks the guest relay for, and the shared pty-ipc mock had no openCode2HookService at all, so no test could reach the opencode2 branch of buildPtyHostEnv; - requestGuestOpenCodeOverlayDir had no coverage for the v2 guest dir; - PluginOverlayManager had no case for a remote config root that still holds the other major's stale Orca plugin. Tests only; no behavior change. Each new case was mutation-checked against the production line it guards.
…E_AGENT The generated plugin self-disables when ORCA_OPENCODE_AGENT names a different major, and the contract test saved and restored that variable without ever setting it. Run from a shell that has it — which is any shell inside an Orca OpenCode pane, i.e. how this repo is usually developed — the plugin returned an empty hook set and the contract failed for the wrong reason. Delete it in beforeEach, the way the opencode2 setup test already pins it. Verified the file passes with the variable set to either major and unset; before this it failed for two of the three.
2e135d8 to
79eff5b
Compare

ELI5
Two test-only fixes. One adds coverage for a path that no test could reach, so a bug there would have shipped silently. The other stops a test failing for everyone who runs it from inside an Orca OpenCode pane — which is how most of us develop this repo.
What Changed
Test-only. No production code.
1. The opencode2 branch of
buildPtyHostEnvwas unreachable by any test. The shared pty-ipc mock registry exported noopenCode2HookServiceat all, so nothing could exercise the v2 side of the host-env assembly. A regression dropping the variant argument would have passed CI.src/main/ipc/pty-ipc-mock-registry.ts,pty-ipc-suite-environment.ts— add the missing v2 service mocksrc/main/ipc/pty-daemon-spawn-agent-home-env.test.ts— a WSL spawn must ask the guest for the matching majorsrc/main/agent-hooks/wsl-guest-plugin-install.test.ts— v1 and v2 guest overlay dirs stay independentsrc/relay/plugin-overlay.test.ts— a remote config root holding the other major's stale Orca plugin must not have it mirrored inEach was mutation-checked: reverting
getOpenCodeOverlayDir(distro, openCodeAgent)→(distro)fails 2 tests; removing the cross-major skip inmirrorOpenCodeConfigfails 2 more.2.
hook-plugin-module-contract.test.tsinheritedORCA_OPENCODE_AGENT. The file saved and restored that variable but never set it. The generated plugin self-disables when it names a different major, so run from a shell that exports it, the plugin returned an empty hook set and the contract failed for the wrong reason —TypeError: hooks?.event is not a function. Fixed by deleting it inbeforeEach, the way the sibling opencode2 suite already does.Why
Both came out of investigating a Slack report that "Orca SSH WSL's opencode v2 orca-overlay is starting to report errors."
That report is #22506 seen from a host where it applies, not a WSL-specific defect — and the host matrix is the useful part:
hook-service.tswrites both majors into the canonical~/.config/opencode/plugins/OPENCODE_CONFIG_DIR)OPENCODE_CONFIG_DIR)mirrorOpenCodeConfigskips both Orca filenamesVerified on a real WSL2 Ubuntu-24.04 guest (via
orca --environment awin), not just reasoned:~/.orca-relay/opencode2-overlaysdoes not exist, and~/.config/opencode/pluginsdoes not exist in the guest — so the canonical dir is untouched and there is nowhere in WSL for the two files to meet. The guest's own OpenCode log shows it reading config from/home/<user>/.orca-relay/opencode-overlays/<hash>/opencode.json— direct evidence thatOPENCODE_CONFIG_DIRstays guest-side rather than leaking a WindowsuserDatapath.Two corrections to my original wording, from that verification:
mirrorOpenCodeConfigexcluding both plugin filenames (plugin-overlay.ts:194-201). Saying "per-major" understated it.relay-agent-hook-runtime.ts:98-107). With no source dir the relay falls back toinstallOpenCodePlugininto the canonical dir — the same collision site as local. In the verified guest the user does have~/.config/opencode, so the overlay branch is what actually ran; a guest without one would not be immune.So WSL is strictly better isolated than local, and SSH is merely equal to it. There is no worse WSL variant and no wrong-variant delivery —
ORCA_OPENCODE_AGENTreaches both hosts correctly, and7b97551acfbalready blocks a Windows overlay path from crossing into a guest. The fix for that reporter is #22544, not anything WSL-shaped.Two things I settled from OpenCode source (
v2.0.15) rather than by inference, because the obvious hypothesis was that a localuserDatapath leaks into a guest and errors:OPENCODE_CONFIG_DIRis still honoured by v2 (packages/cli/src/index.ts:117,server-process.ts:36→Global.layerWith({config})), so the overlay mechanism is not obsolete.packages/util/src/global.ts:66doesmkdir(config, { recursive: true }), and plugin discovery swallows a missingplugins/(Effect.orElseSucceed(() => [])). A meaningless overlay path would produce a silently wrong config root, not an error message. That ruled the hypothesis out, and is why this PR carries no production change.The second fix is unrelated to WSL but was found the same way — it cost the investigation a wasted run, and it will cost every other contributor one.
Linked Issue
Refs #22506
Visual Proof
N/A— test-only; no user-visible surface is touched.Testing
Platforms: macOS for the unit tests. The WSL rows of the matrix were since verified on a real WSL2 Ubuntu-24.04 guest (see Why). SSH-to-Windows remains derived rather than measured.
pnpm test src/main/ipc src/relay src/main/agent-hooks src/main/opencode→ 720 files, 7096 passed, 24 skippedpnpm tcclean;pnpm run check:code-quality:changedpassedContract-test fix verified against all three states:
ORCA_OPENCODE_AGENT=opencode,=opencode2, and unset — 9/9 in each. Before it, two of the three failed.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
relay-agent-hook-runtime.ts:88-90) still has no test. It duplicates the WSL one pinned here, but testing it needsRelayAgentHookRuntimewith a real hook server and ahomedir()override, andmaterializeOmpFreshConfig()writes to the real~/.orca-relay. A HOME-mutating test looked more fragile than the coverage was worth. Flagging rather than forcing it.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm testpass locally