@@ -44,7 +44,7 @@ import {
4444 ConfigurationError ,
4545 TestError ,
4646} from 'e2e/engine' ;
47- import { isNoSessionApp , isSnapshotPresentationFailure , runCommand , staleOr } from './errors.ts' ;
47+ import { isSnapshotPresentationFailure , runCommand , staleOr } from './errors.ts' ;
4848import { pointerInteraction , DEFAULT_LONG_PRESS_MS } from './actions.ts' ;
4949import { resolveExpression } from './locate.ts' ;
5050import {
@@ -360,14 +360,6 @@ export class AgentDeviceSurface {
360360 private readonly located = new Map < string , NodeBinding > ( ) ;
361361 private idCounter = 0 ;
362362 private appIdentity : string | undefined ;
363- /**
364- * The app this worker's agent-device session is on, and so the app a
365- * permission command there acts on: what the warm-up in `prepare` opened
366- * under the session this worker resumed, while that session is still open,
367- * then whatever this surface last opened. Undefined while nothing has been opened in the session, and once
368- * `closeApp` ended it.
369- */
370- private sessionApp : string | undefined ;
371363 /** The app the build `appPath` installed, once `init` has, itself or through a lease. */
372364 private installedApp : string | undefined ;
373365 /** The target's app, as `init` received it. */
@@ -509,31 +501,12 @@ export class AgentDeviceSurface {
509501 ? undefined
510502 : { provider, lease, runId : info . runId , targetName : info . targetName , env : info . env } ;
511503 await this . command ( 'boot' , ( client ) => client . devices . boot ( this . selection ( ) ) , info . signal ) ;
512- this . sessionApp = binding ?. sessionApp === undefined ? undefined : await this . resumedSessionApp ( session , binding . sessionApp , info . signal ) ;
513504 // Nothing is installed here: a device provider that installed the build
514505 // from `appPath` says so on the binding, and otherwise the suite installs
515506 // it where it wants to, with `device.installApp()`.
516507 this . installedApp = binding ?. installedApp ;
517508 }
518509
519- /**
520- * The app the warm-up left the slot's session on, while agent-device still
521- * holds that session. Only the slot's first worker finds it: a worker
522- * retired after a failing test closed it in `dispose`, and a permission
523- * command on a closed session reaches no device. A session not listed, or
524- * a list that fails, leaves the app unknown, and the first permission
525- * change opens it again.
526- */
527- private async resumedSessionApp ( session : string , app : string , signal : AbortSignal ) : Promise < string | undefined > {
528- const sessions : unknown = await this . command ( 'sessions' , ( client ) => client . sessions . list ( ) , signal ) . catch ( ( cause : unknown ) => {
529- if ( signal . aborted ) throw cause ;
530- return undefined ;
531- } ) ;
532- if ( ! Array . isArray ( sessions ) ) return undefined ;
533- const open = sessions . some ( ( entry : { name ?: unknown ; address ?: unknown } ) => ( entry . address ?? entry . name ) === session ) ;
534- return open ? app : undefined ;
535- }
536-
537510 async startAttempt ( context : EngineAttemptContext ) : Promise < void > {
538511 if ( this . attempt !== undefined ) {
539512 throw invalidState ( 'an attempt is already running on this agent-device engine' ) ;
@@ -644,7 +617,6 @@ export class AgentDeviceSurface {
644617 private async stopScreenRecording ( signal : AbortSignal ) : Promise < { readonly outPath ?: unknown } > {
645618 const result = await this . command ( 'stop video recording' , ( client ) => client . recording . record ( { action : 'stop' } ) , signal ) ;
646619 if ( result . recordOnlySession === true ) {
647- this . sessionApp = undefined ;
648620 this . screenReplaced ( ) ;
649621 }
650622 return result ;
@@ -685,7 +657,6 @@ export class AgentDeviceSurface {
685657 this . generation = new Map ( ) ;
686658 this . located . clear ( ) ;
687659 this . appIdentity = undefined ;
688- this . sessionApp = undefined ;
689660 this . installedApp = undefined ;
690661 this . knownViewport = undefined ;
691662 if ( client === undefined ) return ;
@@ -725,53 +696,32 @@ export class AgentDeviceSurface {
725696 } ) ,
726697 signal ,
727698 ) ;
728- this . sessionApp = app ;
729699 this . launched ( result . appBundleId ?? result . appName ?? app ) ;
730700 }
731701
732702 /**
733- * Puts an app's permissions in place before it launches. agent-device sets
734- * a permission on the app its session is on, so a session on another app,
735- * or on none yet, is first brought onto this one with a foreground open;
736- * the warm-up in `prepare` did that for the pinned app under the session
737- * this worker resumed, so its first launch needs none. Before the launch,
738- * never after: iOS terminates a running app whose
739- * permission changed, and Android one whose permission was revoked, so a
740- * change after the launch would leave the test on no screen.
703+ * Puts an app's permissions in place before it launches, never after: iOS
704+ * terminates a running app whose permission changed, and Android one whose
705+ * permission was revoked, so a change after the launch would leave the
706+ * test on no screen.
741707 */
742708 private async presetPermissions ( app : string , permissions : LaunchPermissions , signal : AbortSignal ) : Promise < void > {
743709 const entries = Object . entries ( permissions ) . filter (
744710 ( entry ) : entry is [ DevicePermission , PermissionState ] => entry [ 1 ] !== undefined ,
745711 ) ;
746- if ( entries . length === 0 ) return ;
747- if ( this . sessionApp !== app ) await this . open ( app , false , undefined , signal ) ;
748- for ( const [ permission , state ] of entries ) await this . permission ( permission , state , signal ) ;
712+ for ( const [ permission , state ] of entries ) await this . permission ( permission , state , app , signal ) ;
749713 }
750714
751- /**
752- * One permission change for `device.setPermission`: on the app the session
753- * is on, which is what agent-device acts on. With none known here (nothing
754- * opened yet, `closeApp`, a worker resumed on a bare session) the pinned
755- * app is brought to the foreground first. agent-device's own refusal, met
756- * when its session lost the app since (a failed attempt left it on none),
757- * gets the same foreground open and the command once more.
758- */
715+ /** One permission change for `device.setPermission`: on the pinned app, else on the app agent-device's session is on. */
759716 async setPermission ( permission : DevicePermission , state : PermissionState , signal : AbortSignal ) : Promise < void > {
760- const app = this . pinnedApp ;
761- if ( this . sessionApp === undefined && app !== undefined ) await this . open ( app , false , undefined , signal ) ;
762- try {
763- await this . permission ( permission , state , signal ) ;
764- } catch ( cause ) {
765- if ( signal . aborted || app === undefined || ! isNoSessionApp ( cause ) ) throw cause ;
766- await this . open ( app , false , undefined , signal ) ;
767- await this . permission ( permission , state , signal ) ;
768- }
717+ await this . permission ( permission , state , this . pinnedApp , signal ) ;
769718 }
770719
771- private async permission ( permission : DevicePermission , state : PermissionState , signal : AbortSignal ) : Promise < void > {
720+ /** One permission change on `app`, which needs no running app and no open in the session. */
721+ private async permission ( permission : DevicePermission , state : PermissionState , app : string | undefined , signal : AbortSignal ) : Promise < void > {
772722 await this . command (
773723 `permission ${ permission } ${ state } ` ,
774- ( client ) => client . settings . update ( { setting : 'permission' , permission, state } ) ,
724+ ( client ) => client . settings . update ( { setting : 'permission' , permission, state, ... this . selection ( ) , ... ( app === undefined ? { } : { app } ) } ) ,
775725 signal ,
776726 ) ;
777727 }
@@ -806,7 +756,6 @@ export class AgentDeviceSurface {
806756 } ) ,
807757 signal ,
808758 ) ;
809- this . sessionApp = target ;
810759 this . launched ( result . appBundleId ?? ( target === undefined ? undefined : ( result . appName ?? target ) ) ) ;
811760 }
812761
@@ -843,7 +792,6 @@ export class AgentDeviceSurface {
843792 async closeApp ( signal : AbortSignal ) : Promise < void > {
844793 const app = this . appIdentity ?? this . pinnedApp ;
845794 await this . command ( 'device.closeApp' , ( client ) => client . apps . close ( app === undefined ? { } : { app } ) , signal ) ;
846- this . sessionApp = undefined ;
847795 this . screenReplaced ( ) ;
848796 }
849797
0 commit comments