@e2e-dev/desktop 0.0.0-stage → 0.0.1-nightly-20261122030204
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 +18 -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/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @e2e-dev/desktop
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The desktop engine for [`e2e`](https://www.npmjs.com/package/e2e), built on
|
|
4
|
+
[agent-desktop](https://github.com/vercel-labs/agent-desktop): native macOS
|
|
5
|
+
apps, read and driven through the accessibility tree, through the same
|
|
6
|
+
`@e2e-dev/core/engine` contract the browser and mobile engines implement. A
|
|
7
|
+
test written against `screen`, `expect`, `app`, and `agent` runs on a desktop
|
|
8
|
+
target unchanged.
|
|
9
|
+
|
|
10
|
+
> [!NOTE]
|
|
11
|
+
> This is a prototype, and it runs on macOS only. A config with a desktop
|
|
12
|
+
> target still loads elsewhere, but the target fails to start.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install --save-dev e2e @e2e-dev/desktop
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The engine downloads its pinned agent-desktop release on the first run and
|
|
21
|
+
checks it against its SHA-256 digest. To use an install of your own (Homebrew,
|
|
22
|
+
a CI image), pass `desktop({ binary: '/path/to/agent-desktop' })`.
|
|
23
|
+
|
|
24
|
+
On macOS, the app that starts e2e (your terminal, IDE, or CI agent) needs
|
|
25
|
+
Accessibility permission, and Screen Recording for screenshots, in System
|
|
26
|
+
Settings > Privacy & Security. Run `npx e2e doctor` to check.
|
|
27
|
+
|
|
28
|
+
```ts title="e2e.config.ts"
|
|
29
|
+
import type { E2EConfig } from 'e2e';
|
|
30
|
+
import { desktop } from '@e2e-dev/desktop';
|
|
31
|
+
|
|
32
|
+
export default {
|
|
33
|
+
targets: [{ name: 'mac', engine: desktop(), app: { appPath: 'build/MyApp.app' } }],
|
|
34
|
+
} satisfies E2EConfig;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`app.bundleId` names an installed app instead (`'com.apple.TextEdit'`, or an
|
|
38
|
+
app name), and `app.launchArguments` are passed to every launch.
|
|
39
|
+
|
|
40
|
+
```ts title="tests/sign-in.e2e.ts"
|
|
41
|
+
import { test } from '@e2e-dev/desktop';
|
|
42
|
+
import { credentials, expect } from 'e2e';
|
|
43
|
+
|
|
44
|
+
test('signs in', async ({ app, screen }) => {
|
|
45
|
+
await app.open();
|
|
46
|
+
await screen.getByRole('textbox', 'Username').fill('ada');
|
|
47
|
+
await screen.getByRole('textbox', 'Password').fill(credentials.user('ada').password);
|
|
48
|
+
await screen.getByRole('button', 'Sign in').tap();
|
|
49
|
+
await expect(screen.getByTestId('status')).toContainText('Signed in');
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## How it works
|
|
54
|
+
|
|
55
|
+
- `app.open()` launches the app fresh, in the background, after quitting the
|
|
56
|
+
copy the engine launched before. A copy you opened yourself is never read,
|
|
57
|
+
driven, or quit. Every test ends with the app quit.
|
|
58
|
+
- The app gets only `HOME`, `USER`, `LOGNAME`, `SHELL`, `PATH`, `TMPDIR`,
|
|
59
|
+
`LANG`, `LC_*`, and `__CF_USER_TEXT_ENCODING` of the run's environment, and
|
|
60
|
+
`E2E_DESKTOP_LAUNCH`, the token the engine finds its copy by.
|
|
61
|
+
- An observation is one agent-desktop snapshot of the app's window. Roles map
|
|
62
|
+
onto the ARIA names other engines use (`textbox`, `checkbox`, `combobox`,
|
|
63
|
+
`button`); the developer id (`AXIdentifier`) is the node's test id, so
|
|
64
|
+
`getByTestId` finds it.
|
|
65
|
+
- Actions go through the accessibility API and leave your pointer, focus, and
|
|
66
|
+
typing alone. `desktop({ headed: true })` brings the app forward and allows
|
|
67
|
+
physical input: `doubleTap`, `hover`, `press`, point-addressed taps, and
|
|
68
|
+
typing into whatever has focus.
|
|
69
|
+
- A fill sends the text to agent-desktop on stdin, never in its arguments.
|
|
70
|
+
A secure field reports no value, and screenshots paint over its bounds; when
|
|
71
|
+
a secure field has no bounds, the screenshot is withheld.
|
|
72
|
+
- Not supported yet: the menu bar, and web content (a browser window, an
|
|
73
|
+
Electron app, a web view).
|
|
74
|
+
- One worker per target: its workers would share one screen. Two desktop
|
|
75
|
+
targets run at the same time. With `headed: true` they would share the
|
|
76
|
+
pointer and keyboard too, so set the run's `workers: 1`.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
Apache-2.0
|
package/dist/.build.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"0.0.1-nightly-20261122030204"}
|
package/dist/binary.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the agent-desktop executable comes from: the `binary` option, or the
|
|
3
|
+
* pinned release the engine downloads once per machine and checks against
|
|
4
|
+
* its SHA-256 digest. The npm package `agent-desktop` is not a dependency:
|
|
5
|
+
* its `postinstall` script would run in every install of this package.
|
|
6
|
+
*/
|
|
7
|
+
/** The agent-desktop release this engine is written and tested against. */
|
|
8
|
+
export declare const AGENT_DESKTOP_VERSION = "1.3.1";
|
|
9
|
+
/** Whether the pinned release is in the cache whole and checked, as `prepare` leaves it and a worker needs it. */
|
|
10
|
+
export declare function pinnedInstalled(env: Readonly<Record<string, string | undefined>>): Promise<boolean>;
|
|
11
|
+
/** Where the executable is, or would be once `prepare` downloads it; undefined when nothing can be run here. */
|
|
12
|
+
export declare function pinnedExecutable(env: Readonly<Record<string, string | undefined>>): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The executable a worker runs: the `binary` option resolved against the
|
|
15
|
+
* project, else the pinned release. Throws when neither exists, which means
|
|
16
|
+
* `prepare` did not run (a programmatic host that skips it) or failed.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveExecutable(binary: string | undefined, projectRoot: string, env: Readonly<Record<string, string | undefined>>): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Downloads and unpacks the pinned release unless a whole, checked copy is
|
|
21
|
+
* already in the cache; a damaged one is replaced. Any failure but a
|
|
22
|
+
* cancellation is `AGENT_DESKTOP_INSTALL_FAILED`. `digests` is the pinned
|
|
23
|
+
* table, which only a test replaces, to unpack an archive of its own.
|
|
24
|
+
*/
|
|
25
|
+
export declare function installPinned(env: Readonly<Record<string, string | undefined>>, signal: AbortSignal, log: (line: string) => void, digests?: Readonly<Record<string, string>>): Promise<string>;
|
package/dist/binary.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the agent-desktop executable comes from: the `binary` option, or the
|
|
3
|
+
* pinned release the engine downloads once per machine and checks against
|
|
4
|
+
* its SHA-256 digest. The npm package `agent-desktop` is not a dependency:
|
|
5
|
+
* its `postinstall` script would run in every install of this package.
|
|
6
|
+
*/
|
|
7
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
8
|
+
import { execFile } from 'node:child_process';
|
|
9
|
+
import { constants } from 'node:fs';
|
|
10
|
+
import { access, chmod, mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { promisify } from 'node:util';
|
|
14
|
+
import { ConfigurationError, InfrastructureError } from '@e2e-dev/core/engine';
|
|
15
|
+
/** The agent-desktop release this engine is written and tested against. */
|
|
16
|
+
export const AGENT_DESKTOP_VERSION = '1.3.1';
|
|
17
|
+
/** SHA-256 of each release archive, by Rust target triple, from the release's `checksums.txt`. */
|
|
18
|
+
const ARCHIVE_DIGESTS = {
|
|
19
|
+
'aarch64-apple-darwin': '9b7b7cfc74892eab46c2c85d6cb7dc4863bf8dab0a222cfcfb8ae4604c69c86c',
|
|
20
|
+
'x86_64-apple-darwin': '469da10cfb68928c58caff88b92b30526e0ca895ac06bc86b7f533b1d9b309b3',
|
|
21
|
+
'aarch64-pc-windows-msvc': '805f1f61890f9983fceaf38cda94a37a049c379435d65607db5cedd22c8ef97b',
|
|
22
|
+
'x86_64-pc-windows-msvc': '6ee4b1e078f4e78792e79f16e32e4a78b9919464aa3c55629b7e27ed53a08c13',
|
|
23
|
+
'aarch64-unknown-linux-gnu': '438990a703fbeb19775596c341c3701435e80adbfa1b2f64b82ff17567d5573b',
|
|
24
|
+
'x86_64-unknown-linux-gnu': 'ca77b6b75034eeb12e537dd8c0a4f2a3424119253f38b7e6bd79ba0d2fef1264',
|
|
25
|
+
};
|
|
26
|
+
const execFileAsync = promisify(execFile);
|
|
27
|
+
/** The release target for this machine; undefined on an OS or architecture agent-desktop ships no build for. */
|
|
28
|
+
function releaseTarget() {
|
|
29
|
+
const arch = process.arch === 'arm64' ? 'aarch64' : process.arch === 'x64' ? 'x86_64' : undefined;
|
|
30
|
+
if (arch === undefined)
|
|
31
|
+
return undefined;
|
|
32
|
+
switch (process.platform) {
|
|
33
|
+
case 'darwin':
|
|
34
|
+
return `${arch}-apple-darwin`;
|
|
35
|
+
case 'win32':
|
|
36
|
+
return `${arch}-pc-windows-msvc`;
|
|
37
|
+
case 'linux':
|
|
38
|
+
return `${arch}-unknown-linux-gnu`;
|
|
39
|
+
default:
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The executable's file name on this OS. */
|
|
44
|
+
function executableName() {
|
|
45
|
+
return process.platform === 'win32' ? 'agent-desktop.exe' : 'agent-desktop';
|
|
46
|
+
}
|
|
47
|
+
/** The file an unpacked release is stamped with once its archive's digest checked out: the digest itself. */
|
|
48
|
+
const STAMP = '.verified';
|
|
49
|
+
/**
|
|
50
|
+
* Whether the cache entry is a whole, checked release: stamped with the
|
|
51
|
+
* pinned digest, its executable still executable, and on macOS the helper
|
|
52
|
+
* beside it. An entry that is not (cut short, its execute bit lost, the
|
|
53
|
+
* helper deleted) is downloaded again.
|
|
54
|
+
*/
|
|
55
|
+
async function usable(directory, digest) {
|
|
56
|
+
try {
|
|
57
|
+
if ((await readFile(path.join(directory, STAMP), 'utf8')).trim() !== digest)
|
|
58
|
+
return false;
|
|
59
|
+
await access(path.join(directory, executableName()), constants.X_OK);
|
|
60
|
+
if (process.platform === 'darwin')
|
|
61
|
+
await access(path.join(directory, 'agent-desktop-macos-helper'), constants.X_OK);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The per-user cache the pinned release unpacks into, under the OS's cache
|
|
70
|
+
* directory: `~/Library/Caches/e2e` on macOS, `%LOCALAPPDATA%\\e2e\\cache` on
|
|
71
|
+
* Windows, `$XDG_CACHE_HOME/e2e` (or `~/.cache/e2e`) on Linux. Read from the
|
|
72
|
+
* run's environment, never `process.env`, so `prepare` and the workers agree.
|
|
73
|
+
*/
|
|
74
|
+
function cacheDirectory(env, target) {
|
|
75
|
+
const home = (process.platform === 'win32' ? env.USERPROFILE : env.HOME) ?? homedir();
|
|
76
|
+
const base = process.platform === 'darwin'
|
|
77
|
+
? path.join(home, 'Library', 'Caches', 'e2e')
|
|
78
|
+
: process.platform === 'win32'
|
|
79
|
+
? path.join(env.LOCALAPPDATA ?? path.join(home, 'AppData', 'Local'), 'e2e', 'cache')
|
|
80
|
+
: path.join(env.XDG_CACHE_HOME ?? path.join(home, '.cache'), 'e2e');
|
|
81
|
+
return path.join(base, 'agent-desktop', `${AGENT_DESKTOP_VERSION}-${target}`);
|
|
82
|
+
}
|
|
83
|
+
/** Whether the pinned release is in the cache whole and checked, as `prepare` leaves it and a worker needs it. */
|
|
84
|
+
export async function pinnedInstalled(env) {
|
|
85
|
+
const target = releaseTarget();
|
|
86
|
+
const digest = target === undefined ? undefined : ARCHIVE_DIGESTS[target];
|
|
87
|
+
return target !== undefined && digest !== undefined && (await usable(cacheDirectory(env, target), digest));
|
|
88
|
+
}
|
|
89
|
+
/** Where the executable is, or would be once `prepare` downloads it; undefined when nothing can be run here. */
|
|
90
|
+
export function pinnedExecutable(env) {
|
|
91
|
+
const target = releaseTarget();
|
|
92
|
+
return target === undefined ? undefined : path.join(cacheDirectory(env, target), executableName());
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The executable a worker runs: the `binary` option resolved against the
|
|
96
|
+
* project, else the pinned release. Throws when neither exists, which means
|
|
97
|
+
* `prepare` did not run (a programmatic host that skips it) or failed.
|
|
98
|
+
*/
|
|
99
|
+
export async function resolveExecutable(binary, projectRoot, env) {
|
|
100
|
+
if (binary !== undefined) {
|
|
101
|
+
const resolved = path.resolve(projectRoot, binary);
|
|
102
|
+
try {
|
|
103
|
+
await access(resolved, constants.X_OK);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new ConfigurationError('INVALID_CONFIG', `desktop({ binary }) names ${resolved}, which is not an executable file`);
|
|
107
|
+
}
|
|
108
|
+
return resolved;
|
|
109
|
+
}
|
|
110
|
+
const target = releaseTarget();
|
|
111
|
+
const digest = target === undefined ? undefined : ARCHIVE_DIGESTS[target];
|
|
112
|
+
if (target === undefined || digest === undefined) {
|
|
113
|
+
throw new ConfigurationError('INVALID_CONFIG', `agent-desktop has no release for ${process.platform} on ${process.arch}; pass desktop({ binary }) to use a build of your own`);
|
|
114
|
+
}
|
|
115
|
+
const directory = cacheDirectory(env, target);
|
|
116
|
+
if (!(await usable(directory, digest))) {
|
|
117
|
+
throw new InfrastructureError('AGENT_DESKTOP_INSTALL_FAILED', `agent-desktop ${AGENT_DESKTOP_VERSION} is not installed whole at ${directory}; the engine's prepare step downloads it before the first test`);
|
|
118
|
+
}
|
|
119
|
+
return path.join(directory, executableName());
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Downloads and unpacks the pinned release unless a whole, checked copy is
|
|
123
|
+
* already in the cache; a damaged one is replaced. Any failure but a
|
|
124
|
+
* cancellation is `AGENT_DESKTOP_INSTALL_FAILED`. `digests` is the pinned
|
|
125
|
+
* table, which only a test replaces, to unpack an archive of its own.
|
|
126
|
+
*/
|
|
127
|
+
export async function installPinned(env, signal, log, digests = ARCHIVE_DIGESTS) {
|
|
128
|
+
const target = releaseTarget();
|
|
129
|
+
const digest = target === undefined ? undefined : digests[target];
|
|
130
|
+
if (target === undefined || digest === undefined) {
|
|
131
|
+
throw new ConfigurationError('INVALID_CONFIG', `agent-desktop has no release for ${process.platform} on ${process.arch}; pass desktop({ binary }) to use a build of your own`);
|
|
132
|
+
}
|
|
133
|
+
const directory = cacheDirectory(env, target);
|
|
134
|
+
const executable = path.join(directory, executableName());
|
|
135
|
+
if (await usable(directory, digest))
|
|
136
|
+
return executable;
|
|
137
|
+
const archive = `agent-desktop-v${AGENT_DESKTOP_VERSION}-${target}.tar.gz`;
|
|
138
|
+
const url = `https://github.com/vercel-labs/agent-desktop/releases/download/v${AGENT_DESKTOP_VERSION}/${archive}`;
|
|
139
|
+
log(`downloading agent-desktop ${AGENT_DESKTOP_VERSION} (${target})`);
|
|
140
|
+
try {
|
|
141
|
+
await download(url, archive, digest, directory, signal);
|
|
142
|
+
}
|
|
143
|
+
catch (cause) {
|
|
144
|
+
if (cause instanceof InfrastructureError || signal.aborted)
|
|
145
|
+
throw cause;
|
|
146
|
+
throw new InfrastructureError('AGENT_DESKTOP_INSTALL_FAILED', `installing agent-desktop from ${url} failed: ${cause.message}`, { cause });
|
|
147
|
+
}
|
|
148
|
+
return executable;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Fetches the archive, checks its digest before anything is unpacked, and
|
|
152
|
+
* unpacks it by the OS's `tar` into a fresh directory that becomes the cache
|
|
153
|
+
* entry in one rename, so a download cut short never leaves a half-written
|
|
154
|
+
* executable behind.
|
|
155
|
+
*/
|
|
156
|
+
async function download(url, archive, digest, directory, signal) {
|
|
157
|
+
const response = await fetch(url, { signal });
|
|
158
|
+
if (!response.ok)
|
|
159
|
+
throw new InfrastructureError('AGENT_DESKTOP_INSTALL_FAILED', `downloading ${url} failed: HTTP ${response.status}`);
|
|
160
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
161
|
+
const actual = createHash('sha256').update(bytes).digest('hex');
|
|
162
|
+
if (actual !== digest) {
|
|
163
|
+
throw new InfrastructureError('AGENT_DESKTOP_INSTALL_FAILED', `${archive} has SHA-256 ${actual}, expected ${digest}; refusing to unpack it`);
|
|
164
|
+
}
|
|
165
|
+
await mkdir(path.dirname(directory), { recursive: true });
|
|
166
|
+
const staging = await mkdtemp(`${directory}.partial-`);
|
|
167
|
+
try {
|
|
168
|
+
const file = path.join(staging, archive);
|
|
169
|
+
await writeFile(file, bytes);
|
|
170
|
+
await execFileAsync('tar', ['-xzf', file, '-C', staging], { signal });
|
|
171
|
+
await rm(file);
|
|
172
|
+
if (process.platform !== 'win32')
|
|
173
|
+
await chmod(path.join(staging, executableName()), 0o755);
|
|
174
|
+
// Written last, so only a whole, checked unpack is ever stamped.
|
|
175
|
+
await writeFile(path.join(staging, STAMP), digest);
|
|
176
|
+
await publish(staging, directory, digest);
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
await rm(staging, { recursive: true, force: true });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** How many times a publish looks again after another run changed the cache entry under it. */
|
|
183
|
+
const PUBLISH_TRIES = 10;
|
|
184
|
+
/**
|
|
185
|
+
* Puts a checked unpack in place as the cache entry, with no lock: every
|
|
186
|
+
* run that installs at the same time publishes a copy of the same checked
|
|
187
|
+
* release, so whichever copy is in place, checked, is the winner and the
|
|
188
|
+
* others are dropped. A rename onto an existing entry fails, so an entry is
|
|
189
|
+
* replaced only once it was seen damaged and moved aside; one that turns out
|
|
190
|
+
* whole once moved (another run put it there meanwhile) goes back.
|
|
191
|
+
*/
|
|
192
|
+
async function publish(staging, directory, digest) {
|
|
193
|
+
for (let tries = 0; tries < PUBLISH_TRIES; tries += 1) {
|
|
194
|
+
if (await rename(staging, directory).then(() => true, () => false))
|
|
195
|
+
return;
|
|
196
|
+
if (await usable(directory, digest))
|
|
197
|
+
return;
|
|
198
|
+
// A damaged entry is moved aside, not deleted first, so the executable is missing only between two renames. Of two runs that move it, one fails and looks again.
|
|
199
|
+
const aside = `${directory}.stale-${process.pid}-${randomUUID()}`;
|
|
200
|
+
if (!(await rename(directory, aside).then(() => true, () => false)))
|
|
201
|
+
continue;
|
|
202
|
+
if (await usable(aside, digest))
|
|
203
|
+
await rename(aside, directory).catch(() => undefined);
|
|
204
|
+
await rm(aside, { recursive: true, force: true });
|
|
205
|
+
}
|
|
206
|
+
if (await usable(directory, digest))
|
|
207
|
+
return;
|
|
208
|
+
throw new InfrastructureError('AGENT_DESKTOP_INSTALL_FAILED', `could not put agent-desktop in place at ${directory}: other runs kept changing it`);
|
|
209
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
/** How agent-desktop says whether a command reached the app. */
|
|
27
|
+
interface Disposition {
|
|
28
|
+
readonly delivery?: string;
|
|
29
|
+
readonly retry?: string;
|
|
30
|
+
}
|
|
31
|
+
/** The `error` of a failed envelope. */
|
|
32
|
+
interface Failure {
|
|
33
|
+
readonly code: string;
|
|
34
|
+
readonly message: string;
|
|
35
|
+
readonly disposition?: Disposition;
|
|
36
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
37
|
+
}
|
|
38
|
+
/** One command to run. */
|
|
39
|
+
export interface CliCall {
|
|
40
|
+
/** Arguments after the executable; never a value a test typed. */
|
|
41
|
+
readonly args: readonly string[];
|
|
42
|
+
/** Text written to the command's stdin, for `--stdin`. */
|
|
43
|
+
readonly stdin?: string;
|
|
44
|
+
/** Whether the command sends input to an app; decides how a cut-off or failed command is reported. */
|
|
45
|
+
readonly input: boolean;
|
|
46
|
+
/** Ends the command when it aborts. */
|
|
47
|
+
readonly signal: AbortSignal;
|
|
48
|
+
/** The command is killed once this budget is spent. */
|
|
49
|
+
readonly timeoutMs: number;
|
|
50
|
+
/** Names the command in an error message. */
|
|
51
|
+
readonly label: string;
|
|
52
|
+
}
|
|
53
|
+
/** A failure agent-desktop reported, before translation, for a caller that tries another way when nothing was sent. */
|
|
54
|
+
export declare class AgentDesktopFailure extends Error {
|
|
55
|
+
readonly code: string;
|
|
56
|
+
/** Whether agent-desktop says nothing reached the app, so another way may be tried. */
|
|
57
|
+
readonly notDelivered: boolean;
|
|
58
|
+
readonly details: Readonly<Record<string, unknown>>;
|
|
59
|
+
constructor(failure: Failure);
|
|
60
|
+
}
|
|
61
|
+
/** Runs agent-desktop commands for one worker: its executable, its private state directory. */
|
|
62
|
+
export declare class AgentDesktopCli {
|
|
63
|
+
private readonly executable;
|
|
64
|
+
private readonly env;
|
|
65
|
+
constructor(executable: string, env: Readonly<Record<string, string | undefined>>);
|
|
66
|
+
/**
|
|
67
|
+
* Runs one command and returns its `data`. A failure the envelope reports
|
|
68
|
+
* is thrown as `AgentDesktopFailure`, untranslated, so a caller can try
|
|
69
|
+
* another way when nothing was sent; `translate` turns it into the engine
|
|
70
|
+
* contract.
|
|
71
|
+
*/
|
|
72
|
+
run<T>(call: CliCall): Promise<T>;
|
|
73
|
+
/** One process, killed when the call's signal aborts or its budget runs out. */
|
|
74
|
+
private spawn;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The engine error for a failure of `label`. An `EngineError` passes through.
|
|
78
|
+
* `input` says whether the command sent input to the app: its failure is
|
|
79
|
+
* `ACTION_MAY_HAVE_COMMITTED` unless agent-desktop says nothing was sent.
|
|
80
|
+
*/
|
|
81
|
+
export declare function translate(cause: unknown, label: string, input: boolean): Error;
|
|
82
|
+
export {};
|