refactor(core): canonicalize pty service (#32182)

This commit is contained in:
Shoubhit Dash
2026-06-14 16:16:39 +05:30
committed by GitHub
parent 7efade2d53
commit f2cf607376
30 changed files with 1134 additions and 506 deletions
@@ -136,6 +136,33 @@ describe("pty HttpApi bridge", () => {
})
})
testPty("hides exited sessions on the legacy surface", async () => {
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
const headers = { "x-opencode-directory": tmp.path }
const created = await app().request(PtyPaths.create, {
method: "POST",
headers: { ...headers, "content-type": "application/json" },
body: JSON.stringify({ command: "/usr/bin/env", args: ["sh", "-c", "exit 0"] }),
})
expect(created.status).toBe(200)
const info = await created.json()
// Exited sessions are retained by core for the canonical surface, but the legacy
// routes preserve pre-retention behavior: exited sessions are invisible here.
const deadline = Date.now() + 5_000
while (Date.now() < deadline) {
const found = await app().request(PtyPaths.get.replace(":ptyID", info.id), { headers })
if (found.status === 404) break
await new Promise((resolve) => setTimeout(resolve, 50))
}
const found = await app().request(PtyPaths.get.replace(":ptyID", info.id), { headers })
expect(found.status).toBe(404)
const list = await app().request(PtyPaths.list, { headers })
expect(list.status).toBe(200)
expect(await list.json()).toEqual([])
})
testPty("disposes PTY sessions with their legacy instance", async () => {
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
const headers = { "x-opencode-directory": tmp.path }