Parcourir la source

fix(worktree): accept missing create payload (#27582)

Kit Langton il y a 3 mois
Parent
commit
d353a6bc24

+ 2 - 1
packages/opencode/src/server/routes/instance/httpapi/groups/experimental.ts

@@ -166,8 +166,9 @@ export const ExperimentalApi = HttpApi.make("experimental")
           }),
           }),
         ),
         ),
         HttpApiEndpoint.post("worktreeCreate", ExperimentalPaths.worktree, {
         HttpApiEndpoint.post("worktreeCreate", ExperimentalPaths.worktree, {
+          disableCodecs: true,
           query: WorkspaceRoutingQuery,
           query: WorkspaceRoutingQuery,
-          payload: Schema.optional(Worktree.CreateInput),
+          payload: Schema.UndefinedOr(Worktree.CreateInput),
           success: described(Worktree.Info, "Worktree created"),
           success: described(Worktree.Info, "Worktree created"),
           error: WorktreeApiError,
           error: WorktreeApiError,
         }).annotateMerge(
         }).annotateMerge(

+ 44 - 0
packages/opencode/test/server/worktree-endpoint-repro.test.ts

@@ -129,6 +129,10 @@ function createWorktreeScoped(input: {
         input.timeoutLabel,
         input.timeoutLabel,
         input.timeoutMs,
         input.timeoutMs,
       )
       )
+      if (response.status !== 200) {
+        const message = yield* Effect.promise(() => response.text())
+        throw new Error(`${input.timeoutLabel} failed: ${response.status} ${message}`)
+      }
       expect(response.status).toBe(200)
       expect(response.status).toBe(200)
       const body = yield* json<CreatedWorktree>(response)
       const body = yield* json<CreatedWorktree>(response)
       return { directory: body.directory, body, ready: waitReady(body.directory) } satisfies ScopedWorktree
       return { directory: body.directory, body, ready: waitReady(body.directory) } satisfies ScopedWorktree
@@ -186,6 +190,46 @@ describe("worktree endpoint reproduction", () => {
     { git: true },
     { git: true },
   )
   )
 
 
+  worktreeTest(
+    "direct HttpApi worktree create accepts missing body",
+    () =>
+      Effect.gen(function* () {
+        const test = yield* TestInstance
+        const server = yield* serverScoped()
+
+        const response = yield* createWorktreeScoped({
+          server,
+          directory: test.directory,
+          path: `${ExperimentalPaths.worktree}?directory=${encodeURIComponent(test.directory)}`,
+          init: { method: "POST", headers: { "content-type": "application/json" } },
+          timeoutLabel: "direct worktree create without body",
+        })
+
+        expect(response).toMatchObject({ directory: expect.any(String) })
+      }),
+    { git: true },
+  )
+
+  worktreeTest(
+    "direct HttpApi worktree create accepts missing content type and body",
+    () =>
+      Effect.gen(function* () {
+        const test = yield* TestInstance
+        const server = yield* serverScoped()
+
+        const response = yield* createWorktreeScoped({
+          server,
+          directory: test.directory,
+          path: `${ExperimentalPaths.worktree}?directory=${encodeURIComponent(test.directory)}`,
+          init: { method: "POST" },
+          timeoutLabel: "direct worktree create without content type or body",
+        })
+
+        expect(response).toMatchObject({ directory: expect.any(String) })
+      }),
+    { git: true },
+  )
+
   worktreeTest(
   worktreeTest(
     "workspace worktree create does not hang",
     "workspace worktree create does not hang",
     () =>
     () =>