@adea-ai/app-framework 0.25.0 → 0.26.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 +157 -19
- package/dist/app/application.d.ts +11 -4
- package/dist/app/application.js +24 -4
- package/dist/app/create-application.d.ts +9 -0
- package/dist/app/create-application.js +214 -143
- package/dist/app/private-group.d.ts +14 -0
- package/dist/app/private-group.js +39 -0
- package/dist/app/service-registry.d.ts +8 -4
- package/dist/app/service-registry.js +43 -6
- package/dist/appearance/custom-theme-import.d.ts +5 -7
- package/dist/appearance/custom-theme-import.js +66 -18
- package/dist/appearance/custom-theme-library.d.ts +51 -3
- package/dist/appearance/custom-theme-library.js +262 -33
- package/dist/appearance/editor.d.ts +3 -1
- package/dist/appearance/editor.js +37 -2
- package/dist/appearance/theme-file-importer.d.ts +7 -3
- package/dist/appearance/theme-file-importer.js +27 -7
- package/dist/appearance/theme-library-action-fence.d.ts +11 -0
- package/dist/appearance/theme-library-action-fence.js +29 -0
- package/dist/cli/cef-helper-cli.js +0 -0
- package/dist/cli/create-application-cli.js +0 -0
- package/dist/cli/electrobun-shortcut-patch-cli.js +0 -0
- package/dist/cli/framework-update-cli.js +16 -3
- package/dist/cli/macos-signing-cli.js +0 -0
- package/dist/cli/release-assets-plan-cli.js +0 -0
- package/dist/cli/release-cut-cli.js +0 -0
- package/dist/cli/release-descriptor-staging-cli.js +0 -0
- package/dist/cli/release-finalize-cli.js +0 -0
- package/dist/cli/release-promote-cli.js +0 -0
- package/dist/cli/release-publish-cli.js +0 -0
- package/dist/cli/release-sign-cli.js +0 -0
- package/dist/cli/release-step-cli.js +0 -0
- package/dist/cli/toolchain-identity-cli.js +0 -0
- package/dist/cli/windows-runtime-patch-cli.js +0 -0
- package/dist/desktop/application-command-client.d.ts +11 -1
- package/dist/desktop/application-command-client.js +66 -3
- package/dist/desktop/channel-handshake.d.ts +2 -1
- package/dist/desktop/channel-handshake.js +21 -5
- package/dist/desktop/client-asset-stream.d.ts +10 -0
- package/dist/desktop/client-asset-stream.js +97 -0
- package/dist/desktop/client-assets.d.ts +3 -1
- package/dist/desktop/client-assets.js +41 -6
- package/dist/desktop/desktop-client.d.ts +15 -1
- package/dist/desktop/desktop-client.js +235 -109
- package/dist/desktop/desktop-gateway.d.ts +2 -0
- package/dist/desktop/desktop-gateway.js +134 -22
- package/dist/desktop/desktop-host-websocket.d.ts +10 -0
- package/dist/desktop/desktop-host-websocket.js +28 -0
- package/dist/desktop/desktop-host.d.ts +9 -0
- package/dist/desktop/desktop-host.js +70 -61
- package/dist/desktop/desktop-port-file.d.ts +2 -0
- package/dist/desktop/desktop-port-file.js +23 -0
- package/dist/desktop/desktop-stream.d.ts +5 -0
- package/dist/desktop/desktop-stream.js +83 -15
- package/dist/desktop/gateway-limits.d.ts +2 -0
- package/dist/desktop/gateway-limits.js +6 -0
- package/dist/desktop/open-url-channel.d.ts +5 -3
- package/dist/desktop/open-url-channel.js +18 -5
- package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
- package/dist/desktop/typed-array-intrinsics.js +19 -0
- package/dist/framework-source.json +1 -1
- package/dist/installer/installed-payload.js +1 -1
- package/dist/installer/installer-ci-bootstrap.js +2 -1
- package/dist/installer/installer-command.d.ts +13 -0
- package/dist/installer/installer-command.js +47 -0
- package/dist/installer/installer-extraction.js +27 -61
- package/dist/installer/installer-identity.d.ts +19 -3
- package/dist/installer/installer-identity.js +58 -70
- package/dist/installer/installer-image-mount.d.ts +48 -0
- package/dist/installer/installer-image-mount.js +347 -0
- package/dist/installer/installer-layout.js +1 -1
- package/dist/installer/installer-process-cleanup.js +1 -1
- package/dist/installer/installer-renderer-evidence.js +6 -2
- package/dist/installer/upgrade-asset-download.js +30 -8
- package/dist/native/app-bundle.d.ts +2 -2
- package/dist/native/app-bundle.js +5 -4
- package/dist/native/cef-helper-download.d.ts +1 -0
- package/dist/native/cef-helper-download.js +35 -0
- package/dist/native/cef-helper.js +146 -61
- package/dist/native/exclusive-rename.d.ts +2 -0
- package/dist/native/exclusive-rename.js +52 -0
- package/dist/native/native-secret-store.js +5 -4
- package/dist/native/partitioned-window.d.ts +5 -2
- package/dist/native/partitioned-window.js +69 -9
- package/dist/native/sidecar-services.js +2 -2
- package/dist/native/sidecar.js +68 -25
- package/dist/native/window-bootstrap.js +2 -2
- package/dist/release/feed-state.js +2 -1
- package/dist/release/framework-update-lock.d.ts +2 -0
- package/dist/release/framework-update-lock.js +42 -0
- package/dist/release/framework-update.d.ts +6 -2
- package/dist/release/framework-update.js +165 -40
- package/dist/release/local-release.js +68 -39
- package/dist/release/release-config.js +1 -1
- package/dist/shared/discard-stream.d.ts +4 -0
- package/dist/shared/discard-stream.js +9 -0
- package/dist/shell/app-shell.js +59 -7
- package/dist/shell/app-utilities.js +2 -2
- package/dist/shell/application-menu.d.ts +13 -0
- package/dist/shell/application-menu.js +21 -8
- package/dist/update-helper.bundle.js +40 -4
- package/dist/updates/channel-update-manager.d.ts +2 -0
- package/dist/updates/channel-update-manager.js +15 -3
- package/dist/updates/desktop-updater.d.ts +2 -0
- package/dist/updates/desktop-updater.js +36 -7
- package/dist/updates/linux-process-state.d.ts +2 -0
- package/dist/updates/linux-process-state.js +13 -0
- package/dist/updates/release-location.js +5 -4
- package/dist/updates/update-adapter.js +5 -0
- package/dist/updates/update-arm.d.ts +2 -0
- package/dist/updates/update-arm.js +58 -7
- package/dist/updates/update-discovery.js +2 -1
- package/dist/updates/update-download-cleanup.d.ts +7 -0
- package/dist/updates/update-download-cleanup.js +21 -0
- package/dist/updates/update-download.js +41 -20
- package/dist/updates/update-exclusive-rename.d.ts +3 -2
- package/dist/updates/update-exclusive-rename.js +3 -50
- package/dist/updates/update-extraction.js +1 -1
- package/dist/updates/update-manager.d.ts +17 -1
- package/dist/updates/update-manager.js +27 -8
- package/dist/updates/update-process-fence.js +18 -3
- package/dist/views/appearance-surface.js +51 -15
- package/package.json +11 -6
- package/src/app/application.tsx +49 -7
- package/src/appearance/custom-theme-import.ts +67 -7
- package/src/appearance/custom-theme-library.ts +391 -33
- package/src/appearance/editor.ts +49 -10
- package/src/appearance/theme-file-importer.ts +43 -12
- package/src/appearance/theme-library-action-fence.ts +28 -0
- package/src/desktop/client-asset-stream.ts +118 -0
- package/src/desktop/client-assets.ts +55 -5
- package/src/shell/app-shell.tsx +71 -8
- package/src/shell/app-utilities.tsx +2 -2
- package/src/updates/update-adapter.ts +5 -0
- package/src/views/appearance-surface.tsx +61 -29
- package/templates/application/README.md +5 -1
- package/templates/application/scripts/app-version.ts +7 -3
- package/templates/application/src/bun/index.ts +2 -0
|
@@ -1,41 +1,18 @@
|
|
|
1
1
|
import { assertInstallerContext, assertInstallerLayout, assertPortableAppName } from "./installer-layout.js";
|
|
2
2
|
import { assertNativeExecutable } from "./native-executable.js";
|
|
3
|
+
import { cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, withInstallerImageRetries } from "./installer-image-mount.js";
|
|
4
|
+
import { runInstallerCommand } from "./installer-command.js";
|
|
3
5
|
import { verifyInstallerPayload } from "./installer-identity.js";
|
|
4
|
-
import { chmod, lstat, mkdir, mkdtemp, open, readdir, realpath
|
|
6
|
+
import { chmod, lstat, mkdir, mkdtemp, open, readdir, realpath } from "node:fs/promises";
|
|
5
7
|
import { isAbsolute, join, relative, resolve, sep, win32 } from "node:path";
|
|
6
8
|
import { createHash } from "node:crypto";
|
|
7
9
|
// src/installer/installer-extraction.ts
|
|
8
10
|
async function run(cmd, env) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
stderr: "pipe",
|
|
14
|
-
signal: AbortSignal.timeout(12e4)
|
|
11
|
+
return runInstallerCommand(cmd, env, {
|
|
12
|
+
outputLimit: 8388608,
|
|
13
|
+
overflowMessage: "Installer command output exceeds bound",
|
|
14
|
+
failureMessage: "Installer preparation command failed"
|
|
15
15
|
});
|
|
16
|
-
const output = (async () => {
|
|
17
|
-
const chunks = [];
|
|
18
|
-
let size = 0;
|
|
19
|
-
for await (const chunk of child.stdout) {
|
|
20
|
-
size += chunk.length;
|
|
21
|
-
if (size > 8388608) {
|
|
22
|
-
child.kill();
|
|
23
|
-
throw new Error("Installer command output exceeds bound");
|
|
24
|
-
}
|
|
25
|
-
chunks.push(chunk);
|
|
26
|
-
}
|
|
27
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
28
|
-
})();
|
|
29
|
-
const errors = (async () => {
|
|
30
|
-
for await (const _chunk of child.stderr);
|
|
31
|
-
})();
|
|
32
|
-
const [text, , status] = await Promise.all([
|
|
33
|
-
output,
|
|
34
|
-
errors,
|
|
35
|
-
child.exited
|
|
36
|
-
]);
|
|
37
|
-
if (status !== 0) throw new Error("Installer preparation command failed");
|
|
38
|
-
return text;
|
|
39
16
|
}
|
|
40
17
|
async function extract(tar, archive, member, destination, maximum, env) {
|
|
41
18
|
const output = await open(destination, "wx", 384);
|
|
@@ -172,27 +149,20 @@ async function prepareInstallerExecution(options) {
|
|
|
172
149
|
env
|
|
173
150
|
});
|
|
174
151
|
const directory = await mkdtemp(join(parent, "framework-installer-"));
|
|
175
|
-
|
|
152
|
+
const imageIo = defaultInstallerImageMountIo(run);
|
|
176
153
|
try {
|
|
177
154
|
const profile = join(directory, "profile"), incoming = join(directory, "incoming");
|
|
178
155
|
await mkdir(profile, { mode: 448 });
|
|
179
156
|
await mkdir(incoming, { mode: 448 });
|
|
180
157
|
const clean = cleanEnv(env);
|
|
181
158
|
let executable;
|
|
182
|
-
if (options.platform === "macos-arm64") {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"-nobrowse",
|
|
190
|
-
"-mountpoint",
|
|
191
|
-
mount,
|
|
192
|
-
sourceInstaller
|
|
193
|
-
], clean);
|
|
194
|
-
mounted = true;
|
|
195
|
-
try {
|
|
159
|
+
if (options.platform === "macos-arm64") executable = await withInstallerImageRetries({
|
|
160
|
+
parent,
|
|
161
|
+
prefix: "framework-installer-mount-attempt-",
|
|
162
|
+
image: sourceInstaller,
|
|
163
|
+
env: clean,
|
|
164
|
+
run,
|
|
165
|
+
work: async (mount) => {
|
|
196
166
|
const appName = `${options.appName}.app`, apps = (await readdir(mount)).filter((name) => name.endsWith(".app"));
|
|
197
167
|
if (apps.length !== 1 || apps[0] !== appName) throw new Error("Unexpected installer application");
|
|
198
168
|
const sourceApp = await realpath(join(mount, appName));
|
|
@@ -214,24 +184,19 @@ async function prepareInstallerExecution(options) {
|
|
|
214
184
|
plist
|
|
215
185
|
], clean)).trim();
|
|
216
186
|
if (!name || name === "." || name === ".." || /[\\/]/.test(name)) throw new Error("Invalid installer executable");
|
|
217
|
-
|
|
187
|
+
const appExecutable = join(actualApp, "Contents", "MacOS", name);
|
|
218
188
|
const sourceExecutable = join(sourceApp, "Contents", "MacOS", name);
|
|
219
|
-
if (!within(actualApp, await realpath(
|
|
220
|
-
await assertExecutable(
|
|
221
|
-
if (JSON.stringify(await digest(sourceExecutable)) !== JSON.stringify(await digest(
|
|
189
|
+
if (!within(actualApp, await realpath(appExecutable)) || !within(sourceApp, await realpath(sourceExecutable))) throw new Error("Installer executable escapes application");
|
|
190
|
+
await assertExecutable(appExecutable, options.platform);
|
|
191
|
+
if (JSON.stringify(await digest(sourceExecutable)) !== JSON.stringify(await digest(appExecutable))) throw new Error("Copied installer executable differs");
|
|
222
192
|
const archives = (await readdir(resources)).filter((value) => value.endsWith(".tar.zst"));
|
|
223
193
|
if (archives.length !== 1) throw new Error("Missing installer archive");
|
|
224
194
|
const embedded = await digest(join(resources, archives[0]));
|
|
225
195
|
if (embedded.size !== verified.archive.size || embedded.digest !== verified.archive.digest) throw new Error("Copied installer archive differs");
|
|
226
|
-
|
|
227
|
-
await run([
|
|
228
|
-
"/usr/bin/hdiutil",
|
|
229
|
-
"detach",
|
|
230
|
-
mount
|
|
231
|
-
], clean);
|
|
232
|
-
mounted = false;
|
|
196
|
+
return executable;
|
|
233
197
|
}
|
|
234
|
-
}
|
|
198
|
+
});
|
|
199
|
+
else {
|
|
235
200
|
const root = env.SystemRoot;
|
|
236
201
|
if (options.platform === "windows-x64" && (!root || !/^[A-Za-z]:[\\/]/.test(root))) throw new Error("Missing Windows system directory");
|
|
237
202
|
const tar = options.platform === "windows-x64" ? win32.join(root, "System32", "tar.exe") : "tar";
|
|
@@ -279,10 +244,11 @@ async function prepareInstallerExecution(options) {
|
|
|
279
244
|
executable
|
|
280
245
|
};
|
|
281
246
|
} catch (error) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
247
|
+
try {
|
|
248
|
+
await cleanupInstallerDirectoryAfterFailure(directory, error, imageIo);
|
|
249
|
+
} catch (cleanupError) {
|
|
250
|
+
throw new AggregateError([error, cleanupError], "Installer preparation and cleanup failed", { cause: cleanupError });
|
|
251
|
+
}
|
|
286
252
|
throw error;
|
|
287
253
|
}
|
|
288
254
|
}
|
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
import { type InstallerPlatform } from './installer-layout';
|
|
2
|
+
import { type InstallerImageMountState } from './installer-image-mount';
|
|
2
3
|
import type { Artifact } from '../release/release-qualification';
|
|
3
4
|
export type ImageAttachIo = {
|
|
4
5
|
run(args: string[], env: Record<string, string>): Promise<unknown>;
|
|
5
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. */
|
|
6
10
|
wait(ms: number): Promise<unknown>;
|
|
7
11
|
};
|
|
8
12
|
/**
|
|
9
|
-
* Attach
|
|
10
|
-
*
|
|
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.
|
|
11
23
|
*/
|
|
12
24
|
export declare function attachImage(mount: string, image: string, env: Record<string, string>, io?: ImageAttachIo): Promise<void>;
|
|
13
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Inspect a shipped installer without executing it, on a matching disposable runner.
|
|
27
|
+
* macOS attach gets up to three attempts at fresh private mountpoints. Failed-attempt
|
|
28
|
+
* directories remain available for recovery because Disk Arbitration may mount them later.
|
|
29
|
+
*/
|
|
14
30
|
export declare function verifyInstallerPayload(options: {
|
|
15
31
|
platform: InstallerPlatform;
|
|
16
32
|
appName: string;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { assertInstallerContext, assertInstallerLayout, assertPortableAppName } from "./installer-layout.js";
|
|
2
2
|
import { assertNativeExecutable } from "./native-executable.js";
|
|
3
|
-
import {
|
|
3
|
+
import { InstallerImageLifecycleError, cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, installerImageMountState, withInstallerImageRetries } from "./installer-image-mount.js";
|
|
4
|
+
import { runInstallerCommand } from "./installer-command.js";
|
|
5
|
+
import { lstat, mkdtemp, open, readdir, realpath } from "node:fs/promises";
|
|
4
6
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep, win32 } from "node:path";
|
|
5
7
|
import { createHash } from "node:crypto";
|
|
6
8
|
import { tmpdir } from "node:os";
|
|
@@ -44,26 +46,36 @@ function environment(parent) {
|
|
|
44
46
|
]) if (parent[name]) env[name] = parent[name];
|
|
45
47
|
return env;
|
|
46
48
|
}
|
|
47
|
-
/** Hosted macOS runners intermittently refuse an attach while disk arbitration is busy. */
|
|
48
49
|
/** Whether a volume is mounted at a directory; unknown counts as mounted. */
|
|
49
50
|
async function volumeAt(mount) {
|
|
50
|
-
|
|
51
|
-
const [own, parent] = await Promise.all([stat(mount), stat(dirname(mount))]);
|
|
52
|
-
return own.dev !== parent.dev;
|
|
53
|
-
} catch {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
51
|
+
return await installerImageMountState(mount) !== "unmounted";
|
|
56
52
|
}
|
|
57
53
|
/**
|
|
58
|
-
* Attach
|
|
59
|
-
*
|
|
54
|
+
* Attach once at a caller-provided mountpoint. The caller must create and reserve a fresh,
|
|
55
|
+
* empty mountpoint exclusively for this image operation, and keep it exclusive until this
|
|
56
|
+
* call finishes. The state probe rejects paths that are already mounted or whose state is
|
|
57
|
+
* unknown, but a mounted-state probe does not identify which image owns a volume; this API
|
|
58
|
+
* trusts the caller's exclusivity precondition and does not claim to verify image identity.
|
|
59
|
+
*
|
|
60
|
+
* A failed attach is indeterminate, so this function never retries or detaches by path and
|
|
61
|
+
* the caller must retain its temporary directory for recovery. This changes the former
|
|
62
|
+
* three-attempt, five-second retry behavior; internal verification and extraction preserve
|
|
63
|
+
* three attempts by using fresh private mountpoints and retaining failed-attempt directories.
|
|
60
64
|
*/
|
|
61
65
|
async function attachImage(mount, image, env, io = {
|
|
62
66
|
run: command,
|
|
63
67
|
mounted: volumeAt,
|
|
68
|
+
state: installerImageMountState,
|
|
64
69
|
wait: Bun.sleep
|
|
65
70
|
}) {
|
|
66
|
-
|
|
71
|
+
let initialState;
|
|
72
|
+
try {
|
|
73
|
+
initialState = io.state ? await io.state(mount) : await io.mounted(mount) ? "mounted" : "unmounted";
|
|
74
|
+
} catch (error) {
|
|
75
|
+
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}`);
|
|
76
|
+
}
|
|
77
|
+
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}`);
|
|
78
|
+
try {
|
|
67
79
|
await io.run([
|
|
68
80
|
"/usr/bin/hdiutil",
|
|
69
81
|
"attach",
|
|
@@ -73,49 +85,23 @@ async function attachImage(mount, image, env, io = {
|
|
|
73
85
|
mount,
|
|
74
86
|
image
|
|
75
87
|
], env);
|
|
76
|
-
return;
|
|
77
88
|
} catch (error) {
|
|
78
|
-
|
|
79
|
-
"/usr/bin/hdiutil",
|
|
80
|
-
"detach",
|
|
81
|
-
"-force",
|
|
82
|
-
mount
|
|
83
|
-
], env);
|
|
84
|
-
if (attempt === 3) throw error;
|
|
85
|
-
await io.wait(5e3);
|
|
89
|
+
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}`);
|
|
86
90
|
}
|
|
91
|
+
let state;
|
|
92
|
+
try {
|
|
93
|
+
state = io.state ? await io.state(mount) : await io.mounted(mount) ? "mounted" : "unmounted";
|
|
94
|
+
} catch (error) {
|
|
95
|
+
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}`);
|
|
96
|
+
}
|
|
97
|
+
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}`);
|
|
87
98
|
}
|
|
88
99
|
async function command(args, env) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
stderr: "pipe",
|
|
94
|
-
signal: AbortSignal.timeout(12e4)
|
|
100
|
+
return runInstallerCommand(args, env, {
|
|
101
|
+
outputLimit: 8388608,
|
|
102
|
+
overflowMessage: "Installer listing exceeds bound",
|
|
103
|
+
failureMessage: "Installer inspection command failed"
|
|
95
104
|
});
|
|
96
|
-
const stdout = (async () => {
|
|
97
|
-
let size = 0;
|
|
98
|
-
const chunks = [];
|
|
99
|
-
for await (const chunk of child.stdout) {
|
|
100
|
-
size += chunk.length;
|
|
101
|
-
if (size > 8388608) {
|
|
102
|
-
child.kill();
|
|
103
|
-
throw new Error("Installer listing exceeds bound");
|
|
104
|
-
}
|
|
105
|
-
chunks.push(Buffer.from(chunk));
|
|
106
|
-
}
|
|
107
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
108
|
-
})();
|
|
109
|
-
const stderr = (async () => {
|
|
110
|
-
for await (const _chunk of child.stderr);
|
|
111
|
-
})();
|
|
112
|
-
const [text, , status] = await Promise.all([
|
|
113
|
-
stdout,
|
|
114
|
-
stderr,
|
|
115
|
-
child.exited
|
|
116
|
-
]);
|
|
117
|
-
if (status !== 0) throw new Error("Installer inspection command failed");
|
|
118
|
-
return text;
|
|
119
105
|
}
|
|
120
106
|
async function extractMember(tar, installer, member, output, maximum, env) {
|
|
121
107
|
const file = await open(output, "wx", 384);
|
|
@@ -179,7 +165,11 @@ function within(root, path) {
|
|
|
179
165
|
const rel = relative(root, path);
|
|
180
166
|
return rel !== "" && rel !== ".." && !rel.startsWith(".." + sep) && !isAbsolute(rel);
|
|
181
167
|
}
|
|
182
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Inspect a shipped installer without executing it, on a matching disposable runner.
|
|
170
|
+
* macOS attach gets up to three attempts at fresh private mountpoints. Failed-attempt
|
|
171
|
+
* directories remain available for recovery because Disk Arbitration may mount them later.
|
|
172
|
+
*/
|
|
183
173
|
async function verifyInstallerPayload(options) {
|
|
184
174
|
const parent = options.env ?? process.env;
|
|
185
175
|
assertInstallerContext(parent, options.platform, process.platform, process.arch);
|
|
@@ -192,14 +182,15 @@ async function verifyInstallerPayload(options) {
|
|
|
192
182
|
if (!Number.isSafeInteger(before.archive.size + 268435456)) throw new Error("Installer archive exceeds bound");
|
|
193
183
|
const env = environment(parent);
|
|
194
184
|
const temporary = await mkdtemp(join(tmpdir(), "framework-installer-inspect-"));
|
|
195
|
-
const
|
|
196
|
-
let mounted = false;
|
|
185
|
+
const cleanupIo = defaultInstallerImageMountIo(command);
|
|
197
186
|
try {
|
|
198
|
-
if (options.platform === "macos-arm64") {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
187
|
+
if (options.platform === "macos-arm64") await withInstallerImageRetries({
|
|
188
|
+
parent: tmpdir(),
|
|
189
|
+
prefix: "framework-installer-inspect-attempt-",
|
|
190
|
+
image: installerPath,
|
|
191
|
+
env,
|
|
192
|
+
run: command,
|
|
193
|
+
work: async (mount) => {
|
|
203
194
|
const apps = (await readdir(mount)).filter((name) => name.endsWith(".app"));
|
|
204
195
|
if (apps.length !== 1) throw new Error("Installer application is missing or ambiguous");
|
|
205
196
|
const resources = join(mount, apps[0], "Contents", "Resources");
|
|
@@ -219,15 +210,9 @@ async function verifyInstallerPayload(options) {
|
|
|
219
210
|
if (archives.length !== 1) throw new Error("Installer archive is missing or ambiguous");
|
|
220
211
|
const embedded = await identity(join(actualResources, archives[0]));
|
|
221
212
|
if (embedded.size !== before.archive.size || embedded.digest !== before.archive.digest) throw new Error("Installer archive differs from release archive");
|
|
222
|
-
} finally {
|
|
223
|
-
await command([
|
|
224
|
-
"/usr/bin/hdiutil",
|
|
225
|
-
"detach",
|
|
226
|
-
mount
|
|
227
|
-
], env);
|
|
228
|
-
mounted = false;
|
|
229
213
|
}
|
|
230
|
-
}
|
|
214
|
+
});
|
|
215
|
+
else {
|
|
231
216
|
const systemRoot = parent.SystemRoot;
|
|
232
217
|
if (options.platform === "windows-x64" && (!systemRoot || !/^[A-Za-z]:[\\/]/.test(systemRoot))) throw new Error("Missing Windows system directory");
|
|
233
218
|
const tar = options.platform === "windows-x64" ? win32.join(systemRoot, "System32", "tar.exe") : "tar";
|
|
@@ -275,12 +260,15 @@ async function verifyInstallerPayload(options) {
|
|
|
275
260
|
archive: await identity(archivePath)
|
|
276
261
|
};
|
|
277
262
|
if (JSON.stringify(before) !== JSON.stringify(after)) throw new Error("Installer artifacts changed during inspection");
|
|
263
|
+
await cleanupInstallerDirectoryAfterFailure(temporary, void 0, cleanupIo);
|
|
278
264
|
return before;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
265
|
+
} catch (error) {
|
|
266
|
+
try {
|
|
267
|
+
await cleanupInstallerDirectoryAfterFailure(temporary, error, cleanupIo);
|
|
268
|
+
} catch (cleanupError) {
|
|
269
|
+
throw new AggregateError([error, cleanupError], "Installer inspection and cleanup failed", { cause: cleanupError });
|
|
270
|
+
}
|
|
271
|
+
throw error;
|
|
284
272
|
}
|
|
285
273
|
}
|
|
286
274
|
export { attachImage, verifyInstallerPayload };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type InstallerImageMountState = 'mounted' | 'unmounted' | 'unknown';
|
|
2
|
+
export type InstallerImageMountIo = {
|
|
3
|
+
run(args: string[], env: Record<string, string>): Promise<unknown>;
|
|
4
|
+
state(mount: string): Promise<InstallerImageMountState>;
|
|
5
|
+
containsNestedMount(directory: string): Promise<boolean>;
|
|
6
|
+
wait(ms: number): Promise<unknown>;
|
|
7
|
+
remove(directory: string): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export declare function installerImageMountState(mount: string): Promise<InstallerImageMountState>;
|
|
10
|
+
export declare function defaultInstallerImageMountIo(run: InstallerImageMountIo['run']): InstallerImageMountIo;
|
|
11
|
+
/** Skip only cleanup already owned by this exact lifecycle attempt. */
|
|
12
|
+
export declare function cleanupInstallerDirectoryAfterFailure(directory: string, error: unknown, io: InstallerImageMountIo): Promise<void>;
|
|
13
|
+
export declare class InstallerImageLifecycleError extends AggregateError {
|
|
14
|
+
readonly directoryRetained: boolean;
|
|
15
|
+
readonly directory: string;
|
|
16
|
+
readonly phase: 'attach' | 'lifecycle';
|
|
17
|
+
constructor(errors: unknown[], directoryRetained: boolean, directory: string, phase?: 'attach' | 'lifecycle', message?: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Attach an installer image, inspect/copy its contents, and reconcile the mount before
|
|
21
|
+
* allowing recursive cleanup. A failed attach is always treated as indeterminate because
|
|
22
|
+
* disk arbitration can finish mounting after the attach command has exited.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withInstallerImage<T>(options: {
|
|
25
|
+
directory: string;
|
|
26
|
+
mount: string;
|
|
27
|
+
image: string;
|
|
28
|
+
env: Record<string, string>;
|
|
29
|
+
io: InstallerImageMountIo;
|
|
30
|
+
work(): Promise<T>;
|
|
31
|
+
}): Promise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Retry a transient attach only with fresh mountpoints. Failed paths are retained and
|
|
34
|
+
* rechecked during backoff and after a later success; finite checks cannot rule out a
|
|
35
|
+
* mount that appears later, so callers must not treat retries as proof those paths are gone.
|
|
36
|
+
*/
|
|
37
|
+
export declare function withInstallerImageRetries<T>(options: {
|
|
38
|
+
parent: string;
|
|
39
|
+
prefix: string;
|
|
40
|
+
image: string;
|
|
41
|
+
env: Record<string, string>;
|
|
42
|
+
run: InstallerImageMountIo['run'];
|
|
43
|
+
attempts?: number;
|
|
44
|
+
retryDelayMs?: number;
|
|
45
|
+
createIo?: (directory: string, mount: string) => InstallerImageMountIo;
|
|
46
|
+
onRecovered?: (failures: InstallerImageLifecycleError[]) => void;
|
|
47
|
+
work(mount: string): Promise<T>;
|
|
48
|
+
}): Promise<T>;
|