Skip to content

test(server): expand workspace routing fixed-id coverage#26458

Merged
kitlangton merged 1 commit into
devfrom
kit/httpapi-workspace-routing-test-coverage
May 9, 2026
Merged

test(server): expand workspace routing fixed-id coverage#26458
kitlangton merged 1 commit into
devfrom
kit/httpapi-workspace-routing-test-coverage

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Summary

Follow-up to #26454, which locked one invariant of the OPENCODE_WORKSPACE_ID env override on the HttpApi workspace routing middleware. This PR tightens the surrounding coverage of planRequest in packages/opencode/src/server/routes/instance/httpapi/middleware/workspace-routing.ts and removes the small amount of duplication introduced by the original test.

Tests-only — no production code is touched.

Changes

  • New test: MissingWorkspace short-circuit suppression. When OPENCODE_WORKSPACE_ID is set and the request references an unknown ?workspace=... id, planRequest must skip the RequestPlan.MissingWorkspace branch and fall through to Local with the configured id (covers planRequest line 145's !envWorkspaceID guard — without it the route would 500).
  • New test: control-plane interaction. When env is set and the path matches isLocalWorkspaceRoute (e.g. GET /session), the route must stay Local with the configured id rather than diverting to the requested workspace's local directory (covers the shouldStayOnControlPlane interaction with the env-set Local fallthrough at line 153).
  • Title tightening. Existing test renamed from "to requested workspaces" → "to the requested workspace" (singular).
  • Helper extraction. The save-then-restore-via-finalizer pattern for Flag.OPENCODE_WORKSPACE_ID is extracted into test/fixture/flag.ts as withFixedWorkspaceID(id) and adopted by all three sites in httpapi-instance-context.test.ts. The original try/finally semantics are preserved via Effect.addFinalizer on 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 fail
  • cd packages/opencode && bun run typecheck

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").
@kitlangton kitlangton merged commit cbdb2d9 into dev May 9, 2026
12 checks passed
@kitlangton kitlangton deleted the kit/httpapi-workspace-routing-test-coverage branch May 9, 2026 04:00
katosun2 pushed a commit to katosun2/opencode that referenced this pull request May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant