Skip to content

test(opencode): run OpenCode with the plugin against a real Server - #2533

Merged
hidb4ai merged 3 commits into
oceanbase:masterfrom
Fengzdadi:test/opencode-service-chain
Nov 11, 2026
Merged

hidb4ai merged 3 commits into
oceanbase:masterfrom
Fengzdadi:test/opencode-service-chain

Conversation

@Fengzdadi

@Fengzdadi Fengzdadi commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

No tracking issue. This is the OpenCode counterpart of #2531 (Pi). The same real-host coverage is tracked for Hermes in #2438 and for the gateway in #2466.

Rationale for this change

The OpenCode plugin's own tests stub fetch and OpenCode's plugin API. tests/e2e/test_opencode_plugin_host.py does run opencode run, but against a recording HTTP server, and only when opencode is on PATH, which no CI job provides. Nothing runs OpenCode, the plugin bundle, and a real Server together. A break between OpenCode's hooks, the bundle, and the Server's HTTP contract would reach users first.

What changes are included in this PR?

  • tests/e2e/test_opencode_service_chain.py starts three things:

    • OpenCode: opencode serve (pinned 1.19.5) in an isolated home, with the checked-in bundle where powercontext setup opencode installs it.
      • npm runs offline, so OpenCode's own dependency install fails at once.
      • The bundle resolves @opencode-ai/plugin from the plugin package's development install.
      • Proxy variables are not inherited, and the plugin's request timeouts are raised so that a slow runner cannot silently skip a preparation or capture.
    • Server: an in-process Server (SQLite, bearer auth, no memory schedule).
    • Models: deterministic fixtures for OpenCode's model and the Server's generation model.

    It covers four cases:

    • Recall in a later session: a prompt captured in one session becomes Memory after a flush and is prepared for the next session.
      • The model call carries the prepared content after the PowerContext host-supplied context. label.
      • OpenCode's stored transcript contains neither the label nor the content.
      • A prompt that contains a credential is not captured, and its recall query reads [REDACTED].
      • The credential reaches neither the Server nor the generation model.
    • Resume keeps the Scope: a session without an explicit Scope resolves the workspace binding.
      • It keeps that Scope after OpenCode restarts and the workspace is bound to another Scope.
      • A new session follows the new binding.
    • Recall and capture settings: each setting turns off only its own request. With both off, the plugin sends nothing for the prompt.
    • Memory writes wait for confirmation: pc_remember raises an OpenCode permission request for powercontext with the pattern remember_memory.
      • Nothing is written while the request is pending.
      • A rejected request stores nothing.
      • An approved request stores the memory, and pc_search returns it from the bound Scope.
  • CI, opencode-package job:

    • It installs the platform package opencode-<platform>-<arch>@1.19.5, using the baseline build on x64 without AVX2, and checks the version.
    • It runs the file and refuses to start without the binary, because the cases skip otherwise.
    • It keeps the OpenCode logs of a failed run as an artifact.
    • .github/ci-paths.toml routes the two ZCode acceptance fixture modules the test imports to the opencode suite.
  • tests/e2e/zcode_acceptance/runner.py: the shared serve helper waits up to 45 s for a Server to start, as RestartableServer does, so a loaded host does not fail a case before it runs. A Server whose thread exits still fails at once.

Defect found by these cases

With OpenCode's default configuration, PowerContext writes run without confirmation.

  • OpenCode's built-in agents allow every permission they do not name, so the plugin's request for powercontext is allowed without asking.
  • The docs say OpenCode asks before a durable mutation.

The permission case therefore configures "permission": {"powercontext": "ask"}. The fix is #2534, which changes only the plugin and its docs.

Are there any user-facing changes?

No. Tests and CI only.

How was this change tested?

  • OPENCODE_CLI_BIN=<OpenCode 1.19.5> uv run pytest tests/e2e/test_opencode_service_chain.py on macOS arm64: 4 passed in about 15 s.
    • It also passes with -n 4, and with an unreachable proxy exported in the parent environment.
    • Without OPENCODE_CLI_BIN the cases skip.
  • CI opencode-package job on linux x64 with opencode-linux-x64@1.19.5: 4 passed in about 32 s.
  • Each of 12 mutations of the bundle fails the case meant to catch it:
    • capture ignores credentials
    • recall query not scrubbed
    • prepared context not injected
    • prepared context not labeled
    • prepared context written into the stored prompt
    • Session binding not persisted
    • Session binding not consulted
    • recall setting ignored
    • capture setting ignored
    • remember skips confirmation
    • permission renamed
    • tools ignore the bound Scope
  • uv run pytest tests/test_ci_changes.py tests/test_ci_pipeline.py: 157 passed.
  • uv run python -m pytest -n 0 tests/e2e/test_zcode_service_chain.py, which also uses serve: 4 passed.
  • make check: passed.
  • Self-review: Claude Code /code-review (high), plus an independent review agent.
    • The agent also checked three things:
      • A failed case leaves no opencode serve process behind.
      • No case opens an outbound connection.
      • Each turn makes exactly one model request.
    • Their findings are addressed here, except two points that stay as they are:
      • The Server settings repeat about 15 lines of tests/e2e/test_pi_service_chain.py. Pi wraps the app in a flush-outage middleware and OpenCode does not, so a shared helper would cover only the settings.
      • Only the two fixture modules the test imports are routed to opencode. An import error in the modules they import still fails collection in the tests job's e2e suite, which collects this file and skips it without the binary.
  • Not validated:
    • No live model ran (fixtures only).
    • The TUI and powercontext setup opencode are outside these cases.
    • Only OpenCode 1.19.5 ran, on darwin-arm64 locally and linux x64 in CI. The documented minimum is 1.18.21.
    • The baseline build for x64 without AVX2 has not run, because the CI runner supports AVX2.
    • The Pi service chain and the cross-host continuity cases also use serve. They need the Pi package dependencies or a ZCode binary, so they did not run locally.

AI usage statement

This PR was prepared with Claude Code (Claude Opus 5.5). It traced OpenCode's plugin loading and permission handling, wrote the test and CI wiring, ran the checks, mutations, and reviews, and drafted this description. I reviewed the changes and the results.

Start the pinned OpenCode 1.19.5 with the checked-in plugin bundle against an in-process PowerContext Server and
deterministic model fixtures. The cases cover recall in a later session and the transcript boundary, prompt privacy,
the Session Scope on resume, the recall and capture settings, and the confirmation before a memory write.

The opencode-package job installs the platform binary, runs the cases, and keeps the host logs of a failed run.
Copilot AI balanced review requested due to automatic review settings November 7, 2026 08:21

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@hidb4ai hidb4ai 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 blocking findings at ee1be21. This closes the real OpenCode/plugin/Server CI coverage gap without adding database tables or public interfaces. The approach is reasonable; merge index: 82/100.

Validated the real OpenCode 1.19.5 and SQLite Server flows locally. The recall case passed unchanged on retry after the shared Server fixture hit its startup deadline. Permission coverage requires the explicit ask rule; default-permission behavior remains tracked in #2534.

The separate SeekDB query timeout and macOS Desktop test timeout still leave CI red. This approval does not establish merge readiness.

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@AlexStocks AlexStocks added the 1.5.2 v1.5.2 release tracking label Nov 9, 2026
Copilot AI balanced review requested due to automatic review settings November 10, 2026 15:26

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

The shared `serve` helper failed a case when a Server took more than
15 seconds to finish starting, which a loaded host can exceed. It now
waits 45 seconds, as `RestartableServer` does; a Server whose thread
exits still fails at once.
Copilot AI balanced review requested due to automatic review settings November 10, 2026 23:59

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@hidb4ai hidb4ai 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.

Re-reviewed d5556da. No blocking findings in the updated test/CI diff, and no new database tables or public interfaces. Merge index: 84/100.

The 45-second startup budget is reasonable: a real HTTP probe with a 16-second startup fails on base and succeeds on head, while an explicit startup failure still returns promptly. The real OpenCode 1.19.5/SQLite scenarios pass locally. Permission coverage still requires explicit ask configuration pending #2534.

CI remains blocked by the Handoff report SQL-count assertion (38 statements versus a limit of 37), with downstream jobs including opencode-package skipped. That test and its runtime paths are unchanged from base; its isolated local Python 3.14 replay passes. This approval does not clear the CI gate.

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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

Labels

1.5.2 v1.5.2 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants