@@ -4467,6 +4467,40 @@ describe("Cline", () => {
44674467 expect ( messageUpdates . map ( ( { text } ) => text ) ) . toEqual ( [ "second" ] )
44684468 } )
44694469
4470+ it ( "holds a queued update until the 120ms interval elapses" , async ( ) => {
4471+ const { task, messageUpdates } = createStreamingTask ( )
4472+
4473+ await task . say ( "text" , "first" , undefined , true )
4474+ await task . say ( "text" , "second" , undefined , true )
4475+ await task . say ( "text" , "third" , undefined , true )
4476+ expect ( messageUpdates . map ( ( { text } ) => text ) ) . toEqual ( [ "second" ] )
4477+
4478+ await vi . advanceTimersByTimeAsync ( 119 )
4479+ expect ( messageUpdates . map ( ( { text } ) => text ) ) . toEqual ( [ "second" ] )
4480+
4481+ await vi . advanceTimersByTimeAsync ( 1 )
4482+ expect ( messageUpdates . map ( ( { text } ) => text ) ) . toEqual ( [ "second" , "third" ] )
4483+ } )
4484+
4485+ it ( "delivers a queued update for one message before updating a different message" , async ( ) => {
4486+ const { task, messageUpdates } = createStreamingTask ( )
4487+
4488+ await task . say ( "reasoning" , "r1" , undefined , true )
4489+ await task . say ( "reasoning" , "r2" , undefined , true )
4490+ await task . say ( "reasoning" , "r3" , undefined , true )
4491+ expect ( messageUpdates . map ( ( { text } ) => text ) ) . toEqual ( [ "r2" ] )
4492+
4493+ // A new message starts, then streams: its update must not replace the queued "r3".
4494+ // Message timestamps are Date.now(), which fake timers freeze, so step the clock.
4495+ await vi . advanceTimersByTimeAsync ( 1 )
4496+ await task . say ( "text" , "t1" , undefined , true )
4497+ await task . say ( "text" , "t2" , undefined , true )
4498+ expect ( messageUpdates . map ( ( { text } ) => text ) ) . toEqual ( [ "r2" , "r3" ] )
4499+
4500+ await vi . advanceTimersByTimeAsync ( 500 )
4501+ expect ( messageUpdates . map ( ( { text } ) => text ) ) . toEqual ( [ "r2" , "r3" , "t2" ] )
4502+ } )
4503+
44704504 it ( "posts updates that are far enough apart immediately" , async ( ) => {
44714505 const { task, messageUpdates } = createStreamingTask ( )
44724506
0 commit comments