fix(httpapi): return pty error bodies (#28838)

This commit is contained in:
Shoubhit Dash
2026-05-22 21:00:20 +05:30
committed by GitHub
parent d92b8d8009
commit 5cf597d583
7 changed files with 119 additions and 14 deletions

View File

@@ -112,6 +112,31 @@ describe("pty HttpApi bridge", () => {
const missing = await app().request(PtyPaths.get.replace(":ptyID", info.id), { headers })
expect(missing.status).toBe(404)
expect(await missing.json()).toEqual({
_tag: "PtyNotFoundError",
ptyID: info.id,
message: `PTY session not found: ${info.id}`,
})
const missingUpdate = await app().request(PtyPaths.update.replace(":ptyID", info.id), {
method: "PUT",
headers: { ...headers, "content-type": "application/json" },
body: JSON.stringify({ title: "missing" }),
})
expect(missingUpdate.status).toBe(404)
expect(await missingUpdate.json()).toEqual({
_tag: "PtyNotFoundError",
ptyID: info.id,
message: `PTY session not found: ${info.id}`,
})
const missingRemove = await app().request(PtyPaths.remove.replace(":ptyID", info.id), { method: "DELETE", headers })
expect(missingRemove.status).toBe(404)
expect(await missingRemove.json()).toEqual({
_tag: "PtyNotFoundError",
ptyID: info.id,
message: `PTY session not found: ${info.id}`,
})
})
test("returns 404 for missing PTY websocket before upgrade", async () => {
@@ -121,6 +146,37 @@ describe("pty HttpApi bridge", () => {
})
expect(response.status).toBe(404)
})
test("returns typed errors for PTY connect token failures", async () => {
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
const headers = { "x-opencode-directory": tmp.path }
const missingID = String(PtyID.ascending())
const forbidden = await app().request(PtyPaths.connectToken.replace(":ptyID", missingID), {
method: "POST",
headers,
})
expect(forbidden.status).toBe(403)
expect(await forbidden.json()).toEqual({
_tag: "PtyForbiddenError",
message: "Invalid PTY connect token request",
})
const missing = await app().request(PtyPaths.connectToken.replace(":ptyID", missingID), {
method: "POST",
headers: {
...headers,
"x-opencode-ticket": "1",
},
})
expect(missing.status).toBe(404)
expect(await missing.json()).toEqual({
_tag: "PtyNotFoundError",
ptyID: missingID,
message: `PTY session not found: ${missingID}`,
})
})
;(process.platform === "win32" ? effectIt.live.skip : effectIt.live)(
"serves PTY websocket output and input through Effect routes",
() =>