@e2e-dev/desktop 0.0.0-stage → 0.0.0
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +79 -2
- package/dist/.build.json +1 -0
- package/dist/binary.d.ts +25 -0
- package/dist/binary.js +209 -0
- package/dist/cli.d.ts +82 -0
- package/dist/cli.js +170 -0
- package/dist/desktop.d.ts +25 -0
- package/dist/desktop.js +27 -0
- package/dist/engine-entry.d.ts +12 -0
- package/dist/engine-entry.js +8 -0
- package/dist/engine.d.ts +18 -0
- package/dist/engine.js +109 -0
- package/dist/fixtures.d.ts +6 -0
- package/dist/fixtures.js +2 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +18 -0
- package/dist/keys.d.ts +8 -0
- package/dist/keys.js +79 -0
- package/dist/nodes.d.ts +95 -0
- package/dist/nodes.js +290 -0
- package/dist/options.d.ts +67 -0
- package/dist/options.js +53 -0
- package/dist/png.d.ts +24 -0
- package/dist/png.js +144 -0
- package/dist/runner-test.d.ts +15 -0
- package/dist/runner-test.js +45 -0
- package/dist/surface.d.ts +270 -0
- package/dist/surface.js +1439 -0
- package/package.json +71 -3
package/dist/cli.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One agent-desktop command per process, its JSON envelope read off stdout,
|
|
3
|
+
* and its failure translated onto the engine error contract.
|
|
4
|
+
*
|
|
5
|
+
* | agent-desktop result | Code |
|
|
6
|
+
* | ------------------------------------------------------------- | ------------------------- |
|
|
7
|
+
* | `STALE_REF`, `SNAPSHOT_NOT_FOUND`, `ELEMENT_NOT_FOUND`, sent nothing | NODE_STALE (retryable) |
|
|
8
|
+
* | `ACTION_NOT_SUPPORTED`, `PLATFORM_NOT_SUPPORTED`, `POLICY_DENIED` | UNSUPPORTED_CAPABILITY |
|
|
9
|
+
* | `APP_NOT_FOUND`, `WINDOW_NOT_FOUND` | INVALID_STATE |
|
|
10
|
+
* | `AMBIGUOUS_TARGET`, `ACTION_FAILED`, `TIMEOUT`, sent nothing | NOT_ACTIONABLE |
|
|
11
|
+
* | `TIMEOUT` of a read | OPERATION_TIMEOUT |
|
|
12
|
+
* | any failure of an input that may have been delivered | ACTION_MAY_HAVE_COMMITTED |
|
|
13
|
+
* | an input still running when the operation's budget ran out | ACTION_MAY_HAVE_COMMITTED |
|
|
14
|
+
* | an input whose process exited without printing a result | ACTION_MAY_HAVE_COMMITTED |
|
|
15
|
+
* | a read still running when the operation's budget ran out | OPERATION_TIMEOUT |
|
|
16
|
+
* | the operation's signal aborted | CANCELLED |
|
|
17
|
+
* | anything else, `PERM_DENIED` included | ENGINE_FAILURE |
|
|
18
|
+
*
|
|
19
|
+
* agent-desktop states delivery on every failure (`disposition.delivery`),
|
|
20
|
+
* so the line between "refused" and "may have committed" is its own, never a
|
|
21
|
+
* guess from the error code.
|
|
22
|
+
*
|
|
23
|
+
* Text an action types reaches the process on stdin, never in its arguments,
|
|
24
|
+
* which any process on the machine can read; no error here quotes stdin.
|
|
25
|
+
*/
|
|
26
|
+
import { spawn } from 'node:child_process';
|
|
27
|
+
import { EngineError } from '@e2e-dev/core/engine';
|
|
28
|
+
/** A failure agent-desktop reported, before translation, for a caller that tries another way when nothing was sent. */
|
|
29
|
+
export class AgentDesktopFailure extends Error {
|
|
30
|
+
code;
|
|
31
|
+
/** Whether agent-desktop says nothing reached the app, so another way may be tried. */
|
|
32
|
+
notDelivered;
|
|
33
|
+
details;
|
|
34
|
+
constructor(failure) {
|
|
35
|
+
super(failure.message);
|
|
36
|
+
this.name = 'AgentDesktopFailure';
|
|
37
|
+
this.code = failure.code;
|
|
38
|
+
this.notDelivered = failure.disposition?.delivery === 'not_delivered';
|
|
39
|
+
this.details = failure.details ?? {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The least time an input gets once started, however little budget was left: a click that lands is then not reported as cut off. A read gets exactly its budget. */
|
|
43
|
+
const MIN_INPUT_MS = 500;
|
|
44
|
+
/** Runs agent-desktop commands for one worker: its executable, its private state directory. */
|
|
45
|
+
export class AgentDesktopCli {
|
|
46
|
+
executable;
|
|
47
|
+
env;
|
|
48
|
+
constructor(executable, env) {
|
|
49
|
+
this.executable = executable;
|
|
50
|
+
this.env = env;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Runs one command and returns its `data`. A failure the envelope reports
|
|
54
|
+
* is thrown as `AgentDesktopFailure`, untranslated, so a caller can try
|
|
55
|
+
* another way when nothing was sent; `translate` turns it into the engine
|
|
56
|
+
* contract.
|
|
57
|
+
*/
|
|
58
|
+
async run(call) {
|
|
59
|
+
if (call.signal.aborted)
|
|
60
|
+
throw new EngineError('CANCELLED', `${call.label} was cancelled`, { retryable: false });
|
|
61
|
+
const { stdout, stderr, cutOff } = await this.spawn(call);
|
|
62
|
+
if (cutOff === 'aborted')
|
|
63
|
+
throw new EngineError('CANCELLED', `${call.label} was cancelled`, { retryable: false });
|
|
64
|
+
if (cutOff === 'timeout') {
|
|
65
|
+
throw call.input
|
|
66
|
+
? new EngineError('ACTION_MAY_HAVE_COMMITTED', `${call.label} timed out before agent-desktop answered; its input may have reached the app`, { retryable: false })
|
|
67
|
+
: new EngineError('OPERATION_TIMEOUT', `${call.label} timed out`, { retryable: false });
|
|
68
|
+
}
|
|
69
|
+
const envelope = parseEnvelope(stdout);
|
|
70
|
+
// A process that started and printed no result may have sent its input before it died.
|
|
71
|
+
if (envelope === undefined && call.input) {
|
|
72
|
+
throw new EngineError('ACTION_MAY_HAVE_COMMITTED', `${call.label}: agent-desktop exited without a result; its input may have reached the app`, { retryable: false });
|
|
73
|
+
}
|
|
74
|
+
if (envelope === undefined) {
|
|
75
|
+
const detail = stderr.trim().split('\n').slice(-3).join(' ').slice(0, 500);
|
|
76
|
+
throw new EngineError('ENGINE_FAILURE', `${call.label}: agent-desktop printed no result${detail === '' ? '' : ` (${detail})`}`, { retryable: false });
|
|
77
|
+
}
|
|
78
|
+
if (!envelope.ok)
|
|
79
|
+
throw new AgentDesktopFailure(envelope.error ?? { code: 'INTERNAL', message: 'agent-desktop failed without an error' });
|
|
80
|
+
return envelope.data;
|
|
81
|
+
}
|
|
82
|
+
/** One process, killed when the call's signal aborts or its budget runs out. */
|
|
83
|
+
spawn(call) {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
const child = spawn(this.executable, call.args, {
|
|
86
|
+
env: this.env,
|
|
87
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
88
|
+
windowsHide: true,
|
|
89
|
+
});
|
|
90
|
+
const stdout = [];
|
|
91
|
+
const stderr = [];
|
|
92
|
+
let cutOff;
|
|
93
|
+
const stop = (reason) => {
|
|
94
|
+
cutOff ??= reason;
|
|
95
|
+
child.kill('SIGKILL');
|
|
96
|
+
};
|
|
97
|
+
const timer = setTimeout(() => stop('timeout'), call.input ? Math.max(call.timeoutMs, MIN_INPUT_MS) : call.timeoutMs);
|
|
98
|
+
const onAbort = () => stop('aborted');
|
|
99
|
+
call.signal.addEventListener('abort', onAbort, { once: true });
|
|
100
|
+
child.stdout.on('data', (chunk) => stdout.push(chunk));
|
|
101
|
+
child.stderr.on('data', (chunk) => stderr.push(chunk));
|
|
102
|
+
// A command that exits before reading its stdin closes the pipe; the write error is that, not a failure.
|
|
103
|
+
child.stdin.on('error', () => undefined);
|
|
104
|
+
child.stdin.end(call.stdin ?? '');
|
|
105
|
+
child.on('error', (cause) => {
|
|
106
|
+
clearTimeout(timer);
|
|
107
|
+
call.signal.removeEventListener('abort', onAbort);
|
|
108
|
+
reject(new EngineError('ENGINE_FAILURE', `${call.label}: could not start agent-desktop at ${this.executable}: ${cause.message}`, { retryable: false, cause }));
|
|
109
|
+
});
|
|
110
|
+
child.on('close', () => {
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
call.signal.removeEventListener('abort', onAbort);
|
|
113
|
+
resolve({
|
|
114
|
+
stdout: Buffer.concat(stdout).toString('utf8'),
|
|
115
|
+
stderr: Buffer.concat(stderr).toString('utf8'),
|
|
116
|
+
...(cutOff === undefined ? {} : { cutOff }),
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** The envelope agent-desktop printed: the last line of stdout that parses as one. */
|
|
123
|
+
function parseEnvelope(stdout) {
|
|
124
|
+
const lines = stdout.trim().split('\n');
|
|
125
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
126
|
+
const line = lines[index].trim();
|
|
127
|
+
if (!line.startsWith('{'))
|
|
128
|
+
continue;
|
|
129
|
+
try {
|
|
130
|
+
const parsed = JSON.parse(line);
|
|
131
|
+
if (typeof parsed === 'object' && parsed !== null && typeof parsed.ok === 'boolean')
|
|
132
|
+
return parsed;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Not the envelope; keep looking.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
const STALE_CODES = new Set(['STALE_REF', 'SNAPSHOT_NOT_FOUND', 'ELEMENT_NOT_FOUND']);
|
|
141
|
+
const UNSUPPORTED_CODES = new Set(['ACTION_NOT_SUPPORTED', 'PLATFORM_NOT_SUPPORTED', 'POLICY_DENIED']);
|
|
142
|
+
const GONE_CODES = new Set(['APP_NOT_FOUND', 'WINDOW_NOT_FOUND']);
|
|
143
|
+
const REFUSED_CODES = new Set(['AMBIGUOUS_TARGET', 'ACTION_FAILED', 'TIMEOUT']);
|
|
144
|
+
/**
|
|
145
|
+
* The engine error for a failure of `label`. An `EngineError` passes through.
|
|
146
|
+
* `input` says whether the command sent input to the app: its failure is
|
|
147
|
+
* `ACTION_MAY_HAVE_COMMITTED` unless agent-desktop says nothing was sent.
|
|
148
|
+
*/
|
|
149
|
+
export function translate(cause, label, input) {
|
|
150
|
+
if (!(cause instanceof AgentDesktopFailure))
|
|
151
|
+
return cause instanceof Error ? cause : new EngineError('ENGINE_FAILURE', `${label}: ${String(cause)}`, { retryable: false });
|
|
152
|
+
const text = `${label}: ${cause.message}`;
|
|
153
|
+
if (input && !cause.notDelivered)
|
|
154
|
+
return new EngineError('ACTION_MAY_HAVE_COMMITTED', `${text} (the input may have reached the app)`, { retryable: false, cause });
|
|
155
|
+
if (STALE_CODES.has(cause.code))
|
|
156
|
+
return new EngineError('NODE_STALE', text, { retryable: true, cause });
|
|
157
|
+
if (UNSUPPORTED_CODES.has(cause.code))
|
|
158
|
+
return new EngineError('UNSUPPORTED_CAPABILITY', text, { retryable: false, cause });
|
|
159
|
+
if (GONE_CODES.has(cause.code))
|
|
160
|
+
return new EngineError('INVALID_STATE', `${text}; open the app with app.open()`, { retryable: false, cause });
|
|
161
|
+
// A read that ran out of time is a timeout; only an input that could not be delivered in time is not actionable.
|
|
162
|
+
if (cause.code === 'TIMEOUT' && !input)
|
|
163
|
+
return new EngineError('OPERATION_TIMEOUT', text, { retryable: false, cause });
|
|
164
|
+
if (REFUSED_CODES.has(cause.code))
|
|
165
|
+
return new EngineError('NOT_ACTIONABLE', text, { retryable: false, cause });
|
|
166
|
+
if (cause.code === 'PERM_DENIED') {
|
|
167
|
+
return new EngineError('ENGINE_FAILURE', `${text}. Grant Accessibility (and Screen Recording, for screenshots) to the app that starts e2e, such as your terminal, then run again`, { retryable: false, cause });
|
|
168
|
+
}
|
|
169
|
+
return new EngineError('ENGINE_FAILURE', text, { retryable: false, cause });
|
|
170
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `desktop` fixture: what a test asks of the desktop itself rather than
|
|
3
|
+
* of a control on screen. The harness records each call as a
|
|
4
|
+
* `desktop.<method>` step bounded by the action timeout.
|
|
5
|
+
*/
|
|
6
|
+
import type { EngineFixtureContext } from '@e2e-dev/core/engine';
|
|
7
|
+
import type { DesktopPlatform } from './options.ts';
|
|
8
|
+
import type { DesktopSurface, DesktopWindow } from './surface.ts';
|
|
9
|
+
/** Deterministic desktop management exposed to tests as `desktop`. */
|
|
10
|
+
export interface Desktop {
|
|
11
|
+
/** The OS the app runs on. */
|
|
12
|
+
readonly platform: DesktopPlatform;
|
|
13
|
+
/** The app's open windows, the focused one marked. */
|
|
14
|
+
windows(): Promise<readonly DesktopWindow[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Reads and acts in this window from now on, rather than the focused one,
|
|
17
|
+
* until the app quits: a panel or bubble that takes focus then cannot hide
|
|
18
|
+
* the window the test is about. With no window, goes back to the focused
|
|
19
|
+
* one.
|
|
20
|
+
*/
|
|
21
|
+
useWindow(window?: DesktopWindow | string): Promise<void>;
|
|
22
|
+
/** Quits the app. `app.open()` launches it again; every test ends with it quit. */
|
|
23
|
+
closeApp(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createDesktopFixture(surface: DesktopSurface, context: EngineFixtureContext): Desktop;
|
package/dist/desktop.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `desktop` fixture: what a test asks of the desktop itself rather than
|
|
3
|
+
* of a control on screen. The harness records each call as a
|
|
4
|
+
* `desktop.<method>` step bounded by the action timeout.
|
|
5
|
+
*/
|
|
6
|
+
export function createDesktopFixture(surface, context) {
|
|
7
|
+
const desktop = {
|
|
8
|
+
platform: surface.platform,
|
|
9
|
+
async windows() {
|
|
10
|
+
const operation = context.operation();
|
|
11
|
+
return await surface.windows(operation.signal, operation.timeoutMs);
|
|
12
|
+
},
|
|
13
|
+
async useWindow(window) {
|
|
14
|
+
const operation = context.operation();
|
|
15
|
+
await surface.useWindow(typeof window === 'string' ? window : window?.id, operation.signal, operation.timeoutMs);
|
|
16
|
+
},
|
|
17
|
+
async closeApp() {
|
|
18
|
+
const operation = context.operation();
|
|
19
|
+
await surface.closeApp(operation.signal, operation.timeoutMs);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
return context.fixture('desktop', desktop, {
|
|
23
|
+
windows: { kind: 'resource' },
|
|
24
|
+
useWindow: { kind: 'resource' },
|
|
25
|
+
closeApp: { kind: 'resource' },
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@e2e-dev/desktop/engine`: the `desktop()` factory and its types, without
|
|
3
|
+
* `test`, so a program that drives a desktop app with `@e2e-dev/core` never
|
|
4
|
+
* loads the test runner. The main entry re-exports all of it beside `test`.
|
|
5
|
+
*/
|
|
6
|
+
export { desktop } from './engine.ts';
|
|
7
|
+
/** The engine factory again, as the default export: what `e2e mcp` calls when `open_session` names this package as its `engine`. */
|
|
8
|
+
export { desktop as default } from './engine.ts';
|
|
9
|
+
export type { DesktopOptions, DesktopPlatform } from './options.ts';
|
|
10
|
+
export type { Desktop } from './desktop.ts';
|
|
11
|
+
export type { DesktopWindow } from './surface.ts';
|
|
12
|
+
export type { DesktopFixtures } from './fixtures.ts';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@e2e-dev/desktop/engine`: the `desktop()` factory and its types, without
|
|
3
|
+
* `test`, so a program that drives a desktop app with `@e2e-dev/core` never
|
|
4
|
+
* loads the test runner. The main entry re-exports all of it beside `test`.
|
|
5
|
+
*/
|
|
6
|
+
export { desktop } from './engine.js';
|
|
7
|
+
/** The engine factory again, as the default export: what `e2e mcp` calls when `open_session` names this package as its `engine`. */
|
|
8
|
+
export { desktop as default } from './engine.js';
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent-desktop engine for e2e: a desktop body built with the public
|
|
3
|
+
* `defineEngine`, validated by the same rules and graded by the same
|
|
4
|
+
* capabilities as any other engine. Core imports nothing from here; this
|
|
5
|
+
* package imports the contract from `@e2e-dev/core/engine` and contributes the
|
|
6
|
+
* `desktop` fixture the way the browser engine contributes `browser`.
|
|
7
|
+
*/
|
|
8
|
+
import { type EngineHandle } from '@e2e-dev/core/engine';
|
|
9
|
+
import type { DesktopFixtures } from './fixtures.ts';
|
|
10
|
+
import { type DesktopOptions } from './options.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Creates one desktop engine: it drives the target's macOS app on this
|
|
13
|
+
* machine, one worker at a time. A test launches the app with `app.open()`;
|
|
14
|
+
* every test ends with the app quit. A config that names it loads on any OS,
|
|
15
|
+
* so its other targets still run elsewhere; the target itself fails to start
|
|
16
|
+
* on any OS but macOS.
|
|
17
|
+
*/
|
|
18
|
+
export declare function desktop(options?: DesktopOptions): EngineHandle<DesktopFixtures>;
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent-desktop engine for e2e: a desktop body built with the public
|
|
3
|
+
* `defineEngine`, validated by the same rules and graded by the same
|
|
4
|
+
* capabilities as any other engine. Core imports nothing from here; this
|
|
5
|
+
* package imports the contract from `@e2e-dev/core/engine` and contributes the
|
|
6
|
+
* `desktop` fixture the way the browser engine contributes `browser`.
|
|
7
|
+
*/
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
import { ConfigurationError, defineEngine } from '@e2e-dev/core/engine';
|
|
10
|
+
import { createDesktopFixture } from './desktop.js';
|
|
11
|
+
import { requireMacOS, resolveOptions } from './options.js';
|
|
12
|
+
import { DesktopSurface } from './surface.js';
|
|
13
|
+
/** What `perform` honors through the accessibility API alone, on macOS. */
|
|
14
|
+
const ACTIONS = ['tap', 'secondaryTap', 'fill', 'clear', 'check', 'uncheck', 'focus', 'scrollIntoView', 'selectOption', 'swipe'];
|
|
15
|
+
/**
|
|
16
|
+
* What physical input adds: a double click and the pointer over a control
|
|
17
|
+
* (agent-desktop does both with the real pointer only), a key, which
|
|
18
|
+
* agent-desktop sends only to the active window, and taps at a point.
|
|
19
|
+
*/
|
|
20
|
+
const HEADED_ACTIONS = [...ACTIONS, 'press', 'doubleTap', 'hover'];
|
|
21
|
+
const HEADED_POINTER_ACTIONS = ['tap', 'doubleTap', 'secondaryTap', 'hover'];
|
|
22
|
+
/**
|
|
23
|
+
* Creates one desktop engine: it drives the target's macOS app on this
|
|
24
|
+
* machine, one worker at a time. A test launches the app with `app.open()`;
|
|
25
|
+
* every test ends with the app quit. A config that names it loads on any OS,
|
|
26
|
+
* so its other targets still run elsewhere; the target itself fails to start
|
|
27
|
+
* on any OS but macOS.
|
|
28
|
+
*/
|
|
29
|
+
export function desktop(options = {}) {
|
|
30
|
+
const resolved = resolveOptions(options);
|
|
31
|
+
const platform = 'macos';
|
|
32
|
+
const surface = new DesktopSurface(resolved, platform);
|
|
33
|
+
const headed = resolved.headed;
|
|
34
|
+
return defineEngine({
|
|
35
|
+
name: 'desktop',
|
|
36
|
+
version: ownVersion(),
|
|
37
|
+
spiVersion: 1,
|
|
38
|
+
platform,
|
|
39
|
+
workers: 1,
|
|
40
|
+
prepare: (info) => {
|
|
41
|
+
requireMacOS();
|
|
42
|
+
return surface.prepare(info);
|
|
43
|
+
},
|
|
44
|
+
doctor: async (info) => process.platform === 'darwin' ? await surface.doctor(info) : [{ id: 'platform', status: 'fail', message: `desktop() drives macOS apps only for now; this machine runs ${process.platform}` }],
|
|
45
|
+
init: (info) => {
|
|
46
|
+
requireMacOS();
|
|
47
|
+
return surface.init(info);
|
|
48
|
+
},
|
|
49
|
+
startAttempt: (context) => surface.startAttempt(context),
|
|
50
|
+
endAttempt: (context) => surface.endAttempt(context),
|
|
51
|
+
dispose: (context) => surface.dispose(context),
|
|
52
|
+
observe: (operation, observeOptions) => surface.observe(operation, observeOptions),
|
|
53
|
+
locate: (expression, operation) => surface.locate(expression, operation),
|
|
54
|
+
perform: (ref, action, operation) => surface.perform(ref, action, operation),
|
|
55
|
+
actions: headed ? HEADED_ACTIONS : ACTIONS,
|
|
56
|
+
...(headed
|
|
57
|
+
? { performAt: (point, action, operation) => surface.performAt(point, action, operation), pointerActions: HEADED_POINTER_ACTIONS }
|
|
58
|
+
: {}),
|
|
59
|
+
// Typing into whatever has focus must send keystrokes, which agent-desktop does with physical input only.
|
|
60
|
+
...(headed
|
|
61
|
+
? {
|
|
62
|
+
keyboard: {
|
|
63
|
+
type: (text, keyboardOptions, operation) => surface.typeText(text, keyboardOptions, operation),
|
|
64
|
+
press: (key, operation) => surface.pressKey(key, operation),
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
: {}),
|
|
68
|
+
validateApp: (app, info) => validateApp(app, info),
|
|
69
|
+
// No `open`: a desktop app has no URL, so the runner serves `app.open()`
|
|
70
|
+
// with `restart`, a fresh launch of the target's app.
|
|
71
|
+
session: {
|
|
72
|
+
restart: (operation) => surface.restart(operation),
|
|
73
|
+
},
|
|
74
|
+
artifacts: {
|
|
75
|
+
screenshot: (label, operation) => surface.screenshot(label, operation),
|
|
76
|
+
},
|
|
77
|
+
fixtures: {
|
|
78
|
+
desktop: (context) => createDesktopFixture(surface, context),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A desktop target launches an app: `bundleId` names an installed one (a
|
|
84
|
+
* bundle id or an app name), or `appPath` names a built `.app` bundle.
|
|
85
|
+
*/
|
|
86
|
+
function validateApp(app, { targetName }) {
|
|
87
|
+
const where = `target "${targetName}"`;
|
|
88
|
+
if (app.url !== undefined) {
|
|
89
|
+
throw new ConfigurationError('INVALID_CONFIG', `${where} declares app.url, but a desktop() target drives an installed app; name it with app.bundleId or app.appPath`);
|
|
90
|
+
}
|
|
91
|
+
if (app.bundleId === undefined && app.appPath === undefined) {
|
|
92
|
+
throw new ConfigurationError('INVALID_CONFIG', `${where} needs app.bundleId or app.appPath: desktop() launches an installed app, such as app: { bundleId: 'com.example.app' } or app: { appPath: 'build/Example.app' }`);
|
|
93
|
+
}
|
|
94
|
+
if (app.appPath !== undefined && !/\.app\/?$/.test(app.appPath)) {
|
|
95
|
+
throw new ConfigurationError('INVALID_CONFIG', `${where} app.appPath must name a macOS .app bundle, got ${JSON.stringify(app.appPath)}`);
|
|
96
|
+
}
|
|
97
|
+
if (app.permissions !== undefined) {
|
|
98
|
+
throw new ConfigurationError('INVALID_CONFIG', `${where} declares app.permissions, which a desktop() target cannot set`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** This package's published version, read through require resolution. */
|
|
102
|
+
function ownVersion() {
|
|
103
|
+
try {
|
|
104
|
+
return createRequire(import.meta.url)('../package.json').version;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return 'unknown';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The fixtures a `desktop()` target contributes, as types only. */
|
|
2
|
+
import type { Desktop } from './desktop.ts';
|
|
3
|
+
/** What a session on a `desktop()` target holds beside `screen` and `app`: the `desktop` fixture. */
|
|
4
|
+
export interface DesktopFixtures {
|
|
5
|
+
readonly desktop: Desktop;
|
|
6
|
+
}
|
package/dist/fixtures.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@e2e-dev/desktop` public surface: the `desktop()` engine factory, the
|
|
3
|
+
* `desktop` fixture types, and `test`, `describe`, and the hooks typed with
|
|
4
|
+
* that fixture. `expect`, `credentials`, and `secrets` still come from
|
|
5
|
+
* `e2e`. Without `e2e` installed, `desktop()` still loads and `test` throws
|
|
6
|
+
* when used.
|
|
7
|
+
*/
|
|
8
|
+
import type { DesktopFixtures } from './fixtures.ts';
|
|
9
|
+
export * from './engine-entry.ts';
|
|
10
|
+
/** The engine factory as the default export: what `e2e mcp` calls when `open_session` names this package as its `engine`. */
|
|
11
|
+
export { default } from './engine-entry.ts';
|
|
12
|
+
/**
|
|
13
|
+
* `test` typed with this engine's contributed `desktop` fixture. The same
|
|
14
|
+
* runtime `test` as `e2e`'s; only the fixture types differ.
|
|
15
|
+
*/
|
|
16
|
+
export declare const test: import("e2e").TestAPI<import("e2e").TestFixtures & DesktopFixtures, import("e2e").WorkerFixtures>;
|
|
17
|
+
/** `describe` and the hooks, the same functions as `test.describe` and `test.beforeEach`, typed with the `desktop` fixture. */
|
|
18
|
+
export declare const describe: {
|
|
19
|
+
<Result>(title: string, body: import("e2e").SynchronousBody<Result>): void;
|
|
20
|
+
<Result>(title: string, options: import("e2e").DescribeOptions, body: import("e2e").SynchronousBody<Result>): void;
|
|
21
|
+
}, beforeEach: (fn: import("e2e").TestHookFn<import("e2e").TestFixtures & DesktopFixtures & import("e2e").WorkerFixtures>) => void, afterEach: (fn: import("e2e").TestHookFn<import("e2e").TestFixtures & DesktopFixtures & import("e2e").WorkerFixtures>) => void, beforeAll: (fn: import("e2e").TestHookFn<import("e2e").WorkerFixtures>) => void, afterAll: (fn: import("e2e").TestHookFn<import("e2e").WorkerFixtures>) => void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@e2e-dev/desktop` public surface: the `desktop()` engine factory, the
|
|
3
|
+
* `desktop` fixture types, and `test`, `describe`, and the hooks typed with
|
|
4
|
+
* that fixture. `expect`, `credentials`, and `secrets` still come from
|
|
5
|
+
* `e2e`. Without `e2e` installed, `desktop()` still loads and `test` throws
|
|
6
|
+
* when used.
|
|
7
|
+
*/
|
|
8
|
+
import { runnerTest } from './runner-test.js';
|
|
9
|
+
export * from './engine-entry.js';
|
|
10
|
+
/** The engine factory as the default export: what `e2e mcp` calls when `open_session` names this package as its `engine`. */
|
|
11
|
+
export { default } from './engine-entry.js';
|
|
12
|
+
/**
|
|
13
|
+
* `test` typed with this engine's contributed `desktop` fixture. The same
|
|
14
|
+
* runtime `test` as `e2e`'s; only the fixture types differ.
|
|
15
|
+
*/
|
|
16
|
+
export const test = runnerTest().extend();
|
|
17
|
+
/** `describe` and the hooks, the same functions as `test.describe` and `test.beforeEach`, typed with the `desktop` fixture. */
|
|
18
|
+
export const { describe, beforeEach, afterEach, beforeAll, afterAll } = test;
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The contract's `press` grammar spelled as an agent-desktop key combo. */
|
|
2
|
+
/**
|
|
3
|
+
* The combo agent-desktop's `press` takes for one contract key: `Enter` is
|
|
4
|
+
* `return`, `ControlOrMeta+a` is `cmd+a`.
|
|
5
|
+
* A key agent-desktop has no name for is `UNSUPPORTED_CAPABILITY`, and so is
|
|
6
|
+
* `+`, which its combo syntax uses as the separator.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toCombo(key: string): string;
|
package/dist/keys.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** The contract's `press` grammar spelled as an agent-desktop key combo. */
|
|
2
|
+
import { EngineError, parseKey } from '@e2e-dev/core/engine';
|
|
3
|
+
/**
|
|
4
|
+
* agent-desktop's name for each contract key. Its `delete` is the key that
|
|
5
|
+
* deletes backwards, as a Mac labels it, so the forward Delete is
|
|
6
|
+
* `forwarddelete`. Insert has no key on a Mac keyboard and no name there.
|
|
7
|
+
*/
|
|
8
|
+
const KEY_NAMES = {
|
|
9
|
+
Enter: 'return',
|
|
10
|
+
Escape: 'escape',
|
|
11
|
+
Tab: 'tab',
|
|
12
|
+
Backspace: 'backspace',
|
|
13
|
+
Delete: 'forwarddelete',
|
|
14
|
+
Insert: undefined,
|
|
15
|
+
Space: 'space',
|
|
16
|
+
ArrowUp: 'up',
|
|
17
|
+
ArrowDown: 'down',
|
|
18
|
+
ArrowLeft: 'left',
|
|
19
|
+
ArrowRight: 'right',
|
|
20
|
+
Home: 'home',
|
|
21
|
+
End: 'end',
|
|
22
|
+
PageUp: 'pageup',
|
|
23
|
+
PageDown: 'pagedown',
|
|
24
|
+
F1: 'f1',
|
|
25
|
+
F2: 'f2',
|
|
26
|
+
F3: 'f3',
|
|
27
|
+
F4: 'f4',
|
|
28
|
+
F5: 'f5',
|
|
29
|
+
F6: 'f6',
|
|
30
|
+
F7: 'f7',
|
|
31
|
+
F8: 'f8',
|
|
32
|
+
F9: 'f9',
|
|
33
|
+
F10: 'f10',
|
|
34
|
+
F11: 'f11',
|
|
35
|
+
F12: 'f12',
|
|
36
|
+
};
|
|
37
|
+
function modifierName(modifier) {
|
|
38
|
+
switch (modifier) {
|
|
39
|
+
case 'Shift':
|
|
40
|
+
return 'shift';
|
|
41
|
+
case 'Control':
|
|
42
|
+
return 'ctrl';
|
|
43
|
+
case 'Alt':
|
|
44
|
+
return 'alt';
|
|
45
|
+
case 'Meta':
|
|
46
|
+
case 'ControlOrMeta':
|
|
47
|
+
return 'cmd';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The combo agent-desktop's `press` takes for one contract key: `Enter` is
|
|
52
|
+
* `return`, `ControlOrMeta+a` is `cmd+a`.
|
|
53
|
+
* A key agent-desktop has no name for is `UNSUPPORTED_CAPABILITY`, and so is
|
|
54
|
+
* `+`, which its combo syntax uses as the separator.
|
|
55
|
+
*/
|
|
56
|
+
export function toCombo(key) {
|
|
57
|
+
const parsed = parseKey(key);
|
|
58
|
+
if (parsed === undefined)
|
|
59
|
+
throw new EngineError('UNSUPPORTED_CAPABILITY', `"${key}" is not a key in the press grammar`, { retryable: false });
|
|
60
|
+
let name;
|
|
61
|
+
if (parsed.key.kind === 'named') {
|
|
62
|
+
name = KEY_NAMES[parsed.key.name];
|
|
63
|
+
}
|
|
64
|
+
else if (parsed.key.char === ' ') {
|
|
65
|
+
name = 'space';
|
|
66
|
+
}
|
|
67
|
+
else if (parsed.key.char !== '+') {
|
|
68
|
+
// agent-desktop lower-cases a combo and adds Shift for a lone capital letter, so a capital needs no help.
|
|
69
|
+
name = parsed.key.char;
|
|
70
|
+
}
|
|
71
|
+
if (name === undefined) {
|
|
72
|
+
throw new EngineError('UNSUPPORTED_CAPABILITY', `agent-desktop cannot press "${key}" on macOS`, { retryable: false });
|
|
73
|
+
}
|
|
74
|
+
const modifiers = parsed.modifiers.map(modifierName);
|
|
75
|
+
// A capital letter with other modifiers loses its case in agent-desktop's combo, so Shift says it.
|
|
76
|
+
if (parsed.key.kind === 'char' && /^[A-Z]$/.test(parsed.key.char) && modifiers.length > 0 && !modifiers.includes('shift'))
|
|
77
|
+
modifiers.push('shift');
|
|
78
|
+
return [...modifiers, name].join('+');
|
|
79
|
+
}
|
package/dist/nodes.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-desktop's snapshot tree projected onto the contract's semantic
|
|
3
|
+
* nodes. agent-desktop already speaks one closed role and state vocabulary
|
|
4
|
+
* on every OS; this maps it onto the ARIA names `screen.getByRole` and the
|
|
5
|
+
* agent use on every other engine, so `getByRole('textbox')` means the same
|
|
6
|
+
* field in a browser, on a phone, and in a desktop app.
|
|
7
|
+
*/
|
|
8
|
+
import type { SemanticNode, ViewportSize } from '@e2e-dev/core/engine';
|
|
9
|
+
/** A rectangle in screen points, as agent-desktop reports bounds. */
|
|
10
|
+
export interface Rect {
|
|
11
|
+
readonly x: number;
|
|
12
|
+
readonly y: number;
|
|
13
|
+
readonly width: number;
|
|
14
|
+
readonly height: number;
|
|
15
|
+
}
|
|
16
|
+
/** One node of an agent-desktop snapshot (`snapshot --include-bounds`). */
|
|
17
|
+
export interface RawNode {
|
|
18
|
+
readonly ref_id?: string;
|
|
19
|
+
readonly role: string;
|
|
20
|
+
readonly name?: string;
|
|
21
|
+
readonly value?: string;
|
|
22
|
+
readonly description?: string;
|
|
23
|
+
readonly hint?: string;
|
|
24
|
+
readonly placeholder?: string;
|
|
25
|
+
readonly native_id?: {
|
|
26
|
+
readonly kind: string;
|
|
27
|
+
readonly value: string;
|
|
28
|
+
};
|
|
29
|
+
readonly states?: readonly string[];
|
|
30
|
+
readonly available_actions?: readonly string[];
|
|
31
|
+
readonly bounds?: Rect;
|
|
32
|
+
readonly subtree_truncated?: boolean;
|
|
33
|
+
/** How many children the element has, when agent-desktop stopped at the depth limit and listed none of them. */
|
|
34
|
+
readonly children_count?: number;
|
|
35
|
+
readonly children?: readonly RawNode[];
|
|
36
|
+
}
|
|
37
|
+
/** The `data` of an agent-desktop `snapshot`. */
|
|
38
|
+
export interface RawSnapshot {
|
|
39
|
+
readonly app?: string;
|
|
40
|
+
readonly snapshot_id: string;
|
|
41
|
+
readonly complete?: boolean;
|
|
42
|
+
readonly truncated?: boolean;
|
|
43
|
+
readonly tree: RawNode;
|
|
44
|
+
readonly window?: {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly title?: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** The observation root's id: one window, the same id across observations, as the contract requires. */
|
|
50
|
+
export declare const ROOT_ID = "root";
|
|
51
|
+
/** What an action needs to know about a node, kept beside the node the harness sees. */
|
|
52
|
+
export interface NodeBinding {
|
|
53
|
+
readonly id: string;
|
|
54
|
+
/** agent-desktop's snapshot-qualified ref (`@s8f3k2p9:e3`); absent for a node it gives none, such as static text. */
|
|
55
|
+
readonly ref?: string;
|
|
56
|
+
readonly role?: string;
|
|
57
|
+
readonly name?: string;
|
|
58
|
+
readonly states: SemanticNode['states'];
|
|
59
|
+
/** The actions agent-desktop says the element takes (`Click`, `SetValue`, `Expand`, ...). */
|
|
60
|
+
readonly actions: readonly string[];
|
|
61
|
+
/** The window the snapshot read the node in. */
|
|
62
|
+
readonly windowId?: string;
|
|
63
|
+
/** The node's box in the window, which finds it again where its id cannot (a look-alike's). */
|
|
64
|
+
readonly rect?: Rect;
|
|
65
|
+
/** Whether the id comes from the node's identity and every ancestor's, and so names it in the next snapshot too; a look-alike's, or one inside a look-alike, is new in every snapshot. */
|
|
66
|
+
readonly stable: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** A snapshot as the engine keeps it: the tree the harness sees, and a binding for every node in it. */
|
|
69
|
+
export interface ProjectedScreen {
|
|
70
|
+
readonly root: SemanticNode;
|
|
71
|
+
readonly bindings: ReadonlyMap<string, NodeBinding>;
|
|
72
|
+
/** The window, in screen points: the viewport every node's rect is measured from. */
|
|
73
|
+
readonly window: Rect;
|
|
74
|
+
readonly viewport: ViewportSize;
|
|
75
|
+
/** Rects of the secure fields, in the viewport's points, for masking. Undefined when a secure field has no bounds to mask. */
|
|
76
|
+
readonly secureRects: readonly Rect[] | undefined;
|
|
77
|
+
readonly truncated: boolean;
|
|
78
|
+
readonly windowId?: string;
|
|
79
|
+
readonly title?: string;
|
|
80
|
+
/** The first scrollable node, which the observation root's swipe scrolls. */
|
|
81
|
+
readonly scrollTarget?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Projects one snapshot. `idFor` turns a node's identity (its parent's id,
|
|
85
|
+
* and its own role and developer id or name) into the id the harness sees:
|
|
86
|
+
* the caller hands out the same id for the same identity across
|
|
87
|
+
* observations, so a control keeps its id for as long as it exists, as the
|
|
88
|
+
* contract asks. A node with a look-alike sibling has no identity
|
|
89
|
+
* (`undefined`) and gets a new id, which no later snapshot gives out again.
|
|
90
|
+
* The window is always `root`.
|
|
91
|
+
* Wrappers nothing reads (anonymous groups) are dropped
|
|
92
|
+
* and their children lifted, so the model reads the controls, not the
|
|
93
|
+
* scaffolding, and the window's title-bar buttons are left out.
|
|
94
|
+
*/
|
|
95
|
+
export declare function projectSnapshot(raw: RawSnapshot, idFor: (identity: string | undefined) => string): ProjectedScreen;
|