@@ -442,6 +442,94 @@ describe("resolveThreadStatusPill", () => {
442442 } ,
443443 } ;
444444
445+ it ( "does not claim live work while the environment is reconnecting" , ( ) => {
446+ const thread = { ...baseThread , connectionPhase : "reconnecting" as const } ;
447+ expect ( resolveSidebarThreadStatus ( thread ) ) . toBe ( "reconnecting" ) ;
448+ expect ( resolveThreadStatusPill ( { thread } ) ) . toMatchObject ( {
449+ label : "Reconnecting" ,
450+ pulse : false ,
451+ } ) ;
452+ } ) ;
453+
454+ it . each ( [
455+ [ "connecting" , "connecting" , "Connecting" ] ,
456+ [ "reconnecting" , "reconnecting" , "Reconnecting" ] ,
457+ [ "offline" , "offline" , "Offline" ] ,
458+ [ "error" , "offline" , "Offline" ] ,
459+ [ "unsupported" , "offline" , "Offline" ] ,
460+ [ "available" , "offline" , "Offline" ] ,
461+ [ "connected" , "working" , "Working" ] ,
462+ [ undefined , "working" , "Working" ] ,
463+ ] as const ) (
464+ "presents cached running work with connection phase %s" ,
465+ ( connectionPhase , status , label ) => {
466+ const thread = { ...baseThread , connectionPhase } ;
467+ expect ( resolveSidebarThreadStatus ( thread ) ) . toBe ( status ) ;
468+ expect ( resolveThreadStatusPill ( { thread } ) ) . toMatchObject ( {
469+ label,
470+ pulse : status === "working" ,
471+ } ) ;
472+ expect ( thread . runtime . status ) . toBe ( "running" ) ;
473+ } ,
474+ ) ;
475+
476+ it ( "keeps cached requests and terminal outcomes when the connection is lost" , ( ) => {
477+ const thread = { ...baseThread , connectionPhase : "reconnecting" as const } ;
478+ expect (
479+ resolveThreadStatusPill ( { thread : { ...thread , hasPendingApprovals : true } } ) ?. label ,
480+ ) . toBe ( "Pending Approval" ) ;
481+ expect (
482+ resolveThreadStatusPill ( { thread : { ...thread , hasPendingUserInput : true } } ) ?. label ,
483+ ) . toBe ( "Awaiting Input" ) ;
484+ for ( const status of [ "failed" , "completed" , "cancelled" , "interrupted" , "idle" ] as const ) {
485+ const online = {
486+ ...baseThread ,
487+ runtime : { ...baseThread . runtime , status, activeRunId : null } ,
488+ } ;
489+ const disconnected = { ...online , connectionPhase : "reconnecting" as const } ;
490+ expect ( resolveSidebarThreadStatus ( disconnected ) ) . toBe ( resolveSidebarThreadStatus ( online ) ) ;
491+ expect ( resolveThreadStatusPill ( { thread : disconnected } ) ) . toEqual (
492+ resolveThreadStatusPill ( { thread : online } ) ,
493+ ) ;
494+ }
495+ } ) ;
496+
497+ it . each ( [ "preparing" , "queued" , "starting" , "running" , "waiting" ] as const ) (
498+ "qualifies a cached %s runtime while reconnecting" ,
499+ ( status ) => {
500+ const thread = {
501+ ...baseThread ,
502+ connectionPhase : "reconnecting" as const ,
503+ runtime : { ...baseThread . runtime , status } ,
504+ } ;
505+ expect ( resolveSidebarThreadStatus ( thread ) ) . toBe ( "reconnecting" ) ;
506+ expect ( resolveThreadStatusPill ( { thread } ) ?. label ) . toBe ( "Reconnecting" ) ;
507+ } ,
508+ ) ;
509+
510+ it . each ( [ "failed" , "completed" ] as const ) (
511+ "preserves an unseen %s outcome while disconnected" ,
512+ ( status ) => {
513+ const thread = {
514+ ...baseThread ,
515+ connectionPhase : "reconnecting" as const ,
516+ runtime : { ...baseThread . runtime , status, activeRunId : null } ,
517+ lastVisitedAt : "2026-03-09T09:00:00.000Z" ,
518+ latestRun : {
519+ runId : RunId . make ( "run-ended" ) ,
520+ status,
521+ requestedAt : "2026-03-09T09:30:00.000Z" ,
522+ startedAt : "2026-03-09T09:30:00.000Z" ,
523+ completedAt : "2026-03-09T10:00:00.000Z" ,
524+ assistantMessageId : null ,
525+ } ,
526+ } ;
527+ expect ( resolveThreadStatusPill ( { thread } ) ?. label ) . toBe (
528+ status === "failed" ? "Failed" : "Completed" ,
529+ ) ;
530+ } ,
531+ ) ;
532+
445533 it ( "shows an active thread wait without a pulse and resumes Working when it ends" , ( ) => {
446534 const blocked = { ...baseThread , blockedOnThreadWait : true } ;
447535 expect ( resolveSidebarThreadStatus ( blocked ) ) . toBe ( "waiting" ) ;
0 commit comments