From 44ee5e6ae71bfc757ddb2ec528a6922fffd4cfc5 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 18 May 2026 15:49:09 +0900 Subject: [PATCH] test(messages-transform): lock assistant-tail continuation guard Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/plugin/messages-transform.test.ts | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/plugin/messages-transform.test.ts b/src/plugin/messages-transform.test.ts index 1620d1c3b..dca36f03c 100644 --- a/src/plugin/messages-transform.test.ts +++ b/src/plugin/messages-transform.test.ts @@ -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" }] }, ]