@@ -17,12 +17,14 @@ import {
1717import { makeStreamingTimelineFixture } from "../../test-fixtures" ;
1818import type { TurnDiffSummary } from "../../types" ;
1919import { describe , expect , it } from "vite-plus/test" ;
20- import { MessageId , RunId } from "@t3tools/contracts" ;
20+ import { EnvironmentId , MessageId , RunId } from "@t3tools/contracts" ;
21+ import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations" ;
2122import {
2223 computeStableMessagesTimelineRows ,
2324 computeMessageDurationStart ,
2425 deriveMessagesTimelineRows ,
2526 deriveMessagesTimelineRowsWithState ,
27+ shouldCollapseUserMessage ,
2628 liveWorkEntryLabel ,
2729 normalizeCompactToolLabel ,
2830 resolveAssistantMessageCopyState ,
@@ -4889,3 +4891,36 @@ describe("failed turn transcript", () => {
48894891 } ,
48904892 ) ;
48914893} ) ;
4894+
4895+ describe ( "shouldCollapseUserMessage" , ( ) => {
4896+ it ( "measures a quote chip by its label, not its encoded link" , ( ) => {
4897+ const quote = "A long assistant paragraph that the user quoted. " . repeat ( 40 ) ;
4898+ const citation = serializeAssistantCitation ( {
4899+ version : 1 ,
4900+ environmentId : EnvironmentId . make ( "environment" ) ,
4901+ threadId : ThreadId . make ( "thread" ) ,
4902+ messageId : MessageId . make ( "source" ) ,
4903+ text : quote ,
4904+ comment : "Why does this matter?" ,
4905+ start : 0 ,
4906+ end : quote . length ,
4907+ prefix : "" ,
4908+ suffix : "" ,
4909+ } ) ;
4910+
4911+ expect ( shouldCollapseUserMessage ( `${ citation } Can you expand on this?` ) ) . toBe ( false ) ;
4912+ expect ( shouldCollapseUserMessage ( `${ citation } ${ "More text. " . repeat ( 60 ) } ` ) ) . toBe ( true ) ;
4913+ } ) ;
4914+
4915+ it ( "measures file links and context chips by their label" , ( ) => {
4916+ const links = Array . from (
4917+ { length : 8 } ,
4918+ ( _ , index ) =>
4919+ `[file${ index } .ts](/workspace/projects/example/packages/some/deeply/nested/directory/file${ index } .ts)` ,
4920+ ) ;
4921+ const text = `Compare ${ links . join ( ", " ) } with [terminal 1](t3-context://v1/terminal/${ "a" . repeat ( 36 ) } ).` ;
4922+
4923+ expect ( text . length ) . toBeGreaterThan ( 600 ) ;
4924+ expect ( shouldCollapseUserMessage ( text ) ) . toBe ( false ) ;
4925+ } ) ;
4926+ } ) ;
0 commit comments