@adea-ai/app-framework 0.37.0 → 0.37.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/dist/appearance/appearance-host.js +2 -1
- package/dist/appearance/custom-theme-import.js +3 -1
- package/dist/appearance/custom-theme-library.d.ts +6 -185
- package/dist/appearance/custom-theme-library.js +3 -621
- package/dist/appearance/theme-library-mutation.d.ts +42 -0
- package/dist/appearance/theme-library-mutation.js +172 -0
- package/dist/appearance/theme-library-schema.d.ts +108 -0
- package/dist/appearance/theme-library-schema.js +189 -0
- package/dist/appearance/theme-library-store.d.ts +61 -0
- package/dist/appearance/theme-library-store.js +268 -0
- package/dist/appearance/theme-record-adapter.js +3 -1
- package/dist/appearance/theme-registry.js +2 -1
- package/dist/cli/update-helper-cli.js +1 -1
- package/dist/desktop/desktop-client.d.ts +1 -1
- package/dist/framework-source.json +1 -1
- package/dist/installer/installed-payload.js +2 -2
- package/dist/installer/{installer-archive.js → installer-archive-members.js} +2 -2
- package/dist/installer/installer-extraction.js +2 -2
- package/dist/installer/installer-fetch-guard.d.ts +1 -1
- package/dist/installer/installer-identity.js +2 -2
- package/dist/installer/installer-observation.d.ts +1 -1
- package/dist/installer/installer-observation.js +2 -2
- package/dist/installer/installer-upgrade-command.d.ts +2 -2
- package/dist/installer/installer-upgrade-command.js +5 -5
- package/dist/installer/linux-process-group.js +1 -1
- package/dist/installer/upgrade-asset-download.d.ts +1 -1
- package/dist/installer/upgrade-asset-download.js +2 -2
- package/dist/native/posix-tree-removal.d.ts +1 -1
- package/dist/release/feed-release-cut.d.ts +1 -1
- package/dist/release/feed-state.d.ts +2 -2
- package/dist/release/feed-state.js +3 -3
- package/dist/release/github-release-cut.js +1 -1
- package/dist/release/github-release-promotion.js +1 -1
- package/dist/release/github-release-publisher.js +1 -1
- package/dist/release/github-release-qualification.js +1 -1
- package/dist/release/local-release.d.ts +2 -2
- package/dist/release/local-release.js +3 -3
- package/dist/release/release-artifact.d.ts +1 -1
- package/dist/release/release-artifact.js +2 -2
- package/dist/release/release-assets-plan.js +1 -1
- package/dist/release/release-config.d.ts +1 -1
- package/dist/release/release-config.js +1 -1
- package/dist/release/release-descriptor-staging.js +3 -3
- package/dist/release/release-finalize.js +1 -1
- package/dist/release/release-promotion.js +1 -1
- package/dist/release/release-publication.d.ts +1 -1
- package/dist/release/release-publication.js +2 -2
- package/dist/release/release-publish-command.js +2 -2
- package/dist/update-helper.bundle.js +18 -18
- package/dist/updates/channel-update-manager.d.ts +3 -3
- package/dist/updates/channel-update-manager.js +2 -2
- package/dist/updates/desktop-updater.d.ts +10 -83
- package/dist/updates/desktop-updater.js +14 -217
- package/dist/updates/{packaged-release-config.js → feed/packaged-release-config.js} +5 -5
- package/dist/updates/{release-feed.js → feed/release-feed.js} +2 -2
- package/dist/updates/{release-location.js → feed/release-location.js} +2 -2
- package/dist/updates/{release-version.js → feed/release-version.js} +1 -1
- package/dist/updates/{signed-release.js → feed/signed-release.js} +2 -2
- package/dist/updates/{update-discovery.js → feed/update-discovery.js} +1 -1
- package/dist/updates/helper/launch-gate-recovery.d.ts +8 -0
- package/dist/updates/{update-resume.js → helper/launch-gate-recovery.js} +13 -423
- package/dist/updates/helper/resume-staging.d.ts +22 -0
- package/dist/updates/helper/resume-staging.js +180 -0
- package/dist/updates/{update-helper.d.ts → helper/update-helper.d.ts} +1 -1
- package/dist/updates/{update-helper.js → helper/update-helper.js} +9 -9
- package/dist/updates/{update-resume.d.ts → helper/update-resume.d.ts} +4 -10
- package/dist/updates/helper/update-resume.js +252 -0
- package/dist/updates/{update-shutdown.js → helper/update-shutdown.js} +2 -2
- package/dist/updates/{update-arm.d.ts → install/update-arm.d.ts} +2 -2
- package/dist/updates/{update-arm.js → install/update-arm.js} +9 -9
- package/dist/updates/{update-download-cleanup.d.ts → install/update-download-cleanup.d.ts} +1 -1
- package/dist/updates/{update-download-cleanup.js → install/update-download-cleanup.js} +3 -3
- package/dist/updates/{update-download.d.ts → install/update-download.d.ts} +2 -2
- package/dist/updates/{update-download.js → install/update-download.js} +3 -3
- package/dist/updates/{update-extraction.d.ts → install/update-extraction.d.ts} +2 -2
- package/dist/updates/{update-extraction.js → install/update-extraction.js} +6 -6
- package/dist/updates/{update-handoff-plan.d.ts → install/update-handoff-plan.d.ts} +2 -2
- package/dist/updates/{update-handoff-plan.js → install/update-handoff-plan.js} +5 -5
- package/dist/updates/{update-marker.js → install/update-marker.js} +2 -2
- package/dist/updates/{update-swap-stage.d.ts → install/update-swap-stage.d.ts} +2 -2
- package/dist/updates/{update-swap-stage.js → install/update-swap-stage.js} +7 -6
- package/dist/updates/{update-swap.d.ts → install/update-swap.d.ts} +1 -1
- package/dist/updates/{update-swap.js → install/update-swap.js} +5 -5
- package/dist/updates/install-target.d.ts +8 -0
- package/dist/updates/install-target.js +27 -0
- package/dist/updates/{launch-environment.js → launch/launch-environment.js} +1 -1
- package/dist/updates/{packaged-launch-admission.js → launch/packaged-launch-admission.js} +4 -4
- package/dist/updates/{packaged-update-startup.d.ts → launch/packaged-update-startup.d.ts} +3 -3
- package/dist/updates/{packaged-update-startup.js → launch/packaged-update-startup.js} +10 -7
- package/dist/updates/{update-launch-gate.d.ts → launch/update-launch-gate.d.ts} +1 -1
- package/dist/updates/{update-launch-gate.js → launch/update-launch-gate.js} +9 -9
- package/dist/updates/{update-launch.d.ts → launch/update-launch.d.ts} +1 -1
- package/dist/updates/{update-launch.js → launch/update-launch.js} +2 -2
- package/dist/updates/{linux-process-state.js → locks/linux-process-state.js} +1 -1
- package/dist/updates/{native-file-lock.js → locks/native-file-lock.js} +1 -1
- package/dist/updates/{stable-file.js → locks/stable-file.js} +2 -2
- package/dist/updates/{update-download-lock.js → locks/update-download-lock.js} +1 -1
- package/dist/updates/{update-generation-lease.js → locks/update-generation-lease.js} +3 -3
- package/dist/updates/{update-inherited-launch-lease.d.ts → locks/update-inherited-launch-lease.d.ts} +1 -1
- package/dist/updates/{update-inherited-launch-lease.js → locks/update-inherited-launch-lease.js} +2 -2
- package/dist/updates/{update-instance-lease.js → locks/update-instance-lease.js} +2 -2
- package/dist/updates/{update-lock.js → locks/update-lock.js} +2 -2
- package/dist/updates/{update-process-fence.js → locks/update-process-fence.js} +3 -3
- package/dist/updates/{update-process-liveness.js → locks/update-process-liveness.js} +2 -2
- package/dist/updates/retained-client-assets.d.ts +60 -0
- package/dist/updates/retained-client-assets.js +116 -0
- package/dist/updates/retention/retention-cleanup.d.ts +103 -0
- package/dist/updates/retention/retention-cleanup.js +439 -0
- package/dist/updates/retention/retention-prune-progress.d.ts +27 -0
- package/dist/updates/retention/retention-prune-progress.js +203 -0
- package/dist/updates/retention/retirement-inventory.d.ts +93 -0
- package/dist/updates/retention/retirement-inventory.js +373 -0
- package/dist/updates/retention/retirement-records.d.ts +75 -0
- package/dist/updates/retention/retirement-records.js +309 -0
- package/dist/updates/{update-retention-marker.d.ts → retention/update-retention-marker.d.ts} +1 -1
- package/dist/updates/{update-retention-marker.js → retention/update-retention-marker.js} +3 -3
- package/dist/updates/{update-retention-plan.d.ts → retention/update-retention-plan.d.ts} +1 -1
- package/dist/updates/{update-retention-plan.js → retention/update-retention-plan.js} +2 -2
- package/dist/updates/{update-retention-sync.d.ts → retention/update-retention-sync.d.ts} +1 -1
- package/dist/updates/{update-retention-sync.js → retention/update-retention-sync.js} +2 -2
- package/dist/updates/retention/update-retirement.d.ts +26 -0
- package/dist/updates/retention/update-retirement.js +205 -0
- package/dist/updates/update-adapter.js +1 -1
- package/dist/updates/update-channel-store.d.ts +1 -1
- package/dist/updates/update-channel-store.js +2 -2
- package/dist/updates/update-manager.d.ts +4 -4
- package/dist/updates/update-manager.js +5 -5
- package/dist/updates/update-services.d.ts +15 -0
- package/dist/updates/update-services.js +77 -0
- package/dist/updates/update-state-store.d.ts +2 -2
- package/dist/updates/update-state-store.js +2 -2
- package/dist/views/appearance-surface.js +3 -1
- package/package.json +29 -29
- package/src/appearance/custom-theme-library.ts +42 -956
- package/src/appearance/theme-library-mutation.ts +288 -0
- package/src/appearance/theme-library-schema.ts +347 -0
- package/src/appearance/theme-library-store.ts +379 -0
- package/src/updates/update-adapter.ts +1 -1
- package/dist/updates/update-retirement.d.ts +0 -205
- package/dist/updates/update-retirement.js +0 -1485
- /package/dist/installer/{installer-archive.d.ts → installer-archive-members.d.ts} +0 -0
- /package/dist/updates/{packaged-release-config.d.ts → feed/packaged-release-config.d.ts} +0 -0
- /package/dist/updates/{release-feed.d.ts → feed/release-feed.d.ts} +0 -0
- /package/dist/updates/{release-location.d.ts → feed/release-location.d.ts} +0 -0
- /package/dist/updates/{release-version.d.ts → feed/release-version.d.ts} +0 -0
- /package/dist/updates/{signed-release.d.ts → feed/signed-release.d.ts} +0 -0
- /package/dist/updates/{update-discovery.d.ts → feed/update-discovery.d.ts} +0 -0
- /package/dist/updates/{update-shutdown.d.ts → helper/update-shutdown.d.ts} +0 -0
- /package/dist/updates/{update-marker.d.ts → install/update-marker.d.ts} +0 -0
- /package/dist/updates/{launch-environment.d.ts → launch/launch-environment.d.ts} +0 -0
- /package/dist/updates/{packaged-launch-admission.d.ts → launch/packaged-launch-admission.d.ts} +0 -0
- /package/dist/updates/{linux-process-state.d.ts → locks/linux-process-state.d.ts} +0 -0
- /package/dist/updates/{native-file-lock.d.ts → locks/native-file-lock.d.ts} +0 -0
- /package/dist/updates/{stable-file.d.ts → locks/stable-file.d.ts} +0 -0
- /package/dist/updates/{update-download-lock.d.ts → locks/update-download-lock.d.ts} +0 -0
- /package/dist/updates/{update-generation-lease.d.ts → locks/update-generation-lease.d.ts} +0 -0
- /package/dist/updates/{update-instance-lease.d.ts → locks/update-instance-lease.d.ts} +0 -0
- /package/dist/updates/{update-lock.d.ts → locks/update-lock.d.ts} +0 -0
- /package/dist/updates/{update-process-fence.d.ts → locks/update-process-fence.d.ts} +0 -0
- /package/dist/updates/{update-process-liveness.d.ts → locks/update-process-liveness.d.ts} +0 -0
- /package/src/updates/{release-version.ts → feed/release-version.ts} +0 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { isUuid } from "../../app/value-guards.js";
|
|
2
|
+
import { isCanonicalPath } from "../../native/canonical-path.js";
|
|
3
|
+
import { verifyReleaseDescriptor } from "../feed/signed-release.js";
|
|
4
|
+
import { readUpdateStageState, withUpdateLock } from "../update-state-store.js";
|
|
5
|
+
import { readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, updateStagingFor } from "../install/update-swap.js";
|
|
6
|
+
import { readUpdateLaunchGate, tryAcquireUpdateHelperLiveness } from "../launch/update-launch-gate.js";
|
|
7
|
+
import { hasUpdateHelperArtifacts } from "../helper/update-helper.js";
|
|
8
|
+
import { tryAcquireUpdateGenerationLease } from "../locks/update-generation-lease.js";
|
|
9
|
+
import { updateProcessMayBeAlive } from "../locks/update-process-liveness.js";
|
|
10
|
+
import { planUpdateRetention, retentionIdentityKey } from "./update-retention-plan.js";
|
|
11
|
+
import { readUpdateRetentionIntent, updateRetentionIntentPath } from "./update-retention-marker.js";
|
|
12
|
+
import { VERSION, generationFromClaimName, healthReceiptMatches, matchesInstalledTree, matchesOwnedTree, matchesPartiallyPrunedContainer, ownerMatches, pathInfo, readHealthReceipt, readOwner, updateRetirementPaths, validRetirementContainer } from "./retirement-records.js";
|
|
13
|
+
import { assertNoUnresolvedRetentionPruneArtifacts, isPruneProgressName, pruneProgressNames, readPruneProgress, readPruneProgressFile, retentionPruneProgressPath } from "./retention-prune-progress.js";
|
|
14
|
+
import { lstat, readdir } from "node:fs/promises";
|
|
15
|
+
import { basename, dirname, join } from "node:path";
|
|
16
|
+
// src/updates/retention/retirement-inventory.ts
|
|
17
|
+
/**
|
|
18
|
+
* Read and validate every retirement claim and container while the install lock
|
|
19
|
+
* is held. Retention planning can opt into rejecting in-progress cleanup and
|
|
20
|
+
* receipt publication artifacts; acknowledgement discovery preserves its
|
|
21
|
+
* existing support for those recoverable receipt temporaries.
|
|
22
|
+
*/
|
|
23
|
+
async function readValidatedRetirementInventoryWhileLocked(target, currentVersion, options = {}) {
|
|
24
|
+
const strictRetentionState = options.strictRetentionState === true;
|
|
25
|
+
const targetInfo = await pathInfo(target);
|
|
26
|
+
const actualVersion = targetInfo?.isDirectory() ? await readUpdateTreeVersion(target) : void 0;
|
|
27
|
+
const actualIdentity = targetInfo?.isDirectory() ? await readUpdateTreeIdentity(target) : void 0;
|
|
28
|
+
if (!targetInfo?.isDirectory() || targetInfo.isSymbolicLink() || actualVersion !== currentVersion || !actualIdentity) throw new Error("The installed update does not match the host version");
|
|
29
|
+
const names = await readdir(dirname(target));
|
|
30
|
+
const retirementPrefix = `.${basename(target)}.framework-retired-`;
|
|
31
|
+
const cleanupMarkerName = `.${basename(target)}.framework-update-cleanup.json`;
|
|
32
|
+
const cleanupTemporaryPrefix = `.${basename(target)}.framework-update-cleanup-`;
|
|
33
|
+
const progressNames = names.filter((name) => isPruneProgressName(name, target));
|
|
34
|
+
let pruneProgress;
|
|
35
|
+
let pruneProgressTemporary;
|
|
36
|
+
let pruneIntentOnDisk;
|
|
37
|
+
if (progressNames.length > 0) {
|
|
38
|
+
const generation = options.allowedPruneProgressGeneration;
|
|
39
|
+
if (!generation || progressNames.some((name) => !pruneProgressNames(target, generation).includes(name))) throw new Error("A partial update retention prune requires recovery");
|
|
40
|
+
const progressTemporaryPrefix = `${basename(retentionPruneProgressPath(target, generation))}.`;
|
|
41
|
+
pruneIntentOnDisk = await readUpdateRetentionIntent(target, generation);
|
|
42
|
+
pruneProgress = await readPruneProgress(target, generation, pruneIntentOnDisk);
|
|
43
|
+
if (!pruneProgress) throw new Error("An update retention progress marker requires recovery");
|
|
44
|
+
if (!pruneIntentOnDisk && pruneProgress.phase !== "empty") throw new Error("A partial update retention prune lost its intent");
|
|
45
|
+
const progressTemporaries = names.filter((name) => name.startsWith(progressTemporaryPrefix) && name.endsWith(".tmp"));
|
|
46
|
+
if (progressTemporaries.length > 0) {
|
|
47
|
+
const temporaryName = options.allowedPruneProgressTemporaryName;
|
|
48
|
+
if (progressTemporaries.length !== 1 || !temporaryName || progressTemporaries[0] !== temporaryName || !isUuid(temporaryName.slice(progressTemporaryPrefix.length, -4))) throw new Error("An update retention progress publication requires recovery");
|
|
49
|
+
pruneProgressTemporary = await readPruneProgressFile(join(dirname(target), temporaryName), target, generation, pruneIntentOnDisk, pruneProgress.owner);
|
|
50
|
+
const [finalInfo, temporaryInfo] = await Promise.all([lstat(retentionPruneProgressPath(target, generation), { bigint: true }), lstat(join(dirname(target), temporaryName), { bigint: true })]);
|
|
51
|
+
const sameHardLink = finalInfo.dev === temporaryInfo.dev && finalInfo.ino === temporaryInfo.ino;
|
|
52
|
+
const duplicatePublication = pruneProgressTemporary !== void 0 && sameHardLink && pruneProgressTemporary.phase === pruneProgress.phase && healthReceiptMatches(pruneProgressTemporary.healthReceipt, pruneProgress.healthReceipt);
|
|
53
|
+
const interruptedPhaseTransition = pruneProgressTemporary !== void 0 && !sameHardLink && pruneProgress.phase === "deleting" && pruneProgressTemporary.phase === "empty" && healthReceiptMatches(pruneProgressTemporary.healthReceipt, pruneProgress.healthReceipt) && await matchesPartiallyPrunedContainer(pruneProgressTemporary.intent, pruneProgressTemporary.owner, updateRetirementPaths(target, generation), "empty");
|
|
54
|
+
if (!duplicatePublication && !interruptedPhaseTransition) throw new Error("An update retention progress temporary is ambiguous");
|
|
55
|
+
} else if (options.allowedPruneProgressTemporaryName !== void 0) throw new Error("An update retention progress temporary disappeared");
|
|
56
|
+
} else if (options.allowedPruneProgressGeneration !== void 0) {
|
|
57
|
+
const generation = options.allowedPruneProgressGeneration;
|
|
58
|
+
const temporaryName = options.allowedPruneProgressTemporaryName;
|
|
59
|
+
const progressTemporaryPrefix = `${basename(retentionPruneProgressPath(target, generation))}.`;
|
|
60
|
+
const progressTemporaries = names.filter((name) => name.startsWith(progressTemporaryPrefix) && name.endsWith(".tmp"));
|
|
61
|
+
if (!temporaryName || progressTemporaries.length !== 1 || progressTemporaries[0] !== temporaryName || !isUuid(temporaryName.slice(progressTemporaryPrefix.length, -4))) throw new Error("An update retention progress marker disappeared");
|
|
62
|
+
pruneIntentOnDisk = await readUpdateRetentionIntent(target, generation);
|
|
63
|
+
pruneProgressTemporary = await readPruneProgressFile(join(dirname(target), temporaryName), target, generation, pruneIntentOnDisk);
|
|
64
|
+
if (!pruneIntentOnDisk || !pruneProgressTemporary || pruneProgressTemporary.phase !== "deleting") throw new Error("An orphaned update retention progress temporary requires recovery");
|
|
65
|
+
} else if (options.allowedPruneProgressTemporaryName !== void 0) throw new Error("An update retention progress marker disappeared");
|
|
66
|
+
const allowedRetentionIntentName = options.allowedRetentionIntentGeneration ? basename(updateRetentionIntentPath(target, options.allowedRetentionIntentGeneration)) : void 0;
|
|
67
|
+
if (strictRetentionState && names.some((name) => {
|
|
68
|
+
const foldedName = name.toLowerCase();
|
|
69
|
+
return foldedName === cleanupMarkerName.toLowerCase() || foldedName.startsWith(cleanupTemporaryPrefix.toLowerCase());
|
|
70
|
+
})) throw new Error("An update retirement cleanup marker requires recovery");
|
|
71
|
+
if (strictRetentionState) assertNoUnresolvedRetentionPruneArtifacts(target, names, options);
|
|
72
|
+
const claimNames = /* @__PURE__ */ new Set();
|
|
73
|
+
const containerGenerations = /* @__PURE__ */ new Set();
|
|
74
|
+
for (const name of names.filter((entry) => entry.startsWith(retirementPrefix))) {
|
|
75
|
+
if (isPruneProgressName(name, target)) continue;
|
|
76
|
+
if (name === options.allowedPruneProgressTemporaryName) continue;
|
|
77
|
+
const suffix = name.slice(retirementPrefix.length);
|
|
78
|
+
if (isUuid(suffix)) {
|
|
79
|
+
const containerInfo = await pathInfo(join(dirname(target), name));
|
|
80
|
+
if (!containerInfo?.isDirectory() || containerInfo.isSymbolicLink()) throw new Error("An update retirement container requires recovery");
|
|
81
|
+
containerGenerations.add(suffix);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (generationFromClaimName(name, target)) {
|
|
85
|
+
claimNames.add(name);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (suffix.endsWith(".claim.json")) throw new Error("An update retirement claim has an invalid generation");
|
|
89
|
+
const generation = suffix.slice(0, 36);
|
|
90
|
+
const claimTemporaryId = suffix.startsWith(`${generation}.claim-`) && suffix.endsWith(".tmp") ? suffix.slice(generation.length + 7, -4) : "";
|
|
91
|
+
if (isUuid(generation) && isUuid(claimTemporaryId)) throw new Error("An update retirement claim publication is incomplete");
|
|
92
|
+
throw new Error("An unknown update retirement entry requires recovery");
|
|
93
|
+
}
|
|
94
|
+
for (const generation of containerGenerations) if (!claimNames.has(basename(updateRetirementPaths(target, generation).claim)) && generation.toLowerCase() !== pruneProgress?.intent.generation) throw new Error("An update retirement container has no matching claim");
|
|
95
|
+
const records = [];
|
|
96
|
+
for (const name of claimNames) {
|
|
97
|
+
const generation = generationFromClaimName(name, target);
|
|
98
|
+
if (!generation) {
|
|
99
|
+
if (name.endsWith(".claim.json")) throw new Error("An update retirement claim has an invalid generation");
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const paths = updateRetirementPaths(target, generation);
|
|
103
|
+
if (name !== basename(paths.claim)) continue;
|
|
104
|
+
if (pruneProgress?.intent.generation === generation.toLowerCase()) continue;
|
|
105
|
+
const claimInfo = await pathInfo(paths.claim);
|
|
106
|
+
const owner = await readOwner(paths.claim);
|
|
107
|
+
if (!claimInfo?.isFile() || claimInfo.isSymbolicLink() || !owner || owner.target !== target || owner.generation !== generation) throw new Error("An update retirement claim requires recovery");
|
|
108
|
+
const recordProgress = pruneProgress && owner.generation.toLowerCase() === pruneProgress.intent.generation ? pruneProgress : void 0;
|
|
109
|
+
if (recordProgress && !ownerMatches(owner, recordProgress.owner) || !await validRetirementContainer(owner, paths, !strictRetentionState, recordProgress)) throw new Error("An update retirement container requires recovery");
|
|
110
|
+
records.push({
|
|
111
|
+
owner,
|
|
112
|
+
paths,
|
|
113
|
+
healthy: Boolean(await pathInfo(paths.healthReceipt))
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (pruneProgressTemporary && !pruneProgress) {
|
|
117
|
+
const record = records.find(({ owner }) => owner.generation.toLowerCase() === pruneProgressTemporary.intent.generation);
|
|
118
|
+
if (!record || !ownerMatches(record.owner, pruneProgressTemporary.owner) || !healthReceiptMatches(await readHealthReceipt(record.paths.healthReceipt), pruneProgressTemporary.healthReceipt)) throw new Error("An orphaned update retention progress temporary is stale");
|
|
119
|
+
}
|
|
120
|
+
if (pruneProgress) {
|
|
121
|
+
const owner = pruneProgress.owner;
|
|
122
|
+
const paths = updateRetirementPaths(target, owner.generation);
|
|
123
|
+
const installedOwner = records.find(({ owner: recordOwner }) => recordOwner.generation.toLowerCase() === pruneProgress.intent.installedGeneration)?.owner;
|
|
124
|
+
if (owner.target !== target || owner.generation.toLowerCase() !== pruneProgress.intent.generation || pruneProgress.intent.target !== target || !sameUpdateTreeIdentity(pruneProgress.intent.installedTreeIdentity, actualIdentity) || !installedOwner || installedOwner.newVersion !== actualVersion || !sameUpdateTreeIdentity(installedOwner.newTreeIdentity, actualIdentity) || !await matchesInstalledTree(target, installedOwner) || !await matchesPartiallyPrunedContainer(pruneProgress.intent, owner, paths, pruneProgress.phase)) throw new Error("An update retention prune no longer matches its installed generation");
|
|
125
|
+
const claimInfo = await pathInfo(paths.claim);
|
|
126
|
+
if (pruneProgress.phase === "deleting" && !claimInfo) throw new Error("A partial update retention prune lost its claim");
|
|
127
|
+
if (claimInfo) {
|
|
128
|
+
if (!claimInfo.isFile() || claimInfo.isSymbolicLink()) throw new Error("An update retention prune claim changed during recovery");
|
|
129
|
+
const claimOwner = await readOwner(paths.claim);
|
|
130
|
+
if (!claimOwner || !ownerMatches(claimOwner, owner)) throw new Error("An update retention prune claim changed during recovery");
|
|
131
|
+
}
|
|
132
|
+
if (pruneProgress.phase === "deleting" && !pruneIntentOnDisk) throw new Error("A partial update retention prune lost its intent");
|
|
133
|
+
const healthInfo = await pathInfo(paths.healthReceipt);
|
|
134
|
+
if (pruneProgress.phase === "deleting" && !healthInfo) throw new Error("A partial update retention prune lost its health receipt");
|
|
135
|
+
if (healthInfo) {
|
|
136
|
+
const receipt = await readHealthReceipt(paths.healthReceipt);
|
|
137
|
+
if (!healthInfo.isFile() || healthInfo.isSymbolicLink() || !healthReceiptMatches(receipt, pruneProgress.healthReceipt)) throw new Error("An update retention prune health receipt changed during recovery");
|
|
138
|
+
}
|
|
139
|
+
records.push({
|
|
140
|
+
owner,
|
|
141
|
+
paths,
|
|
142
|
+
healthy: true
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
actualVersion,
|
|
147
|
+
actualIdentity,
|
|
148
|
+
records,
|
|
149
|
+
allowedIntentObserved: allowedRetentionIntentName !== void 0 && names.includes(allowedRetentionIntentName)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Discover the exact unacknowledged installed generation after staging cleanup.
|
|
154
|
+
* The generation claim is persistent beside the retired tree, so discovery does
|
|
155
|
+
* not depend on a startup return value or log message.
|
|
156
|
+
*/
|
|
157
|
+
async function findPendingUpdateHealthAcknowledgement(options) {
|
|
158
|
+
const { target, currentVersion } = options;
|
|
159
|
+
if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update health acknowledgement lookup");
|
|
160
|
+
return withUpdateLock(target, async () => {
|
|
161
|
+
const staging = updateStagingFor(target);
|
|
162
|
+
const stagingInfo = await pathInfo(staging);
|
|
163
|
+
if (stagingInfo) {
|
|
164
|
+
if (!stagingInfo.isDirectory() || stagingInfo.isSymbolicLink()) return null;
|
|
165
|
+
const state = await readUpdateStageState(staging);
|
|
166
|
+
if (state?.helperPid && updateProcessMayBeAlive(state.helperPid)) return null;
|
|
167
|
+
if ((!state || !state.helperPid) && await hasUpdateHelperArtifacts(staging)) return null;
|
|
168
|
+
}
|
|
169
|
+
const inventory = await readValidatedRetirementInventoryWhileLocked(target, currentVersion);
|
|
170
|
+
const pending = [];
|
|
171
|
+
for (const record of inventory.records) {
|
|
172
|
+
const { owner } = record;
|
|
173
|
+
if (owner.newVersion !== inventory.actualVersion || !sameUpdateTreeIdentity(owner.newTreeIdentity, inventory.actualIdentity)) continue;
|
|
174
|
+
if (!await matchesInstalledTree(target, owner)) throw new Error("An installed update retirement record requires recovery");
|
|
175
|
+
if (!record.healthy) pending.push({
|
|
176
|
+
generation: owner.generation,
|
|
177
|
+
version: owner.newVersion
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (pending.length > 1) throw new Error("Multiple update generations match the installed tree");
|
|
181
|
+
return pending[0] ?? null;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Fail closed before publishing a new stage while any retention-prune intent,
|
|
186
|
+
* progress marker, temporary, or unknown prune-shaped artifact is present.
|
|
187
|
+
* Uses the same artifact-name check as strict retention inventory and must be
|
|
188
|
+
* called while the per-install update lock is held. It deliberately does not
|
|
189
|
+
* require unrelated retirement history to be valid before a new stage.
|
|
190
|
+
*/
|
|
191
|
+
async function assertNoUpdateRetentionPruneArtifactsWhileLocked(target) {
|
|
192
|
+
if (!isCanonicalPath(target) || !basename(target)) throw new Error("Invalid update retention prune gate target");
|
|
193
|
+
assertNoUnresolvedRetentionPruneArtifacts(target, await readdir(dirname(target)), {}, "update retention prune requires recovery before staging");
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Plan rollback-tree retention from a complete, read-only filesystem inventory.
|
|
197
|
+
* This does not delete or modify retirement records; callers must revalidate
|
|
198
|
+
* ownership and the returned plan before any future cleanup operation.
|
|
199
|
+
*/
|
|
200
|
+
async function planValidatedUpdateRetention(options) {
|
|
201
|
+
const { target, currentVersion } = options;
|
|
202
|
+
if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
|
|
203
|
+
return withUpdateLock(target, async () => (await planRetentionWhileLocked(target, currentVersion)).plan);
|
|
204
|
+
}
|
|
205
|
+
async function planRetentionWhileLocked(target, currentVersion, options = {}) {
|
|
206
|
+
const staging = updateStagingFor(target);
|
|
207
|
+
if (await pathInfo(staging)) {
|
|
208
|
+
if (!options.validatedStagedVersion || !options.stagedTrust) throw new Error("An update staging directory requires recovery");
|
|
209
|
+
const stagedTrust = options.stagedTrust;
|
|
210
|
+
const info = await pathInfo(staging);
|
|
211
|
+
const state = await readUpdateStageState(staging);
|
|
212
|
+
const descriptor = state?.signedRelease ? verifyReleaseDescriptor(state.signedRelease, stagedTrust) : { ok: false };
|
|
213
|
+
const candidate = join(staging, "candidate");
|
|
214
|
+
const [targetVersion, candidateVersion, targetIdentity, candidateIdentity] = await Promise.all([
|
|
215
|
+
readUpdateTreeVersion(target),
|
|
216
|
+
readUpdateTreeVersion(candidate),
|
|
217
|
+
readUpdateTreeIdentity(target),
|
|
218
|
+
readUpdateTreeIdentity(candidate)
|
|
219
|
+
]);
|
|
220
|
+
if (!info?.isDirectory() || info.isSymbolicLink() || !state || state.phase !== "staged" || state.version !== options.validatedStagedVersion || state.previousVersion !== currentVersion || state.helperPid !== void 0 || state.helperOwner !== void 0 || state.launchGateOwner !== void 0 || !state.candidateTreeDigest || !descriptor.ok || descriptor.descriptor.version !== state.version || descriptor.descriptor.channel !== stagedTrust.channel || await readUpdateLaunchGate(target) || await hasUpdateHelperArtifacts(staging) || await pathInfo(join(staging, "old")) || targetVersion !== currentVersion || candidateVersion !== state.version || state.previousTreeIdentity !== void 0 && !sameUpdateTreeIdentity(targetIdentity, state.previousTreeIdentity) || !sameUpdateTreeIdentity(candidateIdentity, state.candidateTreeIdentity) || !sameUpdateTreeDigest(await readUpdateTreeDigest(candidate), state.candidateTreeDigest)) throw new Error("A staged update changed before retained tree acquisition");
|
|
221
|
+
}
|
|
222
|
+
const inventory = await readValidatedRetirementInventoryWhileLocked(target, currentVersion, {
|
|
223
|
+
strictRetentionState: true,
|
|
224
|
+
allowedRetentionIntentGeneration: options.allowedRetentionIntentGeneration,
|
|
225
|
+
allowedRetentionTemporaryName: options.allowedRetentionTemporaryName,
|
|
226
|
+
allowedPruneProgressGeneration: options.allowedPruneProgressGeneration,
|
|
227
|
+
allowedPruneProgressTemporaryName: options.allowedPruneProgressTemporaryName
|
|
228
|
+
});
|
|
229
|
+
const head = inventory.records.filter((record) => sameUpdateTreeIdentity(record.owner.newTreeIdentity, inventory.actualIdentity));
|
|
230
|
+
if (head.length === 1) {
|
|
231
|
+
const current = head[0].owner;
|
|
232
|
+
if (current.newVersion !== inventory.actualVersion || !await matchesInstalledTree(target, current)) throw new Error("An installed update retirement record requires recovery");
|
|
233
|
+
}
|
|
234
|
+
const byInstalledIdentity = /* @__PURE__ */ new Map();
|
|
235
|
+
for (const { owner } of inventory.records) {
|
|
236
|
+
const key = retentionIdentityKey(owner.newTreeIdentity);
|
|
237
|
+
if (!key) throw new Error("An update retirement lineage requires recovery");
|
|
238
|
+
if (!byInstalledIdentity.has(key)) byInstalledIdentity.set(key, owner);
|
|
239
|
+
}
|
|
240
|
+
for (const { owner } of inventory.records) {
|
|
241
|
+
const previousKey = retentionIdentityKey(owner.previousTreeIdentity);
|
|
242
|
+
if (!previousKey) throw new Error("An update retirement lineage requires recovery");
|
|
243
|
+
const parent = byInstalledIdentity.get(previousKey);
|
|
244
|
+
if (parent && owner.previousVersion !== parent.newVersion) throw new Error("An update retirement lineage requires recovery");
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
inventory,
|
|
248
|
+
plan: planUpdateRetention(inventory.actualIdentity, inventory.records.map(({ owner, healthy }) => ({
|
|
249
|
+
generation: owner.generation,
|
|
250
|
+
installed: owner.newTreeIdentity,
|
|
251
|
+
previous: owner.previousTreeIdentity,
|
|
252
|
+
healthy: options.allowUnhealthyReads === true || healthy
|
|
253
|
+
})))
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Acquire shared leases on every validated retained generation. Keep the
|
|
258
|
+
* returned leases until all readers and response bodies have finished. A future
|
|
259
|
+
* deletion implementation must hold the update lock and the same generation's
|
|
260
|
+
* exclusive lease while it revalidates and removes that generation.
|
|
261
|
+
*/
|
|
262
|
+
async function acquireRetainedUpdateTrees(options) {
|
|
263
|
+
const { target, currentVersion } = options;
|
|
264
|
+
if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid retained update tree lookup");
|
|
265
|
+
let retained;
|
|
266
|
+
try {
|
|
267
|
+
return await withUpdateLock(target, async () => {
|
|
268
|
+
retained = await acquireRetainedUpdateTreesWhileLocked(options);
|
|
269
|
+
return retained;
|
|
270
|
+
});
|
|
271
|
+
} catch (error) {
|
|
272
|
+
if (retained?.status === "acquired") try {
|
|
273
|
+
await retained.release();
|
|
274
|
+
} catch (releaseError) {
|
|
275
|
+
throw new AggregateError([error, releaseError], "Update lock release failed after retained tree acquisition", { cause: releaseError });
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Acquire retained generations while the caller holds the per-install update
|
|
282
|
+
* lock. A staged candidate is accepted only after its caller has run trusted
|
|
283
|
+
* resume validation; this function repeats the stage identity and descriptor
|
|
284
|
+
* checks before permitting the retention inventory.
|
|
285
|
+
*/
|
|
286
|
+
async function acquireRetainedUpdateTreesWhileLocked(options) {
|
|
287
|
+
const { target, currentVersion } = options;
|
|
288
|
+
const stagedExists = await pathInfo(updateStagingFor(target));
|
|
289
|
+
if (stagedExists && (!options.validatedStagedVersion || !options.stagedTrust)) throw new Error("An update staging directory requires recovery");
|
|
290
|
+
let helperLiveness;
|
|
291
|
+
if (stagedExists) {
|
|
292
|
+
helperLiveness = await tryAcquireUpdateHelperLiveness(target);
|
|
293
|
+
if (!helperLiveness) return { status: "busy" };
|
|
294
|
+
}
|
|
295
|
+
const held = [];
|
|
296
|
+
const releaseHeld = async () => {
|
|
297
|
+
const failures = [];
|
|
298
|
+
for (const lease of held.splice(0).toReversed()) try {
|
|
299
|
+
await lease.release();
|
|
300
|
+
} catch (error) {
|
|
301
|
+
failures.push(error);
|
|
302
|
+
}
|
|
303
|
+
if (failures.length) throw new AggregateError(failures, "Could not release retained tree leases");
|
|
304
|
+
};
|
|
305
|
+
try {
|
|
306
|
+
const result = await (async () => {
|
|
307
|
+
const { inventory, plan: lineage } = await planRetentionWhileLocked(target, currentVersion, {
|
|
308
|
+
allowUnhealthyReads: true,
|
|
309
|
+
...options.validatedStagedVersion === void 0 ? {} : {
|
|
310
|
+
validatedStagedVersion: options.validatedStagedVersion,
|
|
311
|
+
stagedTrust: options.stagedTrust
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
if (lineage.status !== "ready") throw new Error("Update retention lineage requires recovery");
|
|
315
|
+
if (!inventory.records.length) return { status: "none" };
|
|
316
|
+
const trees = [];
|
|
317
|
+
const ordered = inventory.records.toSorted((left, right) => {
|
|
318
|
+
const a = left.owner.generation.toLowerCase();
|
|
319
|
+
const b = right.owner.generation.toLowerCase();
|
|
320
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
321
|
+
});
|
|
322
|
+
for (const { owner, paths } of ordered) {
|
|
323
|
+
const lease = await tryAcquireUpdateGenerationLease(target, owner.generation, "shared");
|
|
324
|
+
if (!lease) return { status: "busy" };
|
|
325
|
+
held.push(lease);
|
|
326
|
+
if (!await matchesOwnedTree(paths.tree, owner)) throw new Error("A retained update tree changed during lease acquisition");
|
|
327
|
+
trees.push(Object.freeze({
|
|
328
|
+
generation: owner.generation,
|
|
329
|
+
version: owner.previousVersion,
|
|
330
|
+
tree: paths.tree
|
|
331
|
+
}));
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
status: "acquired",
|
|
335
|
+
trees: Object.freeze(trees)
|
|
336
|
+
};
|
|
337
|
+
})();
|
|
338
|
+
if (result.status !== "acquired") {
|
|
339
|
+
await releaseHeld();
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
let release;
|
|
343
|
+
const retained = Object.freeze({
|
|
344
|
+
...result,
|
|
345
|
+
release: () => release ??= releaseHeld()
|
|
346
|
+
});
|
|
347
|
+
if (helperLiveness) {
|
|
348
|
+
const helper = helperLiveness;
|
|
349
|
+
helperLiveness = void 0;
|
|
350
|
+
try {
|
|
351
|
+
await helper.release();
|
|
352
|
+
} catch (error) {
|
|
353
|
+
try {
|
|
354
|
+
await releaseHeld();
|
|
355
|
+
} catch (releaseError) {
|
|
356
|
+
throw new AggregateError([error, releaseError], "Retained tree and helper leases failed to release", { cause: releaseError });
|
|
357
|
+
}
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return retained;
|
|
362
|
+
} catch (error) {
|
|
363
|
+
try {
|
|
364
|
+
await releaseHeld();
|
|
365
|
+
} catch (releaseError) {
|
|
366
|
+
throw new AggregateError([error, releaseError], "Retained tree acquisition and release failed", { cause: releaseError });
|
|
367
|
+
}
|
|
368
|
+
throw error;
|
|
369
|
+
} finally {
|
|
370
|
+
await helperLiveness?.release();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
export { acquireRetainedUpdateTrees, acquireRetainedUpdateTreesWhileLocked, assertNoUpdateRetentionPruneArtifactsWhileLocked, findPendingUpdateHealthAcknowledgement, planRetentionWhileLocked, planValidatedUpdateRetention };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { UpdateRetentionIntent } from './update-retention-marker';
|
|
2
|
+
import type { UpdateStageState } from '../update-state-store';
|
|
3
|
+
import { type UpdateTreeIdentity } from '../install/update-swap';
|
|
4
|
+
import type { RetentionPruneProgress } from './retention-prune-progress';
|
|
5
|
+
export type RetirementOwner = Readonly<{
|
|
6
|
+
schema: 2;
|
|
7
|
+
generation: string;
|
|
8
|
+
target: string;
|
|
9
|
+
newVersion: string;
|
|
10
|
+
previousVersion: string;
|
|
11
|
+
previousTreeIdentity: UpdateTreeIdentity;
|
|
12
|
+
newTreeIdentity: UpdateTreeIdentity;
|
|
13
|
+
container: string;
|
|
14
|
+
tree: 'tree';
|
|
15
|
+
}>;
|
|
16
|
+
export type UpdateHealthAcknowledgement = Readonly<{
|
|
17
|
+
generation: string;
|
|
18
|
+
version: string;
|
|
19
|
+
}>;
|
|
20
|
+
export type HealthReceipt = Readonly<{
|
|
21
|
+
schema: 1;
|
|
22
|
+
generation: string;
|
|
23
|
+
target: string;
|
|
24
|
+
version: string;
|
|
25
|
+
treeIdentity: UpdateTreeIdentity;
|
|
26
|
+
}>;
|
|
27
|
+
type RetirementCleanupMarker = Readonly<{
|
|
28
|
+
schema: 1;
|
|
29
|
+
generation: string;
|
|
30
|
+
target: string;
|
|
31
|
+
version: string;
|
|
32
|
+
claim: string;
|
|
33
|
+
phase: 'staging-cleanup';
|
|
34
|
+
}>;
|
|
35
|
+
export declare const VERSION: RegExp;
|
|
36
|
+
export declare const PUBLISHER_TEMP_UUID: RegExp;
|
|
37
|
+
export declare function hasExactOwnKeys(value: Record<string, unknown>, expected: readonly string[]): boolean;
|
|
38
|
+
/** Generation-specific retirement paths, all beside the fixed staging path. */
|
|
39
|
+
export declare function updateRetirementPaths(target: string, generation: string): Readonly<{
|
|
40
|
+
container: string;
|
|
41
|
+
tree: string;
|
|
42
|
+
healthReceipt: string;
|
|
43
|
+
healthTemporaryPrefix: ".healthy-";
|
|
44
|
+
claim: string;
|
|
45
|
+
claimTemporaryPrefix: `${string}.claim-`;
|
|
46
|
+
cleanupMarker: string;
|
|
47
|
+
cleanupMarkerTemporaryPrefix: `.${string}.framework-update-cleanup-`;
|
|
48
|
+
}>;
|
|
49
|
+
export declare function matchesPartiallyPrunedContainer(intent: UpdateRetentionIntent, owner: RetirementOwner, paths: ReturnType<typeof updateRetirementPaths>, phase: RetentionPruneProgress['phase']): Promise<boolean>;
|
|
50
|
+
export declare function samePathTreeIdentity(path: string, identity: UpdateTreeIdentity): Promise<boolean>;
|
|
51
|
+
export declare function ownerFor(target: string, state: UpdateStageState): RetirementOwner | undefined;
|
|
52
|
+
export declare function parseOwner(value: unknown): RetirementOwner | undefined;
|
|
53
|
+
export declare function ownerMatches(actual: RetirementOwner | undefined, expected: RetirementOwner): boolean;
|
|
54
|
+
export declare function cleanupMarkerMatches(actual: RetirementCleanupMarker | undefined, expected: RetirementCleanupMarker): boolean;
|
|
55
|
+
export declare function readOwner(path: string): Promise<RetirementOwner | undefined>;
|
|
56
|
+
export declare function parseHealthReceipt(value: unknown): HealthReceipt | undefined;
|
|
57
|
+
export declare function readHealthReceipt(path: string): Promise<HealthReceipt | undefined>;
|
|
58
|
+
export declare function healthReceiptFor(owner: RetirementOwner): HealthReceipt;
|
|
59
|
+
export declare function healthReceiptMatches(actual: HealthReceipt | undefined, expected: HealthReceipt): boolean;
|
|
60
|
+
export declare function readCleanupMarker(path: string): Promise<RetirementCleanupMarker | undefined>;
|
|
61
|
+
export declare function pathInfo(path: string): Promise<import("node:fs").Stats | undefined>;
|
|
62
|
+
export declare function matchesOldTree(path: string, state: UpdateStageState): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Publish the generation claim from a complete private temporary using an
|
|
65
|
+
* exclusive rename. A valid interrupted temporary can be promoted on retry;
|
|
66
|
+
* malformed or colliding files are preserved and never treated as ownership.
|
|
67
|
+
*/
|
|
68
|
+
export declare function ensureClaim(target: string, state: UpdateStageState): Promise<boolean>;
|
|
69
|
+
export declare function ensureCleanupMarker(target: string, state: UpdateStageState): Promise<boolean>;
|
|
70
|
+
export declare function matchesOwnedTree(path: string, owner: RetirementOwner): Promise<boolean>;
|
|
71
|
+
export declare function matchesInstalledTree(path: string, owner: RetirementOwner): Promise<boolean>;
|
|
72
|
+
export declare function isMatchingHealthTemporary(name: string): boolean;
|
|
73
|
+
export declare function validRetirementContainer(owner: RetirementOwner, paths: ReturnType<typeof updateRetirementPaths>, allowHealthTemporaries?: boolean, pruneProgress?: RetentionPruneProgress): Promise<boolean>;
|
|
74
|
+
export declare function generationFromClaimName(name: string, target: string): string | undefined;
|
|
75
|
+
export {};
|