mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-25 12:50:35 -04:00
302e9b45ab
Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: BB84 <110078428+BB-84C@users.noreply.github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Sebastian <hasta84@gmail.com> Co-authored-by: Jérôme Benoit <jerome.benoit@sap.com> Co-authored-by: Test User <test@test.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Rahul A Mistry <149420892+ProdigyRahul@users.noreply.github.com> Co-authored-by: Qiping Li <liqiping1991@gmail.com> Co-authored-by: liqiping <liqiping@msh.team> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Matthias Reso <13337103+mreso@users.noreply.github.com> Co-authored-by: tobwen <1864057+tobwen@users.noreply.github.com> Co-authored-by: Daniel Polito <danielbpolito@gmail.com> Co-authored-by: opencode <noreply@opencode.ai> Co-authored-by: Devin R Leopold <devin.leopold@gmail.com> Co-authored-by: Zach Bruggeman <mail@bruggie.com> Co-authored-by: Zach Bruggeman <zbruggeman@ramp.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: David Siewert <david1gruppenplan@gmail.com> Co-authored-by: Andrei Dziahel <develop7@develop7.info> Co-authored-by: adityachaudhary99 <adityaachaudhary2003@gmail.com> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: Matt Carey <mcarey@cloudflare.com>
105 lines
3.6 KiB
TypeScript
105 lines
3.6 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import type { Message, Part, PermissionRequest, QuestionRequest, SessionStatus, Todo } from "@opencode-ai/sdk/v2/client"
|
|
import type { FileDiffInfo } from "@opencode-ai/client/promise"
|
|
import { dropSessionCaches, pickSessionCacheEvictions } from "./session-cache"
|
|
|
|
const msg = (id: string, sessionID: string) =>
|
|
({
|
|
id,
|
|
sessionID,
|
|
role: "user",
|
|
time: { created: 1 },
|
|
agent: "assistant",
|
|
model: { providerID: "openai", modelID: "gpt" },
|
|
}) as Message
|
|
|
|
const part = (id: string, sessionID: string, messageID: string) =>
|
|
({
|
|
id,
|
|
sessionID,
|
|
messageID,
|
|
type: "text",
|
|
text: id,
|
|
}) as Part
|
|
|
|
describe("app session cache", () => {
|
|
test("dropSessionCaches clears orphaned parts without message rows", () => {
|
|
const store: {
|
|
session_status: Record<string, SessionStatus | undefined>
|
|
session_diff: Record<string, FileDiffInfo[] | undefined>
|
|
todo: Record<string, Todo[] | undefined>
|
|
message: Record<string, Message[] | undefined>
|
|
session_message: Record<string, never[] | undefined>
|
|
part: Record<string, Part[] | undefined>
|
|
permission: Record<string, PermissionRequest[] | undefined>
|
|
question: Record<string, QuestionRequest[] | undefined>
|
|
part_text_accum_delta: Record<string, string | undefined>
|
|
} = {
|
|
session_status: { ses_1: { type: "busy" } as SessionStatus },
|
|
session_diff: { ses_1: [] },
|
|
todo: { ses_1: [] as Todo[] },
|
|
message: {},
|
|
session_message: {},
|
|
part: { msg_1: [part("prt_1", "ses_1", "msg_1")] },
|
|
permission: { ses_1: [] as PermissionRequest[] },
|
|
question: { ses_1: [] as QuestionRequest[] },
|
|
part_text_accum_delta: { prt_1: "streamed text" },
|
|
}
|
|
|
|
dropSessionCaches(store, ["ses_1"])
|
|
|
|
expect(store.message.ses_1).toBeUndefined()
|
|
expect(store.part.msg_1).toBeUndefined()
|
|
expect(store.part_text_accum_delta.prt_1).toBeUndefined()
|
|
expect(store.todo.ses_1).toBeUndefined()
|
|
expect(store.session_diff.ses_1).toBeUndefined()
|
|
expect(store.session_status.ses_1).toBeUndefined()
|
|
expect(store.permission.ses_1).toBeUndefined()
|
|
expect(store.question.ses_1).toBeUndefined()
|
|
})
|
|
|
|
test("dropSessionCaches clears message-backed parts", () => {
|
|
const m = msg("msg_1", "ses_1")
|
|
const store: {
|
|
session_status: Record<string, SessionStatus | undefined>
|
|
session_diff: Record<string, FileDiffInfo[] | undefined>
|
|
todo: Record<string, Todo[] | undefined>
|
|
message: Record<string, Message[] | undefined>
|
|
session_message: Record<string, never[] | undefined>
|
|
part: Record<string, Part[] | undefined>
|
|
permission: Record<string, PermissionRequest[] | undefined>
|
|
question: Record<string, QuestionRequest[] | undefined>
|
|
part_text_accum_delta: Record<string, string | undefined>
|
|
} = {
|
|
session_status: {},
|
|
session_diff: {},
|
|
todo: {},
|
|
message: { ses_1: [m] },
|
|
session_message: {},
|
|
part: { [m.id]: [part("prt_1", "ses_1", m.id)] },
|
|
permission: {},
|
|
question: {},
|
|
part_text_accum_delta: {},
|
|
}
|
|
|
|
dropSessionCaches(store, ["ses_1"])
|
|
|
|
expect(store.message.ses_1).toBeUndefined()
|
|
expect(store.part[m.id]).toBeUndefined()
|
|
})
|
|
|
|
test("pickSessionCacheEvictions preserves requested sessions", () => {
|
|
const seen = new Set(["ses_1", "ses_2", "ses_3"])
|
|
|
|
const stale = pickSessionCacheEvictions({
|
|
seen,
|
|
keep: "ses_4",
|
|
limit: 2,
|
|
preserve: ["ses_1"],
|
|
})
|
|
|
|
expect(stale).toEqual(["ses_2", "ses_3"])
|
|
expect([...seen]).toEqual(["ses_1", "ses_4"])
|
|
})
|
|
})
|