test(server): migrate missing patch diff test (#27202)
This commit is contained in:
@@ -10,19 +10,20 @@
|
|||||||
* asserts that GET /session/<id>/diff returns 200 with the row intact.
|
* asserts that GET /session/<id>/diff returns 200 with the row intact.
|
||||||
*/
|
*/
|
||||||
import { afterEach, describe, expect } from "bun:test"
|
import { afterEach, describe, expect } from "bun:test"
|
||||||
import { Effect } from "effect"
|
import { Effect, Layer } from "effect"
|
||||||
import { Server } from "@/server/server"
|
import { Server } from "@/server/server"
|
||||||
import { SessionPaths } from "@/server/routes/instance/httpapi/groups/session"
|
import { SessionPaths } from "@/server/routes/instance/httpapi/groups/session"
|
||||||
import { Session } from "@/session/session"
|
import { Session } from "@/session/session"
|
||||||
import { Storage } from "@/storage/storage"
|
import { Storage } from "@/storage/storage"
|
||||||
import { WithInstance } from "@/project/with-instance"
|
|
||||||
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"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
|
|
||||||
void Log.init({ print: false })
|
void Log.init({ print: false })
|
||||||
|
|
||||||
|
const it = testEffect(Layer.mergeAll(Session.defaultLayer, Storage.defaultLayer))
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await disposeAllInstances()
|
await disposeAllInstances()
|
||||||
await resetDatabase()
|
await resetDatabase()
|
||||||
@@ -32,50 +33,46 @@ function pathFor(template: string, params: Record<string, string>) {
|
|||||||
return Object.entries(params).reduce((result, [key, value]) => result.replace(`:${key}`, value), template)
|
return Object.entries(params).reduce((result, [key, value]) => result.replace(`:${key}`, value), template)
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("session diff with missing patch (#26574)", () => {
|
const withSession = (input?: Parameters<Session.Interface["create"]>[0]) =>
|
||||||
it.live("GET /session/<id>/diff returns 200 when summary_diffs row has no patch", () =>
|
Effect.acquireRelease(
|
||||||
Effect.gen(function* () {
|
Session.Service.use((session) => session.create(input)),
|
||||||
const tmp = yield* Effect.acquireRelease(
|
(created) => Session.Service.use((session) => session.remove(created.id)).pipe(Effect.ignore),
|
||||||
Effect.promise(() => tmpdir({ git: true, config: { formatter: false, lsp: false } })),
|
|
||||||
(t) => Effect.promise(() => t[Symbol.asyncDispose]()),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
yield* Effect.promise(() =>
|
describe("session diff with missing patch (#26574)", () => {
|
||||||
WithInstance.provide({
|
it.instance(
|
||||||
directory: tmp.path,
|
"GET /session/<id>/diff returns 200 when summary_diffs row has no patch",
|
||||||
fn: async () => {
|
() =>
|
||||||
const session = await Effect.runPromise(
|
Effect.gen(function* () {
|
||||||
Effect.provide(
|
const test = yield* TestInstance
|
||||||
Session.Service.use((s) => s.create({ title: "missing-patch" })),
|
const session = yield* withSession({ title: "missing-patch" })
|
||||||
Session.defaultLayer,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Mimic legacy/imported on-disk shape: a diff entry with no
|
// Mimic legacy/imported on-disk shape: a diff entry with no
|
||||||
// `patch` text. Pre-fix the typed response encoder rejects
|
// `patch` text. Pre-fix the typed response encoder rejects
|
||||||
// this and returns 400.
|
// this and returns 400.
|
||||||
await Effect.runPromise(
|
yield* Storage.Service.use((storage) =>
|
||||||
Effect.provide(
|
storage.write(["session_diff", session.id], [{ file: "legacy.txt", additions: 1, deletions: 0 }]),
|
||||||
Storage.Service.use((s) =>
|
)
|
||||||
s.write(["session_diff", session.id], [{ file: "legacy.txt", additions: 1, deletions: 0 }]),
|
|
||||||
),
|
const response = yield* Effect.promise(() =>
|
||||||
Storage.defaultLayer,
|
Promise.resolve(
|
||||||
|
Server.Default().app.request(pathFor(SessionPaths.diff, { sessionID: session.id }), {
|
||||||
|
headers: { "x-opencode-directory": test.directory },
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const headers = { "x-opencode-directory": tmp.path }
|
|
||||||
const response = await Server.Default().app.request(pathFor(SessionPaths.diff, { sessionID: session.id }), {
|
|
||||||
headers,
|
|
||||||
})
|
|
||||||
expect(response.status).toBe(200)
|
expect(response.status).toBe(200)
|
||||||
const body = (await response.json()) as Array<{ file: string; patch?: string; additions: number }>
|
const body = (yield* Effect.promise(() => response.json())) as Array<{
|
||||||
|
file: string
|
||||||
|
patch?: string
|
||||||
|
additions: number
|
||||||
|
}>
|
||||||
expect(body).toHaveLength(1)
|
expect(body).toHaveLength(1)
|
||||||
expect(body[0]?.file).toBe("legacy.txt")
|
expect(body[0]?.file).toBe("legacy.txt")
|
||||||
expect(body[0]?.additions).toBe(1)
|
expect(body[0]?.additions).toBe(1)
|
||||||
expect(body[0]?.patch).toBeUndefined()
|
expect(body[0]?.patch).toBeUndefined()
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}),
|
}),
|
||||||
|
{ git: true, config: { formatter: false, lsp: false } },
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user