import { expect, test } from "bun:test" import { SessionCompaction } from "@opencode-ai/core/session/compaction" test("compaction prompt preserves detailed work state and relevant files", () => { const prompt = SessionCompaction.buildPrompt({ context: ["conversation history"] }) expect(prompt).toStartWith( "Here is the conversation so far:\n\n\nconversation history\n", ) expect(prompt.indexOf("")).toBeLessThan(prompt.indexOf("Create a new anchored summary")) expect(prompt).toContain("conversation history in the tags above") expect(prompt).toContain("## Work State\n### Completed") expect(prompt).toContain("### Active") expect(prompt).toContain("### Blocked") expect(prompt).toContain("## Relevant Files") }) test("compaction prompt gives update instructions for a prior summary", () => { const prompt = SessionCompaction.buildPrompt({ context: ["new conversation"], previousSummary: "existing summary", }) expect(prompt.indexOf("")).toBeLessThan(prompt.indexOf("")) expect(prompt.indexOf("")).toBeLessThan(prompt.indexOf("The summarizes")) expect(prompt).toContain( "Carry forward objectives, constraints, user directives, decisions, and parallel workstreams from the ", ) expect(prompt).toContain('Move completed work from "Active" to "Completed".') expect(prompt).toContain('Update "Objective" and "Next Move" to reflect the current work state.') }) test("compaction describes tool media without embedding base64", () => { const base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB" const serialized = SessionCompaction.serializeToolContent([ { type: "text", text: "Image read successfully" }, { type: "file", uri: `data:image/png;base64,${base64}`, mime: "image/png", name: "pixel.png", }, ]) expect(serialized).toBe("Image read successfully\n[Attached image/png: pixel.png]") expect(serialized).not.toContain(base64) })