@@ -442,6 +442,95 @@ 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 ( resolveSidebarV2TopStatus ( { status, isUnread : false , isWoke : false } ) ) . toBe ( status ) ;
473+ expect ( thread . runtime . status ) . toBe ( "running" ) ;
474+ } ,
475+ ) ;
476+
477+ it ( "keeps cached requests and terminal outcomes when the connection is lost" , ( ) => {
478+ const thread = { ...baseThread , connectionPhase : "reconnecting" as const } ;
479+ expect (
480+ resolveThreadStatusPill ( { thread : { ...thread , hasPendingApprovals : true } } ) ?. label ,
481+ ) . toBe ( "Pending Approval" ) ;
482+ expect (
483+ resolveThreadStatusPill ( { thread : { ...thread , hasPendingUserInput : true } } ) ?. label ,
484+ ) . toBe ( "Awaiting Input" ) ;
485+ for ( const status of [ "failed" , "completed" , "cancelled" , "interrupted" , "idle" ] as const ) {
486+ const online = {
487+ ...baseThread ,
488+ runtime : { ...baseThread . runtime , status, activeRunId : null } ,
489+ } ;
490+ const disconnected = { ...online , connectionPhase : "reconnecting" as const } ;
491+ expect ( resolveSidebarThreadStatus ( disconnected ) ) . toBe ( resolveSidebarThreadStatus ( online ) ) ;
492+ expect ( resolveThreadStatusPill ( { thread : disconnected } ) ) . toEqual (
493+ resolveThreadStatusPill ( { thread : online } ) ,
494+ ) ;
495+ }
496+ } ) ;
497+
498+ it . each ( [ "preparing" , "queued" , "starting" , "running" , "waiting" ] as const ) (
499+ "qualifies a cached %s runtime while reconnecting" ,
500+ ( status ) => {
501+ const thread = {
502+ ...baseThread ,
503+ connectionPhase : "reconnecting" as const ,
504+ runtime : { ...baseThread . runtime , status } ,
505+ } ;
506+ expect ( resolveSidebarThreadStatus ( thread ) ) . toBe ( "reconnecting" ) ;
507+ expect ( resolveThreadStatusPill ( { thread } ) ?. label ) . toBe ( "Reconnecting" ) ;
508+ } ,
509+ ) ;
510+
511+ it . each ( [ "failed" , "completed" ] as const ) (
512+ "preserves an unseen %s outcome while disconnected" ,
513+ ( status ) => {
514+ const thread = {
515+ ...baseThread ,
516+ connectionPhase : "reconnecting" as const ,
517+ runtime : { ...baseThread . runtime , status, activeRunId : null } ,
518+ lastVisitedAt : "2026-03-09T09:00:00.000Z" ,
519+ latestRun : {
520+ runId : RunId . make ( "run-ended" ) ,
521+ status,
522+ requestedAt : "2026-03-09T09:30:00.000Z" ,
523+ startedAt : "2026-03-09T09:30:00.000Z" ,
524+ completedAt : "2026-03-09T10:00:00.000Z" ,
525+ assistantMessageId : null ,
526+ } ,
527+ } ;
528+ expect ( resolveThreadStatusPill ( { thread } ) ?. label ) . toBe (
529+ status === "failed" ? "Failed" : "Completed" ,
530+ ) ;
531+ } ,
532+ ) ;
533+
445534 it ( "shows an active thread wait without a pulse and resumes Working when it ends" , ( ) => {
446535 const blocked = { ...baseThread , blockedOnThreadWait : true } ;
447536 expect ( resolveSidebarThreadStatus ( blocked ) ) . toBe ( "waiting" ) ;
0 commit comments