@adea-ai/app-framework 0.39.3 → 0.39.4

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 (199) hide show
  1. package/README.md +158 -52
  2. package/dist/app/application.d.ts +0 -1
  3. package/dist/app/application.js +8 -6
  4. package/dist/app/create-application.js +3 -11
  5. package/dist/app/service-registry.d.ts +0 -1
  6. package/dist/app/service-registry.js +3 -3
  7. package/dist/app/value-guards.d.ts +2 -0
  8. package/dist/app/value-guards.js +6 -1
  9. package/dist/appearance/appearance-host.d.ts +1 -1
  10. package/dist/appearance/appearance-host.js +11 -2
  11. package/dist/appearance/appearance-preferences.d.ts +0 -1
  12. package/dist/appearance/custom-theme-import.d.ts +8 -2
  13. package/dist/appearance/custom-theme-import.js +58 -23
  14. package/dist/appearance/custom-theme-library.d.ts +3 -3
  15. package/dist/appearance/custom-theme-library.js +3 -3
  16. package/dist/appearance/theme-file-importer.d.ts +1 -1
  17. package/dist/appearance/theme-file-importer.js +2 -1
  18. package/dist/appearance/theme-library-mutation.d.ts +7 -0
  19. package/dist/appearance/theme-library-mutation.js +10 -2
  20. package/dist/appearance/theme-library-store.d.ts +17 -13
  21. package/dist/appearance/theme-library-store.js +35 -22
  22. package/dist/appearance/theme-record-adapter.js +1 -2
  23. package/dist/appearance/theme-registry.js +0 -1
  24. package/dist/cli/cli-runner.d.ts +3 -2
  25. package/dist/cli/cli-runner.js +5 -10
  26. package/dist/cli/release-assets-plan-cli.js +2 -2
  27. package/dist/cli/release-cut-cli.js +2 -3
  28. package/dist/cli/release-descriptor-staging-cli.js +2 -2
  29. package/dist/cli/release-finalize-cli.js +3 -3
  30. package/dist/cli/release-promote-cli.js +2 -2
  31. package/dist/cli/release-publish-cli.js +2 -2
  32. package/dist/cli/release-sign-cli.js +2 -1
  33. package/dist/cli/release-step-cli.js +2 -2
  34. package/dist/desktop/channel-proof.js +27 -11
  35. package/dist/desktop/client-assets.d.ts +6 -1
  36. package/dist/desktop/client-assets.js +16 -3
  37. package/dist/desktop/client-dev-proxy.d.ts +0 -2
  38. package/dist/desktop/client-dev-proxy.js +2 -2
  39. package/dist/desktop/desktop-client.js +2 -1
  40. package/dist/desktop/desktop-gateway.js +24 -82
  41. package/dist/desktop/desktop-host-websocket.d.ts +5 -1
  42. package/dist/desktop/desktop-host-websocket.js +9 -7
  43. package/dist/desktop/desktop-host.d.ts +5 -0
  44. package/dist/desktop/desktop-host.js +3 -0
  45. package/dist/desktop/desktop-stream.js +5 -10
  46. package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
  47. package/dist/desktop/typed-array-intrinsics.js +13 -1
  48. package/dist/developer-app/developer-app.d.ts +1 -1
  49. package/dist/developer-app/developer-app.js +26 -13
  50. package/dist/framework-source.json +1 -1
  51. package/dist/installer/command-artifact.d.ts +1 -0
  52. package/dist/installer/command-artifact.js +47 -27
  53. package/dist/installer/installed-payload.js +3 -1
  54. package/dist/installer/installer-ci-bootstrap.js +5 -6
  55. package/dist/installer/installer-ci-preflight.js +3 -3
  56. package/dist/installer/installer-identity.d.ts +0 -22
  57. package/dist/installer/installer-identity.js +3 -53
  58. package/dist/installer/installer-image-mount.d.ts +0 -1
  59. package/dist/installer/installer-image-mount.js +1 -1
  60. package/dist/installer/installer-observation.d.ts +5 -5
  61. package/dist/installer/installer-observation.js +32 -47
  62. package/dist/installer/installer-process-cleanup.js +2 -2
  63. package/dist/installer/installer-renderer-evidence.js +7 -28
  64. package/dist/installer/installer-upgrade-command.js +8 -20
  65. package/dist/installer/installer-worker-guard.js +3 -3
  66. package/dist/native/cef-helper.js +4 -4
  67. package/dist/native/desktop-build.d.ts +0 -3
  68. package/dist/native/desktop-build.js +2 -2
  69. package/dist/native/electrobun-source-patch.d.ts +4 -0
  70. package/dist/native/electrobun-source-patch.js +5 -1
  71. package/dist/native/native-utilities.js +4 -3
  72. package/dist/native/pinned-download.d.ts +16 -0
  73. package/dist/native/pinned-download.js +42 -0
  74. package/dist/native/posix-launcher-build.js +15 -35
  75. package/dist/native/posix-tree-removal.js +21 -33
  76. package/dist/native/sidecar-services.d.ts +0 -2
  77. package/dist/native/sidecar-services.js +1 -1
  78. package/dist/native/sidecar.d.ts +3 -0
  79. package/dist/native/sidecar.js +15 -2
  80. package/dist/native/window-surface-store.js +3 -3
  81. package/dist/native/windows-extractor-build.d.ts +6 -16
  82. package/dist/native/windows-extractor-build.js +11 -14
  83. package/dist/release/feed-release-cut.d.ts +2 -6
  84. package/dist/release/feed-release-cut.js +5 -93
  85. package/dist/release/feed-state.js +1 -5
  86. package/dist/release/github-release-cut.js +5 -66
  87. package/dist/release/github-release-provenance.d.ts +2 -0
  88. package/dist/release/github-release-provenance.js +4 -7
  89. package/dist/release/github-release-publisher.js +2 -2
  90. package/dist/release/github-release-qualification.js +3 -3
  91. package/dist/release/local-release.d.ts +3 -3
  92. package/dist/release/local-release.js +12 -23
  93. package/dist/release/qualification-run.js +1 -1
  94. package/dist/release/release-assets-plan.js +1 -1
  95. package/dist/release/release-config.d.ts +7 -15
  96. package/dist/release/release-config.js +25 -29
  97. package/dist/release/release-cut-command.d.ts +1 -1
  98. package/dist/release/release-cut-command.js +1 -1
  99. package/dist/release/release-cut.d.ts +5 -32
  100. package/dist/release/release-cut.js +9 -55
  101. package/dist/release/release-descriptor-staging.js +3 -8
  102. package/dist/release/release-promotion.js +2 -1
  103. package/dist/release/release-publish-command.js +5 -15
  104. package/dist/release/release-qualification.js +1 -1
  105. package/dist/shared/bounded-body.d.ts +33 -0
  106. package/dist/shared/bounded-body.js +102 -0
  107. package/dist/shared/file-system.d.ts +12 -0
  108. package/dist/shared/file-system.js +40 -0
  109. package/dist/shell/app-shell.js +29 -14
  110. package/dist/shell/app-utilities.d.ts +2 -1
  111. package/dist/shell/app-utilities.js +2 -1
  112. package/dist/shell/application-menu.d.ts +1 -1
  113. package/dist/shell/application-menu.js +7 -3
  114. package/dist/shell/poll.d.ts +27 -0
  115. package/dist/shell/poll.js +88 -0
  116. package/dist/update-helper.bundle.js +268 -144
  117. package/dist/updates/channel-update-manager.js +0 -1
  118. package/dist/updates/desktop-updater.d.ts +9 -0
  119. package/dist/updates/desktop-updater.js +103 -50
  120. package/dist/updates/feed/release-feed.d.ts +7 -4
  121. package/dist/updates/feed/release-feed.js +3 -7
  122. package/dist/updates/feed/release-location.js +6 -26
  123. package/dist/updates/feed/release-version.d.ts +7 -2
  124. package/dist/updates/feed/release-version.js +9 -2
  125. package/dist/updates/feed/signed-release.d.ts +1 -1
  126. package/dist/updates/feed/signed-release.js +2 -2
  127. package/dist/updates/feed/update-discovery.js +2 -6
  128. package/dist/updates/helper/launch-gate-recovery.js +28 -78
  129. package/dist/updates/helper/resume-staging.d.ts +14 -3
  130. package/dist/updates/helper/resume-staging.js +23 -37
  131. package/dist/updates/helper/update-helper.d.ts +6 -2
  132. package/dist/updates/helper/update-helper.js +38 -33
  133. package/dist/updates/helper/update-resume.js +9 -6
  134. package/dist/updates/install/update-extraction.js +28 -8
  135. package/dist/updates/install/update-handoff-plan.d.ts +0 -1
  136. package/dist/updates/install/update-handoff-plan.js +3 -4
  137. package/dist/updates/install/update-swap-stage.js +1 -6
  138. package/dist/updates/install/update-swap.d.ts +5 -2
  139. package/dist/updates/install/update-swap.js +193 -72
  140. package/dist/updates/launch/helper-exit-wait.d.ts +6 -0
  141. package/dist/updates/launch/helper-exit-wait.js +18 -0
  142. package/dist/updates/launch/packaged-update-startup.js +8 -6
  143. package/dist/updates/launch/update-launch-gate.js +7 -14
  144. package/dist/updates/locks/stable-file.js +4 -1
  145. package/dist/updates/locks/update-helper-presence.d.ts +12 -0
  146. package/dist/updates/locks/update-helper-presence.js +27 -0
  147. package/dist/updates/retention/retention-cleanup.js +10 -9
  148. package/dist/updates/retention/retention-maintenance.d.ts +40 -0
  149. package/dist/updates/retention/retention-maintenance.js +95 -0
  150. package/dist/updates/retention/retention-prune-progress.js +4 -5
  151. package/dist/updates/retention/retirement-inventory.d.ts +13 -0
  152. package/dist/updates/retention/retirement-inventory.js +39 -31
  153. package/dist/updates/retention/retirement-records.d.ts +1 -4
  154. package/dist/updates/retention/retirement-records.js +18 -32
  155. package/dist/updates/retention/update-retention-marker.d.ts +4 -0
  156. package/dist/updates/retention/update-retention-marker.js +9 -14
  157. package/dist/updates/retention/update-retirement.d.ts +12 -0
  158. package/dist/updates/retention/update-retirement.js +59 -31
  159. package/dist/updates/update-adapter.d.ts +1 -23
  160. package/dist/updates/update-adapter.js +31 -24
  161. package/dist/updates/update-channel-store.d.ts +2 -1
  162. package/dist/updates/update-channel-store.js +6 -4
  163. package/dist/updates/update-manager.js +2 -2
  164. package/dist/updates/update-services.d.ts +1 -1
  165. package/dist/updates/update-services.js +9 -4
  166. package/dist/updates/update-state-store.d.ts +0 -2
  167. package/dist/updates/update-state-store.js +5 -12
  168. package/dist/updates/update-state.d.ts +6 -10
  169. package/dist/updates/update-state.js +1 -1
  170. package/dist/views/app-help.d.ts +1 -1
  171. package/dist/views/app-help.js +1 -3
  172. package/dist/views/appearance-surface.js +15 -8
  173. package/dist/views/update-surface.d.ts +1 -3
  174. package/dist/views/update-surface.js +2 -2
  175. package/package.json +18 -16
  176. package/src/app/application.tsx +13 -6
  177. package/src/appearance/appearance-host.tsx +17 -7
  178. package/src/appearance/appearance-preferences.ts +0 -1
  179. package/src/appearance/custom-theme-import.ts +99 -26
  180. package/src/appearance/custom-theme-library.ts +3 -2
  181. package/src/appearance/theme-file-importer.ts +3 -2
  182. package/src/appearance/theme-library-mutation.ts +20 -8
  183. package/src/appearance/theme-library-schema.ts +7 -0
  184. package/src/appearance/theme-library-store.ts +41 -26
  185. package/src/desktop/client-assets.ts +27 -12
  186. package/src/shell/app-shell.tsx +33 -13
  187. package/src/shell/app-utilities.tsx +7 -1
  188. package/src/shell/poll.ts +125 -0
  189. package/src/updates/feed/release-version.ts +11 -3
  190. package/src/updates/update-adapter.ts +27 -44
  191. package/src/updates/update-state.ts +7 -13
  192. package/src/views/app-help.tsx +1 -1
  193. package/src/views/appearance-surface.tsx +36 -8
  194. package/src/views/update-surface.tsx +0 -4
  195. package/templates/application/.github/workflows/release-assets.yml +2 -2
  196. package/templates/application/README.md +3 -3
  197. package/dist/native/cef-helper-download.d.ts +0 -1
  198. package/dist/native/cef-helper-download.js +0 -35
  199. package/src/desktop/client-response-lifecycle.ts +0 -305
@@ -1,7 +1,8 @@
1
- import { errorCode, isSha256Hex } from "../../app/value-guards.js";
1
+ import { isSha256Hex } from "../../app/value-guards.js";
2
2
  import { exchangeDirectories, probeDirectoryExchange } from "../../native/native-rename.js";
3
3
  import { withUpdateLock } from "../update-state-store.js";
4
4
  import { isCanonicalPath } from "../../native/canonical-path.js";
5
+ import { pathExists, syncDirectory } from "../../shared/file-system.js";
5
6
  import { lstat, open, readFile, readdir, readlink } from "node:fs/promises";
6
7
  import { basename, dirname, join } from "node:path";
7
8
  import { createHash } from "node:crypto";
@@ -41,6 +42,37 @@ function sameUpdateTreeIdentity(left, right) {
41
42
  function sameTreeEntrySnapshot(left, right) {
42
43
  return left.dev === right.dev && left.ino === right.ino && left.mode === right.mode && left.nlink === right.nlink && left.size === right.size && left.mtimeNs === right.mtimeNs && left.ctimeNs === right.ctimeNs;
43
44
  }
45
+ var TREE_DIGEST_CONCURRENCY = 16;
46
+ var TREE_DIGEST_PREFETCH_BYTES = 262144;
47
+ var TREE_DIGEST_STREAM_BYTES = 1048576;
48
+ /** Run at most `limit` tasks at once, handing each freed slot to the oldest waiter. */
49
+ function createTaskLimiter(limit) {
50
+ let active = 0;
51
+ const waiting = [];
52
+ let head = 0;
53
+ return async (task) => {
54
+ if (active < limit) active++;
55
+ else await new Promise((resolve) => waiting.push(resolve));
56
+ try {
57
+ return await task();
58
+ } finally {
59
+ if (head < waiting.length) waiting[head++]();
60
+ else {
61
+ active--;
62
+ waiting.length = head = 0;
63
+ }
64
+ }
65
+ };
66
+ }
67
+ /** Read exactly `length` bytes from `position`, or fail if the file ended early. */
68
+ async function readTreeFileBytes(file, buffer, length, position) {
69
+ let offset = 0;
70
+ while (offset < length) {
71
+ const { bytesRead } = await file.read(buffer, offset, length - offset, position + offset);
72
+ if (bytesRead === 0) throw new Error("Update tree changed while reading a file");
73
+ offset += bytesRead;
74
+ }
75
+ }
44
76
  /**
45
77
  * Compute a deterministic integrity digest for a complete extracted app tree.
46
78
  * The manifest binds relative names, entry types, permission/special mode bits,
@@ -52,6 +84,9 @@ function sameTreeEntrySnapshot(left, right) {
52
84
  * host provides it, and compare lstat/fstat metadata before and after reads.
53
85
  * This detects ordinary concurrent changes by cooperating updater processes;
54
86
  * it is not an atomic filesystem snapshot against a hostile same-user writer.
87
+ * The walk lists the whole tree first, then reads entries with bounded
88
+ * concurrency while the hash consumes them strictly in manifest order. Each
89
+ * directory is re-checked after every entry has been read.
55
90
  *
56
91
  * Candidate proofs refuse regular files with more than one hard link, because
57
92
  * an alias outside the private staging tree could change bytes after the proof.
@@ -66,6 +101,7 @@ async function readUpdateTreeDigest(tree, options = {}) {
66
101
  const root = await lstat(tree, { bigint: true });
67
102
  if (!root.isDirectory() || root.isSymbolicLink()) throw new Error("Update tree is not a real directory");
68
103
  const rootDevice = root.dev;
104
+ const limit = createTaskLimiter(TREE_DIGEST_CONCURRENCY);
69
105
  let entryCount = 0n;
70
106
  const writeRecord = (kind, relative, mode, size, linkTarget) => {
71
107
  const name = Buffer.from(relative, "utf8");
@@ -84,52 +120,142 @@ async function readUpdateTreeDigest(tree, options = {}) {
84
120
  }
85
121
  entryCount++;
86
122
  };
87
- const visit = async (path, relative) => {
88
- const before = await lstat(path, { bigint: true });
89
- if (relative === "" && !sameTreeEntrySnapshot(root, before)) throw new Error("Update tree root changed before its digest was computed");
123
+ const list = async (path, relative, before) => {
90
124
  if (before.dev !== rootDevice) throw new Error("Update tree crosses a filesystem device");
91
- if (before.isSymbolicLink()) {
92
- const target = Buffer.from(await readlink(path), "utf8");
93
- if (!sameTreeEntrySnapshot(before, await lstat(path, { bigint: true }))) throw new Error("Update tree changed while reading a symbolic link");
94
- writeRecord("symlink", relative, before.mode, BigInt(target.length), target);
95
- return;
96
- }
125
+ if (before.isSymbolicLink()) return [{
126
+ kind: "symlink",
127
+ path,
128
+ relative,
129
+ before
130
+ }];
97
131
  if (before.isDirectory()) {
98
- writeRecord("directory", relative, before.mode, 0n);
99
- const names = (await readdir(path)).map((name) => ({
132
+ const names = (await limit(() => readdir(path))).map((name) => ({
100
133
  name,
101
134
  bytes: Buffer.from(name, "utf8")
102
135
  })).toSorted((left, right) => Buffer.compare(left.bytes, right.bytes)).map(({ name }) => name);
103
- for (const name of names) {
104
- const child = relative ? `${relative}/${name}` : name;
105
- await visit(join(path, name), child);
106
- }
107
- if (!sameTreeEntrySnapshot(before, await lstat(path, { bigint: true }))) throw new Error("Update tree changed while reading a directory");
108
- return;
136
+ const children = await Promise.all(names.map(async (name) => {
137
+ const childPath = join(path, name);
138
+ return list(childPath, relative ? `${relative}/${name}` : name, await limit(() => lstat(childPath, { bigint: true })));
139
+ }));
140
+ return [{
141
+ kind: "directory",
142
+ path,
143
+ relative,
144
+ before
145
+ }, ...children.flat()];
146
+ }
147
+ if (!before.isFile() || before.nlink < 1n || !allowHardLinkedFiles && before.nlink !== 1n || before.size < 0n || before.size > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error("Update tree contains an unsupported filesystem entry");
148
+ return [{
149
+ kind: "file",
150
+ path,
151
+ relative,
152
+ before
153
+ }];
154
+ };
155
+ const prepare = async (entry) => {
156
+ const { path, before } = entry;
157
+ if (entry.kind === "directory") return { kind: "none" };
158
+ if (entry.kind === "symlink") {
159
+ const target = Buffer.from(await readlink(path), "utf8");
160
+ if (!sameTreeEntrySnapshot(before, await lstat(path, { bigint: true }))) throw new Error("Update tree changed while reading a symbolic link");
161
+ return {
162
+ kind: "bytes",
163
+ bytes: target
164
+ };
109
165
  }
110
- if (!before.isFile() || before.nlink < 1n || !allowHardLinkedFiles && before.nlink !== 1n || before.size < 0n) throw new Error("Update tree contains an unsupported filesystem entry");
111
- writeRecord("file", relative, before.mode, before.size);
112
166
  const noFollow = constants$1.O_NOFOLLOW ?? 0;
113
167
  const file = await open(path, constants$1.O_RDONLY | noFollow | (constants$1.O_NONBLOCK ?? 0));
168
+ let handedOff = false;
114
169
  try {
115
170
  const opened = await file.stat({ bigint: true });
116
171
  if (!opened.isFile() || !sameTreeEntrySnapshot(before, opened)) throw new Error("Update tree changed before a file could be read");
117
- let bytesRead = 0n;
118
- const buffer = Buffer.allocUnsafe(131072);
119
- for (;;) {
120
- const result = await file.read(buffer, 0, buffer.length, null);
121
- if (result.bytesRead === 0) break;
122
- bytesRead += BigInt(result.bytesRead);
123
- hash.update(buffer.subarray(0, result.bytesRead));
172
+ if (before.size > BigInt(TREE_DIGEST_PREFETCH_BYTES)) {
173
+ handedOff = true;
174
+ return {
175
+ kind: "stream",
176
+ file
177
+ };
124
178
  }
125
- const afterOpen = await file.stat({ bigint: true });
126
- const afterPath = await lstat(path, { bigint: true });
127
- if (bytesRead !== before.size || !sameTreeEntrySnapshot(opened, afterOpen) || !sameTreeEntrySnapshot(before, afterPath)) throw new Error("Update tree changed while reading a file");
179
+ const size = Number(before.size);
180
+ const bytes = Buffer.allocUnsafe(size);
181
+ await readTreeFileBytes(file, bytes, size, 0);
182
+ if (!sameTreeEntrySnapshot(before, await lstat(path, { bigint: true }))) throw new Error("Update tree changed while reading a file");
183
+ return {
184
+ kind: "bytes",
185
+ bytes
186
+ };
128
187
  } finally {
129
- await file.close();
188
+ if (!handedOff) await file.close();
130
189
  }
131
190
  };
132
- await visit(tree, "");
191
+ const entries = await list(tree, "", root);
192
+ const pending = [];
193
+ let streamBuffers;
194
+ let started = 0;
195
+ let consumed = 0;
196
+ try {
197
+ for (; consumed < entries.length; consumed++) {
198
+ while (started < entries.length && started < consumed + TREE_DIGEST_CONCURRENCY) {
199
+ const next = prepare(entries[started]);
200
+ next.catch(() => void 0);
201
+ pending[started++] = next;
202
+ }
203
+ const entry = entries[consumed];
204
+ const prepared = await pending[consumed];
205
+ pending[consumed] = void 0;
206
+ if (entry.kind === "directory") {
207
+ writeRecord("directory", entry.relative, entry.before.mode, 0n);
208
+ continue;
209
+ }
210
+ if (entry.kind === "symlink") {
211
+ if (prepared.kind !== "bytes") throw new Error("Update tree entry was not prepared");
212
+ const target = prepared.bytes;
213
+ writeRecord("symlink", entry.relative, entry.before.mode, BigInt(target.length), target);
214
+ continue;
215
+ }
216
+ writeRecord("file", entry.relative, entry.before.mode, entry.before.size);
217
+ if (prepared.kind === "bytes") {
218
+ hash.update(prepared.bytes);
219
+ continue;
220
+ }
221
+ if (prepared.kind !== "stream") throw new Error("Update tree entry was not prepared");
222
+ const { file } = prepared;
223
+ try {
224
+ streamBuffers ??= [Buffer.allocUnsafe(TREE_DIGEST_STREAM_BYTES), Buffer.allocUnsafe(TREE_DIGEST_STREAM_BYTES)];
225
+ const buffers = streamBuffers;
226
+ const size = Number(entry.before.size);
227
+ const readChunk = async (index, position) => {
228
+ const length = Math.min(TREE_DIGEST_STREAM_BYTES, size - position);
229
+ await readTreeFileBytes(file, buffers[index], length, position);
230
+ return length;
231
+ };
232
+ let position = 0;
233
+ let index = 0;
234
+ let reading = readChunk(index, position);
235
+ while (position < size) {
236
+ const length = await reading;
237
+ const nextPosition = position + length;
238
+ const nextIndex = index === 0 ? 1 : 0;
239
+ if (nextPosition < size) reading = readChunk(nextIndex, nextPosition);
240
+ hash.update(buffers[index].subarray(0, length));
241
+ position = nextPosition;
242
+ index = nextIndex;
243
+ }
244
+ if (!sameTreeEntrySnapshot(entry.before, await lstat(entry.path, { bigint: true }))) throw new Error("Update tree changed while reading a file");
245
+ } finally {
246
+ await file.close();
247
+ }
248
+ }
249
+ } catch (error) {
250
+ const unconsumed = await Promise.allSettled(pending.slice(consumed + 1).filter((entry) => entry !== void 0));
251
+ await Promise.all(unconsumed.map((result) => result.status === "fulfilled" && result.value.kind === "stream" ? result.value.file.close().catch(() => void 0) : void 0));
252
+ throw error;
253
+ }
254
+ await Promise.all(entries.map(async (entry) => {
255
+ if (entry.kind !== "directory" || entry.relative === "") return;
256
+ const after = await limit(() => lstat(entry.path, { bigint: true }));
257
+ if (!sameTreeEntrySnapshot(entry.before, after)) throw new Error("Update tree changed while reading a directory");
258
+ }));
133
259
  if (!sameTreeEntrySnapshot(root, await lstat(tree, { bigint: true }))) throw new Error("Update tree changed while its digest was computed");
134
260
  const count = Buffer.allocUnsafe(8);
135
261
  count.writeBigUInt64BE(entryCount);
@@ -143,57 +269,51 @@ function readInstalledUpdateTreeDigest(tree) {
143
269
  function sameUpdateTreeDigest(left, right) {
144
270
  return typeof left === "string" && typeof right === "string" && isSha256Hex(left) && left === right;
145
271
  }
146
- /** Sync a directory's entries to disk. */
147
- async function syncDirectoryPath(path) {
148
- const directory = await open(path, constants$1.O_RDONLY);
149
- try {
150
- await directory.sync();
151
- } finally {
152
- await directory.close();
153
- }
154
- }
272
+ var TREE_SYNC_CONCURRENCY = 16;
155
273
  /** Sync candidate file contents and directory entries before a gated schema-3 exchange. */
156
274
  async function syncUpdateTree(tree) {
157
275
  const root = await lstat(tree);
158
276
  if (!root.isDirectory()) throw new Error("Update tree changed while syncing");
159
277
  const rootDevice = root.dev;
278
+ const limit = createTaskLimiter(TREE_SYNC_CONCURRENCY);
279
+ let failure;
280
+ const run = (task) => limit(() => failure ? Promise.reject(failure.error) : task());
160
281
  const syncEntry = async (path) => {
161
- const info = await lstat(path);
162
- if (info.isSymbolicLink()) return;
163
- if (info.dev !== rootDevice) throw new Error("Update tree crosses a filesystem device");
164
- if (info.isDirectory()) {
165
- for (const name of await readdir(path)) await syncEntry(join(path, name));
166
- await syncDirectoryPath(path);
167
- return;
168
- }
169
- if (!info.isFile()) throw new Error("Update tree contains an unsupported filesystem entry");
170
- const file = await open(path, constants$1.O_RDONLY | (constants$1.O_NOFOLLOW ?? 0));
171
282
  try {
172
- if (!(await file.stat()).isFile()) throw new Error("Update tree changed while syncing");
173
- await file.sync();
174
- } finally {
175
- await file.close();
283
+ const info = await run(() => lstat(path));
284
+ if (info.isSymbolicLink()) return;
285
+ if (info.dev !== rootDevice) throw new Error("Update tree crosses a filesystem device");
286
+ if (info.isDirectory()) {
287
+ const names = await run(() => readdir(path));
288
+ const children = await Promise.allSettled(names.map((name) => syncEntry(join(path, name))));
289
+ for (const child of children) if (child.status === "rejected") throw child.reason;
290
+ await run(() => syncDirectory(path));
291
+ return;
292
+ }
293
+ if (!info.isFile()) throw new Error("Update tree contains an unsupported filesystem entry");
294
+ await run(async () => {
295
+ const file = await open(path, constants$1.O_RDONLY | (constants$1.O_NOFOLLOW ?? 0));
296
+ try {
297
+ if (!(await file.stat()).isFile()) throw new Error("Update tree changed while syncing");
298
+ await file.sync();
299
+ } finally {
300
+ await file.close();
301
+ }
302
+ });
303
+ } catch (error) {
304
+ failure ??= { error };
305
+ throw error;
176
306
  }
177
307
  };
178
- await syncEntry(tree);
308
+ await syncEntry(tree).catch(() => {
309
+ throw failure.error;
310
+ });
179
311
  const final = await lstat(tree);
180
312
  if (!final.isDirectory() || final.dev !== rootDevice) throw new Error("Update tree changed while syncing");
181
313
  }
182
314
  /** Sync parent directory entries after the atomic exchange has completed. */
183
- async function syncUpdateTreeParent(target) {
184
- const directory = await open(dirname(target), constants$1.O_RDONLY);
185
- try {
186
- await directory.sync();
187
- } finally {
188
- await directory.close();
189
- }
190
- }
191
- /** Whether a path exists, without following a final symbolic link. */
192
- async function exists(path) {
193
- return lstat(path).then(() => true, (error) => {
194
- if (errorCode(error) === "ENOENT") return false;
195
- throw error;
196
- });
315
+ function syncUpdateTreeParent(target) {
316
+ return syncDirectory(dirname(target));
197
317
  }
198
318
  async function assertDirectory(path) {
199
319
  const info = await lstat(path);
@@ -211,7 +331,8 @@ async function swapUpdateTreeWhileLocked(options, exchangeOperation = exchangeDi
211
331
  const { target, staging } = options;
212
332
  if (dirname(staging) !== dirname(target) || staging === target) throw new Error("Invalid update swap context");
213
333
  const candidate = join(staging, "candidate");
214
- if (await exists(join(staging, "old"))) throw new Error("A legacy update tree requires recovery before another swap");
334
+ const legacyOld = join(staging, "old");
335
+ if (await pathExists(legacyOld)) throw new Error("A legacy update tree requires recovery before another swap");
215
336
  await assertDirectory(target);
216
337
  await assertDirectory(staging);
217
338
  await assertDirectory(candidate);
@@ -234,4 +355,4 @@ async function swapUpdateTreeWhileLocked(options, exchangeOperation = exchangeDi
234
355
  ]);
235
356
  if (nextTargetVersion !== candidateVersion || nextCandidateVersion !== previousVersion || !sameUpdateTreeIdentity(nextTargetId, candidateIdentity) || !sameUpdateTreeIdentity(nextCandidateId, previousIdentity)) throw new Error("Atomic update exchange did not preserve both app trees");
236
357
  }
237
- export { exists, readInstalledUpdateTreeDigest, readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, swapUpdateTree, swapUpdateTreeWhileLocked, syncUpdateTree, syncUpdateTreeParent, updateStagingFor, updateTreeIdentityFromStat };
358
+ export { createTaskLimiter, readInstalledUpdateTreeDigest, readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, swapUpdateTree, swapUpdateTreeWhileLocked, syncUpdateTree, syncUpdateTreeParent, updateStagingFor, updateTreeIdentityFromStat };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The update helper relaunches the app and then exits, so the new process can start while
3
+ * the helper still holds its locks for a moment. Retry a resume that reports the helper as
4
+ * active for a bounded time instead of pausing the launch on that race.
5
+ */
6
+ export declare function whileUpdateHelperExits<T>(attempt: () => Promise<T>, helperActive: (result: T) => boolean, waitMs?: number): Promise<T>;
@@ -0,0 +1,18 @@
1
+ // src/updates/launch/helper-exit-wait.ts
2
+ /** How long a launch waits for the helper that relaunched it to finish exiting. */
3
+ var UPDATE_HELPER_EXIT_WAIT_MS = 5e3;
4
+ /**
5
+ * The update helper relaunches the app and then exits, so the new process can start while
6
+ * the helper still holds its locks for a moment. Retry a resume that reports the helper as
7
+ * active for a bounded time instead of pausing the launch on that race.
8
+ */
9
+ async function whileUpdateHelperExits(attempt, helperActive, waitMs = UPDATE_HELPER_EXIT_WAIT_MS) {
10
+ const deadline = performance.now() + waitMs;
11
+ for (;;) {
12
+ const result = await attempt();
13
+ const remaining = deadline - performance.now();
14
+ if (!helperActive(result) || remaining <= 0) return result;
15
+ await Bun.sleep(Math.min(50, remaining));
16
+ }
17
+ }
18
+ export { whileUpdateHelperExits };
@@ -1,11 +1,12 @@
1
+ import { whileUpdateHelperExits } from "./helper-exit-wait.js";
1
2
  import { updateTrust } from "../desktop-updater.js";
2
3
  import { readUpdateLaunchGate } from "./update-launch-gate.js";
3
4
  import { recoverUpdateLaunchGate } from "../helper/launch-gate-recovery.js";
4
5
  import { resumeUpdate } from "../helper/update-resume.js";
5
6
  import { feedUrl } from "../feed/release-feed.js";
6
- import { createUpdateChannelStore, releaseChannelForUpdate } from "../update-channel-store.js";
7
7
  import { installTarget, updatePlatform } from "../install-target.js";
8
8
  import { resumeAndAcquireRetainedDesktopClientAssets } from "../retained-client-assets.js";
9
+ import { createUpdateChannelStore, releaseChannelForUpdate } from "../update-channel-store.js";
9
10
  import { readPackagedVersion } from "../../native/app-bundle.js";
10
11
  import { readPackagedReleaseConfig } from "../feed/packaged-release-config.js";
11
12
  import { realpath } from "node:fs/promises";
@@ -14,7 +15,7 @@ async function preparePackagedUpdateStartup(options) {
14
15
  if (options.admission === "unmanaged") return prepareUnmanagedUpdateStartup(options);
15
16
  const { release, trust, savedChannel, channel } = await packagedReleaseTrust(options);
16
17
  const { version: currentVersion } = readPackagedVersion(options.entryDirectory);
17
- const resumed = await resumeAndAcquireRetainedDesktopClientAssets({
18
+ const resumed = await whileUpdateHelperExits(() => resumeAndAcquireRetainedDesktopClientAssets({
18
19
  entryDirectory: options.entryDirectory,
19
20
  currentVersion,
20
21
  trust: {
@@ -22,7 +23,7 @@ async function preparePackagedUpdateStartup(options) {
22
23
  channel
23
24
  },
24
25
  loadManifest: options.loadManifest
25
- });
26
+ }), (result) => result.status === "in-progress" || result.status === "busy");
26
27
  if (resumed.status !== "ready") throw new Error(`Packaged update recovery is ${resumed.status}; startup is paused`);
27
28
  return {
28
29
  status: "ready",
@@ -39,19 +40,20 @@ async function prepareUnmanagedUpdateStartup(options) {
39
40
  try {
40
41
  const { release, platform, trust, savedChannel, channel } = await packagedReleaseTrust(options);
41
42
  const { version: currentVersion } = readPackagedVersion(options.entryDirectory);
43
+ const target = await realpath(installTarget(options.entryDirectory, platform));
42
44
  return {
43
45
  status: "ready",
44
46
  release,
45
47
  currentVersion,
46
48
  savedChannel,
47
- resume: await resumeUpdate({
48
- target: await realpath(installTarget(options.entryDirectory, platform)),
49
+ resume: await whileUpdateHelperExits(() => resumeUpdate({
50
+ target,
49
51
  trust: {
50
52
  ...trust,
51
53
  channel
52
54
  },
53
55
  currentVersion
54
- }),
56
+ }), (result) => result.status === "in-progress"),
55
57
  retainedClientAssets: [],
56
58
  releaseLease: releaseNothing
57
59
  };
@@ -6,6 +6,8 @@ import { acquireUpdateLock } from "../update-state-store.js";
6
6
  import { publishExclusiveUpdateMarker, readUpdateMarker } from "../install/update-marker.js";
7
7
  import { isCanonicalPath } from "../../native/canonical-path.js";
8
8
  import { readSmallStateFile } from "../locks/stable-file.js";
9
+ import { syncUpdateTreeParent } from "../install/update-swap.js";
10
+ import { isReleaseVersion } from "../feed/release-version.js";
9
11
  import { open, rename, unlink } from "node:fs/promises";
10
12
  import { basename, dirname, join } from "node:path";
11
13
  import { randomUUID } from "node:crypto";
@@ -76,19 +78,10 @@ var UpdateLaunchHandoffCleanupError = class extends Error {
76
78
  this.released = true;
77
79
  }
78
80
  };
79
- var VERSION = /^\d+\.\d+\.\d+(?:-dev\.\d+)?$/;
80
81
  var MAX_GATE_BYTES = 1024;
81
82
  function validateTarget(target) {
82
83
  if (!isCanonicalPath(target)) throw new Error("Invalid update launch gate target");
83
84
  }
84
- async function syncDirectory(directoryPath) {
85
- const directory = await open(directoryPath, constants$1.O_RDONLY);
86
- try {
87
- await directory.sync();
88
- } finally {
89
- await directory.close();
90
- }
91
- }
92
85
  /** Stable gate metadata path, adjacent to the install and distinct from both lock files. */
93
86
  function updateLaunchGatePath(target) {
94
87
  validateTarget(target);
@@ -165,7 +158,7 @@ async function cancelUpdateLaunchGateBeforeTransition(target, helperLiveness, ex
165
158
  if (!validated) return "absent";
166
159
  if (!sameGate(validated, gate)) return "owner-mismatch";
167
160
  await unlink(updateLaunchGatePath(target));
168
- await syncDirectory(dirname(updateLaunchGatePath(target)));
161
+ await syncUpdateTreeParent(target);
169
162
  return "cleared";
170
163
  } finally {
171
164
  await transition.release();
@@ -180,7 +173,7 @@ function helperLeaseState(lease, target, owner) {
180
173
  return state;
181
174
  }
182
175
  function validateGateInput(gate) {
183
- if (typeof gate !== "object" || gate === null || Object.keys(gate).length !== 4 || gate.schema !== 1 || typeof gate.generation !== "string" || !isUuid(gate.generation) || typeof gate.version !== "string" || !VERSION.test(gate.version) || typeof gate.owner !== "string" || !isUuid(gate.owner)) throw new Error("Invalid update launch gate");
176
+ if (typeof gate !== "object" || gate === null || Object.keys(gate).length !== 4 || gate.schema !== 1 || typeof gate.generation !== "string" || !isUuid(gate.generation) || typeof gate.version !== "string" || !isReleaseVersion(gate.version) || typeof gate.owner !== "string" || !isUuid(gate.owner)) throw new Error("Invalid update launch gate");
184
177
  return Object.freeze({
185
178
  schema: 1,
186
179
  generation: gate.generation,
@@ -250,7 +243,7 @@ async function publishUpdateLaunchGate(target, helperLiveness, input, persistOwn
250
243
  }
251
244
  await rename(temporary, path);
252
245
  renamed = true;
253
- await syncDirectory(dirname(path));
246
+ await syncUpdateTreeParent(target);
254
247
  } catch (error) {
255
248
  if (!renamed) await unlink(temporary).catch(() => {});
256
249
  throw error;
@@ -301,7 +294,7 @@ async function tryRecoverUpdateLaunchGate(target, reconcileJournalAndTree) {
301
294
  if (!await reconcileJournalAndTree(gate)) return "unreconciled";
302
295
  if (!sameGate(await readUpdateLaunchGate(target), gate)) throw new Error("Update launch gate changed after journal and tree reconciliation");
303
296
  await unlink(updateLaunchGatePath(target));
304
- await syncDirectory(dirname(updateLaunchGatePath(target)));
297
+ await syncUpdateTreeParent(target);
305
298
  return "recovered";
306
299
  } finally {
307
300
  try {
@@ -333,7 +326,7 @@ async function clearOwnedUpdateLaunchGate(target, expected, transitionCompleted,
333
326
  if (!verified) return "absent";
334
327
  if (!sameGate(verified, gate)) return "ownership-mismatch";
335
328
  await unlink(updateLaunchGatePath(target));
336
- await syncDirectory(dirname(updateLaunchGatePath(target)));
329
+ await syncUpdateTreeParent(target);
337
330
  return "cleared";
338
331
  } finally {
339
332
  await lock.release();
@@ -75,7 +75,10 @@ async function readSmallStateFile(path, maximum, message) {
75
75
  try {
76
76
  const info = await file.stat();
77
77
  if (!info.isFile() || info.size < 1 || info.size > maximum || linkFree && (linkFree.dev !== info.dev || linkFree.ino !== info.ino)) throw new Error(message);
78
- const text = await file.readFile("utf8");
78
+ const bytes = Buffer.allocUnsafe(info.size + 1);
79
+ const { bytesRead } = await file.read(bytes, 0, bytes.length, 0);
80
+ if (bytesRead !== info.size) throw new Error(message);
81
+ const text = bytes.toString("utf8", 0, bytesRead);
79
82
  if (Buffer.byteLength(text) !== info.size) throw new Error(message);
80
83
  return text;
81
84
  } finally {
@@ -0,0 +1,12 @@
1
+ import type { UpdateStageState } from '../update-state-store';
2
+ /**
3
+ * Whether the helper a journal records may still be running. A recorded PID that is gone
4
+ * settles it. After the exchange, a gated helper has held the per-install liveness lock for
5
+ * its whole run, so a free lock proves it exited even when the PID still answers: a helper
6
+ * that relaunched the app and is between releasing the lock and exiting, a zombie, or a
7
+ * reused PID. Before the exchange the PID is the only evidence, because the helper may
8
+ * have started without taking the lock yet.
9
+ *
10
+ * Call while holding the install update lock.
11
+ */
12
+ export declare function recordedUpdateHelperMayBeRunning(target: string, state: Pick<UpdateStageState, 'helperPid' | 'phase' | 'launchGateOwner'>): Promise<boolean>;
@@ -0,0 +1,27 @@
1
+ import { tryAcquireUpdateHelperLiveness } from "../launch/update-launch-gate.js";
2
+ import { updateProcessMayBeAlive } from "./update-process-liveness.js";
3
+ // src/updates/locks/update-helper-presence.ts
4
+ var AFTER_EXCHANGE = /* @__PURE__ */ new Set([
5
+ "completed",
6
+ "retiring",
7
+ "retired"
8
+ ]);
9
+ /**
10
+ * Whether the helper a journal records may still be running. A recorded PID that is gone
11
+ * settles it. After the exchange, a gated helper has held the per-install liveness lock for
12
+ * its whole run, so a free lock proves it exited even when the PID still answers: a helper
13
+ * that relaunched the app and is between releasing the lock and exiting, a zombie, or a
14
+ * reused PID. Before the exchange the PID is the only evidence, because the helper may
15
+ * have started without taking the lock yet.
16
+ *
17
+ * Call while holding the install update lock.
18
+ */
19
+ async function recordedUpdateHelperMayBeRunning(target, state) {
20
+ if (!state.helperPid || !updateProcessMayBeAlive(state.helperPid)) return false;
21
+ if (state.launchGateOwner === void 0 || !AFTER_EXCHANGE.has(state.phase)) return true;
22
+ const liveness = await tryAcquireUpdateHelperLiveness(target);
23
+ if (!liveness) return true;
24
+ await liveness.release();
25
+ return false;
26
+ }
27
+ export { recordedUpdateHelperMayBeRunning };
@@ -1,13 +1,14 @@
1
1
  import { tryAcquireUpdateGenerationLease } from "../locks/update-generation-lease.js";
2
2
  import { removeDirectoryContentsChunk } from "../../native/posix-tree-removal.js";
3
3
  import { syncUpdateRetentionIntent } from "./update-retention-sync.js";
4
- import { publishUpdateRetentionIntent, readUpdateRetentionIntent, readUpdateRetentionIntentFile, sameRetentionIntent, updateRetentionIntentPath } from "./update-retention-marker.js";
4
+ import { LOWERCASE_UUID, publishUpdateRetentionIntent, readUpdateRetentionIntent, readUpdateRetentionIntentFile, sameRetentionIntent, updateRetentionIntentPath } from "./update-retention-marker.js";
5
5
  import { withUpdateLock } from "../update-state-store.js";
6
6
  import { sameUpdateTreeIdentity } from "../install/update-swap.js";
7
7
  import { isCanonicalPath } from "../../native/canonical-path.js";
8
8
  import { findPruneProgressTemporaryName, publishPruneProgress, readPruneProgress, readPruneProgressFile, retentionPruneProgressPath, syncPruneDirectory, syncPruneFile, syncPruneProgress, syncPruneRecoveryEvidence } from "./retention-prune-progress.js";
9
9
  import { planRetentionWhileLocked } from "./retirement-inventory.js";
10
- import { PUBLISHER_TEMP_UUID, VERSION, healthReceiptFor, healthReceiptMatches, matchesInstalledTree, ownerMatches, pathInfo, readHealthReceipt, readOwner, samePathTreeIdentity, updateRetirementPaths } from "./retirement-records.js";
10
+ import { healthReceiptFor, healthReceiptMatches, matchesInstalledTree, ownerMatches, pathInfo, readHealthReceipt, readOwner, samePathTreeIdentity, updateRetirementPaths } from "./retirement-records.js";
11
+ import { isReleaseVersion } from "../feed/release-version.js";
11
12
  import { link, readdir, rmdir, unlink } from "node:fs/promises";
12
13
  import { basename, dirname, join } from "node:path";
13
14
  // src/updates/retention/retention-cleanup.ts
@@ -41,7 +42,7 @@ function retentionTemporaryName(names, target, generation) {
41
42
  if (temporaryNames.length === 1) {
42
43
  const name = temporaryNames[0];
43
44
  const id = name.startsWith(temporaryPrefix) && name.endsWith(".tmp") ? name.slice(temporaryPrefix.length, -4) : "";
44
- if (!PUBLISHER_TEMP_UUID.test(id)) throw new Error("Malformed update retention temporary requires recovery");
45
+ if (!LOWERCASE_UUID.test(id)) throw new Error("Malformed update retention temporary requires recovery");
45
46
  selected = name;
46
47
  }
47
48
  for (const name of artifacts) {
@@ -63,7 +64,7 @@ async function assertIntentMatchesRetentionPlan(target, inventory, plan, intent)
63
64
  */
64
65
  async function inspectUpdateRetentionCleanup(options) {
65
66
  const { target, currentVersion, generation } = options;
66
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
67
+ if (typeof currentVersion !== "string" || !isReleaseVersion(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
67
68
  updateRetentionIntentPath(target, generation);
68
69
  return withUpdateLock(target, () => inspectRetentionWhileLocked(target, currentVersion, generation));
69
70
  }
@@ -83,7 +84,7 @@ async function inspectRetentionWhileLocked(target, currentVersion, generation) {
83
84
  */
84
85
  async function syncValidatedUpdateRetentionCleanup(options) {
85
86
  const { target, currentVersion, generation } = options;
86
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
87
+ if (typeof currentVersion !== "string" || !isReleaseVersion(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
87
88
  updateRetentionIntentPath(target, generation);
88
89
  return withUpdateLock(target, async () => {
89
90
  const intent = await inspectRetentionWhileLocked(target, currentVersion, generation);
@@ -108,7 +109,7 @@ async function syncValidatedUpdateRetentionCleanup(options) {
108
109
  */
109
110
  async function promoteOrphanUpdateRetentionCleanup(options) {
110
111
  const { target, currentVersion, generation } = options;
111
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
112
+ if (typeof currentVersion !== "string" || !isReleaseVersion(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
112
113
  const finalPath = updateRetentionIntentPath(target, generation);
113
114
  const readOrphan = async (expectedTemporaryName) => {
114
115
  const names = await readdir(dirname(target));
@@ -172,7 +173,7 @@ async function promoteOrphanUpdateRetentionCleanup(options) {
172
173
  */
173
174
  async function reconcileUpdateRetentionCleanup(options) {
174
175
  const { target, currentVersion, generation } = options;
175
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
176
+ if (typeof currentVersion !== "string" || !isReleaseVersion(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
176
177
  const markerPath = updateRetentionIntentPath(target, generation);
177
178
  return withUpdateLock(target, async () => {
178
179
  const temporaryName = retentionTemporaryName(await readdir(dirname(target)), target, generation);
@@ -224,7 +225,7 @@ async function reconcileUpdateRetentionCleanup(options) {
224
225
  */
225
226
  async function beginUpdateRetentionCleanup(options) {
226
227
  const { target, currentVersion } = options;
227
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
228
+ if (typeof currentVersion !== "string" || !isReleaseVersion(currentVersion) || !isCanonicalPath(target)) throw new Error("Invalid update retention lookup");
228
229
  return withUpdateLock(target, async () => {
229
230
  const { inventory, plan } = await planRetentionWhileLocked(target, currentVersion);
230
231
  if (plan.status !== "ready") throw new Error("Update retention lineage requires recovery");
@@ -263,7 +264,7 @@ async function beginUpdateRetentionCleanup(options) {
263
264
  async function pruneUpdateRetentionStep(options) {
264
265
  const { target, currentVersion, generation } = options;
265
266
  const maxOperations = options.maxOperations ?? 64;
266
- if (typeof currentVersion !== "string" || !VERSION.test(currentVersion) || !isCanonicalPath(target) || !Number.isSafeInteger(maxOperations) || maxOperations < 1 || maxOperations > 4096) throw new Error("Invalid update retention prune request");
267
+ if (typeof currentVersion !== "string" || !isReleaseVersion(currentVersion) || !isCanonicalPath(target) || !Number.isSafeInteger(maxOperations) || maxOperations < 1 || maxOperations > 4096) throw new Error("Invalid update retention prune request");
267
268
  updateRetirementPaths(target, generation);
268
269
  if (process.platform !== "darwin" || process.arch !== "arm64") return { status: "recovery-required" };
269
270
  return withUpdateLock(target, async () => {