test(server): apply simplify pass — drop redundant Effect.gen, prose comments, and assertion casts

This commit is contained in:
Kit Langton
2026-05-09 23:07:35 -04:00
parent 62ff152642
commit ff52ec2272
2 changed files with 17 additions and 41 deletions
@@ -5,38 +5,21 @@ import * as Log from "@opencode-ai/core/util/log"
const log = Log.create({ service: "server" })
// Effect's default Respondable for HttpApiSchemaError returns 400 with an
// empty body. That gives the renderer / SDK / curl no information about
// what was actually rejected (Body field, Query param, etc.). PR #26457
// previously tried `{data:{}, errors:[], success:false}` and broke a
// plugin (#26546) — root cause was the SDK throwing raw POJOs instead
// of Errors, which has since been fixed by `wrapClientError`.
//
// We use the same shape every other 4xx/5xx in the API already uses —
// NamedError serialization (`{name, data}`). The SDK's `wrapClientError`
// extracts `.data.message` automatically, so plugins that already handle
// 404 NotFoundError bodies handle this with no changes.
// Default Respondable returns an empty 400 body. Match the NamedError shape
// used by other 4xx/5xx so the SDK's `wrapClientError` extracts `.data.message`.
export class SchemaErrorMiddleware extends HttpApiMiddleware.Service<SchemaErrorMiddleware>()(
"@opencode/HttpApiSchemaError",
) {}
export const schemaErrorLayer = HttpApiMiddleware.layerSchemaErrorTransform(
SchemaErrorMiddleware,
(error) =>
Effect.gen(function* () {
log.warn("schema rejection", {
kind: error.kind,
reason: error.cause.message,
})
return HttpServerResponse.jsonUnsafe(
{
name: "BadRequest",
data: {
message: error.cause.message,
kind: error.kind,
},
},
(error) => {
log.warn("schema rejection", { kind: error.kind, reason: error.cause.message })
return Effect.succeed(
HttpServerResponse.jsonUnsafe(
{ name: "BadRequest", data: { message: error.cause.message, kind: error.kind } },
{ status: 400 },
)
}),
),
)
},
)