Something went wrong. Try again.
opencode v2 mirror
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import { expect, test } from "bun:test"import type { SessionInfo } from "@opencode/client/promise"import { createSessionMutations } from "./data"
const session: SessionInfo = { id: "ses_test", projectID: "project", cost: 0, tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } }, time: { created: 0, updated: 0 }, location: { directory: "/project" },}
test("keeps a removed session hidden after its deletion event, for lists cached before it", async () => { const release = Promise.withResolvers<void>() const mutation = createSessionMutations(async () => release.promise)
const request = mutation.remove(session.id) expect(mutation.apply([session])).toEqual([]) release.resolve() await request expect(mutation.apply([session])).toEqual([])
mutation.deleted(session.id) expect(mutation.apply([session])).toEqual([])})
test("hides a session another client deleted", () => { const mutation = createSessionMutations(async () => {}) mutation.deleted(session.id) expect(mutation.apply([session])).toEqual([])})
test("rolls back a failed removal", async () => { const release = Promise.withResolvers<void>()
const mutation = createSessionMutations(async () => { await release.promise throw new Error("offline") })
const request = mutation.remove(session.id) expect(mutation.apply([session])).toEqual([]) release.resolve() await expect(request).rejects.toThrow("offline") expect(mutation.apply([session])).toEqual([session])})
test("treats SessionNotFoundError on removal as already deleted", async () => { const mutation = createSessionMutations(async () => { throw JSON.parse('{"_tag":"SessionNotFoundError","sessionID":"ses_test","message":"Session not found: ses_test"}') })
await expect(mutation.remove(session.id)).resolves.toBeUndefined() expect(mutation.apply([session])).toEqual([])})