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:
@@ -2,6 +2,7 @@ import { describe, it, expect } from "bun:test"
|
|||||||
|
|
||||||
import { createMessagesTransformHandler } from "./messages-transform"
|
import { createMessagesTransformHandler } from "./messages-transform"
|
||||||
import { createToolPairValidatorHook } from "../hooks/tool-pair-validator/hook"
|
import { createToolPairValidatorHook } from "../hooks/tool-pair-validator/hook"
|
||||||
|
import { OMO_INTERNAL_INITIATOR_MARKER } from "../shared/internal-initiator-marker"
|
||||||
import type { CreatedHooks } from "../create-hooks"
|
import type { CreatedHooks } from "../create-hooks"
|
||||||
|
|
||||||
type TestPart = {
|
type TestPart = {
|
||||||
@@ -14,6 +15,7 @@ type TestPart = {
|
|||||||
content?: string
|
content?: string
|
||||||
text?: string
|
text?: string
|
||||||
synthetic?: boolean
|
synthetic?: boolean
|
||||||
|
metadata?: { compaction_continue?: boolean }
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestMessage = {
|
type TestMessage = {
|
||||||
@@ -169,10 +171,34 @@ describe("createMessagesTransformHandler", () => {
|
|||||||
await runHandler(hooks, [])
|
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
|
//#given
|
||||||
const messages: TestMessage[] = [
|
const messages: TestMessage[] = [
|
||||||
{ info: { role: "user" }, parts: [{ type: "text", text: "work on this" }] },
|
{ 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" }] },
|
{ info: { role: "assistant" }, parts: [{ type: "text", text: "partial assistant tail" }] },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user