@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.33
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 +8 -0
- package/README.md +2411 -2
- package/box/Dockerfile +69 -0
- package/box/agentrun-archil +168 -0
- package/box/build-daytona.py +26 -0
- package/box/build-e2b.mjs +32 -0
- package/box/build-modal.py +17 -0
- package/dist/actions.d.ts +18 -0
- package/dist/actions.js +139 -0
- package/dist/browser.d.ts +151 -0
- package/dist/browser.js +305 -0
- package/dist/browserbase.d.ts +139 -0
- package/dist/browserbase.js +408 -0
- package/dist/child.d.ts +40 -0
- package/dist/child.js +127 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.js +136 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/archil.d.ts +68 -0
- package/dist/conformance/archil.js +152 -0
- package/dist/conformance/browserbase.d.ts +35 -0
- package/dist/conformance/browserbase.js +45 -0
- package/dist/conformance/cases/apps.d.ts +2 -0
- package/dist/conformance/cases/apps.js +155 -0
- package/dist/conformance/cases/browser.d.ts +4 -0
- package/dist/conformance/cases/browser.js +105 -0
- package/dist/conformance/cases/drift.d.ts +2 -0
- package/dist/conformance/cases/drift.js +64 -0
- package/dist/conformance/cases/exec.d.ts +2 -0
- package/dist/conformance/cases/exec.js +125 -0
- package/dist/conformance/cases/files.d.ts +2 -0
- package/dist/conformance/cases/files.js +294 -0
- package/dist/conformance/cases/health.d.ts +2 -0
- package/dist/conformance/cases/health.js +71 -0
- package/dist/conformance/cases/index.d.ts +9 -0
- package/dist/conformance/cases/index.js +37 -0
- package/dist/conformance/cases/input.d.ts +12 -0
- package/dist/conformance/cases/input.js +109 -0
- package/dist/conformance/cases/isolation.d.ts +21 -0
- package/dist/conformance/cases/isolation.js +98 -0
- package/dist/conformance/cases/lifetime.d.ts +2 -0
- package/dist/conformance/cases/lifetime.js +64 -0
- package/dist/conformance/cases/mount.d.ts +2 -0
- package/dist/conformance/cases/mount.js +252 -0
- package/dist/conformance/cases/process.d.ts +2 -0
- package/dist/conformance/cases/process.js +240 -0
- package/dist/conformance/cases/provider.d.ts +2 -0
- package/dist/conformance/cases/provider.js +302 -0
- package/dist/conformance/cases/screen.d.ts +9 -0
- package/dist/conformance/cases/screen.js +230 -0
- package/dist/conformance/cases/settings.d.ts +57 -0
- package/dist/conformance/cases/settings.js +142 -0
- package/dist/conformance/cases/touch.d.ts +2 -0
- package/dist/conformance/cases/touch.js +117 -0
- package/dist/conformance/cases/util.d.ts +7 -0
- package/dist/conformance/cases/util.js +8 -0
- package/dist/conformance/cdp.d.ts +13 -0
- package/dist/conformance/cdp.js +88 -0
- package/dist/conformance/cli.d.ts +29 -0
- package/dist/conformance/cli.js +231 -0
- package/dist/conformance/daytona-sweep.d.ts +18 -0
- package/dist/conformance/daytona-sweep.js +126 -0
- package/dist/conformance/daytona.d.ts +83 -0
- package/dist/conformance/daytona.js +107 -0
- package/dist/conformance/docker.d.ts +38 -0
- package/dist/conformance/docker.js +70 -0
- package/dist/conformance/drift-daemon.d.ts +8 -0
- package/dist/conformance/drift-daemon.js +41 -0
- package/dist/conformance/e2b-diagnose.d.ts +16 -0
- package/dist/conformance/e2b-diagnose.js +61 -0
- package/dist/conformance/e2b-sweep.d.ts +18 -0
- package/dist/conformance/e2b-sweep.js +132 -0
- package/dist/conformance/e2b.d.ts +74 -0
- package/dist/conformance/e2b.js +111 -0
- package/dist/conformance/fixture.d.ts +65 -0
- package/dist/conformance/fixture.js +98 -0
- package/dist/conformance/index.d.ts +8 -0
- package/dist/conformance/index.js +8 -0
- package/dist/conformance/kernel.d.ts +31 -0
- package/dist/conformance/kernel.js +40 -0
- package/dist/conformance/kind.d.ts +23 -0
- package/dist/conformance/kind.js +58 -0
- package/dist/conformance/modal-sweep.d.ts +22 -0
- package/dist/conformance/modal-sweep.js +213 -0
- package/dist/conformance/modal.d.ts +69 -0
- package/dist/conformance/modal.js +76 -0
- package/dist/conformance/orgo.d.ts +41 -0
- package/dist/conformance/orgo.js +69 -0
- package/dist/conformance/phone-harness.d.ts +61 -0
- package/dist/conformance/phone-harness.js +241 -0
- package/dist/conformance/png.d.ts +16 -0
- package/dist/conformance/png.js +132 -0
- package/dist/conformance/report.d.ts +2 -0
- package/dist/conformance/report.js +86 -0
- package/dist/conformance/runner.d.ts +11 -0
- package/dist/conformance/runner.js +585 -0
- package/dist/conformance/tar.d.ts +13 -0
- package/dist/conformance/tar.js +105 -0
- package/dist/conformance/types.d.ts +257 -0
- package/dist/conformance/types.js +24 -0
- package/dist/daemon-copy.d.ts +40 -0
- package/dist/daemon-copy.js +259 -0
- package/dist/daytona.d.ts +180 -0
- package/dist/daytona.js +1498 -0
- package/dist/desktop.d.ts +24 -0
- package/dist/desktop.js +68 -0
- package/dist/docker/egress-main.d.ts +1 -0
- package/dist/docker/egress-main.js +68 -0
- package/dist/docker/egress-proxy.d.ts +53 -0
- package/dist/docker/egress-proxy.js +450 -0
- package/dist/docker/egress-table.d.ts +39 -0
- package/dist/docker/egress-table.js +197 -0
- package/dist/docker/egress.d.ts +109 -0
- package/dist/docker/egress.js +318 -0
- package/dist/docker/image.d.ts +49 -0
- package/dist/docker/image.js +302 -0
- package/dist/docker/stage.d.ts +21 -0
- package/dist/docker/stage.js +290 -0
- package/dist/docker/volume.d.ts +24 -0
- package/dist/docker/volume.js +67 -0
- package/dist/docker.d.ts +156 -0
- package/dist/docker.js +1277 -0
- package/dist/drift.d.ts +200 -0
- package/dist/drift.js +416 -0
- package/dist/e2b.d.ts +337 -0
- package/dist/e2b.js +1516 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.js +24 -0
- package/dist/files.d.ts +50 -0
- package/dist/files.js +208 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/isolation.d.ts +29 -0
- package/dist/isolation.js +71 -0
- package/dist/janitor.d.ts +50 -0
- package/dist/janitor.js +135 -0
- package/dist/kernel.d.ts +113 -0
- package/dist/kernel.js +358 -0
- package/dist/kinds.d.ts +79 -0
- package/dist/kinds.js +133 -0
- package/dist/labels.d.ts +23 -0
- package/dist/labels.js +50 -0
- package/dist/modal.d.ts +302 -0
- package/dist/modal.js +1374 -0
- package/dist/mount-archil.d.ts +164 -0
- package/dist/mount-archil.js +471 -0
- package/dist/mount.d.ts +57 -0
- package/dist/mount.js +104 -0
- package/dist/orgo-channel.d.ts +96 -0
- package/dist/orgo-channel.js +391 -0
- package/dist/orgo.d.ts +139 -0
- package/dist/orgo.js +1006 -0
- package/dist/phone-harness.d.ts +185 -0
- package/dist/phone-harness.js +1420 -0
- package/dist/processes.d.ts +24 -0
- package/dist/processes.js +40 -0
- package/dist/protocol.d.ts +729 -0
- package/dist/protocol.js +54 -0
- package/dist/provider.d.ts +245 -0
- package/dist/provider.js +37 -0
- package/dist/providers.d.ts +68 -0
- package/dist/providers.js +25 -0
- package/dist/result.d.ts +15 -0
- package/dist/result.js +2 -0
- package/dist/screen-watch.d.ts +150 -0
- package/dist/screen-watch.js +490 -0
- package/dist/test-connection.d.ts +17 -0
- package/dist/test-connection.js +26 -0
- package/dist/wait.d.ts +23 -0
- package/dist/wait.js +65 -0
- package/package.json +62 -4
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** The stock Settings app of each phone kind this suite knows. */
|
|
2
|
+
export const PHONE_SETTINGS = { android: "com.android.settings" };
|
|
3
|
+
/** Whether the case checks what it did through Settings: a phone with apps and a UI tree that takes no fixture file. */
|
|
4
|
+
export function throughSettings(t) {
|
|
5
|
+
const { kind, groups } = t.provider.capabilities();
|
|
6
|
+
return PHONE_SETTINGS[kind] !== undefined && !groups.includes("files") && groups.includes("apps") && groups.includes("apps.ui_tree");
|
|
7
|
+
}
|
|
8
|
+
/** The kind's Settings app, or the case skips in words. */
|
|
9
|
+
export function settingsApp(t) {
|
|
10
|
+
const { kind } = t.provider.capabilities();
|
|
11
|
+
return PHONE_SETTINGS[kind] ?? t.skip(`no stock app is known for a ${kind} computer`);
|
|
12
|
+
}
|
|
13
|
+
const foreground = async (t) => (await t.call("apps.list", {})).foreground;
|
|
14
|
+
/** Settings, fresh and in front: ended, launched, and waited for until it is the app in front. */
|
|
15
|
+
export async function openSettings(t) {
|
|
16
|
+
const app = settingsApp(t);
|
|
17
|
+
t.deepEqual(await t.call("apps.terminate", { id: app }), {}, `apps.terminate ${app}`);
|
|
18
|
+
t.deepEqual(await t.call("apps.launch", { id: app }), {}, `apps.launch ${app}`);
|
|
19
|
+
// What is in front instead, the last time it was read, goes in the words: a live run showed only the wait.
|
|
20
|
+
let seen = null;
|
|
21
|
+
try {
|
|
22
|
+
await t.until(async () => (seen = await foreground(t)) === app, `${app} in front after apps.launch`);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new Error(`${error instanceof Error ? error.message : String(error)} (in front: ${seen ?? "nothing"})`);
|
|
26
|
+
}
|
|
27
|
+
return app;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* What a tap on a row met, in words for a failure: the screen in px and in dp (px over the shot's scale; Settings shows
|
|
31
|
+
* two panes from 600 dp wide), what is in front, the tap point and the row's bounds, whether the row's title shows
|
|
32
|
+
* outside the list (a page opened beside it), and whether the next row is still shown. A part that cannot be read
|
|
33
|
+
* says so; none of it throws.
|
|
34
|
+
*/
|
|
35
|
+
export async function tapScene(t, { at, row, next, tree }) {
|
|
36
|
+
const unread = (error) => `unread (${error instanceof Error ? error.message : String(error)})`;
|
|
37
|
+
let screen;
|
|
38
|
+
try {
|
|
39
|
+
const { width, height, scale } = await t.call("screen.shot", {});
|
|
40
|
+
screen = `screen ${width}x${height} px${scale > 0 ? `, ${Math.round(width / scale)}x${Math.round(height / scale)} dp` : ""}`;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
screen = `screen ${unread(error)}`;
|
|
44
|
+
}
|
|
45
|
+
let front;
|
|
46
|
+
try {
|
|
47
|
+
front = (await foreground(t)) ?? "nothing";
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
front = unread(error);
|
|
51
|
+
}
|
|
52
|
+
const tap = `the tap at ${at} on the row's bounds ${JSON.stringify(row.bounds)}`;
|
|
53
|
+
if (tree === undefined)
|
|
54
|
+
return `${screen}; in front: ${front}; ${tap}; no tree was read`;
|
|
55
|
+
const list = listOf(tree);
|
|
56
|
+
const inList = new Set(list === undefined ? [] : nodesOf(list));
|
|
57
|
+
const outside = nodesOf(tree.root).find((node) => names(node, row.text) && !inList.has(node));
|
|
58
|
+
const title = `its title outside the list: ${outside === undefined ? "no" : `yes, at ${JSON.stringify(outside.bounds)}`}`;
|
|
59
|
+
const shown = `the row ${JSON.stringify(next.text)}: ${textsOf(tree).includes(next.text) ? "still shown" : "gone"}`;
|
|
60
|
+
return `${screen}; in front: ${front}; ${tap}; ${title}; ${shown}`;
|
|
61
|
+
}
|
|
62
|
+
/** Every node of a tree, depth first. */
|
|
63
|
+
export function nodesOf(root) {
|
|
64
|
+
const out = [];
|
|
65
|
+
const walk = (node) => {
|
|
66
|
+
out.push(node);
|
|
67
|
+
for (const child of node.children ?? [])
|
|
68
|
+
walk(child);
|
|
69
|
+
};
|
|
70
|
+
walk(root);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/** Whether a node shows a name: as its text, or as its label (content-desc). */
|
|
74
|
+
const names = (node, name) => node.text === name || node.label === name;
|
|
75
|
+
/**
|
|
76
|
+
* Whether a tree shows a name anywhere, as a text or a label. A live Android 15 Settings page shows its title only as
|
|
77
|
+
* its collapsing toolbar's content-desc (phone probe 3), with no text node holding it.
|
|
78
|
+
*/
|
|
79
|
+
export const showsName = (tree, name) => nodesOf(tree.root).some((node) => names(node, name));
|
|
80
|
+
/** The texts a tree shows. */
|
|
81
|
+
export const textsOf = (tree) => nodesOf(tree.root).flatMap((node) => (node.text ? [node.text] : []));
|
|
82
|
+
/** The middle of a rect, in whole pixels. */
|
|
83
|
+
export const middle = ([x, y, w, h]) => [Math.floor(x + w / 2), Math.floor(y + h / 2)];
|
|
84
|
+
/** The scrollable list a tree shows, the first one. */
|
|
85
|
+
export function listOf(tree) {
|
|
86
|
+
return nodesOf(tree.root).find((node) => node.scrollable === true);
|
|
87
|
+
}
|
|
88
|
+
/** Whether a node, or one under it, says search: its text, its label or its id. */
|
|
89
|
+
const saysSearch = (node) => nodesOf(node).some((one) => /search/i.test(`${one.text ?? ""} ${one.label ?? ""} ${one.id ?? ""}`));
|
|
90
|
+
/**
|
|
91
|
+
* The rows of a tree's list: each clickable node in it, whole inside it, with the first text it holds. Settings' search
|
|
92
|
+
* entry is not a row, though a live Settings shows it as the list's first item.
|
|
93
|
+
*/
|
|
94
|
+
export function rowsOf(tree) {
|
|
95
|
+
const list = listOf(tree);
|
|
96
|
+
if (list === undefined)
|
|
97
|
+
return [];
|
|
98
|
+
const [lx, ly, lw, lh] = list.bounds;
|
|
99
|
+
const rows = [];
|
|
100
|
+
for (const node of nodesOf(list).slice(1)) {
|
|
101
|
+
if (node.clickable !== true || saysSearch(node))
|
|
102
|
+
continue;
|
|
103
|
+
const [x, y, w, h] = node.bounds;
|
|
104
|
+
if (x < lx || y < ly || x + w > lx + lw || y + h > ly + lh || w === 0 || h === 0)
|
|
105
|
+
continue;
|
|
106
|
+
const text = nodesOf(node).find((one) => one.text)?.text;
|
|
107
|
+
if (text !== undefined)
|
|
108
|
+
rows.push({ text, bounds: node.bounds });
|
|
109
|
+
}
|
|
110
|
+
return rows;
|
|
111
|
+
}
|
|
112
|
+
/** Settings' top list, with at least `count` rows of different titles on screen, or the case fails in words. */
|
|
113
|
+
export async function settingsRows(t, count) {
|
|
114
|
+
return t.until(async () => {
|
|
115
|
+
const tree = await t.call("apps.ui_tree", {});
|
|
116
|
+
const rows = rowsOf(tree);
|
|
117
|
+
return new Set(rows.map((row) => row.text)).size >= count ? { tree, rows } : undefined;
|
|
118
|
+
}, `Settings' list with ${count} rows in apps.ui_tree`);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A node text is typed into: any editable field, by its class, an EditText or a subclass the platform names apart
|
|
122
|
+
* (AutoCompleteTextView, MultiAutoCompleteTextView, ExtractEditText). A live Android 15's Settings search field is an
|
|
123
|
+
* AutoCompleteTextView (phone probe 2).
|
|
124
|
+
*/
|
|
125
|
+
const isField = (node) => /(EditText|AutoCompleteTextView)$/.test(node.role);
|
|
126
|
+
/**
|
|
127
|
+
* Settings' search field, opened from its list: the case taps the search entry (the first clickable node that says
|
|
128
|
+
* search, by its own text, label or id or a child's; a live Settings shows it inside the list, its text on a child) and
|
|
129
|
+
* waits for the field. An empty field may show its hint as its text, so only the field is waited for.
|
|
130
|
+
*/
|
|
131
|
+
export async function openSearch(t) {
|
|
132
|
+
const { tree } = await settingsRows(t, 1);
|
|
133
|
+
const entry = t.present(nodesOf(tree.root).find((node) => node.clickable === true && saysSearch(node)), "Settings' search entry (a clickable node saying search) in apps.ui_tree");
|
|
134
|
+
const at = middle(entry.bounds);
|
|
135
|
+
t.deepEqual(await t.call("input.actions", { actions: [{ type: "tap", at }] }), { done: 1 }, `input.actions of a tap on Settings' search entry at ${at}`);
|
|
136
|
+
await t.until(async () => (await searchText(t)) !== undefined, "Settings' search field in apps.ui_tree");
|
|
137
|
+
}
|
|
138
|
+
/** The text in Settings' search field now, or undefined when no field is shown. */
|
|
139
|
+
export async function searchText(t) {
|
|
140
|
+
const field = nodesOf((await t.call("apps.ui_tree", {})).root).find(isField);
|
|
141
|
+
return field === undefined ? undefined : (field.text ?? "");
|
|
142
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { act, allRan, logged, pointIn } from "./input.js";
|
|
2
|
+
import { listOf, middle, openSettings, rowsOf, settingsRows, showsName, tapScene, textsOf, throughSettings } from "./settings.js";
|
|
3
|
+
/** How far a logged touch may be from where it was aimed: a phone's input path may round. */
|
|
4
|
+
const SLACK = 2;
|
|
5
|
+
const touches = (events) => events.filter((e) => e.event === "touch");
|
|
6
|
+
const near = (a, b) => Math.abs(a[0] - b[0]) <= SLACK && Math.abs(a[1] - b[1]) <= SLACK;
|
|
7
|
+
const distance = (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1]);
|
|
8
|
+
const lifted = (events, fingers) => new Set(touches(events).filter((e) => e.phase === "up").map((e) => e.pointer)).size >= fingers;
|
|
9
|
+
/** The fixture, once the case has a way to see what touch did: the fixture's log over files. */
|
|
10
|
+
async function observed(t) {
|
|
11
|
+
const declared = t.provider.capabilities().groups;
|
|
12
|
+
if (!declared.includes("files")) {
|
|
13
|
+
if (!declared.includes("apps.ui_tree"))
|
|
14
|
+
return t.skip("no way to observe the effect: declare files or apps.ui_tree");
|
|
15
|
+
return t.skip(`no fixture runs on a ${t.provider.capabilities().kind} computer with no files, and no stock app is known for it`);
|
|
16
|
+
}
|
|
17
|
+
return t.fixture();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A tap on Settings' first row opens its page: the row's title shows, as a text or a label (a live Android 15 page
|
|
21
|
+
* shows it only as its toolbar's content-desc), and the next row is gone. Back comes back to the list. A tap that lands
|
|
22
|
+
* nowhere leaves the next row, and one on another row shows another title, so neither passes.
|
|
23
|
+
*/
|
|
24
|
+
async function tapThroughSettings(t) {
|
|
25
|
+
await openSettings(t);
|
|
26
|
+
const { rows } = await settingsRows(t, 2);
|
|
27
|
+
const [row, next] = [rows[0], t.present(rows.find((one) => one.text !== rows[0].text), "a second row with another title")];
|
|
28
|
+
const at = middle(row.bounds);
|
|
29
|
+
allRan(t, await act(t, [{ type: "tap", at }]), 1, `a tap on Settings' row ${JSON.stringify(row.text)} at ${at}`);
|
|
30
|
+
let seen;
|
|
31
|
+
try {
|
|
32
|
+
await t.until(async () => {
|
|
33
|
+
seen = await t.call("apps.ui_tree", {});
|
|
34
|
+
return showsName(seen, row.text) && !showsName(seen, next.text);
|
|
35
|
+
}, `the page of ${JSON.stringify(row.text)} after a tap on its row: its title, as a text or a label, and not the row ${JSON.stringify(next.text)}`);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
// A live run showed only the wait: the words say what the case saw, so a page beside the list tells apart from a
|
|
39
|
+
// tap that missed.
|
|
40
|
+
throw new Error(`${error instanceof Error ? error.message : String(error)} (${await tapScene(t, { at, row, next, tree: seen })})`);
|
|
41
|
+
}
|
|
42
|
+
allRan(t, await act(t, [{ type: "button", name: "back" }]), 1, "the back button");
|
|
43
|
+
await t.until(async () => textsOf(await t.call("apps.ui_tree", {})).includes(next.text), `Settings' list again after back: the row ${JSON.stringify(next.text)}`);
|
|
44
|
+
}
|
|
45
|
+
/** A swipe up Settings' list moves it up: a row on screen before and after is higher by a quarter of the swipe at least, or the first row has left. */
|
|
46
|
+
async function swipeThroughSettings(t) {
|
|
47
|
+
await openSettings(t);
|
|
48
|
+
const { tree, rows } = await settingsRows(t, 2);
|
|
49
|
+
const [x, y, w, h] = t.present(listOf(tree), "Settings' list in apps.ui_tree").bounds;
|
|
50
|
+
const from = [Math.floor(x + w / 2), Math.floor(y + h * 0.8)];
|
|
51
|
+
const to = [from[0], Math.floor(y + h * 0.2)];
|
|
52
|
+
allRan(t, await act(t, [{ type: "swipe", path: [from, to], ms: 400 }]), 1, `a swipe up Settings' list from ${from} to ${to}`);
|
|
53
|
+
const enough = (from[1] - to[1]) / 4;
|
|
54
|
+
await t.until(async () => {
|
|
55
|
+
const after = rowsOf(await t.call("apps.ui_tree", {}));
|
|
56
|
+
const moved = rows.some((before) => {
|
|
57
|
+
const now = after.find((one) => one.text === before.text);
|
|
58
|
+
return now !== undefined && before.bounds[1] - now.bounds[1] >= enough;
|
|
59
|
+
});
|
|
60
|
+
return moved || (after.length > 0 && !after.some((one) => one.text === rows[0].text));
|
|
61
|
+
}, `Settings' list moved up by ${Math.round(enough)} px at least after a swipe up`);
|
|
62
|
+
}
|
|
63
|
+
/** One finger's touches: where it went down, and where it came up. */
|
|
64
|
+
function stroke(t, events, pointer, what) {
|
|
65
|
+
const mine = touches(events).filter((e) => e.pointer === pointer);
|
|
66
|
+
const down = t.present(mine.find((e) => e.phase === "down"), `${what}: the fixture logged no touch down of finger ${pointer}`);
|
|
67
|
+
const up = t.present(mine.findLast((e) => e.phase === "up"), `${what}: the fixture logged no touch up of finger ${pointer}`);
|
|
68
|
+
return { down: down.at, up: up.at };
|
|
69
|
+
}
|
|
70
|
+
const touch = (name, run, level = "core") => ({ id: `touch.${name}`, level, group: "touch", needs: ["input.touch"], run });
|
|
71
|
+
export const touchCases = [
|
|
72
|
+
touch("tap", async (t) => {
|
|
73
|
+
if (throughSettings(t))
|
|
74
|
+
return tapThroughSettings(t);
|
|
75
|
+
const fixture = await observed(t);
|
|
76
|
+
const at = pointIn(fixture, 0.5, 0.4);
|
|
77
|
+
const before = (await fixture.events()).length;
|
|
78
|
+
allRan(t, await act(t, [{ type: "tap", at }]), 1, `a tap at ${at}`);
|
|
79
|
+
const events = await logged(t, fixture, before, (events) => lifted(events, 1), `a tap in the fixture's log`);
|
|
80
|
+
t.deepEqual([...new Set(touches(events).map((e) => e.pointer))], [0], "the fingers a tap used");
|
|
81
|
+
const { down, up } = stroke(t, events, 0, "a tap");
|
|
82
|
+
t.assert(near(down, at) && near(up, at), `a tap at ${at} was logged down at ${down} and up at ${up}`);
|
|
83
|
+
}),
|
|
84
|
+
touch("swipe", async (t) => {
|
|
85
|
+
if (throughSettings(t))
|
|
86
|
+
return swipeThroughSettings(t);
|
|
87
|
+
const fixture = await observed(t);
|
|
88
|
+
const from = pointIn(fixture, 0.5, 0.7);
|
|
89
|
+
const to = pointIn(fixture, 0.5, 0.3);
|
|
90
|
+
const before = (await fixture.events()).length;
|
|
91
|
+
allRan(t, await act(t, [{ type: "swipe", path: [from, to], ms: 300 }]), 1, `a swipe from ${from} to ${to}`);
|
|
92
|
+
const events = await logged(t, fixture, before, (events) => lifted(events, 1), "a swipe in the fixture's log");
|
|
93
|
+
const { down, up } = stroke(t, events, 0, "a swipe");
|
|
94
|
+
t.assert(near(down, from), `a swipe from ${from} was logged starting at ${down}`);
|
|
95
|
+
t.assert(near(up, to), `a swipe to ${to} was logged ending at ${up}`);
|
|
96
|
+
}),
|
|
97
|
+
touch("pinch", async (t) => {
|
|
98
|
+
if (throughSettings(t)) {
|
|
99
|
+
// Settings shows nothing a pinch changes; a provider that refuses pinch says so, and either way it is not seen.
|
|
100
|
+
const shot = await t.call("screen.shot", {});
|
|
101
|
+
const tried = await act(t, [{ type: "pinch", at: [Math.floor(shot.width / 2), Math.floor(shot.height / 2)], scale: 2, ms: 400 }]);
|
|
102
|
+
if (tried.failed?.kind === "unsupported")
|
|
103
|
+
return t.skip(`the provider refuses a pinch in words: ${tried.failed.message}`);
|
|
104
|
+
return t.skip("a pinch shows nothing in Settings' tree; only the fixture's log sees one");
|
|
105
|
+
}
|
|
106
|
+
const fixture = await observed(t);
|
|
107
|
+
const at = pointIn(fixture, 0.5, 0.5);
|
|
108
|
+
const before = (await fixture.events()).length;
|
|
109
|
+
allRan(t, await act(t, [{ type: "pinch", at, scale: 2, ms: 400 }]), 1, `a pinch apart at ${at}`);
|
|
110
|
+
const events = await logged(t, fixture, before, (events) => lifted(events, 2), "two fingers in the fixture's log");
|
|
111
|
+
const one = stroke(t, events, 0, "a pinch");
|
|
112
|
+
const two = stroke(t, events, 1, "a pinch");
|
|
113
|
+
const start = distance(one.down, two.down);
|
|
114
|
+
const end = distance(one.up, two.up);
|
|
115
|
+
t.assert(end > start, `a pinch apart: the fingers went from ${Math.round(start)} px apart to ${Math.round(end)} px`);
|
|
116
|
+
}, "full"),
|
|
117
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const decode: (base64: string) => string;
|
|
2
|
+
export declare const b64: (text: string | Uint8Array) => string;
|
|
3
|
+
export declare const delay: (ms: number) => Promise<unknown>;
|
|
4
|
+
/** A label a case adds to tell its own computers apart from the rest of the run's. */
|
|
5
|
+
export declare const CASE_LABEL = "agentrun.conformance.case";
|
|
6
|
+
/** A shell line that prints the stat line of each pid still alive, and nothing when none is. */
|
|
7
|
+
export declare const alive: (pids: number[]) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// What the cases share.
|
|
2
|
+
export const decode = (base64) => Buffer.from(base64, "base64").toString("utf8");
|
|
3
|
+
export const b64 = (text) => Buffer.from(text).toString("base64");
|
|
4
|
+
export const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
/** A label a case adds to tell its own computers apart from the rest of the run's. */
|
|
6
|
+
export const CASE_LABEL = "agentrun.conformance.case";
|
|
7
|
+
/** A shell line that prints the stat line of each pid still alive, and nothing when none is. */
|
|
8
|
+
export const alive = (pids) => `for p in ${pids.join(" ")}; do [ -e /proc/$p ] && cat /proc/$p/stat; done; true`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** An open CDP socket: send a command, to the browser or to an attached target's session, wait for an event, and close. */
|
|
2
|
+
export interface CdpSocket {
|
|
3
|
+
send<T = Record<string, unknown>>(method: string, params?: Record<string, unknown>, sessionId?: string): Promise<T>;
|
|
4
|
+
/** The next event of this method (from this session, when given), with its params; ask before the command that causes it. */
|
|
5
|
+
event<T = Record<string, unknown>>(method: string, sessionId?: string): Promise<T>;
|
|
6
|
+
close(): void;
|
|
7
|
+
}
|
|
8
|
+
/** Opens a CDP socket to url; rejects in words that never carry the URL. */
|
|
9
|
+
export type CdpDialer = (url: string, options: {
|
|
10
|
+
signal: AbortSignal;
|
|
11
|
+
}) => Promise<CdpSocket>;
|
|
12
|
+
/** The global WebSocket (Node 22), to a vendor's CDP URL. */
|
|
13
|
+
export declare const dialCdp: CdpDialer;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// A CDP socket for the browser cases: one WebSocket to a browser's CDP URL, a command at a time by id, flat sessions by
|
|
2
|
+
// sessionId. The URL is a secret: no error here carries it, or any part of it.
|
|
3
|
+
/** The global WebSocket (Node 22), to a vendor's CDP URL. */
|
|
4
|
+
export const dialCdp = (url, { signal }) => new Promise((resolve, reject) => {
|
|
5
|
+
if (signal.aborted)
|
|
6
|
+
return reject(new Error("the CDP socket was not opened: the case was aborted"));
|
|
7
|
+
let ws;
|
|
8
|
+
try {
|
|
9
|
+
ws = new WebSocket(url);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return reject(new Error("the CDP URL is not one a WebSocket opens"));
|
|
13
|
+
}
|
|
14
|
+
const pending = new Map();
|
|
15
|
+
const waiting = [];
|
|
16
|
+
let next = 0;
|
|
17
|
+
let opened = false;
|
|
18
|
+
const failAll = (why) => {
|
|
19
|
+
for (const [id, call] of pending) {
|
|
20
|
+
pending.delete(id);
|
|
21
|
+
call.reject(new Error(`CDP ${call.method}: ${why}`));
|
|
22
|
+
}
|
|
23
|
+
for (const waiter of waiting.splice(0))
|
|
24
|
+
waiter.reject(new Error(`CDP ${waiter.method}: ${why}`));
|
|
25
|
+
};
|
|
26
|
+
const stop = () => ws.close();
|
|
27
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
28
|
+
ws.addEventListener("open", () => {
|
|
29
|
+
opened = true;
|
|
30
|
+
resolve({
|
|
31
|
+
send(method, params = {}, sessionId) {
|
|
32
|
+
return new Promise((yes, no) => {
|
|
33
|
+
if (ws.readyState !== WebSocket.OPEN)
|
|
34
|
+
return no(new Error(`CDP ${method}: the socket is closed`));
|
|
35
|
+
const id = ++next;
|
|
36
|
+
pending.set(id, { method, resolve: yes, reject: no });
|
|
37
|
+
ws.send(JSON.stringify({ id, method, params, ...(sessionId === undefined ? {} : { sessionId }) }));
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
event(method, sessionId) {
|
|
41
|
+
return new Promise((yes, no) => {
|
|
42
|
+
if (ws.readyState !== WebSocket.OPEN)
|
|
43
|
+
return no(new Error(`CDP ${method}: the socket is closed`));
|
|
44
|
+
waiting.push({ method, sessionId, resolve: yes, reject: no });
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
close() {
|
|
48
|
+
signal.removeEventListener("abort", stop);
|
|
49
|
+
ws.close();
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
ws.addEventListener("message", (event) => {
|
|
54
|
+
let message;
|
|
55
|
+
try {
|
|
56
|
+
message = JSON.parse(String(event.data));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (typeof message.method === "string" && message.id === undefined) {
|
|
62
|
+
const at = waiting.findIndex((w) => w.method === message.method && (w.sessionId === undefined || w.sessionId === message.sessionId));
|
|
63
|
+
if (at >= 0)
|
|
64
|
+
waiting.splice(at, 1)[0]?.resolve((message.params ?? {}));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (typeof message.id !== "number")
|
|
68
|
+
return;
|
|
69
|
+
const call = pending.get(message.id);
|
|
70
|
+
if (call === undefined)
|
|
71
|
+
return;
|
|
72
|
+
pending.delete(message.id);
|
|
73
|
+
if (message.error !== undefined)
|
|
74
|
+
call.reject(new Error(`CDP ${call.method}: ${typeof message.error.message === "string" ? message.error.message : "an error"}`));
|
|
75
|
+
else
|
|
76
|
+
call.resolve(message.result);
|
|
77
|
+
});
|
|
78
|
+
ws.addEventListener("error", () => {
|
|
79
|
+
if (!opened)
|
|
80
|
+
reject(new Error("the CDP socket could not be opened"));
|
|
81
|
+
});
|
|
82
|
+
ws.addEventListener("close", () => {
|
|
83
|
+
signal.removeEventListener("abort", stop);
|
|
84
|
+
if (!opened)
|
|
85
|
+
reject(new Error("the CDP socket closed before it opened"));
|
|
86
|
+
failAll("the socket closed");
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ProviderEnv } from "../providers.js";
|
|
2
|
+
import type { CdpDialer } from "./cdp.js";
|
|
3
|
+
import type { Case } from "./types.js";
|
|
4
|
+
/** A stream as main writes to it: done is called once the text is handed on, as Writable.write's callback is. */
|
|
5
|
+
export interface Writer {
|
|
6
|
+
write(text: string, done?: (error?: Error | null) => void): unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface CliIo {
|
|
9
|
+
stdout?: Writer;
|
|
10
|
+
stderr?: Writer;
|
|
11
|
+
/** Where a module path is resolved from; default the directory npm was run in. */
|
|
12
|
+
cwd?: string;
|
|
13
|
+
/** The cases to run; default the browser case set for a provider of kind browser, else the whole suite. */
|
|
14
|
+
cases?: Case[];
|
|
15
|
+
/** How the browser cases open a CDP socket; default a WebSocket. A test gives a fake browser's. */
|
|
16
|
+
cdp?: CdpDialer;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
/** Print each case to stderr as it ends. */
|
|
19
|
+
progress?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Given to the module's createProvider(), createDriftedProvider() and conformanceImage(), which may ignore them; its env
|
|
22
|
+
* is where a conformance module reads its settings (default process.env). A provider file with no conformance module
|
|
23
|
+
* is given them, but the env, as create()'s options. A test gives a fake SDK or a shorter bound through it.
|
|
24
|
+
*/
|
|
25
|
+
providerOptions?: {
|
|
26
|
+
env?: ProviderEnv;
|
|
27
|
+
} & Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export declare function main(argv: string[], io?: CliIo): Promise<number>;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// `npm run conformance -w @parcha/agentrun-computer -- --provider <id> | ./module.js [--image <image>] [--only <groups> | --kind <kind>] [--json]`
|
|
2
|
+
// An id is resolved through the provider registry (../providers.ts) and nothing else, so a new computer needs no edit here.
|
|
3
|
+
// Exits 0 when Core passes, 1 when it fails, 2 on a usage error, and 3 when --only left Core cases out and every case
|
|
4
|
+
// that ran passed: a partial run is never a Core pass, so no script reads its exit code as one. With --kind it exits on
|
|
5
|
+
// the kind's verdict alone: 0 when the provider passes the kind, 1 when it does not.
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
import { isCommand } from "../entry.js";
|
|
9
|
+
import { isProviderId, providerIds, providerModule } from "../providers.js";
|
|
10
|
+
import { SETTING_KIND_NAMES } from "../kinds.js";
|
|
11
|
+
import { browserCases, casesFor, conformanceCases } from "./cases/index.js";
|
|
12
|
+
import { kindRunProblem } from "./kind.js";
|
|
13
|
+
import { formatReport } from "./report.js";
|
|
14
|
+
import { runConformance } from "./runner.js";
|
|
15
|
+
/** Writes text and settles once the stream has taken it, so an exit after it cuts nothing off. */
|
|
16
|
+
const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
|
|
17
|
+
const USAGE = `usage: npm run conformance -w @parcha/agentrun-computer -- --provider ${providerIds.join("|")}|<module.js> [--image <image>] [--only <group|case>,... | --kind <kind>] [--fixture <path>] [--json]
|
|
18
|
+
--provider a computer in the registry (${providerIds.join(", ")}), or a module path: a provider file that exports
|
|
19
|
+
create(options), or a conformance module that exports createProvider() (and, for the drift case,
|
|
20
|
+
createDriftedProvider(); for the mount cases, mountFor(kind), a fresh run folder for that mount kind)
|
|
21
|
+
--image the image every computer starts from (default the module's conformanceImage(), else debian:bookworm-slim)
|
|
22
|
+
--only run only these groups (health, exec, files, process, provider, drift, mount, screen, input, touch,
|
|
23
|
+
apps, lifetime; browser, run alone for a provider of kind browser) or case ids; a run that leaves Core cases out is partial: no Core verdict, and exit 3 when
|
|
24
|
+
every case that ran passed
|
|
25
|
+
--kind run a setting kind's cases (sandbox, desktop, phone, browser) and exit on its verdict: the provider passes the kind only
|
|
26
|
+
when it serves it and every case of each required group passes; not with --only
|
|
27
|
+
--fixture the fixture the screen, input, touch and apps cases check effects with: computerd-fixture for a
|
|
28
|
+
desktop, the fixture APK for an Android phone
|
|
29
|
+
--json print the report as JSON
|
|
30
|
+
exit: 0 Core passes, 1 it fails, 2 usage error, 3 partial (--only) and every case that ran passed; with --kind,
|
|
31
|
+
0 the provider passes the kind, 1 it does not`;
|
|
32
|
+
const PROVIDER_METHODS = ["capabilities", "check", "create", "attach", "list", "network", "connect", "release"];
|
|
33
|
+
class Usage extends Error {
|
|
34
|
+
}
|
|
35
|
+
function parse(argv, cases) {
|
|
36
|
+
const args = { json: false, help: false };
|
|
37
|
+
for (let i = 0; i < argv.length; i++) {
|
|
38
|
+
const [flag = "", inline] = (argv[i] ?? "").split(/=(.*)/s, 2);
|
|
39
|
+
const value = () => {
|
|
40
|
+
const given = inline ?? argv[++i];
|
|
41
|
+
if (given === undefined || given === "")
|
|
42
|
+
throw new Usage(`${flag} needs a value`);
|
|
43
|
+
return given;
|
|
44
|
+
};
|
|
45
|
+
if (flag === "--provider")
|
|
46
|
+
args.provider = value();
|
|
47
|
+
else if (flag === "--image")
|
|
48
|
+
args.image = value();
|
|
49
|
+
else if (flag === "--only")
|
|
50
|
+
args.only = value().split(",").map((part) => part.trim()).filter(Boolean);
|
|
51
|
+
else if (flag === "--kind") {
|
|
52
|
+
const kind = value();
|
|
53
|
+
if (!SETTING_KIND_NAMES.includes(kind))
|
|
54
|
+
throw new Usage(`--kind: ${JSON.stringify(kind)} is not a kind (${SETTING_KIND_NAMES.join(", ")})`);
|
|
55
|
+
const problem = kindRunProblem(kind);
|
|
56
|
+
if (problem !== undefined)
|
|
57
|
+
throw new Usage(`--kind ${kind}: ${problem}`);
|
|
58
|
+
args.kind = kind;
|
|
59
|
+
}
|
|
60
|
+
else if (flag === "--fixture")
|
|
61
|
+
args.fixture = value();
|
|
62
|
+
else if (flag === "--json")
|
|
63
|
+
args.json = true;
|
|
64
|
+
else if (flag === "--help" || flag === "-h")
|
|
65
|
+
args.help = true;
|
|
66
|
+
else
|
|
67
|
+
throw new Usage(`unknown option ${flag}`);
|
|
68
|
+
}
|
|
69
|
+
if (args.help)
|
|
70
|
+
return { provider: "", json: false, help: true };
|
|
71
|
+
if (args.provider === undefined)
|
|
72
|
+
throw new Usage("--provider is required");
|
|
73
|
+
if (args.kind !== undefined && args.only !== undefined)
|
|
74
|
+
throw new Usage("--kind and --only go apart: a kind runs its own cases");
|
|
75
|
+
const groups = [...new Set(cases.map((c) => c.group))];
|
|
76
|
+
for (const name of args.only ?? []) {
|
|
77
|
+
if (!groups.includes(name) && !cases.some((c) => c.id === name)) {
|
|
78
|
+
throw new Usage(`--only: ${name} is neither a group (${groups.join(", ")}) nor a case id`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
provider: args.provider,
|
|
83
|
+
...(args.image === undefined ? {} : { image: args.image }),
|
|
84
|
+
...(args.only ? { only: args.only } : {}),
|
|
85
|
+
...(args.kind ? { kind: args.kind } : {}),
|
|
86
|
+
...(args.fixture ? { fixture: args.fixture } : {}),
|
|
87
|
+
json: args.json,
|
|
88
|
+
help: false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const DEFAULT_IMAGE = "debian:bookworm-slim";
|
|
92
|
+
/** A bare name, which is an id; a module path has a slash or an extension. */
|
|
93
|
+
// Any bare name, whatever its case: "Docker" is an unknown provider, not a module path.
|
|
94
|
+
const BARE = /^[A-Za-z][A-Za-z0-9-]*$/;
|
|
95
|
+
/**
|
|
96
|
+
* The conformance module for --provider: a registry id's provider file, or the module at a path. A provider file's
|
|
97
|
+
* conformance() module is run when it has one, else its create() alone, given the CLI's options but the env (a provider
|
|
98
|
+
* reads no environment), with no drifted twin.
|
|
99
|
+
*/
|
|
100
|
+
async function conformanceModule(name, cwd) {
|
|
101
|
+
let label = name;
|
|
102
|
+
let module;
|
|
103
|
+
if (isProviderId(name)) {
|
|
104
|
+
module = { ...(await providerModule(name)) };
|
|
105
|
+
}
|
|
106
|
+
else if (BARE.test(name)) {
|
|
107
|
+
throw new Usage(`unknown computer provider ${JSON.stringify(name)}: the registry holds ${providerIds.join(", ")}; or give a module path, such as ./my-provider.js`);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
label = resolve(cwd, name);
|
|
111
|
+
try {
|
|
112
|
+
module = await import(pathToFileURL(label).href);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
throw new Usage(`cannot load the provider module ${label}: ${error.message.split("\n")[0]}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (typeof module.conformance === "function")
|
|
119
|
+
return { label, module: await module.conformance() };
|
|
120
|
+
if (typeof module.createProvider !== "function" && typeof module.create === "function") {
|
|
121
|
+
const create = module.create;
|
|
122
|
+
return {
|
|
123
|
+
label,
|
|
124
|
+
module: {
|
|
125
|
+
createProvider: (options = {}) => {
|
|
126
|
+
const { env: _env, ...rest } = options;
|
|
127
|
+
return create(rest);
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return { label, module: module };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The provider a conformance module makes, its drifted twin and its run folders (mountFor) when it offers them, and what
|
|
136
|
+
* it says of its run: conformanceImage(), the image when --image names none, and conformanceNotes, strings for the report.
|
|
137
|
+
*/
|
|
138
|
+
async function load(label, module, options) {
|
|
139
|
+
const { createProvider, createDriftedProvider, conformanceImage, mountFor } = module;
|
|
140
|
+
if (typeof createProvider !== "function")
|
|
141
|
+
throw new Usage(`${label} does not export createProvider() or create()`);
|
|
142
|
+
const provider = (await createProvider(options));
|
|
143
|
+
const lacks = PROVIDER_METHODS.filter((name) => typeof provider?.[name] !== "function");
|
|
144
|
+
if (lacks.length > 0 || typeof provider.id !== "string") {
|
|
145
|
+
throw new Usage(`${label}: createProvider() did not return a ComputerProvider: it lacks ${[...lacks, ...(typeof provider?.id === "string" ? [] : ["id"])].join(", ")}`);
|
|
146
|
+
}
|
|
147
|
+
const target = { provider };
|
|
148
|
+
if (typeof createDriftedProvider === "function")
|
|
149
|
+
target.drifted = async () => (await createDriftedProvider(options));
|
|
150
|
+
if (typeof mountFor === "function")
|
|
151
|
+
target.mountFor = (kind) => mountFor(kind, options);
|
|
152
|
+
if (conformanceImage !== undefined) {
|
|
153
|
+
const image = typeof conformanceImage === "function" ? await conformanceImage(options) : undefined;
|
|
154
|
+
if (typeof image !== "string" || image === "")
|
|
155
|
+
throw new Usage(`${label}: conformanceImage() did not return an image`);
|
|
156
|
+
target.image = image;
|
|
157
|
+
}
|
|
158
|
+
const notes = module.conformanceNotes;
|
|
159
|
+
if (notes !== undefined) {
|
|
160
|
+
if (!Array.isArray(notes) || !notes.every((note) => typeof note === "string"))
|
|
161
|
+
throw new Usage(`${label}: conformanceNotes is not an array of strings`);
|
|
162
|
+
target.notes = notes;
|
|
163
|
+
}
|
|
164
|
+
return target;
|
|
165
|
+
}
|
|
166
|
+
export async function main(argv, io = {}) {
|
|
167
|
+
const { stdout = process.stdout, stderr = process.stderr, signal, progress = false } = io;
|
|
168
|
+
let args;
|
|
169
|
+
try {
|
|
170
|
+
// --only is read against every case either set holds; the set itself is chosen once the provider says its kind.
|
|
171
|
+
args = parse(argv, io.cases ?? [...conformanceCases, ...browserCases.filter((c) => !conformanceCases.includes(c))]);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
await write(stderr, `${error.message}\n${USAGE}\n`);
|
|
175
|
+
return 2;
|
|
176
|
+
}
|
|
177
|
+
if (args.help) {
|
|
178
|
+
await write(stdout, `${USAGE}\n`);
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
const cwd = io.cwd ?? process.env.INIT_CWD ?? process.cwd();
|
|
182
|
+
// What the provider says that is no failure (onNote, as each remote provider takes it) goes in the report.
|
|
183
|
+
const providerNotes = [];
|
|
184
|
+
const options = { ...(io.providerOptions ?? {}), onNote: (note) => providerNotes.push({ computer: note.computer, note: note.note }) };
|
|
185
|
+
let target;
|
|
186
|
+
try {
|
|
187
|
+
const { label, module } = await conformanceModule(args.provider, cwd);
|
|
188
|
+
target = await load(label, module, options);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
await write(stderr, `${error.message}\n`);
|
|
192
|
+
if (error instanceof Usage) {
|
|
193
|
+
await write(stderr, `${USAGE}\n`);
|
|
194
|
+
return 2;
|
|
195
|
+
}
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
const cases = io.cases ?? casesFor(target.provider.capabilities().kind);
|
|
199
|
+
const onResult = progress ? (r) => stderr.write(`${r.status === "pass" ? "✓" : r.status === "fail" ? "✗" : "-"} ${r.id}\n`) : undefined;
|
|
200
|
+
const report = await runConformance(target.provider, {
|
|
201
|
+
image: args.image ?? target.image ?? DEFAULT_IMAGE,
|
|
202
|
+
...(target.notes && target.notes.length > 0 ? { notes: target.notes } : {}),
|
|
203
|
+
cases,
|
|
204
|
+
...(args.only ? { only: args.only } : {}),
|
|
205
|
+
...(args.kind ? { kind: args.kind } : {}),
|
|
206
|
+
...(args.fixture ? { fixture: resolve(cwd, args.fixture) } : {}),
|
|
207
|
+
...(signal ? { signal } : {}),
|
|
208
|
+
...(target.drifted ? { drifted: target.drifted } : {}),
|
|
209
|
+
...(target.mountFor ? { mountFor: target.mountFor } : {}),
|
|
210
|
+
...(onResult ? { onResult } : {}),
|
|
211
|
+
...(io.cdp ? { cdp: io.cdp } : {}),
|
|
212
|
+
});
|
|
213
|
+
if (providerNotes.length > 0)
|
|
214
|
+
report.providerNotes = providerNotes;
|
|
215
|
+
await write(stdout, args.json ? `${JSON.stringify(report, null, 2)}\n` : formatReport(report));
|
|
216
|
+
if (report.kindVerdict)
|
|
217
|
+
return report.kindVerdict.verdict === "pass" ? 0 : 1;
|
|
218
|
+
return report.core === "pass" ? 0 : report.core === "partial" ? 3 : 1;
|
|
219
|
+
}
|
|
220
|
+
if (isCommand(import.meta)) {
|
|
221
|
+
const controller = new AbortController();
|
|
222
|
+
const stop = () => controller.abort();
|
|
223
|
+
process.once("SIGINT", stop);
|
|
224
|
+
process.once("SIGTERM", stop);
|
|
225
|
+
process.exitCode = await main(process.argv.slice(2), { signal: controller.signal, progress: process.stderr.isTTY === true });
|
|
226
|
+
process.off("SIGINT", stop);
|
|
227
|
+
process.off("SIGTERM", stop);
|
|
228
|
+
// The report is written. Node exits once nothing is left; a provider call the runner stopped waiting for may still
|
|
229
|
+
// hold the event loop, so this ends the process after a grace period, without holding it open itself.
|
|
230
|
+
setTimeout(() => process.exit(), 5000).unref();
|
|
231
|
+
}
|