mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-24 06:33:01 -04:00
dab2637217
Co-authored-by: akenra <37288280+akenra@users.noreply.github.com>
48 lines
2.0 KiB
TypeScript
48 lines
2.0 KiB
TypeScript
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<conversation>\nconversation history\n</conversation>",
|
|
)
|
|
expect(prompt.indexOf("</conversation>")).toBeLessThan(prompt.indexOf("Create a new anchored summary"))
|
|
expect(prompt).toContain("conversation history in the <conversation> 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("<conversation>")).toBeLessThan(prompt.indexOf("<prior-summary>"))
|
|
expect(prompt.indexOf("</prior-summary>")).toBeLessThan(prompt.indexOf("The <prior-summary> summarizes"))
|
|
expect(prompt).toContain(
|
|
"Carry forward objectives, constraints, user directives, decisions, and parallel workstreams from the <prior-summary>",
|
|
)
|
|
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)
|
|
})
|