@@ -291,6 +291,100 @@ function makeThread(
291291}
292292
293293describe ( "buildThreadFeed" , ( ) => {
294+ it ( "keeps completed tool rows stable when another activity arrives" , ( ) => {
295+ const turnId = TurnId . make ( "tool-history" ) ;
296+ const started = makeActivity ( {
297+ id : EventId . make ( "tool-start" ) ,
298+ kind : "tool.updated" ,
299+ summary : "Run checks" ,
300+ createdAt : "2026-04-01T00:00:01.000Z" ,
301+ turnId,
302+ payload : {
303+ toolCallId : "checks" ,
304+ itemType : "command_execution" ,
305+ data : { command : "vp test" } ,
306+ status : "inProgress" ,
307+ } ,
308+ } ) ;
309+ const completed = makeActivity ( {
310+ ...started ,
311+ id : EventId . make ( "tool-complete" ) ,
312+ kind : "tool.completed" ,
313+ createdAt : "2026-04-01T00:00:02.000Z" ,
314+ payload : { toolCallId : "checks" , status : "completed" , detail : "All checks passed" } ,
315+ } ) ;
316+ const thread = { messages : [ ] , activities : [ started , completed ] } ;
317+ const rows = ( activities : ReadonlyArray < OrchestrationThreadActivity > ) =>
318+ buildThreadFeed ( { ...thread , activities } ) . flatMap ( ( entry ) =>
319+ entry . type === "activity-group" ? entry . activities : [ ] ,
320+ ) ;
321+ const previous = rows ( thread . activities ) [ 0 ] ! ;
322+ const appended = makeActivity ( {
323+ id : EventId . make ( "next-tool" ) ,
324+ kind : "tool.completed" ,
325+ summary : "Read file" ,
326+ createdAt : "2026-04-01T00:00:03.000Z" ,
327+ turnId,
328+ payload : { toolCallId : "read" , itemType : "file_read" , status : "completed" } ,
329+ } ) ;
330+ const next = rows ( [ ...thread . activities , appended ] ) ;
331+ expect ( next ) . toHaveLength ( 2 ) ;
332+ expect ( next [ 0 ] ) . toBe ( previous ) ;
333+ expect ( next [ 0 ] ?. getCopyText ( ) ) . toContain ( "All checks passed" ) ;
334+ expect ( next [ 0 ] ?. status ) . toBe ( "success" ) ;
335+
336+ const failed = {
337+ ...completed ,
338+ payload : { toolCallId : "checks" , status : "failed" , detail : "Checks failed" } ,
339+ } ;
340+ const updated = rows ( [ started , failed , appended ] ) ;
341+ expect ( updated [ 0 ] ) . not . toBe ( previous ) ;
342+ expect ( updated [ 0 ] ?. status ) . toBe ( "failure" ) ;
343+ expect ( updated [ 0 ] ?. getCopyText ( ) ) . toContain ( "Checks failed" ) ;
344+ expect ( updated [ 1 ] ) . toBe ( next [ 1 ] ) ;
345+ } ) ;
346+
347+ it ( "recomputes a tool merge when pagination changes its earlier activity" , ( ) => {
348+ const completed = makeActivity ( {
349+ id : EventId . make ( "completion" ) ,
350+ kind : "tool.completed" ,
351+ summary : "Command completed" ,
352+ createdAt : "2026-04-01T00:00:02.000Z" ,
353+ payload : { toolCallId : "call" , status : "completed" , detail : "Done" } ,
354+ } ) ;
355+ const started = makeActivity ( {
356+ ...completed ,
357+ id : EventId . make ( "start" ) ,
358+ kind : "tool.updated" ,
359+ createdAt : "2026-04-01T00:00:01.000Z" ,
360+ payload : {
361+ toolCallId : "call" ,
362+ data : { command : "original command" } ,
363+ status : "inProgress" ,
364+ } ,
365+ } ) ;
366+ const row = ( activities : ReadonlyArray < OrchestrationThreadActivity > ) =>
367+ buildThreadFeed ( { messages : [ ] , activities } ) . flatMap ( ( entry ) =>
368+ entry . type === "activity-group" ? entry . activities : [ ] ,
369+ ) [ 0 ] ! ;
370+ const original = row ( [ started , completed ] ) ;
371+ expect ( original . workEntry . command ) . toBe ( "original command" ) ;
372+ const replaced = row ( [
373+ {
374+ ...started ,
375+ payload : {
376+ toolCallId : "call" ,
377+ data : { command : "replacement command" } ,
378+ status : "inProgress" ,
379+ } ,
380+ } ,
381+ completed ,
382+ ] ) ;
383+ expect ( replaced . workEntry . command ) . toBe ( "replacement command" ) ;
384+ expect ( row ( [ completed ] ) . workEntry . command ) . toBeUndefined ( ) ;
385+ expect ( row ( [ started , completed ] ) . workEntry . command ) . toBe ( "original command" ) ;
386+ } ) ;
387+
294388 it ( "reuses unchanged feed and presentation rows during an assistant text update" , ( ) => {
295389 const completedTurnId = TurnId . make ( "completed-turn" ) ;
296390 const activeTurnId = TurnId . make ( "active-turn" ) ;
0 commit comments