|
1 | 1 | import { NodeHttpServer, NodeServices } from "@effect/platform-node" |
2 | 2 | import { Flag } from "@opencode-ai/core/flag/flag" |
3 | 3 | import { describe, expect } from "bun:test" |
4 | | -import { Config, Effect, FileSystem, Layer, Path } from "effect" |
| 4 | +import { Config, Context, Effect, FileSystem, Layer, Path } from "effect" |
5 | 5 | import { HttpClient, HttpClientRequest, HttpRouter, HttpServer } from "effect/unstable/http" |
6 | 6 | import * as Socket from "effect/unstable/socket/Socket" |
7 | 7 | import { WorkspaceID } from "../../src/control-plane/schema" |
@@ -53,6 +53,7 @@ const httpApiServerLayer = servedRoutes.pipe( |
53 | 53 | ) |
54 | 54 |
|
55 | 55 | const it = testEffect(Layer.mergeAll(testStateLayer, httpApiServerLayer)) |
| 56 | +const handlerContext = Context.empty() as Context.Context<unknown> |
56 | 57 |
|
57 | 58 | const directoryHeader = (dir: string) => HttpClientRequest.setHeader("x-opencode-directory", dir) |
58 | 59 |
|
@@ -121,6 +122,34 @@ describe("instance HttpApi", () => { |
121 | 122 | }), |
122 | 123 | ) |
123 | 124 |
|
| 125 | + it.live("rejects malformed permission and question request ids", () => |
| 126 | + Effect.gen(function* () { |
| 127 | + const dir = yield* tmpdirScoped({ git: true }) |
| 128 | + const request = (path: string, init?: RequestInit) => |
| 129 | + Effect.promise(() => |
| 130 | + ExperimentalHttpApiServer.webHandler().handler( |
| 131 | + new Request(`http://localhost${path}`, { |
| 132 | + ...init, |
| 133 | + headers: { "x-opencode-directory": dir, "content-type": "application/json", ...init?.headers }, |
| 134 | + }), |
| 135 | + handlerContext, |
| 136 | + ), |
| 137 | + ) |
| 138 | + const [permission, questionReply, questionReject] = yield* Effect.all( |
| 139 | + [ |
| 140 | + request("/permission/invalid-permission-id/reply", { method: "POST", body: JSON.stringify({ reply: "once" }) }), |
| 141 | + request("/question/invalid-question-id/reply", { method: "POST", body: JSON.stringify({ answers: [["Yes"]] }) }), |
| 142 | + request("/question/invalid-question-id/reject", { method: "POST" }), |
| 143 | + ], |
| 144 | + { concurrency: "unbounded" }, |
| 145 | + ) |
| 146 | + |
| 147 | + expect(permission.status).toBe(400) |
| 148 | + expect(questionReply.status).toBe(400) |
| 149 | + expect(questionReject.status).toBe(400) |
| 150 | + }), |
| 151 | + ) |
| 152 | + |
124 | 153 | it.live("serves path and VCS read endpoints", () => |
125 | 154 | Effect.gen(function* () { |
126 | 155 | const dir = yield* tmpdirScoped({ git: true }) |
|
0 commit comments