@@ -298,6 +298,35 @@ describe("SessionService", () => {
298298 } ) ;
299299
300300 describe ( "connectToTask" , ( ) => {
301+ it ( "skips local connection for cloud runs" , async ( ) => {
302+ const service = getSessionService ( ) ;
303+
304+ await service . connectToTask ( {
305+ task : createMockTask ( {
306+ latest_run : {
307+ id : "run-123" ,
308+ task : "task-123" ,
309+ team : 123 ,
310+ environment : "cloud" ,
311+ status : "in_progress" ,
312+ log_url : "https://logs.example.com/run-123" ,
313+ error_message : null ,
314+ output : null ,
315+ state : { } ,
316+ branch : "main" ,
317+ created_at : "2024-01-01T00:00:00Z" ,
318+ updated_at : "2024-01-01T00:00:00Z" ,
319+ completed_at : null ,
320+ } ,
321+ } ) ,
322+ repoPath : "/repo" ,
323+ } ) ;
324+
325+ expect ( mockAuth . fetchAuthState ) . not . toHaveBeenCalled ( ) ;
326+ expect ( mockTrpcAgent . reconnect . mutate ) . not . toHaveBeenCalled ( ) ;
327+ expect ( mockSessionStoreSetters . setSession ) . not . toHaveBeenCalled ( ) ;
328+ } ) ;
329+
301330 it ( "skips connection if already connected" , async ( ) => {
302331 const service = getSessionService ( ) ;
303332 const mockSession = createMockSession ( { status : "connected" } ) ;
@@ -457,6 +486,40 @@ describe("SessionService", () => {
457486 } ) ;
458487
459488 describe ( "watchCloudTask" , ( ) => {
489+ it ( "resets a same-run preloaded session before the first cloud snapshot" , ( ) => {
490+ const service = getSessionService ( ) ;
491+ mockSessionStoreSetters . getSessionByTaskId . mockReturnValue (
492+ createMockSession ( {
493+ taskRunId : "run-123" ,
494+ taskId : "task-123" ,
495+ taskTitle : "Cloud Task" ,
496+ events : [ { type : "acp_message" , ts : 1 , message : { method : "test" } } ] ,
497+ } ) ,
498+ ) ;
499+
500+ service . watchCloudTask (
501+ "task-123" ,
502+ "run-123" ,
503+ "https://app.example.com" ,
504+ 2 ,
505+ ) ;
506+
507+ expect ( mockSessionStoreSetters . setSession ) . toHaveBeenCalledWith (
508+ expect . objectContaining ( {
509+ taskRunId : "run-123" ,
510+ taskId : "task-123" ,
511+ taskTitle : "Cloud Task" ,
512+ isCloud : true ,
513+ status : "disconnected" ,
514+ events : [ ] ,
515+ } ) ,
516+ ) ;
517+ expect ( mockSessionStoreSetters . updateSession ) . not . toHaveBeenCalledWith (
518+ "run-123" ,
519+ expect . objectContaining ( { isCloud : true } ) ,
520+ ) ;
521+ } ) ;
522+
460523 it ( "subscribes to cloud updates before starting the watcher" , async ( ) => {
461524 const service = getSessionService ( ) ;
462525
0 commit comments