@@ -5,6 +5,7 @@ import * as DateTime from "effect/DateTime";
55import { v2Projection , v2ThreadId } from "./orchestrationV2TestFixtures.ts" ;
66import { mergeOlderHistoryIntoProjection } from "./threadHistoryMerge.ts" ;
77import { applyOrchestrationV2ProjectionEvent } from "./orchestrationV2Projection.ts" ;
8+ import { derivePendingThreadRequests } from "./threadRequests.ts" ;
89
910const NOW = DateTime . makeUnsafe ( "2026-06-20T00:00:00.000Z" ) ;
1011
@@ -223,50 +224,95 @@ describe("threadHistoryMerge", () => {
223224 } ) ;
224225
225226 // regression: #25806 a pending question card retained outside the window shows when paged in
226- it ( "shows a pending request card retained at cold open when its history page arrives" , ( ) => {
227- const recent = row ( 5 ) ;
228- const card = {
229- id : "item-question" as never ,
230- type : "user_input_request" as const ,
231- threadId : v2ThreadId ,
232- runId : null ,
233- nodeId : null ,
234- providerThreadId : null ,
235- providerTurnId : null ,
236- nativeItemRef : null ,
237- parentItemId : null ,
238- ordinal : 1 ,
239- status : "running" as const ,
240- title : null ,
241- requestId : "request-question" as never ,
242- questions : [ ] ,
243- startedAt : NOW ,
244- completedAt : null ,
245- updatedAt : NOW ,
246- } ;
247- const coldOpen = {
248- ...v2Projection ,
249- turnItems : [ card , recent . item ] ,
250- visibleTurnItems : [ { ...recent , position : 0 } ] ,
251- } ;
227+ it . each ( [ "completed" , "rolled_back" ] as const ) (
228+ "keeps a pending question actionable when paging a %s run" ,
229+ ( status ) => {
230+ const recent = row ( 5 ) ;
231+ const runId = "question-run" as never ;
232+ const nodeId = "question-node" as never ;
233+ const card = {
234+ id : "item-question" as never ,
235+ type : "user_input_request" as const ,
236+ threadId : v2ThreadId ,
237+ runId,
238+ nodeId,
239+ providerThreadId : null ,
240+ providerTurnId : null ,
241+ nativeItemRef : null ,
242+ parentItemId : null ,
243+ ordinal : 1 ,
244+ status : "running" as const ,
245+ title : null ,
246+ requestId : "request-question" as never ,
247+ responseMode : "message" as const ,
248+ questions : [ { id : "scope" , header : "Scope" , question : "Which scope?" , options : [ ] } ] ,
249+ startedAt : NOW ,
250+ completedAt : null ,
251+ updatedAt : NOW ,
252+ } ;
253+ const coldOpen = {
254+ ...v2Projection ,
255+ runs : [
256+ {
257+ id : runId ,
258+ threadId : v2ThreadId ,
259+ ordinal : 1 ,
260+ providerInstanceId : v2Projection . thread . providerInstanceId ,
261+ modelSelection : v2Projection . thread . modelSelection ,
262+ providerThreadId : null ,
263+ userMessageId : "question-message" as never ,
264+ rootNodeId : nodeId ,
265+ activeAttemptId : null ,
266+ status,
267+ requestedAt : NOW ,
268+ startedAt : NOW ,
269+ completedAt : NOW ,
270+ checkpointId : null ,
271+ contextHandoffId : null ,
272+ } ,
273+ ] ,
274+ runtimeRequests : [
275+ {
276+ id : card . requestId ,
277+ nodeId,
278+ providerTurnId : null ,
279+ nativeRequestRef : null ,
280+ kind : "user_input" as const ,
281+ status : "pending" as const ,
282+ responseCapability : { type : "message" as const } ,
283+ createdAt : NOW ,
284+ resolvedAt : null ,
285+ } ,
286+ ] ,
287+ turnItems : [ card , recent . item ] ,
288+ visibleTurnItems : [ { ...recent , position : 0 } ] ,
289+ } ;
252290
253- const merged = mergeOlderHistoryIntoProjection ( coldOpen , [
254- { ...row ( 0 ) , position : 0 } ,
255- {
256- position : 1 ,
257- visibility : "local" ,
258- sourceThreadId : v2ThreadId ,
259- sourceItemId : card . id ,
260- item : card ,
261- } ,
262- ] ) ;
291+ const merged = mergeOlderHistoryIntoProjection ( coldOpen , [
292+ { ...row ( 0 ) , position : 0 } ,
293+ {
294+ position : 1 ,
295+ visibility : "local" ,
296+ sourceThreadId : v2ThreadId ,
297+ sourceItemId : card . id ,
298+ item : card ,
299+ } ,
300+ ] ) ;
263301
264- expect ( merged . visibleTurnItems . map ( ( entry ) => String ( entry . sourceItemId ) ) ) . toEqual ( [
265- "item-0" ,
266- "item-question" ,
267- "item-5" ,
268- ] ) ;
269- } ) ;
302+ expect ( merged . visibleTurnItems . map ( ( entry ) => String ( entry . sourceItemId ) ) ) . toEqual (
303+ status === "rolled_back" ? [ "item-0" , "item-5" ] : [ "item-0" , "item-question" , "item-5" ] ,
304+ ) ;
305+ expect ( merged . turnItems ) . toContain ( card ) ;
306+ const pending = derivePendingThreadRequests ( merged ) . userInputs ;
307+ expect ( pending ) . toEqual ( derivePendingThreadRequests ( coldOpen ) . userInputs ) ;
308+ expect ( pending ) . toHaveLength ( 1 ) ;
309+ expect ( pending [ 0 ] ) . toMatchObject ( {
310+ requestId : card . requestId ,
311+ dismissible : true ,
312+ questions : card . questions . map ( ( question ) => ( { ...question , multiSelect : false } ) ) ,
313+ } ) ;
314+ } ,
315+ ) ;
270316
271317 it ( "keeps a history-page interrupt result visible when its request was retained at cold open" , ( ) => {
272318 const runId = "run-interrupt-cold" as never ;
0 commit comments