@@ -21,12 +21,14 @@ import {
2121import { makeStreamingTimelineFixture } from "../../test-fixtures" ;
2222import type { TurnDiffSummary } from "../../types" ;
2323import { describe , expect , it } from "vite-plus/test" ;
24- import { MessageId , RunId } from "@t3tools/contracts" ;
24+ import { EnvironmentId , MessageId , RunId } from "@t3tools/contracts" ;
25+ import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations" ;
2526import {
2627 computeStableMessagesTimelineRows ,
2728 computeMessageDurationStart ,
2829 deriveMessagesTimelineRows ,
2930 deriveMessagesTimelineRowsWithState ,
31+ shouldCollapseUserMessage ,
3032 liveWorkEntryLabel ,
3133 normalizeCompactToolLabel ,
3234 resolveAssistantMessageCopyState ,
@@ -5162,3 +5164,36 @@ describe("live subagents after their parent turn settles", () => {
51625164 expect ( rows . map ( ( row ) => row . id ) ) . toEqual ( [ `attempt-fold:${ attempt . id } ` , "child" ] ) ;
51635165 } ) ;
51645166} ) ;
5167+
5168+ describe ( "shouldCollapseUserMessage" , ( ) => {
5169+ it ( "measures a quote chip by its label, not its encoded link" , ( ) => {
5170+ const quote = "A long assistant paragraph that the user quoted. " . repeat ( 40 ) ;
5171+ const citation = serializeAssistantCitation ( {
5172+ version : 1 ,
5173+ environmentId : EnvironmentId . make ( "environment" ) ,
5174+ threadId : ThreadId . make ( "thread" ) ,
5175+ messageId : MessageId . make ( "source" ) ,
5176+ text : quote ,
5177+ comment : "Why does this matter?" ,
5178+ start : 0 ,
5179+ end : quote . length ,
5180+ prefix : "" ,
5181+ suffix : "" ,
5182+ } ) ;
5183+
5184+ expect ( shouldCollapseUserMessage ( `${ citation } Can you expand on this?` ) ) . toBe ( false ) ;
5185+ expect ( shouldCollapseUserMessage ( `${ citation } ${ "More text. " . repeat ( 60 ) } ` ) ) . toBe ( true ) ;
5186+ } ) ;
5187+
5188+ it ( "measures file links and context chips by their label" , ( ) => {
5189+ const links = Array . from (
5190+ { length : 8 } ,
5191+ ( _ , index ) =>
5192+ `[file${ index } .ts](/workspace/projects/example/packages/some/deeply/nested/directory/file${ index } .ts)` ,
5193+ ) ;
5194+ const text = `Compare ${ links . join ( ", " ) } with [terminal 1](t3-context://v1/terminal/${ "a" . repeat ( 36 ) } ).` ;
5195+
5196+ expect ( text . length ) . toBeGreaterThan ( 600 ) ;
5197+ expect ( shouldCollapseUserMessage ( text ) ) . toBe ( false ) ;
5198+ } ) ;
5199+ } ) ;
0 commit comments