mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-01 05:59:50 +00:00
fix(httpapi): preserve optional session fields (#24671)
This commit is contained in:
parent
dfc0075f90
commit
576efed196
2 changed files with 257 additions and 227 deletions
|
|
@ -3,6 +3,7 @@ import { AppRuntime } from "@/effect/app-runtime"
|
||||||
import { Agent } from "@/agent/agent"
|
import { Agent } from "@/agent/agent"
|
||||||
import { Bus } from "@/bus"
|
import { Bus } from "@/bus"
|
||||||
import { Command } from "@/command"
|
import { Command } from "@/command"
|
||||||
|
import { WorkspaceID } from "@/control-plane/schema"
|
||||||
import { Permission } from "@/permission"
|
import { Permission } from "@/permission"
|
||||||
import { PermissionID } from "@/permission/schema"
|
import { PermissionID } from "@/permission/schema"
|
||||||
import { Instance } from "@/project/instance"
|
import { Instance } from "@/project/instance"
|
||||||
|
|
@ -21,7 +22,7 @@ import { MessageID, PartID, SessionID } from "@/session/schema"
|
||||||
import { Snapshot } from "@/snapshot"
|
import { Snapshot } from "@/snapshot"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { NamedError } from "@opencode-ai/core/util/error"
|
import { NamedError } from "@opencode-ai/core/util/error"
|
||||||
import { Effect, Layer, Schema, Struct } from "effect"
|
import { Effect, Layer, Option, Schema, SchemaGetter, Struct } from "effect"
|
||||||
import * as Stream from "effect/Stream"
|
import * as Stream from "effect/Stream"
|
||||||
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http"
|
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http"
|
||||||
import {
|
import {
|
||||||
|
|
@ -44,6 +45,19 @@ const ListQuery = Schema.Struct({
|
||||||
search: Schema.optional(Schema.String),
|
search: Schema.optional(Schema.String),
|
||||||
limit: Schema.optional(Schema.NumberFromString),
|
limit: Schema.optional(Schema.NumberFromString),
|
||||||
})
|
})
|
||||||
|
const omitUndefined = <S extends Schema.Top>(schema: S) =>
|
||||||
|
Schema.optionalKey(schema).pipe(
|
||||||
|
Schema.decodeTo(Schema.optional(schema), {
|
||||||
|
decode: SchemaGetter.passthrough({ strict: false }),
|
||||||
|
encode: SchemaGetter.transformOptional(Option.filter((value) => value !== undefined)),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
const SessionInfoResponse = Session.Info.mapFields(
|
||||||
|
Struct.evolve({
|
||||||
|
workspaceID: () => omitUndefined(WorkspaceID),
|
||||||
|
parentID: () => omitUndefined(SessionID),
|
||||||
|
}),
|
||||||
|
)
|
||||||
const DiffQuery = Schema.Struct(Struct.omit(SessionSummary.DiffInput.fields, ["sessionID"]))
|
const DiffQuery = Schema.Struct(Struct.omit(SessionSummary.DiffInput.fields, ["sessionID"]))
|
||||||
const MessagesQuery = Schema.Struct({
|
const MessagesQuery = Schema.Struct({
|
||||||
limit: Schema.optional(Schema.NumberFromString.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))),
|
limit: Schema.optional(Schema.NumberFromString.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))),
|
||||||
|
|
@ -123,7 +137,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
.add(
|
.add(
|
||||||
HttpApiEndpoint.get("list", SessionPaths.list, {
|
HttpApiEndpoint.get("list", SessionPaths.list, {
|
||||||
query: ListQuery,
|
query: ListQuery,
|
||||||
success: Schema.Array(Session.Info),
|
success: Schema.Array(SessionInfoResponse),
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.list",
|
identifier: "session.list",
|
||||||
|
|
@ -142,7 +156,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
),
|
),
|
||||||
HttpApiEndpoint.get("get", SessionPaths.get, {
|
HttpApiEndpoint.get("get", SessionPaths.get, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
success: Session.Info,
|
success: SessionInfoResponse,
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.get",
|
identifier: "session.get",
|
||||||
|
|
@ -152,7 +166,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
),
|
),
|
||||||
HttpApiEndpoint.get("children", SessionPaths.children, {
|
HttpApiEndpoint.get("children", SessionPaths.children, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
success: Schema.Array(Session.Info),
|
success: Schema.Array(SessionInfoResponse),
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.children",
|
identifier: "session.children",
|
||||||
|
|
@ -204,7 +218,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
),
|
),
|
||||||
HttpApiEndpoint.post("create", SessionPaths.create, {
|
HttpApiEndpoint.post("create", SessionPaths.create, {
|
||||||
payload: [HttpApiSchema.NoContent, Session.CreateInput],
|
payload: [HttpApiSchema.NoContent, Session.CreateInput],
|
||||||
success: Session.Info,
|
success: SessionInfoResponse,
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.create",
|
identifier: "session.create",
|
||||||
|
|
@ -225,7 +239,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
HttpApiEndpoint.patch("update", SessionPaths.update, {
|
HttpApiEndpoint.patch("update", SessionPaths.update, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
payload: UpdatePayload,
|
payload: UpdatePayload,
|
||||||
success: Session.Info,
|
success: SessionInfoResponse,
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.update",
|
identifier: "session.update",
|
||||||
|
|
@ -236,7 +250,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
HttpApiEndpoint.post("fork", SessionPaths.fork, {
|
HttpApiEndpoint.post("fork", SessionPaths.fork, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
payload: ForkPayload,
|
payload: ForkPayload,
|
||||||
success: Session.Info,
|
success: SessionInfoResponse,
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.fork",
|
identifier: "session.fork",
|
||||||
|
|
@ -268,7 +282,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
),
|
),
|
||||||
HttpApiEndpoint.post("share", SessionPaths.share, {
|
HttpApiEndpoint.post("share", SessionPaths.share, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
success: Session.Info,
|
success: SessionInfoResponse,
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.share",
|
identifier: "session.share",
|
||||||
|
|
@ -278,7 +292,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
),
|
),
|
||||||
HttpApiEndpoint.delete("unshare", SessionPaths.share, {
|
HttpApiEndpoint.delete("unshare", SessionPaths.share, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
success: Session.Info,
|
success: SessionInfoResponse,
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.unshare",
|
identifier: "session.unshare",
|
||||||
|
|
@ -345,7 +359,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
HttpApiEndpoint.post("revert", SessionPaths.revert, {
|
HttpApiEndpoint.post("revert", SessionPaths.revert, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
payload: RevertPayload,
|
payload: RevertPayload,
|
||||||
success: Session.Info,
|
success: SessionInfoResponse,
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.revert",
|
identifier: "session.revert",
|
||||||
|
|
@ -356,7 +370,7 @@ export const SessionApi = HttpApi.make("session")
|
||||||
),
|
),
|
||||||
HttpApiEndpoint.post("unrevert", SessionPaths.unrevert, {
|
HttpApiEndpoint.post("unrevert", SessionPaths.unrevert, {
|
||||||
params: { sessionID: SessionID },
|
params: { sessionID: SessionID },
|
||||||
success: Session.Info,
|
success: SessionInfoResponse,
|
||||||
}).annotateMerge(
|
}).annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
identifier: "session.unrevert",
|
identifier: "session.unrevert",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { afterEach, describe, expect, test } from "bun:test"
|
import { afterEach, describe, expect } from "bun:test"
|
||||||
import type { UpgradeWebSocket } from "hono/ws"
|
import type { UpgradeWebSocket } from "hono/ws"
|
||||||
import { Effect } from "effect"
|
import { Effect } from "effect"
|
||||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||||
|
|
@ -13,6 +13,7 @@ import { MessageV2 } from "../../src/session/message-v2"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { resetDatabase } from "../fixture/db"
|
import { resetDatabase } from "../fixture/db"
|
||||||
import { tmpdir } from "../fixture/fixture"
|
import { tmpdir } from "../fixture/fixture"
|
||||||
|
import { it } from "../lib/effect"
|
||||||
|
|
||||||
void Log.init({ print: false })
|
void Log.init({ print: false })
|
||||||
|
|
||||||
|
|
@ -32,17 +33,22 @@ function pathFor(path: string, params: Record<string, string>) {
|
||||||
return Object.entries(params).reduce((result, [key, value]) => result.replace(`:${key}`, value), path)
|
return Object.entries(params).reduce((result, [key, value]) => result.replace(`:${key}`, value), path)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createSession(directory: string, input?: Session.CreateInput) {
|
function createSession(directory: string, input?: Session.CreateInput) {
|
||||||
return Instance.provide({
|
return Effect.promise(
|
||||||
|
async () =>
|
||||||
|
await Instance.provide({
|
||||||
directory,
|
directory,
|
||||||
fn: async () => runSession(Session.Service.use((svc) => svc.create(input))),
|
fn: () => runSession(Session.Service.use((svc) => svc.create(input))),
|
||||||
})
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createTextMessage(directory: string, sessionID: SessionID, text: string) {
|
function createTextMessage(directory: string, sessionID: SessionID, text: string) {
|
||||||
return Instance.provide({
|
return Effect.promise(
|
||||||
|
async () =>
|
||||||
|
await Instance.provide({
|
||||||
directory,
|
directory,
|
||||||
fn: async () =>
|
fn: () =>
|
||||||
runSession(
|
runSession(
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const svc = yield* Session.Service
|
const svc = yield* Session.Service
|
||||||
|
|
@ -64,12 +70,33 @@ async function createTextMessage(directory: string, sessionID: SessionID, text:
|
||||||
return { info, part }
|
return { info, part }
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function request(path: string, init?: RequestInit) {
|
||||||
|
return Effect.promise(async () => app().request(path, init))
|
||||||
|
}
|
||||||
|
|
||||||
|
function json<T>(response: Response) {
|
||||||
|
return Effect.promise(async () => {
|
||||||
|
if (response.status !== 200) throw new Error(await response.text())
|
||||||
|
return (await response.json()) as T
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function json<T>(response: Response) {
|
function requestJson<T>(path: string, init?: RequestInit) {
|
||||||
if (response.status !== 200) throw new Error(await response.text())
|
return request(path, init).pipe(Effect.flatMap(json<T>))
|
||||||
return (await response.json()) as T
|
}
|
||||||
|
|
||||||
|
function withTmp<A, E, R>(
|
||||||
|
options: Parameters<typeof tmpdir>[0],
|
||||||
|
fn: (tmp: Awaited<ReturnType<typeof tmpdir>>) => Effect.Effect<A, E, R>,
|
||||||
|
) {
|
||||||
|
return Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir(options)),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
).pipe(Effect.flatMap(fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
|
@ -79,135 +106,129 @@ afterEach(async () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("session HttpApi", () => {
|
describe("session HttpApi", () => {
|
||||||
test("serves read routes through Hono bridge", async () => {
|
it.live(
|
||||||
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
|
"serves read routes through Hono bridge",
|
||||||
|
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
||||||
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path }
|
const headers = { "x-opencode-directory": tmp.path }
|
||||||
const parent = await createSession(tmp.path, { title: "parent" })
|
const parent = yield* createSession(tmp.path, { title: "parent" })
|
||||||
const child = await createSession(tmp.path, { title: "child", parentID: parent.id })
|
const child = yield* createSession(tmp.path, { title: "child", parentID: parent.id })
|
||||||
const message = await createTextMessage(tmp.path, parent.id, "hello")
|
const message = yield* createTextMessage(tmp.path, parent.id, "hello")
|
||||||
await createTextMessage(tmp.path, parent.id, "world")
|
yield* createTextMessage(tmp.path, parent.id, "world")
|
||||||
|
|
||||||
|
const listed = yield* requestJson<Session.Info[]>(`${SessionPaths.list}?roots=true`, { headers })
|
||||||
|
expect(listed.map((item) => item.id)).toContain(parent.id)
|
||||||
|
expect(Object.hasOwn(listed[0]!, "parentID")).toBe(false)
|
||||||
|
|
||||||
|
expect(yield* requestJson<Record<string, unknown>>(SessionPaths.status, { headers })).toEqual({})
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
(await json<Session.Info[]>(await app().request(`${SessionPaths.list}?roots=true`, { headers }))).map(
|
yield* requestJson<Session.Info>(pathFor(SessionPaths.get, { sessionID: parent.id }), { headers }),
|
||||||
(item) => item.id,
|
|
||||||
),
|
|
||||||
).toContain(parent.id)
|
|
||||||
|
|
||||||
expect(await json<Record<string, unknown>>(await app().request(SessionPaths.status, { headers }))).toEqual({})
|
|
||||||
|
|
||||||
expect(
|
|
||||||
await json<Session.Info>(await app().request(pathFor(SessionPaths.get, { sessionID: parent.id }), { headers })),
|
|
||||||
).toMatchObject({ id: parent.id, title: "parent" })
|
).toMatchObject({ id: parent.id, title: "parent" })
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
(
|
(yield* requestJson<Session.Info[]>(pathFor(SessionPaths.children, { sessionID: parent.id }), {
|
||||||
await json<Session.Info[]>(
|
headers,
|
||||||
await app().request(pathFor(SessionPaths.children, { sessionID: parent.id }), { headers }),
|
})).map((item) => item.id),
|
||||||
)
|
|
||||||
).map((item) => item.id),
|
|
||||||
).toEqual([child.id])
|
).toEqual([child.id])
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<unknown[]>(await app().request(pathFor(SessionPaths.todo, { sessionID: parent.id }), { headers })),
|
yield* requestJson<unknown[]>(pathFor(SessionPaths.todo, { sessionID: parent.id }), { headers }),
|
||||||
).toEqual([])
|
).toEqual([])
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<unknown[]>(await app().request(pathFor(SessionPaths.diff, { sessionID: parent.id }), { headers })),
|
yield* requestJson<unknown[]>(pathFor(SessionPaths.diff, { sessionID: parent.id }), { headers }),
|
||||||
).toEqual([])
|
).toEqual([])
|
||||||
|
|
||||||
const messages = await app().request(`${pathFor(SessionPaths.messages, { sessionID: parent.id })}?limit=1`, {
|
const messages = yield* request(`${pathFor(SessionPaths.messages, { sessionID: parent.id })}?limit=1`, {
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
const messagePage = await json<MessageV2.WithParts[]>(messages)
|
const messagePage = yield* json<MessageV2.WithParts[]>(messages)
|
||||||
const nextCursor = messages.headers.get("x-next-cursor")
|
const nextCursor = messages.headers.get("x-next-cursor")
|
||||||
expect(nextCursor).toBeTruthy()
|
expect(nextCursor).toBeTruthy()
|
||||||
expect(messagePage[0]?.parts[0]).toMatchObject({ type: "text" })
|
expect(messagePage[0]?.parts[0]).toMatchObject({ type: "text" })
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
(
|
(yield* request(`${pathFor(SessionPaths.messages, { sessionID: parent.id })}?before=${nextCursor}`, {
|
||||||
await app().request(`${pathFor(SessionPaths.messages, { sessionID: parent.id })}?before=${nextCursor}`, {
|
|
||||||
headers,
|
headers,
|
||||||
})
|
})).status,
|
||||||
).status,
|
|
||||||
).toBe(400)
|
).toBe(400)
|
||||||
expect(
|
expect(
|
||||||
(
|
(yield* request(`${pathFor(SessionPaths.messages, { sessionID: parent.id })}?limit=1&before=invalid`, {
|
||||||
await app().request(`${pathFor(SessionPaths.messages, { sessionID: parent.id })}?limit=1&before=invalid`, {
|
|
||||||
headers,
|
headers,
|
||||||
})
|
})).status,
|
||||||
).status,
|
|
||||||
).toBe(400)
|
).toBe(400)
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<MessageV2.WithParts>(
|
yield* requestJson<MessageV2.WithParts>(
|
||||||
await app().request(pathFor(SessionPaths.message, { sessionID: parent.id, messageID: message.info.id }), {
|
pathFor(SessionPaths.message, { sessionID: parent.id, messageID: message.info.id }),
|
||||||
headers,
|
{ headers },
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
).toMatchObject({ info: { id: message.info.id } })
|
).toMatchObject({ info: { id: message.info.id } })
|
||||||
})
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
test("serves lifecycle mutation routes through Hono bridge", async () => {
|
it.live(
|
||||||
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false, share: "disabled" } })
|
"serves lifecycle mutation routes through Hono bridge",
|
||||||
|
withTmp({ git: true, config: { formatter: false, lsp: false, share: "disabled" } }, (tmp) =>
|
||||||
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
||||||
|
|
||||||
const createdEmpty = await json<Session.Info>(
|
const createdEmpty = yield* requestJson<Session.Info>(SessionPaths.create, {
|
||||||
await app().request(SessionPaths.create, {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers,
|
headers,
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
expect(createdEmpty.id).toBeTruthy()
|
expect(createdEmpty.id).toBeTruthy()
|
||||||
|
|
||||||
const created = await json<Session.Info>(
|
const created = yield* requestJson<Session.Info>(SessionPaths.create, {
|
||||||
await app().request(SessionPaths.create, {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify({ title: "created" }),
|
body: JSON.stringify({ title: "created" }),
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
expect(created.title).toBe("created")
|
expect(created.title).toBe("created")
|
||||||
|
|
||||||
const updated = await json<Session.Info>(
|
const updated = yield* requestJson<Session.Info>(pathFor(SessionPaths.update, { sessionID: created.id }), {
|
||||||
await app().request(pathFor(SessionPaths.update, { sessionID: created.id }), {
|
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify({ title: "updated", time: { archived: 1 } }),
|
body: JSON.stringify({ title: "updated", time: { archived: 1 } }),
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
expect(updated).toMatchObject({ id: created.id, title: "updated", time: { archived: 1 } })
|
expect(updated).toMatchObject({ id: created.id, title: "updated", time: { archived: 1 } })
|
||||||
|
|
||||||
const forked = await json<Session.Info>(
|
const forked = yield* requestJson<Session.Info>(pathFor(SessionPaths.fork, { sessionID: created.id }), {
|
||||||
await app().request(pathFor(SessionPaths.fork, { sessionID: created.id }), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
expect(forked.id).not.toBe(created.id)
|
expect(forked.id).not.toBe(created.id)
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<boolean>(
|
yield* requestJson<boolean>(pathFor(SessionPaths.abort, { sessionID: created.id }), {
|
||||||
await app().request(pathFor(SessionPaths.abort, { sessionID: created.id }), { method: "POST", headers }),
|
method: "POST",
|
||||||
),
|
headers,
|
||||||
|
}),
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<boolean>(
|
yield* requestJson<boolean>(pathFor(SessionPaths.remove, { sessionID: created.id }), {
|
||||||
await app().request(pathFor(SessionPaths.remove, { sessionID: created.id }), { method: "DELETE", headers }),
|
method: "DELETE",
|
||||||
),
|
headers,
|
||||||
|
}),
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
})
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
test("serves message mutation routes through Hono bridge", async () => {
|
it.live(
|
||||||
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
|
"serves message mutation routes through Hono bridge",
|
||||||
|
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
||||||
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
||||||
const session = await createSession(tmp.path, { title: "messages" })
|
const session = yield* createSession(tmp.path, { title: "messages" })
|
||||||
const first = await createTextMessage(tmp.path, session.id, "first")
|
const first = yield* createTextMessage(tmp.path, session.id, "first")
|
||||||
const second = await createTextMessage(tmp.path, session.id, "second")
|
const second = yield* createTextMessage(tmp.path, session.id, "second")
|
||||||
|
|
||||||
const updated = await json<MessageV2.Part>(
|
const updated = yield* requestJson<MessageV2.Part>(
|
||||||
await app().request(
|
|
||||||
pathFor(SessionPaths.updatePart, {
|
pathFor(SessionPaths.updatePart, {
|
||||||
sessionID: session.id,
|
sessionID: session.id,
|
||||||
messageID: first.info.id,
|
messageID: first.info.id,
|
||||||
|
|
@ -218,13 +239,11 @@ describe("session HttpApi", () => {
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify({ ...first.part, text: "updated" }),
|
body: JSON.stringify({ ...first.part, text: "updated" }),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
)
|
)
|
||||||
expect(updated).toMatchObject({ id: first.part.id, type: "text", text: "updated" })
|
expect(updated).toMatchObject({ id: first.part.id, type: "text", text: "updated" })
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<boolean>(
|
yield* requestJson<boolean>(
|
||||||
await app().request(
|
|
||||||
pathFor(SessionPaths.deletePart, {
|
pathFor(SessionPaths.deletePart, {
|
||||||
sessionID: session.id,
|
sessionID: session.id,
|
||||||
messageID: first.info.id,
|
messageID: first.info.id,
|
||||||
|
|
@ -232,46 +251,42 @@ describe("session HttpApi", () => {
|
||||||
}),
|
}),
|
||||||
{ method: "DELETE", headers },
|
{ method: "DELETE", headers },
|
||||||
),
|
),
|
||||||
),
|
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<boolean>(
|
yield* requestJson<boolean>(
|
||||||
await app().request(pathFor(SessionPaths.deleteMessage, { sessionID: session.id, messageID: second.info.id }), {
|
pathFor(SessionPaths.deleteMessage, { sessionID: session.id, messageID: second.info.id }),
|
||||||
method: "DELETE",
|
{ method: "DELETE", headers },
|
||||||
headers,
|
),
|
||||||
|
).toBe(true)
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
).toBe(true)
|
)
|
||||||
})
|
|
||||||
|
|
||||||
test("serves remaining non-LLM session mutation routes through Hono bridge", async () => {
|
it.live(
|
||||||
await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
|
"serves remaining non-LLM session mutation routes through Hono bridge",
|
||||||
|
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
||||||
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
||||||
const session = await createSession(tmp.path, { title: "remaining" })
|
const session = yield* createSession(tmp.path, { title: "remaining" })
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<Session.Info>(
|
yield* requestJson<Session.Info>(pathFor(SessionPaths.revert, { sessionID: session.id }), {
|
||||||
await app().request(pathFor(SessionPaths.revert, { sessionID: session.id }), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify({ messageID: MessageID.ascending() }),
|
body: JSON.stringify({ messageID: MessageID.ascending() }),
|
||||||
}),
|
}),
|
||||||
),
|
|
||||||
).toMatchObject({ id: session.id })
|
).toMatchObject({ id: session.id })
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<Session.Info>(
|
yield* requestJson<Session.Info>(pathFor(SessionPaths.unrevert, { sessionID: session.id }), {
|
||||||
await app().request(pathFor(SessionPaths.unrevert, { sessionID: session.id }), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers,
|
headers,
|
||||||
}),
|
}),
|
||||||
),
|
|
||||||
).toMatchObject({ id: session.id })
|
).toMatchObject({ id: session.id })
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await json<boolean>(
|
yield* requestJson<boolean>(
|
||||||
await app().request(
|
|
||||||
pathFor(SessionPaths.permissions, {
|
pathFor(SessionPaths.permissions, {
|
||||||
sessionID: session.id,
|
sessionID: session.id,
|
||||||
permissionID: String(PermissionID.ascending()),
|
permissionID: String(PermissionID.ascending()),
|
||||||
|
|
@ -282,7 +297,8 @@ describe("session HttpApi", () => {
|
||||||
body: JSON.stringify({ response: "once" }),
|
body: JSON.stringify({ response: "once" }),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
})
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue