+21

![opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



James Long
Brendan Allan
Kit Langton
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Affan Ali
affanali2k3
Frank
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
Aiden Cline
Jay V
Dax Raad
Aarav Sareen
OpeOginni
Luke Parker
Ben Guthrie
Dax
Filip
Max Anderson
Brendan Allan
Jack
Shoubhit Dash
Dustin Deus
starptech
Aiden Cline
usrnk1
Jay
runvip
opencode
Julian Coy
Vladimir Glafirov
8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
98 lines
4.0 KiB
TypeScript
98 lines
4.0 KiB
TypeScript
/**
|
|
* Regression test for the same bug class as #26574 (sibling of #26566 and
|
|
* #26553). The Desktop app calls GET /session/<id>/diff; before #26574
|
|
* the response was Schema-encoded against `Snapshot.FileDiff` with
|
|
* `patch: Schema.String` (required), so any session whose stored
|
|
* `summary_diffs` had a row without `patch` returned HTTP 400 and the
|
|
* session never loaded. Legacy session-level diffs are no longer surfaced,
|
|
* but the endpoint remains compatible and must still return successfully.
|
|
*
|
|
* This test inserts a session row with a missing-patch diff entry and
|
|
* asserts that GET /session/<id>/diff returns 200 with empty data.
|
|
*/
|
|
import { afterEach, describe, expect } from "bun:test"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { Effect, Layer } from "effect"
|
|
import { SessionPaths } from "@/server/routes/instance/httpapi/groups/session"
|
|
import { Session } from "@/session/session"
|
|
import { Storage } from "@/storage/storage"
|
|
import { SessionV1 } from "@opencode-ai/core/v1/session"
|
|
import { MessageID } from "@/session/schema"
|
|
import { ProviderV2 } from "@opencode-ai/core/provider"
|
|
import { ModelV2 } from "@opencode-ai/core/model"
|
|
import { resetDatabase } from "../fixture/db"
|
|
import { disposeAllInstances, TestInstance } from "../fixture/fixture"
|
|
import { testEffect } from "../lib/effect"
|
|
import { httpApiLayer, requestInDirectory } from "./httpapi-layer"
|
|
|
|
const it = testEffect(Layer.mergeAll(LayerNode.compile(LayerNode.group([Session.node, Storage.node])), httpApiLayer))
|
|
|
|
afterEach(async () => {
|
|
await disposeAllInstances()
|
|
await resetDatabase()
|
|
})
|
|
|
|
function pathFor(template: string, params: Record<string, string>) {
|
|
return Object.entries(params).reduce((result, [key, value]) => result.replace(`:${key}`, value), template)
|
|
}
|
|
|
|
const withSession = (input?: Parameters<Session.Interface["create"]>[0]) =>
|
|
Effect.acquireRelease(Session.use.create(input), (created) => Session.use.remove(created.id).pipe(Effect.ignore))
|
|
|
|
describe("session diff with missing patch (#26574)", () => {
|
|
it.instance(
|
|
"GET /session/<id>/diff ignores legacy session-level diff storage",
|
|
() =>
|
|
Effect.gen(function* () {
|
|
const test = yield* TestInstance
|
|
const session = yield* withSession({ title: "missing-patch" })
|
|
|
|
// Mimic legacy/imported on-disk shape: a diff entry with no
|
|
// `patch` text. Pre-fix the typed response encoder rejects
|
|
// this and returns 400.
|
|
yield* Storage.Service.use((storage) =>
|
|
storage.write(["session_diff", session.id], [{ file: "legacy.txt", additions: 1, deletions: 0 }]),
|
|
)
|
|
|
|
const response = yield* requestInDirectory(
|
|
pathFor(SessionPaths.diff, { sessionID: session.id }),
|
|
test.directory,
|
|
)
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(yield* response.json).toEqual([])
|
|
}),
|
|
{ git: true, config: { formatter: false, lsp: false } },
|
|
)
|
|
|
|
it.instance(
|
|
"GET /session/<id>/diff returns requested turn diffs",
|
|
() =>
|
|
Effect.gen(function* () {
|
|
const test = yield* TestInstance
|
|
const session = yield* withSession({ title: "turn-diff" })
|
|
const messageID = MessageID.ascending()
|
|
yield* Session.use.updateMessage({
|
|
id: messageID,
|
|
sessionID: session.id,
|
|
role: "user",
|
|
time: { created: Date.now() },
|
|
agent: "build",
|
|
model: { providerID: ProviderV2.ID.make("test"), modelID: ModelV2.ID.make("model") },
|
|
summary: {
|
|
diffs: [{ file: "turn.ts", additions: 1, deletions: 0, status: "modified" }],
|
|
},
|
|
} satisfies SessionV1.User)
|
|
|
|
const response = yield* requestInDirectory(
|
|
`${pathFor(SessionPaths.diff, { sessionID: session.id })}?messageID=${messageID}`,
|
|
test.directory,
|
|
)
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(yield* response.json).toEqual([{ file: "turn.ts", additions: 1, deletions: 0, status: "modified" }])
|
|
}),
|
|
{ git: true, config: { formatter: false, lsp: false } },
|
|
)
|
|
})
|