test(server): migrate httpapi session test to effect runner (#27207)
This commit is contained in:
@@ -8,8 +8,8 @@ import type { WorkspaceAdapter } from "../../src/control-plane/types"
|
|||||||
import { Workspace } from "../../src/control-plane/workspace"
|
import { Workspace } from "../../src/control-plane/workspace"
|
||||||
import { PermissionID } from "../../src/permission/schema"
|
import { PermissionID } from "../../src/permission/schema"
|
||||||
import { ModelID, ProviderID } from "../../src/provider/schema"
|
import { ModelID, ProviderID } from "../../src/provider/schema"
|
||||||
import { WithInstance } from "../../src/project/with-instance"
|
|
||||||
import { InstanceBootstrap } from "../../src/project/bootstrap"
|
import { InstanceBootstrap } from "../../src/project/bootstrap"
|
||||||
|
import { InstanceBootstrap as InstanceBootstrapService } from "../../src/project/bootstrap-service"
|
||||||
import { InstanceStore } from "../../src/project/instance-store"
|
import { InstanceStore } from "../../src/project/instance-store"
|
||||||
import { Project } from "../../src/project/project"
|
import { Project } from "../../src/project/project"
|
||||||
import { Server } from "../../src/server/server"
|
import { Server } from "../../src/server/server"
|
||||||
@@ -25,8 +25,8 @@ import * as DateTime from "effect/DateTime"
|
|||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { eq } from "drizzle-orm"
|
import { eq } from "drizzle-orm"
|
||||||
import { resetDatabase } from "../fixture/db"
|
import { resetDatabase } from "../fixture/db"
|
||||||
import { disposeAllInstances, tmpdir } from "../fixture/fixture"
|
import { disposeAllInstances, TestInstance } from "../fixture/fixture"
|
||||||
import { it } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
|
|
||||||
void Log.init({ print: false })
|
void Log.init({ print: false })
|
||||||
|
|
||||||
@@ -35,37 +35,27 @@ const workspaceLayer = Workspace.defaultLayer.pipe(
|
|||||||
Layer.provide(InstanceStore.defaultLayer),
|
Layer.provide(InstanceStore.defaultLayer),
|
||||||
Layer.provide(InstanceBootstrap.defaultLayer),
|
Layer.provide(InstanceBootstrap.defaultLayer),
|
||||||
)
|
)
|
||||||
|
const instanceStoreLayer = InstanceStore.defaultLayer.pipe(
|
||||||
|
Layer.provide(
|
||||||
|
Layer.succeed(InstanceBootstrapService.Service, InstanceBootstrapService.Service.of({ run: Effect.void })),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
const it = testEffect(Layer.mergeAll(instanceStoreLayer, Project.defaultLayer, Session.defaultLayer, workspaceLayer))
|
||||||
|
|
||||||
function app() {
|
function app() {
|
||||||
return Server.Default().app
|
return Server.Default().app
|
||||||
}
|
}
|
||||||
|
|
||||||
function runSession<A, E>(fx: Effect.Effect<A, E, Session.Service>) {
|
|
||||||
return Effect.runPromise(fx.pipe(Effect.provide(Session.defaultLayer)))
|
|
||||||
}
|
|
||||||
|
|
||||||
function pathFor(path: string, params: Record<string, string>) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSession(directory: string, input?: Session.CreateInput) {
|
function createSession(input?: Session.CreateInput) {
|
||||||
return Effect.promise(
|
return Session.Service.use((svc) => svc.create(input))
|
||||||
async () =>
|
|
||||||
await WithInstance.provide({
|
|
||||||
directory,
|
|
||||||
fn: () => runSession(Session.Service.use((svc) => svc.create(input))),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTextMessage(directory: string, sessionID: SessionIDType, text: string) {
|
function createTextMessage(sessionID: SessionIDType, text: string) {
|
||||||
return Effect.promise(
|
return Effect.gen(function* () {
|
||||||
async () =>
|
|
||||||
await WithInstance.provide({
|
|
||||||
directory,
|
|
||||||
fn: () =>
|
|
||||||
runSession(
|
|
||||||
Effect.gen(function* () {
|
|
||||||
const svc = yield* Session.Service
|
const svc = yield* Session.Service
|
||||||
const info = yield* svc.updateMessage({
|
const info = yield* svc.updateMessage({
|
||||||
id: MessageID.ascending(),
|
id: MessageID.ascending(),
|
||||||
@@ -83,10 +73,7 @@ function createTextMessage(directory: string, sessionID: SessionIDType, text: st
|
|||||||
text,
|
text,
|
||||||
})
|
})
|
||||||
return { info, part }
|
return { info, part }
|
||||||
}),
|
})
|
||||||
),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const localAdapter = (directory: string): WorkspaceAdapter => ({
|
const localAdapter = (directory: string): WorkspaceAdapter => ({
|
||||||
@@ -101,6 +88,7 @@ const localAdapter = (directory: string): WorkspaceAdapter => ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const createLocalWorkspace = (input: { projectID: Project.Info["id"]; type: string; directory: string }) =>
|
const createLocalWorkspace = (input: { projectID: Project.Info["id"]; type: string; directory: string }) =>
|
||||||
|
Effect.acquireRelease(
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
registerAdapter(input.projectID, input.type, localAdapter(input.directory))
|
registerAdapter(input.projectID, input.type, localAdapter(input.directory))
|
||||||
return yield* Workspace.Service.use((svc) =>
|
return yield* Workspace.Service.use((svc) =>
|
||||||
@@ -110,8 +98,77 @@ const createLocalWorkspace = (input: { projectID: Project.Info["id"]; type: stri
|
|||||||
extra: null,
|
extra: null,
|
||||||
projectID: input.projectID,
|
projectID: input.projectID,
|
||||||
}),
|
}),
|
||||||
).pipe(Effect.provide(workspaceLayer))
|
)
|
||||||
|
}),
|
||||||
|
(info) => Workspace.Service.use((svc) => svc.remove(info.id)).pipe(Effect.ignore),
|
||||||
|
)
|
||||||
|
|
||||||
|
const insertLegacyAssistantMessage = (sessionID: SessionIDType) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
const message = new SessionMessage.Assistant({
|
||||||
|
id: SessionMessage.ID.create(),
|
||||||
|
type: "assistant",
|
||||||
|
agent: "build",
|
||||||
|
model: {
|
||||||
|
id: Modelv2.ID.make("model"),
|
||||||
|
providerID: Modelv2.ProviderID.make("provider"),
|
||||||
|
variant: Modelv2.VariantID.make("default"),
|
||||||
|
},
|
||||||
|
time: { created: DateTime.makeUnsafe(1) },
|
||||||
|
content: [],
|
||||||
})
|
})
|
||||||
|
Database.use((db) =>
|
||||||
|
db
|
||||||
|
.insert(SessionMessageTable)
|
||||||
|
.values([
|
||||||
|
{
|
||||||
|
id: message.id,
|
||||||
|
session_id: sessionID,
|
||||||
|
type: message.type,
|
||||||
|
time_created: 1,
|
||||||
|
data: {
|
||||||
|
time: { created: 1 },
|
||||||
|
agent: message.agent,
|
||||||
|
model: message.model,
|
||||||
|
content: message.content,
|
||||||
|
} as NonNullable<(typeof SessionMessageTable.$inferInsert)["data"]>,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
.run(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const setLegacySummaryDiff = (sessionID: SessionIDType) =>
|
||||||
|
Effect.sync(() =>
|
||||||
|
Database.use((db) =>
|
||||||
|
db
|
||||||
|
.update(SessionTable)
|
||||||
|
.set({
|
||||||
|
summary_additions: 1,
|
||||||
|
summary_deletions: 0,
|
||||||
|
summary_files: 1,
|
||||||
|
summary_diffs: [{ additions: 1, deletions: 0 }],
|
||||||
|
})
|
||||||
|
.where(eq(SessionTable.id, sessionID))
|
||||||
|
.run(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
const getWorkspaceID = (sessionID: SessionIDType) =>
|
||||||
|
Effect.sync(() =>
|
||||||
|
Database.use((db) =>
|
||||||
|
db
|
||||||
|
.select({ workspaceID: SessionTable.workspace_id })
|
||||||
|
.from(SessionTable)
|
||||||
|
.where(eq(SessionTable.id, sessionID))
|
||||||
|
.get(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
const clearSessionPath = (sessionID: SessionIDType) =>
|
||||||
|
Effect.sync(() =>
|
||||||
|
Database.use((db) => db.update(SessionTable).set({ path: null }).where(eq(SessionTable.id, sessionID)).run()),
|
||||||
|
)
|
||||||
|
|
||||||
function request(path: string, init?: RequestInit) {
|
function request(path: string, init?: RequestInit) {
|
||||||
return Effect.promise(async () => app().request(path, init))
|
return Effect.promise(async () => app().request(path, init))
|
||||||
@@ -132,16 +189,6 @@ function requestJson<T>(path: string, init?: RequestInit) {
|
|||||||
return request(path, init).pipe(Effect.flatMap(json<T>))
|
return request(path, init).pipe(Effect.flatMap(json<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 () => {
|
||||||
Flag.OPENCODE_EXPERIMENTAL_WORKSPACES = originalWorkspaces
|
Flag.OPENCODE_EXPERIMENTAL_WORKSPACES = originalWorkspaces
|
||||||
await disposeAllInstances()
|
await disposeAllInstances()
|
||||||
@@ -149,11 +196,12 @@ afterEach(async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("session HttpApi", () => {
|
describe("session HttpApi", () => {
|
||||||
it.live(
|
it.instance(
|
||||||
"returns declared not found errors for read routes",
|
"returns declared not found errors for read routes",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path }
|
const test = yield* TestInstance
|
||||||
|
const headers = { "x-opencode-directory": test.directory }
|
||||||
const missingSession = SessionID.descending()
|
const missingSession = SessionID.descending()
|
||||||
const missingSessionBody = {
|
const missingSessionBody = {
|
||||||
name: "NotFoundError",
|
name: "NotFoundError",
|
||||||
@@ -175,7 +223,7 @@ describe("session HttpApi", () => {
|
|||||||
expect(remove.status).toBe(404)
|
expect(remove.status).toBe(404)
|
||||||
expect(yield* responseJson(remove)).toEqual(missingSessionBody)
|
expect(yield* responseJson(remove)).toEqual(missingSessionBody)
|
||||||
|
|
||||||
const session = yield* createSession(tmp.path, { title: "missing message" })
|
const session = yield* createSession({ title: "missing message" })
|
||||||
const missingMessage = MessageID.ascending()
|
const missingMessage = MessageID.ascending()
|
||||||
const message = yield* request(
|
const message = yield* request(
|
||||||
pathFor(SessionPaths.message, { sessionID: session.id, messageID: missingMessage }),
|
pathFor(SessionPaths.message, { sessionID: session.id, messageID: missingMessage }),
|
||||||
@@ -187,18 +235,19 @@ describe("session HttpApi", () => {
|
|||||||
data: { message: `Message not found: ${missingMessage}` },
|
data: { message: `Message not found: ${missingMessage}` },
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false } },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live(
|
it.instance(
|
||||||
"serves read routes",
|
"serves read routes",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path }
|
const test = yield* TestInstance
|
||||||
const parent = yield* createSession(tmp.path, { title: "parent" })
|
const headers = { "x-opencode-directory": test.directory }
|
||||||
const child = yield* createSession(tmp.path, { title: "child", parentID: parent.id })
|
const parent = yield* createSession({ title: "parent" })
|
||||||
const message = yield* createTextMessage(tmp.path, parent.id, "hello")
|
const child = yield* createSession({ title: "child", parentID: parent.id })
|
||||||
yield* createTextMessage(tmp.path, parent.id, "world")
|
const message = yield* createTextMessage(parent.id, "hello")
|
||||||
|
yield* createTextMessage(parent.id, "world")
|
||||||
|
|
||||||
const listed = yield* requestJson<Session.Info[]>(`${SessionPaths.list}?roots=true`, { headers })
|
const listed = yield* requestJson<Session.Info[]>(`${SessionPaths.list}?roots=true`, { headers })
|
||||||
expect(listed.map((item) => item.id)).toContain(parent.id)
|
expect(listed.map((item) => item.id)).toContain(parent.id)
|
||||||
@@ -250,88 +299,40 @@ describe("session HttpApi", () => {
|
|||||||
),
|
),
|
||||||
).toMatchObject({ info: { id: message.info.id } })
|
).toMatchObject({ info: { id: message.info.id } })
|
||||||
|
|
||||||
yield* Effect.promise(() =>
|
yield* insertLegacyAssistantMessage(parent.id)
|
||||||
WithInstance.provide({
|
|
||||||
directory: tmp.path,
|
|
||||||
fn: async () => {
|
|
||||||
const message = new SessionMessage.Assistant({
|
|
||||||
id: SessionMessage.ID.create(),
|
|
||||||
type: "assistant",
|
|
||||||
agent: "build",
|
|
||||||
model: {
|
|
||||||
id: Modelv2.ID.make("model"),
|
|
||||||
providerID: Modelv2.ProviderID.make("provider"),
|
|
||||||
variant: Modelv2.VariantID.make("default"),
|
|
||||||
},
|
|
||||||
time: { created: DateTime.makeUnsafe(1) },
|
|
||||||
content: [],
|
|
||||||
})
|
|
||||||
Database.use((db) =>
|
|
||||||
db
|
|
||||||
.insert(SessionMessageTable)
|
|
||||||
.values([
|
|
||||||
{
|
|
||||||
id: message.id,
|
|
||||||
session_id: parent.id,
|
|
||||||
type: message.type,
|
|
||||||
time_created: 1,
|
|
||||||
data: {
|
|
||||||
time: { created: 1 },
|
|
||||||
agent: message.agent,
|
|
||||||
model: message.model,
|
|
||||||
content: message.content,
|
|
||||||
} as NonNullable<(typeof SessionMessageTable.$inferInsert)["data"]>,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
.run(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
(yield* requestJson<{ items: SessionMessage.Message[] }>(`/api/session/${parent.id}/message`, { headers }))
|
(yield* requestJson<{ items: SessionMessage.Message[] }>(`/api/session/${parent.id}/message`, { headers }))
|
||||||
.items,
|
.items,
|
||||||
).toMatchObject([{ type: "assistant" }])
|
).toMatchObject([{ type: "assistant" }])
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false } },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live(
|
it.instance(
|
||||||
"serves sessions with migrated summary diffs missing file details",
|
"serves sessions with migrated summary diffs missing file details",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const session = yield* createSession(tmp.path, { title: "legacy diff" })
|
const test = yield* TestInstance
|
||||||
yield* Effect.sync(() =>
|
const session = yield* createSession({ title: "legacy diff" })
|
||||||
Database.use((db) =>
|
yield* setLegacySummaryDiff(session.id)
|
||||||
db
|
|
||||||
.update(SessionTable)
|
|
||||||
.set({
|
|
||||||
summary_additions: 1,
|
|
||||||
summary_deletions: 0,
|
|
||||||
summary_files: 1,
|
|
||||||
summary_diffs: [{ additions: 1, deletions: 0 }],
|
|
||||||
})
|
|
||||||
.where(eq(SessionTable.id, session.id))
|
|
||||||
.run(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
const response = yield* request(pathFor(SessionPaths.get, { sessionID: session.id }), {
|
const response = yield* request(pathFor(SessionPaths.get, { sessionID: session.id }), {
|
||||||
headers: { "x-opencode-directory": tmp.path },
|
headers: { "x-opencode-directory": test.directory },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(response.status).toBe(200)
|
expect(response.status).toBe(200)
|
||||||
expect((yield* json<Session.Info>(response)).summary?.diffs).toEqual([{ additions: 1, deletions: 0 }])
|
expect((yield* json<Session.Info>(response)).summary?.diffs).toEqual([{ additions: 1, deletions: 0 }])
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false } },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live(
|
it.instance(
|
||||||
"serves lifecycle mutation routes",
|
"serves lifecycle mutation routes",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false, share: "disabled" } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
const test = yield* TestInstance
|
||||||
|
const headers = { "x-opencode-directory": test.directory, "content-type": "application/json" }
|
||||||
|
|
||||||
const createdEmpty = yield* requestJson<Session.Info>(SessionPaths.create, {
|
const createdEmpty = yield* requestJson<Session.Info>(SessionPaths.create, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -373,56 +374,48 @@ describe("session HttpApi", () => {
|
|||||||
}),
|
}),
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false, share: "disabled" } },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live(
|
it.instance(
|
||||||
"persists selected workspace id when creating a session",
|
"persists selected workspace id when creating a session",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false, share: "disabled" } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
|
const test = yield* TestInstance
|
||||||
Flag.OPENCODE_EXPERIMENTAL_WORKSPACES = true
|
Flag.OPENCODE_EXPERIMENTAL_WORKSPACES = true
|
||||||
const project = yield* Project.use.fromDirectory(tmp.path).pipe(Effect.provide(Project.defaultLayer))
|
const project = yield* Project.use.fromDirectory(test.directory)
|
||||||
const workspace = yield* createLocalWorkspace({
|
const workspace = yield* createLocalWorkspace({
|
||||||
projectID: project.project.id,
|
projectID: project.project.id,
|
||||||
type: "session-create-workspace",
|
type: "session-create-workspace",
|
||||||
directory: path.join(tmp.path, ".workspace-local"),
|
directory: path.join(test.directory, ".workspace-local"),
|
||||||
})
|
})
|
||||||
|
|
||||||
const created = yield* requestJson<Session.Info>(`${SessionPaths.create}?workspace=${workspace.id}`, {
|
const created = yield* requestJson<Session.Info>(`${SessionPaths.create}?workspace=${workspace.id}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "x-opencode-directory": tmp.path, "content-type": "application/json" },
|
headers: { "x-opencode-directory": test.directory, "content-type": "application/json" },
|
||||||
body: JSON.stringify({ title: "workspace session" }),
|
body: JSON.stringify({ title: "workspace session" }),
|
||||||
})
|
})
|
||||||
const messages = yield* request(
|
const messages = yield* request(
|
||||||
`${pathFor(SessionPaths.messages, { sessionID: created.id })}?workspace=${workspace.id}`,
|
`${pathFor(SessionPaths.messages, { sessionID: created.id })}?workspace=${workspace.id}`,
|
||||||
{
|
{
|
||||||
headers: { "x-opencode-directory": tmp.path },
|
headers: { "x-opencode-directory": test.directory },
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(created).toMatchObject({ id: created.id, workspaceID: workspace.id })
|
expect(created).toMatchObject({ id: created.id, workspaceID: workspace.id })
|
||||||
expect(messages.status).toBe(200)
|
expect(messages.status).toBe(200)
|
||||||
expect(
|
expect(yield* getWorkspaceID(created.id)).toEqual({ workspaceID: workspace.id })
|
||||||
yield* Effect.sync(() =>
|
|
||||||
Database.use((db) =>
|
|
||||||
db
|
|
||||||
.select({ workspaceID: SessionTable.workspace_id })
|
|
||||||
.from(SessionTable)
|
|
||||||
.where(eq(SessionTable.id, created.id))
|
|
||||||
.get(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
).toEqual({ workspaceID: workspace.id })
|
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false, share: "disabled" } },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live(
|
it.instance(
|
||||||
"validates archived timestamp values",
|
"validates archived timestamp values",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
const test = yield* TestInstance
|
||||||
const session = yield* createSession(tmp.path, { title: "archived" })
|
const headers = { "x-opencode-directory": test.directory, "content-type": "application/json" }
|
||||||
|
const session = yield* createSession({ title: "archived" })
|
||||||
const body = JSON.stringify({ time: { archived: -1 } })
|
const body = JSON.stringify({ time: { archived: -1 } })
|
||||||
|
|
||||||
const response = yield* request(pathFor(SessionPaths.update, { sessionID: session.id }), {
|
const response = yield* request(pathFor(SessionPaths.update, { sessionID: session.id }), {
|
||||||
@@ -433,30 +426,35 @@ describe("session HttpApi", () => {
|
|||||||
expect(response.status).toBe(200)
|
expect(response.status).toBe(200)
|
||||||
expect((yield* json<Session.Info>(response)).time.archived).toBe(-1)
|
expect((yield* json<Session.Info>(response)).time.archived).toBe(-1)
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false } },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live(
|
it.instance(
|
||||||
"uses project-scoped path and directory precedence",
|
"uses project-scoped path and directory precedence",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const currentDir = path.join(tmp.path, "packages", "opencode", "src")
|
const test = yield* TestInstance
|
||||||
|
const currentDir = path.join(test.directory, "packages", "opencode", "src")
|
||||||
yield* Effect.promise(() => mkdir(currentDir, { recursive: true }))
|
yield* Effect.promise(() => mkdir(currentDir, { recursive: true }))
|
||||||
|
|
||||||
const pathSession = yield* createSession(currentDir)
|
const store = yield* InstanceStore.Service
|
||||||
const pathlessSession = yield* createSession(currentDir)
|
const { pathSession, pathlessSession } = yield* store.provide(
|
||||||
yield* Effect.sync(() =>
|
{ directory: currentDir },
|
||||||
Database.use((db) =>
|
Effect.gen(function* () {
|
||||||
db.update(SessionTable).set({ path: null }).where(eq(SessionTable.id, pathlessSession.id)).run(),
|
return {
|
||||||
),
|
pathSession: yield* createSession(),
|
||||||
|
pathlessSession: yield* createSession(),
|
||||||
|
}
|
||||||
|
}).pipe(Effect.provideService(TestInstance, { directory: currentDir }), Effect.provide(Session.defaultLayer)),
|
||||||
)
|
)
|
||||||
|
yield* clearSessionPath(pathlessSession.id)
|
||||||
|
|
||||||
const query = new URLSearchParams({
|
const query = new URLSearchParams({
|
||||||
scope: "project",
|
scope: "project",
|
||||||
path: "packages/opencode/src",
|
path: "packages/opencode/src",
|
||||||
directory: currentDir,
|
directory: currentDir,
|
||||||
})
|
})
|
||||||
const headers = { "x-opencode-directory": tmp.path }
|
const headers = { "x-opencode-directory": test.directory }
|
||||||
const sessions = (yield* json<Session.Info[]>(
|
const sessions = (yield* json<Session.Info[]>(
|
||||||
yield* request(`${SessionPaths.list}?${query}`, { headers }),
|
yield* request(`${SessionPaths.list}?${query}`, { headers }),
|
||||||
)).map((item) => item.id)
|
)).map((item) => item.id)
|
||||||
@@ -464,17 +462,18 @@ describe("session HttpApi", () => {
|
|||||||
expect(sessions).toContain(pathSession.id)
|
expect(sessions).toContain(pathSession.id)
|
||||||
expect(sessions).not.toContain(pathlessSession.id)
|
expect(sessions).not.toContain(pathlessSession.id)
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false } },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live(
|
it.instance(
|
||||||
"serves paginated message link headers",
|
"serves paginated message link headers",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path }
|
const test = yield* TestInstance
|
||||||
const session = yield* createSession(tmp.path, { title: "messages" })
|
const headers = { "x-opencode-directory": test.directory }
|
||||||
yield* createTextMessage(tmp.path, session.id, "first")
|
const session = yield* createSession({ title: "messages" })
|
||||||
yield* createTextMessage(tmp.path, session.id, "second")
|
yield* createTextMessage(session.id, "first")
|
||||||
|
yield* createTextMessage(session.id, "second")
|
||||||
const route = `${pathFor(SessionPaths.messages, { sessionID: session.id })}?limit=1`
|
const route = `${pathFor(SessionPaths.messages, { sessionID: session.id })}?limit=1`
|
||||||
|
|
||||||
const response = yield* request(route, { headers })
|
const response = yield* request(route, { headers })
|
||||||
@@ -483,17 +482,18 @@ describe("session HttpApi", () => {
|
|||||||
expect(response.headers.get("link")).toContain("limit=1")
|
expect(response.headers.get("link")).toContain("limit=1")
|
||||||
expect(response.headers.get("access-control-expose-headers")?.toLowerCase()).toContain("x-next-cursor")
|
expect(response.headers.get("access-control-expose-headers")?.toLowerCase()).toContain("x-next-cursor")
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false } },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live(
|
it.instance(
|
||||||
"serves message mutation routes",
|
"serves message mutation routes",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
const test = yield* TestInstance
|
||||||
const session = yield* createSession(tmp.path, { title: "messages" })
|
const headers = { "x-opencode-directory": test.directory, "content-type": "application/json" }
|
||||||
const first = yield* createTextMessage(tmp.path, session.id, "first")
|
const session = yield* createSession({ title: "messages" })
|
||||||
const second = yield* createTextMessage(tmp.path, session.id, "second")
|
const first = yield* createTextMessage(session.id, "first")
|
||||||
|
const second = yield* createTextMessage(session.id, "second")
|
||||||
|
|
||||||
const updated = yield* requestJson<MessageV2.Part>(
|
const updated = yield* requestJson<MessageV2.Part>(
|
||||||
pathFor(SessionPaths.updatePart, {
|
pathFor(SessionPaths.updatePart, {
|
||||||
@@ -527,15 +527,16 @@ describe("session HttpApi", () => {
|
|||||||
),
|
),
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false } },
|
||||||
)
|
)
|
||||||
|
|
||||||
it.live(
|
it.instance(
|
||||||
"serves remaining non-LLM session mutation routes",
|
"serves remaining non-LLM session mutation routes",
|
||||||
withTmp({ git: true, config: { formatter: false, lsp: false } }, (tmp) =>
|
() =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const headers = { "x-opencode-directory": tmp.path, "content-type": "application/json" }
|
const test = yield* TestInstance
|
||||||
const session = yield* createSession(tmp.path, { title: "remaining" })
|
const headers = { "x-opencode-directory": test.directory, "content-type": "application/json" }
|
||||||
|
const session = yield* createSession({ title: "remaining" })
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
yield* requestJson<Session.Info>(pathFor(SessionPaths.revert, { sessionID: session.id }), {
|
yield* requestJson<Session.Info>(pathFor(SessionPaths.revert, { sessionID: session.id }), {
|
||||||
@@ -566,6 +567,6 @@ describe("session HttpApi", () => {
|
|||||||
),
|
),
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true, config: { formatter: false, lsp: false } },
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user