@adea-ai/app-framework 0.39.3 → 0.39.4
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 +158 -52
- package/dist/app/application.d.ts +0 -1
- package/dist/app/application.js +8 -6
- package/dist/app/create-application.js +3 -11
- package/dist/app/service-registry.d.ts +0 -1
- package/dist/app/service-registry.js +3 -3
- package/dist/app/value-guards.d.ts +2 -0
- package/dist/app/value-guards.js +6 -1
- package/dist/appearance/appearance-host.d.ts +1 -1
- package/dist/appearance/appearance-host.js +11 -2
- package/dist/appearance/appearance-preferences.d.ts +0 -1
- package/dist/appearance/custom-theme-import.d.ts +8 -2
- package/dist/appearance/custom-theme-import.js +58 -23
- package/dist/appearance/custom-theme-library.d.ts +3 -3
- package/dist/appearance/custom-theme-library.js +3 -3
- package/dist/appearance/theme-file-importer.d.ts +1 -1
- package/dist/appearance/theme-file-importer.js +2 -1
- package/dist/appearance/theme-library-mutation.d.ts +7 -0
- package/dist/appearance/theme-library-mutation.js +10 -2
- package/dist/appearance/theme-library-store.d.ts +17 -13
- package/dist/appearance/theme-library-store.js +35 -22
- package/dist/appearance/theme-record-adapter.js +1 -2
- package/dist/appearance/theme-registry.js +0 -1
- package/dist/cli/cli-runner.d.ts +3 -2
- package/dist/cli/cli-runner.js +5 -10
- package/dist/cli/release-assets-plan-cli.js +2 -2
- package/dist/cli/release-cut-cli.js +2 -3
- package/dist/cli/release-descriptor-staging-cli.js +2 -2
- package/dist/cli/release-finalize-cli.js +3 -3
- package/dist/cli/release-promote-cli.js +2 -2
- package/dist/cli/release-publish-cli.js +2 -2
- package/dist/cli/release-sign-cli.js +2 -1
- package/dist/cli/release-step-cli.js +2 -2
- package/dist/desktop/channel-proof.js +27 -11
- package/dist/desktop/client-assets.d.ts +6 -1
- package/dist/desktop/client-assets.js +16 -3
- package/dist/desktop/client-dev-proxy.d.ts +0 -2
- package/dist/desktop/client-dev-proxy.js +2 -2
- package/dist/desktop/desktop-client.js +2 -1
- package/dist/desktop/desktop-gateway.js +24 -82
- package/dist/desktop/desktop-host-websocket.d.ts +5 -1
- package/dist/desktop/desktop-host-websocket.js +9 -7
- package/dist/desktop/desktop-host.d.ts +5 -0
- package/dist/desktop/desktop-host.js +3 -0
- package/dist/desktop/desktop-stream.js +5 -10
- package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
- package/dist/desktop/typed-array-intrinsics.js +13 -1
- package/dist/developer-app/developer-app.d.ts +1 -1
- package/dist/developer-app/developer-app.js +26 -13
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-artifact.d.ts +1 -0
- package/dist/installer/command-artifact.js +47 -27
- package/dist/installer/installed-payload.js +3 -1
- package/dist/installer/installer-ci-bootstrap.js +5 -6
- package/dist/installer/installer-ci-preflight.js +3 -3
- package/dist/installer/installer-identity.d.ts +0 -22
- package/dist/installer/installer-identity.js +3 -53
- package/dist/installer/installer-image-mount.d.ts +0 -1
- package/dist/installer/installer-image-mount.js +1 -1
- package/dist/installer/installer-observation.d.ts +5 -5
- package/dist/installer/installer-observation.js +32 -47
- package/dist/installer/installer-process-cleanup.js +2 -2
- package/dist/installer/installer-renderer-evidence.js +7 -28
- package/dist/installer/installer-upgrade-command.js +8 -20
- package/dist/installer/installer-worker-guard.js +3 -3
- package/dist/native/cef-helper.js +4 -4
- package/dist/native/desktop-build.d.ts +0 -3
- package/dist/native/desktop-build.js +2 -2
- package/dist/native/electrobun-source-patch.d.ts +4 -0
- package/dist/native/electrobun-source-patch.js +5 -1
- package/dist/native/native-utilities.js +4 -3
- package/dist/native/pinned-download.d.ts +16 -0
- package/dist/native/pinned-download.js +42 -0
- package/dist/native/posix-launcher-build.js +15 -35
- package/dist/native/posix-tree-removal.js +21 -33
- package/dist/native/sidecar-services.d.ts +0 -2
- package/dist/native/sidecar-services.js +1 -1
- package/dist/native/sidecar.d.ts +3 -0
- package/dist/native/sidecar.js +15 -2
- package/dist/native/window-surface-store.js +3 -3
- package/dist/native/windows-extractor-build.d.ts +6 -16
- package/dist/native/windows-extractor-build.js +11 -14
- package/dist/release/feed-release-cut.d.ts +2 -6
- package/dist/release/feed-release-cut.js +5 -93
- package/dist/release/feed-state.js +1 -5
- package/dist/release/github-release-cut.js +5 -66
- package/dist/release/github-release-provenance.d.ts +2 -0
- package/dist/release/github-release-provenance.js +4 -7
- package/dist/release/github-release-publisher.js +2 -2
- package/dist/release/github-release-qualification.js +3 -3
- package/dist/release/local-release.d.ts +3 -3
- package/dist/release/local-release.js +12 -23
- package/dist/release/qualification-run.js +1 -1
- package/dist/release/release-assets-plan.js +1 -1
- package/dist/release/release-config.d.ts +7 -15
- package/dist/release/release-config.js +25 -29
- package/dist/release/release-cut-command.d.ts +1 -1
- package/dist/release/release-cut-command.js +1 -1
- package/dist/release/release-cut.d.ts +5 -32
- package/dist/release/release-cut.js +9 -55
- package/dist/release/release-descriptor-staging.js +3 -8
- package/dist/release/release-promotion.js +2 -1
- package/dist/release/release-publish-command.js +5 -15
- package/dist/release/release-qualification.js +1 -1
- package/dist/shared/bounded-body.d.ts +33 -0
- package/dist/shared/bounded-body.js +102 -0
- package/dist/shared/file-system.d.ts +12 -0
- package/dist/shared/file-system.js +40 -0
- package/dist/shell/app-shell.js +29 -14
- package/dist/shell/app-utilities.d.ts +2 -1
- package/dist/shell/app-utilities.js +2 -1
- package/dist/shell/application-menu.d.ts +1 -1
- package/dist/shell/application-menu.js +7 -3
- package/dist/shell/poll.d.ts +27 -0
- package/dist/shell/poll.js +88 -0
- package/dist/update-helper.bundle.js +268 -144
- package/dist/updates/channel-update-manager.js +0 -1
- package/dist/updates/desktop-updater.d.ts +9 -0
- package/dist/updates/desktop-updater.js +103 -50
- package/dist/updates/feed/release-feed.d.ts +7 -4
- package/dist/updates/feed/release-feed.js +3 -7
- package/dist/updates/feed/release-location.js +6 -26
- package/dist/updates/feed/release-version.d.ts +7 -2
- package/dist/updates/feed/release-version.js +9 -2
- package/dist/updates/feed/signed-release.d.ts +1 -1
- package/dist/updates/feed/signed-release.js +2 -2
- package/dist/updates/feed/update-discovery.js +2 -6
- package/dist/updates/helper/launch-gate-recovery.js +28 -78
- package/dist/updates/helper/resume-staging.d.ts +14 -3
- package/dist/updates/helper/resume-staging.js +23 -37
- package/dist/updates/helper/update-helper.d.ts +6 -2
- package/dist/updates/helper/update-helper.js +38 -33
- package/dist/updates/helper/update-resume.js +9 -6
- package/dist/updates/install/update-extraction.js +28 -8
- package/dist/updates/install/update-handoff-plan.d.ts +0 -1
- package/dist/updates/install/update-handoff-plan.js +3 -4
- package/dist/updates/install/update-swap-stage.js +1 -6
- package/dist/updates/install/update-swap.d.ts +5 -2
- package/dist/updates/install/update-swap.js +193 -72
- package/dist/updates/launch/helper-exit-wait.d.ts +6 -0
- package/dist/updates/launch/helper-exit-wait.js +18 -0
- package/dist/updates/launch/packaged-update-startup.js +8 -6
- package/dist/updates/launch/update-launch-gate.js +7 -14
- package/dist/updates/locks/stable-file.js +4 -1
- package/dist/updates/locks/update-helper-presence.d.ts +12 -0
- package/dist/updates/locks/update-helper-presence.js +27 -0
- package/dist/updates/retention/retention-cleanup.js +10 -9
- package/dist/updates/retention/retention-maintenance.d.ts +40 -0
- package/dist/updates/retention/retention-maintenance.js +95 -0
- package/dist/updates/retention/retention-prune-progress.js +4 -5
- package/dist/updates/retention/retirement-inventory.d.ts +13 -0
- package/dist/updates/retention/retirement-inventory.js +39 -31
- package/dist/updates/retention/retirement-records.d.ts +1 -4
- package/dist/updates/retention/retirement-records.js +18 -32
- package/dist/updates/retention/update-retention-marker.d.ts +4 -0
- package/dist/updates/retention/update-retention-marker.js +9 -14
- package/dist/updates/retention/update-retirement.d.ts +12 -0
- package/dist/updates/retention/update-retirement.js +59 -31
- package/dist/updates/update-adapter.d.ts +1 -23
- package/dist/updates/update-adapter.js +31 -24
- package/dist/updates/update-channel-store.d.ts +2 -1
- package/dist/updates/update-channel-store.js +6 -4
- package/dist/updates/update-manager.js +2 -2
- package/dist/updates/update-services.d.ts +1 -1
- package/dist/updates/update-services.js +9 -4
- package/dist/updates/update-state-store.d.ts +0 -2
- package/dist/updates/update-state-store.js +5 -12
- package/dist/updates/update-state.d.ts +6 -10
- package/dist/updates/update-state.js +1 -1
- package/dist/views/app-help.d.ts +1 -1
- package/dist/views/app-help.js +1 -3
- package/dist/views/appearance-surface.js +15 -8
- package/dist/views/update-surface.d.ts +1 -3
- package/dist/views/update-surface.js +2 -2
- package/package.json +18 -16
- package/src/app/application.tsx +13 -6
- package/src/appearance/appearance-host.tsx +17 -7
- package/src/appearance/appearance-preferences.ts +0 -1
- package/src/appearance/custom-theme-import.ts +99 -26
- package/src/appearance/custom-theme-library.ts +3 -2
- package/src/appearance/theme-file-importer.ts +3 -2
- package/src/appearance/theme-library-mutation.ts +20 -8
- package/src/appearance/theme-library-schema.ts +7 -0
- package/src/appearance/theme-library-store.ts +41 -26
- package/src/desktop/client-assets.ts +27 -12
- package/src/shell/app-shell.tsx +33 -13
- package/src/shell/app-utilities.tsx +7 -1
- package/src/shell/poll.ts +125 -0
- package/src/updates/feed/release-version.ts +11 -3
- package/src/updates/update-adapter.ts +27 -44
- package/src/updates/update-state.ts +7 -13
- package/src/views/app-help.tsx +1 -1
- package/src/views/appearance-surface.tsx +36 -8
- package/src/views/update-surface.tsx +0 -4
- package/templates/application/.github/workflows/release-assets.yml +2 -2
- package/templates/application/README.md +3 -3
- package/dist/native/cef-helper-download.d.ts +0 -1
- package/dist/native/cef-helper-download.js +0 -35
- package/src/desktop/client-response-lifecycle.ts +0 -305
|
@@ -10,6 +10,7 @@ var MAX_ENTRIES = 1e5;
|
|
|
10
10
|
var MAX_EXPANDED_BYTES = 2147483648;
|
|
11
11
|
var MAX_ARCHIVE_BYTES = 1073741824;
|
|
12
12
|
var COMMAND_TIMEOUT_MS = 6e4;
|
|
13
|
+
var OUTPUT_DRAIN_MS = 1e3;
|
|
13
14
|
var SERVICE_SETTLE_MS = 5e3;
|
|
14
15
|
var SERVICE_STOP_MS = 3e4;
|
|
15
16
|
/** The archive's one root directory: the asset name without `.tar.gz`. */
|
|
@@ -114,12 +115,22 @@ async function readCommandArtifact(options) {
|
|
|
114
115
|
bytes
|
|
115
116
|
};
|
|
116
117
|
}
|
|
117
|
-
|
|
118
|
+
/** Read a pipe until it closes or `stop` aborts; a stopped read keeps what arrived. */
|
|
119
|
+
async function boundedText(stream, maximum, stop) {
|
|
118
120
|
const chunks = [];
|
|
119
121
|
let size = 0;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
const reader = stream.getReader();
|
|
123
|
+
const cancel = () => void reader.cancel().catch(() => void 0);
|
|
124
|
+
stop.addEventListener("abort", cancel, { once: true });
|
|
125
|
+
try {
|
|
126
|
+
for (;;) {
|
|
127
|
+
const { done, value } = await reader.read();
|
|
128
|
+
if (done) break;
|
|
129
|
+
size += value.length;
|
|
130
|
+
if (size <= maximum) chunks.push(value);
|
|
131
|
+
}
|
|
132
|
+
} finally {
|
|
133
|
+
stop.removeEventListener("abort", cancel);
|
|
123
134
|
}
|
|
124
135
|
return size > maximum ? void 0 : Buffer.concat(chunks).toString("utf8");
|
|
125
136
|
}
|
|
@@ -284,18 +295,24 @@ async function qualifyCommandArtifact(options) {
|
|
|
284
295
|
});
|
|
285
296
|
const runOnce = async (args) => {
|
|
286
297
|
const child = spawn(args, "pipe");
|
|
287
|
-
const
|
|
288
|
-
const
|
|
298
|
+
const drained = new AbortController();
|
|
299
|
+
const stdout = boundedText(child.stdout, 65536, drained.signal);
|
|
300
|
+
const stderr = boundedText(child.stderr, 65536, drained.signal);
|
|
289
301
|
const status = await exitedWithin(child, COMMAND_TIMEOUT_MS);
|
|
290
302
|
if (status === void 0) {
|
|
291
303
|
child.kill("SIGKILL");
|
|
292
304
|
await child.exited;
|
|
293
305
|
}
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
306
|
+
const timer = setTimeout(() => drained.abort(), options.outputDrainMs ?? OUTPUT_DRAIN_MS);
|
|
307
|
+
try {
|
|
308
|
+
const [text] = await Promise.all([stdout, stderr]);
|
|
309
|
+
return {
|
|
310
|
+
status,
|
|
311
|
+
text
|
|
312
|
+
};
|
|
313
|
+
} finally {
|
|
314
|
+
clearTimeout(timer);
|
|
315
|
+
}
|
|
299
316
|
};
|
|
300
317
|
const reported = await runOnce(["--version"]);
|
|
301
318
|
if (reported.status !== 0 || reported.text?.trim() !== version) throw new Error("Command artifact version mismatch");
|
|
@@ -344,24 +361,27 @@ async function qualifyCommandArtifact(options) {
|
|
|
344
361
|
serviceStopped: windows ? "process-tree" : "sigterm"
|
|
345
362
|
};
|
|
346
363
|
} finally {
|
|
347
|
-
|
|
348
|
-
if (
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
364
|
+
try {
|
|
365
|
+
if (service) {
|
|
366
|
+
if (windows) {
|
|
367
|
+
try {
|
|
368
|
+
service.kill("SIGKILL");
|
|
369
|
+
} catch {}
|
|
370
|
+
await exitedWithin(service, SERVICE_STOP_MS);
|
|
371
|
+
} else {
|
|
372
|
+
if (!unixGroupKilled) signalProcessGroup(service.pid, "SIGKILL");
|
|
373
|
+
await exitedWithin(service, SERVICE_STOP_MS);
|
|
374
|
+
if (!await processGroupExited(service.pid, SERVICE_STOP_MS)) cleanupFailure = "Command artifact service process tree did not stop";
|
|
375
|
+
}
|
|
357
376
|
}
|
|
377
|
+
} finally {
|
|
378
|
+
await rm(location, {
|
|
379
|
+
recursive: true,
|
|
380
|
+
force: true,
|
|
381
|
+
maxRetries: 5,
|
|
382
|
+
retryDelay: 200
|
|
383
|
+
});
|
|
358
384
|
}
|
|
359
|
-
await rm(location, {
|
|
360
|
-
recursive: true,
|
|
361
|
-
force: true,
|
|
362
|
-
maxRetries: 5,
|
|
363
|
-
retryDelay: 200
|
|
364
|
-
});
|
|
365
385
|
}
|
|
366
386
|
if (cleanupFailure) throw new Error(cleanupFailure);
|
|
367
387
|
if (!qualification) throw new Error("Command artifact qualification did not complete");
|
|
@@ -119,10 +119,12 @@ async function readMembers(archive, limits, collect) {
|
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
121
|
const ended = once(parser, "end");
|
|
122
|
+
ended.catch(() => void 0);
|
|
122
123
|
const file = await open(archive, "r");
|
|
123
124
|
try {
|
|
124
125
|
const input = file.createReadStream({ autoClose: false }), inflate = createZstdDecompress();
|
|
125
126
|
input.on("error", (error) => inflate.destroy(error));
|
|
127
|
+
parser.on("error", (error) => inflate.destroy(error));
|
|
126
128
|
for await (const chunk of input.pipe(inflate)) if (!parser.write(chunk)) await once(parser, "drain");
|
|
127
129
|
parser.end();
|
|
128
130
|
await ended;
|
|
@@ -155,7 +157,7 @@ async function verifyInstalledPayload(options) {
|
|
|
155
157
|
assertInstallerContext(env, options.platform, process.platform, process.arch);
|
|
156
158
|
assertPortableAppName(options.appName);
|
|
157
159
|
const sidecars = assertSidecarNames(options.sidecars ?? [], options.platform).map((name) => sidecarBundlePath(name, options.platform));
|
|
158
|
-
if (!/^\d+\.\d+\.\d
|
|
160
|
+
if (!/^\d+\.\d+\.\d+$/.test(options.version) || options.version.length > 64) throw new Error("Invalid installed version");
|
|
159
161
|
const profile = await realpath(options.profile), root = await realpath(options.installedRoot), archive = resolve(options.archive);
|
|
160
162
|
if (!(await lstat(profile)).isDirectory() || !(await lstat(root)).isDirectory() || !isWithin(profile, root)) throw new Error("Installed root escapes isolated profile");
|
|
161
163
|
const { archiveInfo, entries } = await listArchive(archive, options.platform, env);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { errorCode } from "../app/value-guards.js";
|
|
2
2
|
import { isHostedRunner, runnerTemp } from "./hosted-runner.js";
|
|
3
|
-
import {
|
|
3
|
+
import { readBoundedFile } from "../shared/file-system.js";
|
|
4
|
+
import { lstat, mkdir, mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
|
|
4
5
|
import { dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
5
6
|
import { randomBytes } from "node:crypto";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
@@ -16,7 +17,8 @@ var bootstrapModules = [
|
|
|
16
17
|
"installer/hosted-runner.js",
|
|
17
18
|
"release/release-qualification.js",
|
|
18
19
|
"desktop/string-policy.js",
|
|
19
|
-
"shared/discard-stream.js"
|
|
20
|
+
"shared/discard-stream.js",
|
|
21
|
+
"shared/bounded-body.js"
|
|
20
22
|
];
|
|
21
23
|
/** Copy a bounded external preload into the current disposable runner's temp directory. */
|
|
22
24
|
async function prepareInstallerCiBootstrap(env = process.env) {
|
|
@@ -28,10 +30,7 @@ async function prepareInstallerCiBootstrap(env = process.env) {
|
|
|
28
30
|
const directory = await mkdtemp(join(parent, "framework-ci-"));
|
|
29
31
|
try {
|
|
30
32
|
for (const name of bootstrapModules) {
|
|
31
|
-
const
|
|
32
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 2097152) throw new Error("Invalid installer bootstrap module");
|
|
33
|
-
const contents = await readFile(file);
|
|
34
|
-
if (contents.length !== info.size) throw new Error("Installer bootstrap module changed");
|
|
33
|
+
const contents = await readBoundedFile(join(source, name), 2097152, "installer bootstrap module");
|
|
35
34
|
await mkdir(dirname(join(directory, name)), {
|
|
36
35
|
recursive: true,
|
|
37
36
|
mode: 448
|
|
@@ -7,9 +7,9 @@ async function drivePreflight() {
|
|
|
7
7
|
if (!entry || !nonce || !ack || !permit) throw new Error("Missing preflight context");
|
|
8
8
|
const worker = new Worker(entry, {});
|
|
9
9
|
const result = new Promise((resolve) => worker.addEventListener("message", (event) => resolve(event.data), { once: true }));
|
|
10
|
-
const deadline =
|
|
10
|
+
const deadline = performance.now() + 1e4;
|
|
11
11
|
let acknowledged = false;
|
|
12
|
-
while (!acknowledged &&
|
|
12
|
+
while (!acknowledged && performance.now() < deadline) {
|
|
13
13
|
try {
|
|
14
14
|
acknowledged = await readFile(ack, "utf8") === nonce + "\n";
|
|
15
15
|
} catch {}
|
|
@@ -22,7 +22,7 @@ async function drivePreflight() {
|
|
|
22
22
|
});
|
|
23
23
|
let timer;
|
|
24
24
|
const timeout = new Promise((resolve) => {
|
|
25
|
-
timer = setTimeout(() => resolve(null), Math.max(0, deadline -
|
|
25
|
+
timer = setTimeout(() => resolve(null), Math.max(0, deadline - performance.now()));
|
|
26
26
|
});
|
|
27
27
|
const value = await Promise.race([result, timeout]);
|
|
28
28
|
clearTimeout(timer);
|
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
import { type InstallerPlatform } from './installer-layout';
|
|
2
|
-
import { type InstallerImageMountState } from './installer-image-mount';
|
|
3
2
|
import type { Artifact } from '../release/release-qualification';
|
|
4
|
-
export type ImageAttachIo = {
|
|
5
|
-
run(args: string[], env: Record<string, string>): Promise<unknown>;
|
|
6
|
-
mounted(mount: string): Promise<boolean>;
|
|
7
|
-
/** Optional tri-state probe; unknown is never treated as ownership proof. */
|
|
8
|
-
state?(mount: string): Promise<InstallerImageMountState>;
|
|
9
|
-
/** Kept for adapter compatibility; retries are unsafe after an indeterminate attach. */
|
|
10
|
-
wait(ms: number): Promise<unknown>;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Attach once at a caller-provided mountpoint. The caller must create and reserve a fresh,
|
|
14
|
-
* empty mountpoint exclusively for this image operation, and keep it exclusive until this
|
|
15
|
-
* call finishes. The state probe rejects paths that are already mounted or whose state is
|
|
16
|
-
* unknown, but a mounted-state probe does not identify which image owns a volume; this API
|
|
17
|
-
* trusts the caller's exclusivity precondition and does not claim to verify image identity.
|
|
18
|
-
*
|
|
19
|
-
* A failed attach is indeterminate, so this function never retries or detaches by path and
|
|
20
|
-
* the caller must retain its temporary directory for recovery. This changes the former
|
|
21
|
-
* three-attempt, five-second retry behavior; internal verification and extraction preserve
|
|
22
|
-
* three attempts by using fresh private mountpoints and retaining failed-attempt directories.
|
|
23
|
-
*/
|
|
24
|
-
export declare function attachImage(mount: string, image: string, env: Record<string, string>, io?: ImageAttachIo): Promise<void>;
|
|
25
3
|
/**
|
|
26
4
|
* Inspect a shipped installer without executing it, on a matching disposable runner, or with
|
|
27
5
|
* `local` on the maintainer's own matching machine for a local release (read-only inspection of
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { assertEmbeddedArchive, assertInstallerExecutable, extractArchiveMember, findArchiveMember, isWithin, normalizeArchiveMember } from "./installer-archive-members.js";
|
|
2
2
|
import { hashFileAt } from "../updates/locks/stable-file.js";
|
|
3
3
|
import { assertInstallerContext, assertInstallerHost, assertInstallerLayout, assertPortableAppName } from "./installer-layout.js";
|
|
4
|
-
import {
|
|
4
|
+
import { cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, withInstallerImageRetries } from "./installer-image-mount.js";
|
|
5
5
|
import { runInstallerCommand } from "./installer-command.js";
|
|
6
6
|
import { lstat, mkdtemp, readdir, realpath } from "node:fs/promises";
|
|
7
|
-
import { basename,
|
|
7
|
+
import { basename, join, resolve, win32 } from "node:path";
|
|
8
8
|
import { tmpdir } from "node:os";
|
|
9
9
|
// src/installer/installer-identity.ts
|
|
10
10
|
async function identity(path) {
|
|
@@ -31,56 +31,6 @@ function environment(parent) {
|
|
|
31
31
|
]) if (parent[name]) env[name] = parent[name];
|
|
32
32
|
return env;
|
|
33
33
|
}
|
|
34
|
-
/** Whether a volume is mounted at a directory; unknown counts as mounted. */
|
|
35
|
-
async function volumeAt(mount) {
|
|
36
|
-
return await installerImageMountState(mount) !== "unmounted";
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Attach once at a caller-provided mountpoint. The caller must create and reserve a fresh,
|
|
40
|
-
* empty mountpoint exclusively for this image operation, and keep it exclusive until this
|
|
41
|
-
* call finishes. The state probe rejects paths that are already mounted or whose state is
|
|
42
|
-
* unknown, but a mounted-state probe does not identify which image owns a volume; this API
|
|
43
|
-
* trusts the caller's exclusivity precondition and does not claim to verify image identity.
|
|
44
|
-
*
|
|
45
|
-
* A failed attach is indeterminate, so this function never retries or detaches by path and
|
|
46
|
-
* the caller must retain its temporary directory for recovery. This changes the former
|
|
47
|
-
* three-attempt, five-second retry behavior; internal verification and extraction preserve
|
|
48
|
-
* three attempts by using fresh private mountpoints and retaining failed-attempt directories.
|
|
49
|
-
*/
|
|
50
|
-
async function attachImage(mount, image, env, io = {
|
|
51
|
-
run: command,
|
|
52
|
-
mounted: volumeAt,
|
|
53
|
-
state: installerImageMountState,
|
|
54
|
-
wait: Bun.sleep
|
|
55
|
-
}) {
|
|
56
|
-
let initialState;
|
|
57
|
-
try {
|
|
58
|
-
initialState = io.state ? await io.state(mount) : await io.mounted(mount) ? "mounted" : "unmounted";
|
|
59
|
-
} catch (error) {
|
|
60
|
-
throw new InstallerImageLifecycleError([error, /* @__PURE__ */ new Error("Attach was not attempted because the caller-provided mount state is unknown")], true, dirname(mount), "attach", `Installer image attach refused because mountpoint state is unknown at ${mount}`);
|
|
61
|
-
}
|
|
62
|
-
if (initialState !== "unmounted") throw new InstallerImageLifecycleError([/* @__PURE__ */ new Error(`Attach was not attempted because the caller-provided mount path is ${initialState}`)], true, dirname(mount), "attach", `Installer image attach refused because mountpoint is ${initialState} at ${mount}`);
|
|
63
|
-
try {
|
|
64
|
-
await io.run([
|
|
65
|
-
"/usr/bin/hdiutil",
|
|
66
|
-
"attach",
|
|
67
|
-
"-readonly",
|
|
68
|
-
"-nobrowse",
|
|
69
|
-
"-mountpoint",
|
|
70
|
-
mount,
|
|
71
|
-
image
|
|
72
|
-
], env);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
throw new InstallerImageLifecycleError([error, /* @__PURE__ */ new Error("Attach completion is indeterminate; do not retry or detach the caller-provided mount path")], true, dirname(mount), "attach", `Installer image attach failed; caller-provided mount path state is indeterminate at ${mount}`);
|
|
75
|
-
}
|
|
76
|
-
let state;
|
|
77
|
-
try {
|
|
78
|
-
state = io.state ? await io.state(mount) : await io.mounted(mount) ? "mounted" : "unmounted";
|
|
79
|
-
} catch (error) {
|
|
80
|
-
throw new InstallerImageLifecycleError([error, /* @__PURE__ */ new Error("Attach returned success but the mount state is unknown")], true, dirname(mount), "attach", `Installer image attach returned success without a confirmed mount at ${mount}`);
|
|
81
|
-
}
|
|
82
|
-
if (state !== "mounted") throw new InstallerImageLifecycleError([/* @__PURE__ */ new Error(`Attach returned success but the requested mountpoint is ${state}`)], true, dirname(mount), "attach", `Installer image attach returned success without a confirmed mount at ${mount}`);
|
|
83
|
-
}
|
|
84
34
|
async function command(args, env) {
|
|
85
35
|
return runInstallerCommand(args, env, {
|
|
86
36
|
outputLimit: 8388608,
|
|
@@ -196,4 +146,4 @@ async function verifyInstallerPayload(options) {
|
|
|
196
146
|
throw error;
|
|
197
147
|
}
|
|
198
148
|
}
|
|
199
|
-
export {
|
|
149
|
+
export { verifyInstallerPayload };
|
|
@@ -6,7 +6,6 @@ export type InstallerImageMountIo = {
|
|
|
6
6
|
wait(ms: number): Promise<unknown>;
|
|
7
7
|
remove(directory: string): Promise<void>;
|
|
8
8
|
};
|
|
9
|
-
export declare function installerImageMountState(mount: string): Promise<InstallerImageMountState>;
|
|
10
9
|
export declare function defaultInstallerImageMountIo(run: InstallerImageMountIo['run']): InstallerImageMountIo;
|
|
11
10
|
/** Skip only cleanup already owned by this exact lifecycle attempt. */
|
|
12
11
|
export declare function cleanupInstallerDirectoryAfterFailure(directory: string, error: unknown, io: InstallerImageMountIo): Promise<void>;
|
|
@@ -344,4 +344,4 @@ async function withInstallerImageRetries(options) {
|
|
|
344
344
|
}
|
|
345
345
|
throw new Error("Installer image attach attempts exhausted");
|
|
346
346
|
}
|
|
347
|
-
export { InstallerImageLifecycleError, cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo,
|
|
347
|
+
export { InstallerImageLifecycleError, cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, withInstallerImage, withInstallerImageRetries };
|
|
@@ -2,6 +2,11 @@ import { type InstallerPlatform, type InstallerRenderer } from './installer-layo
|
|
|
2
2
|
import { type InstallerRendererObservation } from './installer-renderer-evidence';
|
|
3
3
|
import { type Artifact, type OfflinePolicy, type RendererEvidence } from '../release/release-qualification';
|
|
4
4
|
import type { ReleaseTrust, VerifiedRelease } from '../updates/feed/signed-release';
|
|
5
|
+
/**
|
|
6
|
+
* The installer's last `error: Name` line, for diagnosing a failed install.
|
|
7
|
+
* Only a bounded identifier is returned: never paths, output or credentials.
|
|
8
|
+
*/
|
|
9
|
+
export declare function installerErrorName(stderr: string): string | undefined;
|
|
5
10
|
/** Whether the runner should start the installed app on this loop iteration.
|
|
6
11
|
*
|
|
7
12
|
* Electrobun's Windows and Linux extractors (since 2.0.1, `launchInstalledApp` in
|
|
@@ -13,11 +18,6 @@ import type { ReleaseTrust, VerifiedRelease } from '../updates/feed/signed-relea
|
|
|
13
18
|
* never gets a renderer and its process exits after the permit. So the runner never starts the
|
|
14
19
|
* app on Windows or Linux. The macOS installer instead asks `open -n`, which the launch shim
|
|
15
20
|
* records without opening anything, so the runner starts the recorded bundle exactly once. */
|
|
16
|
-
/**
|
|
17
|
-
* The installer's last `error: Name` line, for diagnosing a failed install.
|
|
18
|
-
* Only a bounded identifier is returned: never paths, output or credentials.
|
|
19
|
-
*/
|
|
20
|
-
export declare function installerErrorName(stderr: string): string | undefined;
|
|
21
21
|
export declare function shouldLaunchInstalledApp(state: {
|
|
22
22
|
platform: InstallerPlatform;
|
|
23
23
|
ready: boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { errorCode } from "../app/value-guards.js";
|
|
2
|
+
import { pathExists, readJsonFile } from "../shared/file-system.js";
|
|
2
3
|
import { preflightInstallerRuntime, prepareInstallerCiBootstrap } from "./installer-ci-bootstrap.js";
|
|
3
4
|
import { prepareInstallerExecution } from "./installer-extraction.js";
|
|
4
5
|
import { verifyInstallerPayload } from "./installer-identity.js";
|
|
@@ -9,7 +10,7 @@ import { parseOfflinePolicy } from "../release/release-qualification.js";
|
|
|
9
10
|
import { terminateGuardedWorker } from "./installer-process-cleanup.js";
|
|
10
11
|
import { stageUpdateSwap } from "../updates/install/update-swap-stage.js";
|
|
11
12
|
import { swapUpdateTree } from "../updates/install/update-swap.js";
|
|
12
|
-
import { chmod,
|
|
13
|
+
import { chmod, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
|
|
13
14
|
import { delimiter, dirname, join } from "node:path";
|
|
14
15
|
import { randomBytes } from "node:crypto";
|
|
15
16
|
import { createServer } from "node:net";
|
|
@@ -58,33 +59,6 @@ async function choosePort() {
|
|
|
58
59
|
await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
|
|
59
60
|
return address.port;
|
|
60
61
|
}
|
|
61
|
-
async function boundedJson(path) {
|
|
62
|
-
const info = await lstat(path);
|
|
63
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 16384) throw new Error("Invalid renderer observation");
|
|
64
|
-
const bytes = await readFile(path);
|
|
65
|
-
if (bytes.length !== info.size) throw new Error("Renderer observation changed");
|
|
66
|
-
return JSON.parse(bytes.toString("utf8"));
|
|
67
|
-
}
|
|
68
|
-
async function exists(path) {
|
|
69
|
-
try {
|
|
70
|
-
await lstat(path);
|
|
71
|
-
return true;
|
|
72
|
-
} catch (error) {
|
|
73
|
-
if (errorCode(error) === "ENOENT") return false;
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/** Whether the runner should start the installed app on this loop iteration.
|
|
78
|
-
*
|
|
79
|
-
* Electrobun's Windows and Linux extractors (since 2.0.1, `launchInstalledApp` in
|
|
80
|
-
* package/src/extractor/main.zig, still in 2.0.5) start the installed launcher themselves after
|
|
81
|
-
* a first install, inheriting the runner's isolated environment and guard context. Starting a
|
|
82
|
-
* second launcher there runs two instances against one profile: one Chromium/CEF profile
|
|
83
|
-
* (`root_cache_path`) admits a single process, while the worker guard admits whichever worker
|
|
84
|
-
* writes its identity first. When those two races pick different processes, the guarded worker
|
|
85
|
-
* never gets a renderer and its process exits after the permit. So the runner never starts the
|
|
86
|
-
* app on Windows or Linux. The macOS installer instead asks `open -n`, which the launch shim
|
|
87
|
-
* records without opening anything, so the runner starts the recorded bundle exactly once. */
|
|
88
62
|
/**
|
|
89
63
|
* The installer's last `error: Name` line, for diagnosing a failed install.
|
|
90
64
|
* Only a bounded identifier is returned: never paths, output or credentials.
|
|
@@ -100,6 +74,17 @@ async function boundedStderr(stream, limit = 65536) {
|
|
|
100
74
|
for await (const chunk of stream) if (text.length < limit) text += decoder.decode(chunk, { stream: true });
|
|
101
75
|
return text.slice(-limit);
|
|
102
76
|
}
|
|
77
|
+
/** Whether the runner should start the installed app on this loop iteration.
|
|
78
|
+
*
|
|
79
|
+
* Electrobun's Windows and Linux extractors (since 2.0.1, `launchInstalledApp` in
|
|
80
|
+
* package/src/extractor/main.zig, still in 2.0.5) start the installed launcher themselves after
|
|
81
|
+
* a first install, inheriting the runner's isolated environment and guard context. Starting a
|
|
82
|
+
* second launcher there runs two instances against one profile: one Chromium/CEF profile
|
|
83
|
+
* (`root_cache_path`) admits a single process, while the worker guard admits whichever worker
|
|
84
|
+
* writes its identity first. When those two races pick different processes, the guarded worker
|
|
85
|
+
* never gets a renderer and its process exits after the permit. So the runner never starts the
|
|
86
|
+
* app on Windows or Linux. The macOS installer instead asks `open -n`, which the launch shim
|
|
87
|
+
* records without opening anything, so the runner starts the recorded bundle exactly once. */
|
|
103
88
|
function shouldLaunchInstalledApp(state) {
|
|
104
89
|
return state.platform === "macos-arm64" && state.ready && !state.launched && !state.acknowledged && state.installerExit === 0;
|
|
105
90
|
}
|
|
@@ -115,7 +100,7 @@ async function observeInstalledApp(options) {
|
|
|
115
100
|
};
|
|
116
101
|
assertInstallerContext(parent, options.platform, process.platform, process.arch);
|
|
117
102
|
assertPortableAppName(options.appName);
|
|
118
|
-
if (!/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(options.appId) || options.appId.length > 255 || !/^\d+\.\d+\.\d
|
|
103
|
+
if (!/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(options.appId) || options.appId.length > 255 || !/^\d+\.\d+\.\d+$/.test(options.version) || options.version.length > 64 || (options.platform === "linux-x64" || options.platform === "linux-arm64") && !parent.DISPLAY) throw new Error("Invalid installer observation context");
|
|
119
104
|
const policy = options.offlinePolicy === void 0 ? void 0 : parseOfflinePolicy(options.offlinePolicy);
|
|
120
105
|
const expectedReads = options.expectedReads ?? [];
|
|
121
106
|
if (!Array.isArray(expectedReads) || expectedReads.length > 32 || new Set(expectedReads).size !== expectedReads.length || JSON.stringify(expectedReads).length > 8192) throw new Error("Invalid expected reads");
|
|
@@ -268,25 +253,25 @@ async function observeInstalledApp(options) {
|
|
|
268
253
|
let app = viaInstaller ? void 0 : spawnApp(), guardedPid;
|
|
269
254
|
stage(viaInstaller ? "installer-started" : "updated-app-started");
|
|
270
255
|
try {
|
|
271
|
-
let deadline =
|
|
256
|
+
let deadline = performance.now() + 15e4;
|
|
272
257
|
let granted = false;
|
|
273
|
-
while (
|
|
258
|
+
while (performance.now() < deadline) {
|
|
274
259
|
if (installer && installer.exitCode !== null && installer.exitCode !== 0) {
|
|
275
260
|
const error = installerErrorName(await Promise.race([installerStderr, Bun.sleep(2e3).then(() => "")]));
|
|
276
|
-
throw new Error(`Installer exited unsuccessfully (exit=${installer.exitCode}, signal=${installer.signalCode ?? "none"}, ready=${await
|
|
261
|
+
throw new Error(`Installer exited unsuccessfully (exit=${installer.exitCode}, signal=${installer.signalCode ?? "none"}, ready=${await pathExists(worker) && await pathExists(launcher)}, acknowledged=${await pathExists(ack)}, error=${error ?? "none"})`);
|
|
277
262
|
}
|
|
278
|
-
const ready = await
|
|
263
|
+
const ready = await pathExists(worker) && await pathExists(launcher) && await pathExists(join(resources, "version.json"));
|
|
279
264
|
if (installer && shouldLaunchInstalledApp({
|
|
280
265
|
platform: options.platform,
|
|
281
266
|
ready,
|
|
282
267
|
launched: app !== void 0,
|
|
283
|
-
acknowledged: await
|
|
268
|
+
acknowledged: await pathExists(ack),
|
|
284
269
|
installerExit: installer.exitCode
|
|
285
270
|
})) {
|
|
286
|
-
if (!launchRecord || !expectedApp || !await
|
|
271
|
+
if (!launchRecord || !expectedApp || !await pathExists(launchRecord) || await readFile(launchRecord, "utf8") !== expectedApp + "\n") throw new Error("Installer launch request mismatch");
|
|
287
272
|
app = spawnApp();
|
|
288
273
|
}
|
|
289
|
-
if (await
|
|
274
|
+
if (await pathExists(ack) && !granted) {
|
|
290
275
|
stage("worker-acknowledged");
|
|
291
276
|
if (await readFile(ack, "utf8") !== nonce + "\n") throw new Error("Worker guard acknowledgement mismatch");
|
|
292
277
|
const record = await readFile(pidRecord, "utf8"), match = /^([a-f0-9]{48})\n([1-9]\d{0,9})\n$/.exec(record);
|
|
@@ -300,14 +285,14 @@ async function observeInstalledApp(options) {
|
|
|
300
285
|
mode: 384
|
|
301
286
|
});
|
|
302
287
|
granted = true;
|
|
303
|
-
deadline =
|
|
288
|
+
deadline = performance.now() + 9e4;
|
|
304
289
|
stage("worker-permitted");
|
|
305
290
|
}
|
|
306
|
-
if (granted && await
|
|
291
|
+
if (granted && await pathExists(observation)) break;
|
|
307
292
|
await Bun.sleep(250);
|
|
308
293
|
}
|
|
309
|
-
const observed = await
|
|
310
|
-
const unexpectedObserved = await
|
|
294
|
+
const observed = await pathExists(observation);
|
|
295
|
+
const unexpectedObserved = await pathExists(unexpected);
|
|
311
296
|
if (!granted || !observed || unexpectedObserved) {
|
|
312
297
|
let workerState = "unknown";
|
|
313
298
|
if (guardedPid !== void 0) try {
|
|
@@ -321,28 +306,28 @@ async function observeInstalledApp(options) {
|
|
|
321
306
|
}
|
|
322
307
|
stage("renderer-observed");
|
|
323
308
|
if (installer) {
|
|
324
|
-
const installerDeadline =
|
|
325
|
-
while (installer.exitCode === null &&
|
|
309
|
+
const installerDeadline = performance.now() + 3e4;
|
|
310
|
+
while (installer.exitCode === null && performance.now() < installerDeadline) await Bun.sleep(250);
|
|
326
311
|
if (installer.exitCode !== 0) {
|
|
327
312
|
const error = installer.exitCode === null ? void 0 : installerErrorName(await Promise.race([installerStderr, Bun.sleep(2e3).then(() => "")]));
|
|
328
313
|
throw new Error(`Installer did not complete successfully (exit=${installer.exitCode ?? "running"}, error=${error ?? "none"})`);
|
|
329
314
|
}
|
|
330
315
|
stage("installer-completed");
|
|
331
316
|
}
|
|
332
|
-
const proof = await
|
|
317
|
+
const proof = await readJsonFile(observation, 16384, "renderer observation");
|
|
333
318
|
if (typeof proof !== "object" || proof === null || Array.isArray(proof)) throw new Error("Invalid renderer observation");
|
|
334
319
|
const { nonce: proofNonce, origin: proofOrigin, blockedReads, unexpectedActivity, offlinePolicy: proofPolicy, bootstrapDenied, ...metrics } = proof;
|
|
335
320
|
assertInstallerRendererObservation(metrics, Boolean(policy));
|
|
336
321
|
if (proofNonce !== nonce || proofOrigin !== origin || !Number.isSafeInteger(blockedReads) || Number(blockedReads) < 0 || unexpectedActivity !== false) throw new Error("Renderer observation identity mismatch");
|
|
337
322
|
if (policy && (JSON.stringify(parseOfflinePolicy(proofPolicy)) !== JSON.stringify(policy) || bootstrapDenied !== (policy.kind === "local-bootstrap") || foreignHits !== 0)) throw new Error("Offline observation does not match policy");
|
|
338
323
|
await Bun.sleep(3e3);
|
|
339
|
-
if (await
|
|
324
|
+
if (await pathExists(unexpected) || foreignHits !== 0 || !(await fetch(origin + "/", {
|
|
340
325
|
signal: AbortSignal.timeout(1e3),
|
|
341
326
|
redirect: "error"
|
|
342
327
|
})).ok) throw new Error("Installed app did not remain available");
|
|
343
328
|
await installedPayload(run.version, run.archive);
|
|
344
329
|
if (viaInstaller) await installerUnchanged();
|
|
345
|
-
if (await
|
|
330
|
+
if (await pathExists(unexpected) || foreignHits !== 0) throw new Error("Unexpected activity after renderer observation");
|
|
346
331
|
if (guardedPid === void 0) throw new Error("Missing guarded process identity");
|
|
347
332
|
await terminateGuardedWorker({
|
|
348
333
|
pid: guardedPid,
|
|
@@ -459,7 +444,7 @@ async function observeInstalledApp(options) {
|
|
|
459
444
|
}
|
|
460
445
|
/** The terminated app's processes can hold its files briefly, most visibly on Windows. */
|
|
461
446
|
async function swapAfterExit(target, staging) {
|
|
462
|
-
const deadline =
|
|
447
|
+
const deadline = performance.now() + 6e4;
|
|
463
448
|
for (;;) try {
|
|
464
449
|
await swapUpdateTree({
|
|
465
450
|
target,
|
|
@@ -467,7 +452,7 @@ async function swapAfterExit(target, staging) {
|
|
|
467
452
|
});
|
|
468
453
|
return;
|
|
469
454
|
} catch (error) {
|
|
470
|
-
if (
|
|
455
|
+
if (performance.now() > deadline) throw error;
|
|
471
456
|
await Bun.sleep(500);
|
|
472
457
|
}
|
|
473
458
|
}
|
|
@@ -30,8 +30,8 @@ async function terminateGuardedWorker(options) {
|
|
|
30
30
|
if (platform === "windows-x64" ? actual.toLowerCase() !== expected.toLowerCase() : actual !== expected) throw new Error("Guarded process executable mismatch");
|
|
31
31
|
process.kill(pid, "SIGKILL");
|
|
32
32
|
}
|
|
33
|
-
const deadline =
|
|
34
|
-
while (
|
|
33
|
+
const deadline = performance.now() + 5e3;
|
|
34
|
+
while (performance.now() < deadline) {
|
|
35
35
|
if (platform === "macos-arm64" ? await macosWorkerExited(() => readMacosState(pid, env)) : await runningExecutable(pid, platform, env) === void 0) return;
|
|
36
36
|
await Bun.sleep(100);
|
|
37
37
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseOfflinePolicy } from "../release/release-qualification.js";
|
|
2
|
-
import {
|
|
2
|
+
import { BoundedBodyError, readBoundedText } from "../shared/bounded-body.js";
|
|
3
3
|
import { assertHostedRunner } from "./hosted-runner.js";
|
|
4
4
|
// src/installer/installer-renderer-evidence.ts
|
|
5
5
|
function safeScriptString(value) {
|
|
@@ -22,35 +22,14 @@ function assertInstallerRendererObservation(value, offline = false) {
|
|
|
22
22
|
if (offline && (item.markerObserved !== true || item.foreignBlocked !== true) || Object.keys(item).length !== keys.length || keys.some((key) => !Object.hasOwn(item, key)) || item.samples !== 2 || typeof item.elapsedMs !== "number" || !Number.isFinite(item.elapsedMs) || item.elapsedMs < 3e3 || item.elapsedMs > 12e4 || item.visible !== true || !["interactive", "complete"].includes(String(item.readyState)) || typeof item.width !== "number" || !Number.isFinite(item.width) || item.width < 100 || typeof item.height !== "number" || !Number.isFinite(item.height) || item.height < 100 || !Number.isSafeInteger(item.interactiveElements) || Number(item.interactiveElements) < 1 || !Number.isSafeInteger(item.textLength) || Number(item.textLength) < 1) throw new Error("Incomplete renderer observation");
|
|
23
23
|
}
|
|
24
24
|
async function boundedBody(message, maximum) {
|
|
25
|
-
const declared = message.headers.get("content-length");
|
|
26
|
-
if (declared !== null && (!/^\d+$/.test(declared) || Number(declared) > maximum)) {
|
|
27
|
-
discardStream(message.body);
|
|
28
|
-
throw new Error("Renderer body exceeds bound");
|
|
29
|
-
}
|
|
30
|
-
if (!message.body) throw new Error("Missing renderer body");
|
|
31
|
-
const reader = message.body.getReader(), chunks = [];
|
|
32
|
-
let size = 0;
|
|
33
25
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
throw new Error("Renderer body exceeds bound");
|
|
41
|
-
}
|
|
42
|
-
chunks.push(next.value);
|
|
43
|
-
}
|
|
44
|
-
} finally {
|
|
45
|
-
reader.releaseLock();
|
|
46
|
-
}
|
|
47
|
-
const bytes = new Uint8Array(size);
|
|
48
|
-
let offset = 0;
|
|
49
|
-
for (const chunk of chunks) {
|
|
50
|
-
bytes.set(chunk, offset);
|
|
51
|
-
offset += chunk.length;
|
|
26
|
+
return await readBoundedText(message, maximum);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (!(error instanceof BoundedBodyError)) throw error;
|
|
29
|
+
if (error.reason === "too-large") throw new Error("Renderer body exceeds bound", { cause: error });
|
|
30
|
+
if (error.reason === "missing") throw new Error("Missing renderer body", { cause: error });
|
|
31
|
+
throw error.cause ?? error;
|
|
52
32
|
}
|
|
53
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
54
33
|
}
|
|
55
34
|
function probeScript(nonce, policy, foreignOrigin) {
|
|
56
35
|
return `<script>(()=>{const started=performance.now();requestAnimationFrame(()=>{setTimeout(()=>requestAnimationFrame(async()=>{const d=document;const data={samples:2,elapsedMs:performance.now()-started,visible:d.visibilityState==='visible',readyState:d.readyState,width:innerWidth,height:innerHeight,interactiveElements:d.querySelectorAll('button,input,textarea,select,a[href],[role="button"]').length,textLength:(d.body?.innerText||'').trim().length};${policy ? `data.markerObserved=(d.body?.innerText||'').includes(${safeScriptString(policy.marker)});try{await fetch(${safeScriptString(foreignOrigin)}+'/',{mode:'no-cors',cache:'no-store'});data.foreignBlocked=false}catch{data.foreignBlocked=true}` : ""};fetch('/__framework_installer_probe/${nonce}',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(data),redirect:'error'}).catch(()=>{});}),3100);});})();<\/script>`;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { errorCode, isRecord } from "../app/value-guards.js";
|
|
2
|
+
import { readJsonFile } from "../shared/file-system.js";
|
|
2
3
|
import { observeInstalledApp } from "./installer-observation.js";
|
|
3
4
|
import { downloadAsset } from "./upgrade-asset-download.js";
|
|
4
5
|
import { planReleaseAssets } from "../release/release-assets-plan.js";
|
|
@@ -8,7 +9,7 @@ import { versionLessThan } from "../updates/feed/release-version.js";
|
|
|
8
9
|
import { discoverSignedRelease } from "../updates/feed/update-discovery.js";
|
|
9
10
|
import { downloadVerifiedRelease } from "../updates/install/update-download.js";
|
|
10
11
|
import { verifyReleaseDescriptor } from "../updates/feed/signed-release.js";
|
|
11
|
-
import { lstat, mkdir,
|
|
12
|
+
import { lstat, mkdir, rename, writeFile } from "node:fs/promises";
|
|
12
13
|
import { join, resolve } from "node:path";
|
|
13
14
|
// src/installer/installer-upgrade-command.ts
|
|
14
15
|
var MAX_COMPRESSED_BYTES = 1073741824;
|
|
@@ -31,16 +32,6 @@ function discoveryName(config, channel, platform) {
|
|
|
31
32
|
if (matches.length !== 1 || matches[0].includes("{tag}")) throw new Error("Invalid discovery policy");
|
|
32
33
|
return matches[0];
|
|
33
34
|
}
|
|
34
|
-
async function readBounded(path, maximum) {
|
|
35
|
-
const info = await lstat(path);
|
|
36
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > maximum) throw new Error("Invalid staged descriptor");
|
|
37
|
-
const file = await open(path, "r");
|
|
38
|
-
try {
|
|
39
|
-
return await file.readFile("utf8");
|
|
40
|
-
} finally {
|
|
41
|
-
await file.close();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
35
|
/**
|
|
45
36
|
* Prove in the trusted release-assets workflow that an installation of the newest published
|
|
46
37
|
* release takes this release's signed update: install the previous version with its own
|
|
@@ -76,29 +67,26 @@ async function qualifyUpgradeCommand(options) {
|
|
|
76
67
|
feed,
|
|
77
68
|
keys
|
|
78
69
|
};
|
|
79
|
-
const channel =
|
|
70
|
+
const channel = "daily";
|
|
80
71
|
const trust = {
|
|
81
72
|
...base,
|
|
82
73
|
channel
|
|
83
74
|
};
|
|
84
|
-
const
|
|
75
|
+
const discovery = discoveryName(config, channel, platform);
|
|
76
|
+
const signed = await readJsonFile(join(directory, discovery), 65536, "staged descriptor");
|
|
85
77
|
const verified = verifyReleaseDescriptor(signed, trust);
|
|
86
78
|
if (!verified.ok || verified.descriptor.tag !== tag || verified.descriptor.asset.name !== names[1]) throw new Error("Untrusted staged descriptor");
|
|
87
79
|
const descriptor = verified.descriptor;
|
|
88
80
|
const fetcher = options.fetch ?? fetch;
|
|
89
81
|
let previous;
|
|
90
|
-
|
|
82
|
+
try {
|
|
91
83
|
previous = await discoverSignedRelease({
|
|
92
|
-
trust
|
|
93
|
-
|
|
94
|
-
channel: from
|
|
95
|
-
},
|
|
96
|
-
discoveryName: discoveryName(config, from, platform),
|
|
84
|
+
trust,
|
|
85
|
+
discoveryName: discovery,
|
|
97
86
|
timeoutMs: 3e4,
|
|
98
87
|
fetch: fetcher,
|
|
99
88
|
olderThan: descriptor.version
|
|
100
89
|
});
|
|
101
|
-
break;
|
|
102
90
|
} catch (error) {
|
|
103
91
|
if (error.message !== "No qualified channel descriptor is available") throw error;
|
|
104
92
|
}
|