@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.
@@ -0,0 +1,270 @@
1
+ /**
2
+ * One worker's desktop session: the macOS app the target declares, driven
3
+ * through agent-desktop's accessibility commands. The app is launched in the
4
+ * background, and every action goes through the accessibility API, so the
5
+ * user's pointer, focus, and typing stay where they are, unless the target
6
+ * opts into physical input with `headed`.
7
+ */
8
+ import { type EngineAttemptContext, type EngineCleanupContext, type EngineDoctorCheck, type EngineDoctorInfo, type EngineInitInfo, type EngineObserveOptions, type EnginePrepareInfo, type EnginePrepareResult, type EngineSnapshot, type LocatorAction, type LocatorExpression, type NodeRef, type OperationContext, type PointerAction, type SemanticNode, type ViewportPoint } from '@e2e-dev/core/engine';
9
+ import type { DesktopPlatform, ResolvedDesktopOptions } from './options.ts';
10
+ /** One window of the app under test, as `desktop.windows()` lists it. */
11
+ export interface DesktopWindow {
12
+ /** agent-desktop's window id, valid while the window stays open. */
13
+ readonly id: string;
14
+ readonly title: string;
15
+ readonly focused: boolean;
16
+ }
17
+ export declare class DesktopSurface {
18
+ readonly options: ResolvedDesktopOptions;
19
+ readonly platform: DesktopPlatform;
20
+ private cli;
21
+ private home;
22
+ private app;
23
+ private projectRoot;
24
+ /** The app's bundle id or name: the target's `bundleId`, or the bundle id read from its `appPath`. */
25
+ private launchTarget;
26
+ /** The `.app` bundle an `appPath` names, resolved; the launched process must run from it. */
27
+ private bundle;
28
+ /** The process name agent-desktop reported at launch, which window lookups filter by before they keep the launched process's own. */
29
+ private appName;
30
+ /** The process the engine launched, which it alone quits; another instance of the same app is never touched. */
31
+ private pid;
32
+ /** agent-desktop's identity of that process, which a later process given the same id does not share. */
33
+ private instance;
34
+ /**
35
+ * A launch whose outcome is unknown (it timed out, or failed after it may
36
+ * have started the app): its token, so the next quit can still find and
37
+ * end the process it started.
38
+ */
39
+ private pending;
40
+ private attempt;
41
+ /** The launch or quit running now, which the next one waits for. */
42
+ private lifecycle;
43
+ /** The window a test chose with `desktop.useWindow`, which every read and command then uses until the app quits. */
44
+ private chosenWindow;
45
+ /** The window of the newest screen handed to the harness, by observe or locate: the one a point is measured in. */
46
+ private pointWindow;
47
+ /** The newest binding of every node id an observation or a locate handed out, newest last. */
48
+ private readonly bindings;
49
+ /** The id handed out for each node identity since the app launched; see `projectSnapshot`. */
50
+ private readonly ids;
51
+ private sequence;
52
+ private toolVersion;
53
+ /** The run's environment cut to `INHERITED_ENV`: all the app and agent-desktop are given of it. */
54
+ private appEnv;
55
+ constructor(options: ResolvedDesktopOptions, platform: DesktopPlatform);
56
+ /** Downloads the pinned agent-desktop once per machine, unless the target names its own. */
57
+ prepare(info: EnginePrepareInfo): Promise<EnginePrepareResult>;
58
+ init(info: EngineInitInfo): Promise<void>;
59
+ /**
60
+ * The app's bundle id or name. An `appPath` on macOS is an `.app` bundle,
61
+ * which is what gets launched even when `bundleId` is set too: its
62
+ * `CFBundleIdentifier`, which `list-apps` reports for the process that
63
+ * bundle starts, and which must then equal `bundleId`.
64
+ */
65
+ private resolveLaunchTarget;
66
+ startAttempt(context: EngineAttemptContext): Promise<void>;
67
+ /**
68
+ * Quits the app the attempt launched, so the next test starts from a
69
+ * closed app as the first one did. A quit that fails is reported, and the
70
+ * engine keeps the process as its own, so `dispose` tries again.
71
+ */
72
+ endAttempt(context: EngineCleanupContext): Promise<void>;
73
+ dispose(context: EngineCleanupContext): Promise<void>;
74
+ doctor(info: EngineDoctorInfo): Promise<readonly EngineDoctorCheck[]>;
75
+ /**
76
+ * `app.open()`: the copy of the app the engine launched is quit, and the
77
+ * app launched fresh, in the background unless `headed`, with the target's
78
+ * launch arguments. A copy the engine did not launch (the developer's own)
79
+ * is left alone, and never read or driven. A launch that failed after the
80
+ * app started still leaves the engine owning the new process, so the end
81
+ * of the attempt quits it.
82
+ */
83
+ restart(context: OperationContext): Promise<void>;
84
+ /** `restart` once no other launch or quit of this surface is running. */
85
+ private launchFresh;
86
+ /** Puts the launch record in the state directory, renamed into place so a worker killed mid-write never leaves half a record. */
87
+ private writeRecord;
88
+ /**
89
+ * The process ids of the app's copies running now. Undefined when
90
+ * agent-desktop listed the apps only in part: then no copy can be shown to
91
+ * be new, and a launch is told by its token alone.
92
+ */
93
+ private runningCopies;
94
+ /** Launches an installed app by bundle id or name through agent-desktop, which reports the process it started. */
95
+ private launchById;
96
+ /**
97
+ * Starts a new process of the `.app` bundle an `appPath` names, by its
98
+ * path: launching by bundle id would let LaunchServices pick another copy
99
+ * with the same id (an installed release, another checkout's build). The
100
+ * process is then found by its launch token among the app's running copies
101
+ * (see `claim`), since `open` reports no process id; one
102
+ * that cannot be found within `LAUNCH_READY_MS` fails the open, and stays
103
+ * pending, so the end of the attempt still looks for it.
104
+ */
105
+ private openBundle;
106
+ /**
107
+ * Takes as the engine's own the running copy of the app this launch
108
+ * started: the one that carries its token in its environment. False when
109
+ * there is none (yet); undefined when agent-desktop listed the apps only
110
+ * in part and none carries the token, which shows nothing: the launch's
111
+ * copy may be among the ones left out. A copy without the token is never
112
+ * taken, not even the one new copy whose environment cannot be read: being
113
+ * new does not show this launch started it, and the developer's own copy
114
+ * may be the one that just started.
115
+ */
116
+ private claim;
117
+ private take;
118
+ /**
119
+ * Waits until the launched app's window can be read: a window exists soon
120
+ * after the launch, but its accessibility element can arrive a moment
121
+ * later, and an observation then would show the agent an empty screen. A
122
+ * window that stays unreadable for `LAUNCH_READY_MS` fails the open: every
123
+ * later step would only time out on an empty screen. Any other failure of a
124
+ * read is reported as it is. An app in the background is never brought
125
+ * forward: one that opens no window there (a document-based app opens its
126
+ * first one only when it comes forward) fails the open, and needs `headed`.
127
+ */
128
+ private windowReadable;
129
+ /** The windows of the app the engine launched, for the `desktop` fixture; none while it is not running. */
130
+ windows(signal: AbortSignal, timeoutMs: number): Promise<readonly DesktopWindow[]>;
131
+ /**
132
+ * `desktop.useWindow()`: reads and acts in the window `id` names from now
133
+ * on, until the app quits, rather than the focused one. With no id, goes
134
+ * back to the focused window.
135
+ */
136
+ useWindow(id: string | undefined, signal: AbortSignal, timeoutMs: number): Promise<void>;
137
+ private chosenClosed;
138
+ /** `desktop.closeApp()`: the app quit, as at the end of every test. */
139
+ closeApp(signal: AbortSignal, timeoutMs: number): Promise<void>;
140
+ /**
141
+ * Quits the app the engine launched, forcefully: a test needs it gone, not
142
+ * asked to save. It is ended by its process id, so another instance of the
143
+ * same app (the developer's own copy) is left alone, and waited for, so the
144
+ * next launch cannot find it still running. The process is looked up
145
+ * first: one that exited on its own, or whose id the OS gave to another
146
+ * process since, is not running any more, and nothing is killed. Until the
147
+ * process is known to be gone, the engine keeps it as its own, so a quit
148
+ * that failed is tried again.
149
+ */
150
+ /**
151
+ * Runs launches and quits of this surface one at a time: two at once would
152
+ * each launch a copy into the one process id and launch record the engine
153
+ * keeps, and the end of the attempt would quit only one of them.
154
+ */
155
+ private serially;
156
+ /** `quitNow` once no other launch or quit of this surface is running. */
157
+ private quit;
158
+ private quitNow;
159
+ /** Every binding of the screen before: after a launch or a quit, none names a control that still exists. */
160
+ private forget;
161
+ /** The node id for an identity: the one it had before, else a new one, never handed out before since the app launched. */
162
+ private idFor;
163
+ /**
164
+ * Projects a snapshot of one window, its node identities scoped to that
165
+ * window. An identity of that window the snapshot no longer has is retired:
166
+ * a control that went, or now has a look-alike sibling, never passes its id
167
+ * on to another. Another window's identities stay, so its controls keep
168
+ * their ids when it is read again.
169
+ */
170
+ private projectWindow;
171
+ /**
172
+ * One snapshot of a window of the app the engine launched, projected: the
173
+ * window `windowId` names, else the one the test chose (and no other while
174
+ * it is chosen), else the focused one, the visible ones, and the rest, in
175
+ * that order, the first one accessibility can read. `forMask` is a
176
+ * read that only places secure fields: it reads every node even with
177
+ * `snapshot: 'interactive'`, which leaves out a secure node with no action
178
+ * of its own, and hands out no ids, so the ids of the screen the harness
179
+ * holds stay as they are. Undefined, an empty screen, before `app.open()`
180
+ * and while the running app has no window; a copy of the app the engine
181
+ * did not launch is never read. A read that fails is no empty screen,
182
+ * which would let a negative assertion pass: an app that quit is
183
+ * `INVALID_STATE`, as is a chosen window that closed, and windows none of
184
+ * which could be read are a retryable `NODE_STALE`, so a locator reads
185
+ * again until its deadline.
186
+ */
187
+ private capture;
188
+ /**
189
+ * Throws unless the process the engine launched still runs: its id alone
190
+ * does not show that, since another process can take the id over once the
191
+ * app quits, so the app list must show the same process instance. A list
192
+ * that left copies out shows nothing, and the read is tried again.
193
+ */
194
+ private requireRunning;
195
+ /** The windows of the process the engine launched; none before `app.open()` or after the app quit. */
196
+ private ownWindows;
197
+ /** The window of the launched process a command reads or acts in: the one the test chose, else the focused one, else the first visible one. */
198
+ private ownWindow;
199
+ observe(context: OperationContext, options: EngineObserveOptions | undefined): Promise<EngineSnapshot>;
200
+ private snapshotOf;
201
+ locate(expression: LocatorExpression, context: OperationContext): Promise<readonly SemanticNode[]>;
202
+ private binding;
203
+ /**
204
+ * Keeps the newest binding of each node: an id names the same control in
205
+ * every snapshot, and the newest snapshot's agent-desktop ref is the one to
206
+ * act on. A control that has since gone keeps its last ref, which
207
+ * agent-desktop refuses as stale.
208
+ */
209
+ private remember;
210
+ private refOf;
211
+ perform(ref: NodeRef, action: LocatorAction, context: OperationContext): Promise<void>;
212
+ /** The agent reads the screen right after acting, so its actions let the UI settle first; a test's own steps verify with `expect`. */
213
+ private settle;
214
+ /** One command on a node's ref, failures translated. */
215
+ private refCommand;
216
+ /** One command on a node's ref, a failure left as agent-desktop reported it so a caller can try another way when nothing was sent. */
217
+ private tryRef;
218
+ /**
219
+ * Chooses an option of a list or dropdown with agent-desktop's `select`,
220
+ * never by setting the value, which would put a missing option in an
221
+ * editable combo box as free text. A stale ref is `NODE_STALE`, so the
222
+ * harness locates the list again. For a pop-up button agent-desktop opens
223
+ * the menu to find the option; when it cannot, it leaves the menu open,
224
+ * which is closed again here. A failure after the menu opened stays one
225
+ * that may have chosen something: a menu left open does not show which
226
+ * control opened it, or that the option is missing.
227
+ */
228
+ private select;
229
+ /**
230
+ * Closes a menu the launched process has open, with Escape. True only when
231
+ * a menu was open and is closed now; false when there was none, or it
232
+ * cannot be told whose it is (another copy shares the app's name).
233
+ */
234
+ private closeOpenMenu;
235
+ private scroll;
236
+ /** Physical pointer input at a point in the window: only with `headed`, and only then declared. */
237
+ performAt(point: ViewportPoint, action: PointerAction, context: OperationContext): Promise<void>;
238
+ /** The keyboard capability's `type` (declared with `headed` only): keystrokes into the focused field, which a fresh snapshot names. */
239
+ typeText(text: string, options: {
240
+ readonly replace: boolean;
241
+ }, context: OperationContext): Promise<void>;
242
+ /** One key to whatever holds focus in the app; agent-desktop sends it to the process without focusing its window. */
243
+ pressKey(key: string, context: OperationContext): Promise<void>;
244
+ /**
245
+ * Sends one key combo to the launched process's window. agent-desktop
246
+ * sends a key to a named window only while that window is active, which
247
+ * an app in the background never is, and refuses it before sending. A key
248
+ * is never sent by the app's name instead: the name does not pin the
249
+ * process, so the key could reach another copy. With `headed`,
250
+ * agent-desktop brings the window forward first.
251
+ */
252
+ private sendKey;
253
+ screenshot(label: string | undefined, context: OperationContext): Promise<string>;
254
+ /**
255
+ * The window's pixels with every secure field painted over. The fields
256
+ * come from the snapshot taken just before, and the window is read again
257
+ * after the capture: a secure field without bounds, a partial snapshot, or
258
+ * a field that moved in between withholds the image rather than ship it
259
+ * unproven.
260
+ */
261
+ private pixelsFor;
262
+ /** agent-desktop's own wait inside one command: the operation's budget less a margin, so it answers before it is killed. */
263
+ private toolBudget;
264
+ /**
265
+ * Runs one command. A failure is translated onto the engine contract
266
+ * unless `raw` asks for agent-desktop's own, which a caller reads to try
267
+ * another way.
268
+ */
269
+ private run;
270
+ }