@inflatable-cookie/longhorn 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@ Every domain is a subpath. `@inflatable-cookie/longhorn` itself resolves to
15
15
  | Subpath | Domain |
16
16
  | --- | --- |
17
17
  | `/core` | identity, opaque values, transports, diagnostics |
18
- | `/agent-control` | in-page semantic shim (dev control surface, contract 022). Synthetic events are untrusted (`isTrusted` stays false); `wait_for` is DOM-relative. |
18
+ | `/agent-control` | in-page semantic shim (contract 022 control surface). Synthetic events are untrusted (`isTrusted` stays false); `wait_for` is DOM-relative. |
19
19
  | `/config` | configuration store, backup, restore, recovery |
20
20
  | `/layout` | containers, regions, panels, sizing |
21
21
  | `/surfaces`, `/surface-transfer` | optional Surface documents and their transfer |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflatable-cookie/longhorn",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,19 +1,25 @@
1
1
  import type {
2
+ UpdateApplyCommand,
3
+ UpdateCancelCommand,
2
4
  UpdateChangedEvent,
3
5
  UpdateCheckCommand,
4
6
  UpdateDeferCommand,
5
- UpdateInstallCommand,
6
7
  UpdateOutcomeProjection,
8
+ UpdatePrepareCommand,
9
+ UpdateProgressEvent,
7
10
  UpdateSelectChannelCommand,
8
11
  UpdateSnapshot,
9
12
  } from "./generated/protocol.ts";
10
13
  import type { CheckedUpdatePort, UpdatePort, UpdateUnlisten } from "./ports.ts";
11
14
  import {
15
+ assertUpdateApplyCommand,
16
+ assertUpdateCancelCommand,
12
17
  assertUpdateChangedEvent,
13
18
  assertUpdateCheckCommand,
14
19
  assertUpdateDeferCommand,
15
- assertUpdateInstallCommand,
16
20
  assertUpdateOutcome,
21
+ assertUpdatePrepareCommand,
22
+ assertUpdateProgressEvent,
17
23
  assertUpdateSelectChannelCommand,
18
24
  assertUpdateSnapshot,
19
25
  } from "./validation.ts";
@@ -24,6 +30,9 @@ export class UpdateClient implements CheckedUpdatePort {
24
30
  async check(command: UpdateCheckCommand): Promise<UpdateOutcomeProjection> { assertUpdateCheckCommand(command); const value = await this.port.check(command); assertUpdateOutcome(value); return value; }
25
31
  async selectChannel(command: UpdateSelectChannelCommand): Promise<UpdateOutcomeProjection> { assertUpdateSelectChannelCommand(command); const value = await this.port.selectChannel(command); assertUpdateOutcome(value); return value; }
26
32
  async defer(command: UpdateDeferCommand): Promise<UpdateOutcomeProjection> { assertUpdateDeferCommand(command); const value = await this.port.defer(command); assertUpdateOutcome(value); return value; }
27
- async install(command: UpdateInstallCommand): Promise<UpdateOutcomeProjection> { assertUpdateInstallCommand(command); const value = await this.port.install(command); assertUpdateOutcome(value); return value; }
33
+ async prepare(command: UpdatePrepareCommand): Promise<UpdateOutcomeProjection> { assertUpdatePrepareCommand(command); const value = await this.port.prepare(command); assertUpdateOutcome(value); return value; }
34
+ async apply(command: UpdateApplyCommand): Promise<UpdateOutcomeProjection> { assertUpdateApplyCommand(command); const value = await this.port.apply(command); assertUpdateOutcome(value); return value; }
35
+ async cancel(command: UpdateCancelCommand): Promise<UpdateOutcomeProjection> { assertUpdateCancelCommand(command); const value = await this.port.cancel(command); assertUpdateOutcome(value); return value; }
28
36
  async listen(listener: (event: UpdateChangedEvent) => void): Promise<UpdateUnlisten> { if (this.port.listen === undefined) return () => {}; return this.port.listen((value) => { assertUpdateChangedEvent(value); listener(value); }); }
37
+ async listenProgress(listener: (event: UpdateProgressEvent) => void): Promise<UpdateUnlisten> { if (this.port.listenProgress === undefined) return () => {}; return this.port.listenProgress((value) => { assertUpdateProgressEvent(value); listener(value); }); }
29
38
  }
@@ -7,6 +7,7 @@ import {
7
7
  type UpdateProgressProjection,
8
8
  type UpdateRejectionCode,
9
9
  type UpdateSnapshot,
10
+ type UpdateStagedArtifactProjection,
10
11
  } from "./generated/protocol.ts";
11
12
  import type { UpdatePort, UpdateUnlisten } from "./ports.ts";
12
13
 
@@ -60,6 +61,15 @@ export class UpdateController {
60
61
  #lifecycle = 0;
61
62
  #pending = false;
62
63
  #unlisten: UpdateUnlisten[] = [];
64
+ /**
65
+ * The most recent live progress report.
66
+ *
67
+ * Held apart from the snapshot because it is *out of band*: a transfer
68
+ * publishes bytes while the controller's retained state still says what it
69
+ * said before the transfer began. It is cleared when the command that
70
+ * started the transfer settles, so a stale report cannot outlive it.
71
+ */
72
+ #liveProgress?: UpdateProgressProjection;
63
73
 
64
74
  constructor(options: UpdateControllerOptions) {
65
75
  this.#client = new UpdateClient(options.port);
@@ -68,7 +78,16 @@ export class UpdateController {
68
78
  get status(): UpdateControllerStatus { return this.#status; }
69
79
  get snapshot(): UpdateSnapshot | undefined { return this.#snapshot; }
70
80
  get availability(): UpdateAvailabilityProjection | undefined { return this.#snapshot?.availability; }
71
- get progress(): UpdateProgressProjection | undefined { return this.#snapshot?.progress; }
81
+ /**
82
+ * What the transfer is doing right now.
83
+ *
84
+ * A live report wins over the snapshot, because the snapshot is only as
85
+ * fresh as the last commit and the transfer deliberately does not hold the
86
+ * authority while it runs.
87
+ */
88
+ get progress(): UpdateProgressProjection | undefined { return this.#liveProgress ?? this.#snapshot?.progress; }
89
+ /** The retained verified artifact, when one is staged. */
90
+ get staged(): UpdateStagedArtifactProjection | undefined { return this.#snapshot?.staged ?? undefined; }
72
91
  get channel(): Channel | undefined { return this.#snapshot?.channel; }
73
92
  get installedVersion(): string | undefined { return this.#snapshot?.installedVersion; }
74
93
  get pending(): boolean { return this.#pending; }
@@ -123,7 +142,7 @@ export class UpdateController {
123
142
  const snapshot = this.#snapshot;
124
143
  if (snapshot === undefined) return "hidden";
125
144
 
126
- switch (snapshot.progress.state) {
145
+ switch (this.progress?.state) {
127
146
  case "downloading":
128
147
  case "verifying":
129
148
  case "installing":
@@ -131,6 +150,7 @@ export class UpdateController {
131
150
  case "readyToInstall":
132
151
  return "attention";
133
152
  case "idle":
153
+ case undefined:
134
154
  break;
135
155
  }
136
156
 
@@ -160,6 +180,16 @@ export class UpdateController {
160
180
  return;
161
181
  }
162
182
  this.#unlisten.push(unlisten);
183
+ const unlistenProgress = await this.#client.listenProgress((event) => {
184
+ if (!this.#started || lifecycle !== this.#lifecycle) return;
185
+ this.#liveProgress = event.progress;
186
+ this.#notify();
187
+ });
188
+ if (!this.#started || lifecycle !== this.#lifecycle) {
189
+ await unlistenProgress();
190
+ return;
191
+ }
192
+ this.#unlisten.push(unlistenProgress);
163
193
  await this.refresh();
164
194
  } catch (error) {
165
195
  if (this.#started && lifecycle === this.#lifecycle) this.#setStatus({ kind: "failed", error });
@@ -208,10 +238,29 @@ export class UpdateController {
208
238
  );
209
239
  }
210
240
 
211
- /** Fetches, verifies, gates and installs. */
212
- async install(version: string): Promise<void> {
241
+ /** Fetches, verifies and retains an update for a later apply. */
242
+ async prepare(version: string): Promise<void> {
243
+ await this.#command((client, epoch) =>
244
+ client.prepare({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch: epoch, version }),
245
+ );
246
+ }
247
+
248
+ /**
249
+ * Applies the retained staged artifact, replacing the application.
250
+ *
251
+ * A gate refusal is a deferral: the artifact stays staged and the surface
252
+ * can offer the restart again.
253
+ */
254
+ async apply(version: string): Promise<void> {
255
+ await this.#command((client, epoch) =>
256
+ client.apply({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch: epoch, version }),
257
+ );
258
+ }
259
+
260
+ /** Discards the retained staged artifact. */
261
+ async cancel(): Promise<void> {
213
262
  await this.#command((client, epoch) =>
214
- client.install({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch: epoch, version }),
263
+ client.cancel({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch: epoch }),
215
264
  );
216
265
  }
217
266
 
@@ -227,11 +276,13 @@ export class UpdateController {
227
276
  }
228
277
  const lifecycle = this.#lifecycle;
229
278
  this.#pending = true;
279
+ this.#liveProgress = undefined;
230
280
  this.#notify();
231
281
  try {
232
282
  const outcome = await run(this.#client, epoch);
233
283
  if (lifecycle !== this.#lifecycle) return;
234
284
  this.#snapshot = outcome.snapshot;
285
+ this.#liveProgress = undefined;
235
286
  this.#lastRejection = outcome.status === "rejected" ? outcome.code : undefined;
236
287
  this.#setStatus({ kind: "ready" });
237
288
  } catch (error) {
@@ -5,10 +5,14 @@
5
5
 
6
6
  export const UPDATE_FIELDS: Record<string, readonly string[]> = {
7
7
  "UpdateDeferralProjection": ["version", "cause"],
8
- "UpdateSnapshot": ["protocolVersion", "authorityEpoch", "channel", "installedVersion", "availability", "deferral", "progress"],
8
+ "UpdateStagedArtifactProjection": ["version", "channel", "digest"],
9
+ "UpdateProgressEvent": ["protocolVersion", "authorityEpoch", "progress"],
10
+ "UpdateSnapshot": ["protocolVersion", "authorityEpoch", "channel", "installedVersion", "availability", "deferral", "staged", "progress"],
9
11
  "UpdateCheckCommand": ["protocolVersion", "authorityEpoch"],
10
12
  "UpdateSelectChannelCommand": ["protocolVersion", "authorityEpoch", "channel"],
11
13
  "UpdateDeferCommand": ["protocolVersion", "authorityEpoch", "version", "cause"],
12
- "UpdateInstallCommand": ["protocolVersion", "authorityEpoch", "version"],
14
+ "UpdatePrepareCommand": ["protocolVersion", "authorityEpoch", "version"],
15
+ "UpdateApplyCommand": ["protocolVersion", "authorityEpoch", "version"],
16
+ "UpdateCancelCommand": ["protocolVersion", "authorityEpoch"],
13
17
  "UpdateChangedEvent": ["protocolVersion", "authorityEpoch", "kind"],
14
18
  };
@@ -9,7 +9,7 @@ export const UPDATE_INSTALL_MANAGERS = ["macAppStore","homebrewCask","flatpak","
9
9
  export const UPDATE_DEFERRAL_CAUSES = ["userPostponed","workInFlight","installationNotWritable","externallyManaged","installFailed"] as const;
10
10
  export const UPDATE_AVAILABILITY_STATES = ["offer","upToDate","aheadOfChannel","withheldByRollout","managedElsewhere"] as const;
11
11
  export const UPDATE_PROGRESS_STATES = ["idle","downloading","verifying","readyToInstall","installing"] as const;
12
- export const UPDATE_INSTALL_AUTHORIZATION_STATUSES = ["approved","deferred"] as const;
12
+ export const UPDATE_INSTALL_AUTHORIZATION_STATUSES = ["held","deferred"] as const;
13
13
  export const UPDATE_REJECTION_CODES = ["staleAuthority","noOffer","unavailable","channelMismatch","unreachable","signatureRejected","notWritable","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;
@@ -88,13 +88,37 @@ version: string,
88
88
  */
89
89
  cause: DeferralCause, };
90
90
 
91
+ export type UpdateStagedArtifactProjection = {
92
+ /**
93
+ * The version the bytes were verified for.
94
+ */
95
+ version: string,
96
+ /**
97
+ * The channel the bytes were fetched for.
98
+ */
99
+ channel: Channel,
100
+ /**
101
+ * SHA-256 of the verified bytes, lowercase hex.
102
+ */
103
+ digest: string, };
104
+
91
105
  export type UpdateProgressProjection = { "state": "idle" } | { "state": "downloading",
106
+ /**
107
+ * Bytes received so far.
108
+ */
109
+ received: number,
110
+ /**
111
+ * Bytes the source said to expect, when it said.
112
+ */
113
+ expected: number | null,
92
114
  /**
93
115
  * How far through, when the source reports a length.
94
116
  *
95
117
  * Absent rather than zero when it does not. A source with no content
96
118
  * length cannot produce a fraction, and a bar that invents one is
97
- * worse than a bar that says it does not know.
119
+ * worse than a bar that says it does not know. Kept on the wire beside
120
+ * the byte counts because the clamp and the absent case are the
121
+ * protocol's answer, not each surface's.
98
122
  */
99
123
  fraction: number | null, } | { "state": "verifying" } | { "state": "readyToInstall",
100
124
  /**
@@ -106,6 +130,20 @@ version: string, } | { "state": "installing",
106
130
  */
107
131
  version: string, };
108
132
 
133
+ export type UpdateProgressEvent = {
134
+ /**
135
+ * Exact metadata protocol line.
136
+ */
137
+ protocolVersion: UpdateProtocolVersion,
138
+ /**
139
+ * Live authority lifetime the transfer was started under.
140
+ */
141
+ authorityEpoch: number,
142
+ /**
143
+ * What the transfer reports right now.
144
+ */
145
+ progress: UpdateProgressProjection, };
146
+
109
147
  export type UpdateSnapshot = {
110
148
  /**
111
149
  * Exact metadata protocol line.
@@ -134,6 +172,13 @@ availability: UpdateAvailabilityProjection,
134
172
  * The standing deferral, when one applies.
135
173
  */
136
174
  deferral: UpdateDeferralProjection | null,
175
+ /**
176
+ * The retained verified artifact, when one is staged.
177
+ *
178
+ * Survives across calls: a deferred install keeps it, an explicit cancel
179
+ * discards it, and a verification failure never creates it.
180
+ */
181
+ staged: UpdateStagedArtifactProjection | null,
137
182
  /**
138
183
  * What is in flight.
139
184
  */
@@ -182,7 +227,21 @@ version: string,
182
227
  */
183
228
  cause: DeferralCause, };
184
229
 
185
- export type UpdateInstallCommand = {
230
+ export type UpdatePrepareCommand = {
231
+ /**
232
+ * Exact metadata protocol line.
233
+ */
234
+ protocolVersion: UpdateProtocolVersion,
235
+ /**
236
+ * Authority lifetime observed by the caller.
237
+ */
238
+ authorityEpoch: number,
239
+ /**
240
+ * The version to prepare.
241
+ */
242
+ version: string, };
243
+
244
+ export type UpdateApplyCommand = {
186
245
  /**
187
246
  * Exact metadata protocol line.
188
247
  */
@@ -192,13 +251,23 @@ protocolVersion: UpdateProtocolVersion,
192
251
  */
193
252
  authorityEpoch: number,
194
253
  /**
195
- * The version to install.
254
+ * The version the caller believes is staged.
196
255
  */
197
256
  version: string, };
198
257
 
199
- export type UpdateInstallAuthorizationProjection = { "status": "approved" } | { "status": "deferred",
258
+ export type UpdateCancelCommand = {
259
+ /**
260
+ * Exact metadata protocol line.
261
+ */
262
+ protocolVersion: UpdateProtocolVersion,
263
+ /**
264
+ * Authority lifetime observed by the caller.
265
+ */
266
+ authorityEpoch: number, };
267
+
268
+ export type UpdateInstallAuthorizationProjection = { "status": "held" } | { "status": "deferred",
200
269
  /**
201
- * What was in flight.
270
+ * What was in flight, or why the lease was refused.
202
271
  */
203
272
  cause: DeferralCause, };
204
273
 
@@ -20,13 +20,13 @@ export const UPDATE_VARIANT_FIELDS: Record<string, Record<string, readonly strin
20
20
  },
21
21
  "UpdateProgressProjection": {
22
22
  "idle": ["state"],
23
- "downloading": ["state", "fraction"],
23
+ "downloading": ["state", "received", "expected", "fraction"],
24
24
  "verifying": ["state"],
25
25
  "readyToInstall": ["state", "version"],
26
26
  "installing": ["state", "version"],
27
27
  },
28
28
  "UpdateInstallAuthorizationProjection": {
29
- "approved": ["status"],
29
+ "held": ["status"],
30
30
  "deferred": ["status", "cause"],
31
31
  },
32
32
  "UpdateOutcomeProjection": {
@@ -1,9 +1,12 @@
1
1
  import type {
2
+ UpdateApplyCommand,
3
+ UpdateCancelCommand,
2
4
  UpdateChangedEvent,
3
5
  UpdateCheckCommand,
4
6
  UpdateDeferCommand,
5
- UpdateInstallCommand,
6
7
  UpdateOutcomeProjection,
8
+ UpdatePrepareCommand,
9
+ UpdateProgressEvent,
7
10
  UpdateSelectChannelCommand,
8
11
  UpdateSnapshot,
9
12
  } from "./generated/protocol.ts";
@@ -21,8 +24,11 @@ export interface UpdatePort {
21
24
  check(command: UpdateCheckCommand): Promise<unknown>;
22
25
  selectChannel(command: UpdateSelectChannelCommand): Promise<unknown>;
23
26
  defer(command: UpdateDeferCommand): Promise<unknown>;
24
- install(command: UpdateInstallCommand): Promise<unknown>;
27
+ prepare(command: UpdatePrepareCommand): Promise<unknown>;
28
+ apply(command: UpdateApplyCommand): Promise<unknown>;
29
+ cancel(command: UpdateCancelCommand): Promise<unknown>;
25
30
  listen?(listener: (event: unknown) => void): UpdateUnlisten | Promise<UpdateUnlisten>;
31
+ listenProgress?(listener: (event: unknown) => void): UpdateUnlisten | Promise<UpdateUnlisten>;
26
32
  }
27
33
 
28
34
  /** The same seam after validation. */
@@ -31,6 +37,9 @@ export interface CheckedUpdatePort {
31
37
  check(command: UpdateCheckCommand): Promise<UpdateOutcomeProjection>;
32
38
  selectChannel(command: UpdateSelectChannelCommand): Promise<UpdateOutcomeProjection>;
33
39
  defer(command: UpdateDeferCommand): Promise<UpdateOutcomeProjection>;
34
- install(command: UpdateInstallCommand): Promise<UpdateOutcomeProjection>;
40
+ prepare(command: UpdatePrepareCommand): Promise<UpdateOutcomeProjection>;
41
+ apply(command: UpdateApplyCommand): Promise<UpdateOutcomeProjection>;
42
+ cancel(command: UpdateCancelCommand): Promise<UpdateOutcomeProjection>;
35
43
  listen(listener: (event: UpdateChangedEvent) => void): Promise<UpdateUnlisten>;
44
+ listenProgress(listener: (event: UpdateProgressEvent) => void): Promise<UpdateUnlisten>;
36
45
  }
@@ -1,4 +1,11 @@
1
- import type { UpdateCheckCommand, UpdateDeferCommand, UpdateInstallCommand, UpdateSelectChannelCommand } from "./generated/protocol.ts";
1
+ import type {
2
+ UpdateApplyCommand,
3
+ UpdateCancelCommand,
4
+ UpdateCheckCommand,
5
+ UpdateDeferCommand,
6
+ UpdatePrepareCommand,
7
+ UpdateSelectChannelCommand,
8
+ } from "./generated/protocol.ts";
2
9
  import type { UpdatePort, UpdateUnlisten } from "./ports.ts";
3
10
  export class SerializedUpdatePort implements UpdatePort {
4
11
  constructor(readonly inner: UpdatePort) {}
@@ -6,7 +13,10 @@ export class SerializedUpdatePort implements UpdatePort {
6
13
  async check(command: UpdateCheckCommand): Promise<unknown> { return clone(await this.inner.check(clone(command))); }
7
14
  async selectChannel(command: UpdateSelectChannelCommand): Promise<unknown> { return clone(await this.inner.selectChannel(clone(command))); }
8
15
  async defer(command: UpdateDeferCommand): Promise<unknown> { return clone(await this.inner.defer(clone(command))); }
9
- async install(command: UpdateInstallCommand): Promise<unknown> { return clone(await this.inner.install(clone(command))); }
16
+ async prepare(command: UpdatePrepareCommand): Promise<unknown> { return clone(await this.inner.prepare(clone(command))); }
17
+ async apply(command: UpdateApplyCommand): Promise<unknown> { return clone(await this.inner.apply(clone(command))); }
18
+ async cancel(command: UpdateCancelCommand): Promise<unknown> { return clone(await this.inner.cancel(clone(command))); }
10
19
  async listen(listener: (event: unknown) => void): Promise<UpdateUnlisten> { if (this.inner.listen === undefined) return () => {}; return this.inner.listen((event) => listener(clone(event))); }
20
+ async listenProgress(listener: (event: unknown) => void): Promise<UpdateUnlisten> { if (this.inner.listenProgress === undefined) return () => {}; return this.inner.listenProgress((event) => listener(clone(event))); }
11
21
  }
12
22
  function clone<T>(value: T): T { return JSON.parse(JSON.stringify(value)) as T; }
@@ -4,17 +4,22 @@ import {
4
4
  UPDATE_CHANGED_KINDS,
5
5
  UPDATE_CHANNELS,
6
6
  UPDATE_DEFERRAL_CAUSES,
7
+ UPDATE_INSTALL_AUTHORIZATION_STATUSES,
7
8
  UPDATE_INSTALL_MANAGERS,
8
9
  UPDATE_OFFER_REASONS,
9
10
  UPDATE_OUTCOME_STATUSES,
10
11
  UPDATE_PROGRESS_STATES,
11
12
  UPDATE_PROTOCOL_VERSION,
12
13
  UPDATE_REJECTION_CODES,
14
+ type UpdateApplyCommand,
15
+ type UpdateCancelCommand,
13
16
  type UpdateChangedEvent,
14
17
  type UpdateCheckCommand,
15
18
  type UpdateDeferCommand,
16
- type UpdateInstallCommand,
19
+ type UpdateInstallAuthorizationProjection,
17
20
  type UpdateOutcomeProjection,
21
+ type UpdatePrepareCommand,
22
+ type UpdateProgressEvent,
18
23
  type UpdateSelectChannelCommand,
19
24
  type UpdateSnapshot,
20
25
  } from "./generated/protocol.ts";
@@ -43,6 +48,13 @@ export function assertUpdateSnapshot(value: unknown): asserts value is UpdateSna
43
48
  version(root.installedVersion, "$.installedVersion");
44
49
  availability(root.availability, "$.availability");
45
50
  progress(root.progress, "$.progress");
51
+ if (root.staged !== null) {
52
+ const staged = object(root.staged, "$.staged");
53
+ exact(staged, "$.staged", UPDATE_FIELDS.UpdateStagedArtifactProjection);
54
+ version(staged.version, "$.staged.version");
55
+ oneOf(staged.channel, "$.staged.channel", UPDATE_CHANNELS);
56
+ digest(staged.digest, "$.staged.digest");
57
+ }
46
58
  if (root.deferral !== null) {
47
59
  const deferral = object(root.deferral, "$.deferral");
48
60
  exact(deferral, "$.deferral", UPDATE_FIELDS.UpdateDeferralProjection);
@@ -87,11 +99,48 @@ export function assertUpdateDeferCommand(value: unknown): asserts value is Updat
87
99
  cause(root.cause, "$.cause");
88
100
  }
89
101
 
90
- export function assertUpdateInstallCommand(value: unknown): asserts value is UpdateInstallCommand {
91
- commandBase(value, UPDATE_FIELDS.UpdateInstallCommand);
102
+ export function assertUpdatePrepareCommand(value: unknown): asserts value is UpdatePrepareCommand {
103
+ commandBase(value, UPDATE_FIELDS.UpdatePrepareCommand);
104
+ version(object(value, "$").version, "$.version");
105
+ }
106
+
107
+ export function assertUpdateApplyCommand(value: unknown): asserts value is UpdateApplyCommand {
108
+ commandBase(value, UPDATE_FIELDS.UpdateApplyCommand);
92
109
  version(object(value, "$").version, "$.version");
93
110
  }
94
111
 
112
+ export function assertUpdateCancelCommand(value: unknown): asserts value is UpdateCancelCommand {
113
+ commandBase(value, UPDATE_FIELDS.UpdateCancelCommand);
114
+ }
115
+
116
+ /**
117
+ * The live progress channel, which carries a report rather than an
118
+ * invalidation. It is the only thing that shows bytes while a transfer runs.
119
+ */
120
+ export function assertUpdateProgressEvent(value: unknown): asserts value is UpdateProgressEvent {
121
+ noPayload(value);
122
+ const root = object(value, "$");
123
+ exact(root, "$", UPDATE_FIELDS.UpdateProgressEvent);
124
+ protocol(root.protocolVersion, "$.protocolVersion");
125
+ positive(root.authorityEpoch, "$.authorityEpoch");
126
+ progress(root.progress, "$.progress");
127
+ }
128
+
129
+ /**
130
+ * The gate's answer: an exclusive admission lease is held, or the install was
131
+ * deferred with its reason. There is no fourth state, and no "approved" one —
132
+ * authorization is a held value, not a point-in-time flag.
133
+ */
134
+ export function assertUpdateInstallAuthorization(
135
+ value: unknown,
136
+ ): asserts value is UpdateInstallAuthorizationProjection {
137
+ noPayload(value);
138
+ const root = object(value, "$");
139
+ oneOf(root.status, "$.status", UPDATE_INSTALL_AUTHORIZATION_STATUSES);
140
+ exact(root, "$", variantFields("UpdateInstallAuthorizationProjection", root, "$"));
141
+ if (root.status === "deferred") cause(root.cause, "$.cause");
142
+ }
143
+
95
144
  function availability(value: unknown, path: string): void {
96
145
  const root = object(value, path);
97
146
  oneOf(root.state, `${path}.state`, UPDATE_AVAILABILITY_STATES);
@@ -123,7 +172,11 @@ function progress(value: unknown, path: string): void {
123
172
  // Absent rather than zero when the source declares no length. A validator
124
173
  // that coerced `null` to 0 here would put back the invented number the
125
174
  // protocol went out of its way to avoid.
126
- if (root.state === "downloading") fraction(root.fraction, `${path}.fraction`);
175
+ if (root.state === "downloading") {
176
+ count(root.received, `${path}.received`);
177
+ optionalCount(root.expected, `${path}.expected`);
178
+ fraction(root.fraction, `${path}.fraction`);
179
+ }
127
180
  if (root.state === "readyToInstall" || root.state === "installing") {
128
181
  version(root.version, `${path}.version`);
129
182
  }
@@ -182,6 +235,9 @@ function object(value: unknown, path: string): Record<string, unknown> { if (val
182
235
  function exact(value: Record<string, unknown>, path: string, expected: readonly string[]): void { const actual = Object.keys(value).sort(); const wanted = [...expected].sort(); if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) fail(path, `unexpected keys: ${actual.join(",")}`); }
183
236
  function protocol(value: unknown, path: string): void { if (value !== UPDATE_PROTOCOL_VERSION) fail(path, `expected exact protocol ${UPDATE_PROTOCOL_VERSION}`); }
184
237
  function positive(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) fail(path, "expected positive safe integer"); }
238
+ function count(value: unknown, path: string): void { if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) fail(path, "expected a non-negative safe byte count"); }
239
+ function optionalCount(value: unknown, path: string): void { if (value !== null) count(value, path); }
240
+ function digest(value: unknown, path: string): void { if (typeof value !== "string" || !/^[0-9a-f]{64}$/.test(value)) fail(path, "expected 64 lowercase hex digits"); }
185
241
  function string(value: unknown, path: string): void { if (typeof value !== "string") fail(path, "expected string"); }
186
242
  function optionalString(value: unknown, path: string): void { if (value !== null) string(value, path); }
187
243
  /** Versions are strings on the wire, as `semver::Version` serialises them. */