Migrate LLM compaction tail tests (#26734)

This commit is contained in:
Kit Langton
2026-05-10 19:41:28 -04:00
committed by GitHub
parent 8f5f75db12
commit ca8a42c973
@@ -1106,22 +1106,18 @@ describe("session.compaction.process", () => {
{ git: true }, { git: true },
) )
test("falls back to full summary when retained tail media exceeds preserve token budget", async () => { itProcess.instance(
await using tmp = await tmpdir({ git: true }) "falls back to full summary when retained tail media exceeds preserve token budget",
() => {
const stub = llm() const stub = llm()
let captured = "" let captured = ""
stub.push( stub.push(reply("summary", (input) => (captured = JSON.stringify(input.messages))))
reply("summary", (input) => { return Effect.gen(function* () {
captured = JSON.stringify(input.messages) const ssn = yield* SessionNs.Service
}), const session = yield* ssn.create({})
) yield* createUserMessage(session.id, "older")
await WithInstance.provide({ const recent = yield* createUserMessage(session.id, "recent image turn")
directory: tmp.path, yield* ssn.updatePart({
fn: async () => {
const session = await svc.create({})
await user(session.id, "older")
const recent = await user(session.id, "recent image turn")
await svc.updatePart({
id: PartID.ascending(), id: PartID.ascending(),
messageID: recent.id, messageID: recent.id,
sessionID: session.id, sessionID: session.id,
@@ -1130,96 +1126,63 @@ describe("session.compaction.process", () => {
filename: "big.png", filename: "big.png",
url: `data:image/png;base64,${"a".repeat(4_000)}`, url: `data:image/png;base64,${"a".repeat(4_000)}`,
}) })
await SessionCompaction.create({ yield* createSummaryCompaction(session.id)
sessionID: session.id,
agent: "build",
model: ref,
auto: false,
})
const rt = liveRuntime(stub.layer, wide(), cfg({ tail_turns: 1, preserve_recent_tokens: 100 })) const msgs = yield* ssn.messages({ sessionID: session.id })
try {
const msgs = await svc.messages({ sessionID: session.id })
const parent = msgs.at(-1)?.info.id const parent = msgs.at(-1)?.info.id
expect(parent).toBeTruthy() expect(parent).toBeTruthy()
await rt.runPromise( yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
SessionCompaction.Service.use((svc) =>
svc.process({
parentID: parent!,
messages: msgs,
sessionID: session.id,
auto: false,
}),
),
)
const part = await lastCompactionPart(session.id) const part = yield* readCompactionPart(session.id)
expect(part?.type).toBe("compaction") expect(part?.type).toBe("compaction")
expect(part?.tail_start_id).toBeUndefined() expect(part?.tail_start_id).toBeUndefined()
expect(captured).toContain("recent image turn") expect(captured).toContain("recent image turn")
expect(captured).toContain("Attached image/png: big.png") expect(captured).toContain("Attached image/png: big.png")
} finally { }).pipe(
await rt.dispose() Effect.provide(
} compactionProcessLayer({ llm: stub.layer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 100 }) }),
),
)
}, },
}) { git: true },
}) )
test("retains a split turn suffix when a later message fits the preserve token budget", async () => { itProcess.instance(
await using tmp = await tmpdir({ git: true }) "retains a split turn suffix when a later message fits the preserve token budget",
() => {
const stub = llm() const stub = llm()
let captured = "" let captured = ""
stub.push( stub.push(reply("summary", (input) => (captured = JSON.stringify(input.messages))))
reply("summary", (input) => { return Effect.gen(function* () {
captured = JSON.stringify(input.messages) const test = yield* TestInstance
}), const ssn = yield* SessionNs.Service
) const session = yield* ssn.create({})
await WithInstance.provide({ yield* createUserMessage(session.id, "older")
directory: tmp.path, const recent = yield* createUserMessage(session.id, "recent turn")
fn: async () => { const large = yield* createAssistantMessage(session.id, recent.id, test.directory)
const session = await svc.create({}) yield* ssn.updatePart({
await user(session.id, "older")
const recent = await user(session.id, "recent turn")
const large = await assistant(session.id, recent.id, tmp.path)
await svc.updatePart({
id: PartID.ascending(), id: PartID.ascending(),
messageID: large.id, messageID: large.id,
sessionID: session.id, sessionID: session.id,
type: "text", type: "text",
text: "z".repeat(2_000), text: "z".repeat(2_000),
}) })
const keep = await assistant(session.id, recent.id, tmp.path) const keep = yield* createAssistantMessage(session.id, recent.id, test.directory)
await svc.updatePart({ yield* ssn.updatePart({
id: PartID.ascending(), id: PartID.ascending(),
messageID: keep.id, messageID: keep.id,
sessionID: session.id, sessionID: session.id,
type: "text", type: "text",
text: "keep tail", text: "keep tail",
}) })
await SessionCompaction.create({ yield* createSummaryCompaction(session.id)
sessionID: session.id,
agent: "build",
model: ref,
auto: false,
})
const rt = liveRuntime(stub.layer, wide(), cfg({ tail_turns: 1, preserve_recent_tokens: 100 })) const msgs = yield* ssn.messages({ sessionID: session.id })
try {
const msgs = await svc.messages({ sessionID: session.id })
const parent = msgs.at(-1)?.info.id const parent = msgs.at(-1)?.info.id
expect(parent).toBeTruthy() expect(parent).toBeTruthy()
await rt.runPromise( yield* SessionCompaction.use.process({ parentID: parent!, messages: msgs, sessionID: session.id, auto: false })
SessionCompaction.Service.use((svc) =>
svc.process({
parentID: parent!,
messages: msgs,
sessionID: session.id,
auto: false,
}),
),
)
const part = await lastCompactionPart(session.id) const part = yield* readCompactionPart(session.id)
expect(part?.type).toBe("compaction") expect(part?.type).toBe("compaction")
expect(part?.tail_start_id).toBe(keep.id) expect(part?.tail_start_id).toBe(keep.id)
expect(captured).toContain("zzzz") expect(captured).toContain("zzzz")
@@ -1230,12 +1193,14 @@ describe("session.compaction.process", () => {
expect(filtered[1]?.info.role).toBe("assistant") expect(filtered[1]?.info.role).toBe("assistant")
expect(filtered[1]?.info.role === "assistant" ? filtered[1].info.summary : false).toBe(true) expect(filtered[1]?.info.role === "assistant" ? filtered[1].info.summary : false).toBe(true)
expect(filtered.map((msg) => msg.info.id)).not.toContain(large.id) expect(filtered.map((msg) => msg.info.id)).not.toContain(large.id)
} finally { }).pipe(
await rt.dispose() Effect.provide(
} compactionProcessLayer({ llm: stub.layer, config: cfg({ tail_turns: 1, preserve_recent_tokens: 100 }) }),
),
)
}, },
}) { git: true },
}) )
test("allows plugins to disable synthetic continue prompt", async () => { test("allows plugins to disable synthetic continue prompt", async () => {
await using tmp = await tmpdir() await using tmp = await tmpdir()