@@ -24,6 +24,7 @@ import {
2424 evalSampleRate ,
2525 extractToolActivity ,
2626 isCiEvalContext ,
27+ isFirstUserExchange ,
2728 MAX_EVAL_TOOL_OUTPUT_CHARS ,
2829 sanitizeReplayedToolInputs ,
2930 truncateEvalToolOutput ,
@@ -101,6 +102,29 @@ describe("dashboardAgent (mock harness)", () => {
101102 ] ) ;
102103 } ) ;
103104
105+ describe ( "which turn names the chat" , ( ) => {
106+ const user = ( id : string ) => ( { id, role : "user" } ) ;
107+ const assistant = ( id : string ) => ( { id, role : "assistant" } ) ;
108+
109+ it ( "names it on the first exchange" , ( ) => {
110+ expect ( isFirstUserExchange ( [ user ( "u1" ) ] ) ) . toBe ( true ) ;
111+ } ) ;
112+
113+ it ( "still names it when the turn was head-started" , ( ) => {
114+ // The warm first step arrives in `uiMessages`, so the transcript already holds
115+ // two messages on the very first exchange.
116+ expect ( isFirstUserExchange ( [ user ( "u1" ) , assistant ( "a1" ) ] ) ) . toBe ( true ) ;
117+ } ) ;
118+
119+ it ( "does not rename on a later exchange" , ( ) => {
120+ expect ( isFirstUserExchange ( [ user ( "u1" ) , assistant ( "a1" ) , user ( "u2" ) ] ) ) . toBe ( false ) ;
121+ } ) ;
122+
123+ it ( "ignores a watch consent record, which the user never typed" , ( ) => {
124+ expect ( isFirstUserExchange ( [ user ( "watch-request:watch_1" ) , user ( "u1" ) ] ) ) . toBe ( true ) ;
125+ } ) ;
126+ } ) ;
127+
104128 it ( "names the chat once, not on every turn" , async ( ) => {
105129 const { store, calls } = fakeStore ( ) ;
106130 harness = mockChatAgent ( dashboardAgent , {
@@ -112,8 +136,9 @@ describe("dashboardAgent (mock harness)", () => {
112136 } ,
113137 } ) ;
114138
115- await harness . sendMessage ( userMessage ( "first question" ) ) ;
116- await harness . sendMessage ( userMessage ( "second question" ) ) ;
139+ await harness . sendMessage ( userMessage ( "first question" , "u1" ) ) ;
140+ // A distinct id: two turns are two messages, which is what the gate counts.
141+ await harness . sendMessage ( userMessage ( "second question" , "u2" ) ) ;
117142
118143 expect ( calls . setChatTitleIfDefault ) . toHaveLength ( 1 ) ;
119144 } ) ;
0 commit comments