@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.32
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 +2401 -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 +92 -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 +118 -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 +125 -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 +190 -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 +178 -0
- package/dist/daytona.js +1484 -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 +150 -0
- package/dist/docker.js +1200 -0
- package/dist/drift.d.ts +200 -0
- package/dist/drift.js +416 -0
- package/dist/e2b.d.ts +335 -0
- package/dist/e2b.js +1515 -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,302 @@
|
|
|
1
|
+
// The provider: check refuses in words and makes nothing (past maxLifetimeMs too), create, attach, list and release do
|
|
2
|
+
// what they say, the network reads back as asked, a change to a network the provider does not declare is refused
|
|
3
|
+
// (Core) and one it does declare is refused or applied truthfully (Full), a computer does not run past its deadline,
|
|
4
|
+
// the janitor ends only the expired, stopped or running, and a takeover releases the run's lower epochs by label (Full).
|
|
5
|
+
import { randomBytes } from "node:crypto";
|
|
6
|
+
import { releaseOlder, sweep } from "../../janitor.js";
|
|
7
|
+
import { EPOCH_LABEL, RUN_LABEL, runLabels } from "../../labels.js";
|
|
8
|
+
import { CASE_LABEL } from "./util.js";
|
|
9
|
+
/** Labels for one case's computers: the run's, and the case's own. */
|
|
10
|
+
const own = (t, name) => ({ ...t.runLabels, [CASE_LABEL]: name });
|
|
11
|
+
const names = async (t, labels) => t
|
|
12
|
+
.ok(await t.provider.list(labels), `list ${JSON.stringify(labels)}`)
|
|
13
|
+
.map((info) => info.ref.name)
|
|
14
|
+
.sort();
|
|
15
|
+
/** A computer as the cases compare it: its id and name alone, so what else create or attach returns (notes) is not compared. */
|
|
16
|
+
const refOf = ({ id, name }) => ({ id, name });
|
|
17
|
+
const byName = (a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
18
|
+
const kindOf = (policy) => (typeof policy === "string" ? policy : "allow");
|
|
19
|
+
const POLICIES = ["none", "open", { allow: ["example.com"] }];
|
|
20
|
+
/**
|
|
21
|
+
* Asserts create refuses spec for what check() refuses in it: the refusal carries check()'s own words, so a create
|
|
22
|
+
* refused for another reason (no capacity, a network mismatch) does not pass. A computer create makes anyway, even
|
|
23
|
+
* after the case ended, is deleted by the runner.
|
|
24
|
+
*/
|
|
25
|
+
async function refusedCreate(t, spec, what) {
|
|
26
|
+
const checked = t.provider.check(spec);
|
|
27
|
+
t.assert(checked.length > 0, `${what}: check() refuses it`);
|
|
28
|
+
const error = t.refused(await t.attempt(spec), what, ["refused"]);
|
|
29
|
+
t.assert(checked.some(({ message }) => error.message.includes(message)), `${what}: create's refusal names what check() refused (${checked.map(({ field, message }) => `${field}: ${message}`).join("; ")}), not: ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
/** The deadline case's lifetime, and how much of it must be left once create returns: to connect and start a process. */
|
|
32
|
+
const DEADLINE_LIFETIME_MS = 45_000;
|
|
33
|
+
const DEADLINE_LEFT_MS = 15_000;
|
|
34
|
+
const seconds = (ms) => Math.round(ms / 100) / 10;
|
|
35
|
+
/**
|
|
36
|
+
* A computer for the deadline case, the lifetime it was made with, and when create returned, on the run's clock. A
|
|
37
|
+
* lifetime counts from create's start, so a host slow to start a computer eats into it. When create took so long that
|
|
38
|
+
* less than DEADLINE_LEFT_MS is left, or failed once the lifetime had passed, the case asks once more, for 45 s past
|
|
39
|
+
* twice what create took (at most maxLifetimeMs). When that is still too slow the case skips in words: it never saw the
|
|
40
|
+
* deadline, so Core does not pass. A create that fails with lifetime left fails the case in create's words.
|
|
41
|
+
*/
|
|
42
|
+
async function deadlineComputer(t, labels) {
|
|
43
|
+
let lifetimeMs = DEADLINE_LIFETIME_MS;
|
|
44
|
+
let first;
|
|
45
|
+
for (;;) {
|
|
46
|
+
const from = t.clock.now();
|
|
47
|
+
const made = await t.attempt(t.spec({ lifetimeMs, labels }));
|
|
48
|
+
const created = t.clock.now();
|
|
49
|
+
const took = created - from;
|
|
50
|
+
const left = from + lifetimeMs - created;
|
|
51
|
+
if (made.ok && left >= DEADLINE_LEFT_MS)
|
|
52
|
+
return { ref: made.value, lifetimeMs, created };
|
|
53
|
+
if (!made.ok && took < lifetimeMs)
|
|
54
|
+
t.ok(made, "create");
|
|
55
|
+
const words = `create took ${seconds(took)} s of a lifetime of ${seconds(lifetimeMs)} s`;
|
|
56
|
+
const outcome = made.ok ? `it left ${seconds(Math.max(0, left))} s, and the case needs ${seconds(DEADLINE_LEFT_MS)} s` : made.error.message;
|
|
57
|
+
if (first !== undefined)
|
|
58
|
+
t.skip(`${words} (the first took ${first}): this host starts a computer too slowly for the case to watch its deadline; ${outcome}`);
|
|
59
|
+
first = `${seconds(took)} s of ${seconds(lifetimeMs)} s`;
|
|
60
|
+
lifetimeMs = Math.min(t.provider.capabilities().maxLifetimeMs, DEADLINE_LIFETIME_MS + 2 * took);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const provider = (name, run, extra = {}) => ({
|
|
64
|
+
id: `provider.${name}`,
|
|
65
|
+
level: "core",
|
|
66
|
+
group: "provider",
|
|
67
|
+
needs: [],
|
|
68
|
+
computer: "none",
|
|
69
|
+
run,
|
|
70
|
+
...extra,
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* A Full case for one wider policy the provider declares: on a computer of its own (never the run's shared one), a
|
|
74
|
+
* change from none to it and back to none is refused in words with the network unchanged, or applied, returned and
|
|
75
|
+
* read back as asked.
|
|
76
|
+
*/
|
|
77
|
+
const switchCase = (name, wider) => provider(name, async (t) => {
|
|
78
|
+
const ref = await t.create({ labels: own(t, name) });
|
|
79
|
+
for (const policy of [wider, "none"]) {
|
|
80
|
+
const was = t.ok(await t.provider.network(ref), "network read-back");
|
|
81
|
+
const changed = await t.provider.network(ref, policy);
|
|
82
|
+
const words = `a change from network ${JSON.stringify(was)} to ${JSON.stringify(policy)}`;
|
|
83
|
+
if (changed.ok) {
|
|
84
|
+
t.deepEqual(changed.value, policy, `${words}: what it returns`);
|
|
85
|
+
t.deepEqual(t.ok(await t.provider.network(ref), "network read-back"), policy, `${words}: the network read back after it`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const error = t.refused(changed, words, ["refused"]);
|
|
89
|
+
t.assert(error.message !== "", `${words}: the refusal is in words`);
|
|
90
|
+
t.deepEqual(t.ok(await t.provider.network(ref), "network read-back"), was, `${words}, refused: the network read back after it`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, { level: "full", needs: [`network:${kindOf(wider)}`] });
|
|
94
|
+
export const providerCases = [
|
|
95
|
+
provider("check-refuses", async (t) => {
|
|
96
|
+
t.deepEqual(t.provider.check(t.spec()), [], "check of the run's own spec");
|
|
97
|
+
const labels = own(t, "check");
|
|
98
|
+
const { lifetimeMs: _, ...withoutLifetime } = t.spec({ labels });
|
|
99
|
+
for (const [what, spec] of [
|
|
100
|
+
["no lifetime", withoutLifetime],
|
|
101
|
+
["lifetime 0", t.spec({ labels, lifetimeMs: 0 })],
|
|
102
|
+
]) {
|
|
103
|
+
const refusals = t.provider.check(spec);
|
|
104
|
+
t.assert(refusals.some((r) => r.field === "lifetimeMs" && r.message !== ""), `check of a spec with ${what} refuses lifetimeMs in words: ${JSON.stringify(refusals)}`);
|
|
105
|
+
await refusedCreate(t, spec, `create of a spec with ${what}`);
|
|
106
|
+
}
|
|
107
|
+
for (const policy of POLICIES.filter((p) => !t.provider.capabilities().network.includes(kindOf(p)))) {
|
|
108
|
+
const refusals = t.provider.check(t.spec({ labels, network: policy }));
|
|
109
|
+
t.assert(refusals.some((r) => r.field === "network" && r.message !== ""), `check refuses network ${kindOf(policy)}, which the provider does not declare`);
|
|
110
|
+
await refusedCreate(t, t.spec({ labels, network: policy }), `create with network ${kindOf(policy)}`);
|
|
111
|
+
}
|
|
112
|
+
// The vendor's cap is a capability, so check() refuses past it with no vendor call.
|
|
113
|
+
const { maxLifetimeMs } = t.provider.capabilities();
|
|
114
|
+
t.assert(Number.isSafeInteger(maxLifetimeMs) && maxLifetimeMs > 0, `capabilities().maxLifetimeMs is a whole number of milliseconds above 0, not ${JSON.stringify(maxLifetimeMs)}`);
|
|
115
|
+
const over = t.spec({ labels, lifetimeMs: maxLifetimeMs + 1 });
|
|
116
|
+
const refusals = t.provider.check(over);
|
|
117
|
+
t.assert(refusals.some((r) => r.field === "lifetimeMs" && r.message !== ""), `check of lifetimeMs ${maxLifetimeMs + 1}, past maxLifetimeMs, refuses lifetimeMs in words: ${JSON.stringify(refusals)}`);
|
|
118
|
+
await refusedCreate(t, over, "create of a spec past maxLifetimeMs");
|
|
119
|
+
t.deepEqual(await names(t, labels), [], "the computers the refused creates made");
|
|
120
|
+
}),
|
|
121
|
+
provider("create-release", async (t) => {
|
|
122
|
+
const labels = own(t, "release");
|
|
123
|
+
const ref = await t.create({ labels });
|
|
124
|
+
t.assert(typeof ref.id === "string" && ref.id !== "" && typeof ref.name === "string" && ref.name !== "", `a ref with an id and a name: ${JSON.stringify(ref)}`);
|
|
125
|
+
const connected = await t.connect(ref);
|
|
126
|
+
t.deepEqual(t.ok(await connected.client.call("ping", {}), "ping"), {}, "ping in the new computer");
|
|
127
|
+
await connected.close();
|
|
128
|
+
t.deepEqual(await names(t, labels), [ref.name], "listed after create");
|
|
129
|
+
t.ok(await t.provider.release(ref, "delete"), "release delete");
|
|
130
|
+
t.ok(await t.provider.release(ref, "delete"), "a second delete of the same computer");
|
|
131
|
+
t.deepEqual(await names(t, labels), [], "listed after delete");
|
|
132
|
+
t.refused(await t.provider.connect(ref), "connect to a deleted computer", ["gone", "not_found"]);
|
|
133
|
+
}),
|
|
134
|
+
provider("attach", async (t) => {
|
|
135
|
+
const labels = own(t, "attach");
|
|
136
|
+
const spec = t.spec({ labels: { ...labels, role: "a" } });
|
|
137
|
+
const a = await t.create(spec);
|
|
138
|
+
const b = await t.create({ labels: { ...labels, role: "b" } });
|
|
139
|
+
const byId = t.ok(await t.provider.attach({ id: a.id }), "attach by id");
|
|
140
|
+
t.deepEqual(refOf(byId), refOf(a), "attach by id");
|
|
141
|
+
const byLabels = t.ok(await t.provider.attach({ labels: { ...labels, role: "b" } }), "attach by labels");
|
|
142
|
+
t.deepEqual(refOf(byLabels), refOf(b), "attach by labels");
|
|
143
|
+
// What attach reports is read back from the computer: the network and image create asked for, and, since create
|
|
144
|
+
// asked for no user, the provider's non-root default.
|
|
145
|
+
for (const [how, attached] of [["by id", byId], ["by labels", byLabels]]) {
|
|
146
|
+
const read = t.present(attached.spec, `attach ${how} reports the spec it read back`);
|
|
147
|
+
t.deepEqual(read.network, spec.network, `attach ${how}: the network it reports`);
|
|
148
|
+
t.equal(read.image, spec.image, `attach ${how}: the image it reports`);
|
|
149
|
+
t.match(read.user, /^\d+:\d+$/, `attach ${how}: the user it reports, as uid:gid`);
|
|
150
|
+
t.assert(!read.user.startsWith("0:"), `attach ${how} reports user ${read.user}, root, though create asked for no user`);
|
|
151
|
+
}
|
|
152
|
+
const both = t.refused(await t.provider.attach({ labels }), "attach by labels two computers match", ["invalid"]);
|
|
153
|
+
t.assert(both.message !== "", "the refusal is in words");
|
|
154
|
+
t.refused(await t.provider.attach({ labels: { ...labels, role: "c" } }), "attach by labels no computer has", ["not_found"]);
|
|
155
|
+
const connected = await t.connect(byLabels);
|
|
156
|
+
t.deepEqual(t.ok(await connected.client.call("ping", {}), "ping"), {}, "ping in the attached computer");
|
|
157
|
+
t.ok(await t.provider.release(a, "delete"), "release a");
|
|
158
|
+
t.refused(await t.provider.attach({ id: a.id }), "attach to a deleted computer", ["not_found"]);
|
|
159
|
+
}),
|
|
160
|
+
provider("list", async (t) => {
|
|
161
|
+
const labels = own(t, "list");
|
|
162
|
+
const before = Date.now();
|
|
163
|
+
const spec = t.spec({ labels: { ...labels, role: "listed" } });
|
|
164
|
+
const ref = await t.create(spec);
|
|
165
|
+
const after = Date.now();
|
|
166
|
+
const listed = t.ok(await t.provider.list(labels), "list");
|
|
167
|
+
t.equal(listed.length, 1, "computers with the case's labels");
|
|
168
|
+
const info = t.present(listed[0], "the listed computer");
|
|
169
|
+
t.deepEqual(refOf(info.ref), refOf(ref), "its ref");
|
|
170
|
+
t.equal(info.labels.role, "listed", "its label role");
|
|
171
|
+
t.equal(info.labels[CASE_LABEL], labels[CASE_LABEL], "its case label");
|
|
172
|
+
t.equal(info.state, "running", "its state");
|
|
173
|
+
t.deepEqual(info.network, spec.network, "its network, read back");
|
|
174
|
+
const deadline = info.deadline instanceof Date ? info.deadline.getTime() : Number.NaN;
|
|
175
|
+
t.assert(deadline >= before + spec.lifetimeMs - 1000 && deadline <= after + spec.lifetimeMs + 1000, `its deadline, ${String(info.deadline)}, is lifetimeMs after create`);
|
|
176
|
+
t.deepEqual(await names(t, { ...labels, role: "other" }), [], "list by a label no computer has");
|
|
177
|
+
}),
|
|
178
|
+
// Stop is declared or refused: a provider that declares it lists the computer stopped; one that does not refuses it
|
|
179
|
+
// in words and leaves the computer running, never stopped or deleted behind the caller's back.
|
|
180
|
+
provider("stop", async (t) => {
|
|
181
|
+
const labels = own(t, "stop");
|
|
182
|
+
const ref = await t.create({ labels });
|
|
183
|
+
const declared = t.provider.capabilities().release;
|
|
184
|
+
if (!(Array.isArray(declared) && declared.includes("stop"))) {
|
|
185
|
+
const words = "release stop, which the provider does not declare";
|
|
186
|
+
const error = t.refused(await t.provider.release(ref, "stop"), words, ["unsupported"]);
|
|
187
|
+
t.assert(error.message !== "", `${words}: the refusal is in words`);
|
|
188
|
+
t.deepEqual(t.ok(await t.provider.list(labels), "list").map((info) => [info.ref.name, info.state]), [[ref.name, "running"]], `${words}: the computer is still listed, running`);
|
|
189
|
+
t.ok(await t.provider.release(ref, "delete"), "release delete");
|
|
190
|
+
t.deepEqual(await names(t, labels), [], "listed after delete");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
t.ok(await t.provider.release(ref, "stop"), "release stop");
|
|
194
|
+
// A provider that declares stopDeletes ends a stopped computer: once release returns, it is neither listed nor
|
|
195
|
+
// attachable, and a delete after it is the idempotent delete of a computer already gone.
|
|
196
|
+
if (t.provider.capabilities().stopDeletes === true) {
|
|
197
|
+
const words = "a stop on a provider whose stop ends in deletion (stopDeletes)";
|
|
198
|
+
t.deepEqual(await names(t, labels), [], `${words}: listed after it`);
|
|
199
|
+
t.refused(await t.provider.attach({ id: ref.id }), `${words}: attach to it`, ["not_found"]);
|
|
200
|
+
t.ok(await t.provider.release(ref, "delete"), `${words}: a delete after it`);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const listed = t.ok(await t.provider.list(labels), "list");
|
|
204
|
+
t.deepEqual(listed.map((info) => [info.ref.name, info.state]), [[ref.name, "stopped"]], "a stopped computer is listed, stopped");
|
|
205
|
+
t.ok(await t.provider.release(ref, "delete"), "release delete of a stopped computer");
|
|
206
|
+
t.deepEqual(await names(t, labels), [], "listed after delete");
|
|
207
|
+
}),
|
|
208
|
+
provider("network-change", async (t) => {
|
|
209
|
+
const spec = t.spec({ labels: own(t, "network") });
|
|
210
|
+
const ref = await t.create(spec);
|
|
211
|
+
const declared = t.provider.capabilities().network;
|
|
212
|
+
t.deepEqual(t.ok(await t.provider.network(ref), "network read-back"), spec.network, "the network read back");
|
|
213
|
+
t.deepEqual(t.ok(await t.provider.network(ref, spec.network), "asking for the network it has"), spec.network, "asking for the network it has");
|
|
214
|
+
// Core never asks for a network the provider could give: only for one it does not declare, which it must refuse.
|
|
215
|
+
for (const policy of POLICIES.filter((p) => !declared.includes(kindOf(p)))) {
|
|
216
|
+
const words = `a change to network ${JSON.stringify(policy)}, which the provider does not declare`;
|
|
217
|
+
const error = t.refused(await t.provider.network(ref, policy), words, ["refused"]);
|
|
218
|
+
t.assert(error.message !== "", `${words}: the refusal is in words`);
|
|
219
|
+
t.deepEqual(t.ok(await t.provider.network(ref), "network read-back"), spec.network, `${words}, refused: the network read back after it`);
|
|
220
|
+
}
|
|
221
|
+
}),
|
|
222
|
+
switchCase("network-switch", "open"),
|
|
223
|
+
switchCase("network-switch-allow", { allow: ["example.com"] }),
|
|
224
|
+
provider("network-open", async (t) => {
|
|
225
|
+
const labels = own(t, "open");
|
|
226
|
+
const ref = await t.create({ labels, network: "open" });
|
|
227
|
+
t.equal(t.ok(await t.provider.network(ref), "network read-back"), "open", "the network read back");
|
|
228
|
+
t.deepEqual(t.ok(await t.provider.list(labels), "list").map((info) => info.network), ["open"], "the network list reads back");
|
|
229
|
+
const connected = await t.connect(ref);
|
|
230
|
+
t.deepEqual(t.ok(await connected.client.call("ping", {}), "ping"), {}, "ping in an open computer");
|
|
231
|
+
}, { level: "full", needs: ["network:open"] }),
|
|
232
|
+
provider("network-allow", async (t) => {
|
|
233
|
+
const policy = { allow: ["example.com"] };
|
|
234
|
+
const ref = await t.create({ labels: own(t, "allow"), network: policy });
|
|
235
|
+
t.deepEqual(t.ok(await t.provider.network(ref), "network read-back"), policy, "the allowlist read back");
|
|
236
|
+
}, { level: "full", needs: ["network:allow"] }),
|
|
237
|
+
provider("deadline", async (t) => {
|
|
238
|
+
const labels = own(t, "deadline");
|
|
239
|
+
const { ref, lifetimeMs, created } = await deadlineComputer(t, labels);
|
|
240
|
+
const connected = await t.connect(ref);
|
|
241
|
+
t.ok(await connected.client.call("process.start", { argv: ["sh", "-c", "trap '' TERM; sleep 600"] }), "a process that ignores TERM");
|
|
242
|
+
await connected.close();
|
|
243
|
+
await t.clock.sleep(Math.max(0, created + lifetimeMs + 1000 - t.clock.now()));
|
|
244
|
+
if (t.provider.capabilities().lifetime === "janitor")
|
|
245
|
+
t.ok(await sweep(t.provider, { labels, now: new Date(t.clock.now()) }), "the janitor's sweep after the deadline");
|
|
246
|
+
await t.until(async () => t.ok(await t.provider.list(labels), "list").every((info) => info.state !== "running"), "the computer past its deadline, with a process that ignores TERM, stopped or gone", 120_000);
|
|
247
|
+
t.refused(await t.provider.connect(ref), "connect to a computer past its deadline", ["gone", "not_found"]);
|
|
248
|
+
},
|
|
249
|
+
// Two creates on a slow host, the second's longer lifetime, and two minutes for the end to show.
|
|
250
|
+
{ needs: ["processes"], timeoutMs: 600_000 }),
|
|
251
|
+
provider("janitor", async (t) => {
|
|
252
|
+
if (t.provider.capabilities().stopDeletes === true)
|
|
253
|
+
t.skip("the provider declares stopDeletes: a stop ends in deletion, so it keeps no stopped computer for the janitor to sweep");
|
|
254
|
+
const labels = own(t, "janitor");
|
|
255
|
+
const stopped = await t.create({ lifetimeMs: 60_000, labels: { ...labels, role: "stopped" } });
|
|
256
|
+
const running = await t.create({ lifetimeMs: 5 * 60_000, labels: { ...labels, role: "running" } });
|
|
257
|
+
const long = await t.create({ labels: { ...labels, role: "long" } });
|
|
258
|
+
t.ok(await t.provider.release(stopped, "stop"), "release stop");
|
|
259
|
+
const swept = t.ok(await sweep(t.provider, { labels, now: new Date(Date.now() + 6 * 60_000) }), "sweep");
|
|
260
|
+
t.deepEqual([[...swept.deleted].sort(), swept.kept], [[stopped.name, running.name].sort(), 1], "a sweep past two deadlines: the stopped and the running computer deleted, the third kept");
|
|
261
|
+
t.deepEqual(await names(t, labels), [long.name], "left after the sweep");
|
|
262
|
+
t.deepEqual(refOf(t.ok(await t.provider.attach({ id: t.ref.id }), "attach to the run's computer")), refOf(t.ref), "a computer outside the swept labels");
|
|
263
|
+
// The computers only: a provider that also sweeps its own leftovers (Docker's egress proxies) reports them beside.
|
|
264
|
+
const again = t.ok(await sweep(t.provider, { labels }), "a second sweep");
|
|
265
|
+
t.deepEqual({ deleted: again.deleted, kept: again.kept }, { deleted: [], kept: 1 }, "a second sweep, now");
|
|
266
|
+
}, { level: "full", needs: ["lifetime:janitor", "release:stop"], computer: "shared" }),
|
|
267
|
+
// A takeover by label: computers of one run at epochs 1, 2 and 3 and one of another run at epoch 1; a claim at epoch 3
|
|
268
|
+
// releases 1 and 2 and keeps 3 and the other run's, and a claim at epoch 2 after it is fenced and releases nothing.
|
|
269
|
+
// Full: it needs only list, labels and release delete, but the run and epoch labels are the cutover's, not yet Core.
|
|
270
|
+
provider("release-older", async (t) => {
|
|
271
|
+
const labels = own(t, "release-older");
|
|
272
|
+
const nonce = randomBytes(6).toString("hex");
|
|
273
|
+
const run = `conformance-${nonce}`;
|
|
274
|
+
const other = `conformance-other-${nonce}`;
|
|
275
|
+
// Compared by id and name: create may return notes beside the ref (a provider's probe records what it found).
|
|
276
|
+
const [e1, e2, e3, o1] = (await Promise.all([runLabels(run, 1), runLabels(run, 2), runLabels(run, 3), runLabels(other, 1)].map((epochs) => t.create({ labels: { ...labels, ...epochs } })))).map(refOf);
|
|
277
|
+
// The provider carries both labels and reads them back.
|
|
278
|
+
const read = t.ok(await t.provider.list({ [RUN_LABEL]: run }), `list by ${RUN_LABEL}`);
|
|
279
|
+
for (const [ref, of, epoch] of [[e1, run, "1"], [e2, run, "2"], [e3, run, "3"]]) {
|
|
280
|
+
const info = t.present(read.find((one) => one.ref.name === ref.name), `${ref.name} is listed by ${RUN_LABEL}`);
|
|
281
|
+
t.deepEqual([info.labels[RUN_LABEL], info.labels[EPOCH_LABEL]], [of, epoch], `${ref.name}: its ${RUN_LABEL} and ${EPOCH_LABEL} labels, read back`);
|
|
282
|
+
}
|
|
283
|
+
const done = t.ok(await releaseOlder(t.provider, run, 3, { signal: t.signal }), "releaseOlder at epoch 3");
|
|
284
|
+
t.deepEqual(done.released.map(refOf).sort(byName), [e1, e2].sort(byName), "releaseOlder at epoch 3: the computers it released");
|
|
285
|
+
t.deepEqual(done.kept.map(refOf), [e3], "releaseOlder at epoch 3: the computers it kept");
|
|
286
|
+
t.deepEqual(done.unproven, [], "releaseOlder at epoch 3: computers with no epoch it could read");
|
|
287
|
+
// By id first, which no label filter decides: 1 and 2 are gone, 3 and the other run's are there.
|
|
288
|
+
for (const gone of [e1, e2])
|
|
289
|
+
t.refused(await t.provider.attach({ id: gone.id }), `attach to ${gone.name}, released`, ["not_found"]);
|
|
290
|
+
for (const left of [e3, o1])
|
|
291
|
+
t.deepEqual(refOf(t.ok(await t.provider.attach({ id: left.id }), `attach to ${left.name}`)), left, `attach to ${left.name}, kept`);
|
|
292
|
+
// Then by label: list holds to the run's label.
|
|
293
|
+
t.deepEqual(await names(t, { [RUN_LABEL]: run }), [e3.name], "the run's computers after releaseOlder at epoch 3");
|
|
294
|
+
t.deepEqual(await names(t, { [RUN_LABEL]: other }), [o1.name], "the other run's computers after releaseOlder at epoch 3");
|
|
295
|
+
const fenced = t.refused(await releaseOlder(t.provider, run, 2, { signal: t.signal }), "releaseOlder at epoch 2, with epoch 3 there", ["refused"]);
|
|
296
|
+
t.match(fenced.message, /^fenced: /, "releaseOlder at epoch 2, with epoch 3 there: its refusal");
|
|
297
|
+
t.deepEqual(await names(t, { [RUN_LABEL]: run }), [e3.name], "the run's computers after the fenced releaseOlder");
|
|
298
|
+
for (const ref of [e3, o1])
|
|
299
|
+
t.ok(await t.provider.release(ref, "delete"), `release ${ref.name}`);
|
|
300
|
+
t.deepEqual(await names(t, labels), [], "the case's computers after it");
|
|
301
|
+
}, { level: "full", timeoutMs: 300_000 }),
|
|
302
|
+
];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Rect, type ScreenShotResult } from "../../protocol.js";
|
|
2
|
+
import { type Png } from "../png.js";
|
|
3
|
+
import type { Case, CaseContext } from "../types.js";
|
|
4
|
+
/** A whole screenshot: screen.shot, then screen.read from each offset until eof, then every pixel decoded. */
|
|
5
|
+
export declare function shoot(t: CaseContext, region?: Rect): Promise<{
|
|
6
|
+
shot: ScreenShotResult;
|
|
7
|
+
image: Png;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const screenCases: Case[];
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// The screen: a shot is a PNG of the size it says, read whole through screen.read, and every pixel of it decodes; a
|
|
2
|
+
// region shot has the region's size and decodes too; on a desktop the fixture's colors are where the fixture paints them.
|
|
3
|
+
// The live view (provider.watch, screen.watch underneath): the first frame decodes to the size it says, of the screen
|
|
4
|
+
// screen.shot reads, and a pointer move is a new frame with the cursor where it went.
|
|
5
|
+
import { MAX_CHUNK_BYTES } from "../../protocol.js";
|
|
6
|
+
import { FIXTURE_COLORS } from "../fixture.js";
|
|
7
|
+
import { MAX_PNG_BYTES, readPng } from "../png.js";
|
|
8
|
+
/** A whole screenshot: screen.shot, then screen.read from each offset until eof, then every pixel decoded. */
|
|
9
|
+
export async function shoot(t, region) {
|
|
10
|
+
const what = region ? `the shot of region ${JSON.stringify(region)}` : "the shot";
|
|
11
|
+
const shot = await t.call("screen.shot", region ? { region } : {});
|
|
12
|
+
// No accepted PNG is larger than MAX_PNG_BYTES: a shot that says it is is refused before it is read, and the loop below
|
|
13
|
+
// reads no further than the size it says, so no more than MAX_PNG_BYTES is ever held.
|
|
14
|
+
t.assert(shot.size <= MAX_PNG_BYTES, `${what}: screen.shot says ${shot.size} bytes, more than ${MAX_PNG_BYTES} bytes, the largest PNG the suite reads`);
|
|
15
|
+
const first = Buffer.from(shot.data, "base64");
|
|
16
|
+
t.assert(first.length <= MAX_CHUNK_BYTES, `${what}: screen.shot gave ${first.length} bytes, over MAX_CHUNK_BYTES`);
|
|
17
|
+
const parts = [first];
|
|
18
|
+
let offset = first.length;
|
|
19
|
+
let eof = shot.eof;
|
|
20
|
+
while (!eof) {
|
|
21
|
+
t.assert(offset < shot.size, `${what}: ${offset} bytes read of ${shot.size}, and still no eof`);
|
|
22
|
+
const read = await t.call("screen.read", { id: shot.id, offset });
|
|
23
|
+
const data = Buffer.from(read.data, "base64");
|
|
24
|
+
t.assert(data.length > 0 || read.eof, `${what}: screen.read at ${offset} gave no bytes and no eof`);
|
|
25
|
+
t.assert(data.length <= MAX_CHUNK_BYTES, `${what}: screen.read gave ${data.length} bytes, over MAX_CHUNK_BYTES`);
|
|
26
|
+
parts.push(data);
|
|
27
|
+
offset += data.length;
|
|
28
|
+
eof = read.eof;
|
|
29
|
+
}
|
|
30
|
+
const png = Buffer.concat(parts);
|
|
31
|
+
t.equal(png.length, shot.size, `${what}: the bytes read, against its size`);
|
|
32
|
+
let image;
|
|
33
|
+
try {
|
|
34
|
+
image = readPng(png);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new Error(`${what}: ${error instanceof Error ? error.message : String(error)}`);
|
|
38
|
+
}
|
|
39
|
+
return { shot, image };
|
|
40
|
+
}
|
|
41
|
+
const QUADRANTS = ["top left", "top right", "bottom left", "bottom right"];
|
|
42
|
+
export const screenCases = [
|
|
43
|
+
{
|
|
44
|
+
id: "screen.screenshot-size",
|
|
45
|
+
level: "core",
|
|
46
|
+
group: "screen",
|
|
47
|
+
needs: ["screen"],
|
|
48
|
+
async run(t) {
|
|
49
|
+
const { shot, image } = await shoot(t);
|
|
50
|
+
t.assert(shot.width > 0 && shot.height > 0, `the shot is ${shot.width}x${shot.height}`);
|
|
51
|
+
t.deepEqual([image.width, image.height], [shot.width, shot.height], "the PNG's size (IHDR), against the shot's width and height");
|
|
52
|
+
t.assert(typeof shot.scale === "number" && shot.scale > 0, `scale is a number above 0, not ${JSON.stringify(shot.scale)}`);
|
|
53
|
+
const region = [Math.floor(shot.width / 4), Math.floor(shot.height / 4), Math.max(1, Math.floor(shot.width / 2)), Math.max(1, Math.floor(shot.height / 2))];
|
|
54
|
+
const part = await shoot(t, region);
|
|
55
|
+
t.deepEqual([part.image.width, part.image.height], [region[2], region[3]], `the PNG of region ${JSON.stringify(region)}: its size (IHDR)`);
|
|
56
|
+
t.deepEqual([part.shot.width, part.shot.height], [region[2], region[3]], `the shot of region ${JSON.stringify(region)}: its width and height`);
|
|
57
|
+
if (t.provider.capabilities().kind !== "desktop")
|
|
58
|
+
return;
|
|
59
|
+
const fixture = await t.fixture();
|
|
60
|
+
const [x, y, w, h] = fixture.bounds;
|
|
61
|
+
const painted = (await shoot(t)).image;
|
|
62
|
+
for (const [i, [fx, fy]] of [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]].entries()) {
|
|
63
|
+
const px = Math.floor(x + fx * w);
|
|
64
|
+
const py = Math.floor(y + fy * h);
|
|
65
|
+
t.deepEqual(painted.rgb(px, py), FIXTURE_COLORS[i], `the fixture's ${QUADRANTS[i]} quadrant, at (${px}, ${py})`);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "screen.watch",
|
|
71
|
+
level: "core",
|
|
72
|
+
group: "screen",
|
|
73
|
+
needs: ["screen"],
|
|
74
|
+
async run(t) {
|
|
75
|
+
const { shot } = await shoot(t);
|
|
76
|
+
const watcher = t.provider.watch;
|
|
77
|
+
t.assert(watcher !== undefined, "the provider has no watch(): a computer with a screen gives its live view through it");
|
|
78
|
+
// The live view, as the runner's viewer opens it: frames to a handler, each acked before the next.
|
|
79
|
+
const frames = [];
|
|
80
|
+
let ack;
|
|
81
|
+
let ended;
|
|
82
|
+
let wake;
|
|
83
|
+
const handlers = {
|
|
84
|
+
frame(frame, given) {
|
|
85
|
+
frames.push(frame);
|
|
86
|
+
ack = given;
|
|
87
|
+
wake?.();
|
|
88
|
+
},
|
|
89
|
+
ended(error) {
|
|
90
|
+
ended = error;
|
|
91
|
+
wake?.();
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
const watch = t.ok(await watcher.call(t.provider, t.ref, handlers, { signal: t.signal }), "watch");
|
|
95
|
+
try {
|
|
96
|
+
let taken = 0;
|
|
97
|
+
/** The next frame not yet taken, acking the one taken before it: within ms, or undefined. */
|
|
98
|
+
const nextWithin = async (ms) => {
|
|
99
|
+
if (frames.length === taken) {
|
|
100
|
+
const arrived = new Promise((resolve) => (wake = resolve));
|
|
101
|
+
// The frame taken last is drawn: ack it, and the next is asked for.
|
|
102
|
+
const given = ack;
|
|
103
|
+
ack = undefined;
|
|
104
|
+
given?.();
|
|
105
|
+
if (frames.length === taken && ended === undefined)
|
|
106
|
+
await within(arrived, ms, "a frame");
|
|
107
|
+
}
|
|
108
|
+
t.assert(ended === undefined, `the watch ended: ${ended?.code}: ${ended?.message}`);
|
|
109
|
+
return frames.length > taken ? frames[taken++] : undefined;
|
|
110
|
+
};
|
|
111
|
+
const next = async (what) => {
|
|
112
|
+
const got = await nextWithin(t.patience);
|
|
113
|
+
t.assert(got !== undefined, `${what}: no frame within ${t.patience} ms`);
|
|
114
|
+
return got;
|
|
115
|
+
};
|
|
116
|
+
const first = await next("the first frame");
|
|
117
|
+
t.assert(first.seq >= 1, `the first frame's seq is ${first.seq}, not 1 or more`);
|
|
118
|
+
t.assert(first.format === "jpeg" || first.format === "png", `the first frame's format is ${JSON.stringify(first.format)}, not jpeg or png`);
|
|
119
|
+
let w;
|
|
120
|
+
let h;
|
|
121
|
+
try {
|
|
122
|
+
[w, h] = decodedSize(first.bytes, first.format);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw new Error(`the first frame's ${first.format.toUpperCase()} does not decode: ${error instanceof Error ? error.message : String(error)}`);
|
|
126
|
+
}
|
|
127
|
+
t.assert(w === first.frameWidth && h === first.frameHeight, `the first frame's ${first.format.toUpperCase()} is ${w}x${h}, not the ${first.frameWidth}x${first.frameHeight} it says`);
|
|
128
|
+
t.deepEqual([first.width, first.height], [shot.width, shot.height], "the frame's screen size (the input space), against screen.shot's");
|
|
129
|
+
t.assert(first.frameWidth <= first.width, `the frame is ${first.frameWidth} wide, wider than the ${first.width}-pixel screen`);
|
|
130
|
+
// A pointer move is a new frame (the cursor is part of what a frame shows), with the cursor where it went.
|
|
131
|
+
if (!t.hello.groups.includes("input.pointer"))
|
|
132
|
+
return;
|
|
133
|
+
const at = first.cursor?.[0] === Math.floor(first.width / 3) ? [Math.floor(first.width / 3) + 1, Math.floor(first.height / 3)] : [Math.floor(first.width / 3), Math.floor(first.height / 3)];
|
|
134
|
+
t.deepEqual(t.ok(await watch.input([{ type: "move", at }]), `input: a pointer move to ${at}`), { done: 1 }, `input: a pointer move to ${at}`);
|
|
135
|
+
let moved;
|
|
136
|
+
const until = t.clock.now() + t.patience;
|
|
137
|
+
// A desktop may change on its own (a clock): the frame the move made is the first with the cursor there, and a
|
|
138
|
+
// frame with no cursor, or with it elsewhere, is not it.
|
|
139
|
+
const there = (frame) => frame.cursor?.[0] === at[0] && frame.cursor?.[1] === at[1];
|
|
140
|
+
while (moved === undefined || !there(moved)) {
|
|
141
|
+
const left = until - t.clock.now();
|
|
142
|
+
const got = left > 0 ? await nextWithin(left) : undefined;
|
|
143
|
+
if (moved === undefined)
|
|
144
|
+
t.assert(got !== undefined, `a pointer move to ${at} gave no new frame within ${t.patience} ms`);
|
|
145
|
+
else
|
|
146
|
+
t.assert(got !== undefined, `a pointer move to ${at} gave no frame with the cursor there within ${t.patience} ms: the last frame's cursor is ${moved.cursor ? moved.cursor.join(",") : "missing"}`);
|
|
147
|
+
moved = got;
|
|
148
|
+
}
|
|
149
|
+
t.assert(moved.seq > first.seq, `the frame after the move is seq ${moved.seq}, not past ${first.seq}`);
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
await watch.close();
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
/** promise's value, or undefined once ms passed first. */
|
|
158
|
+
async function within(promise, ms, _what) {
|
|
159
|
+
let timer;
|
|
160
|
+
try {
|
|
161
|
+
return await Promise.race([promise, new Promise((done) => (timer = setTimeout(() => done(undefined), ms)))]);
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
clearTimeout(timer);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The width and height of a frame that decodes, or a throw in words. A PNG is decoded whole (every pixel, readPng). A
|
|
169
|
+
* JPEG is walked to its end, with no decoder in the suite: its start, its segments each inside the bytes, a frame header
|
|
170
|
+
* (SOF) and a quantization table (DQT) before its first scan, entropy-coded data in each scan, and its end (EOI) last.
|
|
171
|
+
*/
|
|
172
|
+
function decodedSize(bytes, format) {
|
|
173
|
+
if (format === "png") {
|
|
174
|
+
const png = readPng(bytes);
|
|
175
|
+
return [png.width, png.height];
|
|
176
|
+
}
|
|
177
|
+
return jpegSize(Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength));
|
|
178
|
+
}
|
|
179
|
+
/** A JPEG's width and height once its structure is whole; see decodedSize. */
|
|
180
|
+
function jpegSize(b) {
|
|
181
|
+
if (b.length < 4 || b[0] !== 0xff || b[1] !== 0xd8)
|
|
182
|
+
throw new Error("it lacks the JPEG start (SOI)");
|
|
183
|
+
let size;
|
|
184
|
+
let tables = false;
|
|
185
|
+
let scans = 0;
|
|
186
|
+
for (let i = 2;;) {
|
|
187
|
+
if (i + 2 > b.length || b[i] !== 0xff)
|
|
188
|
+
throw new Error(`byte ${i} is not a marker, and the JPEG has not ended (EOI)`);
|
|
189
|
+
const marker = b[i + 1];
|
|
190
|
+
if (marker === 0xd9) {
|
|
191
|
+
if (scans === 0)
|
|
192
|
+
throw new Error("it ends with no scan (SOS): it holds no pixels");
|
|
193
|
+
if (i + 2 !== b.length)
|
|
194
|
+
throw new Error(`${b.length - i - 2} bytes follow its end (EOI)`);
|
|
195
|
+
if (size === undefined || size[0] === 0 || size[1] === 0)
|
|
196
|
+
throw new Error("its frame header (SOF) gives no size");
|
|
197
|
+
return size;
|
|
198
|
+
}
|
|
199
|
+
if (i + 4 > b.length)
|
|
200
|
+
throw new Error(`its segment at byte ${i} runs past the end, with no scan (SOS) whole`);
|
|
201
|
+
const length = b.readUInt16BE(i + 2);
|
|
202
|
+
if (length < 2 || i + 2 + length > b.length)
|
|
203
|
+
throw new Error(`its segment at byte ${i} runs past the end, with no scan (SOS) whole`);
|
|
204
|
+
// SOF0 to SOF15, but DHT (C4), JPG (C8) and DAC (CC): the frame's height, then its width.
|
|
205
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
|
|
206
|
+
if (length < 8)
|
|
207
|
+
throw new Error(`its frame header (SOF) at byte ${i} is ${length} bytes, too short`);
|
|
208
|
+
size = [b.readUInt16BE(i + 7), b.readUInt16BE(i + 5)];
|
|
209
|
+
}
|
|
210
|
+
if (marker === 0xdb)
|
|
211
|
+
tables = true;
|
|
212
|
+
i += 2 + length;
|
|
213
|
+
if (marker !== 0xda)
|
|
214
|
+
continue;
|
|
215
|
+
if (size === undefined)
|
|
216
|
+
throw new Error("its scan (SOS) comes before a frame header (SOF)");
|
|
217
|
+
if (!tables)
|
|
218
|
+
throw new Error("its scan (SOS) comes before a quantization table (DQT)");
|
|
219
|
+
// The entropy-coded data runs to the next marker: inside it, 0xFF is followed by 0x00 (a stuffed byte) or a
|
|
220
|
+
// restart marker (D0 to D7).
|
|
221
|
+
const start = i;
|
|
222
|
+
while (i + 1 < b.length && !(b[i] === 0xff && b[i + 1] !== 0x00 && !(b[i + 1] >= 0xd0 && b[i + 1] <= 0xd7)))
|
|
223
|
+
i++;
|
|
224
|
+
if (i === start)
|
|
225
|
+
throw new Error(`its scan at byte ${start} holds no data: no pixels`);
|
|
226
|
+
if (i + 1 >= b.length)
|
|
227
|
+
throw new Error("its scan runs to the last byte, with no end (EOI)");
|
|
228
|
+
scans++;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ComputerKind, Point, Rect, UiNode, UiTreeResult } from "../../protocol.js";
|
|
2
|
+
import type { CaseContext } from "../types.js";
|
|
3
|
+
/** The stock Settings app of each phone kind this suite knows. */
|
|
4
|
+
export declare const PHONE_SETTINGS: Readonly<Partial<Record<ComputerKind, string>>>;
|
|
5
|
+
/** Whether the case checks what it did through Settings: a phone with apps and a UI tree that takes no fixture file. */
|
|
6
|
+
export declare function throughSettings(t: CaseContext): boolean;
|
|
7
|
+
/** The kind's Settings app, or the case skips in words. */
|
|
8
|
+
export declare function settingsApp(t: CaseContext): string;
|
|
9
|
+
/** Settings, fresh and in front: ended, launched, and waited for until it is the app in front. */
|
|
10
|
+
export declare function openSettings(t: CaseContext): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* 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
|
|
13
|
+
* two panes from 600 dp wide), what is in front, the tap point and the row's bounds, whether the row's title shows
|
|
14
|
+
* outside the list (a page opened beside it), and whether the next row is still shown. A part that cannot be read
|
|
15
|
+
* says so; none of it throws.
|
|
16
|
+
*/
|
|
17
|
+
export declare function tapScene(t: CaseContext, { at, row, next, tree }: {
|
|
18
|
+
at: Point;
|
|
19
|
+
row: Row;
|
|
20
|
+
next: Row;
|
|
21
|
+
tree: UiTreeResult | undefined;
|
|
22
|
+
}): Promise<string>;
|
|
23
|
+
/** Every node of a tree, depth first. */
|
|
24
|
+
export declare function nodesOf(root: UiNode): UiNode[];
|
|
25
|
+
/**
|
|
26
|
+
* Whether a tree shows a name anywhere, as a text or a label. A live Android 15 Settings page shows its title only as
|
|
27
|
+
* its collapsing toolbar's content-desc (phone probe 3), with no text node holding it.
|
|
28
|
+
*/
|
|
29
|
+
export declare const showsName: (tree: UiTreeResult, name: string) => boolean;
|
|
30
|
+
/** The texts a tree shows. */
|
|
31
|
+
export declare const textsOf: (tree: UiTreeResult) => string[];
|
|
32
|
+
export interface Row {
|
|
33
|
+
text: string;
|
|
34
|
+
bounds: Rect;
|
|
35
|
+
}
|
|
36
|
+
/** The middle of a rect, in whole pixels. */
|
|
37
|
+
export declare const middle: ([x, y, w, h]: Rect) => [number, number];
|
|
38
|
+
/** The scrollable list a tree shows, the first one. */
|
|
39
|
+
export declare function listOf(tree: UiTreeResult): UiNode | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The rows of a tree's list: each clickable node in it, whole inside it, with the first text it holds. Settings' search
|
|
42
|
+
* entry is not a row, though a live Settings shows it as the list's first item.
|
|
43
|
+
*/
|
|
44
|
+
export declare function rowsOf(tree: UiTreeResult): Row[];
|
|
45
|
+
/** Settings' top list, with at least `count` rows of different titles on screen, or the case fails in words. */
|
|
46
|
+
export declare function settingsRows(t: CaseContext, count: number): Promise<{
|
|
47
|
+
tree: UiTreeResult;
|
|
48
|
+
rows: Row[];
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Settings' search field, opened from its list: the case taps the search entry (the first clickable node that says
|
|
52
|
+
* 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
|
|
53
|
+
* waits for the field. An empty field may show its hint as its text, so only the field is waited for.
|
|
54
|
+
*/
|
|
55
|
+
export declare function openSearch(t: CaseContext): Promise<void>;
|
|
56
|
+
/** The text in Settings' search field now, or undefined when no field is shown. */
|
|
57
|
+
export declare function searchText(t: CaseContext): Promise<string | undefined>;
|