@e2e-dev/mobile 0.12.3 → 0.12.4-nightly-20261018072924

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/.build.json CHANGED
@@ -1 +1 @@
1
- {"version":"0.12.3"}
1
+ {"version":"0.12.4-nightly-20261018072924"}
@@ -40,8 +40,8 @@ export interface SlotBinding {
40
40
  /** App a provider already installed from `appPath`, so the worker installs nothing and opens this. */
41
41
  readonly installedApp?: string | undefined;
42
42
  /**
43
- * The id of the provider lease the slot rides, set only for a provider's
44
- * lease: with it the worker hands the lease to the provider's `record`.
43
+ * The slot's provider lease id. The engine uses it to retain healthy
44
+ * sessions across worker replacement and to find the lease for `record`.
45
45
  */
46
46
  readonly leaseId?: string | undefined;
47
47
  }
package/dist/options.d.ts CHANGED
@@ -42,7 +42,14 @@ export interface MobileOptions {
42
42
  * the platform at `prepare`, as many as the run has slots; with none booted,
43
43
  * agent-device boots one. A `DeviceProvider` leases hosted devices instead:
44
44
  * one per worker slot at `prepare`, each driven through the daemon and
45
- * client configuration the lease names, all released when the run ends.
45
+ * client configuration the lease names. A replacement worker resumes a
46
+ * healthy agent-device session on the same lease. Forced worker shutdown
47
+ * can close the session. `device.closeApp()` ends the session and drops
48
+ * the device claim during the run. If agent-device has not confirmed a
49
+ * recording stop, the engine resets the recording before the next
50
+ * attempt. This reset also closes the session and drops the claim.
51
+ * At run end, the engine closes the sessions and the provider releases
52
+ * its leases.
46
53
  */
47
54
  readonly device?: string | readonly string[] | DeviceProvider | undefined;
48
55
  /**
package/dist/pool.d.ts CHANGED
@@ -70,14 +70,11 @@ export declare class DevicePool {
70
70
  */
71
71
  prepare(info: EnginePrepareInfo): Promise<EnginePrepareResult>;
72
72
  /**
73
- * Closes every session `warm` opened for the target and releases what the
74
- * source acquired. A worker closes its own session in `dispose`, but a run
75
- * that failed in `prepare` never had one, and an agent-device session
76
- * outlives the process: left open, the next run resumes it by name with
77
- * the runner state that failed this one. The closes are best-effort under
78
- * the hook's budget and run beside the release, so a close that hangs or
79
- * fails never keeps a leased device billed; a local pool has nothing to
80
- * release.
73
+ * Closes every engine session `warm` opened for the target and releases
74
+ * what the source acquired. This is the normal run-end close for leased
75
+ * slots and a fallback for local sessions or a failed `prepare`. Session
76
+ * closes and source release run concurrently under the hook's cleanup
77
+ * budget, so a hung close does not delay lease release.
81
78
  */
82
79
  finish(info: EngineFinishInfo): Promise<void>;
83
80
  /**
package/dist/pool.js CHANGED
@@ -164,14 +164,11 @@ export class DevicePool {
164
164
  return { workers: bindings.length, env: { [bindingsVariable(info.targetName)]: encodeBindings(bindings) } };
165
165
  }
166
166
  /**
167
- * Closes every session `warm` opened for the target and releases what the
168
- * source acquired. A worker closes its own session in `dispose`, but a run
169
- * that failed in `prepare` never had one, and an agent-device session
170
- * outlives the process: left open, the next run resumes it by name with
171
- * the runner state that failed this one. The closes are best-effort under
172
- * the hook's budget and run beside the release, so a close that hangs or
173
- * fails never keeps a leased device billed; a local pool has nothing to
174
- * release.
167
+ * Closes every engine session `warm` opened for the target and releases
168
+ * what the source acquired. This is the normal run-end close for leased
169
+ * slots and a fallback for local sessions or a failed `prepare`. Session
170
+ * closes and source release run concurrently under the hook's cleanup
171
+ * budget, so a hung close does not delay lease release.
175
172
  */
176
173
  async finish(info) {
177
174
  const clients = this.warmed.get(info.targetName) ?? [];
package/dist/surface.d.ts CHANGED
@@ -69,6 +69,8 @@ export declare class AgentDeviceSurface {
69
69
  private readonly createClient;
70
70
  private client;
71
71
  private attempt;
72
+ /** Retained across attempt cleanup until a stop or native session reset is confirmed. */
73
+ private recording;
72
74
  /** The attempt's `EngineAttemptContext.screen`, which locate captures feed; undefined between attempts. */
73
75
  private screenSink;
74
76
  /** The device this worker drives, the pool's binding for its slot; undefined leaves the choice to agent-device. */
@@ -186,7 +188,9 @@ export declare class AgentDeviceSurface {
186
188
  private startLeaseRecording;
187
189
  /** Ends the provider's recording as the attempt's one segment, a file in its `video` directory or a link. */
188
190
  private stopLeaseRecording;
189
- dispose(context: EngineCleanupContext): Promise<void>;
191
+ dispose(context: EngineCleanupContext & {
192
+ readonly reuseSignal?: AbortSignal;
193
+ }): Promise<void>;
190
194
  /**
191
195
  * Opens an app in the session, remembering its identity for the path
192
196
  * anchor. A link is refused before the device sees it: agent-device would
package/dist/surface.js CHANGED
@@ -190,6 +190,8 @@ export class AgentDeviceSurface {
190
190
  createClient;
191
191
  client;
192
192
  attempt;
193
+ /** Retained across attempt cleanup until a stop or native session reset is confirmed. */
194
+ recording;
193
195
  /** The attempt's `EngineAttemptContext.screen`, which locate captures feed; undefined between attempts. */
194
196
  screenSink;
195
197
  /** The device this worker drives, the pool's binding for its slot; undefined leaves the choice to agent-device. */
@@ -343,11 +345,21 @@ export class AgentDeviceSurface {
343
345
  throw invalidState('an attempt is already running on this agent-device engine');
344
346
  }
345
347
  await this.settleInflight(context.signal);
348
+ const recording = this.recording;
349
+ if (recording?.kind === 'screen') {
350
+ await this.command('reset video recording', (client) => client.sessions.close(), context.signal);
351
+ if (this.recording === recording)
352
+ this.recording = undefined;
353
+ this.screenReplaced();
354
+ }
355
+ else if (recording?.kind === 'lease') {
356
+ await this.stopLeaseRecording(recording, context.signal);
357
+ }
346
358
  // Nothing is launched here: the app is where the last test, or the
347
359
  // worker's `prepare`, left it, and a test that wants it fresh calls
348
360
  // `app.open()`, which is `restart` below. The bindings are forgotten, the
349
361
  // screen is not, so a control still in place is acted on at once.
350
- this.attempt = { attemptId: context.attemptId, artifactsDir: context.artifactsDir, screenshots: 0, video: undefined };
362
+ this.attempt = { attemptId: context.attemptId, artifactsDir: context.artifactsDir, screenshots: 0 };
351
363
  this.generation = new Map();
352
364
  this.located.clear();
353
365
  this.screenSink = context.screen;
@@ -355,8 +367,7 @@ export class AgentDeviceSurface {
355
367
  tellHarness(() => context.environment?.({ platform: this.options.platform, ...(device === undefined ? {} : { device }) }));
356
368
  }
357
369
  async endAttempt(context) {
358
- const attempt = this.attempt;
359
- const dangling = attempt?.video;
370
+ const dangling = this.recording;
360
371
  this.attempt = undefined;
361
372
  this.screenSink = undefined;
362
373
  this.generation = new Map();
@@ -366,12 +377,12 @@ export class AgentDeviceSurface {
366
377
  // and the device must not keep recording into the next one. A start that
367
378
  // outlived its budget may still be landing: it settles first, so the stop
368
379
  // cannot overtake it.
369
- if (attempt !== undefined && dangling?.kind === 'lease') {
370
- await this.stopLeaseRecording(dangling, attempt.artifactsDir, context.signal).catch(() => undefined);
380
+ if (dangling?.kind === 'lease') {
381
+ await this.stopLeaseRecording(dangling, context.signal).catch(() => undefined);
371
382
  }
372
383
  else if (dangling !== undefined) {
373
384
  await this.settleInflight(context.signal).catch(() => undefined);
374
- await this.stopScreenRecording(context.signal).catch(() => undefined);
385
+ await this.stopScreenRecording(dangling, context.signal).catch(() => undefined);
375
386
  }
376
387
  }
377
388
  // --- video ---
@@ -386,7 +397,7 @@ export class AgentDeviceSurface {
386
397
  const attempt = this.attempt;
387
398
  if (attempt === undefined)
388
399
  throw invalidState('startVideo outside an attempt');
389
- if (attempt.video !== undefined)
400
+ if (this.recording !== undefined)
390
401
  throw invalidState('a video is already recording');
391
402
  if (this.leaseRecorder !== undefined) {
392
403
  await this.startLeaseRecording(attempt, this.leaseRecorder, operation.signal);
@@ -398,7 +409,7 @@ export class AgentDeviceSurface {
398
409
  // Marked before the device is asked: a start that outlives its budget
399
410
  // still records, and `endAttempt` must be able to stop it.
400
411
  const recording = { kind: 'screen', relative, absolute, startedAt: new Date().toISOString() };
401
- attempt.video = recording;
412
+ this.recording = recording;
402
413
  await this.command('start video recording',
403
414
  // The whole screen: an app scope refuses to start while no app is open, before `app.open()` and after `closeApp()`.
404
415
  (client) => client.recording.record({
@@ -417,18 +428,13 @@ export class AgentDeviceSurface {
417
428
  const attempt = this.attempt;
418
429
  if (attempt === undefined)
419
430
  throw invalidState('stopVideo outside an attempt');
420
- const video = attempt.video;
431
+ const video = this.recording;
421
432
  if (video === undefined)
422
433
  return [];
423
434
  if (video.kind === 'lease') {
424
- const segment = await this.stopLeaseRecording(video, attempt.artifactsDir, operation.signal);
425
- // Cleared only now: a stop that failed leaves the recording for `endAttempt`.
426
- attempt.video = undefined;
427
- return [segment];
435
+ return [await this.stopLeaseRecording(video, operation.signal)];
428
436
  }
429
- const result = await this.stopScreenRecording(operation.signal);
430
- // Cleared only now: a stop that failed leaves the recording for `endAttempt`.
431
- attempt.video = undefined;
437
+ const result = await this.stopScreenRecording(video, operation.signal);
432
438
  // The device may finalize the file under a path of its own choosing; the
433
439
  // artifact must live where the attempt directory expects it.
434
440
  const written = typeof result.outPath === 'string' ? result.outPath : video.absolute;
@@ -444,8 +450,10 @@ export class AgentDeviceSurface {
444
450
  * whatever the test opened in it since, so the session is then as
445
451
  * `closeApp` leaves it.
446
452
  */
447
- async stopScreenRecording(signal) {
453
+ async stopScreenRecording(video, signal) {
448
454
  const result = await this.command('stop video recording', (client) => client.recording.record({ ...this.selection(), action: 'stop' }), signal);
455
+ if (this.recording === video)
456
+ this.recording = undefined;
449
457
  if (result.recordOnlySession === true) {
450
458
  this.screenReplaced();
451
459
  }
@@ -460,34 +468,68 @@ export class AgentDeviceSurface {
460
468
  async startLeaseRecording(attempt, recorder, signal) {
461
469
  const { provider, lease, runId, targetName, env } = recorder;
462
470
  const started = recordLease(provider, lease, { runId, targetName, attemptId: attempt.attemptId, env, signal });
463
- attempt.video = { kind: 'lease', recorder, started };
471
+ const video = { kind: 'lease', recorder, started, artifactsDir: attempt.artifactsDir };
472
+ this.recording = video;
473
+ void started.catch(() => {
474
+ if (this.recording === video)
475
+ this.recording = undefined;
476
+ });
464
477
  await raceAbort(started, signal, 'start video recording');
465
478
  }
466
479
  /** Ends the provider's recording as the attempt's one segment, a file in its `video` directory or a link. */
467
- async stopLeaseRecording(video, artifactsDir, signal) {
480
+ async stopLeaseRecording(video, signal) {
468
481
  const { provider, lease } = video.recorder;
469
- video.stopping ??= (async () => stopProviderRecording(await video.started, { artifactsDir, provider: `device provider "${provider.name}"`, leaseId: lease.id, signal }))().finally(() => {
482
+ video.stopping ??= (async () => {
483
+ const recording = await video.started;
484
+ return stopProviderRecording({
485
+ startedAt: recording.startedAt,
486
+ stop: async (context) => {
487
+ const result = await recording.stop(context);
488
+ if (this.recording === video)
489
+ this.recording = undefined;
490
+ return result;
491
+ },
492
+ }, { artifactsDir: video.artifactsDir, provider: `device provider "${provider.name}"`, leaseId: lease.id, signal });
493
+ })().finally(() => {
470
494
  video.stopping = undefined;
471
495
  });
472
496
  return raceAbort(video.stopping, signal, 'stop video recording');
473
497
  }
474
498
  async dispose(context) {
475
499
  const client = this.client;
476
- const attempt = this.attempt;
477
- // A worker torn down mid-attempt must not leave the provider recording the device.
478
- if (attempt?.video?.kind === 'lease') {
479
- await withinCleanupBudget(this.stopLeaseRecording(attempt.video, attempt.artifactsDir, context.signal), context).catch(() => undefined);
480
- }
500
+ const recording = this.recording;
481
501
  this.client = undefined;
482
502
  this.attempt = undefined;
503
+ this.screenSink = undefined;
483
504
  this.generation = new Map();
484
505
  this.located.clear();
485
506
  this.appIdentity = undefined;
486
507
  this.installedApp = undefined;
487
508
  this.knownViewport = undefined;
488
- if (client === undefined)
489
- return;
490
- await withinCleanupBudget(client.sessions.close().catch(() => undefined), context);
509
+ let closing;
510
+ const close = () => {
511
+ if (client === undefined)
512
+ return;
513
+ closing ??= client.sessions.close().then(() => {
514
+ if (recording?.kind === 'screen' && this.recording === recording)
515
+ this.recording = undefined;
516
+ }).catch(() => undefined);
517
+ };
518
+ const reuse = context.reuseSignal;
519
+ reuse?.addEventListener('abort', close, { once: true });
520
+ const canKeepSession = this.device?.leaseId !== undefined && recording?.kind !== 'screen' && reuse !== undefined && !reuse.aborted;
521
+ if (!canKeepSession)
522
+ close();
523
+ try {
524
+ const stopping = recording?.kind === 'lease' ? this.stopLeaseRecording(recording, context.signal).catch(() => undefined) : undefined;
525
+ await withinCleanupBudget((async () => {
526
+ await stopping;
527
+ await closing;
528
+ })(), context);
529
+ }
530
+ finally {
531
+ reuse?.removeEventListener('abort', close);
532
+ }
491
533
  }
492
534
  /**
493
535
  * Opens an app in the session, remembering its identity for the path
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e2e-dev/mobile",
3
- "version": "0.12.3",
3
+ "version": "0.12.4-nightly-20261018072924",
4
4
  "description": "Mobile engine (iOS and Android) for e2e agentic end-to-end testing, built on agent-device",
5
5
  "keywords": [
6
6
  "e2e",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "peerDependencies": {
59
59
  "ai": "^7.0.0",
60
- "e2e": ">=0.15.0 <1"
60
+ "e2e": "0.21.3-nightly-20261018072924"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "ai": {
@@ -68,7 +68,7 @@
68
68
  "@types/node": "26.6.2",
69
69
  "@types/pngjs": "6.0.5",
70
70
  "ai": "7.0.107",
71
- "e2e": "0.21.2",
71
+ "e2e": "0.21.3-nightly-20261018072924",
72
72
  "typescript": "7.0.2",
73
73
  "vitest": "5.0.1"
74
74
  },