@adea-ai/app-framework 0.31.0 → 0.33.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 +33 -15
- package/dist/app/create-application.js +4 -3
- package/dist/app/serial-queue.d.ts +5 -0
- package/dist/app/serial-queue.js +14 -0
- package/dist/app/value-guards.d.ts +15 -0
- package/dist/app/value-guards.js +29 -0
- package/dist/ci/toolchain-identity.js +1 -1
- package/dist/desktop/channel-proof.js +2 -1
- package/dist/desktop/client-asset-stream.js +6 -12
- package/dist/desktop/desktop-host.d.ts +25 -5
- package/dist/desktop/desktop-host.js +75 -20
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-artifact.js +4 -3
- package/dist/installer/command-qualification-command.js +6 -5
- package/dist/installer/hosted-runner.d.ts +9 -2
- package/dist/installer/hosted-runner.js +18 -5
- package/dist/installer/installed-payload.js +20 -46
- package/dist/installer/installer-archive.d.ts +33 -0
- package/dist/installer/installer-archive.js +116 -0
- package/dist/installer/installer-ci-bootstrap.js +10 -6
- package/dist/installer/installer-extraction.js +54 -120
- package/dist/installer/installer-identity.js +33 -111
- package/dist/installer/installer-observation.js +3 -2
- package/dist/installer/installer-process-cleanup.js +7 -46
- package/dist/installer/installer-qualification-command.js +6 -5
- package/dist/installer/installer-upgrade-command.js +5 -5
- package/dist/installer/installer-worker-guard.js +2 -1
- package/dist/native/canonical-path.d.ts +5 -0
- package/dist/native/canonical-path.js +10 -0
- package/dist/native/cef-helper.js +5 -4
- package/dist/native/electrobun-source-patch.js +3 -2
- package/dist/native/{directory-exchange.d.ts → native-rename.d.ts} +2 -0
- package/dist/native/native-rename.js +126 -0
- package/dist/native/native-secret-store.js +2 -6
- package/dist/native/native-utilities.js +4 -4
- package/dist/native/posix-launcher-build.js +1 -1
- package/dist/native/posix-tree-removal.js +2 -2
- package/dist/native/windows-process.d.ts +9 -0
- package/dist/native/windows-process.js +60 -0
- package/dist/release/feed-release-cut.js +2 -1
- package/dist/release/framework-package-publish.js +1 -1
- package/dist/release/framework-update-lock.js +2 -1
- package/dist/release/github-cli.d.ts +18 -0
- package/dist/release/github-cli.js +13 -1
- package/dist/release/github-release-cut.js +3 -2
- package/dist/release/github-release-provenance.js +2 -1
- package/dist/release/github-release-publisher.js +2 -1
- package/dist/release/local-provenance.js +3 -2
- package/dist/release/local-release.js +6 -6
- package/dist/release/qualification-run.d.ts +25 -0
- package/dist/release/qualification-run.js +43 -0
- package/dist/release/release-artifact.js +3 -11
- package/dist/release/release-assets-plan.js +16 -6
- package/dist/release/release-config.js +14 -14
- package/dist/release/release-cut-command.js +14 -4
- package/dist/release/release-cut.js +3 -2
- package/dist/release/release-descriptor-staging.js +13 -27
- package/dist/release/release-finalize.js +2 -1
- package/dist/release/release-publication.js +3 -11
- package/dist/release/release-publish-command.js +15 -6
- package/dist/release/release-qualification.js +3 -2
- package/dist/release/retained-release-build.js +12 -12
- package/dist/update-helper.bundle.js +250 -178
- package/dist/updates/desktop-updater.js +53 -58
- package/dist/updates/packaged-launch-admission.js +3 -2
- package/dist/updates/packaged-release-config.js +6 -5
- package/dist/updates/packaged-update-startup.d.ts +25 -5
- package/dist/updates/packaged-update-startup.js +30 -5
- package/dist/updates/release-feed.js +9 -9
- package/dist/updates/signed-release.js +5 -5
- package/dist/updates/stable-file.d.ts +18 -0
- package/dist/updates/stable-file.js +65 -2
- package/dist/updates/update-adapter.d.ts +2 -13
- package/dist/updates/update-arm.js +13 -13
- package/dist/updates/update-channel-store.js +7 -9
- package/dist/updates/update-discovery.js +30 -34
- package/dist/updates/update-download-cleanup.js +2 -1
- package/dist/updates/update-download.js +2 -4
- package/dist/updates/update-extraction.js +1 -1
- package/dist/updates/update-generation-lease.js +4 -3
- package/dist/updates/update-handoff-plan.js +3 -2
- package/dist/updates/update-helper.js +8 -6
- package/dist/updates/update-instance-lease.js +3 -2
- package/dist/updates/update-launch-gate.js +12 -25
- package/dist/updates/update-launch.js +3 -2
- package/dist/updates/update-lock.js +3 -2
- package/dist/updates/update-marker.js +3 -2
- package/dist/updates/update-process-fence.js +10 -39
- package/dist/updates/update-process-liveness.js +2 -1
- package/dist/updates/update-resume.js +30 -27
- package/dist/updates/update-retention-marker.js +7 -5
- package/dist/updates/update-retention-plan.js +2 -2
- package/dist/updates/update-retirement.js +52 -52
- package/dist/updates/update-state-store.d.ts +2 -0
- package/dist/updates/update-state-store.js +34 -38
- package/dist/updates/update-state.d.ts +8 -3
- package/dist/updates/update-swap-stage.js +6 -5
- package/dist/updates/update-swap.d.ts +1 -1
- package/dist/updates/update-swap.js +8 -6
- package/package.json +4 -12
- package/src/desktop/client-asset-stream.ts +6 -12
- package/src/updates/update-adapter.ts +2 -14
- package/src/updates/update-state.ts +11 -2
- package/templates/application/src/bun/index.ts +13 -9
- package/dist/native/directory-exchange.js +0 -90
- package/dist/native/exclusive-rename.d.ts +0 -2
- package/dist/native/exclusive-rename.js +0 -52
- package/dist/release/retention-dry-run.d.ts +0 -46
- package/dist/release/retention-dry-run.js +0 -94
- package/dist/updates/update-exclusive-rename.d.ts +0 -3
- package/dist/updates/update-exclusive-rename.js +0 -5
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { errorCode, isSha256Hex } from "../app/value-guards.js";
|
|
2
|
+
import { isCanonicalPath } from "../native/canonical-path.js";
|
|
3
|
+
import { exchangeDirectories, probeDirectoryExchange } from "../native/native-rename.js";
|
|
2
4
|
import { withUpdateLock } from "./update-state-store.js";
|
|
3
5
|
import { lstat, open, readFile, readdir, readlink } from "node:fs/promises";
|
|
4
|
-
import { basename, dirname,
|
|
5
|
-
import { constants as constants$1 } from "node:fs";
|
|
6
|
+
import { basename, dirname, join } from "node:path";
|
|
6
7
|
import { createHash } from "node:crypto";
|
|
8
|
+
import { constants as constants$1 } from "node:fs";
|
|
7
9
|
// src/updates/update-swap.ts
|
|
8
10
|
/** The private staging directory the framework keeps beside an install. */
|
|
9
11
|
function updateStagingFor(target) {
|
|
10
|
-
if (
|
|
12
|
+
if (!isCanonicalPath(target)) throw new Error("Invalid update target");
|
|
11
13
|
return join(dirname(target), `.${basename(target)}.framework-update`);
|
|
12
14
|
}
|
|
13
15
|
/** Read a version marker from an app tree, returning undefined when it is absent or invalid. */
|
|
@@ -125,7 +127,7 @@ async function readUpdateTreeDigest(tree) {
|
|
|
125
127
|
return hash.digest("hex");
|
|
126
128
|
}
|
|
127
129
|
function sameUpdateTreeDigest(left, right) {
|
|
128
|
-
return typeof left === "string" && typeof right === "string" &&
|
|
130
|
+
return typeof left === "string" && typeof right === "string" && isSha256Hex(left) && left === right;
|
|
129
131
|
}
|
|
130
132
|
/** Sync a directory's entries to disk. */
|
|
131
133
|
async function syncDirectoryPath(path) {
|
|
@@ -174,7 +176,7 @@ async function syncUpdateTreeParent(target) {
|
|
|
174
176
|
}
|
|
175
177
|
async function exists(path) {
|
|
176
178
|
return lstat(path).then(() => true, (error) => {
|
|
177
|
-
if (error
|
|
179
|
+
if (errorCode(error) === "ENOENT") return false;
|
|
178
180
|
throw error;
|
|
179
181
|
});
|
|
180
182
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/app-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -260,18 +260,10 @@
|
|
|
260
260
|
"types": "./dist/updates/update-manager.d.ts",
|
|
261
261
|
"import": "./dist/updates/update-manager.js"
|
|
262
262
|
},
|
|
263
|
-
"./update-launch-gate": {
|
|
264
|
-
"types": "./dist/updates/update-launch-gate.d.ts",
|
|
265
|
-
"import": "./dist/updates/update-launch-gate.js"
|
|
266
|
-
},
|
|
267
263
|
"./update-inherited-launch-lease": {
|
|
268
264
|
"types": "./dist/updates/update-inherited-launch-lease.d.ts",
|
|
269
265
|
"import": "./dist/updates/update-inherited-launch-lease.js"
|
|
270
266
|
},
|
|
271
|
-
"./packaged-release-config": {
|
|
272
|
-
"types": "./dist/updates/packaged-release-config.d.ts",
|
|
273
|
-
"import": "./dist/updates/packaged-release-config.js"
|
|
274
|
-
},
|
|
275
267
|
"./packaged-update-startup": {
|
|
276
268
|
"types": "./dist/updates/packaged-update-startup.d.ts",
|
|
277
269
|
"import": "./dist/updates/packaged-update-startup.js"
|
|
@@ -360,8 +352,8 @@
|
|
|
360
352
|
"registry": "https://registry.npmjs.org/"
|
|
361
353
|
},
|
|
362
354
|
"scripts": {
|
|
363
|
-
"test": "bun test --timeout=$
|
|
364
|
-
"test:ui": "bun test --isolate --timeout=$
|
|
355
|
+
"test": "bun test --timeout=$(bun -e \"process.stdout.write(process.env.ADEA_TEST_TIMEOUT_MS || '5000')\") tests/*/*.test.ts && bun run test:ui",
|
|
356
|
+
"test:ui": "bun test --isolate --timeout=$(bun -e \"process.stdout.write(process.env.ADEA_TEST_TIMEOUT_MS || '5000')\") --conditions=browser --preload @adea-ai/ui/testing/solid-transform tests/*/*.test.tsx",
|
|
365
357
|
"test:sidebar-responsive-matrix": "bash scripts/test-sidebar-responsive-matrix.sh",
|
|
366
358
|
"test:theme-browser": "bun scripts/test-theme-library-browser.ts",
|
|
367
359
|
"build": "vp build && tsc -p tsconfig.json --emitDeclarationOnly && bun build src/cli/update-helper-cli.ts --target=bun --outfile dist/update-helper.bundle.js && bun scripts/write-framework-source.ts",
|
|
@@ -378,7 +370,7 @@
|
|
|
378
370
|
"tar": "^7.5.22"
|
|
379
371
|
},
|
|
380
372
|
"devDependencies": {
|
|
381
|
-
"@adea-ai/ui": "0.151.
|
|
373
|
+
"@adea-ai/ui": "0.151.13",
|
|
382
374
|
"@babel/core": "8.0.10",
|
|
383
375
|
"@babel/preset-typescript": "^8.0.1",
|
|
384
376
|
"@happy-dom/global-registrator": "^21.0.4",
|
|
@@ -303,31 +303,25 @@ export function createClientAssetStream(
|
|
|
303
303
|
if (cancelled) return
|
|
304
304
|
const current = file
|
|
305
305
|
if (!current) return
|
|
306
|
-
|
|
306
|
+
// Verify the file is unchanged once fully read, then release it before ending.
|
|
307
|
+
const finish = async (last?: Uint8Array) => {
|
|
307
308
|
const actual = await current.stat()
|
|
308
309
|
if (cancelled) return
|
|
309
310
|
if (!sameFile(expected, actual))
|
|
310
311
|
throw new Error('Client asset changed during request')
|
|
311
312
|
await close()
|
|
312
313
|
if (cancelled) return
|
|
314
|
+
if (last) controller.enqueue(last)
|
|
313
315
|
controller.close()
|
|
314
|
-
return
|
|
315
316
|
}
|
|
317
|
+
if (offset === expected.size) return await finish()
|
|
316
318
|
const buffer = Buffer.allocUnsafe(Math.min(FILE_CHUNK_BYTES, expected.size - offset))
|
|
317
319
|
const { bytesRead } = await current.read(buffer, 0, buffer.length, offset)
|
|
318
320
|
if (cancelled) return
|
|
319
321
|
if (!bytesRead) throw new Error('Client asset changed during request')
|
|
320
322
|
offset += bytesRead
|
|
321
|
-
if (offset === expected.size)
|
|
322
|
-
|
|
323
|
-
if (cancelled) return
|
|
324
|
-
if (!sameFile(expected, actual))
|
|
325
|
-
throw new Error('Client asset changed during request')
|
|
326
|
-
await close()
|
|
327
|
-
if (cancelled) return
|
|
328
|
-
controller.enqueue(buffer.subarray(0, bytesRead))
|
|
329
|
-
controller.close()
|
|
330
|
-
} else controller.enqueue(buffer.subarray(0, bytesRead))
|
|
323
|
+
if (offset === expected.size) await finish(buffer.subarray(0, bytesRead))
|
|
324
|
+
else controller.enqueue(buffer.subarray(0, bytesRead))
|
|
331
325
|
} catch (error) {
|
|
332
326
|
await close().catch(() => {})
|
|
333
327
|
if (!cancelled) controller.error(error)
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
UpdateChannel,
|
|
4
4
|
UpdateState,
|
|
5
5
|
} from '@adea-ai/ui/components/composites/update-dialog'
|
|
6
|
-
import { toUpdateState } from './update-state'
|
|
6
|
+
import { toUpdateState, type NativeUpdateSnapshotOf } from './update-state'
|
|
7
7
|
|
|
8
8
|
export type { UpdateAdapter, UpdateChannel, UpdateState }
|
|
9
9
|
|
|
@@ -90,19 +90,7 @@ export function mirrorUpdateState(
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/** A native updater snapshot in snake_case, as Rust and older desktop hosts report it. */
|
|
93
|
-
export type NativeUpdateSnapshot =
|
|
94
|
-
available_version: string | null
|
|
95
|
-
changelog: string
|
|
96
|
-
current_version: string
|
|
97
|
-
downloaded_bytes: number
|
|
98
|
-
error: string | null
|
|
99
|
-
github_url: string | null
|
|
100
|
-
phase: UpdateState['phase']
|
|
101
|
-
release_date: string | null
|
|
102
|
-
release_notes?: string | null
|
|
103
|
-
restart_required: boolean
|
|
104
|
-
total_bytes: number | null
|
|
105
|
-
}>
|
|
93
|
+
export type NativeUpdateSnapshot = NativeUpdateSnapshotOf<UpdateState['phase'], string | null>
|
|
106
94
|
|
|
107
95
|
/** A native updater that answers with snake_case snapshots. */
|
|
108
96
|
export type NativeUpdateAdapter = Readonly<{
|
|
@@ -13,10 +13,19 @@ export type NativeUpdateState<Phase extends string = string> = Readonly<{
|
|
|
13
13
|
restart_required: boolean
|
|
14
14
|
}>
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A native updater snapshot: the service fields, with a release URL that may be
|
|
18
|
+
* absent (`Url`) and release notes that older hosts omit.
|
|
19
|
+
*/
|
|
20
|
+
export type NativeUpdateSnapshotOf<
|
|
21
|
+
Phase extends string = string,
|
|
22
|
+
Url extends string | null = string,
|
|
23
|
+
> = Omit<NativeUpdateState<Phase>, 'github_url' | 'release_notes'> &
|
|
24
|
+
Readonly<{ github_url: Url; release_notes?: string | null }>
|
|
25
|
+
|
|
16
26
|
/** Project a native snapshot into the shared UI update dialog contract. */
|
|
17
27
|
export function toUpdateState<Phase extends string, Url extends string | null = string>(
|
|
18
|
-
update:
|
|
19
|
-
Readonly<{ github_url: Url; release_notes?: string | null }>,
|
|
28
|
+
update: NativeUpdateSnapshotOf<Phase, Url>,
|
|
20
29
|
options: { includeReleaseNotes?: boolean } = {}
|
|
21
30
|
) {
|
|
22
31
|
return {
|
|
@@ -66,15 +66,19 @@ const immutableClientAssets = await loadClientAssetManifest(
|
|
|
66
66
|
join(clientRoot, CLIENT_ASSET_MANIFEST_FILE)
|
|
67
67
|
)
|
|
68
68
|
const { version } = readPackagedVersion(import.meta.dir)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
// Every packaged launch gets the updater. Admission only decides whether
|
|
70
|
+
// startup also leases retained asset generations (and must pause on failure)
|
|
71
|
+
// or runs unmanaged, where unavailable updates are reported and skipped.
|
|
72
|
+
const updateStartup = await preparePackagedUpdateStartup({
|
|
73
|
+
entryDirectory: import.meta.dir,
|
|
74
|
+
dataDirectory,
|
|
75
|
+
identity: packagedIdentity,
|
|
76
|
+
loadManifest: (root) => loadClientAssetManifest(join(root, CLIENT_ASSET_MANIFEST_FILE)),
|
|
77
|
+
admission: launchAdmission,
|
|
78
|
+
})
|
|
79
|
+
if (updateStartup.status === 'unavailable')
|
|
80
|
+
console.error(`updates unavailable: ${updateStartup.reason}`)
|
|
81
|
+
let preparedUpdateStartup = updateStartup.status === 'ready' ? updateStartup : undefined
|
|
78
82
|
const services = createServiceRegistry<string>()
|
|
79
83
|
registerNativeUtilities({
|
|
80
84
|
services,
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
3
|
-
import { FFIType, dlopen, ptr } from "bun:ffi";
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
5
|
-
// src/native/directory-exchange.ts
|
|
6
|
-
var RENAME_EXCHANGE = 2;
|
|
7
|
-
/** Atomically exchange two existing paths on supported Darwin and Linux filesystems. */
|
|
8
|
-
function exchangeDirectories(source, destination) {
|
|
9
|
-
if (typeof source !== "string" || typeof destination !== "string" || !isAbsolute(source) || !isAbsolute(destination) || resolve(source) !== source || resolve(destination) !== destination || source === destination || source.includes("\0") || destination.includes("\0")) throw new Error("Invalid atomic directory exchange paths");
|
|
10
|
-
if (process.platform === "darwin") {
|
|
11
|
-
const library = dlopen("libSystem.B.dylib", { renamex_np: {
|
|
12
|
-
args: [
|
|
13
|
-
FFIType.ptr,
|
|
14
|
-
FFIType.ptr,
|
|
15
|
-
FFIType.u32
|
|
16
|
-
],
|
|
17
|
-
returns: FFIType.i32
|
|
18
|
-
} });
|
|
19
|
-
try {
|
|
20
|
-
const from = Buffer.from(source + "\0"), to = Buffer.from(destination + "\0");
|
|
21
|
-
if (library.symbols.renamex_np(ptr(from), ptr(to), RENAME_EXCHANGE) !== 0) throw new Error("Atomic directory exchange is unsupported or failed");
|
|
22
|
-
} finally {
|
|
23
|
-
library.close();
|
|
24
|
-
}
|
|
25
|
-
} else if (process.platform === "linux") {
|
|
26
|
-
const library = dlopen("libc.so.6", { renameat2: {
|
|
27
|
-
args: [
|
|
28
|
-
FFIType.i32,
|
|
29
|
-
FFIType.ptr,
|
|
30
|
-
FFIType.i32,
|
|
31
|
-
FFIType.ptr,
|
|
32
|
-
FFIType.u32
|
|
33
|
-
],
|
|
34
|
-
returns: FFIType.i32
|
|
35
|
-
} });
|
|
36
|
-
try {
|
|
37
|
-
const from = Buffer.from(source + "\0"), to = Buffer.from(destination + "\0");
|
|
38
|
-
if (library.symbols.renameat2(-100, ptr(from), -100, ptr(to), RENAME_EXCHANGE) !== 0) throw new Error("Atomic directory exchange is unsupported or failed");
|
|
39
|
-
} finally {
|
|
40
|
-
library.close();
|
|
41
|
-
}
|
|
42
|
-
} else throw new Error("Atomic directory exchange is unsupported on this platform");
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Exercise the actual volume using two disposable directories before exchanging
|
|
46
|
-
* an install tree. This qualifies only that same-volume probe pair; it cannot
|
|
47
|
-
* prove a provider will behave identically for every later object or survive a
|
|
48
|
-
* power failure. The caller also verifies the real trees' versions and inode
|
|
49
|
-
* identities immediately after the exchange.
|
|
50
|
-
*/
|
|
51
|
-
async function probeDirectoryExchange(parent, exchange = exchangeDirectories) {
|
|
52
|
-
if (typeof parent !== "string" || !isAbsolute(parent) || resolve(parent) !== parent || parent.includes("\0")) throw new Error("Invalid directory exchange probe parent");
|
|
53
|
-
const id = randomUUID();
|
|
54
|
-
const first = join(parent, `.framework-exchange-probe-${id}-a`);
|
|
55
|
-
const second = join(parent, `.framework-exchange-probe-${id}-b`);
|
|
56
|
-
const marker = "exchange-probe";
|
|
57
|
-
const firstValue = `${id}:first`;
|
|
58
|
-
const secondValue = `${id}:second`;
|
|
59
|
-
let firstCreated = false;
|
|
60
|
-
let secondCreated = false;
|
|
61
|
-
try {
|
|
62
|
-
await mkdir(first, { mode: 448 });
|
|
63
|
-
firstCreated = true;
|
|
64
|
-
await mkdir(second, { mode: 448 });
|
|
65
|
-
secondCreated = true;
|
|
66
|
-
await writeFile(join(first, marker), firstValue, {
|
|
67
|
-
flag: "wx",
|
|
68
|
-
mode: 384
|
|
69
|
-
});
|
|
70
|
-
await writeFile(join(second, marker), secondValue, {
|
|
71
|
-
flag: "wx",
|
|
72
|
-
mode: 384
|
|
73
|
-
});
|
|
74
|
-
exchange(first, second);
|
|
75
|
-
const [firstAfter, secondAfter] = await Promise.all([readFile(join(first, marker), "utf8"), readFile(join(second, marker), "utf8")]);
|
|
76
|
-
if (firstAfter !== secondValue || secondAfter !== firstValue) throw new Error("Directory exchange did not exchange both probe trees");
|
|
77
|
-
} finally {
|
|
78
|
-
const cleanup = [];
|
|
79
|
-
if (firstCreated) cleanup.push(rm(first, {
|
|
80
|
-
recursive: true,
|
|
81
|
-
force: true
|
|
82
|
-
}));
|
|
83
|
-
if (secondCreated) cleanup.push(rm(second, {
|
|
84
|
-
recursive: true,
|
|
85
|
-
force: true
|
|
86
|
-
}));
|
|
87
|
-
await Promise.all(cleanup);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
export { exchangeDirectories, probeDirectoryExchange };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { isAbsolute, resolve } from "node:path";
|
|
2
|
-
import { FFIType, dlopen, ptr } from "bun:ffi";
|
|
3
|
-
// src/native/exclusive-rename.ts
|
|
4
|
-
/** Rename without replacing an existing destination on supported desktop platforms. */
|
|
5
|
-
function renameExclusive(source, destination) {
|
|
6
|
-
if (typeof source !== "string" || typeof destination !== "string" || !isAbsolute(source) || !isAbsolute(destination) || resolve(source) !== source || resolve(destination) !== destination || source === destination || source.includes("\0") || destination.includes("\0")) throw new Error("Invalid exclusive rename paths");
|
|
7
|
-
if (process.platform === "darwin") {
|
|
8
|
-
const library = dlopen("libSystem.B.dylib", { renamex_np: {
|
|
9
|
-
args: [
|
|
10
|
-
FFIType.ptr,
|
|
11
|
-
FFIType.ptr,
|
|
12
|
-
FFIType.u32
|
|
13
|
-
],
|
|
14
|
-
returns: FFIType.i32
|
|
15
|
-
} });
|
|
16
|
-
try {
|
|
17
|
-
const from = Buffer.from(source + "\0"), to = Buffer.from(destination + "\0");
|
|
18
|
-
if (library.symbols.renamex_np(ptr(from), ptr(to), 4) !== 0) throw new Error("Exclusive rename failed");
|
|
19
|
-
} finally {
|
|
20
|
-
library.close();
|
|
21
|
-
}
|
|
22
|
-
} else if (process.platform === "linux") {
|
|
23
|
-
const library = dlopen("libc.so.6", { renameat2: {
|
|
24
|
-
args: [
|
|
25
|
-
FFIType.i32,
|
|
26
|
-
FFIType.ptr,
|
|
27
|
-
FFIType.i32,
|
|
28
|
-
FFIType.ptr,
|
|
29
|
-
FFIType.u32
|
|
30
|
-
],
|
|
31
|
-
returns: FFIType.i32
|
|
32
|
-
} });
|
|
33
|
-
try {
|
|
34
|
-
const from = Buffer.from(source + "\0"), to = Buffer.from(destination + "\0");
|
|
35
|
-
if (library.symbols.renameat2(-100, ptr(from), -100, ptr(to), 1) !== 0) throw new Error("Exclusive rename failed");
|
|
36
|
-
} finally {
|
|
37
|
-
library.close();
|
|
38
|
-
}
|
|
39
|
-
} else if (process.platform === "win32") {
|
|
40
|
-
const library = dlopen("kernel32.dll", { MoveFileW: {
|
|
41
|
-
args: [FFIType.ptr, FFIType.ptr],
|
|
42
|
-
returns: FFIType.i32
|
|
43
|
-
} });
|
|
44
|
-
try {
|
|
45
|
-
const from = Buffer.from(source + "\0", "utf16le"), to = Buffer.from(destination + "\0", "utf16le");
|
|
46
|
-
if (library.symbols.MoveFileW(ptr(from), ptr(to)) === 0) throw new Error("Exclusive rename failed");
|
|
47
|
-
} finally {
|
|
48
|
-
library.close();
|
|
49
|
-
}
|
|
50
|
-
} else throw new Error("Unsupported exclusive rename platform");
|
|
51
|
-
}
|
|
52
|
-
export { renameExclusive };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { type FeedChannel } from '../updates/release-feed';
|
|
2
|
-
/** An inventory item from an independent, complete object listing. */
|
|
3
|
-
export type RetentionObject = Readonly<{
|
|
4
|
-
key: string;
|
|
5
|
-
version: string;
|
|
6
|
-
size: number;
|
|
7
|
-
sha256: string;
|
|
8
|
-
modifiedAt: string;
|
|
9
|
-
role: 'payload' | 'provenance';
|
|
10
|
-
}>;
|
|
11
|
-
/**
|
|
12
|
-
* Offline evidence for an advisory report. Completeness must be established by the
|
|
13
|
-
* caller; this module does not fetch, authenticate, lock, or delete any object.
|
|
14
|
-
*/
|
|
15
|
-
export type RetentionEvidence = Readonly<{
|
|
16
|
-
feed: unknown;
|
|
17
|
-
ledger: unknown;
|
|
18
|
-
releases: readonly unknown[];
|
|
19
|
-
pointers: Readonly<Record<FeedChannel, unknown | null>>;
|
|
20
|
-
objects: readonly RetentionObject[];
|
|
21
|
-
protectedTags: Readonly<{
|
|
22
|
-
rollback: readonly string[];
|
|
23
|
-
qualification: readonly string[];
|
|
24
|
-
promotion: readonly string[];
|
|
25
|
-
inFlight: readonly string[];
|
|
26
|
-
}>;
|
|
27
|
-
/** Latest time each unprotected release could have been exposed to a reader. */
|
|
28
|
-
lastExposedAt: Readonly<Record<string, string>>;
|
|
29
|
-
/** All sources must cover the complete namespace and all reference classes. */
|
|
30
|
-
complete: boolean;
|
|
31
|
-
now: string;
|
|
32
|
-
discoveryGraceMs: number;
|
|
33
|
-
}>;
|
|
34
|
-
/** Advisory only: returned object identities are not a deletion authorization. */
|
|
35
|
-
export declare function planRetentionDryRun(input: RetentionEvidence): {
|
|
36
|
-
mode: 'advisory-only';
|
|
37
|
-
review: Readonly<{
|
|
38
|
-
key: string;
|
|
39
|
-
version: string;
|
|
40
|
-
size: number;
|
|
41
|
-
sha256: string;
|
|
42
|
-
modifiedAt: string;
|
|
43
|
-
role: 'payload' | 'provenance';
|
|
44
|
-
}>[];
|
|
45
|
-
protectedTags: string[];
|
|
46
|
-
};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { feedAssetKey, parseFeedRelease, parseReleaseFeed, parseReleaseLedger } from "../updates/release-feed.js";
|
|
2
|
-
import { versionLessThan } from "../updates/release-version.js";
|
|
3
|
-
// src/release/retention-dry-run.ts
|
|
4
|
-
var DAY = 864e5;
|
|
5
|
-
var channels = [
|
|
6
|
-
"dev",
|
|
7
|
-
"daily",
|
|
8
|
-
"stable"
|
|
9
|
-
];
|
|
10
|
-
function time(value) {
|
|
11
|
-
const parsed = Date.parse(value);
|
|
12
|
-
if (!Number.isFinite(parsed) || new Date(parsed).toISOString().replace(".000Z", "Z") !== value.replace(".000Z", "Z")) throw new Error("Invalid retention timestamp");
|
|
13
|
-
return parsed;
|
|
14
|
-
}
|
|
15
|
-
/** Advisory only: returned object identities are not a deletion authorization. */
|
|
16
|
-
function planRetentionDryRun(input) {
|
|
17
|
-
if (input.complete !== true) throw new Error("Incomplete retention evidence");
|
|
18
|
-
const feed = parseReleaseFeed(input.feed);
|
|
19
|
-
const ledger = parseReleaseLedger(input.ledger, feed.app);
|
|
20
|
-
const now = time(input.now);
|
|
21
|
-
if (!Number.isSafeInteger(input.discoveryGraceMs) || input.discoveryGraceMs < DAY || input.discoveryGraceMs > 7 * DAY) throw new Error("Invalid discovery grace");
|
|
22
|
-
const releases = new Map(input.releases.map((value) => {
|
|
23
|
-
const release = parseFeedRelease(value);
|
|
24
|
-
return [release.tag, release];
|
|
25
|
-
}));
|
|
26
|
-
if (releases.size !== input.releases.length || releases.size !== ledger.releases.length) throw new Error("Release inventory does not match ledger");
|
|
27
|
-
const protectedTags = /* @__PURE__ */ new Set();
|
|
28
|
-
for (const key of [
|
|
29
|
-
"rollback",
|
|
30
|
-
"qualification",
|
|
31
|
-
"promotion",
|
|
32
|
-
"inFlight"
|
|
33
|
-
]) {
|
|
34
|
-
const list = input.protectedTags?.[key];
|
|
35
|
-
if (!Array.isArray(list)) throw new Error("Incomplete protection references");
|
|
36
|
-
for (const tag of list) protectedTags.add(tag);
|
|
37
|
-
}
|
|
38
|
-
for (const channel of channels) {
|
|
39
|
-
if (!Object.hasOwn(input.pointers, channel)) throw new Error("Missing channel pointer");
|
|
40
|
-
const value = input.pointers[channel];
|
|
41
|
-
const kinds = channel === "dev" ? ["dev"] : channel === "stable" ? ["stable"] : ["daily", "stable"];
|
|
42
|
-
if (value === null) {
|
|
43
|
-
if (ledger.releases.some((entry) => kinds.includes(entry.kind))) throw new Error("Missing active channel");
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
const pointer = parseFeedRelease(value);
|
|
47
|
-
const newest = ledger.releases.filter((item) => kinds.includes(item.kind)).reduce((best, item) => !best || versionLessThan(best.tag, item.tag) ? item : best, void 0);
|
|
48
|
-
const release = releases.get(pointer.tag);
|
|
49
|
-
const entry = ledger.releases.find((item) => item.tag === pointer.tag);
|
|
50
|
-
if (!release || !entry || newest?.tag !== pointer.tag || pointer.channel !== channel || !kinds.includes(entry.kind) || pointer.publishedAt !== release.publishedAt || JSON.stringify(pointer.assets) !== JSON.stringify(release.assets) || channel === "stable" && JSON.stringify(pointer.missingPlatforms) !== JSON.stringify(release.missingPlatforms)) throw new Error("Inconsistent channel pointer");
|
|
51
|
-
protectedTags.add(pointer.tag);
|
|
52
|
-
}
|
|
53
|
-
for (const tag of protectedTags) if (!releases.has(tag)) throw new Error("Missing protected release");
|
|
54
|
-
const objects = /* @__PURE__ */ new Map();
|
|
55
|
-
for (const item of input.objects) {
|
|
56
|
-
if (objects.has(item.key) || !["payload", "provenance"].includes(item.role) || typeof item.version !== "string" || !item.version || !Number.isSafeInteger(item.size) || item.size < 1 || !/^[a-f0-9]{64}$/.test(item.sha256) || time(item.modifiedAt) > now) throw new Error("Invalid object identity");
|
|
57
|
-
objects.set(item.key, item);
|
|
58
|
-
}
|
|
59
|
-
const review = [];
|
|
60
|
-
let unprotectedDailyCount = 0;
|
|
61
|
-
for (const entry of ledger.releases) {
|
|
62
|
-
const release = releases.get(entry.tag);
|
|
63
|
-
if (!release || release.channel !== entry.kind || release.publishedAt !== entry.publishedAt) throw new Error("Inconsistent release ledger");
|
|
64
|
-
if (entry.kind === "dev" || entry.kind === "stable") protectedTags.add(entry.tag);
|
|
65
|
-
const releaseTime = Math.max(time(entry.publishedAt), entry.promotedAt ? time(entry.promotedAt) : 0);
|
|
66
|
-
if (releaseTime > now) throw new Error("Future release");
|
|
67
|
-
const releaseObjects = [];
|
|
68
|
-
for (const asset of release.assets) {
|
|
69
|
-
const key = feedAssetKey(feed, entry.tag, asset.name);
|
|
70
|
-
const item = objects.get(key);
|
|
71
|
-
if (!item || item.size !== asset.size || item.sha256 !== asset.sha256) throw new Error("Missing or inconsistent asset identity");
|
|
72
|
-
objects.delete(key);
|
|
73
|
-
releaseObjects.push(item);
|
|
74
|
-
}
|
|
75
|
-
if (!protectedTags.has(entry.tag)) {
|
|
76
|
-
unprotectedDailyCount++;
|
|
77
|
-
const lastChange = Math.max(releaseTime, ...releaseObjects.map((item) => time(item.modifiedAt)));
|
|
78
|
-
if (!input.lastExposedAt || !Object.hasOwn(input.lastExposedAt, entry.tag)) throw new Error("Missing last-exposure evidence");
|
|
79
|
-
const exposure = input.lastExposedAt[entry.tag];
|
|
80
|
-
if (typeof exposure !== "string") throw new Error("Missing last-exposure evidence");
|
|
81
|
-
const lastExposed = time(exposure);
|
|
82
|
-
if (lastExposed < releaseTime || lastExposed > now) throw new Error("Invalid last-exposure evidence");
|
|
83
|
-
const age = now - lastChange;
|
|
84
|
-
if (age >= input.discoveryGraceMs && now - lastExposed >= input.discoveryGraceMs && (age >= 7 * DAY || unprotectedDailyCount > 20)) review.push(...releaseObjects.filter((item) => item.role === "payload").map((item) => ({ ...item })));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (objects.size) throw new Error("Unaccounted release asset");
|
|
88
|
-
return {
|
|
89
|
-
mode: "advisory-only",
|
|
90
|
-
review,
|
|
91
|
-
protectedTags: [...protectedTags].toSorted()
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
export { planRetentionDryRun };
|