fix(opencode): forward remote workspace request bodies (#29458)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { NodeHttpServer, NodeServices } from "@effect/platform-node"
|
||||
import { describe, expect } from "bun:test"
|
||||
import { Context, Effect, Layer, Queue, Ref, Schema } from "effect"
|
||||
import { Context, Effect, Layer, Queue, Ref, Schema, Stream } from "effect"
|
||||
import {
|
||||
FetchHttpClient,
|
||||
HttpClient,
|
||||
@@ -64,6 +64,7 @@ type ProxiedRequest = {
|
||||
url: string
|
||||
method: string
|
||||
headers: Record<string, string>
|
||||
body: string
|
||||
}
|
||||
|
||||
type TestHandler<E, R> = (
|
||||
@@ -181,7 +182,12 @@ const startRemoteWorkspaceHttpServer = <E, R>(
|
||||
// everything else is the request being proxied by the middleware.
|
||||
const sync = syncResponse(request)
|
||||
if (sync) return yield* sync
|
||||
return yield* handler({ url: request.url, method: request.method, headers: request.headers })
|
||||
return yield* handler({
|
||||
url: request.url,
|
||||
method: request.method,
|
||||
headers: request.headers,
|
||||
body: yield* request.text,
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -285,13 +291,18 @@ describe("HttpApi workspace routing middleware", () => {
|
||||
// should make the middleware call HttpApiProxy.http instead.
|
||||
yield* serveProbe
|
||||
|
||||
const body = '{"title":"Remote workspace request"}'
|
||||
const response = yield* HttpClientRequest.patch(`/probe?workspace=${workspace.id}&keep=yes`).pipe(
|
||||
HttpClientRequest.setHeaders({
|
||||
"content-type": "application/json",
|
||||
"x-opencode-directory": "/secret/path",
|
||||
"x-opencode-workspace": "internal",
|
||||
}),
|
||||
HttpClientRequest.bodyStream(
|
||||
Stream.make(new TextEncoder().encode('{"title":"Remote '), new TextEncoder().encode('workspace request"}')),
|
||||
{ contentType: "application/json" },
|
||||
),
|
||||
HttpClient.execute,
|
||||
Effect.timeout("2 seconds"),
|
||||
)
|
||||
|
||||
expect(response.status).toBe(201)
|
||||
@@ -304,6 +315,7 @@ describe("HttpApi workspace routing middleware", () => {
|
||||
expect(forwardedURL?.searchParams.get("keep")).toBe("yes")
|
||||
expect(forwardedURL?.searchParams.get("workspace")).toBeNull()
|
||||
expect(forwarded?.method).toBe("PATCH")
|
||||
expect(forwarded?.body).toBe(body)
|
||||
expect(forwarded?.headers["content-type"]).toBe("application/json")
|
||||
expect(forwarded?.headers["x-target-auth"]).toBe("secret")
|
||||
expect(forwarded?.headers["x-opencode-directory"]).toBeUndefined()
|
||||
|
||||
Reference in New Issue
Block a user