From a956150945884ed703aa363cf50e4deada9f15e1 Mon Sep 17 00:00:00 2001 From: James Long Date: Thu, 26 Nov 2026 12:34:47 -0500 Subject: [PATCH] fix(session-ui): keep a script's Output when its changes are grouped (#66638) --- .../src/timeline/script-output.test.ts | 50 +++++++++++++++++++ .../session-ui/src/timeline/script-output.ts | 5 +- .../session-ui/src/timeline/timeline-row.ts | 9 ++-- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/packages/session-ui/src/timeline/script-output.test.ts b/packages/session-ui/src/timeline/script-output.test.ts index a7c6feb8d57..ea0c11a99c8 100644 --- a/packages/session-ui/src/timeline/script-output.test.ts +++ b/packages/session-ui/src/timeline/script-output.test.ts @@ -40,6 +40,41 @@ const rows = [ }), ] +// Changes grouped into a summary row with other edits, as Quiet places them, which the row may draw closed. +const grouped = [ + rows[0]!, + new TimelineRow.AssistantPart({ + userMessageID: "msg_u", + group: { + key: "context:msg_a:script:file:0:a.ts", + type: "context", + refs: [ + { messageID: "msg_a", partID: "script:file:0:a.ts" }, + { messageID: "msg_a", partID: "script:file:1:b.ts" }, + ], + }, + previousAssistantPart: true, + spacing: "tool", + }), +] + +// The script and its changes as items of one group, as Compact places them. +const together = [ + new TimelineRow.AssistantPart({ + userMessageID: "msg_u", + group: { + key: "context:msg_a:script", + type: "context", + refs: [ + { messageID: "msg_a", partID: "script" }, + { messageID: "msg_a", partID: "script:file:0:a.ts" }, + { messageID: "msg_a", partID: "script:file:1:b.ts" }, + ], + }, + previousAssistantPart: false, + }), +] + describe("scriptOutputLayout", () => { test("moves a script's Output after its last change in the flat layout", () => { const layout = scriptOutputLayout(rows, messages, true) @@ -48,6 +83,21 @@ describe("scriptOutputLayout", () => { expect([...layout.outputAfter.keys()]).toEqual(["msg_a:script:file:1:b.ts"]) }) + test("keeps a script's Output under its steps when its changes are grouped into a summary row", () => { + const layout = scriptOutputLayout(grouped, messages, true) + + expect(layout.afterChanges.size).toBe(0) + expect(layout.outputAfter.size).toBe(0) + expect(TimelineRow.scriptChanges(grouped[1]!)).toBe(false) + }) + + test("moves a script's Output after its last change when they share its group", () => { + const layout = scriptOutputLayout(together, messages, true) + + expect([...layout.afterChanges]).toEqual(["script"]) + expect([...layout.outputAfter.keys()]).toEqual(["msg_a:script:file:1:b.ts"]) + }) + test("moves nothing without the flat layout", () => { const layout = scriptOutputLayout(rows, messages, false) diff --git a/packages/session-ui/src/timeline/script-output.ts b/packages/session-ui/src/timeline/script-output.ts index 81678b56e18..4c706ff87c9 100644 --- a/packages/session-ui/src/timeline/script-output.ts +++ b/packages/session-ui/src/timeline/script-output.ts @@ -6,8 +6,9 @@ type Tool = Extract