Skip to content

Commit 075f876

Browse files
authored
fix(httpapi): re-land workspace create payload accepts missing extra (#25412)
1 parent a849812 commit 075f876

3 files changed

Lines changed: 56 additions & 3 deletions

File tree

packages/opencode/src/server/routes/instance/httpapi/groups/workspace.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { WorkspaceRoutingMiddleware } from "../middleware/workspace-routing"
99
import { described } from "./metadata"
1010

1111
const root = "/experimental/workspace"
12-
export const CreatePayload = Schema.Struct(Struct.omit(Workspace.CreateInput.fields, ["projectID"]))
12+
export const CreatePayload = Schema.Struct({
13+
...Struct.omit(Workspace.CreateInput.fields, ["projectID", "extra"]),
14+
extra: Schema.optional(Workspace.CreateInput.fields.extra),
15+
})
1316
export const SessionRestorePayload = Schema.Struct(Struct.omit(Workspace.SessionRestoreInput.fields, ["workspaceID"]))
1417
export const SessionRestoreResponse = Schema.Struct({
1518
total: NonNegativeInt,

packages/opencode/src/server/routes/instance/httpapi/handlers/workspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const workspaceHandlers = HttpApiBuilder.group(InstanceHttpApi, "workspac
2424
return yield* workspace
2525
.create({
2626
...ctx.payload,
27+
extra: ctx.payload.extra ?? null,
2728
projectID: instance.project.id,
2829
})
2930
.pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))

packages/opencode/test/server/httpapi-workspace.test.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const it = testEffect(
2727
Layer.mergeAll(NodeServices.layer, Project.defaultLayer, Session.defaultLayer, Workspace.defaultLayer),
2828
)
2929

30-
function request(path: string, directory: string, init: RequestInit = {}) {
30+
function request(path: string, directory: string, init: RequestInit = {}, httpApi = true) {
3131
return Effect.promise(() => {
32-
Flag.OPENCODE_EXPERIMENTAL_HTTPAPI = true
32+
Flag.OPENCODE_EXPERIMENTAL_HTTPAPI = httpApi
3333
const headers = new Headers(init.headers)
3434
headers.set("x-opencode-directory", directory)
3535
return Promise.resolve(Server.Default().app.request(path, { ...init, headers }))
@@ -195,6 +195,55 @@ describe("workspace HttpApi", () => {
195195
}),
196196
)
197197

198+
it.live("creates workspace with the TUI payload shape", () =>
199+
Effect.gen(function* () {
200+
Flag.OPENCODE_EXPERIMENTAL_WORKSPACES = true
201+
const dir = yield* tmpdirScoped({ git: true })
202+
const project = yield* Project.use.fromDirectory(dir)
203+
registerAdapter(project.project.id, "local-test", localAdapter(path.join(dir, ".workspace")))
204+
205+
const created = yield* request(WorkspacePaths.list, dir, {
206+
method: "POST",
207+
headers: { "content-type": "application/json" },
208+
body: JSON.stringify({ type: "local-test", branch: null }),
209+
})
210+
211+
expect(created.status).toBe(200)
212+
expect((yield* Effect.promise(() => created.json())) as Workspace.Info).toMatchObject({
213+
type: "local-test",
214+
name: "local-test",
215+
extra: null,
216+
})
217+
}),
218+
)
219+
220+
it.live("documents legacy Hono accepting the TUI payload shape", () =>
221+
Effect.gen(function* () {
222+
Flag.OPENCODE_EXPERIMENTAL_WORKSPACES = true
223+
const dir = yield* tmpdirScoped({ git: true })
224+
const project = yield* Project.use.fromDirectory(dir)
225+
registerAdapter(project.project.id, "local-test", localAdapter(path.join(dir, ".workspace")))
226+
227+
const created = yield* request(
228+
WorkspacePaths.list,
229+
dir,
230+
{
231+
method: "POST",
232+
headers: { "content-type": "application/json" },
233+
body: JSON.stringify({ type: "local-test", branch: null }),
234+
},
235+
false,
236+
)
237+
238+
expect(created.status).toBe(200)
239+
expect((yield* Effect.promise(() => created.json())) as Workspace.Info).toMatchObject({
240+
type: "local-test",
241+
name: "local-test",
242+
extra: null,
243+
})
244+
}),
245+
)
246+
198247
it.live("routes local workspace requests through the workspace target directory", () =>
199248
Effect.gen(function* () {
200249
Flag.OPENCODE_EXPERIMENTAL_WORKSPACES = true

0 commit comments

Comments
 (0)