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,307 @@
1
+ import assert from "node:assert/strict";
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import { PutObjectCommand } from "@aws-sdk/client-s3";
4
+ import { writeDatabaseRecords } from "../../../templates/expo-app/scripts/ota-publish/api/database-client.mjs";
5
+
6
+ const originalRuntime = "1.1.1";
7
+ const upgradedRuntime = "1.2.0";
8
+ const matrixChannel = "release-matrix";
9
+
10
+ export async function exerciseReleaseMatrix({
11
+ db,
12
+ storage,
13
+ request,
14
+ manifest,
15
+ }) {
16
+ const deviceHeaders = {
17
+ "expo-extra-params": 'device_id="' + "b".repeat(64) + '"',
18
+ };
19
+ const fastPublisherClock = Date.now() + 5 * 60_000;
20
+ const guard = {
21
+ action: "ota-force-update",
22
+ payload: { message: "Install v2" },
23
+ };
24
+
25
+ // Feed the real publish writer a small, uniquely identifiable platform export.
26
+ // Historical fixture dates keep the main console workflow's release on the first page.
27
+ async function publish(
28
+ platform,
29
+ runtimeVersion,
30
+ patch,
31
+ { active = true, targeted = false, channel = matrixChannel } = {},
32
+ ) {
33
+ const id = randomUUID();
34
+ const name = [channel, runtimeVersion, platform, "v" + patch].join("/");
35
+ const bundle = Buffer.from(
36
+ "globalThis.build = " + JSON.stringify(name) + ";",
37
+ );
38
+ // One CI clock is five minutes ahead of the server; native rollback still needs a newer date.
39
+ const baseTime =
40
+ platform === "android" && runtimeVersion === originalRuntime
41
+ ? fastPublisherClock
42
+ : Date.UTC(2024, 0, 1);
43
+ const createdAt = new Date(baseTime + patch * 1000).toISOString();
44
+ const prefix = [runtimeVersion, platform, channel, id].join("/");
45
+ const launchAsset = {
46
+ path: "bundle.js",
47
+ key: id,
48
+ contentType: "application/javascript",
49
+ fileExtension: ".bundle",
50
+ hash: createHash("sha256").update(bundle).digest("base64url"),
51
+ };
52
+ await storage.send(
53
+ new PutObjectCommand({
54
+ Bucket: "ota-fixtures",
55
+ Key: prefix + "/bundle.js",
56
+ Body: bundle,
57
+ }),
58
+ );
59
+ const update = {
60
+ id,
61
+ buildId: id,
62
+ runtimeVersion,
63
+ platform,
64
+ channel,
65
+ createdAt,
66
+ createdAtPath: id,
67
+ expoClient: { name, version: "2.0." + patch },
68
+ comment: name,
69
+ launchAsset,
70
+ assets: [],
71
+ storageBucket: "ota-fixtures",
72
+ storageBasePath: prefix,
73
+ };
74
+ await writeDatabaseRecords(db, update, { ...update, updateId: id });
75
+ const path = "/api/admin/updates/" + Buffer.from(id).toString("base64url");
76
+ if (targeted) {
77
+ await request(path + "/audience", "PUT", {
78
+ audience_mode: "devices",
79
+ audience_device_ids: ["b".repeat(64)],
80
+ audience_installation_ids: [],
81
+ audience_version: 1,
82
+ });
83
+ await request(path + "/policy", "PUT", {
84
+ expectedPolicyVersion: 1,
85
+ delivery: "background",
86
+ guard,
87
+ });
88
+ }
89
+ if (active)
90
+ await request(path + "/deactivate", "POST", { disabled: false });
91
+ return { path, id, name, bundle, platform, runtimeVersion, channel };
92
+ }
93
+
94
+ function check(platform, runtimeVersion, headers = {}) {
95
+ return manifest({
96
+ "expo-platform": platform,
97
+ "expo-runtime-version": runtimeVersion,
98
+ "expo-channel-name": matrixChannel,
99
+ ...headers,
100
+ });
101
+ }
102
+ const running = ({ id }) => ({ "expo-current-update-id": id });
103
+ async function expectNone(platform, runtime, headers) {
104
+ const value = await check(platform, runtime, headers);
105
+ assert.deepEqual(
106
+ value,
107
+ { type: "noUpdateAvailable" },
108
+ "expected signed no-update for " + [platform, runtime].join("/"),
109
+ );
110
+ }
111
+ async function expectRelease(release, headers) {
112
+ const value = await check(release.platform, release.runtimeVersion, {
113
+ "expo-channel-name": release.channel,
114
+ ...headers,
115
+ });
116
+ assert.equal(
117
+ value.extra?.expoClient.name,
118
+ release.name,
119
+ "expected signed manifest for " +
120
+ release.name +
121
+ "; received " +
122
+ (value.type || value.id),
123
+ );
124
+ assert.equal(value.runtimeVersion, release.runtimeVersion);
125
+ assert.equal(value.metadata.channel, release.channel);
126
+ const response = await fetch(value.launchAsset.url, { headers });
127
+ assert.equal(response.status, 200);
128
+ const bytes = Buffer.from(await response.arrayBuffer());
129
+ assert.deepEqual(bytes, release.bundle);
130
+ assert.equal(
131
+ createHash("sha256").update(bytes).digest("base64url"),
132
+ value.launchAsset.hash,
133
+ );
134
+ return value;
135
+ }
136
+
137
+ const releases = {};
138
+ for (const platform of ["ios", "android"]) {
139
+ // #17–24, #53–55: an unrelated runtime/platform produces only a signed directive.
140
+ const v1 = await publish(platform, originalRuntime, 1);
141
+ const first = await expectRelease(v1);
142
+ await expectNone(platform, "1.1.0");
143
+ await expectNone(platform, upgradedRuntime);
144
+ if (platform === "ios") await expectNone("android", originalRuntime);
145
+
146
+ // The newer targeted release can be retired while the older public release stays active.
147
+ const v2 = await publish(platform, originalRuntime, 2, { targeted: true });
148
+ const candidate = await expectRelease(v2, {
149
+ ...deviceHeaders,
150
+ ...running(first),
151
+ });
152
+ assert.deepEqual(candidate.extra.updatePolicy.guard, guard);
153
+ await request(v2.path + "/deactivate", "POST", { disabled: true });
154
+
155
+ // #27–31: clients that skipped the release stay put. A client already on
156
+ // the retired release gets the older bundle, its own policy, and a fresh native timestamp.
157
+ await expectNone(platform, originalRuntime, running(first));
158
+ const fallback = await expectRelease(v1, {
159
+ ...deviceHeaders,
160
+ ...running(candidate),
161
+ });
162
+ assert.notEqual(fallback.id, candidate.id);
163
+ assert.ok(
164
+ Date.parse(fallback.createdAt) > Date.parse(candidate.createdAt),
165
+ "fallback must be newer to Expo",
166
+ );
167
+ assert.equal(fallback.extra.updatePolicy.delivery, "manual");
168
+ assert.equal(fallback.extra.updatePolicy.guard, undefined);
169
+ await expectNone(platform, originalRuntime, {
170
+ ...deviceHeaders,
171
+ ...running(fallback),
172
+ });
173
+
174
+ const embedded = randomUUID();
175
+ await request(
176
+ "/api/admin/embedded-updates",
177
+ "POST",
178
+ {
179
+ embeddedUpdateId: embedded,
180
+ appVersion: "3.0.0",
181
+ channel: matrixChannel,
182
+ platform,
183
+ createdAt: "2024-01-02T00:00:00Z",
184
+ },
185
+ 201,
186
+ );
187
+ await expectNone(platform, originalRuntime, {
188
+ ...deviceHeaders,
189
+ ...running(candidate),
190
+ "expo-embedded-update-id": embedded,
191
+ });
192
+ await request("/api/admin/embedded-updates/" + embedded, "DELETE");
193
+
194
+ // #25–26, #32–33: reactivation, ignored draft, and a direct jump to the latest eligible patch.
195
+ await request(v2.path + "/deactivate", "POST", { disabled: false });
196
+ const reactivated = await expectRelease(v2, {
197
+ ...deviceHeaders,
198
+ ...running(fallback),
199
+ });
200
+ assert.ok(
201
+ Date.parse(reactivated.createdAt) > Date.parse(fallback.createdAt),
202
+ );
203
+ const v3 = await publish(platform, originalRuntime, 3, {
204
+ active: false,
205
+ targeted: true,
206
+ });
207
+ await expectRelease(v2, { ...deviceHeaders, ...running(first) });
208
+ await request(v3.path + "/deactivate", "POST", { disabled: false });
209
+ await publish(platform, originalRuntime, 4, { active: false });
210
+ const third = await expectRelease(v3, {
211
+ ...deviceHeaders,
212
+ ...running(first),
213
+ });
214
+ await expectNone(platform, originalRuntime, {
215
+ ...deviceHeaders,
216
+ ...running(third),
217
+ });
218
+
219
+ // #23, #69–70, #72: the new native runtime starts empty, then receives only its own v1.
220
+ await expectNone(platform, upgradedRuntime, running(third));
221
+ const newV1 = await publish(platform, upgradedRuntime, 1);
222
+ const upgraded = await expectRelease(newV1);
223
+ assert.notEqual(upgraded.id, first.id);
224
+ await expectNone(platform, upgradedRuntime, running(upgraded));
225
+ releases[platform] = newV1;
226
+ }
227
+
228
+ // #53, #56–57: byte-distinct patches with equal numbers, followed by independent platform histories.
229
+ const iosV2 = await publish("ios", upgradedRuntime, 2);
230
+ const androidV2 = await publish("android", upgradedRuntime, 2);
231
+ const iosLatest = await expectRelease(iosV2);
232
+ const androidSecond = await expectRelease(androidV2);
233
+ assert.notEqual(iosLatest.launchAsset.hash, androidSecond.launchAsset.hash);
234
+ let androidLatest = androidV2;
235
+ for (const number of [3, 4, 5])
236
+ androidLatest = await publish("android", upgradedRuntime, number);
237
+ await expectRelease(androidLatest, running(androidSecond));
238
+ await expectNone("ios", upgradedRuntime, running(iosLatest));
239
+ await expectRelease(iosV2, running(releases.ios));
240
+ // A private build in one channel must never replace a public build in another.
241
+ for (const platform of ["ios", "android"]) {
242
+ const stable = await publish(platform, originalRuntime, 1, {
243
+ channel: "production",
244
+ });
245
+ const beta = await publish(platform, originalRuntime, 1, {
246
+ channel: "matrix-beta",
247
+ });
248
+ const restricted = await publish(platform, originalRuntime, 2, {
249
+ channel: beta.channel,
250
+ targeted: true,
251
+ });
252
+ const betaPublic = await expectRelease(beta);
253
+ await expectRelease(restricted, { ...deviceHeaders, ...running(betaPublic) });
254
+ await expectRelease(stable, deviceHeaders);
255
+ await expectRelease(stable, { "expo-channel-name": " " });
256
+ await expectRelease(beta, { "expo-channel-name": " MATRIX-BETA " });
257
+ await expectNone(platform, originalRuntime, {
258
+ ...deviceHeaders,
259
+ "expo-channel-name": "matrix-unpublished",
260
+ });
261
+ await expectNone(platform, originalRuntime, {
262
+ ...running(betaPublic),
263
+ "expo-channel-name": beta.channel,
264
+ });
265
+ }
266
+
267
+ // Publication order differs from actual public activation history.
268
+ const historyChannel = "manual-restore";
269
+ const historyScope = async () => (await request("/api/admin/distribution-history")).scopes.find(
270
+ (s) => s.runtimeVersion === originalRuntime && s.channel === historyChannel && s.platform === "android",
271
+ );
272
+ const pub = (patch, options) => publish("android", originalRuntime, patch, { channel: historyChannel, ...options });
273
+ const publicA = await pub(1);
274
+ await request(publicA.path + "/deactivate", "POST", { disabled: true });
275
+ assert.equal((await historyScope()).previous, null);
276
+ await request(publicA.path + "/deactivate", "POST", { disabled: false });
277
+ const smoke = await pub(2, { targeted: true });
278
+ for (let patch = 3; patch <= 32; patch++) await pub(patch, { active: false });
279
+ assert.equal((await historyScope()).current.updateId, publicA.id);
280
+ const publicB = await pub(33);
281
+ for (const patch of [34, 35, 36]) await pub(patch, { active: false });
282
+ const live = await historyScope();
283
+ assert.equal(live.current.updateId, publicB.id);
284
+ assert.equal(live.previous.updateId, publicA.id);
285
+ const runningB = await expectRelease(publicB);
286
+ await request(publicB.path + "/deactivate", "POST", { disabled: true });
287
+ await expectNone("android", originalRuntime, { "expo-channel-name": historyChannel });
288
+ await expectNone("android", originalRuntime, { "expo-channel-name": historyChannel, ...running(runningB) });
289
+ const stopped = await historyScope();
290
+ assert.equal(stopped.current, null);
291
+ assert.equal(stopped.previous.updateId, publicA.id);
292
+ assert.notEqual(stopped.revision, live.revision);
293
+ const restore = (updateId, expectedRevision, status = 200) =>
294
+ request("/api/admin/distribution-history/restore", "POST", { updateId, expectedRevision }, status);
295
+ await restore(publicA.id, live.revision, 409);
296
+ await restore(smoke.id, stopped.revision, 409);
297
+ await restore(publicA.id, stopped.revision);
298
+ const restored = await historyScope();
299
+ assert.equal(restored.current.updateId, publicA.id);
300
+ assert.equal(restored.previous.updateId, publicB.id);
301
+ await expectRelease(publicA, running(runningB));
302
+ await restore(publicA.id, stopped.revision, 409);
303
+
304
+ console.log(
305
+ "PASS signed HTTP release matrix: both platform stacks, active/draft selection, scoped retired-build fallback, embedded floor, skipped versions, native runtime transition, normalized/empty/unknown channels and targeted channel isolation",
306
+ );
307
+ }
@@ -0,0 +1,162 @@
1
+ import { seedPublication } from "./delivery.mjs";
2
+ import { expect as playwrightExpect } from "@playwright/test";
3
+
4
+ const expect = playwrightExpect.configure({ timeout: 30_000 });
5
+
6
+ export async function exerciseReleaseConsole(page, password) {
7
+ const origin = new URL(page.url()).origin;
8
+ const go = (path) => page.goto(origin + path);
9
+ await go("/updates");
10
+ const search = page.getByRole("searchbox", { name: "Search releases" });
11
+ await expect(page.getByRole("button", { name: "Apply", exact: true })).toHaveCount(0);
12
+ await search.fill("Candidate");
13
+ await page.getByRole("combobox", { name: "All platforms" }).click();
14
+ await Promise.all([
15
+ page.waitForResponse((response) => {
16
+ const url = new URL(response.url());
17
+ return response.ok() && url.pathname === "/api/admin/updates" &&
18
+ url.searchParams.get("platform") === "ios" && url.searchParams.get("q") === "Candidate";
19
+ }),
20
+ page.getByRole("option", { name: "iOS", exact: true }).click(),
21
+ ]);
22
+ await page.getByRole("combobox", { name: "All channels" }).click();
23
+ await Promise.all([
24
+ page.waitForResponse((response) => {
25
+ const url = new URL(response.url());
26
+ return response.ok() && url.pathname === "/api/admin/updates" &&
27
+ url.searchParams.get("channel") === "production" && url.searchParams.get("platform") === "ios";
28
+ }),
29
+ page.getByRole("option", { name: "production", exact: true }).click(),
30
+ ]);
31
+ const release = page.getByRole("table").getByRole("link", {
32
+ name: "Candidate release",
33
+ exact: true,
34
+ });
35
+ await expect(release).toBeVisible();
36
+ await expect(
37
+ page
38
+ .getByRole("table")
39
+ .getByRole("link", { name: "Initial public build", exact: true }),
40
+ ).toHaveCount(0);
41
+ await search.fill("no such release");
42
+ await expect(
43
+ page.getByText("No matching releases", { exact: true }),
44
+ ).toBeVisible();
45
+ await page
46
+ .getByRole("button", { name: "Reset", exact: true })
47
+ .first()
48
+ .click();
49
+ await search.fill("Initial public build");
50
+ const old = page.getByRole("table").getByRole("link", {
51
+ name: "Initial public build",
52
+ exact: true,
53
+ });
54
+ await expect(old).toBeVisible();
55
+ await old.click();
56
+ await page.getByRole("button", { name: "Rollback", exact: true }).click();
57
+ await page
58
+ .getByRole("dialog")
59
+ .getByRole("button", { name: "Rollback", exact: true })
60
+ .click();
61
+ await expect(
62
+ page.getByRole("status").filter({ hasText: "Rollback" }).first(),
63
+ ).toBeVisible();
64
+ await go("/updates");
65
+ await search.fill("Candidate release");
66
+ await release.click();
67
+ await page.getByRole("button", { name: "Promote", exact: true }).click();
68
+ await page
69
+ .getByRole("dialog")
70
+ .getByRole("button", { name: "Promote", exact: true })
71
+ .click();
72
+ await expect(
73
+ page.getByRole("button", { name: "Promote", exact: true }),
74
+ ).toHaveCount(0);
75
+ await page.getByRole("tab", { name: "Policy", exact: true }).click();
76
+ await expect(
77
+ page.getByRole("heading", { name: "Update policy" }),
78
+ ).toBeVisible();
79
+ await page.getByRole("tab", { name: "Metadata", exact: true }).click();
80
+ await expect(
81
+ page.getByRole("textbox", { name: "JSON editor" }),
82
+ ).toBeVisible();
83
+ const releasePath = new URL(page.url()).pathname;
84
+
85
+ const viewer = await page.context().browser().newContext();
86
+ try {
87
+ const screen = await viewer.newPage();
88
+ const login = await viewer.request.post(origin + "/api/admin/login", {
89
+ data: { username: "viewer", password },
90
+ });
91
+ expect(login.status()).toBe(200);
92
+ await screen.goto(origin + releasePath);
93
+ await expect(screen.getByText("Read only", { exact: true })).toBeVisible();
94
+ await expect(screen.getByRole("radio").first()).toBeDisabled();
95
+ await expect(
96
+ screen.getByRole("button", {
97
+ name: /^(Activate|Deactivate|Promote|Rollback|Save audience)$/,
98
+ }),
99
+ ).toHaveCount(0);
100
+ const denied = await viewer.request.post(
101
+ origin + "/api/admin" + releasePath + "/deactivate",
102
+ { data: { disabled: true } },
103
+ );
104
+ expect(denied.status()).toBe(403);
105
+ await screen.getByRole("tab", { name: "Metadata" }).click();
106
+ await expect(
107
+ screen.getByRole("textbox", { name: "JSON editor" }),
108
+ ).toHaveAttribute("readonly", "");
109
+ } finally {
110
+ await viewer.close();
111
+ }
112
+ console.log(
113
+ "PASS release filters, no matches/reset, rollback/promotion, policy/metadata navigation and viewer UI/API denial",
114
+ );
115
+ }
116
+
117
+ export async function exercisePublicRestore(page, { origin, db, storage }) {
118
+ const scope = { channel: "restore-browser", runtime: "8.0" };
119
+ const publish = (label) =>
120
+ seedPublication(db, storage, label, false, "ios", scope);
121
+ const setActive = async (release, active) => {
122
+ const response = await page.request.post(
123
+ origin + release.path + "/deactivate",
124
+ { data: { disabled: !active } },
125
+ );
126
+ expect(response.status()).toBe(200);
127
+ };
128
+ const previous = await publish("Stable patch");
129
+ await setActive(previous, true);
130
+ const latest = await publish("Replacement patch");
131
+ await setActive(latest, true);
132
+ await setActive(latest, false);
133
+ await page.goto(origin + "/updates");
134
+ const search = page.getByRole("textbox", { name: "Find a delivery scope" });
135
+ await search.fill(scope.channel);
136
+ const row = page.getByRole("region", {
137
+ name: "restore-browser / ios / 8.0",
138
+ exact: true,
139
+ });
140
+ await expect(row.getByText("No active release")).toBeVisible();
141
+ await expect(row.getByRole("link", { name: previous.comment })).toBeVisible();
142
+ const restore = row.getByRole("button", { name: "Restore", exact: true });
143
+ await page.getByRole("button", { name: "Management", exact: true }).click();
144
+ await page.getByRole("button", { name: "Stop all OTA", exact: true }).click();
145
+ await expect(
146
+ page.getByText("Enter a reason for the emergency stop.", { exact: true }),
147
+ ).toBeVisible();
148
+ await expect(restore).toBeEnabled();
149
+ await restore.click();
150
+ const dialog = page.getByRole("dialog");
151
+ await dialog.getByRole("button", { name: "Cancel" }).click();
152
+ await expect(row.getByText("No active release")).toBeVisible();
153
+ await restore.click();
154
+ await dialog
155
+ .getByRole("button", { name: "Restore release", exact: true })
156
+ .click();
157
+ await expect(row.getByRole("link", { name: latest.comment })).toBeVisible();
158
+ await expect(row.getByText("No active release")).toHaveCount(0);
159
+ console.log(
160
+ "PASS manual public restore, confirmation cancellation and refreshed release history",
161
+ );
162
+ }
@@ -0,0 +1,224 @@
1
+ // Own the database, object store, signing key and HTTP process for the whole run.
2
+ import { execFileSync, spawn } from "node:child_process";
3
+ import { once } from "node:events";
4
+ import { generateKeyPairSync, randomBytes, randomUUID } from "node:crypto";
5
+ import { cp, mkdir, mkdtemp, readFile, rm, symlink } from "node:fs/promises";
6
+ import { closeSync, openSync } from "node:fs";
7
+ import { tmpdir } from "node:os";
8
+ import path from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+ import { createServer } from "node:net";
11
+ import { setTimeout as delay } from "node:timers/promises";
12
+ import { Pool } from "pg";
13
+ import { CreateBucketCommand, S3Client } from "@aws-sdk/client-s3";
14
+ import bcrypt from "bcryptjs";
15
+ import { exerciseClientLifecycle } from "./client-lifecycle.mjs";
16
+ import { exerciseDelivery, seedPublication } from "./delivery.mjs";
17
+ import { checkRegistrarToken } from "./registrar-token.mjs";
18
+ import { exerciseConsole } from "./console.mjs";
19
+
20
+ const root = fileURLToPath(new URL("../../../", import.meta.url));
21
+ const scratch = await mkdtemp(path.join(tmpdir(), "ota-e2e-"));
22
+ const suffix = randomUUID();
23
+ const password = randomBytes(24).toString("hex");
24
+ const containers = [];
25
+ const docker = (...args) =>
26
+ execFileSync("docker", args, { encoding: "utf8" }).trim();
27
+ const { privateKey, publicKey } = generateKeyPairSync("rsa", {
28
+ modulusLength: 2048,
29
+ });
30
+ let db, server, storage;
31
+ async function ready(check, label) {
32
+ let last;
33
+ for (let attempt = 0; attempt < 120; attempt++) {
34
+ try {
35
+ await check();
36
+ return;
37
+ } catch (error) {
38
+ last = error;
39
+ }
40
+ if (server && server.exitCode !== null) break;
41
+ await delay(500);
42
+ }
43
+ throw new Error(label, { cause: last });
44
+ }
45
+ function container(name, port, ...args) {
46
+ const id = docker(
47
+ "run",
48
+ "--rm",
49
+ "-d",
50
+ "--name",
51
+ name + "-" + suffix,
52
+ "-p",
53
+ "127.0.0.1::" + port,
54
+ ...args,
55
+ );
56
+ containers.push(id);
57
+ return Number(docker("port", id, String(port)).split(":").at(-1));
58
+ }
59
+ try {
60
+ const image = process.env.OTA_E2E_MINIO_IMAGE || "ota-e2e-minio";
61
+ if (!process.env.OTA_E2E_MINIO_IMAGE)
62
+ docker(
63
+ "build",
64
+ "-q",
65
+ "-t",
66
+ image,
67
+ "-f",
68
+ path.join(root, "docker/minio.Dockerfile"),
69
+ path.join(root, "docker"),
70
+ );
71
+ const pgPort = container(
72
+ "ota-e2e-db",
73
+ 5432,
74
+ "--tmpfs",
75
+ "/var/lib/postgresql/data:rw,size=512m",
76
+ "-e",
77
+ "POSTGRES_PASSWORD=" + password,
78
+ "postgres:17-alpine",
79
+ );
80
+ const storagePort = container(
81
+ "ota-e2e-store",
82
+ 9000,
83
+ "--tmpfs",
84
+ "/data:rw,size=256m",
85
+ "-e",
86
+ "MINIO_ROOT_USER=e2e-local",
87
+ "-e",
88
+ "MINIO_ROOT_PASSWORD=" + password,
89
+ image,
90
+ "server",
91
+ "/data",
92
+ );
93
+ const DATABASE_URL =
94
+ "postgresql://postgres:" + password + "@127.0.0.1:" + pgPort + "/postgres";
95
+ const endpoint = "http://127.0.0.1:" + storagePort;
96
+ db = new Pool({
97
+ connectionString: DATABASE_URL,
98
+ connectionTimeoutMillis: 1500,
99
+ });
100
+ storage = new S3Client({
101
+ endpoint,
102
+ region: "us-east-1",
103
+ forcePathStyle: true,
104
+ credentials: { accessKeyId: "e2e-local", secretAccessKey: password },
105
+ });
106
+ await ready(() => db.query("select 1"), "PostgreSQL startup");
107
+ await ready(
108
+ () => storage.send(new CreateBucketCommand({ Bucket: "ota-fixtures" })),
109
+ "Object store startup",
110
+ );
111
+
112
+ // Exercise fresh and upgrade paths in separate databases on this run's
113
+ // disposable PostgreSQL instance. Each migration test requires an empty DB.
114
+ for (const [database, script, ...args] of [
115
+ ["analytics_fresh", "device-analytics-migrations.mjs", "--fresh"],
116
+ ["analytics_upgrade", "device-analytics-migrations.mjs"],
117
+ ["public_history_upgrade", "public-distribution-history.mjs"],
118
+ ]) {
119
+ await db.query("CREATE DATABASE " + database);
120
+ const testUrl = new URL(DATABASE_URL);
121
+ testUrl.pathname = "/" + database;
122
+ execFileSync(process.execPath, [path.join(root, "scripts/tests", script), ...args], {
123
+ env: { ...process.env, OTA_TEST_DATABASE_URL: testUrl.href },
124
+ stdio: "inherit",
125
+ });
126
+ }
127
+ const schema = await readFile(path.join(root, "docs/migrations/schema.sql"), "utf8");
128
+ await db.query(schema);
129
+ const old = await seedPublication(db, storage, "Initial public build", true);
130
+ const hash = await bcrypt.hash(password, 4);
131
+ for (const role of ["admin", "viewer"]) {
132
+ await db.query(
133
+ "insert into ota_admin_users(username,password_hash,role) values($1,$2,$1)",
134
+ [role, hash],
135
+ );
136
+ }
137
+ const scratchApp = path.join(scratch, "server");
138
+ await mkdir(scratchApp);
139
+ // Copy only source inputs. Next loads .env.local automatically from its app directory.
140
+ for (const name of [
141
+ "app",
142
+ "components",
143
+ "hooks",
144
+ "lib",
145
+ "src",
146
+ "public",
147
+ "package.json",
148
+ "tsconfig.json",
149
+ "next.config.ts",
150
+ "postcss.config.mjs",
151
+ ]) {
152
+ await cp(path.join(root, name), path.join(scratchApp, name), {
153
+ recursive: true,
154
+ });
155
+ }
156
+ await symlink(
157
+ path.join(root, "node_modules"),
158
+ path.join(scratchApp, "node_modules"),
159
+ "dir",
160
+ );
161
+ const reservation = createServer().listen(0, "127.0.0.1");
162
+ await once(reservation, "listening");
163
+ const port = reservation.address().port;
164
+ await new Promise((resolve) => reservation.close(resolve));
165
+ const origin = "http://127.0.0.1:" + port;
166
+ const log = openSync(path.join(scratch, "server.log"), "w");
167
+ const R2_SECRET_ACCESS_KEY = password;
168
+ const CODE_SIGNING_PRIVATE_KEY = privateKey.export({ type: "pkcs8", format: "pem" });
169
+ server = spawn(
170
+ process.execPath,
171
+ [
172
+ path.join(root, "node_modules/next/dist/bin/next"),
173
+ "dev",
174
+ "--webpack",
175
+ "-H",
176
+ "127.0.0.1",
177
+ "-p",
178
+ String(port),
179
+ ],
180
+ {
181
+ cwd: scratchApp,
182
+ stdio: ["ignore", log, log],
183
+ env: {
184
+ PATH: process.env.PATH,
185
+ HOME: process.env.HOME,
186
+ TMPDIR: tmpdir(),
187
+ NEXT_TELEMETRY_DISABLED: "1",
188
+ DATABASE_PROVIDER: "pg",
189
+ DATABASE_URL,
190
+ R2_ENDPOINT: endpoint,
191
+ R2_REGION: "us-east-1",
192
+ R2_ACCESS_KEY_ID: "e2e-local",
193
+ R2_SECRET_ACCESS_KEY,
194
+ OTA_STORAGE_BUCKET: "ota-fixtures",
195
+ S3_FORCE_PATH_STYLE: "true",
196
+ OTA_PUBLIC_BASE_URL: origin,
197
+ CODE_SIGNING_PRIVATE_KEY,
198
+ },
199
+ },
200
+ );
201
+ closeSync(log);
202
+ await ready(async () => {
203
+ if (!(await fetch(origin + "/api/health")).ok) throw new Error("Unhealthy");
204
+ }, "HTTP server startup");
205
+ const fixture = { origin, db, storage, password, publicKey, old };
206
+ await exerciseDelivery(fixture);
207
+ await exerciseClientLifecycle({ ...fixture, scratch });
208
+ await exerciseConsole(fixture);
209
+ await checkRegistrarToken(origin, DATABASE_URL, scratchApp);
210
+ console.log("PASS signed OTA HTTP and browser workflows");
211
+ } catch (error) {
212
+ console.error(error);
213
+ process.exitCode = 1;
214
+ } finally {
215
+ if (server && server.exitCode === null && server.signalCode === null) {
216
+ const stopped = once(server, "exit");
217
+ server.kill("SIGTERM");
218
+ await stopped;
219
+ }
220
+ storage?.destroy();
221
+ await db?.end();
222
+ for (const id of containers) docker("rm", "-f", id);
223
+ await rm(scratch, { recursive: true, force: true });
224
+ }