@inflatable-cookie/longhorn 0.6.0 → 0.7.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 (133) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -7
  3. package/src/agent-control/generated/protocol.ts +228 -0
  4. package/src/agent-control/index.ts +1 -5
  5. package/src/agent-control/selection.ts +10 -8
  6. package/src/agent-control/shim.ts +149 -77
  7. package/src/bridge/generated/fields.ts +1 -1
  8. package/src/bridge/generated/protocol.ts +55 -4
  9. package/src/bridge/generated/variant-fields.ts +1 -1
  10. package/src/bridge/job.ts +49 -2
  11. package/src/bridge/runtime/connection.ts +11 -14
  12. package/src/bridge/stream/connection.ts +14 -23
  13. package/src/bridge/stream/tracker.ts +5 -0
  14. package/src/bridge/supervision.ts +102 -80
  15. package/src/bridge/validation/base.ts +7 -27
  16. package/src/bridge/validation/negotiation.ts +1 -6
  17. package/src/bridge/validation/operations.ts +2 -14
  18. package/src/commands/client.ts +16 -2
  19. package/src/commands/controller.ts +96 -58
  20. package/src/commands/generated/fields.ts +4 -4
  21. package/src/commands/generated/protocol.ts +24 -1
  22. package/src/commands/generated/variant-fields.ts +1 -1
  23. package/src/commands/keyboard.ts +4 -13
  24. package/src/commands/physical-code.ts +11 -0
  25. package/src/commands/ports.ts +2 -1
  26. package/src/commands/projectors.ts +52 -29
  27. package/src/commands/validation.ts +408 -188
  28. package/src/config/client.ts +3 -3
  29. package/src/config/generated/base.ts +22 -6
  30. package/src/config/generated/fields.ts +2 -1
  31. package/src/config/generated/label-template.ts +1 -1
  32. package/src/config/generated/labels.ts +1 -1
  33. package/src/config/generated/protocol.ts +1 -1
  34. package/src/config/generated/restore.ts +35 -12
  35. package/src/config/generated/variant-fields.ts +1 -1
  36. package/src/config/validation/commands.ts +11 -13
  37. package/src/config/validation/outcomes.ts +147 -46
  38. package/src/config/validation/primitives.ts +11 -39
  39. package/src/config/validation/projection.ts +44 -44
  40. package/src/core/connection.ts +124 -29
  41. package/src/core/controller-lifecycle.ts +144 -0
  42. package/src/core/generated/identifiers.ts +4 -0
  43. package/src/core/identifiers.ts +40 -0
  44. package/src/core/index.ts +10 -1
  45. package/src/core/json-value.ts +58 -0
  46. package/src/core/listeners.ts +35 -0
  47. package/src/core/record.ts +76 -0
  48. package/src/core/transport.ts +10 -1
  49. package/src/core/wire-copy.ts +1 -0
  50. package/src/history/client.ts +11 -7
  51. package/src/history/controller.ts +72 -74
  52. package/src/history/generated/fields.ts +2 -1
  53. package/src/history/generated/protocol.ts +8 -5
  54. package/src/history/generated/variant-fields.ts +1 -1
  55. package/src/history/ports.ts +7 -2
  56. package/src/history/validation.ts +15 -37
  57. package/src/history-tree/client.ts +15 -13
  58. package/src/history-tree/controller.ts +131 -90
  59. package/src/history-tree/generated/fields.ts +3 -1
  60. package/src/history-tree/generated/protocol.ts +43 -7
  61. package/src/history-tree/generated/variant-fields.ts +7 -1
  62. package/src/history-tree/ports.ts +9 -4
  63. package/src/history-tree/validation.ts +44 -35
  64. package/src/layout/generated/protocol.ts +2 -1
  65. package/src/layout/generated/variant-fields.ts +47 -0
  66. package/src/layout/index.ts +1 -1
  67. package/src/layout/ratio.ts +9 -2
  68. package/src/layout/validation.ts +88 -13
  69. package/src/licence/client.ts +11 -7
  70. package/src/licence/controller.ts +64 -43
  71. package/src/licence/generated/fields.ts +2 -1
  72. package/src/licence/generated/protocol.ts +8 -4
  73. package/src/licence/generated/variant-fields.ts +1 -1
  74. package/src/licence/key.ts +2 -6
  75. package/src/licence/ports.ts +7 -2
  76. package/src/licence/validation.ts +27 -20
  77. package/src/native-content/client.ts +32 -1
  78. package/src/native-content/generated/fields.ts +4 -4
  79. package/src/native-content/generated/protocol.ts +16 -5
  80. package/src/native-content/generated/variant-fields.ts +1 -1
  81. package/src/native-content/ports.ts +2 -1
  82. package/src/native-content/validation/base.ts +16 -46
  83. package/src/native-content/validation/messages.ts +3 -0
  84. package/src/notifications/client.ts +17 -39
  85. package/src/notifications/controller.ts +266 -165
  86. package/src/notifications/generated/fields.ts +2 -1
  87. package/src/notifications/generated/labels.ts +1 -1
  88. package/src/notifications/generated/protocol.ts +5 -1
  89. package/src/notifications/generated/variant-fields.ts +1 -1
  90. package/src/notifications/ports.ts +2 -1
  91. package/src/notifications/tone.ts +1 -1
  92. package/src/notifications/validation.ts +41 -51
  93. package/src/operation/bridge.ts +79 -19
  94. package/src/operation/client.ts +17 -45
  95. package/src/operation/controller.ts +38 -59
  96. package/src/operation/generated/fields.ts +2 -1
  97. package/src/operation/generated/labels.ts +1 -1
  98. package/src/operation/generated/protocol.ts +5 -1
  99. package/src/operation/generated/variant-fields.ts +1 -1
  100. package/src/operation/ports.ts +2 -1
  101. package/src/operation/validation.ts +48 -50
  102. package/src/settings/connection.ts +10 -14
  103. package/src/settings/generated/fields.ts +2 -1
  104. package/src/settings/generated/protocol.ts +5 -1
  105. package/src/settings/generated/variant-fields.ts +1 -1
  106. package/src/settings/validation/authority.ts +2 -2
  107. package/src/settings/validation/command.ts +5 -4
  108. package/src/settings/validation/primitives.ts +32 -67
  109. package/src/settings/validation/registry.ts +13 -11
  110. package/src/surface-transfer/generated/fields.ts +1 -1
  111. package/src/surface-transfer/generated/protocol.ts +3 -3
  112. package/src/surface-transfer/generated/variant-fields.ts +1 -1
  113. package/src/surface-transfer/validation.ts +76 -53
  114. package/src/surfaces/client.ts +26 -38
  115. package/src/surfaces/generated/fields.ts +1 -1
  116. package/src/surfaces/generated/protocol.ts +1 -1
  117. package/src/surfaces/generated/variant-fields.ts +1 -1
  118. package/src/surfaces/validation.ts +198 -61
  119. package/src/transfer/connection.ts +25 -39
  120. package/src/transfer/generated/fields.ts +2 -1
  121. package/src/transfer/generated/protocol.ts +9 -1
  122. package/src/transfer/generated/variant-fields.ts +1 -1
  123. package/src/transfer/index.ts +8 -1
  124. package/src/transfer/payload.ts +12 -9
  125. package/src/transfer/validation.ts +146 -60
  126. package/src/update/client.ts +43 -16
  127. package/src/update/controller.ts +187 -104
  128. package/src/update/generated/fields.ts +2 -1
  129. package/src/update/generated/protocol.ts +19 -7
  130. package/src/update/generated/variant-fields.ts +3 -2
  131. package/src/update/ports.ts +11 -7
  132. package/src/update/serialized.ts +8 -6
  133. package/src/update/validation.ts +18 -28
@@ -1,3 +1,5 @@
1
+ import type { ConnectionFailureReporter } from "../core/connection.ts";
2
+ import { ControllerLifecycle } from "../core/controller-lifecycle.ts";
1
3
  import { UpdateClient } from "./client.ts";
2
4
  import { UPDATE_PROTOCOL_VERSION } from "./generated/protocol.ts";
3
5
  import type {
@@ -5,12 +7,13 @@ import type {
5
7
  DeferralCause,
6
8
  UpdateAvailabilityProjection,
7
9
  UpdateOutcomeProjection,
10
+ UpdateProgressEvent,
8
11
  UpdateProgressProjection,
9
12
  UpdateRejectionCode,
10
13
  UpdateSnapshot,
11
14
  UpdateStagedArtifactProjection,
12
15
  } from "./generated/protocol.ts";
13
- import type { UpdatePort, UpdateUnlisten } from "./ports.ts";
16
+ import type { UpdatePort } from "./ports.ts";
14
17
 
15
18
  export type UpdateControllerStatus =
16
19
  | { readonly kind: "idle" }
@@ -33,6 +36,7 @@ export type UpdateCommandOutcome =
33
36
  readonly status: "rejected";
34
37
  readonly snapshot: UpdateSnapshot;
35
38
  readonly code: UpdateRejectionCode;
39
+ readonly detail: string | null;
36
40
  }
37
41
  | { readonly status: "failed"; readonly error: unknown };
38
42
 
@@ -57,10 +61,8 @@ export type UpdatePresence = "hidden" | "quiet" | "attention";
57
61
  * update `status` for callers that observe the controller instead:
58
62
  *
59
63
  * - **Committed.** State moved. Read the snapshot.
60
- * - **Committed with a deferral.** The install did not happen and that is not
61
- * a failure — Card 154 step 6. The gate refused because the user has work in
62
- * flight, and `deferral` says so. A surface that reports this as an error
63
- * tells a customer their update is broken when nothing is.
64
+ * - **Committed with a deferral.** The gate postponed the install. Read
65
+ * `deferral` for the reason.
64
66
  * - **Rejected.** The authority refused. `lastRejection` carries the code.
65
67
  *
66
68
  * - **Failed.** The transport or local precondition failed. The error is in
@@ -72,11 +74,11 @@ export class UpdateController {
72
74
  #status: UpdateControllerStatus = { kind: "idle" };
73
75
  #snapshot?: UpdateSnapshot;
74
76
  #lastRejection: UpdateRejectionCode | undefined;
75
- #started = false;
76
- #lifecycle = 0;
77
+ #lastRejectionDetail: string | null = null;
78
+ readonly #lifecycle = new ControllerLifecycle();
77
79
  #commandSequence = 0;
80
+ #refreshRevision = 0;
78
81
  #pending = false;
79
- #unlisten: Array<UpdateUnlisten> = [];
80
82
  /**
81
83
  * The most recent live progress report.
82
84
  *
@@ -92,7 +94,7 @@ export class UpdateController {
92
94
  }
93
95
 
94
96
  get status(): UpdateControllerStatus {
95
- return this.#status;
97
+ return this.#lifecycle.eventFailure ?? this.#status;
96
98
  }
97
99
  get snapshot(): UpdateSnapshot | undefined {
98
100
  return this.#snapshot;
@@ -127,8 +129,7 @@ export class UpdateController {
127
129
  /**
128
130
  * Why the last install did not proceed, when it did not.
129
131
  *
130
- * Present alongside a *committed* outcome. Card 154 step 6: a refused
131
- * restart shows its reason and is not a failure.
132
+ * The reason a committed command postponed installation.
132
133
  */
133
134
  get deferral(): { readonly version: string; readonly cause: DeferralCause } | undefined {
134
135
  return this.#snapshot?.deferral ?? undefined;
@@ -139,14 +140,16 @@ export class UpdateController {
139
140
  return this.#lastRejection;
140
141
  }
141
142
 
143
+ /** Installer detail from the latest rejection, when supplied. */
144
+ get lastRejectionDetail(): string | null {
145
+ return this.#lastRejectionDetail;
146
+ }
147
+
142
148
  /**
143
149
  * Whether this install sits ahead of the channel it follows.
144
150
  *
145
- * Card 154 step 5 calls this the single most likely support question the
146
- * feature generates: an install on `1.3.0-nightly.4` that selects production
147
- * receives nothing until `1.3.0` ships, which is correct and reads as a
148
- * broken updater unless the surface says so. Exposed as its own read so a
149
- * surface cannot render it as "no update available" by omission.
151
+ * A nightly install following production waits for the channel to catch up.
152
+ * The surface can explain this state using the installed and channel versions.
150
153
  */
151
154
  get aheadOfChannel(): { readonly installed: string; readonly channel: string } | undefined {
152
155
  const availability = this.#snapshot?.availability;
@@ -205,65 +208,61 @@ export class UpdateController {
205
208
  return () => this.#observers.delete(observer);
206
209
  }
207
210
 
208
- async start(): Promise<void> {
209
- if (this.#started) {
210
- return;
211
- }
212
- this.#started = true;
213
- const lifecycle = ++this.#lifecycle;
214
- this.#setStatus({ kind: "loading" });
215
- try {
216
- const unlisten = await this.#client.listen(() => void this.refresh());
217
- // The listen resolved after a stop, or after a restart replaced this
218
- // lifetime. Contract 013: an adapter that outlives its owner keeps
219
- // writing into state nobody is reading.
220
- if (!this.#started || lifecycle !== this.#lifecycle) {
221
- await unlisten();
222
- return;
223
- }
224
- this.#unlisten.push(unlisten);
225
- const unlistenProgress = await this.#client.listenProgress((event) => {
226
- if (!this.#started || lifecycle !== this.#lifecycle) {
227
- return;
211
+ start(): Promise<void> {
212
+ return this.#lifecycle.start({
213
+ loading: () => this.#setStatus({ kind: "loading" }),
214
+ connect: async ({ isCurrent, own, reportFailure }) => {
215
+ const unlisten = await this.#client.listen(() => {
216
+ if (isCurrent()) {
217
+ void this.refresh();
218
+ }
219
+ }, reportFailure);
220
+ await own(unlisten);
221
+ if (isCurrent()) {
222
+ await this.refresh();
228
223
  }
229
- this.#liveProgress = event.progress;
230
- this.#notify();
231
- });
232
- if (!this.#started || lifecycle !== this.#lifecycle) {
233
- await unlistenProgress();
234
- return;
235
- }
236
- this.#unlisten.push(unlistenProgress);
237
- await this.refresh();
238
- } catch (error) {
239
- if (this.#started && lifecycle === this.#lifecycle) {
240
- this.#setStatus({ kind: "failed", error });
241
- }
242
- }
224
+ },
225
+ failed: (error) => this.#setStatus({ kind: "failed", error }),
226
+ });
243
227
  }
244
228
 
245
- async stop(): Promise<void> {
246
- this.#started = false;
247
- this.#lifecycle += 1;
248
- const unlisten = this.#unlisten;
249
- this.#unlisten = [];
250
- for (const stop of unlisten) {
251
- await stop();
252
- }
253
- this.#setStatus({ kind: "idle" });
229
+ /** Replaces the current subscription, including after a reported failure. */
230
+ restart(): Promise<void> {
231
+ return this.#lifecycle.restart(
232
+ this.status,
233
+ () => this.stop(),
234
+ () => this.start(),
235
+ );
236
+ }
237
+
238
+ stop(): Promise<void> {
239
+ return this.#lifecycle.stop(() => {
240
+ this.#pending = false;
241
+ this.#liveProgress = undefined;
242
+ this.#setStatus({ kind: "idle" });
243
+ });
254
244
  }
255
245
 
256
246
  async refresh(): Promise<void> {
257
- const lifecycle = this.#lifecycle;
247
+ if (!this.#lifecycle.active) {
248
+ return;
249
+ }
250
+ const lifecycle = this.#lifecycle.revision;
251
+ const revision = ++this.#refreshRevision;
252
+ const isCurrent = () =>
253
+ this.#lifecycle.isCurrent(lifecycle) && revision === this.#refreshRevision;
258
254
  try {
259
255
  const snapshot = await this.#client.snapshot();
260
- if (lifecycle !== this.#lifecycle) {
256
+ if (!isCurrent()) {
261
257
  return;
262
258
  }
259
+ if (snapshot.authorityEpoch !== this.#snapshot?.authorityEpoch) {
260
+ this.#liveProgress = undefined;
261
+ }
263
262
  this.#snapshot = snapshot;
264
263
  this.#setStatus({ kind: "ready" });
265
264
  } catch (error) {
266
- if (lifecycle === this.#lifecycle) {
265
+ if (isCurrent()) {
267
266
  this.#setStatus({ kind: "failed", error });
268
267
  }
269
268
  }
@@ -271,17 +270,17 @@ export class UpdateController {
271
270
 
272
271
  /** Asks the source for the channel's current manifest. */
273
272
  async check(): Promise<UpdateCommandOutcome> {
274
- return this.#command((client, epoch) =>
275
- client.check({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch: epoch }),
273
+ return this.#command((client, { authorityEpoch }) =>
274
+ client.check({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch }),
276
275
  );
277
276
  }
278
277
 
279
278
  /** Follows a different channel from now on. */
280
279
  async selectChannel(channel: Channel): Promise<UpdateCommandOutcome> {
281
- return this.#command((client, epoch) =>
280
+ return this.#command((client, { authorityEpoch }) =>
282
281
  client.selectChannel({
283
282
  protocolVersion: UPDATE_PROTOCOL_VERSION,
284
- authorityEpoch: epoch,
283
+ authorityEpoch,
285
284
  channel,
286
285
  }),
287
286
  );
@@ -290,21 +289,29 @@ export class UpdateController {
290
289
  /** Declines a version for now. */
291
290
  async defer(version: string, cause: DeferralCause): Promise<UpdateCommandOutcome> {
292
291
  return this.#command(
293
- (client, epoch) =>
292
+ (client, { authorityEpoch }) =>
294
293
  client.defer({
295
294
  protocolVersion: UPDATE_PROTOCOL_VERSION,
296
- authorityEpoch: epoch,
295
+ authorityEpoch,
297
296
  version,
298
297
  cause,
299
298
  }),
300
- true,
299
+ { committedMayDefer: true },
301
300
  );
302
301
  }
303
302
 
304
303
  /** Fetches, verifies and retains an update for a later apply. */
305
304
  async prepare(version: string): Promise<UpdateCommandOutcome> {
306
- return this.#command((client, epoch) =>
307
- client.prepare({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch: epoch, version }),
305
+ return this.#command((client, snapshot, progress) =>
306
+ client.prepareWithProgress(
307
+ {
308
+ protocolVersion: UPDATE_PROTOCOL_VERSION,
309
+ authorityEpoch: snapshot.authorityEpoch,
310
+ version,
311
+ },
312
+ progress.report,
313
+ progress.fail,
314
+ ),
308
315
  );
309
316
  }
310
317
 
@@ -312,81 +319,133 @@ export class UpdateController {
312
319
  * Applies the retained staged artifact, replacing the application.
313
320
  *
314
321
  * A gate refusal is a deferral: the artifact stays staged and the surface
315
- * can offer the restart again.
322
+ * can offer the restart again. A version that is not the staged one fails
323
+ * with `UpdateNotStagedError` and nothing is sent.
316
324
  */
317
325
  async apply(version: string): Promise<UpdateCommandOutcome> {
318
- return this.#command(async (client, epoch, snapshot) => {
319
- const staged = snapshot.staged;
320
- if (staged?.version !== version) {
321
- return { status: "rejected", code: "noOffer", snapshot };
322
- }
323
- return client.apply({
324
- protocolVersion: UPDATE_PROTOCOL_VERSION,
325
- authorityEpoch: epoch,
326
- version,
327
- digest: staged.digest,
328
- });
329
- }, true);
326
+ return this.#command(
327
+ (client, snapshot) =>
328
+ client.apply({
329
+ protocolVersion: UPDATE_PROTOCOL_VERSION,
330
+ authorityEpoch: snapshot.authorityEpoch,
331
+ version,
332
+ digest: stagedArtifact(snapshot, version).digest,
333
+ }),
334
+ {
335
+ committedMayDefer: true,
336
+ precondition: (snapshot) => {
337
+ stagedArtifact(snapshot, version);
338
+ },
339
+ },
340
+ );
330
341
  }
331
342
 
332
343
  /** Discards the retained staged artifact. */
333
344
  async cancel(): Promise<UpdateCommandOutcome> {
334
- return this.#command((client, epoch) =>
335
- client.cancel({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch: epoch }),
345
+ return this.#command((client, { authorityEpoch }) =>
346
+ client.cancel({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch }),
336
347
  );
337
348
  }
338
349
 
339
350
  async #command(
340
351
  run: (
341
352
  client: UpdateClient,
342
- epoch: number,
343
353
  snapshot: UpdateSnapshot,
354
+ progress: {
355
+ readonly report: (event: UpdateProgressEvent) => void;
356
+ readonly fail: ConnectionFailureReporter;
357
+ },
344
358
  ) => Promise<UpdateOutcomeProjection>,
345
- committedMayDefer = false,
359
+ options: {
360
+ readonly committedMayDefer?: boolean;
361
+ /** Throws when local state rules the command out before anything is sent. */
362
+ readonly precondition?: (snapshot: UpdateSnapshot) => void;
363
+ } = {},
346
364
  ): Promise<UpdateCommandOutcome> {
347
- const commandSequence = ++this.#commandSequence;
365
+ if (!this.#lifecycle.active) {
366
+ // Nothing is sent and nothing is written: a stopped controller stays idle.
367
+ return { status: "failed", error: new UpdateControllerUnavailableError() };
368
+ }
348
369
  this.#lastRejection = undefined;
370
+ this.#lastRejectionDetail = null;
349
371
  const snapshot = this.#snapshot;
350
- if (snapshot === undefined) {
351
- // No snapshot means no epoch to send, and inventing one would have the
352
- // authority refuse it as stale. Say what is actually wrong.
353
- const error = new Error("update state has not been read yet");
372
+ // A local failure takes no command sequence, so a command already in
373
+ // flight keeps ownership of `pending` and of its result.
374
+ try {
375
+ if (snapshot === undefined) {
376
+ // No snapshot means no epoch to send, and inventing one would have the
377
+ // authority refuse it as stale. Say what is actually wrong.
378
+ throw new Error("update state has not been read yet");
379
+ }
380
+ options.precondition?.(snapshot);
381
+ } catch (error) {
354
382
  this.#setStatus({ kind: "failed", error });
355
383
  return { status: "failed", error };
356
384
  }
357
- const lifecycle = this.#lifecycle;
385
+ const commandSequence = ++this.#commandSequence;
386
+ const lifecycle = this.#lifecycle.revision;
387
+ const isCurrent = () =>
388
+ lifecycle === this.#lifecycle.revision && commandSequence === this.#commandSequence;
389
+ const reportProgress = (event: UpdateProgressEvent) => {
390
+ if (
391
+ this.#lifecycle.active &&
392
+ isCurrent() &&
393
+ this.#pending &&
394
+ event.authorityEpoch === snapshot.authorityEpoch &&
395
+ event.authorityEpoch === this.#snapshot?.authorityEpoch
396
+ ) {
397
+ this.#liveProgress = event.progress;
398
+ this.#notify();
399
+ }
400
+ };
401
+ const failProgress: ConnectionFailureReporter = ({ error }) => {
402
+ if (this.#lifecycle.isCurrent(lifecycle)) {
403
+ this.#lifecycle.recordEventFailure(error);
404
+ this.#liveProgress = undefined;
405
+ this.#notify();
406
+ }
407
+ };
358
408
  this.#pending = true;
359
409
  this.#liveProgress = undefined;
360
410
  this.#notify();
361
411
  try {
362
- const outcome = await run(this.#client, snapshot.authorityEpoch, snapshot);
412
+ const outcome = await run(this.#client, snapshot, {
413
+ report: reportProgress,
414
+ fail: failProgress,
415
+ });
363
416
  const result: UpdateCommandOutcome =
364
417
  outcome.status === "rejected"
365
- ? { status: "rejected", snapshot: outcome.snapshot, code: outcome.code }
366
- : committedMayDefer && outcome.snapshot.deferral !== null
418
+ ? {
419
+ status: "rejected",
420
+ snapshot: outcome.snapshot,
421
+ code: outcome.code,
422
+ detail: outcome.detail,
423
+ }
424
+ : options.committedMayDefer && outcome.snapshot.deferral !== null
367
425
  ? {
368
426
  status: "committedWithDeferral",
369
427
  snapshot: outcome.snapshot,
370
428
  deferral: outcome.snapshot.deferral,
371
429
  }
372
430
  : { status: "committed", snapshot: outcome.snapshot };
373
- if (lifecycle === this.#lifecycle && commandSequence === this.#commandSequence) {
431
+ if (isCurrent()) {
432
+ this.#pending = false;
433
+ this.#refreshRevision += 1;
374
434
  this.#snapshot = outcome.snapshot;
375
435
  this.#liveProgress = undefined;
376
436
  this.#lastRejection = result.status === "rejected" ? result.code : undefined;
437
+ this.#lastRejectionDetail = result.status === "rejected" ? result.detail : null;
377
438
  this.#setStatus({ kind: "ready" });
378
439
  }
379
440
  return result;
380
441
  } catch (error) {
381
- if (lifecycle === this.#lifecycle && commandSequence === this.#commandSequence) {
442
+ if (isCurrent()) {
443
+ this.#refreshRevision += 1;
444
+ this.#pending = false;
445
+ this.#liveProgress = undefined;
382
446
  this.#setStatus({ kind: "failed", error });
383
447
  }
384
448
  return { status: "failed", error };
385
- } finally {
386
- if (lifecycle === this.#lifecycle && commandSequence === this.#commandSequence) {
387
- this.#pending = false;
388
- this.#notify();
389
- }
390
449
  }
391
450
  }
392
451
 
@@ -401,3 +460,27 @@ export class UpdateController {
401
460
  }
402
461
  }
403
462
  }
463
+
464
+ /** A command was issued outside a started lifetime. */
465
+ export class UpdateControllerUnavailableError extends Error {
466
+ constructor() {
467
+ super("update controller is not started");
468
+ this.name = "UpdateControllerUnavailableError";
469
+ }
470
+ }
471
+
472
+ /** `apply` named a version that is not the staged artifact. */
473
+ export class UpdateNotStagedError extends Error {
474
+ constructor(readonly version: string) {
475
+ super(`no staged update artifact for version: ${version}`);
476
+ this.name = "UpdateNotStagedError";
477
+ }
478
+ }
479
+
480
+ function stagedArtifact(snapshot: UpdateSnapshot, version: string): UpdateStagedArtifactProjection {
481
+ const staged = snapshot.staged;
482
+ if (staged?.version !== version) {
483
+ throw new UpdateNotStagedError(version);
484
+ }
485
+ return staged;
486
+ }
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:update`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Allowed field names per protocol type, from the Rust structs.
3
3
  // A `record()` given one of these rejects unknown and missing keys —
4
4
  // contract 010's Boundary Validation Target.
@@ -15,4 +15,5 @@ export const UPDATE_FIELDS = {
15
15
  "UpdateApplyCommand": ["protocolVersion", "authorityEpoch", "version", "digest"],
16
16
  "UpdateCancelCommand": ["protocolVersion", "authorityEpoch"],
17
17
  "UpdateChangedEvent": ["protocolVersion", "authorityEpoch", "kind"],
18
+ "UpdateHostError": ["code", "message", "retryable"],
18
19
  } as const;
@@ -1,16 +1,16 @@
1
- // @generated by `effigy generate:update`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Rust serde types are the wire authority. Versions are strings, as
3
3
  // `semver::Version` serialises them.
4
4
 
5
5
  export const UPDATE_PROTOCOL_VERSION = 1 as const;
6
6
  export const UPDATE_CHANNELS = ["production","beta","nightly"] as const;
7
7
  export const UPDATE_OFFER_REASONS = ["staged","belowMinimumVersion","userInitiated"] as const;
8
- export const UPDATE_INSTALL_MANAGERS = ["macAppStore","homebrewCask","flatpak","snap","appImage","nix","linuxDistribution"] as const;
8
+ export const UPDATE_INSTALL_MANAGERS = ["macAppStore","homebrewCask","homebrewFormula","flatpak","snap","appImage","nix","linuxDistribution"] as const;
9
9
  export const UPDATE_DEFERRAL_CAUSES = ["userPostponed","workInFlight","installationNotWritable","externallyManaged","installFailed"] as const;
10
- export const UPDATE_AVAILABILITY_STATES = ["notChecked","offer","upToDate","aheadOfChannel","withheldByRollout","managedElsewhere"] as const;
10
+ export const UPDATE_AVAILABILITY_STATES = ["notChecked","offer","unavailableForTarget","upToDate","aheadOfChannel","withheldByRollout","managedElsewhere"] as const;
11
11
  export const UPDATE_PROGRESS_STATES = ["idle","downloading","verifying","readyToInstall","installing"] as const;
12
12
  export const UPDATE_INSTALL_AUTHORIZATION_STATUSES = ["held","deferred"] as const;
13
- export const UPDATE_REJECTION_CODES = ["staleAuthority","noOffer","unavailable","channelMismatch","unreachable","signatureRejected","notWritable","installFailed"] as const;
13
+ export const UPDATE_REJECTION_CODES = ["staleAuthority","noOffer","unavailable","channelMismatch","unreachable","signatureRejected","notWritable","malformedArtifact","installFailed"] as const;
14
14
  export const UPDATE_OUTCOME_STATUSES = ["committed","rejected"] as const;
15
15
  export const UPDATE_CHANGED_KINDS = ["checked","channelSelected","deferred","progressed"] as const;
16
16
 
@@ -20,7 +20,7 @@ export type Channel = "production" | "beta" | "nightly";
20
20
 
21
21
  export type OfferReason = "staged" | "belowMinimumVersion" | "userInitiated";
22
22
 
23
- export type InstallManager = "macAppStore" | "homebrewCask" | "flatpak" | "snap" | "appImage" | "nix" | "linuxDistribution";
23
+ export type InstallManager = "macAppStore" | "homebrewCask" | "homebrewFormula" | "flatpak" | "snap" | "appImage" | "nix" | "linuxDistribution";
24
24
 
25
25
  export type DeferralCause = { "cause": "userPostponed" } | { "cause": "workInFlight",
26
26
  /**
@@ -56,7 +56,11 @@ reason: OfferReason,
56
56
  /**
57
57
  * Release notes, when published.
58
58
  */
59
- notes: string | null, } | { "state": "upToDate" } | { "state": "aheadOfChannel",
59
+ notes: string | null, } | { "state": "unavailableForTarget",
60
+ /**
61
+ * The release version.
62
+ */
63
+ version: string, } | { "state": "upToDate" } | { "state": "aheadOfChannel",
60
64
  /**
61
65
  * What is installed.
62
66
  */
@@ -275,7 +279,7 @@ export type UpdateInstallAuthorizationProjection = { "status": "held" } | { "sta
275
279
  */
276
280
  cause: DeferralCause, };
277
281
 
278
- export type UpdateRejectionCode = "staleAuthority" | "noOffer" | "unavailable" | "channelMismatch" | "unreachable" | "signatureRejected" | "notWritable" | "installFailed";
282
+ export type UpdateRejectionCode = "staleAuthority" | "noOffer" | "unavailable" | "channelMismatch" | "unreachable" | "signatureRejected" | "notWritable" | "malformedArtifact" | "installFailed";
279
283
 
280
284
  export type UpdateOutcomeProjection = { "status": "committed",
281
285
  /**
@@ -286,6 +290,10 @@ snapshot: UpdateSnapshot, } | { "status": "rejected",
286
290
  * What a surface should tell the operator.
287
291
  */
288
292
  code: UpdateRejectionCode,
293
+ /**
294
+ * Installer detail with common credential shapes redacted, when supplied.
295
+ */
296
+ detail: string | null,
289
297
  /**
290
298
  * The state as it remains.
291
299
  */
@@ -309,3 +317,7 @@ authorityEpoch: number,
309
317
  * Coarse invalidation category.
310
318
  */
311
319
  kind: UpdateChangedKind, };
320
+
321
+ export type UpdateHostErrorCode = "authorityUnavailable" | "stateUnavailable" | "eventPublication";
322
+
323
+ export type UpdateHostError = { "code": UpdateHostErrorCode, "message": string, "retryable": boolean, };
@@ -1,4 +1,4 @@
1
- // @generated by `effigy generate:update`; do not edit.
1
+ // @generated by `effigy generate:bindings`; do not edit.
2
2
  // Allowed field names per tagged-union variant, from the Rust enums.
3
3
  // Keyed by type, then by discriminant. The discriminant itself is in
4
4
  // each list, because `exact()` compares every key.
@@ -14,6 +14,7 @@ export const UPDATE_VARIANT_FIELDS: Record<string, Record<string, readonly strin
14
14
  "UpdateAvailabilityProjection": {
15
15
  "notChecked": ["state"],
16
16
  "offer": ["state", "version", "reason", "notes"],
17
+ "unavailableForTarget": ["state", "version"],
17
18
  "upToDate": ["state"],
18
19
  "aheadOfChannel": ["state", "installed", "channel"],
19
20
  "withheldByRollout": ["state", "version"],
@@ -32,7 +33,7 @@ export const UPDATE_VARIANT_FIELDS: Record<string, Record<string, readonly strin
32
33
  },
33
34
  "UpdateOutcomeProjection": {
34
35
  "committed": ["status", "snapshot"],
35
- "rejected": ["status", "code", "snapshot"],
36
+ "rejected": ["status", "code", "detail", "snapshot"],
36
37
  },
37
38
  };
38
39
 
@@ -1,3 +1,5 @@
1
+ import type { ConnectionFailureReporter } from "../core/connection.ts";
2
+ import type { Unlisten } from "../core/transport.ts";
1
3
  import type {
2
4
  UpdateApplyCommand,
3
5
  UpdateCancelCommand,
@@ -6,12 +8,11 @@ import type {
6
8
  UpdateDeferCommand,
7
9
  UpdateOutcomeProjection,
8
10
  UpdatePrepareCommand,
9
- UpdateProgressEvent,
10
11
  UpdateSelectChannelCommand,
11
12
  UpdateSnapshot,
12
13
  } from "./generated/protocol.ts";
13
14
 
14
- export type UpdateUnlisten = () => void | Promise<void>;
15
+ export type UpdateUnlisten = Unlisten;
15
16
 
16
17
  /**
17
18
  * The raw seam.
@@ -25,14 +26,15 @@ export interface UpdatePort {
25
26
  selectChannel(command: UpdateSelectChannelCommand): Promise<unknown>;
26
27
  defer(command: UpdateDeferCommand): Promise<unknown>;
27
28
  prepare(command: UpdatePrepareCommand): Promise<unknown>;
29
+ /** Reports from this prepare invocation only. */
30
+ prepareWithProgress?:
31
+ | ((command: UpdatePrepareCommand, listener: (event: unknown) => void) => Promise<unknown>)
32
+ | undefined;
28
33
  apply(command: UpdateApplyCommand): Promise<unknown>;
29
34
  cancel(command: UpdateCancelCommand): Promise<unknown>;
30
35
  listen?:
31
36
  | ((listener: (event: unknown) => void) => UpdateUnlisten | Promise<UpdateUnlisten>)
32
37
  | undefined;
33
- listenProgress?:
34
- | ((listener: (event: unknown) => void) => UpdateUnlisten | Promise<UpdateUnlisten>)
35
- | undefined;
36
38
  }
37
39
 
38
40
  /** The same seam after validation. */
@@ -44,6 +46,8 @@ export interface CheckedUpdatePort {
44
46
  prepare(command: UpdatePrepareCommand): Promise<UpdateOutcomeProjection>;
45
47
  apply(command: UpdateApplyCommand): Promise<UpdateOutcomeProjection>;
46
48
  cancel(command: UpdateCancelCommand): Promise<UpdateOutcomeProjection>;
47
- listen(listener: (event: UpdateChangedEvent) => void): Promise<UpdateUnlisten>;
48
- listenProgress(listener: (event: UpdateProgressEvent) => void): Promise<UpdateUnlisten>;
49
+ listen(
50
+ listener: (event: UpdateChangedEvent) => void,
51
+ onFailure?: ConnectionFailureReporter,
52
+ ): Promise<UpdateUnlisten>;
49
53
  }
@@ -25,6 +25,14 @@ export class SerializedUpdatePort implements UpdatePort {
25
25
  async prepare(command: UpdatePrepareCommand): Promise<unknown> {
26
26
  return wireCopy(await this.inner.prepare(wireCopy(command)));
27
27
  }
28
+ get prepareWithProgress(): UpdatePort["prepareWithProgress"] {
29
+ const prepare = this.inner.prepareWithProgress?.bind(this.inner);
30
+ if (prepare === undefined) {
31
+ return undefined;
32
+ }
33
+ return async (command, listener) =>
34
+ wireCopy(await prepare(wireCopy(command), (event) => listener(wireCopy(event))));
35
+ }
28
36
  async apply(command: UpdateApplyCommand): Promise<unknown> {
29
37
  return wireCopy(await this.inner.apply(wireCopy(command)));
30
38
  }
@@ -37,10 +45,4 @@ export class SerializedUpdatePort implements UpdatePort {
37
45
  }
38
46
  return this.inner.listen((event) => listener(wireCopy(event)));
39
47
  }
40
- async listenProgress(listener: (event: unknown) => void): Promise<UpdateUnlisten> {
41
- if (this.inner.listenProgress === undefined) {
42
- return () => {};
43
- }
44
- return this.inner.listenProgress((event) => listener(wireCopy(event)));
45
- }
46
48
  }