@parcha/agentrun-computer 0.1.0-beta.36 → 0.1.0-beta.37

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.
Files changed (121) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +321 -308
  3. package/box/build-agent37.mjs +177 -0
  4. package/dist/agent37.d.ts +165 -0
  5. package/dist/agent37.js +759 -0
  6. package/dist/attach.d.ts +146 -0
  7. package/dist/attach.js +469 -0
  8. package/dist/browserbase.d.ts +2 -4
  9. package/dist/browserbase.js +2 -1
  10. package/dist/client.d.ts +33 -1
  11. package/dist/client.js +53 -0
  12. package/dist/computerd-linux-amd64 +0 -0
  13. package/dist/computerd-linux-arm64 +0 -0
  14. package/dist/conformance/agent37.d.ts +96 -0
  15. package/dist/conformance/agent37.js +154 -0
  16. package/dist/conformance/cases/apps.d.ts +5 -0
  17. package/dist/conformance/cases/apps.js +160 -73
  18. package/dist/conformance/cases/health.js +14 -0
  19. package/dist/conformance/cases/index.js +2 -0
  20. package/dist/conformance/cases/provider.js +27 -1
  21. package/dist/conformance/cases/screen.d.ts +3 -0
  22. package/dist/conformance/cases/screen.js +18 -0
  23. package/dist/conformance/cases/settings.d.ts +29 -23
  24. package/dist/conformance/cases/settings.js +76 -58
  25. package/dist/conformance/cases/touch.js +19 -17
  26. package/dist/conformance/cases/ui.d.ts +2 -0
  27. package/dist/conformance/cases/ui.js +475 -0
  28. package/dist/conformance/cli.d.ts +9 -0
  29. package/dist/conformance/cli.js +28 -3
  30. package/dist/conformance/e2b.d.ts +6 -0
  31. package/dist/conformance/e2b.js +9 -2
  32. package/dist/conformance/fixture.d.ts +1 -1
  33. package/dist/conformance/fixture.js +25 -1
  34. package/dist/conformance/modal.d.ts +17 -13
  35. package/dist/conformance/modal.js +18 -9
  36. package/dist/conformance/orgo.d.ts +3 -3
  37. package/dist/conformance/orgo.js +6 -8
  38. package/dist/conformance/phone-harness.d.ts +6 -2
  39. package/dist/conformance/phone-harness.js +21 -4
  40. package/dist/conformance/report.js +1 -1
  41. package/dist/conformance/runner.js +23 -4
  42. package/dist/conformance/sweep.d.ts +50 -0
  43. package/dist/conformance/sweep.js +187 -0
  44. package/dist/conformance/types.d.ts +11 -3
  45. package/dist/conformance/ui-fixture.d.ts +56 -0
  46. package/dist/conformance/ui-fixture.js +43 -0
  47. package/dist/create-requests.d.ts +51 -0
  48. package/dist/create-requests.js +121 -0
  49. package/dist/daytona.d.ts +2 -4
  50. package/dist/daytona.js +3 -2
  51. package/dist/descriptor.d.ts +5 -0
  52. package/dist/descriptor.js +2 -0
  53. package/dist/descriptors/agent37.d.ts +41 -0
  54. package/dist/descriptors/agent37.js +28 -0
  55. package/dist/descriptors/index.d.ts +38 -2
  56. package/dist/descriptors/index.js +4 -2
  57. package/dist/descriptors/orgo.d.ts +2 -1
  58. package/dist/descriptors/orgo.js +3 -2
  59. package/dist/descriptors/phone-harness.d.ts +1 -1
  60. package/dist/descriptors/phone-harness.js +2 -2
  61. package/dist/docker.d.ts +7 -4
  62. package/dist/docker.js +271 -29
  63. package/dist/e2b.d.ts +9 -165
  64. package/dist/e2b.js +282 -1342
  65. package/dist/fake-ui-driver.d.ts +97 -0
  66. package/dist/fake-ui-driver.js +717 -0
  67. package/dist/host.d.ts +182 -0
  68. package/dist/host.js +1 -0
  69. package/dist/hosted/process.d.ts +67 -0
  70. package/dist/hosted/process.js +228 -0
  71. package/dist/hosted/provider.d.ts +146 -0
  72. package/dist/hosted/provider.js +1364 -0
  73. package/dist/hosted/scripts.d.ts +76 -0
  74. package/dist/{child.js → hosted/scripts.js} +93 -12
  75. package/dist/index.d.ts +7 -3
  76. package/dist/index.js +7 -4
  77. package/dist/kernel.d.ts +2 -4
  78. package/dist/kernel.js +2 -1
  79. package/dist/kinds.d.ts +8 -1
  80. package/dist/kinds.js +20 -4
  81. package/dist/local-chrome.d.ts +2 -4
  82. package/dist/local-chrome.js +2 -1
  83. package/dist/modal.d.ts +23 -181
  84. package/dist/modal.js +271 -1244
  85. package/dist/orgo-channel.d.ts +3 -2
  86. package/dist/orgo-channel.js +5 -2
  87. package/dist/orgo-desktop.d.ts +9 -4
  88. package/dist/orgo-desktop.js +33 -13
  89. package/dist/orgo-workspaces.d.ts +47 -0
  90. package/dist/orgo-workspaces.js +94 -0
  91. package/dist/orgo.d.ts +10 -4
  92. package/dist/orgo.js +30 -12
  93. package/dist/phone-harness.d.ts +31 -22
  94. package/dist/phone-harness.js +510 -698
  95. package/dist/png.d.ts +4 -0
  96. package/dist/png.js +27 -0
  97. package/dist/protocol.d.ts +335 -32
  98. package/dist/protocol.js +96 -3
  99. package/dist/provider.d.ts +34 -6
  100. package/dist/provider.js +16 -0
  101. package/dist/result.d.ts +1 -1
  102. package/dist/surface/api.d.ts +248 -0
  103. package/dist/surface/api.js +1 -0
  104. package/dist/surface/core.d.ts +42 -0
  105. package/dist/surface/core.js +393 -0
  106. package/dist/surface/index.d.ts +5 -0
  107. package/dist/surface/index.js +3 -0
  108. package/dist/surface/outline.d.ts +8 -0
  109. package/dist/surface/outline.js +50 -0
  110. package/dist/surface/script.d.ts +10 -0
  111. package/dist/surface/script.js +92 -0
  112. package/dist/ui-engine.d.ts +114 -0
  113. package/dist/ui-engine.js +798 -0
  114. package/package.json +17 -1
  115. package/dist/child.d.ts +0 -42
  116. package/dist/conformance/e2b-diagnose.d.ts +0 -16
  117. package/dist/conformance/e2b-diagnose.js +0 -61
  118. package/dist/conformance/e2b-sweep.d.ts +0 -18
  119. package/dist/conformance/e2b-sweep.js +0 -132
  120. package/dist/conformance/modal-sweep.d.ts +0 -22
  121. package/dist/conformance/modal-sweep.js +0 -213
@@ -1,14 +1,20 @@
1
- // Apps: the fixture installs, is listed, comes to the front when launched and leaves it when terminated; the UI tree has
2
- // the protocol's shape, inside the screen, with the fixture's button found by its id. A phone's stock Settings app is
3
- // listed, launched and terminated with no install, which needs the apps group alone: its launch is seen in the UI tree
4
- // (Settings' list) when the phone has one, else in a screenshot that is not the one before. On a phone that takes no
5
- // fixture file the tree's shape is checked on Settings, with its rows found (settings.ts).
6
- import { MAX_UI_NODES } from "../../protocol.js";
1
+ // Apps: the fixture installs, is listed, comes to the front when launched and leaves it when terminated; ui.observe has
2
+ // the protocol's shape, inside its window, with the fixture's button found by its id. A phone's stock Settings app is
3
+ // listed, launched and terminated with no install, which needs the apps group alone: its launch is seen in ui.observe
4
+ // (Settings' list) when the phone has the ui group, else in a screenshot that is not the one before. On a phone that
5
+ // takes no fixture file the observation's shape is checked on Settings, with its rows found (settings.ts).
6
+ import { MAX_UI_NODES, UI_FLAGS, UI_ROLES } from "../../protocol.js";
7
7
  import { FIXTURE_BUTTON } from "../fixture.js";
8
- import { shoot } from "./screen.js";
9
- import { openSettings, rowsOf, settingsApp, textsOf, throughSettings } from "./settings.js";
8
+ import { featureOff } from "../../ui-engine.js";
9
+ import { UI_FIXTURE } from "../ui-fixture.js";
10
+ import { captureOff, shoot } from "./screen.js";
11
+ import { namesOf, observe, openSettings, rowsOf, settingsApp, throughSettings } from "./settings.js";
10
12
  /** Whether the provider and the computer both declare group. */
11
13
  const declares = (t, group) => t.provider.capabilities().groups.includes(group) && t.hello.groups.includes(group);
14
+ /** Why ui.observe gives no elements here (ui.tree is off), or undefined when it gives them. */
15
+ const treeOff = (t) => featureOff(t.hello.features ?? {}, "ui.tree");
16
+ /** Whether ui.observe shows the screen's elements: the ui group, with ui.tree on. */
17
+ const readsTree = (t) => declares(t, "ui") && treeOff(t) === undefined;
12
18
  /** A screenshot's pixels sampled on a 16 x 16 grid, with its size: two different screens differ in it. */
13
19
  async function screenPrint(t) {
14
20
  const { image } = await shoot(t);
@@ -20,53 +26,80 @@ async function screenPrint(t) {
20
26
  return `${image.width}x${image.height}:${samples.join(";")}`;
21
27
  }
22
28
  /**
23
- * What the screen shows now, as the case compares it: the UI tree's texts when the phone has a tree, else a
24
- * screenshot's print. Undefined when it has neither, and the launch cannot be seen.
29
+ * What the screen shows now, as the case compares it: ui.observe's names and values when it reads the elements, else a
30
+ * screenshot's print, else (ui.tree off, no screen group or screen.capture off) ui.observe's image. Undefined when the
31
+ * launch cannot be seen.
25
32
  */
26
33
  async function shown(t) {
27
- if (declares(t, "apps.ui_tree"))
28
- return JSON.stringify(textsOf(await t.call("apps.ui_tree", {})));
29
- if (declares(t, "screen"))
34
+ if (readsTree(t))
35
+ return JSON.stringify(namesOf(await observe(t)));
36
+ if (declares(t, "screen") && captureOff(t) === undefined)
30
37
  return screenPrint(t);
38
+ if (declares(t, "ui"))
39
+ return (await observe(t)).image?.data;
31
40
  return undefined;
32
41
  }
33
- const BOOLEANS = ["clickable", "focused", "selected", "checked", "scrollable"];
34
- const STRINGS = ["id", "text", "label"];
35
- /** The first way node (at path) breaks the protocol's UiNode, in words, or undefined; counts nodes as it walks. */
36
- function shapeOf(node, path, screen, seen) {
37
- if (typeof node !== "object" || node === null)
38
- return `${path} is not an object`;
39
- const n = node;
40
- seen.nodes++;
41
- if (seen.nodes > MAX_UI_NODES)
42
- return `the tree holds more than ${MAX_UI_NODES} nodes`;
43
- if (typeof n.role !== "string" || n.role === "")
44
- return `${path}.role is ${JSON.stringify(n.role)}, not the platform's class`;
45
- for (const field of STRINGS)
46
- if (n[field] !== undefined && typeof n[field] !== "string")
47
- return `${path}.${field} is ${JSON.stringify(n[field])}, not a string`;
48
- if (typeof n.enabled !== "boolean")
49
- return `${path}.enabled is ${JSON.stringify(n.enabled)}, not a boolean`;
50
- for (const field of BOOLEANS)
51
- if (n[field] !== undefined && typeof n[field] !== "boolean")
52
- return `${path}.${field} is ${JSON.stringify(n[field])}, not a boolean`;
53
- const bounds = n.bounds;
54
- if (!(Array.isArray(bounds) && bounds.length === 4 && bounds.every((v) => typeof v === "number" && Number.isFinite(v)) && bounds[2] >= 0 && bounds[3] >= 0)) {
55
- return `${path}.bounds is ${JSON.stringify(bounds)}, not [x, y, w, h]`;
56
- }
57
- if (screen !== undefined) {
58
- const [x, y, w, h] = bounds;
59
- if (x < 0 || y < 0 || x + w > screen[2] || y + h > screen[3])
60
- return `${path}.bounds ${JSON.stringify(bounds)} reach outside the ${screen[2]}x${screen[3]} screenshot`;
61
- }
62
- if (!Array.isArray(n.children))
63
- return `${path}.children is ${JSON.stringify(n.children)}, not a list`;
64
- if (n.id === FIXTURE_BUTTON.id)
65
- seen.button ??= node;
66
- for (const [i, child] of n.children.entries()) {
67
- const wrong = shapeOf(child, `${path}.children[${i}]`, screen, seen);
68
- if (wrong !== undefined)
69
- return wrong;
42
+ const ROLES = new Set(UI_ROLES);
43
+ const FLAGS = new Set(UI_FLAGS);
44
+ const show = (value) => JSON.stringify(value) ?? String(value);
45
+ const isRect = (value) => Array.isArray(value) && value.length === 4 && value.every((v) => typeof v === "number" && Number.isFinite(v)) && value[2] >= 0 && value[3] >= 0;
46
+ const strings = (value) => Array.isArray(value) && value.every((one) => typeof one === "string");
47
+ /**
48
+ * The first way ui.observe's result breaks the protocol, in words, or undefined: its state, app, window and truncated,
49
+ * and each node against UiNode, its bounds inside the window and its parent a node before it.
50
+ */
51
+ export function observeWrong(result) {
52
+ if (typeof result !== "object" || result === null)
53
+ return "the result is not an object";
54
+ const r = result;
55
+ if (typeof r.state !== "string" || r.state === "")
56
+ return `state is ${show(r.state)}, not a state id`;
57
+ if (typeof r.truncated !== "boolean")
58
+ return `truncated is ${show(r.truncated)}, not a boolean`;
59
+ const app = r.app;
60
+ if (typeof app?.id !== "string" || typeof app.name !== "string")
61
+ return `app is ${show(r.app)}, not { id, name }`;
62
+ const window = r.window;
63
+ if (typeof window?.id !== "string" || !isRect(window.bounds))
64
+ return `window is ${show(r.window)}, not { id, bounds: [x, y, w, h] }`;
65
+ if (window.title !== undefined && typeof window.title !== "string")
66
+ return `window.title is ${show(window.title)}, not a string`;
67
+ if (window.role !== undefined && (typeof window.role !== "string" || !ROLES.has(window.role)))
68
+ return `window.role is ${show(window.role)}, not one of the protocol's roles (UI_ROLES)`;
69
+ const [, , width, height] = window.bounds;
70
+ if (!Array.isArray(r.nodes))
71
+ return `nodes is ${show(r.nodes)}, not a list`;
72
+ if (r.nodes.length > MAX_UI_NODES)
73
+ return `nodes holds ${r.nodes.length}, more than the ${MAX_UI_NODES} one observe gives`;
74
+ const refs = new Set();
75
+ for (const [i, node] of r.nodes.entries()) {
76
+ const at = `nodes[${i}]`;
77
+ if (typeof node !== "object" || node === null)
78
+ return `${at} is not an object`;
79
+ const n = node;
80
+ if (typeof n.ref !== "string" || !n.ref.startsWith("@") || n.ref.length < 2)
81
+ return `${at}.ref is ${show(n.ref)}, not a ref ("@e12")`;
82
+ if (refs.has(n.ref))
83
+ return `${at}.ref ${n.ref} is a ref an earlier node has`;
84
+ if (typeof n.role !== "string" || !ROLES.has(n.role))
85
+ return `${at}.role is ${show(n.role)}, not one of the protocol's roles (UI_ROLES)`;
86
+ for (const field of ["name", "value", "desc", "id"])
87
+ if (n[field] !== undefined && typeof n[field] !== "string")
88
+ return `${at}.${field} is ${show(n[field])}, not a string`;
89
+ if (!isRect(n.bounds))
90
+ return `${at}.bounds is ${show(n.bounds)}, not [x, y, w, h]`;
91
+ const [x, y, w, h] = n.bounds;
92
+ if (x < 0 || y < 0 || x + w > width || y + h > height)
93
+ return `${at}.bounds ${show(n.bounds)} reach outside the window's ${width}x${height} points`;
94
+ if (n.parent !== undefined && (typeof n.parent !== "string" || !refs.has(n.parent)))
95
+ return `${at}.parent is ${show(n.parent)}, not the ref of a node before it`;
96
+ if (n.flags !== undefined && !(strings(n.flags) && n.flags.every((flag) => FLAGS.has(flag))))
97
+ return `${at}.flags is ${show(n.flags)}, not a list of the protocol's flags`;
98
+ if (n.actions !== undefined && !strings(n.actions))
99
+ return `${at}.actions is ${show(n.actions)}, not a list of action names`;
100
+ if (n.flags?.includes("secure") && n.value !== undefined)
101
+ return `${at} is secure and sends its value`;
102
+ refs.add(n.ref);
70
103
  }
71
104
  return undefined;
72
105
  }
@@ -97,27 +130,30 @@ export const appsCases = [
97
130
  group: "apps",
98
131
  needs: ["apps"],
99
132
  async run(t) {
100
- // The phone's own Settings app: listed; launched, in front and shown; terminated, and no longer in front.
101
- const app = settingsApp(t);
133
+ // An app the computer has: the ui fixture where it is installed, else the phone's own Settings app. Listed;
134
+ // launched, in front and shown; terminated, and no longer in front.
102
135
  const listed = await t.call("apps.list", {});
103
136
  t.assert(Array.isArray(listed.apps) && listed.apps.every((one) => typeof one?.id === "string"), `apps.list gives apps with ids: ${JSON.stringify(listed.apps).slice(0, 300)}`);
137
+ const uiFixture = listed.apps.some((one) => one.id === UI_FIXTURE.id);
138
+ const app = uiFixture ? UI_FIXTURE.id : settingsApp(t);
104
139
  t.assert(listed.apps.some((one) => one.id === app), `apps.list holds ${app}`);
105
140
  t.deepEqual(await t.call("apps.terminate", { id: app }), {}, `apps.terminate ${app}`);
106
141
  await t.until(async () => (await foreground(t)) !== app, `${app} not in front after apps.terminate`);
107
142
  const before = await shown(t);
108
143
  if (before === undefined)
109
- return t.skip("no way to see a launch: the computer declares neither apps.ui_tree nor screen");
144
+ return t.skip("no way to see a launch: the computer declares neither ui nor screen");
110
145
  t.deepEqual(await t.call("apps.launch", { id: app }), {}, `apps.launch ${app}`);
111
146
  await t.until(async () => (await foreground(t)) === app, `${app} in front after apps.launch`);
112
147
  // apps.list's word is not enough: the screen must show it.
113
- if (declares(t, "apps.ui_tree")) {
148
+ if (readsTree(t)) {
114
149
  await t.until(async () => {
115
- const tree = await t.call("apps.ui_tree", {});
116
- return rowsOf(tree).length > 0 && JSON.stringify(textsOf(tree)) !== before;
117
- }, `${app} shown after apps.launch: Settings' list in apps.ui_tree, not the screen before it`);
150
+ const seen = await observe(t);
151
+ const ready = uiFixture ? seen.nodes.some((node) => node.id === "next") : rowsOf(seen).length > 0;
152
+ return ready && JSON.stringify(namesOf(seen)) !== before;
153
+ }, `${app} shown after apps.launch: ${uiFixture ? "the ui fixture's Next button" : "Settings' list"} in ui.observe, not the screen before it`);
118
154
  }
119
155
  else {
120
- await t.until(async () => (await screenPrint(t)) !== before, `${app} shown after apps.launch: a screenshot other than the one before it`);
156
+ await t.until(async () => (await shown(t)) !== before, `${app} shown after apps.launch: ${declares(t, "screen") ? "a screenshot" : "ui.observe's image"} other than the one before it`);
121
157
  }
122
158
  t.deepEqual(await t.call("apps.terminate", { id: app }), {}, `apps.terminate ${app}, launched`);
123
159
  await t.until(async () => (await foreground(t)) !== app, `${app} no longer in front after apps.terminate`);
@@ -126,30 +162,81 @@ export const appsCases = [
126
162
  },
127
163
  },
128
164
  {
129
- id: "apps.ui-tree-shape",
165
+ // apps.launch answers once the app has a window (wire.md, apps.launch). A driver that answers when the launch is
166
+ // asked for races every caller: the Mac and the phone both answered not_found to the observe right after it.
167
+ id: "apps.launch-window",
130
168
  level: "core",
131
169
  group: "apps",
132
- needs: ["apps.ui_tree"],
170
+ needs: ["apps", "ui"],
171
+ async run(t) {
172
+ if (treeOff(t) !== undefined && featureOff(t.hello.features ?? {}, "ui.image") !== undefined)
173
+ return t.skip("ui.observe has nothing to show on this computer: ui.tree and ui.image are both off");
174
+ const listed = await t.call("apps.list", {});
175
+ const app = listed.apps.some((one) => one.id === UI_FIXTURE.id) ? UI_FIXTURE.id : settingsApp(t);
176
+ t.assert(listed.apps.some((one) => one.id === app), `apps.list holds ${app}`);
177
+ t.deepEqual(await t.call("apps.terminate", { id: app }), {}, `apps.terminate ${app}`);
178
+ await t.until(async () => (await foreground(t)) !== app, `${app} not in front after apps.terminate`);
179
+ t.deepEqual(await t.call("apps.launch", { id: app }), {}, `apps.launch ${app}`);
180
+ // At once, with no wait of the case's own: launch has answered, so the window is there.
181
+ const seen = await t.client.call("ui.observe", { target: { app } }, { signal: t.signal });
182
+ const window = t.ok(seen, `ui.observe of ${app} right after apps.launch answered: launch answers once the app has a window`);
183
+ t.equal(window.app.id, app, "the app ui.observe saw right after apps.launch");
184
+ t.deepEqual(await t.call("apps.terminate", { id: app }), {}, `apps.terminate ${app}, launched`);
185
+ },
186
+ },
187
+ {
188
+ id: "ui.observe-shape",
189
+ level: "core",
190
+ group: "ui",
191
+ needs: ["ui"],
133
192
  async run(t) {
134
- const settings = throughSettings(t);
193
+ // With both off, ui.observe is refused by design (wire.md): there is no shape to read, so the case skips in the
194
+ // words hello gives for each.
195
+ const imageOff = featureOff(t.hello.features ?? {}, "ui.image");
196
+ const bothOff = treeOff(t);
197
+ if (bothOff !== undefined && imageOff !== undefined)
198
+ return t.skip(`ui.observe has nothing to show on this computer: ${bothOff}, and ${imageOff}`);
199
+ // What to observe: the ui fixture where the computer has it installed (it needs no exec, files or processes,
200
+ // which a ui driver need not offer); else Settings on a phone with no fixture file; else the input fixture.
201
+ const listed = t.hello.groups.includes("apps") ? await t.call("apps.list", {}) : undefined;
202
+ const uiFixture = listed?.apps.some((app) => app.id === UI_FIXTURE.id) === true;
203
+ const settings = !uiFixture && throughSettings(t);
135
204
  if (settings)
136
205
  await openSettings(t);
206
+ else if (uiFixture) {
207
+ t.deepEqual(await t.call("apps.launch", { id: UI_FIXTURE.id }), {}, `apps.launch ${UI_FIXTURE.id}`);
208
+ await t.until(async () => (await t.call("apps.list", {})).foreground === UI_FIXTURE.id, `${UI_FIXTURE.id} in front after apps.launch`);
209
+ }
137
210
  else
138
211
  await t.fixture();
139
- const screen = t.provider.capabilities().groups.includes("screen") ? await t.call("screen.shot", {}) : undefined;
140
- const rect = screen ? [0, 0, screen.width, screen.height] : undefined;
141
- const tree = await t.call("apps.ui_tree", {});
142
- const seen = { nodes: 0 };
143
- const wrong = shapeOf(tree.root, "root", rect, seen);
144
- t.assert(wrong === undefined, `apps.ui_tree: ${wrong}`);
145
- t.equal(tree.nodes, seen.nodes, "apps.ui_tree's nodes, against the nodes in its tree");
146
- t.equal(typeof tree.truncated, "boolean", "apps.ui_tree's truncated is a boolean");
147
- if (settings) {
148
- t.assert(rowsOf(tree).length > 0, "Settings' list, with its rows, in apps.ui_tree");
212
+ const off = treeOff(t);
213
+ if (off !== undefined) {
214
+ // With ui.tree off the observation is image-only: no nodes, the reason in empty, and the window's image.
215
+ const seen = await observe(t);
216
+ const wrong = observeWrong(seen);
217
+ t.assert(wrong === undefined, `ui.observe: ${wrong}`);
218
+ t.deepEqual(seen.nodes, [], "with ui.tree off, ui.observe gives no nodes");
219
+ const why = (t.hello.features?.["ui.tree"]).off;
220
+ t.assert(typeof seen.empty === "string" && seen.empty.includes(why), `empty says why with ui.tree's declared sentence "${why}": ${show(seen.empty)}`);
221
+ const image = t.present(seen.image, "with ui.tree off, ui.observe gives the window's image unasked");
222
+ t.assert(image.width > 0 && image.height > 0 && typeof image.data === "string" && image.data !== "", `the image is ${show({ ...image, data: `${image.data?.length} chars` })}, not one with pixels`);
149
223
  return;
150
224
  }
151
- const button = t.present(seen.button, `the fixture's button, by its id ${FIXTURE_BUTTON.id}, in apps.ui_tree`);
152
- t.equal(button.text, FIXTURE_BUTTON.text, "the fixture's button's text");
225
+ // Settings comes up, or the fixture's button, before the shape is read: a phone draws its window after the launch.
226
+ const waitedFor = settings ? "Settings' list, with its rows, in ui.observe" : uiFixture ? `the ui fixture's Next button, by its id, in ui.observe` : `the fixture's button, by its id ${FIXTURE_BUTTON.id}, in ui.observe`;
227
+ const seen = await t.until(async () => {
228
+ const one = await observe(t);
229
+ const ready = settings ? rowsOf(one).length > 0 : one.nodes.some((node) => node.id === (uiFixture ? "next" : FIXTURE_BUTTON.id));
230
+ return ready || observeWrong(one) !== undefined ? one : undefined;
231
+ }, waitedFor);
232
+ const wrong = observeWrong(seen);
233
+ t.assert(wrong === undefined, `ui.observe: ${wrong}`);
234
+ if (settings)
235
+ return;
236
+ if (uiFixture)
237
+ return t.equal(seen.app.id, UI_FIXTURE.id, "the observed app");
238
+ const button = t.present(seen.nodes.find((node) => node.id === FIXTURE_BUTTON.id), `the fixture's button, by its id ${FIXTURE_BUTTON.id}, in ui.observe`);
239
+ t.equal(button.name, FIXTURE_BUTTON.text, "the fixture's button's name");
153
240
  },
154
241
  },
155
242
  ];
@@ -2,6 +2,7 @@
2
2
  // says it is; what the provider declares of itself, its capabilities() and each hello agree, at this protocol's
3
3
  // version; and no error the provider answers holds a key.
4
4
  import { GROUPS, PROTOCOL_VERSION } from "../../protocol.js";
5
+ import { kindServed } from "../../kinds.js";
5
6
  import { kindRefusals } from "../../provider.js";
6
7
  import { coreGroups } from "../types.js";
7
8
  export const healthCases = [
@@ -69,6 +70,19 @@ export const healthCases = [
69
70
  }
70
71
  },
71
72
  },
73
+ {
74
+ // A computer is handed to an agent by the setting kind its machine kind belongs to. A desktop whose hello lists no
75
+ // input.pointer passes every case it declares, and is refused the first time an agent is given it; this fails it
76
+ // here instead, by the groups it lacks.
77
+ id: "health.kind-served",
78
+ level: "core",
79
+ group: "health",
80
+ needs: [],
81
+ async run(t) {
82
+ const missing = kindServed(t.hello);
83
+ t.deepEqual(missing, [], `the groups a ${t.hello.os} ${t.hello.kind} must declare in hello to be given to an agent, which it lacks`);
84
+ },
85
+ },
72
86
  {
73
87
  // The provider says what it is three times: in what it declares of itself (its descriptor), in capabilities(), and
74
88
  // in each computer's hello. A runner trusts the first to pick a provider, the second to call it, and the third to
@@ -13,6 +13,7 @@ import { processCases } from "./process.js";
13
13
  import { providerCases } from "./provider.js";
14
14
  import { screenCases } from "./screen.js";
15
15
  import { touchCases } from "./touch.js";
16
+ import { uiCases } from "./ui.js";
16
17
  export { browserCases, browserOnlyCases } from "./browser.js";
17
18
  export const conformanceCases = [
18
19
  ...healthCases,
@@ -27,6 +28,7 @@ export const conformanceCases = [
27
28
  ...inputCases,
28
29
  ...touchCases,
29
30
  ...appsCases,
31
+ ...uiCases,
30
32
  ...lifetimeCases,
31
33
  ...gpuCases,
32
34
  ];
@@ -2,10 +2,11 @@
2
2
  // what they say, the network reads back as asked, a change to a network the provider does not declare is refused
3
3
  // (Core) and one it does declare is refused or applied truthfully (Full), a computer does not run past its deadline,
4
4
  // the janitor ends only the expired, stopped or running, and a takeover releases the run's lower epochs by label (Full).
5
+ // A create retried with its request id answers the computer the first made, and after release is refused (Full).
5
6
  import { randomBytes } from "node:crypto";
6
7
  import { releaseOlder, sweep } from "../../janitor.js";
7
8
  import { EPOCH_LABEL, OWNER_LABEL, RUN_LABEL, runLabels } from "../../labels.js";
8
- import { runLifetimeMs } from "../../provider.js";
9
+ import { computerNameFor, runLifetimeMs } from "../../provider.js";
9
10
  import { b64, CASE_LABEL, decode } from "./util.js";
10
11
  /** Labels for one case's computers: the run's, and the case's own. */
11
12
  const own = (t, name) => ({ ...t.runLabels, [CASE_LABEL]: name });
@@ -146,6 +147,31 @@ export const providerCases = [
146
147
  t.deepEqual(await names(t, labels), [], "listed after delete");
147
148
  t.refused(await t.provider.connect(ref), "connect to a deleted computer", ["gone", "not_found"]);
148
149
  }),
150
+ provider("create-retried", async (t) => {
151
+ // A retry of one request, at once and after it is up, answers the computer the first made: never a second.
152
+ const labels = own(t, "retried");
153
+ const spec = t.spec({ labels });
154
+ const requestId = `conformance-retried-${randomBytes(6).toString("hex")}`;
155
+ const [first, early] = await Promise.all([t.attempt(spec, t.provider, requestId), t.attempt(spec, t.provider, requestId)]);
156
+ const made = t.ok(first, "create");
157
+ t.deepEqual(refOf(t.ok(early, "the same create again while the first starts")), refOf(made), "the computer a create retried while it starts answers");
158
+ t.deepEqual(refOf(t.ok(await t.attempt(spec, t.provider, requestId), "the same create again once it is up")), refOf(made), "the computer a create retried once it is up answers");
159
+ t.equal(made.name, computerNameFor(requestId), "the computer's name, computer-<12 hex of sha256(request id)>");
160
+ t.deepEqual(await names(t, labels), [made.name], "the computers three creates of one request made");
161
+ const other = t.refused(await t.attempt(t.spec({ labels: { ...labels, role: "other" } }), t.provider, requestId), "the same request id with other labels", ["exists"]);
162
+ t.assert(other.message.includes(made.name), `the refusal names the request's computer ${made.name}: ${other.message}`);
163
+ }, { level: "full" }),
164
+ provider("create-after-release", async (t) => {
165
+ // A request whose computer has ended is spent: the same id again is refused exists, in words, and makes nothing.
166
+ const labels = own(t, "after-release");
167
+ const spec = t.spec({ labels });
168
+ const requestId = `conformance-after-release-${randomBytes(6).toString("hex")}`;
169
+ const made = t.ok(await t.attempt(spec, t.provider, requestId), "create");
170
+ t.ok(await t.provider.release(made, "delete"), "release delete");
171
+ const again = t.refused(await t.attempt(spec, t.provider, requestId), "the same request id after its computer was released", ["exists"]);
172
+ t.match(again.message, /was made for this request and has ended: create with a new request id/, "the refusal says what to do");
173
+ t.deepEqual(await names(t, labels), [], "the computers the refused create made");
174
+ }, { level: "full" }),
149
175
  provider("attach", async (t) => {
150
176
  const labels = own(t, "attach");
151
177
  const spec = t.spec({ labels: { ...labels, role: "a" } });
@@ -6,4 +6,7 @@ export declare function shoot(t: CaseContext, region?: Rect): Promise<{
6
6
  shot: ScreenShotResult;
7
7
  image: Png;
8
8
  }>;
9
+ /** Why this computer's screen is not captured, as hello's screen.capture says it off (an attached Mac whose owner has
10
+ * not granted the screen); undefined when it is on, or not declared, which a computer of the screen group means as on. */
11
+ export declare function captureOff(t: CaseContext): string | undefined;
9
12
  export declare const screenCases: Case[];
@@ -38,6 +38,18 @@ export async function shoot(t, region) {
38
38
  }
39
39
  return { shot, image };
40
40
  }
41
+ /** Why this computer's screen is not captured, as hello's screen.capture says it off (an attached Mac whose owner has
42
+ * not granted the screen); undefined when it is on, or not declared, which a computer of the screen group means as on. */
43
+ export function captureOff(t) {
44
+ const value = t.hello.features?.["screen.capture"];
45
+ return typeof value === "object" ? value.off : undefined;
46
+ }
47
+ /** With screen.capture off, `method` is refused `denied` with its reason, never ignored nor answered. */
48
+ async function refusedOff(t, off, method) {
49
+ const result = method === "screen.shot" ? await t.client.call("screen.shot", {}) : await t.client.call("screen.watch", { after: 0, waitMs: 0 });
50
+ const error = t.refused(result, `${method} with screen.capture off`, ["denied"]);
51
+ t.assert(error.message.includes(off), `${method}'s refusal says hello's screen.capture reason (${JSON.stringify(off)}): ${JSON.stringify(error.message)}`);
52
+ }
41
53
  const QUADRANTS = ["top left", "top right", "bottom left", "bottom right"];
42
54
  export const screenCases = [
43
55
  {
@@ -46,6 +58,9 @@ export const screenCases = [
46
58
  group: "screen",
47
59
  needs: ["screen"],
48
60
  async run(t) {
61
+ const off = captureOff(t);
62
+ if (off !== undefined)
63
+ return refusedOff(t, off, "screen.shot");
49
64
  const { shot, image } = await shoot(t);
50
65
  t.assert(shot.width > 0 && shot.height > 0, `the shot is ${shot.width}x${shot.height}`);
51
66
  t.deepEqual([image.width, image.height], [shot.width, shot.height], "the PNG's size (IHDR), against the shot's width and height");
@@ -72,6 +87,9 @@ export const screenCases = [
72
87
  group: "screen",
73
88
  needs: ["screen"],
74
89
  async run(t) {
90
+ const off = captureOff(t);
91
+ if (off !== undefined)
92
+ return refusedOff(t, off, "screen.watch");
75
93
  const { shot } = await shoot(t);
76
94
  const watcher = t.provider.watch;
77
95
  t.assert(watcher !== undefined, "the provider has no watch(): a computer with a screen gives its live view through it");
@@ -1,56 +1,62 @@
1
- import type { ComputerKind, Point, Rect, UiNode, UiTreeResult } from "../../protocol.js";
1
+ import type { ComputerKind, Point, Rect, UiNode, UiObserveResult } from "../../protocol.js";
2
2
  import type { CaseContext } from "../types.js";
3
3
  /** The stock Settings app of each phone kind this suite knows. */
4
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. */
5
+ /** Whether the case checks what it did through Settings: a phone with apps and the ui group that takes no fixture file. */
6
6
  export declare function throughSettings(t: CaseContext): boolean;
7
7
  /** The kind's Settings app, or the case skips in words. */
8
8
  export declare function settingsApp(t: CaseContext): string;
9
+ /** The app in front's window, as ui.observe sees it. */
10
+ export declare const observe: (t: CaseContext) => Promise<UiObserveResult>;
9
11
  /** Settings, fresh and in front: ended, launched, and waited for until it is the app in front. */
10
12
  export declare function openSettings(t: CaseContext): Promise<string>;
13
+ /** A point of a ui observation (window points) as input.actions aims it: screenshot pixels. */
14
+ export declare function pixelsOf(t: CaseContext, seen: UiObserveResult, [x, y]: Point): Promise<Point>;
11
15
  /**
12
16
  * 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.
17
+ * two panes from 600 dp wide), what is in front, the tap point (px) and the row's bounds (points), whether the row's
18
+ * title shows outside the list (a page opened beside it), and whether the next row is still shown. A part that cannot
19
+ * be read says so; none of it throws.
16
20
  */
17
- export declare function tapScene(t: CaseContext, { at, row, next, tree }: {
21
+ export declare function tapScene(t: CaseContext, { at, row, next, seen }: {
18
22
  at: Point;
19
23
  row: Row;
20
24
  next: Row;
21
- tree: UiTreeResult | undefined;
25
+ seen: UiObserveResult | undefined;
22
26
  }): Promise<string>;
23
- /** Every node of a tree, depth first. */
24
- export declare function nodesOf(root: UiNode): UiNode[];
27
+ /** A node and every node below it, in the observation's order: a node comes after its parent. */
28
+ export declare function under(seen: UiObserveResult, top: UiNode): UiNode[];
25
29
  /**
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.
30
+ * Whether an observation shows a name anywhere. A live Android 15 Settings page shows its title only as its collapsing
31
+ * toolbar's content-desc (phone probe 3), with no text node holding it; a driver gives either as the node's name.
28
32
  */
29
- export declare const showsName: (tree: UiTreeResult, name: string) => boolean;
30
- /** The texts a tree shows. */
31
- export declare const textsOf: (tree: UiTreeResult) => string[];
33
+ export declare const showsName: (seen: UiObserveResult, name: string) => boolean;
34
+ /** The names and values an observation shows, in order. */
35
+ export declare const namesOf: (seen: UiObserveResult) => string[];
32
36
  export interface Row {
33
37
  text: string;
38
+ /** In window points. */
34
39
  bounds: Rect;
35
40
  }
36
- /** The middle of a rect, in whole pixels. */
41
+ /** The middle of a rect, in whole units. */
37
42
  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;
43
+ /** The scrollable list an observation shows, the first one: a scrollarea, or a node that scrolls. */
44
+ export declare function listOf(seen: UiObserveResult): UiNode | undefined;
40
45
  /**
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.
46
+ * The rows of an observation's list: each clickable node in it, whole inside it, with the first text it holds (its own
47
+ * when it is a text, else a text node's under it). Settings' search entry is not a row, though a live Settings shows it
48
+ * as the list's first item.
43
49
  */
44
- export declare function rowsOf(tree: UiTreeResult): Row[];
50
+ export declare function rowsOf(seen: UiObserveResult): Row[];
45
51
  /** Settings' top list, with at least `count` rows of different titles on screen, or the case fails in words. */
46
52
  export declare function settingsRows(t: CaseContext, count: number): Promise<{
47
- tree: UiTreeResult;
53
+ seen: UiObserveResult;
48
54
  rows: Row[];
49
55
  }>;
50
56
  /**
51
57
  * 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.
58
+ * search, by its own name, value or id or a node's under it; a live Settings shows it inside the list, its text on a
59
+ * child) and waits for the field. An empty field may show its hint as its text, so only the field is waited for.
54
60
  */
55
61
  export declare function openSearch(t: CaseContext): Promise<void>;
56
62
  /** The text in Settings' search field now, or undefined when no field is shown. */