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.
- package/README.md +4 -2
- package/dist/template/Dockerfile +4 -6
- package/dist/template/README.md +4 -9
- package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
- package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
- package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
- package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
- package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
- package/dist/template/app/api/admin/updates/route.test.ts +21 -0
- package/dist/template/app/api/admin/updates/route.ts +12 -1
- package/dist/template/app/globals.css +65 -68
- package/dist/template/app/login/page.tsx +66 -42
- package/dist/template/app/updates/[encodedKey]/page.tsx +375 -263
- package/dist/template/app/updates/devices/page.tsx +188 -152
- package/dist/template/app/updates/embedded/page.tsx +63 -29
- package/dist/template/app/updates/emergency-redirects/page.tsx +93 -58
- package/dist/template/app/updates/layout.tsx +2 -1
- package/dist/template/app/updates/page.tsx +381 -283
- package/dist/template/app/updates/releases.test.tsx +156 -0
- package/dist/template/components/admin/admin-role.ts +5 -0
- package/dist/template/components/admin/admin-shell.tsx +166 -101
- package/dist/template/components/admin/confirm-action.tsx +123 -0
- package/dist/template/components/admin/language-switcher.tsx +25 -17
- package/dist/template/components/admin/release-badges.test.tsx +50 -0
- package/dist/template/components/admin/release-badges.tsx +101 -0
- package/dist/template/components/ui/alert.tsx +10 -3
- package/dist/template/components/ui/avatar.tsx +108 -0
- package/dist/template/components/ui/badge.tsx +2 -2
- package/dist/template/components/ui/breadcrumb.tsx +108 -0
- package/dist/template/components/ui/button.tsx +5 -5
- package/dist/template/components/ui/card.tsx +2 -2
- package/dist/template/components/ui/chart.tsx +1 -1
- package/dist/template/components/ui/collapsible.tsx +7 -0
- package/dist/template/components/ui/empty.tsx +103 -0
- package/dist/template/components/ui/field.tsx +248 -0
- package/dist/template/components/ui/input-group.tsx +170 -0
- package/dist/template/components/ui/input.tsx +1 -1
- package/dist/template/components/ui/native-select.tsx +1 -1
- package/dist/template/components/ui/radio-group.tsx +41 -0
- package/dist/template/components/ui/status-tones.ts +15 -0
- package/dist/template/components/ui/table.tsx +1 -1
- package/dist/template/components/ui/textarea.tsx +1 -1
- package/dist/template/docs/admin-ui.md +7 -3
- package/dist/template/docs/device-targeting.md +2 -7
- package/dist/template/docs/doctor.md +2 -2
- package/dist/template/docs/expo-app-setup.md +9 -27
- package/dist/template/docs/getting-started.md +3 -4
- package/dist/template/docs/installation-telemetry.md +2 -8
- package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
- package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
- package/dist/template/docs/migrations/schema.sql +349 -0
- package/dist/template/docs/npm-installer.md +3 -3
- package/dist/template/docs/operations-guide.md +8 -6
- package/dist/template/docs/ota-client-lifecycle.md +30 -68
- package/dist/template/docs/ota-update-policy.md +9 -20
- package/dist/template/docs/ru/admin-ui.md +7 -3
- package/dist/template/docs/ru/device-targeting.md +2 -2
- package/dist/template/docs/ru/doctor.md +2 -2
- package/dist/template/docs/ru/expo-app-setup.md +9 -9
- package/dist/template/docs/ru/getting-started.md +3 -3
- package/dist/template/docs/ru/installation-telemetry.md +2 -2
- package/dist/template/docs/ru/npm-installer.md +3 -3
- package/dist/template/docs/ru/operations-guide.md +8 -3
- package/dist/template/docs/ru/ota-client-lifecycle.md +30 -35
- package/dist/template/docs/ru/ota-update-policy.md +9 -7
- package/dist/template/docs/ru/publishing-npm-installer.md +2 -2
- package/dist/template/docs/uk/admin-ui.md +7 -3
- package/dist/template/docs/uk/device-targeting.md +2 -2
- package/dist/template/docs/uk/doctor.md +2 -2
- package/dist/template/docs/uk/expo-app-setup.md +9 -9
- package/dist/template/docs/uk/getting-started.md +3 -3
- package/dist/template/docs/uk/installation-telemetry.md +2 -2
- package/dist/template/docs/uk/npm-installer.md +3 -3
- package/dist/template/docs/uk/operations-guide.md +8 -3
- package/dist/template/docs/uk/ota-client-lifecycle.md +30 -35
- package/dist/template/docs/uk/ota-update-policy.md +9 -7
- package/dist/template/docs/uk/publishing-npm-installer.md +2 -2
- package/dist/template/lib/audience-ids.ts +4 -0
- package/dist/template/package-lock.json +46 -0
- package/dist/template/package.json +3 -1
- package/dist/template/scripts/configure-expo-app.mjs +3 -3
- package/dist/template/scripts/create-access-token.mjs +1 -1
- package/dist/template/scripts/lib/doctor.mjs +10 -7
- package/dist/template/scripts/lib/doctor.test.mjs +7 -5
- package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
- package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
- package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
- package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
- package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
- package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
- package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
- package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
- package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
- package/dist/template/scripts/tests/e2e/console.mjs +86 -0
- package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
- package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
- package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
- package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
- package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
- package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
- package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
- package/dist/template/scripts/tests/e2e/run.mjs +224 -0
- package/dist/template/scripts/tests/manifest-identity.sql +7 -5
- package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
- package/dist/template/src/client/admin-api.ts +45 -10
- package/dist/template/src/client/admin-types.ts +35 -1
- package/dist/template/src/client/devices/analytics.tsx +168 -231
- package/dist/template/src/client/devices/cohorts.tsx +181 -0
- package/dist/template/src/client/devices/device-name.tsx +37 -23
- package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
- package/dist/template/src/client/devices/registry.tsx +258 -245
- package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
- package/dist/template/src/client/devices/use-devices-report.ts +53 -82
- package/dist/template/src/client/devices/version-adoption-chart.tsx +47 -49
- package/dist/template/src/client/distribution-control.tsx +89 -57
- package/dist/template/src/client/distribution-history.tsx +353 -0
- package/dist/template/src/client/guard-action-catalog.tsx +183 -0
- package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
- package/dist/template/src/client/guard-action-combobox.tsx +133 -239
- package/dist/template/src/client/guard-action-options.ts +4 -6
- package/dist/template/src/client/i18n/en.json +133 -2
- package/dist/template/src/client/i18n/language-switching.test.tsx +12 -3
- package/dist/template/src/client/i18n/ru.json +133 -2
- package/dist/template/src/client/i18n/uk.json +133 -2
- package/dist/template/src/client/logout-button.tsx +3 -3
- package/dist/template/src/client/policy-draft.ts +138 -0
- package/dist/template/src/client/update-audience-editor.tsx +597 -206
- package/dist/template/src/client/update-policy-editor.test.ts +101 -29
- package/dist/template/src/client/update-policy-editor.tsx +454 -320
- package/dist/template/src/client/use-filtered-results.ts +55 -0
- package/dist/template/src/server/controllers/manifest.test.ts +23 -3
- package/dist/template/src/server/controllers/manifest.ts +15 -1
- package/dist/template/src/server/devices/audience.ts +9 -5
- package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
- package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
- package/dist/template/src/server/lib/admin-updates.ts +160 -534
- package/dist/template/src/server/lib/distribution-history.ts +97 -0
- package/dist/template/src/server/lib/supabase.js +24 -0
- package/dist/template/src/server/lib/supabase.test.ts +38 -1
- package/dist/template/src/server/lib/update-policy.test.ts +20 -0
- package/dist/template/src/server/lib/update-policy.ts +23 -10
- package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
- package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
- package/dist/template/src/server/manifest/manifest-values.ts +21 -13
- package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
- package/dist/template/tsconfig.json +2 -2
- package/dist/template-manifest.json +446 -301
- package/package.json +1 -1
- package/dist/template/scripts/lib/device-identity.test.ts +0 -29
- package/dist/template/scripts/lib/ota-client.test.ts +0 -55
- package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
- package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
- package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
- package/dist/template/templates/expo-app/ota-client/README.md +0 -73
- package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
- package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
- package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
- package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
- package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
- package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
- package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import { createHash, verify } from "node:crypto";
|
|
2
|
+
import { act, useSyncExternalStore } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { createUpdateController } from "patched-ota-client/model/update-controller";
|
|
6
|
+
import { OtaUpdateOverlay } from "patched-ota-client/ui/ota-updates";
|
|
7
|
+
|
|
8
|
+
vi.mock(
|
|
9
|
+
"patched-ota-client/model/hooks/useOtaUpdates",
|
|
10
|
+
() => ({
|
|
11
|
+
useOtaUpdates: () => {
|
|
12
|
+
throw new Error("Use the injected native bridge");
|
|
13
|
+
},
|
|
14
|
+
}),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const { origin, publicKey, cookie, platforms } = JSON.parse(
|
|
18
|
+
process.env.OTA_LIFECYCLE_FIXTURE,
|
|
19
|
+
);
|
|
20
|
+
expect(new URL(origin).hostname).toBe("127.0.0.1");
|
|
21
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
22
|
+
|
|
23
|
+
async function admin(path, method = "GET", body) {
|
|
24
|
+
const res = await fetch(origin + path, {
|
|
25
|
+
method,
|
|
26
|
+
headers: { cookie, "content-type": "application/json" },
|
|
27
|
+
body: JSON.stringify(body),
|
|
28
|
+
});
|
|
29
|
+
const data = await res.json();
|
|
30
|
+
expect(res.status, JSON.stringify(data)).toBe(200);
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
async function stop(blocked) {
|
|
34
|
+
const path = "/api/admin/distribution-control";
|
|
35
|
+
const current = await admin(path);
|
|
36
|
+
if (blocked !== current.blocked)
|
|
37
|
+
await admin(path, "PUT", {
|
|
38
|
+
blocked,
|
|
39
|
+
expectedVersion: current.version,
|
|
40
|
+
reason: blocked ? "Local client rehearsal" : undefined,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// This bridge substitutes for expo-updates storage, native reload, connectivity and store handoff.
|
|
45
|
+
// Network selection, signature verification, real asset bytes, the client controller and the overlay all run.
|
|
46
|
+
function device(platform, channel, runtime = "1.0.0") {
|
|
47
|
+
const state = {
|
|
48
|
+
online: true,
|
|
49
|
+
failAsset: false,
|
|
50
|
+
running: null,
|
|
51
|
+
cached: null,
|
|
52
|
+
pending: null,
|
|
53
|
+
checks: 0,
|
|
54
|
+
downloads: 0,
|
|
55
|
+
requests: 0,
|
|
56
|
+
postponedId: null,
|
|
57
|
+
reloads: 0,
|
|
58
|
+
store: null,
|
|
59
|
+
now: 0,
|
|
60
|
+
};
|
|
61
|
+
async function network(url, init) {
|
|
62
|
+
if (!state.online) throw new Error("Offline");
|
|
63
|
+
expect(new URL(url).origin).toBe(origin);
|
|
64
|
+
state.requests++;
|
|
65
|
+
return fetch(url, init);
|
|
66
|
+
}
|
|
67
|
+
async function manifest() {
|
|
68
|
+
const response = await network(origin + "/api/manifest", {
|
|
69
|
+
headers: {
|
|
70
|
+
"expo-platform": platform,
|
|
71
|
+
"expo-runtime-version": runtime,
|
|
72
|
+
"expo-channel-name": channel,
|
|
73
|
+
"expo-protocol-version": "1",
|
|
74
|
+
"expo-expect-signature": "sig, keyid=main",
|
|
75
|
+
...(state.running
|
|
76
|
+
? { "expo-current-update-id": state.running.id }
|
|
77
|
+
: {}),
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
expect(response.status).toBe(200);
|
|
81
|
+
const boundary = response.headers
|
|
82
|
+
.get("content-type")
|
|
83
|
+
.match(/boundary="?([^";]+)/)[1];
|
|
84
|
+
const raw = await response.text();
|
|
85
|
+
const part = raw
|
|
86
|
+
.split("--" + boundary)
|
|
87
|
+
.find((p) => /name="(?:manifest|directive)"/i.test(p));
|
|
88
|
+
const [headers, body] = part.trim().split("\r\n\r\n");
|
|
89
|
+
const sig = headers.match(/expo-signature: sig="([^"]+)"/i)[1];
|
|
90
|
+
expect(
|
|
91
|
+
verify(
|
|
92
|
+
"RSA-SHA256",
|
|
93
|
+
Buffer.from(body),
|
|
94
|
+
publicKey,
|
|
95
|
+
Buffer.from(sig, "base64"),
|
|
96
|
+
),
|
|
97
|
+
).toBe(true);
|
|
98
|
+
const value = JSON.parse(body);
|
|
99
|
+
return value.type === "noUpdateAvailable" ? null : value;
|
|
100
|
+
}
|
|
101
|
+
function launchCached() {
|
|
102
|
+
if (!state.cached) throw new Error("No cached bundle");
|
|
103
|
+
state.running = state.cached.manifest;
|
|
104
|
+
state.pending = null;
|
|
105
|
+
}
|
|
106
|
+
function launch() {
|
|
107
|
+
const controller = createUpdateController({
|
|
108
|
+
enabled: true,
|
|
109
|
+
start() {},
|
|
110
|
+
identity: async () => ({ installationId: null, deviceId: null }),
|
|
111
|
+
readPostponedId: async () => state.postponedId,
|
|
112
|
+
writePostponedId: async (id) => { state.postponedId = id; },
|
|
113
|
+
now: () => state.now,
|
|
114
|
+
isActive: () => true,
|
|
115
|
+
runningCandidate: () =>
|
|
116
|
+
state.running && { type: "new", manifest: state.running },
|
|
117
|
+
check: async () => {
|
|
118
|
+
state.checks++;
|
|
119
|
+
const value = await manifest();
|
|
120
|
+
return { isAvailable: Boolean(value), manifest: value };
|
|
121
|
+
},
|
|
122
|
+
fetch: async () => {
|
|
123
|
+
state.downloads++;
|
|
124
|
+
const value = await manifest();
|
|
125
|
+
if (!value) return { isNew: false };
|
|
126
|
+
const buffers = [];
|
|
127
|
+
for (const asset of [value.launchAsset, ...value.assets]) {
|
|
128
|
+
if (state.failAsset)
|
|
129
|
+
throw new Error("Connection lost during download");
|
|
130
|
+
const response = await network(asset.url);
|
|
131
|
+
if (!response.ok)
|
|
132
|
+
throw new Error("Asset request failed " + response.status);
|
|
133
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
134
|
+
expect(createHash("sha256").update(bytes).digest("base64url")).toBe(
|
|
135
|
+
asset.hash,
|
|
136
|
+
);
|
|
137
|
+
buffers.push(bytes);
|
|
138
|
+
}
|
|
139
|
+
state.cached = { manifest: value, buffers };
|
|
140
|
+
state.pending = { type: "new", manifest: value };
|
|
141
|
+
return { isNew: true, manifest: value };
|
|
142
|
+
},
|
|
143
|
+
reload: async () => {
|
|
144
|
+
state.reloads++;
|
|
145
|
+
launchCached();
|
|
146
|
+
},
|
|
147
|
+
openStore: async (payload) => {
|
|
148
|
+
state.store = payload;
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
controller.configure(Symbol("app"), {
|
|
152
|
+
autoCheck: true,
|
|
153
|
+
autoUpdate: false,
|
|
154
|
+
autoReload: false,
|
|
155
|
+
});
|
|
156
|
+
return controller;
|
|
157
|
+
}
|
|
158
|
+
return { launch, launchCached, state };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function Screen({ model }) {
|
|
162
|
+
const snapshot = useSyncExternalStore(model.subscribe, model.getSnapshot);
|
|
163
|
+
return (
|
|
164
|
+
<OtaUpdateOverlay
|
|
165
|
+
controller={{ ...model, ...snapshot, isBusy: snapshot.status !== "idle" }}
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
let root;
|
|
170
|
+
let host;
|
|
171
|
+
async function screen(model) {
|
|
172
|
+
if (root) await act(async () => root.unmount());
|
|
173
|
+
host?.remove();
|
|
174
|
+
host = document.createElement("div");
|
|
175
|
+
document.body.append(host);
|
|
176
|
+
root = createRoot(host);
|
|
177
|
+
await act(async () => root.render(<Screen model={model} />));
|
|
178
|
+
}
|
|
179
|
+
const text = () => host.textContent;
|
|
180
|
+
// The controller waits for the real HTTP server and object store in this suite.
|
|
181
|
+
const waitForIdle = (model) =>
|
|
182
|
+
vi.waitFor(() => expect(model.getSnapshot().status).toBe("idle"), { timeout: 15_000 });
|
|
183
|
+
const press = async (label, model) => {
|
|
184
|
+
const element = [...host.querySelectorAll("button")].find(
|
|
185
|
+
(el) => el.textContent === label,
|
|
186
|
+
);
|
|
187
|
+
expect(element, label).toBeDefined();
|
|
188
|
+
await act(async () => {
|
|
189
|
+
element.click();
|
|
190
|
+
await waitForIdle(model);
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
async function check(model) {
|
|
194
|
+
await act(async () => {
|
|
195
|
+
await model.check();
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
afterEach(async () => {
|
|
199
|
+
if (root) await act(async () => root.unmount());
|
|
200
|
+
root = undefined;
|
|
201
|
+
host?.remove();
|
|
202
|
+
await stop(false);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe.each(["ios", "android"])(
|
|
206
|
+
"%s signed HTTP delivery and client overlay",
|
|
207
|
+
(platform) => {
|
|
208
|
+
const scopes = platforms[platform];
|
|
209
|
+
it("offers manual downloads, dismisses until remount, retries and restarts cached bytes offline", async () => {
|
|
210
|
+
const phone = device(platform, scopes.manual.channel);
|
|
211
|
+
const app = phone.launch();
|
|
212
|
+
await screen(app);
|
|
213
|
+
await act(async () => {
|
|
214
|
+
app.automaticCheck();
|
|
215
|
+
await waitForIdle(app);
|
|
216
|
+
});
|
|
217
|
+
expect(phone.state.checks).toBe(1);
|
|
218
|
+
expect(phone.state.downloads).toBe(0);
|
|
219
|
+
expect(text()).toContain("Update available");
|
|
220
|
+
await press("Later", app);
|
|
221
|
+
await check(app);
|
|
222
|
+
expect(host.querySelector("[role=dialog]")).toBeNull();
|
|
223
|
+
await screen(app);
|
|
224
|
+
expect(text()).toContain("Download");
|
|
225
|
+
phone.state.failAsset = true;
|
|
226
|
+
await press("Download", app);
|
|
227
|
+
expect(text()).toContain("Connection lost");
|
|
228
|
+
expect(phone.state.cached).toBeNull();
|
|
229
|
+
phone.state.failAsset = false;
|
|
230
|
+
await press("Download", app);
|
|
231
|
+
expect(phone.state.cached.buffers.length).toBe(2);
|
|
232
|
+
expect(phone.state.running).toBeNull();
|
|
233
|
+
const restored = phone.launch();
|
|
234
|
+
await screen(restored);
|
|
235
|
+
await act(async () => {
|
|
236
|
+
await restored.syncPending(phone.state.pending);
|
|
237
|
+
});
|
|
238
|
+
expect(text()).toContain("Restart");
|
|
239
|
+
await stop(true);
|
|
240
|
+
phone.state.online = false;
|
|
241
|
+
const requests = phone.state.requests;
|
|
242
|
+
await press("Restart", restored);
|
|
243
|
+
expect(phone.state.requests).toBe(requests);
|
|
244
|
+
expect(phone.state.running.id).toBe(phone.state.cached.manifest.id);
|
|
245
|
+
const reopened = phone.launch();
|
|
246
|
+
await screen(reopened);
|
|
247
|
+
await act(async () => {
|
|
248
|
+
await expect(reopened.check()).rejects.toThrow("Offline");
|
|
249
|
+
});
|
|
250
|
+
expect(host.querySelector("[role=dialog]")).toBeNull();
|
|
251
|
+
phone.state.online = true;
|
|
252
|
+
await check(reopened);
|
|
253
|
+
expect(phone.state.running.id).toBe(phone.state.cached.manifest.id);
|
|
254
|
+
await stop(false);
|
|
255
|
+
await check(reopened);
|
|
256
|
+
expect(reopened.getSnapshot().available).toBe(false);
|
|
257
|
+
const incompatible = device(
|
|
258
|
+
platform,
|
|
259
|
+
scopes.manual.channel,
|
|
260
|
+
"unpublished",
|
|
261
|
+
).launch();
|
|
262
|
+
await screen(incompatible);
|
|
263
|
+
await check(incompatible);
|
|
264
|
+
expect(incompatible.getSnapshot().available).toBe(false);
|
|
265
|
+
expect(text()).toBe("");
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("downloads after Postpone, retries quietly, and launches cached bytes offline on the next cold start", async () => {
|
|
269
|
+
const phone = device(platform, scopes["manual-postpone"].channel);
|
|
270
|
+
const app = phone.launch();
|
|
271
|
+
app.configure(Symbol(), { autoUpdate: true, autoReload: true });
|
|
272
|
+
await screen(app);
|
|
273
|
+
await check(app);
|
|
274
|
+
expect(phone.state.downloads).toBe(0);
|
|
275
|
+
expect(text()).toContain("Postpone");
|
|
276
|
+
phone.state.failAsset = true;
|
|
277
|
+
await press("Postpone", app);
|
|
278
|
+
expect(host.querySelector("[role=dialog]")).toBeNull();
|
|
279
|
+
expect(phone.state.cached).toBeNull();
|
|
280
|
+
phone.state.failAsset = false;
|
|
281
|
+
const resumed = phone.launch();
|
|
282
|
+
resumed.configure(Symbol(), { autoUpdate: true, autoReload: true });
|
|
283
|
+
await screen(resumed);
|
|
284
|
+
await check(resumed);
|
|
285
|
+
expect(phone.state.cached.manifest.id).toBe(phone.state.postponedId);
|
|
286
|
+
await check(resumed);
|
|
287
|
+
expect(host.querySelector("[role=dialog]")).toBeNull();
|
|
288
|
+
expect(phone.state.downloads).toBe(2);
|
|
289
|
+
expect(phone.state.reloads).toBe(0);
|
|
290
|
+
expect(phone.state.running).toBeNull();
|
|
291
|
+
phone.state.online = false;
|
|
292
|
+
phone.launchCached();
|
|
293
|
+
await phone.launch().initialize();
|
|
294
|
+
expect(phone.state.postponedId).toBeNull();
|
|
295
|
+
expect(phone.state.running.id).toBe(phone.state.cached.manifest.id);
|
|
296
|
+
});
|
|
297
|
+
it("keeps Download and Restart available to a user who accepts instead", async () => {
|
|
298
|
+
const phone = device(platform, scopes["manual-postpone"].channel);
|
|
299
|
+
const model = phone.launch();
|
|
300
|
+
await screen(model);
|
|
301
|
+
await check(model);
|
|
302
|
+
await press("Download", model);
|
|
303
|
+
expect(phone.state.downloads).toBe(1);
|
|
304
|
+
await press("Restart", model);
|
|
305
|
+
expect(phone.state.reloads).toBe(1);
|
|
306
|
+
expect(phone.state.running.id).toBe(phone.state.cached.manifest.id);
|
|
307
|
+
});
|
|
308
|
+
it("keeps background delivery silent, prevents a fresh download during a stop, and retains a cached candidate", async () => {
|
|
309
|
+
const phone = device(platform, scopes.background.channel);
|
|
310
|
+
const app = phone.launch();
|
|
311
|
+
await screen(app);
|
|
312
|
+
await stop(true);
|
|
313
|
+
await check(app);
|
|
314
|
+
expect(phone.state.downloads).toBe(0);
|
|
315
|
+
expect(text()).toBe("");
|
|
316
|
+
await stop(false);
|
|
317
|
+
await check(app);
|
|
318
|
+
expect(app.getSnapshot().pending).toBe(true);
|
|
319
|
+
expect(phone.state.downloads).toBe(1);
|
|
320
|
+
expect(phone.state.reloads).toBe(0);
|
|
321
|
+
expect(text()).toBe("");
|
|
322
|
+
await stop(true);
|
|
323
|
+
await check(app);
|
|
324
|
+
expect(app.getSnapshot().pending).toBe(true);
|
|
325
|
+
expect(phone.state.downloads).toBe(1);
|
|
326
|
+
expect(
|
|
327
|
+
(await fetch(phone.state.cached.manifest.launchAsset.url)).status,
|
|
328
|
+
).toBe(503);
|
|
329
|
+
phone.launchCached();
|
|
330
|
+
const launched = phone.launch();
|
|
331
|
+
await screen(launched);
|
|
332
|
+
await check(launched);
|
|
333
|
+
expect(text()).toBe("");
|
|
334
|
+
expect(phone.state.running.id).toBe(phone.state.cached.manifest.id);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("silently fetches and applies a signed immediate required update, and offers retry after failure", async () => {
|
|
338
|
+
const phone = device(platform, scopes.immediate.channel);
|
|
339
|
+
const app = phone.launch();
|
|
340
|
+
await screen(app);
|
|
341
|
+
phone.state.failAsset = true;
|
|
342
|
+
await act(async () => {
|
|
343
|
+
await expect(app.check()).rejects.toThrow("Connection lost");
|
|
344
|
+
});
|
|
345
|
+
expect(text()).toContain("Retry");
|
|
346
|
+
expect(text()).not.toContain("Later");
|
|
347
|
+
expect(phone.state.reloads).toBe(0);
|
|
348
|
+
phone.state.failAsset = false;
|
|
349
|
+
await press("Retry", app);
|
|
350
|
+
expect(phone.state.reloads).toBe(1);
|
|
351
|
+
expect(phone.state.running.id).toBe(phone.state.cached.manifest.id);
|
|
352
|
+
const reopened = phone.launch();
|
|
353
|
+
await screen(reopened);
|
|
354
|
+
await check(reopened);
|
|
355
|
+
expect(text()).toBe("");
|
|
356
|
+
expect(phone.state.reloads).toBe(1);
|
|
357
|
+
const automatic = device(platform, scopes.immediate.channel);
|
|
358
|
+
const healthy = automatic.launch();
|
|
359
|
+
await screen(healthy);
|
|
360
|
+
await act(async () => {
|
|
361
|
+
healthy.automaticCheck();
|
|
362
|
+
await waitForIdle(healthy);
|
|
363
|
+
});
|
|
364
|
+
expect(automatic.state.downloads).toBe(1);
|
|
365
|
+
expect(automatic.state.reloads).toBe(1);
|
|
366
|
+
expect(text()).toBe("");
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("checks required Guard behavior before download, across a failed fetch, a stop and a replacement", async () => {
|
|
370
|
+
const phone = device(platform, scopes.required.channel);
|
|
371
|
+
const app = phone.launch();
|
|
372
|
+
phone.state.failAsset = true;
|
|
373
|
+
await screen(app);
|
|
374
|
+
await act(async () => {
|
|
375
|
+
await expect(app.check()).rejects.toThrow("Connection lost");
|
|
376
|
+
});
|
|
377
|
+
expect(text()).toContain("Update required");
|
|
378
|
+
expect(text()).not.toContain("Later");
|
|
379
|
+
await act(async () => {
|
|
380
|
+
host
|
|
381
|
+
.querySelector("[role=dialog]")
|
|
382
|
+
.dispatchEvent(
|
|
383
|
+
new KeyboardEvent("keydown", { key: "Escape", bubbles: true }),
|
|
384
|
+
);
|
|
385
|
+
});
|
|
386
|
+
expect(text()).toContain("Retry");
|
|
387
|
+
const reopened = phone.launch();
|
|
388
|
+
await screen(reopened);
|
|
389
|
+
await act(async () => {
|
|
390
|
+
await expect(reopened.check()).rejects.toThrow("Connection lost");
|
|
391
|
+
});
|
|
392
|
+
expect(text()).toContain("Update required");
|
|
393
|
+
await stop(true);
|
|
394
|
+
await press("Retry", reopened);
|
|
395
|
+
expect(reopened.getSnapshot().blocked).toBe(false);
|
|
396
|
+
await stop(false);
|
|
397
|
+
phone.state.failAsset = false;
|
|
398
|
+
await check(reopened);
|
|
399
|
+
expect(text()).toContain("Restart");
|
|
400
|
+
await stop(true);
|
|
401
|
+
await check(reopened);
|
|
402
|
+
expect(reopened.getSnapshot().blocked).toBe(true);
|
|
403
|
+
expect(reopened.getSnapshot().pending).toBe(true);
|
|
404
|
+
await stop(false);
|
|
405
|
+
const waitingPhone = device(platform, scopes.required.channel);
|
|
406
|
+
waitingPhone.state.failAsset = true;
|
|
407
|
+
const waiting = waitingPhone.launch();
|
|
408
|
+
await expect(waiting.check()).rejects.toThrow("Connection lost");
|
|
409
|
+
expect(waiting.getSnapshot().blockReason).toBe("ota-force-update");
|
|
410
|
+
await admin(scopes.required.replacement + "/deactivate", "POST", {
|
|
411
|
+
disabled: false,
|
|
412
|
+
});
|
|
413
|
+
await waiting.retry();
|
|
414
|
+
expect(waiting.getSnapshot().blocked).toBe(false);
|
|
415
|
+
expect(waiting.getSnapshot().pending).toBe(false);
|
|
416
|
+
await check(reopened);
|
|
417
|
+
expect(reopened.getSnapshot().blockReason).toBe("ota-force-update");
|
|
418
|
+
await press("Restart", reopened);
|
|
419
|
+
const fulfilled = phone.launch();
|
|
420
|
+
await screen(fulfilled);
|
|
421
|
+
await act(async () => {
|
|
422
|
+
await fulfilled.initialize();
|
|
423
|
+
});
|
|
424
|
+
expect(fulfilled.getSnapshot().blocked).toBe(false);
|
|
425
|
+
await check(fulfilled);
|
|
426
|
+
expect(text()).toContain("Update available");
|
|
427
|
+
expect(text()).not.toContain("Update required");
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it("keeps the store Guard separate from OTA and observes replacement on explicit retry", async () => {
|
|
431
|
+
const phone = device(platform, scopes.store.channel);
|
|
432
|
+
const app = phone.launch();
|
|
433
|
+
await screen(app);
|
|
434
|
+
await check(app);
|
|
435
|
+
expect(text()).toContain("Open store");
|
|
436
|
+
expect(text()).not.toContain("Download");
|
|
437
|
+
await press("Open store", app);
|
|
438
|
+
expect(phone.state.store.url).toBe("https://example.invalid/store");
|
|
439
|
+
expect(phone.state.downloads).toBe(0);
|
|
440
|
+
await admin(scopes.store.replacement + "/deactivate", "POST", {
|
|
441
|
+
disabled: false,
|
|
442
|
+
});
|
|
443
|
+
phone.state.now += 180000;
|
|
444
|
+
expect(phone.state.checks).toBe(1);
|
|
445
|
+
expect(text()).toContain("Open store");
|
|
446
|
+
await press("Check again", app);
|
|
447
|
+
expect(app.getSnapshot().blocked).toBe(false);
|
|
448
|
+
expect(text()).toContain("Update available");
|
|
449
|
+
// Stopping a public replacement must not silently reinstate its store Guard.
|
|
450
|
+
await admin(scopes.store.replacement + "/deactivate", "POST", { disabled: true });
|
|
451
|
+
await check(app);
|
|
452
|
+
expect(app.getSnapshot().available).toBe(false);
|
|
453
|
+
expect(app.getSnapshot().blocked).toBe(false);
|
|
454
|
+
const { scopes: history } = await admin("/api/admin/distribution-history");
|
|
455
|
+
const stopped = history.find((s) => s.channel === scopes.store.channel && s.platform === platform);
|
|
456
|
+
expect(stopped.current).toBeNull();
|
|
457
|
+
await admin("/api/admin/distribution-history/restore", "POST", {
|
|
458
|
+
updateId: stopped.previous.updateId, expectedRevision: stopped.revision,
|
|
459
|
+
});
|
|
460
|
+
await check(app);
|
|
461
|
+
expect(text()).toContain("Open store");
|
|
462
|
+
|
|
463
|
+
});
|
|
464
|
+
},
|
|
465
|
+
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { defineConfig } from "vitest/config";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
resolve: {
|
|
6
|
+
alias: {
|
|
7
|
+
"patched-ota-client": process.env.OTA_E2E_CLIENT_DIRECTORY!,
|
|
8
|
+
"react-native": fileURLToPath(
|
|
9
|
+
new URL("../fixtures/react-native-ui.tsx", import.meta.url),
|
|
10
|
+
),
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
test: {
|
|
14
|
+
include: ["scripts/tests/e2e/client-lifecycle.scenario.jsx"],
|
|
15
|
+
environment: "jsdom",
|
|
16
|
+
testTimeout: 90_000,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { exerciseDeviceFavorites } from "./device-favorites.mjs";
|
|
4
|
+
import { exercisePolicyEditor } from "./policy.mjs";
|
|
5
|
+
import { exerciseReleaseConsole, exercisePublicRestore } from "./releases.mjs";
|
|
6
|
+
import { exerciseInstallations } from "./installations.mjs";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { chromium, expect } from "@playwright/test";
|
|
9
|
+
|
|
10
|
+
export async function exerciseConsole(fixture) {
|
|
11
|
+
const { origin, password } = fixture;
|
|
12
|
+
const browser = await chromium.launch();
|
|
13
|
+
try {
|
|
14
|
+
const page = await browser.newPage({
|
|
15
|
+
viewport: { width: 1440, height: 900 },
|
|
16
|
+
});
|
|
17
|
+
page.setDefaultTimeout(30000);
|
|
18
|
+
const errors = [];
|
|
19
|
+
page.on("pageerror", (error) => errors.push(error.message));
|
|
20
|
+
await page.goto(origin + "/updates");
|
|
21
|
+
await expect(page).toHaveURL(/\/login$/);
|
|
22
|
+
await page.locator('input[autocomplete="username"]').fill("admin");
|
|
23
|
+
await page.locator('input[type="password"]').fill(password);
|
|
24
|
+
await page.getByRole("button", { name: "Sign in" }).click();
|
|
25
|
+
await expect(page).toHaveURL(/\/updates$/);
|
|
26
|
+
await exerciseReleaseConsole(page, password);
|
|
27
|
+
await exercisePolicyEditor(page, fixture);
|
|
28
|
+
await exerciseDeviceFavorites(page, fixture);
|
|
29
|
+
await exercisePublicRestore(page, fixture);
|
|
30
|
+
await page.goto(origin + "/updates/embedded");
|
|
31
|
+
await expect(page.getByText("beta", { exact: true })).toBeVisible();
|
|
32
|
+
await page.getByRole("button", { name: "Delete", exact: true }).click();
|
|
33
|
+
const dialog = page.getByRole("dialog");
|
|
34
|
+
await expect(dialog.getByRole("button", { name: "Cancel" })).toBeFocused();
|
|
35
|
+
await page.keyboard.press("Escape");
|
|
36
|
+
await expect(dialog).toBeHidden();
|
|
37
|
+
await expect(
|
|
38
|
+
page.getByRole("button", { name: "Delete", exact: true }),
|
|
39
|
+
).toBeFocused();
|
|
40
|
+
for (const width of [390, 1440]) {
|
|
41
|
+
await page.setViewportSize({ width, height: 900 });
|
|
42
|
+
for (const route of [
|
|
43
|
+
"/updates",
|
|
44
|
+
"/updates/devices",
|
|
45
|
+
"/updates/embedded",
|
|
46
|
+
"/updates/emergency-redirects",
|
|
47
|
+
]) {
|
|
48
|
+
await page.goto(origin + route);
|
|
49
|
+
await expect(page.getByRole("heading", { level: 1 })).toBeVisible();
|
|
50
|
+
await expect
|
|
51
|
+
.poll(() =>
|
|
52
|
+
page.evaluate(
|
|
53
|
+
() => document.documentElement.scrollWidth - window.innerWidth,
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
.toBeLessThanOrEqual(1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
await exerciseInstallations(page);
|
|
60
|
+
if (process.env.OTA_E2E_ARTIFACTS) {
|
|
61
|
+
const output = process.env.OTA_E2E_ARTIFACTS;
|
|
62
|
+
await mkdir(output, { recursive: true });
|
|
63
|
+
await page.evaluate(() =>
|
|
64
|
+
localStorage.setItem("ota-console-theme", "dark"),
|
|
65
|
+
);
|
|
66
|
+
await page.getByLabel("Interface language").selectOption("ru");
|
|
67
|
+
for (const [route, name] of [
|
|
68
|
+
["/updates", "releases"],
|
|
69
|
+
["/updates/devices", "installations"],
|
|
70
|
+
]) {
|
|
71
|
+
await page.goto(origin + route);
|
|
72
|
+
await page.waitForLoadState("networkidle");
|
|
73
|
+
await page.screenshot({
|
|
74
|
+
style: "nextjs-portal { display:none; }",
|
|
75
|
+
path: path.join(output, name + ".png"),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
assert.deepEqual(errors, []);
|
|
80
|
+
console.log(
|
|
81
|
+
"PASS browser login, release navigation, embedded deletion cancellation and focus, desktop/mobile layouts",
|
|
82
|
+
);
|
|
83
|
+
} finally {
|
|
84
|
+
await browser.close();
|
|
85
|
+
}
|
|
86
|
+
}
|