@adea-ai/app-framework 0.24.0 → 0.24.1
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 +43 -1
- package/dist/framework-source.json +1 -1
- package/dist/release/framework-package-publish.js +4 -2
- package/dist/shell/app-shell.js +21 -33
- package/dist/shell/navigation-drawer.d.ts +12 -0
- package/dist/shell/navigation-drawer.js +42 -0
- package/package.json +13 -2
- package/src/shell/app-shell.tsx +29 -20
- package/src/shell/navigation-drawer.tsx +36 -0
- package/src/app/create-application.ts +0 -245
- package/src/app/service-registry.ts +0 -124
- package/src/ci/toolchain-identity.ts +0 -244
- package/src/cli/cef-helper-cli.ts +0 -21
- package/src/cli/cli-runner.ts +0 -29
- package/src/cli/create-application-cli.ts +0 -62
- package/src/cli/electrobun-shortcut-patch-cli.ts +0 -24
- package/src/cli/framework-update-cli.ts +0 -41
- package/src/cli/release-assets-plan-cli.ts +0 -14
- package/src/cli/release-cut-cli.ts +0 -41
- package/src/cli/release-descriptor-staging-cli.ts +0 -57
- package/src/cli/release-finalize-cli.ts +0 -34
- package/src/cli/release-promote-cli.ts +0 -31
- package/src/cli/release-publish-cli.ts +0 -46
- package/src/cli/release-sign-cli.ts +0 -24
- package/src/cli/release-step-cli.ts +0 -71
- package/src/cli/toolchain-identity-cli.ts +0 -12
- package/src/cli/update-helper-cli.ts +0 -12
- package/src/cli/windows-runtime-patch-cli.ts +0 -17
- package/src/desktop/application-command-client.ts +0 -43
- package/src/desktop/channel-handshake.ts +0 -136
- package/src/desktop/channel-proof.ts +0 -122
- package/src/desktop/desktop-client.ts +0 -303
- package/src/desktop/desktop-gateway.ts +0 -189
- package/src/desktop/desktop-host.ts +0 -335
- package/src/desktop/desktop-stream.ts +0 -324
- package/src/desktop/loopback-policy.ts +0 -41
- package/src/desktop/open-url-channel.ts +0 -79
- package/src/desktop/string-policy.ts +0 -9
- package/src/installer/archive-entry.ts +0 -32
- package/src/installer/command-artifact.ts +0 -307
- package/src/installer/command-qualification-command.ts +0 -75
- package/src/installer/hosted-runner.ts +0 -11
- package/src/installer/installed-payload.ts +0 -408
- package/src/installer/installer-ci-bootstrap.ts +0 -199
- package/src/installer/installer-ci-preflight.ts +0 -61
- package/src/installer/installer-ci-worker.ts +0 -105
- package/src/installer/installer-extraction.ts +0 -367
- package/src/installer/installer-fetch-guard.ts +0 -75
- package/src/installer/installer-identity.ts +0 -331
- package/src/installer/installer-layout.ts +0 -167
- package/src/installer/installer-observation.ts +0 -671
- package/src/installer/installer-process-cleanup.ts +0 -167
- package/src/installer/installer-qualification-command.ts +0 -81
- package/src/installer/installer-renderer-evidence.ts +0 -268
- package/src/installer/installer-upgrade-command.ts +0 -226
- package/src/installer/installer-worker-guard.ts +0 -112
- package/src/installer/native-executable.ts +0 -37
- package/src/installer/upgrade-asset-download.ts +0 -72
- package/src/installer/write-all.ts +0 -19
- package/src/native/app-bundle.ts +0 -86
- package/src/native/cef-helper.ts +0 -471
- package/src/native/desktop-build-hook.ts +0 -21
- package/src/native/electrobun-source-patch.ts +0 -107
- package/src/native/linux-cef-links.ts +0 -14
- package/src/native/native-secret-store.ts +0 -99
- package/src/native/native-utilities.ts +0 -166
- package/src/native/partitioned-window.ts +0 -62
- package/src/native/secure-window.ts +0 -115
- package/src/native/sidecar-services.ts +0 -71
- package/src/native/sidecar.ts +0 -387
- package/src/native/window-bootstrap.ts +0 -77
- package/src/native/windows-build-hook-internal.ts +0 -49
- package/src/native/windows-build-hook.ts +0 -12
- package/src/native/windows-runtime-patch-internal.ts +0 -48
- package/src/native/windows-runtime-patch.ts +0 -15
- package/src/release/feed-release-cut.ts +0 -110
- package/src/release/feed-state.ts +0 -135
- package/src/release/framework-package-publish.ts +0 -163
- package/src/release/framework-update.ts +0 -196
- package/src/release/github-cli.ts +0 -27
- package/src/release/github-release-assets.ts +0 -36
- package/src/release/github-release-cut.ts +0 -237
- package/src/release/github-release-lookup.ts +0 -39
- package/src/release/github-release-promotion.ts +0 -112
- package/src/release/github-release-provenance.ts +0 -65
- package/src/release/github-release-publisher.ts +0 -90
- package/src/release/github-release-qualification.ts +0 -144
- package/src/release/local-provenance.ts +0 -92
- package/src/release/local-release.ts +0 -525
- package/src/release/macos-dmg.ts +0 -113
- package/src/release/release-artifact.ts +0 -53
- package/src/release/release-assets-plan.ts +0 -118
- package/src/release/release-config.ts +0 -420
- package/src/release/release-cut-command.ts +0 -80
- package/src/release/release-cut.ts +0 -133
- package/src/release/release-descriptor-staging.ts +0 -242
- package/src/release/release-finalize.ts +0 -191
- package/src/release/release-promotion-command.ts +0 -36
- package/src/release/release-promotion.ts +0 -132
- package/src/release/release-publication.ts +0 -213
- package/src/release/release-publish-command.ts +0 -163
- package/src/release/release-qualification.ts +0 -397
- package/src/release/release-staging.ts +0 -87
- package/src/release/release-steps.ts +0 -173
- package/src/release/retained-release-build.ts +0 -217
- package/src/shell/application-menu-commands.ts +0 -6
- package/src/shell/application-menu.ts +0 -250
- package/src/updates/channel-update-manager.ts +0 -127
- package/src/updates/desktop-updater.ts +0 -440
- package/src/updates/release-feed.ts +0 -187
- package/src/updates/release-location.ts +0 -101
- package/src/updates/signed-release.ts +0 -311
- package/src/updates/stable-file.ts +0 -32
- package/src/updates/update-arm.ts +0 -107
- package/src/updates/update-channel-store.ts +0 -86
- package/src/updates/update-discovery.ts +0 -113
- package/src/updates/update-download.ts +0 -82
- package/src/updates/update-exclusive-rename.ts +0 -58
- package/src/updates/update-extraction.ts +0 -261
- package/src/updates/update-handoff-plan.ts +0 -75
- package/src/updates/update-helper.ts +0 -87
- package/src/updates/update-launch.ts +0 -33
- package/src/updates/update-manager.ts +0 -130
- package/src/updates/update-process-fence.ts +0 -125
- package/src/updates/update-resume.ts +0 -34
- package/src/updates/update-shutdown.ts +0 -37
- package/src/updates/update-swap-stage.ts +0 -75
- package/src/updates/update-swap.ts +0 -30
|
@@ -1,671 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from 'node:crypto'
|
|
2
|
-
import { chmod, lstat, mkdir, readFile, realpath, writeFile } from 'node:fs/promises'
|
|
3
|
-
import { createServer } from 'node:net'
|
|
4
|
-
import { delimiter, dirname, join } from 'node:path'
|
|
5
|
-
import { preflightInstallerRuntime, prepareInstallerCiBootstrap } from './installer-ci-bootstrap'
|
|
6
|
-
import { prepareInstallerExecution } from './installer-extraction'
|
|
7
|
-
import { verifyInstallerPayload } from './installer-identity'
|
|
8
|
-
import {
|
|
9
|
-
assertInstallerContext,
|
|
10
|
-
assertPortableAppName,
|
|
11
|
-
type InstallerPlatform,
|
|
12
|
-
type InstallerRenderer,
|
|
13
|
-
} from './installer-layout'
|
|
14
|
-
import {
|
|
15
|
-
assertInstallerRendererObservation,
|
|
16
|
-
type InstallerRendererObservation,
|
|
17
|
-
} from './installer-renderer-evidence'
|
|
18
|
-
import { extractCandidateRuntime, verifyInstalledPayload } from './installed-payload'
|
|
19
|
-
import {
|
|
20
|
-
parseOfflinePolicy,
|
|
21
|
-
type Artifact,
|
|
22
|
-
type OfflinePolicy,
|
|
23
|
-
type RendererEvidence,
|
|
24
|
-
} from '../release/release-qualification'
|
|
25
|
-
import { terminateGuardedWorker } from './installer-process-cleanup'
|
|
26
|
-
import type { ReleaseTrust, VerifiedRelease } from '../updates/signed-release'
|
|
27
|
-
import { stageUpdateSwap } from '../updates/update-swap-stage'
|
|
28
|
-
import { swapUpdateTree } from '../updates/update-swap'
|
|
29
|
-
|
|
30
|
-
function isolatedEnv(
|
|
31
|
-
parent: Record<string, string | undefined>,
|
|
32
|
-
profile: string,
|
|
33
|
-
platform: InstallerPlatform
|
|
34
|
-
): Record<string, string> {
|
|
35
|
-
const env: Record<string, string> = {}
|
|
36
|
-
for (const name of [
|
|
37
|
-
'PATH',
|
|
38
|
-
'SystemRoot',
|
|
39
|
-
'WINDIR',
|
|
40
|
-
'COMSPEC',
|
|
41
|
-
'PATHEXT',
|
|
42
|
-
'LANG',
|
|
43
|
-
'LC_ALL',
|
|
44
|
-
'DISPLAY',
|
|
45
|
-
'XAUTHORITY',
|
|
46
|
-
'DBUS_SESSION_BUS_ADDRESS',
|
|
47
|
-
])
|
|
48
|
-
if (parent[name]) env[name] = parent[name]!
|
|
49
|
-
Object.assign(env, {
|
|
50
|
-
CI: 'true',
|
|
51
|
-
GITHUB_ACTIONS: 'true',
|
|
52
|
-
RUNNER_ENVIRONMENT: 'github-hosted',
|
|
53
|
-
HOME: profile,
|
|
54
|
-
USERPROFILE: profile,
|
|
55
|
-
LOCALAPPDATA: join(profile, 'LocalAppData'),
|
|
56
|
-
XDG_DATA_HOME: join(profile, '.local', 'share'),
|
|
57
|
-
TMP: join(profile, 'tmp'),
|
|
58
|
-
TEMP: join(profile, 'tmp'),
|
|
59
|
-
TMPDIR: join(profile, 'tmp'),
|
|
60
|
-
ELECTROBUN_INSTALLER_UI_AUTOCLOSE: '1',
|
|
61
|
-
})
|
|
62
|
-
if (platform === 'windows-x64') env.TAR_OPTIONS = '--force-local'
|
|
63
|
-
return env
|
|
64
|
-
}
|
|
65
|
-
async function choosePort(): Promise<number> {
|
|
66
|
-
const server = createServer()
|
|
67
|
-
await new Promise<void>((resolve, reject) => {
|
|
68
|
-
server.once('error', reject)
|
|
69
|
-
server.listen(0, '127.0.0.1', resolve)
|
|
70
|
-
})
|
|
71
|
-
const address = server.address()
|
|
72
|
-
if (!address || typeof address === 'string' || address.port < 1024) {
|
|
73
|
-
server.close()
|
|
74
|
-
throw new Error('Cannot reserve test port')
|
|
75
|
-
}
|
|
76
|
-
await new Promise<void>((resolve, reject) =>
|
|
77
|
-
server.close((error) => (error ? reject(error) : resolve()))
|
|
78
|
-
)
|
|
79
|
-
return address.port
|
|
80
|
-
}
|
|
81
|
-
async function boundedJson(path: string): Promise<unknown> {
|
|
82
|
-
const info = await lstat(path)
|
|
83
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 16384)
|
|
84
|
-
throw new Error('Invalid renderer observation')
|
|
85
|
-
const bytes = await readFile(path)
|
|
86
|
-
if (bytes.length !== info.size) throw new Error('Renderer observation changed')
|
|
87
|
-
return JSON.parse(bytes.toString('utf8'))
|
|
88
|
-
}
|
|
89
|
-
async function exists(path: string): Promise<boolean> {
|
|
90
|
-
try {
|
|
91
|
-
await lstat(path)
|
|
92
|
-
return true
|
|
93
|
-
} catch (error) {
|
|
94
|
-
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false
|
|
95
|
-
throw error
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/** Whether the runner should start the installed app on this loop iteration.
|
|
99
|
-
*
|
|
100
|
-
* Electrobun's Windows and Linux extractors (since 2.0.1, `launchInstalledApp` in
|
|
101
|
-
* package/src/extractor/main.zig, still in 2.0.5) start the installed launcher themselves after
|
|
102
|
-
* a first install, inheriting the runner's isolated environment and guard context. Starting a
|
|
103
|
-
* second launcher there runs two instances against one profile: one Chromium/CEF profile
|
|
104
|
-
* (`root_cache_path`) admits a single process, while the worker guard admits whichever worker
|
|
105
|
-
* writes its identity first. When those two races pick different processes, the guarded worker
|
|
106
|
-
* never gets a renderer and its process exits after the permit. So the runner never starts the
|
|
107
|
-
* app on Windows or Linux. The macOS installer instead asks `open -n`, which the launch shim
|
|
108
|
-
* records without opening anything, so the runner starts the recorded bundle exactly once. */
|
|
109
|
-
/**
|
|
110
|
-
* The installer's last `error: Name` line, for diagnosing a failed install.
|
|
111
|
-
* Only a bounded identifier is returned: never paths, output or credentials.
|
|
112
|
-
*/
|
|
113
|
-
export function installerErrorName(stderr: string): string | undefined {
|
|
114
|
-
let name: string | undefined
|
|
115
|
-
for (const match of stderr.matchAll(/^error: ([A-Za-z][A-Za-z0-9_]{0,63})\s*$/gm)) name = match[1]
|
|
116
|
-
return name
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function boundedStderr(stream: ReadableStream<Uint8Array>, limit = 64 * 1024) {
|
|
120
|
-
const decoder = new TextDecoder()
|
|
121
|
-
let text = ''
|
|
122
|
-
for await (const chunk of stream) {
|
|
123
|
-
if (text.length < limit) text += decoder.decode(chunk, { stream: true })
|
|
124
|
-
}
|
|
125
|
-
return text.slice(-limit)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function shouldLaunchInstalledApp(state: {
|
|
129
|
-
platform: InstallerPlatform
|
|
130
|
-
ready: boolean
|
|
131
|
-
launched: boolean
|
|
132
|
-
acknowledged: boolean
|
|
133
|
-
installerExit: number | null
|
|
134
|
-
}): boolean {
|
|
135
|
-
return (
|
|
136
|
-
state.platform === 'macos-arm64' &&
|
|
137
|
-
state.ready &&
|
|
138
|
-
!state.launched &&
|
|
139
|
-
!state.acknowledged &&
|
|
140
|
-
state.installerExit === 0
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const shim = `#!/bin/sh\numask 077\nif [ "\${CI:-}" != true ] || [ "\${GITHUB_ACTIONS:-}" != true ] || [ "\${RUNNER_ENVIRONMENT:-}" != github-hosted ] || [ "$#" -ne 2 ] || [ "$1" != "-n" ] || [ "$2" != "\${FRAMEWORK_CI_EXPECTED_APP:-}" ] || [ -z "\${FRAMEWORK_CI_LAUNCH_RECORD:-}" ] || [ -e "$FRAMEWORK_CI_LAUNCH_RECORD" ]; then exit 1; fi\n(set -C; printf '%s\\n' "$2" > "$FRAMEWORK_CI_LAUNCH_RECORD")\n`
|
|
145
|
-
|
|
146
|
-
/** Execute an installer only on a matching disposable hosted runner and return raw observations.
|
|
147
|
-
* This does not produce a release receipt or establish app-specific offline acceptance. */
|
|
148
|
-
export async function observeInstalledApp(options: {
|
|
149
|
-
platform: InstallerPlatform
|
|
150
|
-
renderer: InstallerRenderer
|
|
151
|
-
appName: string
|
|
152
|
-
appId: string
|
|
153
|
-
version: string
|
|
154
|
-
installer: string
|
|
155
|
-
archive: string
|
|
156
|
-
expectedReads?: readonly string[]
|
|
157
|
-
onStage?: (stage: string) => void
|
|
158
|
-
offlinePolicy?: OfflinePolicy
|
|
159
|
-
/** Sidecar executables the app bundles; installed copies must match the archive. */
|
|
160
|
-
sidecars?: readonly string[]
|
|
161
|
-
env?: Record<string, string | undefined>
|
|
162
|
-
/** After observing the installed version, apply this signed update and observe the new version. */
|
|
163
|
-
update?: {
|
|
164
|
-
descriptor: VerifiedRelease
|
|
165
|
-
trust: ReleaseTrust
|
|
166
|
-
archive: string
|
|
167
|
-
maxCompressedBytes: number
|
|
168
|
-
maxExpandedBytes: number
|
|
169
|
-
}
|
|
170
|
-
}): Promise<{
|
|
171
|
-
directory: string
|
|
172
|
-
observation: InstallerRendererObservation
|
|
173
|
-
blockedReads: number
|
|
174
|
-
artifacts: Artifact[]
|
|
175
|
-
evidence?: RendererEvidence
|
|
176
|
-
updated?: {
|
|
177
|
-
version: string
|
|
178
|
-
observation: InstallerRendererObservation
|
|
179
|
-
blockedReads: number
|
|
180
|
-
evidence?: RendererEvidence
|
|
181
|
-
}
|
|
182
|
-
}> {
|
|
183
|
-
const parent = options.env ?? process.env
|
|
184
|
-
const stage = (name: string) => {
|
|
185
|
-
try {
|
|
186
|
-
options.onStage?.(name)
|
|
187
|
-
} catch {
|
|
188
|
-
/* Diagnostics cannot change qualification. */
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
assertInstallerContext(parent, options.platform, process.platform, process.arch)
|
|
192
|
-
assertPortableAppName(options.appName)
|
|
193
|
-
if (
|
|
194
|
-
!/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(options.appId) ||
|
|
195
|
-
options.appId.length > 255 ||
|
|
196
|
-
!/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(options.version) ||
|
|
197
|
-
options.version.length > 64 ||
|
|
198
|
-
(options.platform === 'linux-x64' && !parent.DISPLAY)
|
|
199
|
-
)
|
|
200
|
-
throw new Error('Invalid installer observation context')
|
|
201
|
-
const policy =
|
|
202
|
-
options.offlinePolicy === undefined ? undefined : parseOfflinePolicy(options.offlinePolicy)
|
|
203
|
-
const expectedReads = options.expectedReads ?? []
|
|
204
|
-
if (
|
|
205
|
-
!Array.isArray(expectedReads) ||
|
|
206
|
-
expectedReads.length > 32 ||
|
|
207
|
-
new Set(expectedReads).size !== expectedReads.length ||
|
|
208
|
-
JSON.stringify(expectedReads).length > 8192
|
|
209
|
-
)
|
|
210
|
-
throw new Error('Invalid expected reads')
|
|
211
|
-
for (const value of expectedReads) {
|
|
212
|
-
if (typeof value !== 'string' || value.length > 2048) throw new Error('Invalid expected read')
|
|
213
|
-
const url = new URL(value)
|
|
214
|
-
if (url.protocol !== 'https:' || url.username || url.password || url.hash || url.href !== value)
|
|
215
|
-
throw new Error('Invalid expected read')
|
|
216
|
-
}
|
|
217
|
-
const before = await verifyInstallerPayload({
|
|
218
|
-
platform: options.platform,
|
|
219
|
-
appName: options.appName,
|
|
220
|
-
installer: options.installer,
|
|
221
|
-
archive: options.archive,
|
|
222
|
-
env: parent,
|
|
223
|
-
})
|
|
224
|
-
stage('artifacts-verified')
|
|
225
|
-
const prepared = await prepareInstallerExecution({
|
|
226
|
-
platform: options.platform,
|
|
227
|
-
appName: options.appName,
|
|
228
|
-
installer: options.installer,
|
|
229
|
-
archive: options.archive,
|
|
230
|
-
env: parent,
|
|
231
|
-
})
|
|
232
|
-
stage('installer-prepared')
|
|
233
|
-
const bootstrap = await prepareInstallerCiBootstrap(parent)
|
|
234
|
-
const candidate = await extractCandidateRuntime({
|
|
235
|
-
platform: options.platform,
|
|
236
|
-
renderer: options.renderer,
|
|
237
|
-
appName: options.appName,
|
|
238
|
-
archive: options.archive,
|
|
239
|
-
profile: prepared.profile,
|
|
240
|
-
env: parent,
|
|
241
|
-
})
|
|
242
|
-
stage('runtime-extracted')
|
|
243
|
-
await preflightInstallerRuntime({ env: parent, runtime: candidate.path, bootstrap })
|
|
244
|
-
stage('runtime-preflight-passed')
|
|
245
|
-
for (const path of [
|
|
246
|
-
join(prepared.profile, 'LocalAppData'),
|
|
247
|
-
join(prepared.profile, '.local', 'share'),
|
|
248
|
-
join(prepared.profile, 'tmp'),
|
|
249
|
-
])
|
|
250
|
-
await mkdir(path, { recursive: true, mode: 0o700 })
|
|
251
|
-
const mac = options.platform === 'macos-arm64',
|
|
252
|
-
windows = options.platform === 'windows-x64'
|
|
253
|
-
const installedRoot = mac
|
|
254
|
-
? join(prepared.incoming, `${options.appName}.app`, 'Contents')
|
|
255
|
-
: join(
|
|
256
|
-
prepared.profile,
|
|
257
|
-
windows ? 'LocalAppData' : '.local/share',
|
|
258
|
-
options.appId,
|
|
259
|
-
'stable',
|
|
260
|
-
'app'
|
|
261
|
-
)
|
|
262
|
-
const resources = join(installedRoot, 'Resources'),
|
|
263
|
-
binary = join(installedRoot, mac ? 'MacOS' : 'bin'),
|
|
264
|
-
launcher = join(binary, windows ? 'launcher.exe' : 'launcher'),
|
|
265
|
-
runtime = join(binary, windows ? 'bun.exe' : 'bun')
|
|
266
|
-
const worker = join(resources, 'app', 'bun', 'index.js')
|
|
267
|
-
const sidecars = options.sidecars ?? []
|
|
268
|
-
let foreignHits = 0
|
|
269
|
-
const sentinel = policy
|
|
270
|
-
? Bun.serve({
|
|
271
|
-
hostname: '127.0.0.1',
|
|
272
|
-
port: 0,
|
|
273
|
-
fetch: () => {
|
|
274
|
-
foreignHits++
|
|
275
|
-
return new Response('sentinel')
|
|
276
|
-
},
|
|
277
|
-
})
|
|
278
|
-
: undefined
|
|
279
|
-
const foreignOrigin = sentinel ? `http://127.0.0.1:${sentinel.port}` : undefined
|
|
280
|
-
const baseEnv = isolatedEnv(parent, prepared.profile, options.platform)
|
|
281
|
-
Object.assign(baseEnv, {
|
|
282
|
-
BUN_OPTIONS: bootstrap.bunOptions,
|
|
283
|
-
FRAMEWORK_CI_WORKER_ENTRY: worker,
|
|
284
|
-
FRAMEWORK_CI_EXPECTED_READS: JSON.stringify(expectedReads),
|
|
285
|
-
FRAMEWORK_CI_ALLOW_EPHEMERAL: '1',
|
|
286
|
-
...(policy
|
|
287
|
-
? {
|
|
288
|
-
FRAMEWORK_CI_OFFLINE_POLICY: JSON.stringify(policy),
|
|
289
|
-
FRAMEWORK_CI_FOREIGN_ORIGIN: foreignOrigin!,
|
|
290
|
-
}
|
|
291
|
-
: {}),
|
|
292
|
-
})
|
|
293
|
-
const installedPayload = (version: string, archive: string) =>
|
|
294
|
-
verifyInstalledPayload({
|
|
295
|
-
platform: options.platform,
|
|
296
|
-
renderer: options.renderer,
|
|
297
|
-
appName: options.appName,
|
|
298
|
-
version,
|
|
299
|
-
archive,
|
|
300
|
-
profile: prepared.directory,
|
|
301
|
-
installedRoot,
|
|
302
|
-
sidecars,
|
|
303
|
-
env: parent,
|
|
304
|
-
})
|
|
305
|
-
const installerUnchanged = async () => {
|
|
306
|
-
const after = await verifyInstallerPayload({
|
|
307
|
-
platform: options.platform,
|
|
308
|
-
appName: options.appName,
|
|
309
|
-
installer: options.installer,
|
|
310
|
-
archive: options.archive,
|
|
311
|
-
env: parent,
|
|
312
|
-
})
|
|
313
|
-
if (JSON.stringify(after) !== JSON.stringify(before))
|
|
314
|
-
throw new Error('Installer artifacts changed')
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/** One guarded start of the installed app: by its installer, or by its launcher after an update. */
|
|
318
|
-
async function observeRun(run: {
|
|
319
|
-
directory: string
|
|
320
|
-
version: string
|
|
321
|
-
archive: string
|
|
322
|
-
start: 'installer' | 'launcher'
|
|
323
|
-
}): Promise<{
|
|
324
|
-
metrics: InstallerRendererObservation
|
|
325
|
-
blockedReads: number
|
|
326
|
-
evidence?: RendererEvidence
|
|
327
|
-
}> {
|
|
328
|
-
const viaInstaller = run.start === 'installer'
|
|
329
|
-
if (
|
|
330
|
-
sentinel &&
|
|
331
|
-
(!(await fetch(foreignOrigin + '/', { signal: AbortSignal.timeout(1000) })).ok ||
|
|
332
|
-
foreignHits !== 1)
|
|
333
|
-
)
|
|
334
|
-
throw new Error('Foreign network sentinel unavailable')
|
|
335
|
-
foreignHits = 0
|
|
336
|
-
const nonce = randomBytes(24).toString('hex')
|
|
337
|
-
const ack = join(run.directory, 'ack'),
|
|
338
|
-
permit = join(run.directory, 'permit'),
|
|
339
|
-
observation = join(run.directory, 'observation'),
|
|
340
|
-
unexpected = join(run.directory, 'unexpected'),
|
|
341
|
-
pidRecord = join(run.directory, 'worker-pid')
|
|
342
|
-
const env: Record<string, string> = {
|
|
343
|
-
...baseEnv,
|
|
344
|
-
FRAMEWORK_CI_NONCE: nonce,
|
|
345
|
-
FRAMEWORK_CI_ACK: ack,
|
|
346
|
-
FRAMEWORK_CI_PERMIT: permit,
|
|
347
|
-
FRAMEWORK_CI_ORIGIN: origin,
|
|
348
|
-
FRAMEWORK_CI_OBSERVATION: observation,
|
|
349
|
-
FRAMEWORK_CI_UNEXPECTED: unexpected,
|
|
350
|
-
FRAMEWORK_CI_PID: pidRecord,
|
|
351
|
-
}
|
|
352
|
-
let launchRecord: string | undefined, expectedApp: string | undefined
|
|
353
|
-
if (mac && viaInstaller) {
|
|
354
|
-
const shimDir = join(run.directory, 'launch-shim')
|
|
355
|
-
await mkdir(shimDir, { mode: 0o700 })
|
|
356
|
-
const path = join(shimDir, 'open')
|
|
357
|
-
await writeFile(path, shim, { flag: 'wx', mode: 0o700 })
|
|
358
|
-
await chmod(path, 0o700)
|
|
359
|
-
expectedApp = join(await realpath(prepared.incoming), `${options.appName}.app`)
|
|
360
|
-
launchRecord = join(run.directory, 'launch-record')
|
|
361
|
-
Object.assign(env, {
|
|
362
|
-
PATH: shimDir + delimiter + (env.PATH ?? ''),
|
|
363
|
-
FRAMEWORK_CI_EXPECTED_APP: expectedApp,
|
|
364
|
-
FRAMEWORK_CI_LAUNCH_RECORD: launchRecord,
|
|
365
|
-
})
|
|
366
|
-
}
|
|
367
|
-
function spawnApp() {
|
|
368
|
-
return Bun.spawn({
|
|
369
|
-
cmd: [launcher],
|
|
370
|
-
cwd: prepared.incoming,
|
|
371
|
-
env,
|
|
372
|
-
stdout: 'ignore',
|
|
373
|
-
stderr: 'ignore',
|
|
374
|
-
signal: AbortSignal.timeout(240000),
|
|
375
|
-
})
|
|
376
|
-
}
|
|
377
|
-
const installer = viaInstaller
|
|
378
|
-
? Bun.spawn({
|
|
379
|
-
cmd: [prepared.executable],
|
|
380
|
-
cwd: prepared.incoming,
|
|
381
|
-
env,
|
|
382
|
-
stdout: 'ignore',
|
|
383
|
-
stderr: 'pipe',
|
|
384
|
-
signal: AbortSignal.timeout(360000),
|
|
385
|
-
})
|
|
386
|
-
: undefined
|
|
387
|
-
const installerStderr = installer ? boundedStderr(installer.stderr).catch(() => '') : undefined
|
|
388
|
-
// After an update no installer runs, so the runner starts the swapped-in app exactly once.
|
|
389
|
-
let app: ReturnType<typeof spawnApp> | undefined = viaInstaller ? undefined : spawnApp(),
|
|
390
|
-
guardedPid: number | undefined
|
|
391
|
-
stage(viaInstaller ? 'installer-started' : 'updated-app-started')
|
|
392
|
-
try {
|
|
393
|
-
let deadline = Date.now() + 150000
|
|
394
|
-
let granted = false
|
|
395
|
-
while (Date.now() < deadline) {
|
|
396
|
-
if (installer && installer.exitCode !== null && installer.exitCode !== 0) {
|
|
397
|
-
const error = installerErrorName(
|
|
398
|
-
await Promise.race([installerStderr!, Bun.sleep(2000).then(() => '')])
|
|
399
|
-
)
|
|
400
|
-
throw new Error(
|
|
401
|
-
`Installer exited unsuccessfully (exit=${installer.exitCode}, signal=${installer.signalCode ?? 'none'}, ` +
|
|
402
|
-
`ready=${(await exists(worker)) && (await exists(launcher))}, acknowledged=${await exists(ack)}, ` +
|
|
403
|
-
`error=${error ?? 'none'})`
|
|
404
|
-
)
|
|
405
|
-
}
|
|
406
|
-
const ready =
|
|
407
|
-
(await exists(worker)) &&
|
|
408
|
-
(await exists(launcher)) &&
|
|
409
|
-
(await exists(join(resources, 'version.json')))
|
|
410
|
-
if (
|
|
411
|
-
installer &&
|
|
412
|
-
shouldLaunchInstalledApp({
|
|
413
|
-
platform: options.platform,
|
|
414
|
-
ready,
|
|
415
|
-
launched: app !== undefined,
|
|
416
|
-
acknowledged: await exists(ack),
|
|
417
|
-
installerExit: installer.exitCode,
|
|
418
|
-
})
|
|
419
|
-
) {
|
|
420
|
-
if (
|
|
421
|
-
!launchRecord ||
|
|
422
|
-
!expectedApp ||
|
|
423
|
-
!(await exists(launchRecord)) ||
|
|
424
|
-
(await readFile(launchRecord, 'utf8')) !== expectedApp + '\n'
|
|
425
|
-
)
|
|
426
|
-
throw new Error('Installer launch request mismatch')
|
|
427
|
-
app = spawnApp()
|
|
428
|
-
}
|
|
429
|
-
if ((await exists(ack)) && !granted) {
|
|
430
|
-
stage('worker-acknowledged')
|
|
431
|
-
if ((await readFile(ack, 'utf8')) !== nonce + '\n')
|
|
432
|
-
throw new Error('Worker guard acknowledgement mismatch')
|
|
433
|
-
const record = await readFile(pidRecord, 'utf8'),
|
|
434
|
-
match = /^([a-f0-9]{48})\n([1-9]\d{0,9})\n$/.exec(record)
|
|
435
|
-
if (
|
|
436
|
-
!match ||
|
|
437
|
-
match[1] !== nonce ||
|
|
438
|
-
Number(match[2]) < 2 ||
|
|
439
|
-
Number(match[2]) === process.pid
|
|
440
|
-
)
|
|
441
|
-
throw new Error('Worker process identity mismatch')
|
|
442
|
-
guardedPid = Number(match[2])
|
|
443
|
-
await installedPayload(run.version, run.archive)
|
|
444
|
-
if (viaInstaller) await installerUnchanged()
|
|
445
|
-
stage('installed-files-verified')
|
|
446
|
-
await writeFile(permit, nonce + '\n', { flag: 'wx', mode: 0o600 })
|
|
447
|
-
granted = true
|
|
448
|
-
// Verifying a large CEF payload can consume the installation budget.
|
|
449
|
-
// Give the verified worker its own bounded renderer observation window.
|
|
450
|
-
deadline = Date.now() + 90000
|
|
451
|
-
stage('worker-permitted')
|
|
452
|
-
}
|
|
453
|
-
if (granted && (await exists(observation))) break
|
|
454
|
-
await Bun.sleep(250)
|
|
455
|
-
}
|
|
456
|
-
const observed = await exists(observation)
|
|
457
|
-
const unexpectedObserved = await exists(unexpected)
|
|
458
|
-
if (!granted || !observed || unexpectedObserved) {
|
|
459
|
-
let workerState = 'unknown'
|
|
460
|
-
if (guardedPid !== undefined) {
|
|
461
|
-
try {
|
|
462
|
-
process.kill(guardedPid, 0)
|
|
463
|
-
workerState = 'present'
|
|
464
|
-
} catch (error) {
|
|
465
|
-
workerState = (error as NodeJS.ErrnoException).code === 'ESRCH' ? 'exited' : 'unknown'
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
const appState = app
|
|
469
|
-
? (app.exitCode ?? 'running')
|
|
470
|
-
: mac
|
|
471
|
-
? 'not-spawned'
|
|
472
|
-
: 'installer-launched'
|
|
473
|
-
// Only bounded process states and booleans: no paths, output, or credentials.
|
|
474
|
-
throw new Error(
|
|
475
|
-
'Installed renderer observation missing or unexpected activity observed' +
|
|
476
|
-
` (start=${run.start}, permitted=${granted}, observed=${observed},` +
|
|
477
|
-
` unexpected=${unexpectedObserved}, workerPid=${workerState},` +
|
|
478
|
-
` installerExit=${installer ? (installer.exitCode ?? 'running') : 'none'},` +
|
|
479
|
-
` appExit=${appState})`
|
|
480
|
-
)
|
|
481
|
-
}
|
|
482
|
-
stage('renderer-observed')
|
|
483
|
-
if (installer) {
|
|
484
|
-
const installerDeadline = Date.now() + 30000
|
|
485
|
-
while (installer.exitCode === null && Date.now() < installerDeadline) await Bun.sleep(250)
|
|
486
|
-
if (installer.exitCode !== 0) {
|
|
487
|
-
const error =
|
|
488
|
-
installer.exitCode === null
|
|
489
|
-
? undefined
|
|
490
|
-
: installerErrorName(
|
|
491
|
-
await Promise.race([installerStderr!, Bun.sleep(2000).then(() => '')])
|
|
492
|
-
)
|
|
493
|
-
throw new Error(
|
|
494
|
-
`Installer did not complete successfully (exit=${installer.exitCode ?? 'running'}, error=${error ?? 'none'})`
|
|
495
|
-
)
|
|
496
|
-
}
|
|
497
|
-
stage('installer-completed')
|
|
498
|
-
}
|
|
499
|
-
const proof = await boundedJson(observation)
|
|
500
|
-
if (typeof proof !== 'object' || proof === null || Array.isArray(proof))
|
|
501
|
-
throw new Error('Invalid renderer observation')
|
|
502
|
-
const {
|
|
503
|
-
nonce: proofNonce,
|
|
504
|
-
origin: proofOrigin,
|
|
505
|
-
blockedReads,
|
|
506
|
-
unexpectedActivity,
|
|
507
|
-
offlinePolicy: proofPolicy,
|
|
508
|
-
bootstrapDenied,
|
|
509
|
-
...metrics
|
|
510
|
-
} = proof as Record<string, unknown>
|
|
511
|
-
assertInstallerRendererObservation(metrics, Boolean(policy))
|
|
512
|
-
if (
|
|
513
|
-
proofNonce !== nonce ||
|
|
514
|
-
proofOrigin !== origin ||
|
|
515
|
-
!Number.isSafeInteger(blockedReads) ||
|
|
516
|
-
Number(blockedReads) < 0 ||
|
|
517
|
-
unexpectedActivity !== false
|
|
518
|
-
)
|
|
519
|
-
throw new Error('Renderer observation identity mismatch')
|
|
520
|
-
if (
|
|
521
|
-
policy &&
|
|
522
|
-
(JSON.stringify(parseOfflinePolicy(proofPolicy)) !== JSON.stringify(policy) ||
|
|
523
|
-
bootstrapDenied !== (policy.kind === 'local-bootstrap') ||
|
|
524
|
-
foreignHits !== 0)
|
|
525
|
-
)
|
|
526
|
-
throw new Error('Offline observation does not match policy')
|
|
527
|
-
await Bun.sleep(3000)
|
|
528
|
-
if (
|
|
529
|
-
(await exists(unexpected)) ||
|
|
530
|
-
foreignHits !== 0 ||
|
|
531
|
-
!(await fetch(origin + '/', { signal: AbortSignal.timeout(1000), redirect: 'error' })).ok
|
|
532
|
-
)
|
|
533
|
-
throw new Error('Installed app did not remain available')
|
|
534
|
-
await installedPayload(run.version, run.archive)
|
|
535
|
-
if (viaInstaller) await installerUnchanged()
|
|
536
|
-
if ((await exists(unexpected)) || foreignHits !== 0)
|
|
537
|
-
throw new Error('Unexpected activity after renderer observation')
|
|
538
|
-
if (guardedPid === undefined) throw new Error('Missing guarded process identity')
|
|
539
|
-
await terminateGuardedWorker({ pid: guardedPid, runtime, platform: options.platform, env })
|
|
540
|
-
guardedPid = undefined
|
|
541
|
-
stage('worker-cleaned')
|
|
542
|
-
const evidence: RendererEvidence | undefined = policy
|
|
543
|
-
? {
|
|
544
|
-
method: 'native-dom-raf-v2',
|
|
545
|
-
origin,
|
|
546
|
-
samples: metrics.samples,
|
|
547
|
-
guardInstalled: true,
|
|
548
|
-
bootstrapDenied: Boolean(bootstrapDenied),
|
|
549
|
-
offlineObserved: true,
|
|
550
|
-
unexpectedActivity: false,
|
|
551
|
-
elapsedMs: metrics.elapsedMs,
|
|
552
|
-
visible: metrics.visible,
|
|
553
|
-
readyState: metrics.readyState,
|
|
554
|
-
width: metrics.width,
|
|
555
|
-
height: metrics.height,
|
|
556
|
-
interactiveElements: metrics.interactiveElements,
|
|
557
|
-
textLength: metrics.textLength,
|
|
558
|
-
markerObserved: metrics.markerObserved,
|
|
559
|
-
browserNetworkRestricted: metrics.foreignBlocked === true && foreignHits === 0,
|
|
560
|
-
offlinePolicy: policy,
|
|
561
|
-
}
|
|
562
|
-
: undefined
|
|
563
|
-
return {
|
|
564
|
-
metrics,
|
|
565
|
-
blockedReads: Number(blockedReads),
|
|
566
|
-
...(evidence ? { evidence } : {}),
|
|
567
|
-
}
|
|
568
|
-
} finally {
|
|
569
|
-
for (const child of [installer, app])
|
|
570
|
-
if (child && child.exitCode === null) {
|
|
571
|
-
try {
|
|
572
|
-
child.kill('SIGKILL')
|
|
573
|
-
} catch {}
|
|
574
|
-
}
|
|
575
|
-
if (guardedPid !== undefined) {
|
|
576
|
-
try {
|
|
577
|
-
await terminateGuardedWorker({
|
|
578
|
-
pid: guardedPid,
|
|
579
|
-
runtime,
|
|
580
|
-
platform: options.platform,
|
|
581
|
-
env,
|
|
582
|
-
})
|
|
583
|
-
} catch {
|
|
584
|
-
/* Runner teardown owns unverified descendants. */
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
// Hosted-runner teardown owns any OS-launched descendants.
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
// One origin for both starts: the app keeps its loopback port across an update, as its
|
|
592
|
-
// browser storage is bound to that origin.
|
|
593
|
-
let origin = ''
|
|
594
|
-
try {
|
|
595
|
-
origin = `http://127.0.0.1:${await choosePort()}`
|
|
596
|
-
const installed = await observeRun({
|
|
597
|
-
directory: prepared.directory,
|
|
598
|
-
version: options.version,
|
|
599
|
-
archive: options.archive,
|
|
600
|
-
start: 'installer',
|
|
601
|
-
})
|
|
602
|
-
const result = {
|
|
603
|
-
directory: prepared.directory,
|
|
604
|
-
observation: installed.metrics,
|
|
605
|
-
blockedReads: installed.blockedReads,
|
|
606
|
-
artifacts: [before.installer, before.archive],
|
|
607
|
-
...(installed.evidence ? { evidence: installed.evidence } : {}),
|
|
608
|
-
}
|
|
609
|
-
if (!options.update) {
|
|
610
|
-
stage('observation-complete')
|
|
611
|
-
return result
|
|
612
|
-
}
|
|
613
|
-
// Apply the signed update the way the app does: stage it beside the install,
|
|
614
|
-
// swap it in once the app has exited, then start the new version.
|
|
615
|
-
const update = options.update
|
|
616
|
-
const target = mac ? dirname(installedRoot) : installedRoot
|
|
617
|
-
const staged = await stageUpdateSwap({
|
|
618
|
-
descriptor: update.descriptor,
|
|
619
|
-
trust: update.trust,
|
|
620
|
-
currentVersion: options.version,
|
|
621
|
-
approved: true,
|
|
622
|
-
approvedVersion: update.descriptor.version,
|
|
623
|
-
target,
|
|
624
|
-
appName: options.appName,
|
|
625
|
-
platform: options.platform,
|
|
626
|
-
renderer: options.renderer,
|
|
627
|
-
archive: update.archive,
|
|
628
|
-
maxCompressedBytes: update.maxCompressedBytes,
|
|
629
|
-
maxExpandedBytes: update.maxExpandedBytes,
|
|
630
|
-
sidecars,
|
|
631
|
-
})
|
|
632
|
-
stage('update-staged')
|
|
633
|
-
await swapAfterExit(target, staged.staging)
|
|
634
|
-
stage('update-swapped')
|
|
635
|
-
await preflightInstallerRuntime({ env: parent, runtime, bootstrap })
|
|
636
|
-
const directory = join(prepared.directory, 'update')
|
|
637
|
-
await mkdir(directory, { mode: 0o700 })
|
|
638
|
-
const updated = await observeRun({
|
|
639
|
-
directory,
|
|
640
|
-
version: staged.version,
|
|
641
|
-
archive: update.archive,
|
|
642
|
-
start: 'launcher',
|
|
643
|
-
})
|
|
644
|
-
stage('observation-complete')
|
|
645
|
-
return {
|
|
646
|
-
...result,
|
|
647
|
-
updated: {
|
|
648
|
-
version: staged.version,
|
|
649
|
-
observation: updated.metrics,
|
|
650
|
-
blockedReads: updated.blockedReads,
|
|
651
|
-
...(updated.evidence ? { evidence: updated.evidence } : {}),
|
|
652
|
-
},
|
|
653
|
-
}
|
|
654
|
-
} finally {
|
|
655
|
-
sentinel?.stop(true)
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
/** The terminated app's processes can hold its files briefly, most visibly on Windows. */
|
|
660
|
-
async function swapAfterExit(target: string, staging: string): Promise<void> {
|
|
661
|
-
const deadline = Date.now() + 60000
|
|
662
|
-
for (;;) {
|
|
663
|
-
try {
|
|
664
|
-
await swapUpdateTree({ target, staging })
|
|
665
|
-
return
|
|
666
|
-
} catch (error) {
|
|
667
|
-
if (Date.now() > deadline) throw error
|
|
668
|
-
await Bun.sleep(500)
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
}
|