test(server): expand workspace routing fixed-id coverage#26458
Merged
Conversation
Locks two further invariants of `planRequest` when `OPENCODE_WORKSPACE_ID` is set: (a) an unknown `?workspace=...` id falls through to Local instead of short-circuiting to a 500 MissingWorkspace; (b) control-plane routes still resolve to Local with the configured workspace id rather than diverting to the requested workspace's directory. Extracts the save-and-restore-via-finalizer pattern for the flag into `test/fixture/flag.ts` (`withFixedWorkspaceID`) and adopts it across the three call sites in `httpapi-instance-context.test.ts`. Also tightens the existing test title (singular "the requested workspace").
katosun2
pushed a commit
to katosun2/opencode
that referenced
this pull request
May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #26454, which locked one invariant of the
OPENCODE_WORKSPACE_IDenv override on the HttpApi workspace routing middleware. This PR tightens the surrounding coverage ofplanRequestinpackages/opencode/src/server/routes/instance/httpapi/middleware/workspace-routing.tsand removes the small amount of duplication introduced by the original test.Tests-only — no production code is touched.
Changes
OPENCODE_WORKSPACE_IDis set and the request references an unknown?workspace=...id,planRequestmust skip theRequestPlan.MissingWorkspacebranch and fall through toLocalwith the configured id (coversplanRequestline 145's!envWorkspaceIDguard — without it the route would 500).isLocalWorkspaceRoute(e.g.GET /session), the route must stayLocalwith the configured id rather than diverting to the requested workspace's local directory (covers theshouldStayOnControlPlaneinteraction with the env-set Local fallthrough at line 153).Flag.OPENCODE_WORKSPACE_IDis extracted intotest/fixture/flag.tsaswithFixedWorkspaceID(id)and adopted by all three sites inhttpapi-instance-context.test.ts. The original try/finally semantics are preserved viaEffect.addFinalizeron the test's scope.Test plan
cd packages/opencode && bun run test test/server/httpapi-instance-context.test.ts test/server/httpapi-instance.test.ts— 10 pass, 0 failcd packages/opencode && bun run typecheck