Skip to content

test(opencode): migrate the V1 runtime surface to scenarios - #208

Merged
pgermishuys merged 1 commit into
mainfrom
test/opencode-runtime-migration
Sep 21, 2026
Merged

pgermishuys merged 1 commit into
mainfrom
test/opencode-runtime-migration

Conversation

@pgermishuys

Copy link
Copy Markdown
Contributor

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 .weave source in a temporary project:

  • The command menu. The plugin's config hook writes cfg.command, so the commands a user can type — and what each sends, to which agent — come off the same seam tests/adapters/opencode.scenario.test.ts already uses for agents. registeredCommand(Names) and an optional existing config argument are added to the shared harness, so a scenario can also watch what Weave does to a user's own opencode.json.
  • A running OpenCode instance. FakeOpenCodeInstance is a new harness export: a real in-memory agent store, not a call recorder. createAgent adds, updateAgent replaces, listAgents reports 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.

Before After
runtime-command-projection.test.ts 58 28
reconcile-agent.test.ts 42 2
adapter.test.ts 42 11
plugin.test.ts 36 6
run-workflow.test.ts 27 11
start-plan-execution.test.ts 27 7
Unit total 232 65
Scenarios added — 51 (55 at runtime)

Mutation testing

Twenty-eight mutations against tests/adapters/opencode-runtime.scenario.test.ts alone, with every deleted unit case already gone. Twenty-six caught; the full table is in docs/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

  • Running a workflow destroys the agents it dispatches. The engine emits a placeholder descriptor (composedPrompt: "", models: [], ask-everything policy) and buildProjectEffect feeds it into spawnSubagent(), 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 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 (a config.update() per agent made OpenCode reload every plugin), so the config hook is the only materialization mechanism and it assigns cfg.agent[name] unconditionally. A user with their own shuttle in opencode.json has it silently replaced. All 42 reconcile-agent cases passed against a module nothing reaches.
  • Four exported surfaces have no production caller — runWorkflow, startPlanExecution, RuntimeCommandProjection and OpenCodeAdapter.spawnSubagent. The plugin offers start-work and weave: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_COMMAND and WeavePluginOptions.clientFacade are unread too. Kept and flagged rather than deleted.
  • startPlanExecution() discards every lifecycle error's cause. Its mapper reads error.message/error.reason, but command_lifecycle carries its text on error.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 reads Plan ".weave/plans/auth-work.md" has incomplete checkbox(es).
  • /weave:health can 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 asserted outcome === "success" || outcome === "degraded" — the whole union.
  • disable agents ["tapestry"] removes the agent and still registers both commands with agent: "tapestry".

Test doubles

Per the runners warning: MockOpenCodeAdapter in runtime-command-projection.test.ts and start-plan-execution.test.ts does extend the real OpenCodeAdapter with override spawnSubagent. Unlike the eval runners it overrides only the SDK boundary, not the method under test — but every case that asserted what spawnSubagent was 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 .weave file cannot produce (an empty workflowInstanceId), absence guarantees (runWorkflow is never reachable from an idle hook), error branches the real BunFilesystemPlanStateProvider cannot be made to take, and adapter-supplied context such as OpenCodeModelContext that 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

Copilot AI lite review requested due to automatic review settings September 21, 2026 07:32
@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 40 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 52128747-e1cc-4bd2-a62c-f7da305475ba

📥 Commits

Reviewing files that changed from the base of the PR and between 118958f and d3ec214.

⛔ Files ignored due to path filters (3)
  • .codesight/CODESIGHT.md is excluded by !.codesight/**
  • .codesight/coverage.md is excluded by !.codesight/**
  • .codesight/graph.md is excluded by !.codesight/**
📒 Files selected for processing (9)
  • docs/testing-strategy.md
  • packages/adapters/opencode/src/__tests__/adapter.test.ts
  • packages/adapters/opencode/src/__tests__/plugin.test.ts
  • packages/adapters/opencode/src/__tests__/reconcile-agent.test.ts
  • packages/adapters/opencode/src/__tests__/run-workflow.test.ts
  • packages/adapters/opencode/src/__tests__/runtime-command-projection.test.ts
  • packages/adapters/opencode/src/__tests__/start-plan-execution.test.ts
  • tests/adapters/opencode-runtime.scenario.test.ts
  • tests/support/opencode.ts

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 High severity · 1 Low severity

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.

Comment on lines +342 to +355
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]",
});
Comment on lines +753 to +758
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.
Comment thread tests/support/opencode.ts
Comment on lines +277 to +280
/** 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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Several runtime defects and an uncovered update-error path remain unresolved.

Review effort: Lite
Findings: 2 High severity · 1 Low severity

Open (3)

@pgermishuys

Copy link
Copy Markdown
Contributor Author

Review — verified independently, rebased onto main

Rebased onto the head that now carries #206 and #207. The docs/testing-strategy.md conflict was two additive sections at the same insertion point; both kept, in order. Confirmed #207's tests/adapters/opencode2.scenario.test.ts survived.

Counts re-derived from the rebased tree: runtime-command-projection 28, reconcile-agent 2, adapter 11, plugin 6, run-workflow 11, start-plan-execution 7 — 65 unit, 51 scenario source cases. Every figure matches the report.

Mutation reproduced. Replacing the adapter.spawnSubagent(...) call in projection-helpers.ts with a no-op turns 11 scenarios red, matching the table's "a dispatched step never reaches the adapter".

The agent-wipe scenario is not vacuous. It asserts the before-state positively (prompt: "You are Shuttle…", model: anthropic/claude-sonnet-4-5) before running the workflow, then asserts the exact stripped after-state. A scenario that only checked the after-state would pass against an adapter that never wrote anything.

Findings verified against source, with one qualification. I checked defect 1 (dispatch.ts:79 does emit composedPrompt: "", models: []), defect 5 (12 capabilities declared, none among the 7 optional ones, so degraded is unconditional) and defect 3's reachability. That last one qualifies defect 1: runWorkflow/startPlanExecution/RuntimeCommandProjection are exported from the barrel but called by nothing here, so the wipe is reachable through the adapter's public API, not by a user running the plugin. Real, published, and worth fixing — but not an active production incident, and the report did not draw that line.

All six findings filed as #210 for the product decision.

Checks on the rebased head: bun test 5375 pass / 13 skip / 0 fail; bun run typecheck exit 0 for every package; packages/ verified clean after the mutation.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve

@pgermishuys
pgermishuys merged commit 60ab070 into main Sep 21, 2026
7 checks passed
@pgermishuys
pgermishuys deleted the test/opencode-runtime-migration branch September 21, 2026 07:41
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.

2 participants