@@ -7,6 +7,7 @@ import * as Socket from "effect/unstable/socket/Socket"
77import { mkdir } from "node:fs/promises"
88import path from "node:path"
99import { registerAdapter } from "../../src/control-plane/adapters"
10+ import { WorkspaceID } from "../../src/control-plane/schema"
1011import type { WorkspaceAdapter } from "../../src/control-plane/types"
1112import { Workspace } from "../../src/control-plane/workspace"
1213import { InstanceRef , WorkspaceRef } from "../../src/effect/instance-ref"
@@ -203,6 +204,40 @@ describe("HttpApi instance context middleware", () => {
203204 } ) ,
204205 )
205206
207+ it . live ( "uses configured workspace id instead of routing to requested workspaces" , ( ) =>
208+ Effect . gen ( function * ( ) {
209+ const originalWorkspaceID = Flag . OPENCODE_WORKSPACE_ID
210+ const fixedWorkspaceID = WorkspaceID . ascending ( )
211+ Flag . OPENCODE_WORKSPACE_ID = fixedWorkspaceID
212+ yield * Effect . addFinalizer ( ( ) =>
213+ Effect . sync ( ( ) => {
214+ Flag . OPENCODE_WORKSPACE_ID = originalWorkspaceID
215+ } ) ,
216+ )
217+
218+ const dir = yield * tmpdirScoped ( { git : true } )
219+ const project = yield * Project . use . fromDirectory ( dir )
220+ const workspaceDir = path . join ( dir , ".workspace-local" )
221+ const workspace = yield * createLocalWorkspace ( {
222+ projectID : project . project . id ,
223+ type : "instance-context-fixed-workspace-ref" ,
224+ directory : workspaceDir ,
225+ } )
226+ yield * serveProbe ( )
227+
228+ const response = yield * HttpClientRequest . get ( `/probe?workspace=${ workspace . id } ` ) . pipe (
229+ HttpClientRequest . setHeader ( "x-opencode-directory" , dir ) ,
230+ HttpClient . execute ,
231+ )
232+
233+ expect ( response . status ) . toBe ( 200 )
234+ expect ( yield * response . json ) . toMatchObject ( {
235+ directory : dir ,
236+ workspaceID : fixedWorkspaceID ,
237+ } )
238+ } ) ,
239+ )
240+
206241 it . live ( "preserves selected workspace id on instance disposal events" , ( ) =>
207242 Effect . gen ( function * ( ) {
208243 const dir = yield * tmpdirScoped ( { git : true } )
0 commit comments