mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-25 05:44:37 +00:00
feat(httpapi): bridge remaining session routes (#24510)
This commit is contained in:
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"
|
||||
import type { UpgradeWebSocket } from "hono/ws"
|
||||
import { Effect } from "effect"
|
||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||
import { PermissionID } from "../../src/permission/schema"
|
||||
import { ModelID, ProviderID } from "../../src/provider/schema"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { InstanceRoutes } from "../../src/server/routes/instance"
|
||||
@@ -118,9 +119,25 @@ describe("session HttpApi", () => {
|
||||
headers,
|
||||
})
|
||||
const messagePage = await json<MessageV2.WithParts[]>(messages)
|
||||
expect(messages.headers.get("x-next-cursor")).toBeTruthy()
|
||||
const nextCursor = messages.headers.get("x-next-cursor")
|
||||
expect(nextCursor).toBeTruthy()
|
||||
expect(messagePage[0]?.parts[0]).toMatchObject({ type: "text" })
|
||||
|
||||
expect(
|
||||
(
|
||||
await app().request(`${pathFor(SessionPaths.messages, { sessionID: parent.id })}?before=${nextCursor}`, {
|
||||
headers,
|
||||
})
|
||||
).status,
|
||||
).toBe(400)
|
||||
expect(
|
||||
(
|
||||
await app().request(`${pathFor(SessionPaths.messages, { sessionID: parent.id })}?limit=1&before=invalid`, {
|
||||
headers,
|
||||
})
|
||||
).status,
|
||||
).toBe(400)
|
||||
|
||||
expect(
|
||||
await json<MessageV2.WithParts>(
|
||||
await app().request(pathFor(SessionPaths.message, { sessionID: parent.id, messageID: message.info.id }), {
|
||||
@@ -219,4 +236,45 @@ describe("session HttpApi", () => {
|
||||
),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
test("serves remaining non-LLM session mutation routes through Hono bridge", async () => {
|
||||
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
|
||||
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
||||
const session = await createSession(tmp.path, { title: "remaining" })
|
||||
|
||||
expect(
|
||||
await json<Session.Info>(
|
||||
await app().request(pathFor(SessionPaths.revert, { sessionID: session.id }), {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({ messageID: MessageID.ascending() }),
|
||||
}),
|
||||
),
|
||||
).toMatchObject({ id: session.id })
|
||||
|
||||
expect(
|
||||
await json<Session.Info>(
|
||||
await app().request(pathFor(SessionPaths.unrevert, { sessionID: session.id }), {
|
||||
method: "POST",
|
||||
headers,
|
||||
}),
|
||||
),
|
||||
).toMatchObject({ id: session.id })
|
||||
|
||||
expect(
|
||||
await json<boolean>(
|
||||
await app().request(
|
||||
pathFor(SessionPaths.permissions, {
|
||||
sessionID: session.id,
|
||||
permissionID: String(PermissionID.ascending()),
|
||||
}),
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({ response: "once" }),
|
||||
},
|
||||
),
|
||||
),
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user