Repository navigation
test(opencode): migrate the V1 runtime surface to scenarios - #208
Conversation
|
Warning Review limit reachedNext included review available in 40 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (9)
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.
Copilot review overview
🟡 Changes recommended
Critical destructive runtime behavior and moderate command/error-handling issues remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (3)
What changed in this PR
Migrates OpenCode V1 runtime tests from white-box unit tests to black-box scenarios, adding live configuration and agent harnesses while documenting discovered behavior.
Changes:
- Adds command/configuration and in-memory OpenCode scenario coverage.
- Retains focused unit tests for non-runtime contracts.
- Documents migration metrics, mutation testing, and findings.
- Refreshes generated CodeSight metadata.
| File | Description |
|---|---|
tests/support/opencode.ts |
Adds scenario helpers and fake OpenCode state. |
tests/adapters/opencode-runtime.scenario.test.ts |
Adds runtime and command scenarios. |
packages/adapters/opencode/src/__tests__/start-plan-execution.test.ts |
Retains boundary-focused tests. |
packages/adapters/opencode/src/__tests__/runtime-command-projection.test.ts |
Retains projection-specific tests. |
packages/adapters/opencode/src/__tests__/run-workflow.test.ts |
Retains workflow-specific tests. |
packages/adapters/opencode/src/__tests__/reconcile-agent.test.ts |
Retains unreachable helper coverage. |
packages/adapters/opencode/src/__tests__/plugin.test.ts |
Retains plugin guard coverage. |
packages/adapters/opencode/src/__tests__/adapter.test.ts |
Retains adapter-only coverage. |
docs/testing-strategy.md |
Documents migration results and findings. |
.codesight/graph.md |
Updates generated dependency metadata. |
.codesight/CODESIGHT.md |
Updates generated scan metadata. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| it("replaces one of their agents outright when Weave declares the same name", async () => { | ||
| // Observed, not intended. `reconcile-agent.ts` exists to refuse exactly | ||
| // this — a same-named agent without the Weave ownership marker is a | ||
| // collision, and Weave is meant to leave it alone. The config hook is the | ||
| // only live materialization path and consults none of it, so the user's | ||
| // agent is overwritten with no warning. See the file docblock. | ||
| const cfg = await load(SHUTTLE_ONLY, { | ||
| agent: { shuttle: { prompt: "My own shuttle, thanks." } }, | ||
| }); | ||
|
|
||
| expect(registeredAgent(cfg, "shuttle")).toMatchObject({ | ||
| prompt: "You are Shuttle, and you know this codebase.", | ||
| description: "Shuttle (Domain Specialist) [weave-managed]", | ||
| }); |
| it("strips the dispatched agent back to an empty prompt, no model and ask-everything permissions", async () => { | ||
| // Observed, not intended: a dispatch carries a placeholder descriptor | ||
| // (`composedPrompt: ""`, `models: []`, a default policy), and the adapter | ||
| // writes it straight over the agent OpenCode already held. Running a | ||
| // workflow therefore costs the user the agent they configured for the rest | ||
| // of the session. See the file docblock. |
| /** Makes every subsequent agent update fail. */ | ||
| failUpdateAgent(message: string): this { | ||
| this.updateFailure = message; | ||
| return this; |
Six test files asserted what the OpenCode V1 adapter does at runtime — command projection, reconciliation, workflow running, plan execution — and none of them looked at anything a user can see. `tests/adapters/opencode-runtime.scenario.test.ts` uses two black boxes. The slash commands OpenCode ends up offering come off `cfg.command` through the same config hook the agent scenarios already use. The agents a running OpenCode is left holding come off `FakeOpenCodeInstance`, a new export on the shared harness: a real in-memory agent store rather than a call recorder, so a second startup genuinely sees what the first one wrote. Unit cases 232 -> 65 in source; 51 scenarios added, 55 at runtime. Twenty-eight mutations were run against the scenario file alone with the deleted unit tests already gone; twenty-six were caught. The two survivors are each masked by a second guard — `resolveModelForAgent()` filters unqualified model names twice, and `tagWithOwnership()`'s idempotency guard is unreachable because every caller passes a freshly translated config. Removing both model gates together does turn a scenario red. Writing against observed behaviour turned up six things: - Running a workflow destroys the agents it dispatches. The engine emits a placeholder descriptor (empty prompt, no models, ask-everything policy) and the adapter reconciles it over the agent OpenCode already holds, so a user gets their Shuttle back neutered for the rest of the session. The unit tests drove `MockOpenCodeAdapter`, which overrides `spawnSubagent` and writes nothing, so they could not see it. - The collision protection is not on the live path. SDK reconciliation was deliberately disabled, so the config hook is the only materialization mechanism and it assigns `cfg.agent[name]` unconditionally — a user's own same-named agent is silently replaced. All 42 `reconcile-agent` cases passed against a module nothing reaches. - `runWorkflow`, `startPlanExecution`, `RuntimeCommandProjection` and `OpenCodeAdapter.spawnSubagent` have no production caller. The plugin offers `start-work` and `weave:start`, both prompt templates; the six `/weave:*` commands the projection layer labels are registered with nothing. - `startPlanExecution()` collapses every lifecycle error to "Unknown command operation error" — its mapper lacks the `command_lifecycle` branch `run-workflow.ts` has, so a plan with an unticked task reports nothing. - `/weave:health` can never report a healthy adapter: seven undeclared optional capabilities each count as degraded. Two of its unit cases asserted the whole `ProjectionResult` union and were therefore always true. - `disable agents ["tapestry"]` still registers both commands pointing at the agent it just removed. What stays in each file is recorded in its docblock: argument-validation branches a `.weave` file cannot produce, absence guarantees, and adapter-supplied context such as `OpenCodeModelContext` that the plugin never populates. Refs #183 (task group 14). Claude-Session: https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
cee0787 to
d3ec214
Compare
Review — verified independently, rebased onto
|


Migrates the OpenCode V1 runtime surface from white-box unit tests to black-box scenarios. Refs #183 (task group 14).
The seams
Two black boxes, both entered from
.weavesource in a temporary project:confighook writescfg.command, so the commands a user can type — and what each sends, to which agent — come off the same seamtests/adapters/opencode.scenario.test.tsalready uses for agents.registeredCommand(Names)and an optionalexistingconfig argument are added to the shared harness, so a scenario can also watch what Weave does to a user's ownopencode.json.FakeOpenCodeInstanceis a new harness export: a real in-memory agent store, not a call recorder.createAgentadds,updateAgentreplaces,listAgentsreports what is there now — which is what lets a scenario restart Weave and see an update rather than a duplicate.Counts
One measure — source cases, since both sides lean on tables.
runtime-command-projection.test.tsreconcile-agent.test.tsadapter.test.tsplugin.test.tsrun-workflow.test.tsstart-plan-execution.test.tsMutation testing
Twenty-eight mutations against
tests/adapters/opencode-runtime.scenario.test.tsalone, with every deleted unit case already gone. Twenty-six caught; the full table is indocs/testing-strategy.md. Three of the caught ones are mutations that fix a defect the scenarios pin as observed behaviour — the only way to prove such a scenario is live.The two survivors are not gaps:
resolveModelForAgent()filters unqualified model names on the way in and on the way out. Removing either alone changes nothing; removing both turns a scenario red.tagWithOwnership()'s idempotency guard is unreachable — both callers pass a freshly translated, untagged config. Its unit test is kept and flagged. A mutation that writes the tag twice turns three scenarios red, which proves the assertion watching it is not vacuous.What this turned up
composedPrompt: "",models: [], ask-everything policy) andbuildProjectEffectfeeds it intospawnSubagent(), which reconciles it over the agent OpenCode already holds. A user who runs a two-step workflow gets Shuttle back with no prompt, no model and every permission downgraded, for the rest of the session. The unit tests droveMockOpenCodeAdapter, which overridesspawnSubagentand writes nothing, so they could not see it.config.update()per agent made OpenCode reload every plugin), so the config hook is the only materialization mechanism and it assignscfg.agent[name]unconditionally. A user with their ownshuttleinopencode.jsonhas it silently replaced. All 42reconcile-agentcases passed against a module nothing reaches.runWorkflow,startPlanExecution,RuntimeCommandProjectionandOpenCodeAdapter.spawnSubagent. The plugin offersstart-workandweave:start, both prompt templates dispatching to Tapestry; the six/weave:*commands the projection layer labels and documents are registered with nothing.WEAVE_START_COMMAND,WEAVE_START_LEGACY_COMMANDandWeavePluginOptions.clientFacadeare unread too. Kept and flagged rather than deleted.startPlanExecution()discards every lifecycle error's cause. Its mapper readserror.message/error.reason, butcommand_lifecyclecarries its text onerror.cause.message, so everything collapses to"Unknown command operation error".run-workflow.ts's mapper has the branch this one lacks — the same failure through the projection readsPlan ".weave/plans/auth-work.md" has incomplete checkbox(es)./weave:healthcan never report a healthy adapter. Seven undeclared optional capabilities each count as a degraded operation, so the success branch is unreachable. Two of its unit cases assertedoutcome === "success" || outcome === "degraded"— the whole union.disable agents ["tapestry"]removes the agent and still registers both commands withagent: "tapestry".Test doubles
Per the runners warning:
MockOpenCodeAdapterinruntime-command-projection.test.tsandstart-plan-execution.test.tsdoes extend the realOpenCodeAdapterwithoverride spawnSubagent. Unlike the eval runners it overrides only the SDK boundary, not the method under test — but every case that asserted whatspawnSubagentwas handed was asserting against a stub that wrote nothing, which is how the prompt-wipe above stayed invisible. Those cases are gone; the scenarios watch the real adapter write to a real OpenCode instead.What stays, and why
Recorded in each file's docblock. The pattern is consistent: argument-validation branches a
.weavefile cannot produce (an emptyworkflowInstanceId), absence guarantees (runWorkflowis never reachable from an idle hook), error branches the realBunFilesystemPlanStateProvidercannot be made to take, and adapter-supplied context such asOpenCodeModelContextthat the plugin never populates.Verification
bun run test(5331 pass, 0 fail),bunx tsc --noEmit,bunx biome check,bun run docs:check-links— all green.packages/verified clean after every mutation.🤖 Generated with Claude Code
https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve