test(messages-transform): lock assistant-tail continuation guard

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-18 15:49:09 +09:00
parent f20294a702
commit 44ee5e6ae7
+27 -1
View File
@@ -2,6 +2,7 @@ import { describe, it, expect } from "bun:test"
import { createMessagesTransformHandler } from "./messages-transform"
import { createToolPairValidatorHook } from "../hooks/tool-pair-validator/hook"
import { OMO_INTERNAL_INITIATOR_MARKER } from "../shared/internal-initiator-marker"
import type { CreatedHooks } from "../create-hooks"
type TestPart = {
@@ -14,6 +15,7 @@ type TestPart = {
content?: string
text?: string
synthetic?: boolean
metadata?: { compaction_continue?: boolean }
}
type TestMessage = {
@@ -169,10 +171,34 @@ describe("createMessagesTransformHandler", () => {
await runHandler(hooks, [])
})
it("appends a synthetic user turn when transformed messages end with assistant prefill", async () => {
it("#given a completed assistant response tail #when messages transform runs again #then it does not synthesize a continuation user turn", async () => {
//#given
const messages: TestMessage[] = [
{ info: { role: "user" }, parts: [{ type: "text", text: "work on this" }] },
{ info: { role: "assistant" }, parts: [{ type: "text", text: "completed assistant answer" }] },
]
//#when
await runHandler(makeHooks({}), messages)
//#then
expect(messages).toHaveLength(2)
expect(messages.at(-1)?.info.role).toBe("assistant")
})
it("#given an internal compaction continuation reaches an assistant prefill tail #when messages transform runs #then it appends a synthetic user recovery turn", async () => {
//#given
const messages: TestMessage[] = [
{ info: { role: "user" }, parts: [{ type: "text", text: "work on this" }] },
{
info: { role: "user" },
parts: [{
type: "text",
text: `[session recovered - continuing previous task]\n${OMO_INTERNAL_INITIATOR_MARKER}`,
synthetic: true,
metadata: { compaction_continue: true },
}],
},
{ info: { role: "assistant" }, parts: [{ type: "text", text: "partial assistant tail" }] },
]