@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.
- package/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/selection.ts +10 -8
- package/src/agent-control/shim.ts +149 -77
- package/src/bridge/generated/fields.ts +1 -1
- package/src/bridge/generated/protocol.ts +55 -4
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -2
- package/src/bridge/runtime/connection.ts +11 -14
- package/src/bridge/stream/connection.ts +14 -23
- package/src/bridge/stream/tracker.ts +5 -0
- package/src/bridge/supervision.ts +102 -80
- package/src/bridge/validation/base.ts +7 -27
- package/src/bridge/validation/negotiation.ts +1 -6
- package/src/bridge/validation/operations.ts +2 -14
- package/src/commands/client.ts +16 -2
- package/src/commands/controller.ts +96 -58
- package/src/commands/generated/fields.ts +4 -4
- package/src/commands/generated/protocol.ts +24 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +4 -13
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +2 -1
- package/src/commands/projectors.ts +52 -29
- package/src/commands/validation.ts +408 -188
- package/src/config/client.ts +3 -3
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +2 -1
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/validation/commands.ts +11 -13
- package/src/config/validation/outcomes.ts +147 -46
- package/src/config/validation/primitives.ts +11 -39
- package/src/config/validation/projection.ts +44 -44
- package/src/core/connection.ts +124 -29
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +76 -0
- package/src/core/transport.ts +10 -1
- package/src/core/wire-copy.ts +1 -0
- package/src/history/client.ts +11 -7
- package/src/history/controller.ts +72 -74
- package/src/history/generated/fields.ts +2 -1
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -2
- package/src/history/validation.ts +15 -37
- package/src/history-tree/client.ts +15 -13
- package/src/history-tree/controller.ts +131 -90
- package/src/history-tree/generated/fields.ts +3 -1
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +9 -4
- package/src/history-tree/validation.ts +44 -35
- package/src/layout/generated/protocol.ts +2 -1
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +9 -2
- package/src/layout/validation.ts +88 -13
- package/src/licence/client.ts +11 -7
- package/src/licence/controller.ts +64 -43
- package/src/licence/generated/fields.ts +2 -1
- package/src/licence/generated/protocol.ts +8 -4
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +2 -6
- package/src/licence/ports.ts +7 -2
- package/src/licence/validation.ts +27 -20
- package/src/native-content/client.ts +32 -1
- package/src/native-content/generated/fields.ts +4 -4
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +2 -1
- package/src/native-content/validation/base.ts +16 -46
- package/src/native-content/validation/messages.ts +3 -0
- package/src/notifications/client.ts +17 -39
- package/src/notifications/controller.ts +266 -165
- package/src/notifications/generated/fields.ts +2 -1
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +2 -1
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +41 -51
- package/src/operation/bridge.ts +79 -19
- package/src/operation/client.ts +17 -45
- package/src/operation/controller.ts +38 -59
- package/src/operation/generated/fields.ts +2 -1
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +2 -1
- package/src/operation/validation.ts +48 -50
- package/src/settings/connection.ts +10 -14
- package/src/settings/generated/fields.ts +2 -1
- package/src/settings/generated/protocol.ts +5 -1
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/validation/authority.ts +2 -2
- package/src/settings/validation/command.ts +5 -4
- package/src/settings/validation/primitives.ts +32 -67
- package/src/settings/validation/registry.ts +13 -11
- package/src/surface-transfer/generated/fields.ts +1 -1
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +76 -53
- package/src/surfaces/client.ts +26 -38
- package/src/surfaces/generated/fields.ts +1 -1
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +198 -61
- package/src/transfer/connection.ts +25 -39
- package/src/transfer/generated/fields.ts +2 -1
- package/src/transfer/generated/protocol.ts +9 -1
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +12 -9
- package/src/transfer/validation.ts +146 -60
- package/src/update/client.ts +43 -16
- package/src/update/controller.ts +187 -104
- package/src/update/generated/fields.ts +2 -1
- package/src/update/generated/protocol.ts +19 -7
- package/src/update/generated/variant-fields.ts +3 -2
- package/src/update/ports.ts +11 -7
- package/src/update/serialized.ts +8 -6
- package/src/update/validation.ts +18 -28
package/src/update/controller.ts
CHANGED
|
@@ -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
|
|
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
|
|
61
|
-
*
|
|
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
|
-
#
|
|
76
|
-
#lifecycle =
|
|
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
|
-
*
|
|
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
|
-
*
|
|
146
|
-
*
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
230
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
this.#lifecycle
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
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 (
|
|
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 (
|
|
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,
|
|
275
|
-
client.check({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch
|
|
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,
|
|
280
|
+
return this.#command((client, { authorityEpoch }) =>
|
|
282
281
|
client.selectChannel({
|
|
283
282
|
protocolVersion: UPDATE_PROTOCOL_VERSION,
|
|
284
|
-
authorityEpoch
|
|
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,
|
|
292
|
+
(client, { authorityEpoch }) =>
|
|
294
293
|
client.defer({
|
|
295
294
|
protocolVersion: UPDATE_PROTOCOL_VERSION,
|
|
296
|
-
authorityEpoch
|
|
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,
|
|
307
|
-
client.
|
|
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(
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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,
|
|
335
|
-
client.cancel({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
|
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
|
|
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
|
-
? {
|
|
366
|
-
|
|
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 (
|
|
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 (
|
|
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:
|
|
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:
|
|
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": "
|
|
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:
|
|
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
|
|
package/src/update/ports.ts
CHANGED
|
@@ -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 =
|
|
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(
|
|
48
|
-
|
|
49
|
+
listen(
|
|
50
|
+
listener: (event: UpdateChangedEvent) => void,
|
|
51
|
+
onFailure?: ConnectionFailureReporter,
|
|
52
|
+
): Promise<UpdateUnlisten>;
|
|
49
53
|
}
|
package/src/update/serialized.ts
CHANGED
|
@@ -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
|
}
|