mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-17 12:42:17 +00:00
Some checks failed
deploy / deploy (push) Waiting to run
generate / generate (push) Waiting to run
nix-eval / nix-eval (push) Waiting to run
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Waiting to run
nix-hashes / compute-hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Waiting to run
nix-hashes / compute-hash (macos-15-intel, x86_64-darwin) (push) Waiting to run
nix-hashes / compute-hash (macos-latest, aarch64-darwin) (push) Waiting to run
nix-hashes / update-hashes (push) Blocked by required conditions
publish / version (push) Waiting to run
publish / build-cli (push) Blocked by required conditions
publish / sign-cli-windows (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=arm64 host:macos-26 platform_flag:--mac --arm64 target:aarch64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=x64 host:macos-26-intel platform_flag:--mac --x64 target:x86_64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:x86_64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404-arm platform_flag:--linux --arm64 target:aarch64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[host:blacksmith-4vcpu-windows-2025 platform_flag:--win target:x86_64-pc-windows-msvc]) (push) Blocked by required conditions
publish / build-electron (map[host:windows-2025 platform_flag:--win --arm64 target:aarch64-pc-windows-msvc]) (push) Blocked by required conditions
publish / publish (push) Blocked by required conditions
storybook / storybook build (push) Waiting to run
test / unit (linux) (push) Waiting to run
test / unit (windows) (push) Waiting to run
test / e2e (linux) (push) Waiting to run
test / e2e (windows) (push) Waiting to run
typecheck / typecheck (push) Waiting to run
docs-locale-sync / sync-locales (push) Has been cancelled
71 lines
2.6 KiB
TypeScript
71 lines
2.6 KiB
TypeScript
import { NodeHttpServer, NodeServices } from "@effect/platform-node"
|
|
import { NamedError } from "@opencode-ai/core/util/error"
|
|
import { describe, expect } from "bun:test"
|
|
import { Effect, Layer } from "effect"
|
|
import { HttpClient, HttpClientRequest, HttpRouter } from "effect/unstable/http"
|
|
import { errorLayer } from "../../src/server/routes/instance/httpapi/middleware/error"
|
|
import { NotFoundError } from "../../src/storage/storage"
|
|
import { testEffect } from "../lib/effect"
|
|
|
|
const it = testEffect(Layer.mergeAll(NodeHttpServer.layerTest, NodeServices.layer))
|
|
|
|
describe("HttpApi error middleware", () => {
|
|
it.live("returns a safe body for unknown 500 defects", () =>
|
|
Effect.gen(function* () {
|
|
yield* HttpRouter.add("GET", "/boom", Effect.die(new Error("secret stack marker"))).pipe(
|
|
Layer.provide(errorLayer),
|
|
HttpRouter.serve,
|
|
Layer.build,
|
|
)
|
|
|
|
const response = yield* HttpClientRequest.get("/boom").pipe(HttpClient.execute)
|
|
const body = yield* response.json
|
|
|
|
expect(response.status).toBe(500)
|
|
expect(body).toEqual({
|
|
name: "UnknownError",
|
|
data: { message: "Unexpected server error. Check server logs for details." },
|
|
})
|
|
expect(JSON.stringify(body)).not.toContain("secret stack marker")
|
|
}),
|
|
)
|
|
|
|
it.live("returns a safe body for named defects", () =>
|
|
Effect.gen(function* () {
|
|
yield* HttpRouter.add(
|
|
"GET",
|
|
"/named",
|
|
Effect.die(new NamedError.Unknown({ message: "secret named marker" })),
|
|
).pipe(Layer.provide(errorLayer), HttpRouter.serve, Layer.build)
|
|
|
|
const response = yield* HttpClientRequest.get("/named").pipe(HttpClient.execute)
|
|
const body = yield* response.json
|
|
|
|
expect(response.status).toBe(500)
|
|
expect(body).toEqual({
|
|
name: "UnknownError",
|
|
data: { message: "Unexpected server error. Check server logs for details." },
|
|
})
|
|
expect(JSON.stringify(body)).not.toContain("secret named marker")
|
|
}),
|
|
)
|
|
|
|
it.live("does not map storage not-found defects to 404", () =>
|
|
Effect.gen(function* () {
|
|
yield* HttpRouter.add(
|
|
"GET",
|
|
"/missing",
|
|
Effect.die(new NotFoundError({ message: "Resource not found: secret" })),
|
|
).pipe(Layer.provide(errorLayer), HttpRouter.serve, Layer.build)
|
|
|
|
const response = yield* HttpClientRequest.get("/missing").pipe(HttpClient.execute)
|
|
const body = yield* response.json
|
|
|
|
expect(response.status).toBe(500)
|
|
expect(body).toEqual({
|
|
name: "UnknownError",
|
|
data: { message: "Unexpected server error. Check server logs for details." },
|
|
})
|
|
}),
|
|
)
|
|
})
|