@@ -114,6 +114,41 @@ const install = (...ids: string[]) => {
114114} ;
115115
116116describe ( 'navigation status synchronization' , ( ) => {
117+ it . each ( [ 'editing' , 'creating' ] as const ) (
118+ 'does not query persisted activity for an unmaterialized %s draft' , async phase => {
119+ const id = `draft-${ phase } ` ;
120+ sources . sessions . set ( id , { ...row ( id ) , historyState : 'new' , isHistorical : false ,
121+ draft : { phase, workspaceId : 'workspace-1' , turnId : 'first-turn' } } ) ;
122+ sources . read . mockResolvedValue ( response ( [ ] ) ) ;
123+ install ( id ) ;
124+ await vi . advanceTimersByTimeAsync ( 60_000 ) ;
125+ window . dispatchEvent ( new Event ( 'focus' ) ) ;
126+ await vi . advanceTimersByTimeAsync ( 100 ) ;
127+ expect ( sources . read ) . not . toHaveBeenCalled ( ) ;
128+ expect ( sessionNavStatusService . getSnapshot ( id ) . kind ) . toBe ( 'idle' ) ;
129+ } ,
130+ ) ;
131+
132+ it ( 'starts activity synchronization as soon as a draft is materialized in its chosen workspace' , async ( ) => {
133+ const id = 'materialized-draft' ;
134+ const draft : Session = { ...row ( id ) , historyState : 'new' , isHistorical : false ,
135+ draft : { phase : 'creating' , workspaceId : 'chosen-workspace' , turnId : 'first-turn' } } ;
136+ sources . sessions . set ( id , draft ) ;
137+ sources . read . mockResolvedValue ( response ( [ activity ( id , 'idle' ) ] ) ) ;
138+ install ( id ) ;
139+ await vi . advanceTimersByTimeAsync ( 100 ) ;
140+ sources . sessions . set ( id , { ...draft , workspaceId : 'chosen-workspace' ,
141+ projectWorkspaceId : 'chosen-project' , draft : { ...draft . draft ! , phase : 'ready' } } ) ;
142+ sources . storeListeners . forEach ( listener => listener ( { sessions : sources . sessions } ) ) ;
143+ await vi . advanceTimersByTimeAsync ( 100 ) ;
144+ expect ( sources . read ) . toHaveBeenCalledExactlyOnceWith ( {
145+ sessionId : id , workspaceId : 'chosen-project' , limit : 1 , sessionIds : [ id ] ,
146+ } ) ;
147+ expect ( sessionNavStatusService . getSnapshot ( id ) . kind ) . toBe ( 'idle' ) ;
148+ sources . events . get ( 'onDialogTurnStarted' ) ! ( { sessionId : id , turnId : 'first-turn' } ) ;
149+ expect ( sessionNavStatusService . getSnapshot ( id ) . kind ) . toBe ( 'running' ) ;
150+ } ) ;
151+
117152 it ( 'keeps a local submission running across a host read that predates host acceptance' , async ( ) => {
118153 const id = 'local-start-race' ;
119154 const pending = { id : 'new-turn' , status : 'pending' , modelRounds : [ ] } as unknown as Session [ 'dialogTurns' ] [ number ] ;
0 commit comments