@@ -276,91 +276,138 @@ function makeThread(
276276}
277277
278278describe ( "buildThreadFeed" , ( ) => {
279- it ( "keeps a submitted answer visible until the same-turn assistant resumes" , ( ) => {
280- const turnId = TurnId . make ( "answer-turn" ) ;
281- const startedAt = "2026-04-01T00:00:00.000Z" ;
282- const submittedAt = "2026-04-01T00:00:03.000Z" ;
283- const latestTurn = { turnId, state : "running" as const , startedAt, completedAt : null } ;
284- const thread = makeThread ( {
285- id : ThreadId . make ( "answer-thread" ) ,
286- projectId : ProjectId . make ( "project-1" ) ,
287- title : "Answer visibility" ,
288- messages : [
289- {
290- id : MessageId . make ( "assistant-question" ) ,
291- role : "assistant" ,
292- text : "Choose a runtime." ,
293- turnId,
294- streaming : true ,
295- createdAt : startedAt ,
296- updatedAt : startedAt ,
297- } ,
298- ] ,
299- activities : [
300- makeActivity ( {
301- id : EventId . make ( "previous-tool" ) ,
302- kind : "tool.completed" ,
303- tone : "tool" ,
304- summary : "Read files" ,
305- createdAt : "2026-04-01T00:00:01.000Z" ,
306- turnId,
307- } ) ,
308- makeActivity ( {
309- id : EventId . make ( "answer" ) ,
310- kind : "user-input.answer-submitted" ,
311- summary : "User input submitted" ,
312- createdAt : submittedAt ,
313- turnId,
314- payload : {
315- requestId : "runtime-question" ,
316- questionTextById : { runtime : "Which runtime?" } ,
317- answers : { runtime : "Node.js" } ,
318- attachmentsByQuestionId : { } ,
279+ it . each ( [ false , true ] ) (
280+ "keeps a submitted answer visible until its response turn resumes (async: %s)" ,
281+ ( async ) => {
282+ const turnId = TurnId . make ( "answer-turn" ) ;
283+ const questionTurnId = async ? TurnId . make ( "original-question-turn" ) : turnId ;
284+ const startedAt = "2026-04-01T00:00:00.000Z" ;
285+ const submittedAt = "2026-04-01T00:00:03.000Z" ;
286+ const latestTurn = { turnId, state : "running" as const , startedAt, completedAt : null } ;
287+ const thread = makeThread ( {
288+ id : ThreadId . make ( "answer-thread" ) ,
289+ projectId : ProjectId . make ( "project-1" ) ,
290+ title : "Answer visibility" ,
291+ messages : [
292+ {
293+ id : MessageId . make ( "assistant-question" ) ,
294+ role : "assistant" ,
295+ text : "Choose a runtime." ,
296+ turnId,
297+ streaming : true ,
298+ createdAt : startedAt ,
299+ updatedAt : startedAt ,
319300 } ,
320- } ) ,
321- ] ,
322- } ) ;
323- const feed = buildThreadFeed ( thread ) ;
324- const present = ( source : ReadonlyArray < ThreadFeedEntry > ) =>
325- deriveThreadFeedPresentation ( source , latestTurn , new Set ( ) , new Set ( ) , startedAt ) ;
326- const answerIsVisible = ( rows : ReadonlyArray < ThreadFeedEntry > ) =>
327- rows . some (
328- ( row ) =>
329- row . type === "activity-group" &&
330- row . activities . some ( ( activity ) => activity . workEntry . questionAnswer ) ,
301+ ...( async
302+ ? [
303+ {
304+ id : MessageId . make ( "async-answer:runtime-question" ) ,
305+ role : "user" as const ,
306+ text : "Node.js" ,
307+ turnId,
308+ streaming : false ,
309+ createdAt : submittedAt ,
310+ updatedAt : submittedAt ,
311+ } ,
312+ ]
313+ : [ ] ) ,
314+ ] ,
315+ activities : [
316+ makeActivity ( {
317+ id : EventId . make ( "previous-tool" ) ,
318+ kind : "tool.completed" ,
319+ tone : "tool" ,
320+ summary : "Read files" ,
321+ createdAt : "2026-04-01T00:00:01.000Z" ,
322+ turnId : questionTurnId ,
323+ } ) ,
324+ makeActivity ( {
325+ id : EventId . make ( "answer" ) ,
326+ kind : "user-input.answer-submitted" ,
327+ summary : "User input submitted" ,
328+ createdAt : submittedAt ,
329+ turnId : questionTurnId ,
330+ payload : {
331+ requestId : "runtime-question" ,
332+ questionTextById : { runtime : "Which runtime?" } ,
333+ answers : { runtime : "Node.js" } ,
334+ attachmentsByQuestionId : { } ,
335+ } ,
336+ } ) ,
337+ ] ,
338+ } ) ;
339+ const feed = buildThreadFeed ( thread ) ;
340+ const present = ( source : ReadonlyArray < ThreadFeedEntry > ) =>
341+ deriveThreadFeedPresentation ( source , latestTurn , new Set ( ) , new Set ( ) , startedAt ) ;
342+ const answerIsVisible = ( rows : ReadonlyArray < ThreadFeedEntry > ) =>
343+ rows . some (
344+ ( row ) =>
345+ row . type === "activity-group" &&
346+ row . activities . some ( ( activity ) => activity . workEntry . questionAnswer ) ,
347+ ) ;
348+ expect ( answerIsVisible ( present ( feed ) ) ) . toBe ( true ) ;
349+ expect ( feed . some ( ( entry ) => entry . type === "message" && entry . message . role === "user" ) ) . toBe (
350+ false ,
331351 ) ;
332- expect ( answerIsVisible ( present ( feed ) ) ) . toBe ( true ) ;
333- const updatedFeed = ( messageTurnId : TurnId , text = "Using Node.js." ) =>
334- feed . map ( ( entry ) =>
335- entry . type === "message"
336- ? {
337- ...entry ,
338- message : {
339- ...entry . message ,
340- text,
341- turnId : messageTurnId ,
342- updatedAt : "2026-04-01T00:00:04.000Z" ,
343- } ,
344- }
345- : entry ,
352+ const answerGroup = feed . find (
353+ ( entry ) =>
354+ entry . type === "activity-group" &&
355+ entry . activities . some ( ( activity ) => activity . workEntry . questionAnswer ) ,
346356 ) ;
347- expect ( answerIsVisible ( present ( updatedFeed ( TurnId . make ( "other-turn" ) ) ) ) ) . toBe ( true ) ;
348- expect ( answerIsVisible ( present ( updatedFeed ( turnId , "" ) ) ) ) . toBe ( true ) ;
349- // Reuse the activity group to exercise presentation-cache invalidation.
350- expect ( answerIsVisible ( present ( updatedFeed ( turnId ) ) ) ) . toBe ( false ) ;
351- expect ( answerIsVisible ( deriveThreadFeedPresentation ( feed , latestTurn , new Set ( ) ) ) ) . toBe ( false ) ;
352- expect (
353- answerIsVisible (
354- deriveThreadFeedPresentation (
355- feed ,
356- { ...latestTurn , state : "completed" , completedAt : "2026-04-01T00:00:05.000Z" } ,
357- new Set ( ) ,
358- new Set ( ) ,
359- startedAt ,
357+ expect ( answerGroup ) . toMatchObject ( { turnId } ) ;
358+ const updatedFeed = ( messageTurnId : TurnId , text = "Using Node.js." ) =>
359+ feed . map ( ( entry ) =>
360+ entry . type === "message"
361+ ? {
362+ ...entry ,
363+ message : {
364+ ...entry . message ,
365+ text,
366+ turnId : messageTurnId ,
367+ updatedAt : "2026-04-01T00:00:04.000Z" ,
368+ } ,
369+ }
370+ : entry ,
371+ ) ;
372+ expect ( answerIsVisible ( present ( updatedFeed ( TurnId . make ( "other-turn" ) ) ) ) ) . toBe ( true ) ;
373+ expect ( answerIsVisible ( present ( updatedFeed ( turnId , "" ) ) ) ) . toBe ( true ) ;
374+ // Reuse the activity group to exercise presentation-cache invalidation.
375+ expect ( answerIsVisible ( present ( updatedFeed ( turnId ) ) ) ) . toBe ( false ) ;
376+ expect (
377+ answerIsVisible (
378+ present (
379+ buildThreadFeed ( {
380+ ...thread ,
381+ activities : [
382+ ...thread . activities ,
383+ makeActivity ( {
384+ id : EventId . make ( "resumed-tool" ) ,
385+ kind : "tool.started" ,
386+ summary : "Running tool" ,
387+ createdAt : "2026-04-01T00:00:04.000Z" ,
388+ turnId,
389+ } ) ,
390+ ] ,
391+ } ) ,
392+ ) ,
360393 ) ,
361- ) ,
362- ) . toBe ( false ) ;
363- } ) ;
394+ ) . toBe ( false ) ;
395+ expect ( answerIsVisible ( deriveThreadFeedPresentation ( feed , latestTurn , new Set ( ) ) ) ) . toBe (
396+ false ,
397+ ) ;
398+ expect (
399+ answerIsVisible (
400+ deriveThreadFeedPresentation (
401+ feed ,
402+ { ...latestTurn , state : "completed" , completedAt : "2026-04-01T00:00:05.000Z" } ,
403+ new Set ( ) ,
404+ new Set ( ) ,
405+ startedAt ,
406+ ) ,
407+ ) ,
408+ ) . toBe ( false ) ;
409+ } ,
410+ ) ;
364411
365412 it ( "folds question answers into tool history and only hides the matching async reply" , ( ) => {
366413 const createdAt = "2026-04-01T00:00:01.000Z" ;
0 commit comments