create-expo-updates-server 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +4 -2
  2. package/dist/template/Dockerfile +4 -6
  3. package/dist/template/README.md +4 -9
  4. package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
  5. package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
  6. package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
  7. package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
  8. package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
  9. package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
  10. package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
  11. package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
  12. package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
  13. package/dist/template/app/api/admin/updates/route.test.ts +21 -0
  14. package/dist/template/app/api/admin/updates/route.ts +12 -1
  15. package/dist/template/app/globals.css +65 -68
  16. package/dist/template/app/login/page.tsx +66 -42
  17. package/dist/template/app/updates/[encodedKey]/page.tsx +375 -263
  18. package/dist/template/app/updates/devices/page.tsx +188 -152
  19. package/dist/template/app/updates/embedded/page.tsx +63 -29
  20. package/dist/template/app/updates/emergency-redirects/page.tsx +93 -58
  21. package/dist/template/app/updates/layout.tsx +2 -1
  22. package/dist/template/app/updates/page.tsx +381 -283
  23. package/dist/template/app/updates/releases.test.tsx +156 -0
  24. package/dist/template/components/admin/admin-role.ts +5 -0
  25. package/dist/template/components/admin/admin-shell.tsx +166 -101
  26. package/dist/template/components/admin/confirm-action.tsx +123 -0
  27. package/dist/template/components/admin/language-switcher.tsx +25 -17
  28. package/dist/template/components/admin/release-badges.test.tsx +50 -0
  29. package/dist/template/components/admin/release-badges.tsx +101 -0
  30. package/dist/template/components/ui/alert.tsx +10 -3
  31. package/dist/template/components/ui/avatar.tsx +108 -0
  32. package/dist/template/components/ui/badge.tsx +2 -2
  33. package/dist/template/components/ui/breadcrumb.tsx +108 -0
  34. package/dist/template/components/ui/button.tsx +5 -5
  35. package/dist/template/components/ui/card.tsx +2 -2
  36. package/dist/template/components/ui/chart.tsx +1 -1
  37. package/dist/template/components/ui/collapsible.tsx +7 -0
  38. package/dist/template/components/ui/empty.tsx +103 -0
  39. package/dist/template/components/ui/field.tsx +248 -0
  40. package/dist/template/components/ui/input-group.tsx +170 -0
  41. package/dist/template/components/ui/input.tsx +1 -1
  42. package/dist/template/components/ui/native-select.tsx +1 -1
  43. package/dist/template/components/ui/radio-group.tsx +41 -0
  44. package/dist/template/components/ui/status-tones.ts +15 -0
  45. package/dist/template/components/ui/table.tsx +1 -1
  46. package/dist/template/components/ui/textarea.tsx +1 -1
  47. package/dist/template/docs/admin-ui.md +7 -3
  48. package/dist/template/docs/device-targeting.md +2 -7
  49. package/dist/template/docs/doctor.md +2 -2
  50. package/dist/template/docs/expo-app-setup.md +9 -27
  51. package/dist/template/docs/getting-started.md +3 -4
  52. package/dist/template/docs/installation-telemetry.md +2 -8
  53. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
  54. package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
  55. package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
  56. package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
  57. package/dist/template/docs/migrations/schema.sql +349 -0
  58. package/dist/template/docs/npm-installer.md +3 -3
  59. package/dist/template/docs/operations-guide.md +8 -6
  60. package/dist/template/docs/ota-client-lifecycle.md +30 -68
  61. package/dist/template/docs/ota-update-policy.md +9 -20
  62. package/dist/template/docs/ru/admin-ui.md +7 -3
  63. package/dist/template/docs/ru/device-targeting.md +2 -2
  64. package/dist/template/docs/ru/doctor.md +2 -2
  65. package/dist/template/docs/ru/expo-app-setup.md +9 -9
  66. package/dist/template/docs/ru/getting-started.md +3 -3
  67. package/dist/template/docs/ru/installation-telemetry.md +2 -2
  68. package/dist/template/docs/ru/npm-installer.md +3 -3
  69. package/dist/template/docs/ru/operations-guide.md +8 -3
  70. package/dist/template/docs/ru/ota-client-lifecycle.md +30 -35
  71. package/dist/template/docs/ru/ota-update-policy.md +9 -7
  72. package/dist/template/docs/ru/publishing-npm-installer.md +2 -2
  73. package/dist/template/docs/uk/admin-ui.md +7 -3
  74. package/dist/template/docs/uk/device-targeting.md +2 -2
  75. package/dist/template/docs/uk/doctor.md +2 -2
  76. package/dist/template/docs/uk/expo-app-setup.md +9 -9
  77. package/dist/template/docs/uk/getting-started.md +3 -3
  78. package/dist/template/docs/uk/installation-telemetry.md +2 -2
  79. package/dist/template/docs/uk/npm-installer.md +3 -3
  80. package/dist/template/docs/uk/operations-guide.md +8 -3
  81. package/dist/template/docs/uk/ota-client-lifecycle.md +30 -35
  82. package/dist/template/docs/uk/ota-update-policy.md +9 -7
  83. package/dist/template/docs/uk/publishing-npm-installer.md +2 -2
  84. package/dist/template/lib/audience-ids.ts +4 -0
  85. package/dist/template/package-lock.json +46 -0
  86. package/dist/template/package.json +3 -1
  87. package/dist/template/scripts/configure-expo-app.mjs +3 -3
  88. package/dist/template/scripts/create-access-token.mjs +1 -1
  89. package/dist/template/scripts/lib/doctor.mjs +10 -7
  90. package/dist/template/scripts/lib/doctor.test.mjs +7 -5
  91. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
  92. package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
  93. package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
  94. package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
  95. package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
  96. package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
  97. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
  98. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
  99. package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
  100. package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
  101. package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
  102. package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
  103. package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
  104. package/dist/template/scripts/tests/e2e/console.mjs +86 -0
  105. package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
  106. package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
  107. package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
  108. package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
  109. package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
  110. package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
  111. package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
  112. package/dist/template/scripts/tests/e2e/run.mjs +224 -0
  113. package/dist/template/scripts/tests/manifest-identity.sql +7 -5
  114. package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
  115. package/dist/template/src/client/admin-api.ts +45 -10
  116. package/dist/template/src/client/admin-types.ts +35 -1
  117. package/dist/template/src/client/devices/analytics.tsx +168 -231
  118. package/dist/template/src/client/devices/cohorts.tsx +181 -0
  119. package/dist/template/src/client/devices/device-name.tsx +37 -23
  120. package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
  121. package/dist/template/src/client/devices/registry.tsx +258 -245
  122. package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
  123. package/dist/template/src/client/devices/use-devices-report.ts +53 -82
  124. package/dist/template/src/client/devices/version-adoption-chart.tsx +47 -49
  125. package/dist/template/src/client/distribution-control.tsx +89 -57
  126. package/dist/template/src/client/distribution-history.tsx +353 -0
  127. package/dist/template/src/client/guard-action-catalog.tsx +183 -0
  128. package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
  129. package/dist/template/src/client/guard-action-combobox.tsx +133 -239
  130. package/dist/template/src/client/guard-action-options.ts +4 -6
  131. package/dist/template/src/client/i18n/en.json +133 -2
  132. package/dist/template/src/client/i18n/language-switching.test.tsx +12 -3
  133. package/dist/template/src/client/i18n/ru.json +133 -2
  134. package/dist/template/src/client/i18n/uk.json +133 -2
  135. package/dist/template/src/client/logout-button.tsx +3 -3
  136. package/dist/template/src/client/policy-draft.ts +138 -0
  137. package/dist/template/src/client/update-audience-editor.tsx +597 -206
  138. package/dist/template/src/client/update-policy-editor.test.ts +101 -29
  139. package/dist/template/src/client/update-policy-editor.tsx +454 -320
  140. package/dist/template/src/client/use-filtered-results.ts +55 -0
  141. package/dist/template/src/server/controllers/manifest.test.ts +23 -3
  142. package/dist/template/src/server/controllers/manifest.ts +15 -1
  143. package/dist/template/src/server/devices/audience.ts +9 -5
  144. package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
  145. package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
  146. package/dist/template/src/server/lib/admin-updates.ts +160 -534
  147. package/dist/template/src/server/lib/distribution-history.ts +97 -0
  148. package/dist/template/src/server/lib/supabase.js +24 -0
  149. package/dist/template/src/server/lib/supabase.test.ts +38 -1
  150. package/dist/template/src/server/lib/update-policy.test.ts +20 -0
  151. package/dist/template/src/server/lib/update-policy.ts +23 -10
  152. package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
  153. package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
  154. package/dist/template/src/server/manifest/manifest-values.ts +21 -13
  155. package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
  156. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
  157. package/dist/template/tsconfig.json +2 -2
  158. package/dist/template-manifest.json +446 -301
  159. package/package.json +1 -1
  160. package/dist/template/scripts/lib/device-identity.test.ts +0 -29
  161. package/dist/template/scripts/lib/ota-client.test.ts +0 -55
  162. package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
  163. package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
  164. package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
  165. package/dist/template/templates/expo-app/ota-client/README.md +0 -73
  166. package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
  167. package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
  168. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
  169. package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
  170. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
  171. package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
  172. package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
  173. package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
  174. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
  175. package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
@@ -0,0 +1,296 @@
1
+ import { exerciseReleaseMatrix } from "./release-matrix.mjs";
2
+ import assert from "node:assert/strict";
3
+ import { createHash, randomUUID, verify } from "node:crypto";
4
+ import { PutObjectCommand } from "@aws-sdk/client-s3";
5
+
6
+ const runtime = "1.0.0";
7
+ const channel = "production";
8
+ export async function seedPublication(
9
+ db,
10
+ storage,
11
+ comment,
12
+ active = false,
13
+ platform = "ios",
14
+ scope = {},
15
+ ) {
16
+ const runtime = scope.runtime ?? "1.0.0";
17
+ const channel = scope.channel ?? "production";
18
+ const id = randomUUID();
19
+ const prefix = runtime + "/" + platform + "/" + id;
20
+ const bundle = Buffer.from(
21
+ "globalThis.otaBuild = " + JSON.stringify(comment) + ";",
22
+ );
23
+ const image = Buffer.from([137, 80, 78, 71]);
24
+ const assets = [];
25
+ for (const [key, bytes, contentType, fileExtension] of [
26
+ ["bundle.js", bundle, "application/javascript", ".js"],
27
+ ["icon.png", image, "image/png", ".png"],
28
+ ]) {
29
+ await storage.send(
30
+ new PutObjectCommand({
31
+ Bucket: "ota-fixtures",
32
+ Key: prefix + "/" + key,
33
+ Body: bytes,
34
+ }),
35
+ );
36
+ assets.push({
37
+ key,
38
+ path: key,
39
+ hash: createHash("sha256").update(bytes).digest("base64url"),
40
+ contentType,
41
+ fileExtension,
42
+ });
43
+ }
44
+ await db.query(
45
+ `insert into ota_updates(update_id,build_id,runtime_version,channel,platform,created_at,
46
+ created_at_path,storage_bucket,storage_base_path,manifest,assets_count,launch_asset_path,comment)
47
+ values($1::uuid,$1::uuid,$2,$3,$4,clock_timestamp(),$1::uuid::text,'ota-fixtures',$5,$6,1,'bundle.js',$7)`,
48
+ [
49
+ id,
50
+ runtime,
51
+ channel,
52
+ platform,
53
+ prefix,
54
+ {
55
+ runtimeVersion: runtime,
56
+ launchAsset: assets[0],
57
+ assets: [assets[1]],
58
+ extra: { expoClient: { name: comment, version: "1.0" } },
59
+ },
60
+ comment,
61
+ ],
62
+ );
63
+ await db.query(
64
+ `insert into ota_update_channels(runtime_version,channel,platform)
65
+ values($1,$2,$3) on conflict(runtime_version,channel,platform) do nothing`,
66
+ [runtime, channel, platform],
67
+ );
68
+ if (active) await db.query("select * from ota_change_distribution($1,'activate')", [id]);
69
+ return {
70
+ id,
71
+ path: "/api/admin/updates/" + Buffer.from(id).toString("base64url"),
72
+ bundle,
73
+ image,
74
+ comment,
75
+ };
76
+ }
77
+
78
+ export async function exerciseDelivery({
79
+ origin,
80
+ db,
81
+ storage,
82
+ password,
83
+ publicKey,
84
+ old,
85
+ }) {
86
+ const response = await fetch(origin + "/api/admin/login", {
87
+ method: "POST",
88
+ headers: { "content-type": "application/json" },
89
+ body: JSON.stringify({ username: "admin", password }),
90
+ });
91
+ assert.equal(response.status, 200, await response.text());
92
+ const cookie = response.headers.get("set-cookie").split(";")[0];
93
+ async function request(path, method = "GET", body, status = 200) {
94
+ const res = await fetch(origin + path, {
95
+ method,
96
+ headers: { cookie, "content-type": "application/json" },
97
+ body: JSON.stringify(body),
98
+ });
99
+ const result = await res.json();
100
+ assert.equal(
101
+ res.status,
102
+ status,
103
+ method + " " + path + " " + JSON.stringify(result),
104
+ );
105
+ return result;
106
+ }
107
+ async function manifest(extra = {}) {
108
+ const res = await fetch(origin + "/api/manifest", {
109
+ headers: {
110
+ "expo-platform": "ios",
111
+ "expo-channel-name": channel,
112
+ "expo-runtime-version": runtime,
113
+ "expo-protocol-version": "1",
114
+ "expo-expect-signature": "sig, keyid=main",
115
+ ...extra,
116
+ },
117
+ });
118
+ const raw = await res.text();
119
+ assert.equal(res.status, 200, raw);
120
+ const boundary = res.headers
121
+ .get("content-type")
122
+ .match(/boundary="?([^";]+)/)[1];
123
+ const part = raw
124
+ .split("--" + boundary)
125
+ .find((value) => /name="(?:manifest|directive)"/i.test(value));
126
+ assert.ok(part, raw);
127
+ const [headers, body] = part.trim().split("\r\n\r\n");
128
+ const signature = headers.match(/expo-signature: sig="([^"]+)"/i)?.[1];
129
+ assert.ok(
130
+ signature &&
131
+ verify(
132
+ "RSA-SHA256",
133
+ Buffer.from(body),
134
+ publicKey,
135
+ Buffer.from(signature, "base64"),
136
+ ),
137
+ "signature matches exact payload",
138
+ );
139
+ return JSON.parse(body);
140
+ }
141
+ async function expectArtifact(value, release) {
142
+ assert.equal(value.extra.expoClient.name, release.comment);
143
+ for (const asset of [value.launchAsset, ...value.assets]) {
144
+ const res = await fetch(asset.url);
145
+ assert.equal(res.status, 200);
146
+ const bytes = Buffer.from(await res.arrayBuffer());
147
+ assert.deepEqual(
148
+ bytes,
149
+ asset === value.launchAsset ? release.bundle : release.image,
150
+ );
151
+ assert.equal(
152
+ createHash("sha256").update(bytes).digest("base64url"),
153
+ asset.hash,
154
+ );
155
+ }
156
+ }
157
+ async function noUpdate(headers) {
158
+ assert.equal((await manifest(headers)).type, "noUpdateAvailable");
159
+ }
160
+ await expectArtifact(await manifest(), old);
161
+ const legacyManifest = await manifest();
162
+ await noUpdate({ "expo-current-update-id": legacyManifest.id });
163
+ for (const headers of [
164
+ { "expo-platform": "android" },
165
+ { "expo-runtime-version": "other" },
166
+ { "expo-channel-name": "beta" },
167
+ ])
168
+ await noUpdate(headers);
169
+ const android = await seedPublication(
170
+ db,
171
+ storage,
172
+ "Android release",
173
+ true,
174
+ "android",
175
+ );
176
+ await expectArtifact(await manifest({ "expo-platform": "android" }), android);
177
+
178
+ const draft = await seedPublication(db, storage, "Candidate release");
179
+ await expectArtifact(await manifest(), old);
180
+ const guard = {
181
+ action: "ota-force-store-update",
182
+ payload: { message: "Upgrade" },
183
+ };
184
+ await request(draft.path + "/policy", "PUT", {
185
+ expectedPolicyVersion: 1,
186
+ delivery: "background",
187
+ guard,
188
+ });
189
+ const installation = randomUUID();
190
+ const audience = {
191
+ audience_mode: "devices",
192
+ audience_device_ids: ["a".repeat(64)],
193
+ audience_installation_ids: [installation],
194
+ audience_version: 1,
195
+ };
196
+ await request(draft.path + "/audience", "PUT", audience);
197
+ await request(draft.path + "/audience", "PUT", audience, 409);
198
+ await request(draft.path + "/deactivate", "POST", { disabled: false });
199
+ await request(
200
+ draft.path + "/policy",
201
+ "PUT",
202
+ { expectedPolicyVersion: 2, delivery: "manual", guard: null },
203
+ 409,
204
+ );
205
+ for (const extra of [
206
+ 'device_id="' + "a".repeat(64) + '"',
207
+ 'installation_id="' + installation + '"',
208
+ ]) {
209
+ const targeted = await manifest({ "expo-extra-params": extra });
210
+ await expectArtifact(targeted, draft);
211
+ assert.deepEqual(targeted.extra.updatePolicy.guard, guard);
212
+ assert.equal(targeted.extra.updatePolicy.delivery, "background");
213
+ }
214
+ await expectArtifact(await manifest(), old);
215
+ await request(draft.path + "/audience", "PUT", {
216
+ ...audience,
217
+ audience_mode: "all",
218
+ audience_installation_ids: [],
219
+ audience_device_ids: [],
220
+ audience_version: 2,
221
+ });
222
+ const wide = await manifest();
223
+ await expectArtifact(wide, draft);
224
+ const controlPath = "/api/admin/distribution-control";
225
+ const initial = await request(controlPath);
226
+ const paused = await request(controlPath, "PUT", {
227
+ blocked: true,
228
+ reason: "E2E rehearsal",
229
+ expectedVersion: initial.version,
230
+ });
231
+ await noUpdate({});
232
+ assert.equal((await fetch(wide.launchAsset.url)).status, 503);
233
+ await request(controlPath, "PUT", {
234
+ blocked: false,
235
+ expectedVersion: paused.version,
236
+ });
237
+ await expectArtifact(await manifest(), draft);
238
+ await request(old.path + "/rollback", "POST", {});
239
+ await expectArtifact(
240
+ await manifest({ "expo-current-update-id": wide.id }),
241
+ old,
242
+ );
243
+ await request(draft.path + "/promote", "POST", {});
244
+ await expectArtifact(await manifest(), draft);
245
+ const embedded = randomUUID();
246
+ await request(
247
+ "/api/admin/embedded-updates",
248
+ "POST",
249
+ {
250
+ embeddedUpdateId: embedded,
251
+ appVersion: "1.0",
252
+ channel: "beta",
253
+ platform: "ios",
254
+ createdAt: "2025-01-01T00:00:00Z",
255
+ },
256
+ 201,
257
+ );
258
+ const rule = await request(
259
+ "/api/admin/emergency-redirects",
260
+ "POST",
261
+ {
262
+ name: "Beta recovery",
263
+ enabled: true,
264
+ embeddedUpdateId: embedded,
265
+ runtimeVersion: runtime,
266
+ platform: "ios",
267
+ fromChannel: "beta",
268
+ toChannel: channel,
269
+ targetMode: "pinned",
270
+ expectedUpdateId: draft.id,
271
+ },
272
+ 201,
273
+ );
274
+ const source = {
275
+ "expo-channel-name": "beta",
276
+ "expo-embedded-update-id": embedded,
277
+ };
278
+ await expectArtifact(await manifest(source), draft);
279
+ await noUpdate({ ...source, "expo-embedded-update-id": randomUUID() });
280
+ await request("/api/admin/emergency-redirects/" + rule.id, "PATCH", {
281
+ enabled: false,
282
+ });
283
+ await noUpdate(source);
284
+ await request("/api/admin/emergency-redirects/" + rule.id, "PATCH", {
285
+ enabled: true,
286
+ targetMode: "follow",
287
+ expectedUpdateId: null,
288
+ });
289
+ await expectArtifact(await manifest(source), draft);
290
+ await request("/api/admin/emergency-redirects/" + rule.id, "DELETE");
291
+ await noUpdate(source);
292
+ await exerciseReleaseMatrix({ db, storage, request, manifest });
293
+ console.log(
294
+ "PASS signed manifests, signed directives, asset bytes, platform/runtime/channel, targeting, Guard, stale edits, widening, stop/resume, rollback/promote, emergency recovery",
295
+ );
296
+ }
@@ -0,0 +1,309 @@
1
+ import { randomBytes, randomUUID } from "node:crypto";
2
+ import { expect as playwrightExpect } from "@playwright/test";
3
+ import { seedPublication } from "./delivery.mjs";
4
+
5
+ const expect = playwrightExpect.configure({ timeout: 30_000 });
6
+
7
+ export async function exerciseDeviceFavorites(
8
+ page,
9
+ { origin, db, storage, password },
10
+ ) {
11
+ const runtime = "favorites-e2e";
12
+ const platform = "android";
13
+ const installationId = randomUUID();
14
+ const deviceId = randomBytes(32).toString("hex");
15
+ const draft = await seedPublication(
16
+ db,
17
+ storage,
18
+ "Favorite smoke draft",
19
+ false,
20
+ platform,
21
+ { runtime, channel: "favorites" },
22
+ );
23
+ const path = draft.path.replace("/api/admin", "");
24
+ const api = origin + "/api/admin/device-favorites";
25
+ const listUrl = api + "?platform=android";
26
+ const audience = origin + draft.path + "/audience";
27
+ const target = { platform, target_kind: "device", target_id: deviceId };
28
+ const heartbeat = await page.request.post(origin + "/api/device-heartbeat", {
29
+ data: {
30
+ platform,
31
+ installationId,
32
+ deviceId,
33
+ sequence: 1,
34
+ eventId: randomUUID(),
35
+ observedAt: new Date().toISOString(),
36
+ channel: "favorites",
37
+ runtimeVersion: runtime,
38
+ updateId: null,
39
+ nativeVersion: "1.0",
40
+ nativeBuild: "1",
41
+ isEmbeddedLaunch: true,
42
+ isEmergencyLaunch: false,
43
+ },
44
+ });
45
+ expect(await heartbeat.json()).toEqual({ status: "accepted" });
46
+
47
+ await page.goto(origin + "/updates/devices");
48
+ await page.getByRole("tab", { name: "Registry", exact: true }).click();
49
+ await page
50
+ .getByRole("button", { name: "Installation details " + installationId })
51
+ .click();
52
+ const details = page.getByRole("dialog", { name: "Installation details" });
53
+ await details
54
+ .getByRole("button", { name: "Bookmark " + installationId })
55
+ .click();
56
+ const fromRegistry = page.getByRole("dialog", { name: "Save favorite" });
57
+ await fromRegistry.getByLabel("Favorite name").fill("From registry");
58
+ await fromRegistry.getByRole("button", { name: "Save favorite" }).click();
59
+ await expect(fromRegistry).toBeHidden();
60
+ await expect(details).toBeVisible();
61
+ await page.goto(origin + path);
62
+ const mode = page.getByRole("radio", {
63
+ name: "Selected recipients",
64
+ });
65
+ await mode.click();
66
+ const registryTab = page.getByRole("tab", { name: "Registry", exact: true });
67
+ const favoritesTab = page.getByRole("tab", {
68
+ name: "Favorites",
69
+ exact: true,
70
+ });
71
+ const selected = page.getByRole("region", { name: "Selected recipients" });
72
+ const submit = page.getByRole("button", { name: "Save audience" });
73
+ await expect(submit).toBeDisabled();
74
+ const search = page.getByRole("textbox", { name: "Find a recipient" });
75
+ await search.fill("no such recipient");
76
+ await page.getByRole("button", { name: "Paste IDs" }).click();
77
+ const manual = page.getByRole("textbox", {
78
+ name: "Device or installation IDs",
79
+ });
80
+ const stage = page.getByRole("button", { name: "Add to selection" });
81
+ await manual.fill(deviceId + "\n" + "dasdasdsa");
82
+ await stage.click();
83
+ await expect(manual).toHaveAttribute("aria-invalid", "true");
84
+ await expect(
85
+ page.getByRole("alert").filter({ hasText: "dasdasdsa" }),
86
+ ).toBeVisible();
87
+ await expect(selected.getByRole("listitem")).toHaveCount(0);
88
+ await expect(submit).toBeDisabled();
89
+ await manual.fill(Array.from({ length: 101 }, () => randomUUID()).join("\n"));
90
+ await stage.click();
91
+ await expect(
92
+ page.getByText(
93
+ "Up to 100 device IDs and 100 installation IDs per audience.",
94
+ ),
95
+ ).toBeVisible();
96
+ await manual.fill(
97
+ [deviceId.toUpperCase(), installationId, deviceId].join(", "),
98
+ );
99
+ await stage.click();
100
+ await expect(selected.getByRole("listitem")).toHaveCount(2);
101
+ await manual.fill(installationId);
102
+ await stage.click();
103
+ await expect(
104
+ page.getByText("These recipients are already selected."),
105
+ ).toBeVisible();
106
+ const viewport = page.viewportSize();
107
+ for (const width of [390, 1440]) {
108
+ await page.setViewportSize({ width, height: 900 });
109
+ await expect
110
+ .poll(() =>
111
+ page.evaluate(
112
+ () => document.documentElement.scrollWidth - window.innerWidth,
113
+ ),
114
+ )
115
+ .toBeLessThanOrEqual(1);
116
+ }
117
+ if (viewport) await page.setViewportSize(viewport);
118
+ await page.getByRole("radio", { name: "All compatible devices" }).click();
119
+ await mode.click();
120
+ await expect(selected.getByRole("listitem")).toHaveCount(2);
121
+ await page.getByRole("button", { name: "Discard changes" }).click();
122
+ await mode.click();
123
+ await expect(selected.getByRole("listitem")).toHaveCount(0);
124
+ await registryTab.click();
125
+ await page
126
+ .getByRole("textbox", { name: "Find a recipient" })
127
+ .fill(installationId);
128
+ const bookmark = page.getByRole("button", {
129
+ name: "Bookmark " + installationId,
130
+ });
131
+ const dialog = page.getByRole("dialog", { name: "Save favorite" });
132
+ const favorites = page.getByRole("region", { name: "My favorites" });
133
+ const deviceName = "My QA phone";
134
+ const installationName = "Single installation";
135
+ for (const [kind, name] of [
136
+ ["device", deviceName],
137
+ ["installation", installationName],
138
+ ]) {
139
+ await bookmark.click();
140
+ await dialog.getByLabel("Bookmark target").selectOption(kind);
141
+ if (kind === "device") {
142
+ await expect(dialog.getByLabel("Favorite name")).toHaveValue(
143
+ "From registry",
144
+ );
145
+ }
146
+ await dialog.getByLabel("Favorite name").fill(name);
147
+ await dialog.getByRole("button", { name: "Save favorite" }).click();
148
+ await expect(dialog).toBeHidden();
149
+ await favoritesTab.click();
150
+ await expect(favorites.getByText(name, { exact: true })).toBeVisible();
151
+ await registryTab.click();
152
+ }
153
+ expect((await (await page.request.get(audience)).json()).audience_mode).toBe(
154
+ "all",
155
+ );
156
+ // An older heartbeat stays selectable, with its actual observation time.
157
+ await db.query(
158
+ "update ota_device_state set last_seen_at=last_seen_at - interval '60 days' where platform=$1 and installation_id=$2",
159
+ [platform, installationId],
160
+ );
161
+ await page.reload();
162
+ await mode.click();
163
+ await favoritesTab.click();
164
+ await expect(favorites.locator("time")).toHaveCount(2);
165
+ const seen = await favorites.locator("time").first().getAttribute("datetime");
166
+ expect(Date.now() - Date.parse(seen)).toBeGreaterThan(59 * 86400000);
167
+ const add = (name) =>
168
+ favorites.getByRole("button", { name: "Add " + name + " to audience" });
169
+ await add(deviceName).click();
170
+ await expect(
171
+ favorites.getByRole("button", { name: deviceName + " is selected" }),
172
+ ).toBeDisabled();
173
+ await page.getByRole("button", { name: "Save audience" }).click();
174
+ await expect
175
+ .poll(
176
+ async () =>
177
+ (await (await page.request.get(audience)).json()).audience_device_ids,
178
+ )
179
+ .toEqual([deviceId]);
180
+ await favorites
181
+ .getByRole("button", { name: "Remove " + deviceName + " from favorites" })
182
+ .click();
183
+ await expect(favorites.getByText(deviceName, { exact: true })).toHaveCount(0);
184
+ await add(installationName).click();
185
+ await page.getByRole("button", { name: "Save audience" }).click();
186
+ await expect
187
+ .poll(
188
+ async () =>
189
+ (await (await page.request.get(audience)).json())
190
+ .audience_installation_ids,
191
+ )
192
+ .toEqual([installationId]);
193
+ expect(
194
+ (await (await page.request.get(audience)).json()).audience_device_ids,
195
+ ).toEqual([deviceId]);
196
+ const pub = await db.query(
197
+ "select is_active from ota_updates where update_id=$1",
198
+ [draft.id],
199
+ );
200
+ expect(pub.rows[0].is_active).toBe(false);
201
+
202
+ const installTarget = {
203
+ platform,
204
+ target_kind: "installation",
205
+ target_id: installationId,
206
+ };
207
+ const {
208
+ rows: [other],
209
+ } = await db.query(
210
+ "insert into ota_admin_users(username,password_hash,role) select $1,password_hash,'operator' from ota_admin_users where username='admin' returning id,username",
211
+ ["operator-" + randomUUID().slice(0, 8)],
212
+ );
213
+ const browser = page.context().browser();
214
+ for (const username of [other.username, "viewer"]) {
215
+ const session = await browser.newContext();
216
+ try {
217
+ expect((await session.request.get(listUrl)).status()).toBe(401);
218
+ expect(
219
+ (
220
+ await session.request.post(origin + "/api/admin/login", {
221
+ data: { username, password },
222
+ })
223
+ ).status(),
224
+ ).toBe(200);
225
+ expect(
226
+ (await (await session.request.get(listUrl)).json()).favorites,
227
+ ).toEqual([]);
228
+ const own = { ...installTarget, name: "Operator bookmark" };
229
+ if (username === "viewer") {
230
+ expect((await session.request.put(api, { data: own })).status()).toBe(
231
+ 403,
232
+ );
233
+ expect(
234
+ (await session.request.delete(api, { data: installTarget })).status(),
235
+ ).toBe(403);
236
+ const screen = await session.newPage();
237
+ await screen.goto(origin + path);
238
+ await expect(
239
+ screen
240
+ .getByRole("region", { name: "Selected recipients" })
241
+ .getByText(installationId, { exact: true }),
242
+ ).toBeVisible();
243
+ await expect(
244
+ screen.getByRole("button", { name: /^Bookmark / }),
245
+ ).toHaveCount(0);
246
+ } else {
247
+ expect((await session.request.put(api, { data: own })).status()).toBe(
248
+ 200,
249
+ );
250
+ expect(
251
+ (await (await session.request.get(listUrl)).json()).favorites[0].name,
252
+ ).toBe(own.name);
253
+ expect(
254
+ (await session.request.delete(api, { data: installTarget })).status(),
255
+ ).toBe(200);
256
+ }
257
+ } finally {
258
+ await session.close();
259
+ }
260
+ }
261
+ expect(
262
+ (await (await page.request.get(listUrl)).json()).favorites[0].name,
263
+ ).toBe(installationName);
264
+ expect(
265
+ (await (await page.request.get(api + "?platform=ios")).json()).favorites,
266
+ ).toEqual([]);
267
+ expect(
268
+ (
269
+ await page.request.put(api, { data: { ...target, name: deviceName } })
270
+ ).status(),
271
+ ).toBe(200);
272
+ await db.query(
273
+ "delete from ota_device_state where platform=$1 and installation_id=$2",
274
+ [platform, installationId],
275
+ );
276
+ await page.reload();
277
+ await favoritesTab.click();
278
+ await expect(
279
+ favorites.getByText("Target is no longer in the registry"),
280
+ ).toHaveCount(2);
281
+ // Clearing a selected ID locally makes its Add control visible. A missing
282
+ // registry target is still unavailable even when it is no longer selected.
283
+ await selected
284
+ .getByRole("button", { name: "Remove " + deviceId + " from selection" })
285
+ .click();
286
+ await expect(add(deviceName)).toBeDisabled();
287
+ await expect(
288
+ favorites.getByRole("button", { name: installationName + " is selected" }),
289
+ ).toBeDisabled();
290
+ expect(
291
+ (
292
+ await page.request.put(api, { data: { ...target, name: deviceName } })
293
+ ).status(),
294
+ ).toBe(404);
295
+ await favorites
296
+ .getByRole("button", {
297
+ name: "Remove " + installationName + " from favorites",
298
+ })
299
+ .click();
300
+ await expect(
301
+ favorites.getByText(installationName, { exact: true }),
302
+ ).toHaveCount(0);
303
+ expect(
304
+ (await (await page.request.get(audience)).json()).audience_installation_ids,
305
+ ).toEqual([installationId]);
306
+ console.log(
307
+ "PASS personal device/installation favorites, role and account isolation, draft targeting, independent removal and missing telemetry",
308
+ );
309
+ }