@e2e-dev/testmu 0.0.3-nightly-20261029030210 → 0.0.3

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.0.3-nightly-20261029030210"}
1
+ {"version":"0.0.3"}
package/dist/daemon.d.ts CHANGED
@@ -1,12 +1,8 @@
1
- import type { DriverGrant, DriverRequest } from './driver.ts';
2
- export declare function assertDriverVersion(expected: string): void;
1
+ /** Throws unless the installed plugin matches the agent-device `@e2e-dev/mobile` runs its daemons with. */
2
+ export declare function assertPluginVersion(expected: string): void;
3
3
  /**
4
4
  * Registers the installed `@agent-device/testmu` in a private agent-device
5
5
  * home, the layout `agent-device plugins add` writes, without fetching it
6
6
  * from the registry again.
7
7
  */
8
8
  export declare function installPlugin(home: string): Promise<void>;
9
- /** Not cancellable: an interrupted allocation can still grant a lease, which the caller then releases. */
10
- export declare function startDriver(request: DriverRequest, env: NodeJS.ProcessEnv): Promise<DriverGrant>;
11
- /** Stopping the daemon releases its leases, which ends their TestMu AI sessions. */
12
- export declare function stopDriver(stateDir: string, env: NodeJS.ProcessEnv, signal: AbortSignal): Promise<void>;
package/dist/daemon.js CHANGED
@@ -1,11 +1,8 @@
1
- import { execFile, fork } from 'node:child_process';
2
1
  import { randomUUID } from 'node:crypto';
3
2
  import { readFileSync } from 'node:fs';
4
3
  import { mkdir, symlink, writeFile } from 'node:fs/promises';
5
4
  import { fileURLToPath } from 'node:url';
6
5
  import path from 'node:path';
7
- import { promisify } from 'node:util';
8
- const exec = promisify(execFile);
9
6
  const PLUGIN = '@agent-device/testmu';
10
7
  /** A property of a parsed JSON value, or undefined when the value is not an object. */
11
8
  function field(value, key) {
@@ -19,7 +16,7 @@ function installation(name) {
19
16
  const manifest = JSON.parse(readFileSync(path.join(directory, 'package.json'), 'utf8'));
20
17
  const version = field(manifest, 'version');
21
18
  if (field(manifest, 'name') === name && typeof version === 'string')
22
- return { directory, version, bin: field(manifest, 'bin') };
19
+ return { directory, version };
23
20
  }
24
21
  catch { /* The entry may be several directories below its package. */ }
25
22
  const parent = path.dirname(directory);
@@ -28,10 +25,11 @@ function installation(name) {
28
25
  directory = parent;
29
26
  }
30
27
  }
31
- export function assertDriverVersion(expected) {
32
- const actual = installation('agent-device').version;
28
+ /** Throws unless the installed plugin matches the agent-device `@e2e-dev/mobile` runs its daemons with. */
29
+ export function assertPluginVersion(expected) {
30
+ const actual = installation(PLUGIN).version;
33
31
  if (actual !== expected)
34
- throw new Error(`@e2e-dev/testmu uses agent-device ${actual}, but @e2e-dev/mobile uses ${expected}. Install matching versions.`);
32
+ throw new Error(`@e2e-dev/testmu uses ${PLUGIN} ${actual}, but @e2e-dev/mobile uses agent-device ${expected}. Install matching versions.`);
35
33
  }
36
34
  /**
37
35
  * Registers the installed `@agent-device/testmu` in a private agent-device
@@ -46,35 +44,3 @@ export async function installPlugin(home) {
46
44
  await symlink(plugin.directory, path.join(scope, 'testmu'), 'junction');
47
45
  await writeFile(path.join(home, 'config.json'), `${JSON.stringify({ plugins: { [PLUGIN]: { installation: id, version: plugin.version } } })}\n`, { mode: 0o600 });
48
46
  }
49
- /** Not cancellable: an interrupted allocation can still grant a lease, which the caller then releases. */
50
- export async function startDriver(request, env) {
51
- const entry = new URL(import.meta.url.endsWith('.ts') ? './driver.ts' : './driver.js', import.meta.url);
52
- return new Promise((resolve, reject) => {
53
- const child = fork(entry, [], { env, execArgv: [], stdio: ['ignore', 'ignore', 'ignore', 'ipc'] });
54
- let answered = false;
55
- child.once('error', reject);
56
- child.once('message', (reply) => {
57
- answered = true;
58
- if (reply.grant)
59
- resolve(reply.grant);
60
- else
61
- reject(new Error(reply.error ?? 'TestMu AI driver returned no lease'));
62
- });
63
- child.once('exit', () => {
64
- if (!answered)
65
- reject(new Error('TestMu AI driver exited before allocation finished'));
66
- });
67
- child.send(request);
68
- });
69
- }
70
- /** Stopping the daemon releases its leases, which ends their TestMu AI sessions. */
71
- export async function stopDriver(stateDir, env, signal) {
72
- const cli = installation('agent-device');
73
- const bin = field(cli.bin, 'agent-device');
74
- if (typeof bin !== 'string')
75
- throw new Error('The installed agent-device package has no agent-device bin');
76
- const { stdout } = await exec(process.execPath, [path.join(cli.directory, bin), 'daemon', 'stop', '--state-dir', stateDir, '--clean', '--json'], { env, signal });
77
- const pending = field(field(field(JSON.parse(stdout), 'data'), 'providerReleases'), 'pending');
78
- if (Array.isArray(pending) && pending.length > 0)
79
- throw new Error(`agent-device stopped without ending ${pending.length} TestMu AI session(s)`);
80
- }
package/dist/provider.js CHANGED
@@ -4,14 +4,12 @@
4
4
  * `@agent-device/testmu` plugin: each lease comes from its own agent-device
5
5
  * daemon, which runs the session over TestMu AI's Appium hub.
6
6
  */
7
- import { mkdtemp, rm } from 'node:fs/promises';
8
- import { tmpdir } from 'node:os';
9
- import { isAbsolute, join, resolve } from 'node:path';
7
+ import { isAbsolute, resolve } from 'node:path';
8
+ import { agentDeviceLeases } from '@e2e-dev/mobile/lease';
10
9
  import { ConfigurationError, rejectUnknownKeys } from 'e2e/engine';
11
10
  import { testmuCredentials } from './credentials.js';
12
- import { assertDriverVersion, installPlugin, startDriver, stopDriver } from './daemon.js';
11
+ import { assertPluginVersion, installPlugin } from './daemon.js';
13
12
  import { DEFAULT_PROJECT, defaultSessionName } from './dashboard.js';
14
- import { LEASE_TTL_MS, startHeartbeat } from './heartbeat.js';
15
13
  import { findSession, sessionVideoUrl, testmuApiEndpoint } from './sessions.js';
16
14
  /** agent-device's name for TestMu AI, as the lease provider and the tenant. */
17
15
  const PROVIDER = 'testmu';
@@ -44,21 +42,6 @@ const OPTION_KEYS = Object.keys({
44
42
  locale: true,
45
43
  appiumVersion: true,
46
44
  });
47
- function driverEnv(env, home, credentials) {
48
- const result = { ...env };
49
- // A user's daemon settings must not select a different daemon or plugin home.
50
- for (const key of Object.keys(result)) {
51
- // Keep the user's security policy on both the daemon and its clients.
52
- if (key === 'AGENT_DEVICE_DAEMON_POLICY')
53
- continue;
54
- if (key.startsWith('AGENT_DEVICE_'))
55
- delete result[key];
56
- }
57
- result.AGENT_DEVICE_HOME = home;
58
- result.LT_USERNAME = credentials.username;
59
- result.LT_ACCESS_KEY = credentials.accessKey;
60
- return result;
61
- }
62
45
  /**
63
46
  * TestMu AI devices for `mobile({ device: testmu({ device, osVersion, app }) })`:
64
47
  * one hosted device and isolated agent-device daemon per worker slot. Allocating
@@ -94,34 +77,15 @@ export function testmu(options) {
94
77
  deviceFeatures[leaseKey] = value;
95
78
  }
96
79
  const { device, osVersion, app, project, build, sessionName } = options;
97
- const held = new Map();
98
- /** One release per lease, shared by every caller; a failed one may be tried again. */
99
- function release(id, resource, signal) {
100
- resource.releasing ??= (async () => {
101
- await resource.stopHeartbeat?.();
102
- await stopDriver(resource.stateDir, resource.env, signal);
103
- await rm(resource.dir, { recursive: true, force: true });
104
- if (id !== undefined)
105
- held.delete(id);
106
- })();
107
- resource.releasing.catch(() => { resource.releasing = undefined; });
108
- return resource.releasing;
109
- }
80
+ const leases = agentDeviceLeases({ provider: PROVIDER, label: 'TestMu AI' });
110
81
  return {
111
82
  name: PROVIDER,
112
83
  async acquire(request) {
113
- assertDriverVersion(request.agentDeviceVersion);
84
+ assertPluginVersion(request.agentDeviceVersion);
114
85
  if (request.appPath !== undefined)
115
86
  throw new Error("TestMu AI installs the app from `app`; leave the target's `app.appPath` out");
116
87
  const credentials = testmuCredentials(request.env);
117
- request.signal.throwIfAborted();
118
- const dir = await mkdtemp(join(tmpdir(), 'e2e-testmu-'));
119
- const home = join(dir, 'home');
120
- const resource = { dir, stateDir: join(dir, 'state'), env: driverEnv(request.env, home, credentials) };
121
- const leaseBackend = request.platform === 'ios' ? 'ios-instance' : 'android-instance';
122
88
  const selectors = {
123
- platform: request.platform,
124
- target: 'mobile',
125
89
  device,
126
90
  providerOsVersion: osVersion,
127
91
  providerApp: appSource(app, request.projectRoot),
@@ -131,51 +95,14 @@ export function testmu(options) {
131
95
  providerSessionName: slotSessionName(sessionName, request),
132
96
  ...deviceFeatures,
133
97
  };
134
- let id;
135
- try {
136
- await installPlugin(home);
137
- const grant = await startDriver({
138
- stateDir: resource.stateDir,
139
- allocate: {
140
- tenant: PROVIDER,
141
- runId: request.runId,
142
- leaseBackend,
143
- leaseProvider: PROVIDER,
144
- ttlMs: LEASE_TTL_MS,
145
- // Retain the provider lease when closeApp or cleanup closes the engine session.
146
- // The provider releases the lease at run end.
147
- retainOnClose: true,
148
- ...selectors,
149
- },
150
- }, resource.env);
151
- id = grant.leaseId;
152
- held.set(id, resource);
153
- if (request.signal.aborted)
154
- throw new Error('cancelled');
155
- if (!grant.retainOnClose)
156
- throw new Error('agent-device did not acknowledge retainOnClose. Closing the engine session could end the TestMu AI lease before run-end release');
157
- const scope = { tenant: grant.tenantId, runId: grant.runId, leaseId: grant.leaseId, leaseBackend, leaseProvider: PROVIDER };
158
- resource.stopHeartbeat = await startHeartbeat(resource.stateDir, scope, request.log);
159
- request.log(`lease ${id}: ${device}, ${request.platform} ${osVersion} (${deviceType}); session ${selectors.providerSessionName} started`);
160
- // The worker's client is created with these fields: the scope picks the lease, and the selectors match the session it holds.
161
- return { id, client: { stateDir: resource.stateDir, ...scope, ...selectors } };
162
- }
163
- catch (cause) {
164
- // The engine releases only leases `acquire` returned.
165
- try {
166
- await release(id, resource, AbortSignal.timeout(30_000));
167
- }
168
- catch (cleanup) {
169
- throw new AggregateError([cause, cleanup], `TestMu AI lease failed: ${messageOf(cause)}; cleanup also failed: ${messageOf(cleanup)}`, { cause: cleanup });
170
- }
171
- throw cause;
172
- }
173
- },
174
- async release(lease, context) {
175
- const resource = held.get(lease.id);
176
- if (resource)
177
- await release(lease.id, resource, context.signal);
98
+ return leases.acquire(request, {
99
+ env: { LT_USERNAME: credentials.username, LT_ACCESS_KEY: credentials.accessKey },
100
+ selectors,
101
+ summary: `${device}, ${request.platform} ${osVersion} (${deviceType}); session ${selectors.providerSessionName} started`,
102
+ prepareHome: installPlugin,
103
+ });
178
104
  },
105
+ release: (lease, context) => leases.release(lease, context),
179
106
  // Runs in the worker, from the lease alone. TestMu AI records the whole session, so its video starts when the session did.
180
107
  async record(lease, context) {
181
108
  const calledAt = new Date().toISOString();
@@ -216,6 +143,3 @@ function sessionRef({ client }) {
216
143
  return undefined;
217
144
  return { build, sessionName };
218
145
  }
219
- function messageOf(cause) {
220
- return cause instanceof Error ? cause.message : String(cause);
221
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e2e-dev/testmu",
3
- "version": "0.0.3-nightly-20261029030210",
3
+ "version": "0.0.3",
4
4
  "description": "TestMu AI (formerly LambdaTest) for e2e: hosted Android emulators, iOS simulators, and real devices for mobile tests, and hosted Chrome and Edge for web tests",
5
5
  "keywords": [
6
6
  "e2e",
@@ -55,9 +55,9 @@
55
55
  "NOTICE"
56
56
  ],
57
57
  "peerDependencies": {
58
- "@e2e-dev/mobile": "0.12.5-nightly-20261029030210",
59
- "@e2e-dev/web": "0.15.4-nightly-20261029030210",
60
- "e2e": "0.22.0-nightly-20261029030210"
58
+ "@e2e-dev/mobile": ">=0.12.5 <1",
59
+ "@e2e-dev/web": ">=0.11.0 <1",
60
+ "e2e": ">=0.15.0 <1"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "@e2e-dev/mobile": {
@@ -68,10 +68,10 @@
68
68
  }
69
69
  },
70
70
  "devDependencies": {
71
- "@e2e-dev/mobile": "0.12.5-nightly-20261029030210",
72
- "@e2e-dev/web": "0.15.4-nightly-20261029030210",
71
+ "@e2e-dev/mobile": "0.12.5",
72
+ "@e2e-dev/web": "0.15.4",
73
73
  "@types/node": "26.6.5",
74
- "e2e": "0.22.0-nightly-20261029030210",
74
+ "e2e": "0.22.0",
75
75
  "typescript": "7.0.2",
76
76
  "vitest": "5.0.5"
77
77
  },
@@ -79,8 +79,7 @@
79
79
  "node": "^22.22.3 || >=24.8.0"
80
80
  },
81
81
  "dependencies": {
82
- "@agent-device/testmu": "0.21.33",
83
- "agent-device": "0.21.33"
82
+ "@agent-device/testmu": "0.21.35"
84
83
  },
85
84
  "scripts": {
86
85
  "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc --project tsconfig.build.json && node ../../scripts/stamp-dist.ts",
package/dist/driver.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { type LeaseAllocateOptions } from 'agent-device';
2
- /** A separate process gives each daemon its own credentials and plugin home without changing the runner's environment. */
3
- export interface DriverRequest {
4
- stateDir: string;
5
- allocate: LeaseAllocateOptions;
6
- }
7
- export interface DriverGrant {
8
- leaseId: string;
9
- tenantId: string;
10
- runId: string;
11
- retainOnClose: boolean;
12
- }
package/dist/driver.js DELETED
@@ -1,8 +0,0 @@
1
- import { createAgentDeviceClient } from 'agent-device';
2
- process.once('message', (request) => {
3
- void allocate(request).then((grant) => process.send?.({ grant }, () => process.disconnect?.()), (cause) => process.send?.({ error: cause instanceof Error ? cause.message : String(cause) }, () => process.disconnect?.()));
4
- });
5
- async function allocate({ stateDir, allocate: options }) {
6
- const lease = await createAgentDeviceClient({ stateDir }).leases.allocate(options);
7
- return { leaseId: lease.leaseId, tenantId: lease.tenantId, runId: lease.runId, retainOnClose: lease.retainOnClose === true };
8
- }
@@ -1,4 +0,0 @@
1
- import { type LeaseScopedOptions } from 'agent-device';
2
- export declare const LEASE_TTL_MS = 60000;
3
- /** Renew idle leases while other targets run; session retention alone does not prevent expiry. */
4
- export declare function startHeartbeat(stateDir: string, scope: LeaseScopedOptions, log: (line: string) => void): Promise<() => Promise<void>>;
package/dist/heartbeat.js DELETED
@@ -1,34 +0,0 @@
1
- import { createAgentDeviceClient } from 'agent-device';
2
- export const LEASE_TTL_MS = 60_000;
3
- /** Renew idle leases while other targets run; session retention alone does not prevent expiry. */
4
- export async function startHeartbeat(stateDir, scope, log) {
5
- // An explicit empty URL selects the local stateDir instead of an ambient remote daemon.
6
- const client = createAgentDeviceClient({ stateDir, daemonBaseUrl: '', daemonAuthToken: '', daemonTransport: 'auto' });
7
- const controller = new AbortController();
8
- const beat = () => client.leases.heartbeat({ ...scope, ttlMs: LEASE_TTL_MS, signal: AbortSignal.any([controller.signal, AbortSignal.timeout(10_000)]) });
9
- await beat();
10
- let pending = Promise.resolve();
11
- let timer;
12
- const schedule = () => {
13
- timer = setTimeout(() => {
14
- pending = beat().then(() => { }, (error) => {
15
- if (controller.signal.aborted)
16
- return;
17
- try {
18
- log(`lease ${scope.leaseId}: renewal failed: ${error instanceof Error ? error.message : String(error)}`);
19
- }
20
- catch {
21
- // The run's log may be closed by now.
22
- }
23
- }).finally(() => { if (!controller.signal.aborted)
24
- schedule(); });
25
- }, 20_000);
26
- timer.unref();
27
- };
28
- schedule();
29
- return async () => {
30
- controller.abort();
31
- clearTimeout(timer);
32
- await pending;
33
- };
34
- }