@adea-ai/app-framework 0.31.0 → 0.32.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.
Files changed (107) hide show
  1. package/README.md +26 -11
  2. package/dist/app/create-application.js +4 -3
  3. package/dist/app/serial-queue.d.ts +5 -0
  4. package/dist/app/serial-queue.js +14 -0
  5. package/dist/app/value-guards.d.ts +15 -0
  6. package/dist/app/value-guards.js +29 -0
  7. package/dist/ci/toolchain-identity.js +1 -1
  8. package/dist/desktop/channel-proof.js +2 -1
  9. package/dist/desktop/client-asset-stream.js +6 -12
  10. package/dist/desktop/desktop-host.d.ts +25 -5
  11. package/dist/desktop/desktop-host.js +75 -20
  12. package/dist/framework-source.json +1 -1
  13. package/dist/installer/command-artifact.js +4 -3
  14. package/dist/installer/command-qualification-command.js +6 -5
  15. package/dist/installer/hosted-runner.d.ts +9 -2
  16. package/dist/installer/hosted-runner.js +18 -5
  17. package/dist/installer/installed-payload.js +20 -46
  18. package/dist/installer/installer-archive.d.ts +33 -0
  19. package/dist/installer/installer-archive.js +116 -0
  20. package/dist/installer/installer-ci-bootstrap.js +10 -6
  21. package/dist/installer/installer-extraction.js +54 -120
  22. package/dist/installer/installer-identity.js +33 -111
  23. package/dist/installer/installer-observation.js +3 -2
  24. package/dist/installer/installer-process-cleanup.js +7 -46
  25. package/dist/installer/installer-qualification-command.js +6 -5
  26. package/dist/installer/installer-upgrade-command.js +5 -5
  27. package/dist/installer/installer-worker-guard.js +2 -1
  28. package/dist/native/canonical-path.d.ts +5 -0
  29. package/dist/native/canonical-path.js +10 -0
  30. package/dist/native/cef-helper.js +5 -4
  31. package/dist/native/electrobun-source-patch.js +3 -2
  32. package/dist/native/{directory-exchange.d.ts → native-rename.d.ts} +2 -0
  33. package/dist/native/native-rename.js +126 -0
  34. package/dist/native/native-secret-store.js +2 -6
  35. package/dist/native/native-utilities.js +4 -4
  36. package/dist/native/posix-launcher-build.js +1 -1
  37. package/dist/native/posix-tree-removal.js +2 -2
  38. package/dist/native/windows-process.d.ts +9 -0
  39. package/dist/native/windows-process.js +60 -0
  40. package/dist/release/feed-release-cut.js +2 -1
  41. package/dist/release/framework-package-publish.js +1 -1
  42. package/dist/release/framework-update-lock.js +2 -1
  43. package/dist/release/github-cli.d.ts +18 -0
  44. package/dist/release/github-cli.js +13 -1
  45. package/dist/release/github-release-cut.js +3 -2
  46. package/dist/release/github-release-provenance.js +2 -1
  47. package/dist/release/github-release-publisher.js +2 -1
  48. package/dist/release/local-provenance.js +3 -2
  49. package/dist/release/local-release.js +6 -6
  50. package/dist/release/qualification-run.d.ts +25 -0
  51. package/dist/release/qualification-run.js +43 -0
  52. package/dist/release/release-artifact.js +3 -11
  53. package/dist/release/release-assets-plan.js +16 -6
  54. package/dist/release/release-config.js +14 -14
  55. package/dist/release/release-cut-command.js +14 -4
  56. package/dist/release/release-cut.js +3 -2
  57. package/dist/release/release-descriptor-staging.js +13 -27
  58. package/dist/release/release-finalize.js +2 -1
  59. package/dist/release/release-publication.js +3 -11
  60. package/dist/release/release-publish-command.js +15 -6
  61. package/dist/release/release-qualification.js +3 -2
  62. package/dist/release/retained-release-build.js +12 -12
  63. package/dist/update-helper.bundle.js +250 -190
  64. package/dist/updates/desktop-updater.js +53 -58
  65. package/dist/updates/packaged-launch-admission.js +3 -2
  66. package/dist/updates/packaged-release-config.js +6 -5
  67. package/dist/updates/release-feed.js +9 -9
  68. package/dist/updates/signed-release.js +5 -5
  69. package/dist/updates/stable-file.d.ts +18 -0
  70. package/dist/updates/stable-file.js +54 -1
  71. package/dist/updates/update-adapter.d.ts +2 -13
  72. package/dist/updates/update-arm.js +7 -5
  73. package/dist/updates/update-channel-store.js +7 -9
  74. package/dist/updates/update-discovery.js +30 -34
  75. package/dist/updates/update-download-cleanup.js +2 -1
  76. package/dist/updates/update-download.js +2 -4
  77. package/dist/updates/update-extraction.js +1 -1
  78. package/dist/updates/update-generation-lease.js +4 -3
  79. package/dist/updates/update-handoff-plan.js +3 -2
  80. package/dist/updates/update-helper.js +8 -6
  81. package/dist/updates/update-instance-lease.js +3 -2
  82. package/dist/updates/update-launch-gate.js +12 -25
  83. package/dist/updates/update-launch.js +3 -2
  84. package/dist/updates/update-lock.js +3 -2
  85. package/dist/updates/update-marker.js +3 -2
  86. package/dist/updates/update-process-fence.js +10 -39
  87. package/dist/updates/update-process-liveness.js +2 -1
  88. package/dist/updates/update-resume.js +26 -22
  89. package/dist/updates/update-retention-marker.js +7 -5
  90. package/dist/updates/update-retention-plan.js +2 -2
  91. package/dist/updates/update-retirement.js +40 -39
  92. package/dist/updates/update-state-store.js +29 -37
  93. package/dist/updates/update-state.d.ts +8 -3
  94. package/dist/updates/update-swap-stage.js +6 -5
  95. package/dist/updates/update-swap.d.ts +1 -1
  96. package/dist/updates/update-swap.js +8 -6
  97. package/package.json +4 -12
  98. package/src/desktop/client-asset-stream.ts +6 -12
  99. package/src/updates/update-adapter.ts +2 -14
  100. package/src/updates/update-state.ts +11 -2
  101. package/dist/native/directory-exchange.js +0 -90
  102. package/dist/native/exclusive-rename.d.ts +0 -2
  103. package/dist/native/exclusive-rename.js +0 -52
  104. package/dist/release/retention-dry-run.d.ts +0 -46
  105. package/dist/release/retention-dry-run.js +0 -94
  106. package/dist/updates/update-exclusive-rename.d.ts +0 -3
  107. package/dist/updates/update-exclusive-rename.js +0 -5
@@ -1,5 +1,7 @@
1
+ import { errorCode, isUuid } from "../app/value-guards.js";
2
+ import { isCanonicalPath } from "../native/canonical-path.js";
3
+ import { renameExclusive } from "../native/native-rename.js";
1
4
  import { verifyReleaseDescriptor } from "./signed-release.js";
2
- import { renameUpdateExclusive } from "./update-exclusive-rename.js";
3
5
  import { readUpdateStageState, withUpdateLock, writeUpdateStageState } from "./update-state-store.js";
4
6
  import { readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, updateStagingFor } from "./update-swap.js";
5
7
  import { readUpdateLaunchGate, tryAcquireUpdateHelperLiveness } from "./update-launch-gate.js";
@@ -12,9 +14,9 @@ import { planUpdateRetention, retentionIdentityKey } from "./update-retention-pl
12
14
  import { publishUpdateRetentionIntent, readUpdateRetentionIntent, readUpdateRetentionIntentFile, sameRetentionIntent, updateRetentionIntentPath } from "./update-retention-marker.js";
13
15
  import { syncUpdateRetentionIntent } from "./update-retention-sync.js";
14
16
  import { link, lstat, mkdir, open, readFile, readdir, rename, rm, rmdir, unlink, writeFile } from "node:fs/promises";
15
- import { basename, dirname, isAbsolute, join, resolve } from "node:path";
16
- import { constants as constants$1 } from "node:fs";
17
+ import { basename, dirname, join } from "node:path";
17
18
  import { randomUUID } from "node:crypto";
19
+ import { constants as constants$1 } from "node:fs";
18
20
  // src/updates/update-retirement.ts
19
21
  /** A failed promotion may have left the final marker in place; inspect before retrying. */
20
22
  var UpdateRetentionOrphanPromotionError = class extends Error {
@@ -30,7 +32,6 @@ var UpdateRetentionOrphanPromotionError = class extends Error {
30
32
  }
31
33
  };
32
34
  var VERSION = /^\d+\.\d+\.\d+(?:-dev\.\d+)?$/;
33
- var UUID = /^[0-9a-f]{8}-[0-9a-f-]{27}$/i;
34
35
  var PUBLISHER_TEMP_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
35
36
  function hasExactOwnKeys(value, expected) {
36
37
  const actual = Reflect.ownKeys(value);
@@ -38,7 +39,7 @@ function hasExactOwnKeys(value, expected) {
38
39
  }
39
40
  /** Generation-specific retirement paths, all beside the fixed staging path. */
40
41
  function updateRetirementPaths(target, generation) {
41
- if (typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target || !UUID.test(generation)) throw new Error("Invalid update retirement identity");
42
+ if (!isCanonicalPath(target) || !isUuid(generation)) throw new Error("Invalid update retirement identity");
42
43
  const prefix = `.${basename(target)}.framework-retired-${generation}`;
43
44
  const container = join(dirname(target), prefix);
44
45
  return Object.freeze({
@@ -60,7 +61,7 @@ function isPruneProgressName(name, target) {
60
61
  if (!name.startsWith(prefix)) return false;
61
62
  const suffix = name.slice(prefix.length);
62
63
  const match = /^([0-9a-f-]{36})\.prune-progress\.json$/i.exec(suffix);
63
- return Boolean(match && UUID.test(match[1]));
64
+ return Boolean(match && isUuid(match[1]));
64
65
  }
65
66
  function pruneProgressNames(target, generation) {
66
67
  return [basename(retentionPruneProgressPath(target, generation))];
@@ -85,7 +86,7 @@ async function findPruneProgressTemporaryName(target, generation) {
85
86
  const name = names[0];
86
87
  if (!name) return void 0;
87
88
  const temporaryId = name.slice(prefix.length, -4);
88
- if (!UUID.test(temporaryId)) throw new Error("An update retention progress temporary requires recovery");
89
+ if (!isUuid(temporaryId)) throw new Error("An update retention progress temporary requires recovery");
89
90
  return name;
90
91
  }
91
92
  async function readPruneProgressFile(path, target, generation, expectedIntent, expectedOwner) {
@@ -94,7 +95,7 @@ async function readPruneProgressFile(path, target, generation, expectedIntent, e
94
95
  const canonicalName = basename(canonicalPath);
95
96
  const pathName = basename(path);
96
97
  const temporaryId = pathName.startsWith(`${canonicalName}.`) && pathName.endsWith(".tmp") ? pathName.slice(canonicalName.length + 1, -4) : "";
97
- const canonicalTemporary = dirname(path) === dirname(canonicalPath) && UUID.test(temporaryId);
98
+ const canonicalTemporary = dirname(path) === dirname(canonicalPath) && isUuid(temporaryId);
98
99
  const info = await lstat(path);
99
100
  if (path !== canonicalPath && !canonicalTemporary || !info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 8192) return void 0;
100
101
  const value = JSON.parse(await readFile(path, "utf8"));
@@ -116,7 +117,7 @@ async function readPruneProgressFile(path, target, generation, expectedIntent, e
116
117
  "installedTreeIdentity"
117
118
  ]) || expectedIntent !== void 0 && !sameRetentionIntent(record.intent, expectedIntent) || typeof record.owner !== "object" || record.owner === null || Array.isArray(record.owner)) return void 0;
118
119
  const intent = record.intent;
119
- if (intent.schema !== 1 || intent.phase !== "prune-previous-tree" || typeof intent.target !== "string" || intent.target !== target || typeof intent.generation !== "string" || intent.generation !== generation.toLowerCase() || !retentionIdentityKey(intent.previousTreeIdentity) || !retentionIdentityKey(intent.installedTreeIdentity) || typeof intent.installedGeneration !== "string" || !UUID.test(intent.installedGeneration) || Object.keys(intent.previousTreeIdentity).length !== 2 || !hasExactOwnKeys(intent.previousTreeIdentity, ["device", "inode"]) || Object.keys(intent.installedTreeIdentity).length !== 2 || !hasExactOwnKeys(intent.installedTreeIdentity, ["device", "inode"])) return void 0;
120
+ if (intent.schema !== 1 || intent.phase !== "prune-previous-tree" || typeof intent.target !== "string" || intent.target !== target || typeof intent.generation !== "string" || intent.generation !== generation.toLowerCase() || !retentionIdentityKey(intent.previousTreeIdentity) || !retentionIdentityKey(intent.installedTreeIdentity) || typeof intent.installedGeneration !== "string" || !isUuid(intent.installedGeneration) || Object.keys(intent.previousTreeIdentity).length !== 2 || !hasExactOwnKeys(intent.previousTreeIdentity, ["device", "inode"]) || Object.keys(intent.installedTreeIdentity).length !== 2 || !hasExactOwnKeys(intent.installedTreeIdentity, ["device", "inode"])) return void 0;
120
121
  const owner = parseOwner(record.owner);
121
122
  if (!owner || expectedOwner && !ownerMatches(owner, expectedOwner)) return void 0;
122
123
  const healthReceipt = parseHealthReceipt(record.healthReceipt);
@@ -283,7 +284,7 @@ function parseOwner(value) {
283
284
  const record = value;
284
285
  const identity = record.previousTreeIdentity;
285
286
  const newTreeIdentity = record.newTreeIdentity;
286
- if (record.schema !== 2 || typeof record.generation !== "string" || !UUID.test(record.generation) || typeof record.target !== "string" || !isAbsolute(record.target) || resolve(record.target) !== record.target || typeof record.newVersion !== "string" || !VERSION.test(record.newVersion) || typeof record.previousVersion !== "string" || !VERSION.test(record.previousVersion) || typeof identity !== "object" || identity === null || Array.isArray(identity) || !hasExactOwnKeys(identity, ["device", "inode"]) || typeof identity.device !== "string" || !/^[1-9]\d{0,19}$/.test(identity.device) || typeof identity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(identity.inode) || typeof newTreeIdentity !== "object" || newTreeIdentity === null || Array.isArray(newTreeIdentity) || !hasExactOwnKeys(newTreeIdentity, ["device", "inode"]) || typeof newTreeIdentity.device !== "string" || !/^[1-9]\d{0,19}$/.test(newTreeIdentity.device) || typeof newTreeIdentity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(newTreeIdentity.inode) || typeof record.container !== "string" || record.container !== `.${basename(record.target)}.framework-retired-${record.generation}` || record.tree !== "tree" || !hasExactOwnKeys(record, [
287
+ if (record.schema !== 2 || typeof record.generation !== "string" || !isUuid(record.generation) || !isCanonicalPath(record.target) || typeof record.newVersion !== "string" || !VERSION.test(record.newVersion) || typeof record.previousVersion !== "string" || !VERSION.test(record.previousVersion) || typeof identity !== "object" || identity === null || Array.isArray(identity) || !hasExactOwnKeys(identity, ["device", "inode"]) || typeof identity.device !== "string" || !/^[1-9]\d{0,19}$/.test(identity.device) || typeof identity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(identity.inode) || typeof newTreeIdentity !== "object" || newTreeIdentity === null || Array.isArray(newTreeIdentity) || !hasExactOwnKeys(newTreeIdentity, ["device", "inode"]) || typeof newTreeIdentity.device !== "string" || !/^[1-9]\d{0,19}$/.test(newTreeIdentity.device) || typeof newTreeIdentity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(newTreeIdentity.inode) || typeof record.container !== "string" || record.container !== `.${basename(record.target)}.framework-retired-${record.generation}` || record.tree !== "tree" || !hasExactOwnKeys(record, [
287
288
  "schema",
288
289
  "generation",
289
290
  "target",
@@ -316,7 +317,7 @@ function cleanupMarkerMatches(actual, expected) {
316
317
  function parseCleanupMarker(value) {
317
318
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
318
319
  const record = value;
319
- if (record.schema !== 1 || typeof record.generation !== "string" || !UUID.test(record.generation) || typeof record.target !== "string" || !isAbsolute(record.target) || resolve(record.target) !== record.target || typeof record.version !== "string" || !VERSION.test(record.version) || typeof record.claim !== "string" || record.claim !== basename(updateRetirementPaths(record.target, record.generation).claim) || record.phase !== "staging-cleanup" || Object.keys(record).length !== 6) return void 0;
320
+ if (record.schema !== 1 || typeof record.generation !== "string" || !isUuid(record.generation) || !isCanonicalPath(record.target) || typeof record.version !== "string" || !VERSION.test(record.version) || typeof record.claim !== "string" || record.claim !== basename(updateRetirementPaths(record.target, record.generation).claim) || record.phase !== "staging-cleanup" || Object.keys(record).length !== 6) return void 0;
320
321
  return record;
321
322
  }
322
323
  async function readOwner(path) {
@@ -332,7 +333,7 @@ function parseHealthReceipt(value) {
332
333
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
333
334
  const record = value;
334
335
  const identity = record.treeIdentity;
335
- if (record.schema !== 1 || typeof record.generation !== "string" || !UUID.test(record.generation) || typeof record.target !== "string" || !isAbsolute(record.target) || resolve(record.target) !== record.target || typeof record.version !== "string" || !VERSION.test(record.version) || typeof identity !== "object" || identity === null || Array.isArray(identity) || !hasExactOwnKeys(identity, ["device", "inode"]) || typeof identity.device !== "string" || !/^[1-9]\d{0,19}$/.test(identity.device) || typeof identity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(identity.inode) || !hasExactOwnKeys(record, [
336
+ if (record.schema !== 1 || typeof record.generation !== "string" || !isUuid(record.generation) || !isCanonicalPath(record.target) || typeof record.version !== "string" || !VERSION.test(record.version) || typeof identity !== "object" || identity === null || Array.isArray(identity) || !hasExactOwnKeys(identity, ["device", "inode"]) || typeof identity.device !== "string" || !/^[1-9]\d{0,19}$/.test(identity.device) || typeof identity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(identity.inode) || !hasExactOwnKeys(record, [
336
337
  "schema",
337
338
  "generation",
338
339
  "target",
@@ -375,7 +376,7 @@ async function pathInfo(path) {
375
376
  try {
376
377
  return await lstat(path);
377
378
  } catch (error) {
378
- if (error.code === "ENOENT") return void 0;
379
+ if (errorCode(error) === "ENOENT") return void 0;
379
380
  throw error;
380
381
  }
381
382
  }
@@ -390,7 +391,7 @@ async function matchesOldTree(path, state) {
390
391
  }
391
392
  function isMatchingClaimTemporary(name, paths) {
392
393
  if (!name.startsWith(paths.claimTemporaryPrefix) || !name.endsWith(".tmp")) return false;
393
- return UUID.test(name.slice(paths.claimTemporaryPrefix.length, -4));
394
+ return isUuid(name.slice(paths.claimTemporaryPrefix.length, -4));
394
395
  }
395
396
  /**
396
397
  * Publish the generation claim from a complete private temporary using an
@@ -415,7 +416,7 @@ async function ensureClaim(target, state) {
415
416
  if (!info || !info.isFile() || info.isSymbolicLink()) continue;
416
417
  if (!ownerMatches(await readOwner(temporary), expected)) continue;
417
418
  try {
418
- renameUpdateExclusive(temporary, paths.claim);
419
+ renameExclusive(temporary, paths.claim);
419
420
  } catch {
420
421
  return ownerMatches(await readOwner(paths.claim), expected);
421
422
  }
@@ -428,7 +429,7 @@ async function ensureClaim(target, state) {
428
429
  mode: 384
429
430
  });
430
431
  if (!ownerMatches(await readOwner(temporary), expected)) return false;
431
- renameUpdateExclusive(temporary, paths.claim);
432
+ renameExclusive(temporary, paths.claim);
432
433
  } catch {
433
434
  return ownerMatches(await readOwner(paths.claim), expected);
434
435
  }
@@ -436,7 +437,7 @@ async function ensureClaim(target, state) {
436
437
  }
437
438
  function isMatchingCleanupTemporary(name, paths) {
438
439
  if (!name.startsWith(paths.cleanupMarkerTemporaryPrefix) || !name.endsWith(".tmp")) return false;
439
- return UUID.test(name.slice(paths.cleanupMarkerTemporaryPrefix.length, -4));
440
+ return isUuid(name.slice(paths.cleanupMarkerTemporaryPrefix.length, -4));
440
441
  }
441
442
  async function ensureCleanupMarker(target, state) {
442
443
  const expected = cleanupMarkerFor(target, state);
@@ -454,7 +455,7 @@ async function ensureCleanupMarker(target, state) {
454
455
  if (!info?.isFile() || info.isSymbolicLink()) continue;
455
456
  if (!cleanupMarkerMatches(await readCleanupMarker(temporary), expected)) continue;
456
457
  try {
457
- renameUpdateExclusive(temporary, paths.cleanupMarker);
458
+ renameExclusive(temporary, paths.cleanupMarker);
458
459
  } catch {
459
460
  return cleanupMarkerMatches(await readCleanupMarker(paths.cleanupMarker), expected);
460
461
  }
@@ -467,7 +468,7 @@ async function ensureCleanupMarker(target, state) {
467
468
  mode: 384
468
469
  });
469
470
  if (!cleanupMarkerMatches(await readCleanupMarker(temporary), expected)) return false;
470
- renameUpdateExclusive(temporary, paths.cleanupMarker);
471
+ renameExclusive(temporary, paths.cleanupMarker);
471
472
  } catch {
472
473
  return cleanupMarkerMatches(await readCleanupMarker(paths.cleanupMarker), expected);
473
474
  }
@@ -490,7 +491,7 @@ async function matchesInstalledTree(path, owner) {
490
491
  }
491
492
  }
492
493
  function isMatchingHealthTemporary(name) {
493
- return name.startsWith(".healthy-") && name.endsWith(".tmp") && UUID.test(name.slice(9, -4));
494
+ return name.startsWith(".healthy-") && name.endsWith(".tmp") && isUuid(name.slice(9, -4));
494
495
  }
495
496
  async function validRetirementContainer(owner, paths, allowHealthTemporaries = true, pruneProgress) {
496
497
  const info = await pathInfo(paths.container);
@@ -519,7 +520,7 @@ function generationFromClaimName(name, target) {
519
520
  const prefix = `.${basename(target)}.framework-retired-`;
520
521
  if (!name.startsWith(prefix) || !name.endsWith(".claim.json")) return void 0;
521
522
  const generation = name.slice(prefix.length, -11);
522
- return UUID.test(generation) ? generation : void 0;
523
+ return isUuid(generation) ? generation : void 0;
523
524
  }
524
525
  /**
525
526
  * Read and validate every retirement claim and container while the install lock
@@ -552,7 +553,7 @@ async function readValidatedRetirementInventoryWhileLocked(target, currentVersio
552
553
  const progressTemporaries = names.filter((name) => name.startsWith(progressTemporaryPrefix) && name.endsWith(".tmp"));
553
554
  if (progressTemporaries.length > 0) {
554
555
  const temporaryName = options.allowedPruneProgressTemporaryName;
555
- if (progressTemporaries.length !== 1 || !temporaryName || progressTemporaries[0] !== temporaryName || !UUID.test(temporaryName.slice(progressTemporaryPrefix.length, -4))) throw new Error("An update retention progress publication requires recovery");
556
+ if (progressTemporaries.length !== 1 || !temporaryName || progressTemporaries[0] !== temporaryName || !isUuid(temporaryName.slice(progressTemporaryPrefix.length, -4))) throw new Error("An update retention progress publication requires recovery");
556
557
  pruneProgressTemporary = await readPruneProgressFile(join(dirname(target), temporaryName), target, generation, pruneIntentOnDisk, pruneProgress.owner);
557
558
  const [finalInfo, temporaryInfo] = await Promise.all([lstat(retentionPruneProgressPath(target, generation), { bigint: true }), lstat(join(dirname(target), temporaryName), { bigint: true })]);
558
559
  const sameHardLink = finalInfo.dev === temporaryInfo.dev && finalInfo.ino === temporaryInfo.ino;
@@ -565,7 +566,7 @@ async function readValidatedRetirementInventoryWhileLocked(target, currentVersio
565
566
  const temporaryName = options.allowedPruneProgressTemporaryName;
566
567
  const progressTemporaryPrefix = `${basename(retentionPruneProgressPath(target, generation))}.`;
567
568
  const progressTemporaries = names.filter((name) => name.startsWith(progressTemporaryPrefix) && name.endsWith(".tmp"));
568
- if (!temporaryName || progressTemporaries.length !== 1 || progressTemporaries[0] !== temporaryName || !UUID.test(temporaryName.slice(progressTemporaryPrefix.length, -4))) throw new Error("An update retention progress marker disappeared");
569
+ if (!temporaryName || progressTemporaries.length !== 1 || progressTemporaries[0] !== temporaryName || !isUuid(temporaryName.slice(progressTemporaryPrefix.length, -4))) throw new Error("An update retention progress marker disappeared");
569
570
  pruneIntentOnDisk = await readUpdateRetentionIntent(target, generation);
570
571
  pruneProgressTemporary = await readPruneProgressFile(join(dirname(target), temporaryName), target, generation, pruneIntentOnDisk);
571
572
  if (!pruneIntentOnDisk || !pruneProgressTemporary || pruneProgressTemporary.phase !== "deleting") throw new Error("An orphaned update retention progress temporary requires recovery");
@@ -582,7 +583,7 @@ async function readValidatedRetirementInventoryWhileLocked(target, currentVersio
582
583
  if (isPruneProgressName(name, target)) continue;
583
584
  if (name === options.allowedPruneProgressTemporaryName) continue;
584
585
  const suffix = name.slice(retirementPrefix.length);
585
- if (UUID.test(suffix)) {
586
+ if (isUuid(suffix)) {
586
587
  const containerInfo = await pathInfo(join(dirname(target), name));
587
588
  if (!containerInfo?.isDirectory() || containerInfo.isSymbolicLink()) throw new Error("An update retirement container requires recovery");
588
589
  containerGenerations.add(suffix);
@@ -595,7 +596,7 @@ async function readValidatedRetirementInventoryWhileLocked(target, currentVersio
595
596
  if (suffix.endsWith(".claim.json")) throw new Error("An update retirement claim has an invalid generation");
596
597
  const generation = suffix.slice(0, 36);
597
598
  const claimTemporaryId = suffix.startsWith(`${generation}.claim-`) && suffix.endsWith(".tmp") ? suffix.slice(generation.length + 7, -4) : "";
598
- if (UUID.test(generation) && UUID.test(claimTemporaryId)) throw new Error("An update retirement claim publication is incomplete");
599
+ if (isUuid(generation) && isUuid(claimTemporaryId)) throw new Error("An update retirement claim publication is incomplete");
599
600
  throw new Error("An unknown update retirement entry requires recovery");
600
601
  }
601
602
  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");
@@ -663,7 +664,7 @@ async function readValidatedRetirementInventoryWhileLocked(target, currentVersio
663
664
  */
664
665
  async function findPendingUpdateHealthAcknowledgement(options) {
665
666
  const { target, currentVersion } = options;
666
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target) throw new Error("Invalid update health acknowledgement lookup");
667
+ if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update health acknowledgement lookup");
667
668
  return withUpdateLock(target, async () => {
668
669
  const staging = updateStagingFor(target);
669
670
  const stagingInfo = await pathInfo(staging);
@@ -696,7 +697,7 @@ async function findPendingUpdateHealthAcknowledgement(options) {
696
697
  * require unrelated retirement history to be valid before a new stage.
697
698
  */
698
699
  async function assertNoUpdateRetentionPruneArtifactsWhileLocked(target) {
699
- if (typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target || target.includes("\0") || !basename(target)) throw new Error("Invalid update retention prune gate target");
700
+ if (!isCanonicalPath(target) || !basename(target)) throw new Error("Invalid update retention prune gate target");
700
701
  assertNoUnresolvedRetentionPruneArtifacts(target, await readdir(dirname(target)), {}, "update retention prune requires recovery before staging");
701
702
  }
702
703
  /**
@@ -706,7 +707,7 @@ async function assertNoUpdateRetentionPruneArtifactsWhileLocked(target) {
706
707
  */
707
708
  async function planValidatedUpdateRetention(options) {
708
709
  const { target, currentVersion } = options;
709
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target) throw new Error("Invalid update retention lookup");
710
+ if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
710
711
  return withUpdateLock(target, async () => (await planRetentionWhileLocked(target, currentVersion)).plan);
711
712
  }
712
713
  async function planRetentionWhileLocked(target, currentVersion, options = {}) {
@@ -768,7 +769,7 @@ async function planRetentionWhileLocked(target, currentVersion, options = {}) {
768
769
  */
769
770
  async function acquireRetainedUpdateTrees(options) {
770
771
  const { target, currentVersion } = options;
771
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target || target.includes("\0")) throw new Error("Invalid retained update tree lookup");
772
+ if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid retained update tree lookup");
772
773
  let retained;
773
774
  try {
774
775
  return await withUpdateLock(target, async () => {
@@ -916,7 +917,7 @@ async function assertIntentMatchesRetentionPlan(target, inventory, plan, intent)
916
917
  */
917
918
  async function inspectUpdateRetentionCleanup(options) {
918
919
  const { target, currentVersion, generation } = options;
919
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target) throw new Error("Invalid update retention lookup");
920
+ if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
920
921
  updateRetentionIntentPath(target, generation);
921
922
  return withUpdateLock(target, () => inspectRetentionWhileLocked(target, currentVersion, generation));
922
923
  }
@@ -936,7 +937,7 @@ async function inspectRetentionWhileLocked(target, currentVersion, generation) {
936
937
  */
937
938
  async function syncValidatedUpdateRetentionCleanup(options) {
938
939
  const { target, currentVersion, generation } = options;
939
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target) throw new Error("Invalid update retention lookup");
940
+ if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
940
941
  updateRetentionIntentPath(target, generation);
941
942
  return withUpdateLock(target, async () => {
942
943
  const intent = await inspectRetentionWhileLocked(target, currentVersion, generation);
@@ -961,7 +962,7 @@ async function syncValidatedUpdateRetentionCleanup(options) {
961
962
  */
962
963
  async function promoteOrphanUpdateRetentionCleanup(options) {
963
964
  const { target, currentVersion, generation } = options;
964
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target) throw new Error("Invalid update retention lookup");
965
+ if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
965
966
  const finalPath = updateRetentionIntentPath(target, generation);
966
967
  const readOrphan = async (expectedTemporaryName) => {
967
968
  const names = await readdir(dirname(target));
@@ -1025,7 +1026,7 @@ async function promoteOrphanUpdateRetentionCleanup(options) {
1025
1026
  */
1026
1027
  async function reconcileUpdateRetentionCleanup(options) {
1027
1028
  const { target, currentVersion, generation } = options;
1028
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target) throw new Error("Invalid update retention lookup");
1029
+ if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
1029
1030
  const markerPath = updateRetentionIntentPath(target, generation);
1030
1031
  return withUpdateLock(target, async () => {
1031
1032
  const temporaryName = retentionTemporaryName(await readdir(dirname(target)), target, generation);
@@ -1077,7 +1078,7 @@ async function reconcileUpdateRetentionCleanup(options) {
1077
1078
  */
1078
1079
  async function beginUpdateRetentionCleanup(options) {
1079
1080
  const { target, currentVersion } = options;
1080
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target) throw new Error("Invalid update retention lookup");
1081
+ if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
1081
1082
  return withUpdateLock(target, async () => {
1082
1083
  const { inventory, plan } = await planRetentionWhileLocked(target, currentVersion);
1083
1084
  if (plan.status !== "ready") throw new Error("Update retention lineage requires recovery");
@@ -1116,7 +1117,7 @@ async function beginUpdateRetentionCleanup(options) {
1116
1117
  async function pruneUpdateRetentionStep(options) {
1117
1118
  const { target, currentVersion, generation } = options;
1118
1119
  const maxOperations = options.maxOperations ?? 64;
1119
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target || !Number.isSafeInteger(maxOperations) || maxOperations < 1 || maxOperations > 4096) throw new Error("Invalid update retention prune request");
1120
+ if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target) || !Number.isSafeInteger(maxOperations) || maxOperations < 1 || maxOperations > 4096) throw new Error("Invalid update retention prune request");
1120
1121
  updateRetirementPaths(target, generation);
1121
1122
  if (process.platform !== "darwin" || process.arch !== "arm64") return { status: "recovery-required" };
1122
1123
  return withUpdateLock(target, async () => {
@@ -1289,7 +1290,7 @@ async function pruneUpdateRetentionStep(options) {
1289
1290
  });
1290
1291
  }
1291
1292
  async function acknowledgeUpdateHealthWhileLocked(target, token) {
1292
- if (typeof token !== "object" || token === null || !UUID.test(token.generation) || typeof token.version !== "string" || !VERSION.test(token.version)) return false;
1293
+ if (typeof token !== "object" || token === null || !isUuid(token.generation) || typeof token.version !== "string" || !VERSION.test(token.version)) return false;
1293
1294
  const paths = updateRetirementPaths(target, token.generation);
1294
1295
  const claimInfo = await pathInfo(paths.claim);
1295
1296
  const owner = await readOwner(paths.claim);
@@ -1303,7 +1304,7 @@ async function acknowledgeUpdateHealthWhileLocked(target, token) {
1303
1304
  if (!receipt) continue;
1304
1305
  if (!healthReceiptMatches(receipt, expected)) return false;
1305
1306
  try {
1306
- renameUpdateExclusive(temporary, paths.healthReceipt);
1307
+ renameExclusive(temporary, paths.healthReceipt);
1307
1308
  } catch {
1308
1309
  return healthReceiptMatches(await readHealthReceipt(paths.healthReceipt), expected);
1309
1310
  }
@@ -1316,7 +1317,7 @@ async function acknowledgeUpdateHealthWhileLocked(target, token) {
1316
1317
  mode: 384
1317
1318
  });
1318
1319
  if (!healthReceiptMatches(await readHealthReceipt(temporary), expected)) return false;
1319
- renameUpdateExclusive(temporary, paths.healthReceipt);
1320
+ renameExclusive(temporary, paths.healthReceipt);
1320
1321
  } catch {
1321
1322
  return healthReceiptMatches(await readHealthReceipt(paths.healthReceipt), expected);
1322
1323
  }
@@ -1461,7 +1462,7 @@ async function retireCompletedUpdateWhileLocked(options) {
1461
1462
  if (candidateInfo) {
1462
1463
  if (entries.length !== 0) return false;
1463
1464
  try {
1464
- renameUpdateExclusive(candidate, paths.tree);
1465
+ renameExclusive(candidate, paths.tree);
1465
1466
  } catch {
1466
1467
  return false;
1467
1468
  }
@@ -1,8 +1,10 @@
1
+ import { errorCode, isSha256Hex, isUuid } from "../app/value-guards.js";
2
+ import { readSmallStateFile } from "./stable-file.js";
1
3
  import { tryAcquireUpdateLock } from "./update-lock.js";
2
- import { lstat, open, readFile, rename, unlink, writeFile } from "node:fs/promises";
4
+ import { open, rename, unlink, writeFile } from "node:fs/promises";
3
5
  import { join } from "node:path";
4
- import { constants as constants$1 } from "node:fs";
5
6
  import { randomUUID } from "node:crypto";
7
+ import { constants as constants$1 } from "node:fs";
6
8
  // src/updates/update-state-store.ts
7
9
  var UpdateLockBusyError = class extends Error {
8
10
  constructor() {
@@ -38,7 +40,7 @@ function parseState(value) {
38
40
  const candidateTreeIdentity = record.candidateTreeIdentity;
39
41
  const candidateTreeDigest = record.candidateTreeDigest;
40
42
  const previousTreeIdentity = record.previousTreeIdentity;
41
- if (record.schema !== 1 || typeof record.generation !== "string" || !/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(record.generation) || ![
43
+ if (record.schema !== 1 || typeof record.generation !== "string" || !isUuid(record.generation) || ![
42
44
  "staged",
43
45
  "armed",
44
46
  "swapping",
@@ -46,7 +48,7 @@ function parseState(value) {
46
48
  "retiring",
47
49
  "retired",
48
50
  "failed"
49
- ].includes(String(record.phase)) || typeof record.version !== "string" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(record.version) || typeof record.previousVersion !== "string" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(record.previousVersion) || candidateTreeDigest !== void 0 && (typeof candidateTreeDigest !== "string" || !/^[0-9a-f]{64}$/.test(candidateTreeDigest)) || candidateTreeIdentity !== void 0 && (typeof candidateTreeIdentity !== "object" || candidateTreeIdentity === null || Array.isArray(candidateTreeIdentity) || Object.keys(candidateTreeIdentity).length !== 2 || typeof candidateTreeIdentity.device !== "string" || !/^[1-9]\d{0,19}$/.test(candidateTreeIdentity.device) || typeof candidateTreeIdentity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(candidateTreeIdentity.inode)) || previousTreeIdentity !== void 0 && (typeof previousTreeIdentity !== "object" || previousTreeIdentity === null || Array.isArray(previousTreeIdentity) || Object.keys(previousTreeIdentity).length !== 2 || typeof previousTreeIdentity.device !== "string" || !/^[1-9]\d{0,19}$/.test(previousTreeIdentity.device) || typeof previousTreeIdentity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(previousTreeIdentity.inode)) || record.signedRelease !== void 0 && (typeof record.signedRelease !== "object" || record.signedRelease === null || Array.isArray(record.signedRelease) || Object.keys(record.signedRelease).length !== 2 || !Object.hasOwn(record.signedRelease, "descriptor") || typeof record.signedRelease.signature !== "string") || record.helperPid !== void 0 && (!Number.isSafeInteger(record.helperPid) || record.helperPid < 2) || record.helperOwner !== void 0 && (typeof record.helperOwner !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(record.helperOwner)) || record.launchGateOwner !== void 0 && (typeof record.launchGateOwner !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(record.launchGateOwner)) || Object.keys(record).some((key) => ![
51
+ ].includes(String(record.phase)) || typeof record.version !== "string" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(record.version) || typeof record.previousVersion !== "string" || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(record.previousVersion) || candidateTreeDigest !== void 0 && (typeof candidateTreeDigest !== "string" || !isSha256Hex(candidateTreeDigest)) || candidateTreeIdentity !== void 0 && (typeof candidateTreeIdentity !== "object" || candidateTreeIdentity === null || Array.isArray(candidateTreeIdentity) || Object.keys(candidateTreeIdentity).length !== 2 || typeof candidateTreeIdentity.device !== "string" || !/^[1-9]\d{0,19}$/.test(candidateTreeIdentity.device) || typeof candidateTreeIdentity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(candidateTreeIdentity.inode)) || previousTreeIdentity !== void 0 && (typeof previousTreeIdentity !== "object" || previousTreeIdentity === null || Array.isArray(previousTreeIdentity) || Object.keys(previousTreeIdentity).length !== 2 || typeof previousTreeIdentity.device !== "string" || !/^[1-9]\d{0,19}$/.test(previousTreeIdentity.device) || typeof previousTreeIdentity.inode !== "string" || !/^[1-9]\d{0,19}$/.test(previousTreeIdentity.inode)) || record.signedRelease !== void 0 && (typeof record.signedRelease !== "object" || record.signedRelease === null || Array.isArray(record.signedRelease) || Object.keys(record.signedRelease).length !== 2 || !Object.hasOwn(record.signedRelease, "descriptor") || typeof record.signedRelease.signature !== "string") || record.helperPid !== void 0 && (!Number.isSafeInteger(record.helperPid) || record.helperPid < 2) || record.helperOwner !== void 0 && (typeof record.helperOwner !== "string" || !isUuid(record.helperOwner)) || record.launchGateOwner !== void 0 && (typeof record.launchGateOwner !== "string" || !isUuid(record.launchGateOwner)) || Object.keys(record).some((key) => ![
50
52
  "schema",
51
53
  "generation",
52
54
  "phase",
@@ -65,16 +67,8 @@ function parseState(value) {
65
67
  return Object.freeze(record);
66
68
  }
67
69
  async function readUpdateStageState(staging) {
68
- const path = join(staging, "state.json");
69
- let info;
70
- try {
71
- info = await lstat(path);
72
- } catch (error) {
73
- if (error.code === "ENOENT") return void 0;
74
- throw error;
75
- }
76
- if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 4096) throw new Error("Invalid update staging state");
77
- return parseState(JSON.parse(await readFile(path, "utf8")));
70
+ const text = await readSmallStateFile(join(staging, "state.json"), 4096, "Invalid update staging state");
71
+ return text === void 0 ? void 0 : parseState(JSON.parse(text));
78
72
  }
79
73
  /** Sync a journal directory after a state rename or owned-entry cleanup. */
80
74
  async function syncUpdateStageDirectory(staging) {
@@ -86,19 +80,7 @@ async function syncUpdateStageDirectory(staging) {
86
80
  }
87
81
  }
88
82
  async function writeUpdateStageState(staging, state) {
89
- if (typeof state.generation !== "string" || !/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(state.generation)) throw new Error("Invalid update staging state");
90
- const path = join(staging, "state.json");
91
- const temporary = join(staging, `.state-${state.generation}-${randomUUID()}.tmp`);
92
- await writeFile(temporary, JSON.stringify(state) + "\n", {
93
- flag: "wx",
94
- mode: 384
95
- });
96
- try {
97
- await rename(temporary, path);
98
- } catch (error) {
99
- await unlink(temporary).catch(() => {});
100
- throw error;
101
- }
83
+ await replaceUpdateStageState(staging, state, false);
102
84
  }
103
85
  /**
104
86
  * Atomically replace and sync a journal record before a schema-3 gate decision.
@@ -107,23 +89,33 @@ async function writeUpdateStageState(staging, state) {
107
89
  * proof, callers must keep the launch gate and require recovery.
108
90
  */
109
91
  async function writeUpdateStageStateDurably(staging, state) {
110
- if (typeof state.generation !== "string" || !/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(state.generation)) throw new Error("Invalid update staging state");
92
+ await replaceUpdateStageState(staging, state, true);
93
+ }
94
+ /** Write `state.json` through an exclusive temporary file and rename it into place. */
95
+ async function replaceUpdateStageState(staging, state, durable) {
96
+ if (typeof state.generation !== "string" || !isUuid(state.generation)) throw new Error("Invalid update staging state");
111
97
  const path = join(staging, "state.json");
112
98
  const temporary = join(staging, `.state-${state.generation}-${randomUUID()}.tmp`);
99
+ const contents = JSON.stringify(state) + "\n";
113
100
  let renamed = false;
114
101
  try {
115
- const file = await open(temporary, constants$1.O_WRONLY | constants$1.O_CREAT | constants$1.O_EXCL, 384);
116
- try {
117
- await file.writeFile(JSON.stringify(state) + "\n");
118
- await file.sync();
119
- } finally {
120
- await file.close();
121
- }
102
+ if (durable) {
103
+ const file = await open(temporary, constants$1.O_WRONLY | constants$1.O_CREAT | constants$1.O_EXCL, 384);
104
+ try {
105
+ await file.writeFile(contents);
106
+ await file.sync();
107
+ } finally {
108
+ await file.close();
109
+ }
110
+ } else await writeFile(temporary, contents, {
111
+ flag: "wx",
112
+ mode: 384
113
+ });
122
114
  await rename(temporary, path);
123
115
  renamed = true;
124
- await syncUpdateStageDirectory(staging);
116
+ if (durable) await syncUpdateStageDirectory(staging);
125
117
  } catch (error) {
126
- if (!renamed) await unlink(temporary).catch(() => {});
118
+ if (!renamed && errorCode(error) !== "EEXIST") await unlink(temporary).catch(() => {});
127
119
  throw error;
128
120
  }
129
121
  }
@@ -12,11 +12,16 @@ export type NativeUpdateState<Phase extends string = string> = Readonly<{
12
12
  github_url: string;
13
13
  restart_required: boolean;
14
14
  }>;
15
- /** Project a native snapshot into the shared UI update dialog contract. */
16
- export declare function toUpdateState<Phase extends string, Url extends string | null = string>(update: Omit<NativeUpdateState<Phase>, 'github_url' | 'release_notes'> & Readonly<{
15
+ /**
16
+ * A native updater snapshot: the service fields, with a release URL that may be
17
+ * absent (`Url`) and release notes that older hosts omit.
18
+ */
19
+ export type NativeUpdateSnapshotOf<Phase extends string = string, Url extends string | null = string> = Omit<NativeUpdateState<Phase>, 'github_url' | 'release_notes'> & Readonly<{
17
20
  github_url: Url;
18
21
  release_notes?: string | null;
19
- }>, options?: {
22
+ }>;
23
+ /** Project a native snapshot into the shared UI update dialog contract. */
24
+ export declare function toUpdateState<Phase extends string, Url extends string | null = string>(update: NativeUpdateSnapshotOf<Phase, Url>, options?: {
20
25
  includeReleaseNotes?: boolean;
21
26
  }): {
22
27
  phase: Phase;
@@ -1,7 +1,8 @@
1
+ import { errorCode } from "../app/value-guards.js";
2
+ import { renameExclusive } from "../native/native-rename.js";
1
3
  import { exportVerifiedRelease } from "./signed-release.js";
2
4
  import { planUpdateHandoff } from "./update-handoff-plan.js";
3
5
  import { extractVerifiedUpdate } from "./update-extraction.js";
4
- import { renameUpdateExclusive } from "./update-exclusive-rename.js";
5
6
  import { newUpdateStageState, readUpdateStageState, withUpdateLock, writeUpdateStageState } from "./update-state-store.js";
6
7
  import { readUpdateTreeDigest, readUpdateTreeIdentity, updateStagingFor } from "./update-swap.js";
7
8
  import { assertNoUpdateRetentionPruneArtifactsWhileLocked, reconcileRetirementCleanupMarkerWhileLocked } from "./update-retirement.js";
@@ -51,7 +52,7 @@ async function stageUpdateSwap(options) {
51
52
  maxExpandedBytes: options.maxExpandedBytes,
52
53
  ...options.sidecars === void 0 ? {} : { sidecars: options.sidecars }
53
54
  });
54
- renameUpdateExclusive(extracted.payload, join(preparing, "candidate"));
55
+ renameExclusive(extracted.payload, join(preparing, "candidate"));
55
56
  await rm(extracted.directory, {
56
57
  recursive: true,
57
58
  force: true
@@ -78,13 +79,13 @@ async function stageUpdateSwap(options) {
78
79
  try {
79
80
  existingInfo = await lstat(staging);
80
81
  } catch (error) {
81
- if (error.code === "ENOENT") {
82
+ if (errorCode(error) === "ENOENT") {
82
83
  if (await reconcileRetirementCleanupMarkerWhileLocked({
83
84
  target: plan.target,
84
85
  staging,
85
86
  currentVersion: plan.currentVersion
86
87
  }) === "recovery-required") throw new Error("A previous update retirement requires recovery", { cause: error });
87
- renameUpdateExclusive(preparing, staging);
88
+ renameExclusive(preparing, staging);
88
89
  published = true;
89
90
  return {
90
91
  staging,
@@ -102,7 +103,7 @@ async function stageUpdateSwap(options) {
102
103
  currentVersion: plan.currentVersion
103
104
  });
104
105
  if (retirement === "updated") {
105
- renameUpdateExclusive(preparing, staging);
106
+ renameExclusive(preparing, staging);
106
107
  published = true;
107
108
  return {
108
109
  staging,
@@ -1,4 +1,4 @@
1
- import { exchangeDirectories } from '../native/directory-exchange';
1
+ import { exchangeDirectories } from '../native/native-rename';
2
2
  export type UpdateTreeIdentity = Readonly<{
3
3
  device: string;
4
4
  inode: string;
@@ -1,13 +1,15 @@
1
- import { exchangeDirectories, probeDirectoryExchange } from "../native/directory-exchange.js";
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, isAbsolute, join, resolve } from "node:path";
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 (typeof target !== "string" || !isAbsolute(target) || resolve(target) !== target) throw new Error("Invalid update target");
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" && /^[0-9a-f]{64}$/.test(left) && left === right;
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.code === "ENOENT") return false;
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.31.0",
3
+ "version": "0.32.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=${ADEA_TEST_TIMEOUT_MS:-5000} tests/*/*.test.ts && bun run test:ui",
364
- "test:ui": "bun test --isolate --timeout=${ADEA_TEST_TIMEOUT_MS:-5000} --conditions=browser --preload @adea-ai/ui/testing/solid-transform tests/*/*.test.tsx",
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.12",
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",