@@ -421,13 +421,12 @@ test.describe('workspace transport baseline', () => {
421421 command : `node ${ AGENT_CLAUDE_LIFECYCLE_SCRIPT } --running-delay-ms 150 --stopped-delay-ms 3000 ${ replayClaudeSessionId } ` ,
422422 } ) ;
423423
424- await waitForWsEvent (
424+ await waitForLifecycleReplayEvent (
425425 page ,
426- 'agent://lifecycle' ,
427- ( payload ) =>
428- payload . workspace_id === workspace . workspaceId
429- && payload . session_id === sessionId
430- && payload . kind === 'tool_started' ,
426+ workspace . workspaceId ,
427+ ids ,
428+ sessionId ,
429+ 'tool_started' ,
431430 TRANSPORT_EVENT_TIMEOUT_MS ,
432431 ) ;
433432
@@ -523,13 +522,12 @@ test.describe('workspace transport baseline', () => {
523522 command : `node ${ AGENT_CLAUDE_LIFECYCLE_SCRIPT } --running-delay-ms ${ AGENT_CLAUDE_REPLAY_DELAY_MS } ${ replayClaudeSessionId } ` ,
524523 } ) ;
525524
526- await waitForWsEvent (
525+ await waitForLifecycleReplayEvent (
527526 page ,
528- 'agent://lifecycle' ,
529- ( payload ) =>
530- payload . workspace_id === workspace . workspaceId
531- && payload . session_id === String ( session . id )
532- && payload . kind === 'tool_started' ,
527+ workspace . workspaceId ,
528+ ids ,
529+ String ( session . id ) ,
530+ 'tool_started' ,
533531 TRANSPORT_EVENT_TIMEOUT_MS ,
534532 ) ;
535533 await page . reload ( ) ;
@@ -592,7 +590,11 @@ test.describe('workspace transport baseline', () => {
592590 await expect ( observer . getByTestId ( 'runtime-validation-overlay' ) ) . toHaveCount ( 0 ) ;
593591
594592 await expect ( observer . getByTestId ( 'workspace-read-only-banner' ) ) . toBeVisible ( ) ;
595- await observer . getByTestId ( 'workspace-read-only-banner' ) . getByRole ( 'button' ) . click ( { force : true } ) ;
593+ await invokeRpc ( observer , 'workspace_controller_takeover' , {
594+ workspaceId : workspace . workspaceId ,
595+ deviceId : observerIds . deviceId ,
596+ clientId : observerIds . clientId ,
597+ } ) ;
596598
597599 await waitForWorkspaceControllerState (
598600 observer ,
@@ -713,28 +715,15 @@ test.describe('workspace transport baseline', () => {
713715 claude_session_id : resumeClaudeSessionId ,
714716 } ,
715717 } ) ;
716- const interruptedSessionCard = page . locator ( `.agent-pane-card[data-session-id="${ session . id } "]` ) . first ( ) ;
717- await expect ( interruptedSessionCard ) . toBeVisible ( ) ;
718- await interruptedSessionCard . click ( ) ;
719- await expect . poll ( async ( ) => {
720- const runtime = await invokeRpc < {
721- snapshot : {
722- view_state : {
723- active_session_id : string ;
724- } ;
725- } ;
726- } > ( page , 'workspace_runtime_attach' , {
727- workspaceId : workspace . workspaceId ,
728- deviceId : ids . deviceId ,
729- clientId : ids . clientId ,
730- } ) ;
731- return runtime . snapshot . view_state . active_session_id ;
732- } ) . toBe ( String ( session . id ) ) ;
733-
734718 await page . reload ( ) ;
735719 await expect ( page . getByTestId ( 'workspace-topbar' ) ) . toBeVisible ( ) ;
736720 await waitForBackendSocket ( page ) ;
737721 await currentWorkspaceController ( page , workspace . workspaceId , ids ) ;
722+ const interruptedSessionCard = page . locator ( `.agent-pane-card[data-session-id="${ session . id } "]` ) . first ( ) ;
723+ await expect ( interruptedSessionCard ) . toBeVisible ( {
724+ timeout : 10000 ,
725+ } ) ;
726+ await interruptedSessionCard . click ( ) ;
738727 await expect ( page . getByTestId ( 'workspace-agent-recovery-banner' ) ) . toBeVisible ( {
739728 timeout : 10000 ,
740729 } ) ;
@@ -1431,6 +1420,32 @@ async function waitForWsEvent(
14311420 ) ! ;
14321421}
14331422
1423+ async function waitForLifecycleReplayEvent (
1424+ page : Page ,
1425+ workspaceId : string ,
1426+ ids : { deviceId : string ; clientId : string } ,
1427+ sessionId : string ,
1428+ kind : string ,
1429+ timeoutMs = 10000 ,
1430+ ) {
1431+ await expect
1432+ . poll ( async ( ) => {
1433+ const runtime = await invokeRpc < {
1434+ lifecycle_events ?: Array < { session_id : string ; kind : string } > ;
1435+ } > ( page , 'workspace_runtime_attach' , {
1436+ workspaceId,
1437+ deviceId : ids . deviceId ,
1438+ clientId : ids . clientId ,
1439+ } ) ;
1440+ return runtime . lifecycle_events ?. some ( ( event ) =>
1441+ event . session_id === sessionId && event . kind === kind
1442+ ) ?? false ;
1443+ } , {
1444+ timeout : timeoutMs ,
1445+ } )
1446+ . toBe ( true ) ;
1447+ }
1448+
14341449async function countWsEvents (
14351450 page : Page ,
14361451 eventName : string ,
0 commit comments