Skip to content

Commit cc68afb

Browse files
authored
test(server): lock fixed workspace routing context (#26454)
1 parent 11c33d5 commit cc68afb

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

packages/opencode/test/server/httpapi-instance-context.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Socket from "effect/unstable/socket/Socket"
77
import { mkdir } from "node:fs/promises"
88
import path from "node:path"
99
import { registerAdapter } from "../../src/control-plane/adapters"
10+
import { WorkspaceID } from "../../src/control-plane/schema"
1011
import type { WorkspaceAdapter } from "../../src/control-plane/types"
1112
import { Workspace } from "../../src/control-plane/workspace"
1213
import { 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

Comments
 (0)