@inflatable-cookie/longhorn 0.5.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/inject.ts +4 -1
- package/src/agent-control/selection.ts +42 -25
- package/src/agent-control/shim.ts +428 -198
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +4 -3
- package/src/bridge/generated/protocol.ts +62 -7
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -12
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +78 -109
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +24 -55
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +12 -12
- package/src/bridge/supervision.ts +104 -97
- package/src/bridge/validation/base.ts +21 -63
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +28 -43
- package/src/bridge/validation/operations.ts +29 -65
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +37 -28
- package/src/commands/controller.ts +119 -96
- package/src/commands/generated/fields.ts +7 -6
- package/src/commands/generated/protocol.ts +28 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +94 -100
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +8 -13
- package/src/commands/projectors.ts +100 -75
- package/src/commands/validation.ts +434 -241
- package/src/config/client.ts +9 -22
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +4 -3
- 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/names.ts +6 -12
- package/src/config/validation/commands.ts +11 -25
- package/src/config/validation/outcomes.ts +163 -70
- package/src/config/validation/primitives.ts +35 -80
- package/src/config/validation/projection.ts +100 -128
- package/src/core/connection.ts +187 -83
- 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 +80 -0
- package/src/core/transport.ts +9 -11
- package/src/core/wire-copy.ts +7 -0
- package/src/history/client.ts +11 -13
- package/src/history/controller.ts +106 -108
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +4 -3
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -4
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +69 -75
- package/src/history-tree/client.ts +89 -11
- package/src/history-tree/controller.ts +380 -96
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +5 -3
- 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 +12 -5
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +286 -78
- package/src/layout/generated/protocol.ts +4 -3
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +10 -9
- package/src/layout/validation.ts +98 -32
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +48 -7
- package/src/licence/controller.ts +127 -70
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +4 -3
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +9 -5
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +42 -18
- package/src/licence/ports.ts +10 -3
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +134 -43
- package/src/native-content/client.ts +207 -234
- package/src/native-content/generated/fields.ts +6 -6
- 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 +11 -16
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -80
- package/src/native-content/validation/messages.ts +24 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +85 -51
- package/src/notifications/controller.ts +400 -145
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +4 -3
- 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 +9 -4
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +165 -71
- package/src/operation/bridge.ts +187 -60
- package/src/operation/client.ts +48 -62
- package/src/operation/controller.ts +67 -97
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +4 -3
- 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 +12 -10
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +189 -104
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +35 -53
- package/src/settings/generated/fields.ts +5 -4
- package/src/settings/generated/protocol.ts +14 -5
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +21 -19
- package/src/settings/validation/command.ts +22 -41
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +46 -97
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +33 -79
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +3 -3
- 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 +91 -86
- package/src/surfaces/client.ts +33 -55
- package/src/surfaces/generated/fields.ts +3 -3
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +227 -99
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +29 -51
- package/src/transfer/generated/fields.ts +7 -6
- package/src/transfer/generated/protocol.ts +13 -5
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +20 -35
- package/src/transfer/validation.ts +169 -119
- package/src/update/client.ts +86 -9
- package/src/update/controller.ts +264 -116
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +5 -4
- package/src/update/generated/protocol.ts +25 -9
- package/src/update/generated/variant-fields.ts +4 -2
- package/src/update/ports.ts +14 -6
- package/src/update/serialized.ts +36 -10
- package/src/update/validation.ts +118 -48
package/src/update/controller.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import type { ConnectionFailureReporter } from "../core/connection.ts";
|
|
2
|
+
import { ControllerLifecycle } from "../core/controller-lifecycle.ts";
|
|
1
3
|
import { UpdateClient } from "./client.ts";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import { UPDATE_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
5
|
+
import type {
|
|
6
|
+
Channel,
|
|
7
|
+
DeferralCause,
|
|
8
|
+
UpdateAvailabilityProjection,
|
|
9
|
+
UpdateOutcomeProjection,
|
|
10
|
+
UpdateProgressEvent,
|
|
11
|
+
UpdateProgressProjection,
|
|
12
|
+
UpdateRejectionCode,
|
|
13
|
+
UpdateSnapshot,
|
|
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
|
|
@@ -71,12 +73,12 @@ export class UpdateController {
|
|
|
71
73
|
readonly #observers = new Set<() => void>();
|
|
72
74
|
#status: UpdateControllerStatus = { kind: "idle" };
|
|
73
75
|
#snapshot?: UpdateSnapshot;
|
|
74
|
-
#lastRejection
|
|
75
|
-
#
|
|
76
|
-
#lifecycle =
|
|
76
|
+
#lastRejection: UpdateRejectionCode | undefined;
|
|
77
|
+
#lastRejectionDetail: string | null = null;
|
|
78
|
+
readonly #lifecycle = new ControllerLifecycle();
|
|
77
79
|
#commandSequence = 0;
|
|
80
|
+
#refreshRevision = 0;
|
|
78
81
|
#pending = false;
|
|
79
|
-
#unlisten: UpdateUnlisten[] = [];
|
|
80
82
|
/**
|
|
81
83
|
* The most recent live progress report.
|
|
82
84
|
*
|
|
@@ -85,15 +87,21 @@ export class UpdateController {
|
|
|
85
87
|
* said before the transfer began. It is cleared when the command that
|
|
86
88
|
* started the transfer settles, so a stale report cannot outlive it.
|
|
87
89
|
*/
|
|
88
|
-
#liveProgress
|
|
90
|
+
#liveProgress: UpdateProgressProjection | undefined;
|
|
89
91
|
|
|
90
92
|
constructor(options: UpdateControllerOptions) {
|
|
91
93
|
this.#client = new UpdateClient(options.port);
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
get status(): UpdateControllerStatus {
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
get status(): UpdateControllerStatus {
|
|
97
|
+
return this.#lifecycle.eventFailure ?? this.#status;
|
|
98
|
+
}
|
|
99
|
+
get snapshot(): UpdateSnapshot | undefined {
|
|
100
|
+
return this.#snapshot;
|
|
101
|
+
}
|
|
102
|
+
get availability(): UpdateAvailabilityProjection | undefined {
|
|
103
|
+
return this.#snapshot?.availability;
|
|
104
|
+
}
|
|
97
105
|
/**
|
|
98
106
|
* What the transfer is doing right now.
|
|
99
107
|
*
|
|
@@ -101,38 +109,53 @@ export class UpdateController {
|
|
|
101
109
|
* fresh as the last commit and the transfer deliberately does not hold the
|
|
102
110
|
* authority while it runs.
|
|
103
111
|
*/
|
|
104
|
-
get progress(): UpdateProgressProjection | undefined {
|
|
112
|
+
get progress(): UpdateProgressProjection | undefined {
|
|
113
|
+
return this.#liveProgress ?? this.#snapshot?.progress;
|
|
114
|
+
}
|
|
105
115
|
/** The retained verified artifact, when one is staged. */
|
|
106
|
-
get staged(): UpdateStagedArtifactProjection | undefined {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
get
|
|
116
|
+
get staged(): UpdateStagedArtifactProjection | undefined {
|
|
117
|
+
return this.#snapshot?.staged ?? undefined;
|
|
118
|
+
}
|
|
119
|
+
get channel(): Channel | undefined {
|
|
120
|
+
return this.#snapshot?.channel;
|
|
121
|
+
}
|
|
122
|
+
get installedVersion(): string | undefined {
|
|
123
|
+
return this.#snapshot?.installedVersion;
|
|
124
|
+
}
|
|
125
|
+
get pending(): boolean {
|
|
126
|
+
return this.#pending;
|
|
127
|
+
}
|
|
110
128
|
|
|
111
129
|
/**
|
|
112
130
|
* Why the last install did not proceed, when it did not.
|
|
113
131
|
*
|
|
114
|
-
*
|
|
115
|
-
* restart shows its reason and is not a failure.
|
|
132
|
+
* The reason a committed command postponed installation.
|
|
116
133
|
*/
|
|
117
134
|
get deferral(): { readonly version: string; readonly cause: DeferralCause } | undefined {
|
|
118
135
|
return this.#snapshot?.deferral ?? undefined;
|
|
119
136
|
}
|
|
120
137
|
|
|
121
138
|
/** The latest refusal, cleared as soon as the next command starts. */
|
|
122
|
-
get lastRejection(): UpdateRejectionCode | undefined {
|
|
139
|
+
get lastRejection(): UpdateRejectionCode | undefined {
|
|
140
|
+
return this.#lastRejection;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Installer detail from the latest rejection, when supplied. */
|
|
144
|
+
get lastRejectionDetail(): string | null {
|
|
145
|
+
return this.#lastRejectionDetail;
|
|
146
|
+
}
|
|
123
147
|
|
|
124
148
|
/**
|
|
125
149
|
* Whether this install sits ahead of the channel it follows.
|
|
126
150
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* receives nothing until `1.3.0` ships, which is correct and reads as a
|
|
130
|
-
* broken updater unless the surface says so. Exposed as its own read so a
|
|
131
|
-
* 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.
|
|
132
153
|
*/
|
|
133
154
|
get aheadOfChannel(): { readonly installed: string; readonly channel: string } | undefined {
|
|
134
155
|
const availability = this.#snapshot?.availability;
|
|
135
|
-
if (availability?.state !== "aheadOfChannel")
|
|
156
|
+
if (availability?.state !== "aheadOfChannel") {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
136
159
|
return { installed: availability.installed, channel: availability.channel };
|
|
137
160
|
}
|
|
138
161
|
|
|
@@ -156,7 +179,9 @@ export class UpdateController {
|
|
|
156
179
|
*/
|
|
157
180
|
get presence(): UpdatePresence {
|
|
158
181
|
const snapshot = this.#snapshot;
|
|
159
|
-
if (snapshot === undefined)
|
|
182
|
+
if (snapshot === undefined) {
|
|
183
|
+
return "hidden";
|
|
184
|
+
}
|
|
160
185
|
|
|
161
186
|
switch (this.progress?.state) {
|
|
162
187
|
case "downloading":
|
|
@@ -170,7 +195,9 @@ export class UpdateController {
|
|
|
170
195
|
break;
|
|
171
196
|
}
|
|
172
197
|
|
|
173
|
-
if (snapshot.availability.state !== "offer")
|
|
198
|
+
if (snapshot.availability.state !== "offer") {
|
|
199
|
+
return "hidden";
|
|
200
|
+
}
|
|
174
201
|
// Postponed by the operator, not by the gate. A gate deferral is transient
|
|
175
202
|
// and the offer is still the answer; `userPostponed` is a decision.
|
|
176
203
|
return snapshot.deferral?.cause.cause === "userPostponed" ? "quiet" : "attention";
|
|
@@ -181,84 +208,110 @@ export class UpdateController {
|
|
|
181
208
|
return () => this.#observers.delete(observer);
|
|
182
209
|
}
|
|
183
210
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
this.#
|
|
199
|
-
|
|
200
|
-
if (!this.#started || lifecycle !== this.#lifecycle) return;
|
|
201
|
-
this.#liveProgress = event.progress;
|
|
202
|
-
this.#notify();
|
|
203
|
-
});
|
|
204
|
-
if (!this.#started || lifecycle !== this.#lifecycle) {
|
|
205
|
-
await unlistenProgress();
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
this.#unlisten.push(unlistenProgress);
|
|
209
|
-
await this.refresh();
|
|
210
|
-
} catch (error) {
|
|
211
|
-
if (this.#started && lifecycle === this.#lifecycle) this.#setStatus({ kind: "failed", error });
|
|
212
|
-
}
|
|
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();
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
failed: (error) => this.#setStatus({ kind: "failed", error }),
|
|
226
|
+
});
|
|
213
227
|
}
|
|
214
228
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.#lifecycle
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
});
|
|
222
244
|
}
|
|
223
245
|
|
|
224
246
|
async refresh(): Promise<void> {
|
|
225
|
-
|
|
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;
|
|
226
254
|
try {
|
|
227
255
|
const snapshot = await this.#client.snapshot();
|
|
228
|
-
if (
|
|
256
|
+
if (!isCurrent()) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (snapshot.authorityEpoch !== this.#snapshot?.authorityEpoch) {
|
|
260
|
+
this.#liveProgress = undefined;
|
|
261
|
+
}
|
|
229
262
|
this.#snapshot = snapshot;
|
|
230
263
|
this.#setStatus({ kind: "ready" });
|
|
231
264
|
} catch (error) {
|
|
232
|
-
if (
|
|
265
|
+
if (isCurrent()) {
|
|
266
|
+
this.#setStatus({ kind: "failed", error });
|
|
267
|
+
}
|
|
233
268
|
}
|
|
234
269
|
}
|
|
235
270
|
|
|
236
271
|
/** Asks the source for the channel's current manifest. */
|
|
237
272
|
async check(): Promise<UpdateCommandOutcome> {
|
|
238
|
-
return this.#command((client,
|
|
239
|
-
client.check({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch
|
|
273
|
+
return this.#command((client, { authorityEpoch }) =>
|
|
274
|
+
client.check({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch }),
|
|
240
275
|
);
|
|
241
276
|
}
|
|
242
277
|
|
|
243
278
|
/** Follows a different channel from now on. */
|
|
244
279
|
async selectChannel(channel: Channel): Promise<UpdateCommandOutcome> {
|
|
245
|
-
return this.#command((client,
|
|
246
|
-
client.selectChannel({
|
|
280
|
+
return this.#command((client, { authorityEpoch }) =>
|
|
281
|
+
client.selectChannel({
|
|
282
|
+
protocolVersion: UPDATE_PROTOCOL_VERSION,
|
|
283
|
+
authorityEpoch,
|
|
284
|
+
channel,
|
|
285
|
+
}),
|
|
247
286
|
);
|
|
248
287
|
}
|
|
249
288
|
|
|
250
289
|
/** Declines a version for now. */
|
|
251
290
|
async defer(version: string, cause: DeferralCause): Promise<UpdateCommandOutcome> {
|
|
252
|
-
return this.#command(
|
|
253
|
-
client
|
|
254
|
-
|
|
291
|
+
return this.#command(
|
|
292
|
+
(client, { authorityEpoch }) =>
|
|
293
|
+
client.defer({
|
|
294
|
+
protocolVersion: UPDATE_PROTOCOL_VERSION,
|
|
295
|
+
authorityEpoch,
|
|
296
|
+
version,
|
|
297
|
+
cause,
|
|
298
|
+
}),
|
|
299
|
+
{ committedMayDefer: true },
|
|
255
300
|
);
|
|
256
301
|
}
|
|
257
302
|
|
|
258
303
|
/** Fetches, verifies and retains an update for a later apply. */
|
|
259
304
|
async prepare(version: string): Promise<UpdateCommandOutcome> {
|
|
260
|
-
return this.#command((client,
|
|
261
|
-
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
|
+
),
|
|
262
315
|
);
|
|
263
316
|
}
|
|
264
317
|
|
|
@@ -266,64 +319,133 @@ export class UpdateController {
|
|
|
266
319
|
* Applies the retained staged artifact, replacing the application.
|
|
267
320
|
*
|
|
268
321
|
* A gate refusal is a deferral: the artifact stays staged and the surface
|
|
269
|
-
* 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.
|
|
270
324
|
*/
|
|
271
325
|
async apply(version: string): Promise<UpdateCommandOutcome> {
|
|
272
|
-
return this.#command(
|
|
273
|
-
client
|
|
274
|
-
|
|
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
|
+
},
|
|
275
340
|
);
|
|
276
341
|
}
|
|
277
342
|
|
|
278
343
|
/** Discards the retained staged artifact. */
|
|
279
344
|
async cancel(): Promise<UpdateCommandOutcome> {
|
|
280
|
-
return this.#command((client,
|
|
281
|
-
client.cancel({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch
|
|
345
|
+
return this.#command((client, { authorityEpoch }) =>
|
|
346
|
+
client.cancel({ protocolVersion: UPDATE_PROTOCOL_VERSION, authorityEpoch }),
|
|
282
347
|
);
|
|
283
348
|
}
|
|
284
349
|
|
|
285
350
|
async #command(
|
|
286
|
-
run: (
|
|
287
|
-
|
|
351
|
+
run: (
|
|
352
|
+
client: UpdateClient,
|
|
353
|
+
snapshot: UpdateSnapshot,
|
|
354
|
+
progress: {
|
|
355
|
+
readonly report: (event: UpdateProgressEvent) => void;
|
|
356
|
+
readonly fail: ConnectionFailureReporter;
|
|
357
|
+
},
|
|
358
|
+
) => Promise<UpdateOutcomeProjection>,
|
|
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
|
+
} = {},
|
|
288
364
|
): Promise<UpdateCommandOutcome> {
|
|
289
|
-
|
|
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
|
+
}
|
|
290
369
|
this.#lastRejection = undefined;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
370
|
+
this.#lastRejectionDetail = null;
|
|
371
|
+
const snapshot = this.#snapshot;
|
|
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) {
|
|
296
382
|
this.#setStatus({ kind: "failed", error });
|
|
297
383
|
return { status: "failed", error };
|
|
298
384
|
}
|
|
299
|
-
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
|
+
};
|
|
300
408
|
this.#pending = true;
|
|
301
409
|
this.#liveProgress = undefined;
|
|
302
410
|
this.#notify();
|
|
303
411
|
try {
|
|
304
|
-
const outcome = await run(this.#client,
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
412
|
+
const outcome = await run(this.#client, snapshot, {
|
|
413
|
+
report: reportProgress,
|
|
414
|
+
fail: failProgress,
|
|
415
|
+
});
|
|
416
|
+
const result: UpdateCommandOutcome =
|
|
417
|
+
outcome.status === "rejected"
|
|
418
|
+
? {
|
|
419
|
+
status: "rejected",
|
|
420
|
+
snapshot: outcome.snapshot,
|
|
421
|
+
code: outcome.code,
|
|
422
|
+
detail: outcome.detail,
|
|
423
|
+
}
|
|
424
|
+
: options.committedMayDefer && outcome.snapshot.deferral !== null
|
|
425
|
+
? {
|
|
426
|
+
status: "committedWithDeferral",
|
|
427
|
+
snapshot: outcome.snapshot,
|
|
428
|
+
deferral: outcome.snapshot.deferral,
|
|
429
|
+
}
|
|
430
|
+
: { status: "committed", snapshot: outcome.snapshot };
|
|
431
|
+
if (isCurrent()) {
|
|
432
|
+
this.#pending = false;
|
|
433
|
+
this.#refreshRevision += 1;
|
|
311
434
|
this.#snapshot = outcome.snapshot;
|
|
312
435
|
this.#liveProgress = undefined;
|
|
313
436
|
this.#lastRejection = result.status === "rejected" ? result.code : undefined;
|
|
437
|
+
this.#lastRejectionDetail = result.status === "rejected" ? result.detail : null;
|
|
314
438
|
this.#setStatus({ kind: "ready" });
|
|
315
439
|
}
|
|
316
440
|
return result;
|
|
317
441
|
} catch (error) {
|
|
318
|
-
if (
|
|
442
|
+
if (isCurrent()) {
|
|
443
|
+
this.#refreshRevision += 1;
|
|
444
|
+
this.#pending = false;
|
|
445
|
+
this.#liveProgress = undefined;
|
|
319
446
|
this.#setStatus({ kind: "failed", error });
|
|
320
447
|
}
|
|
321
448
|
return { status: "failed", error };
|
|
322
|
-
} finally {
|
|
323
|
-
if (lifecycle === this.#lifecycle && commandSequence === this.#commandSequence) {
|
|
324
|
-
this.#pending = false;
|
|
325
|
-
this.#notify();
|
|
326
|
-
}
|
|
327
449
|
}
|
|
328
450
|
}
|
|
329
451
|
|
|
@@ -333,6 +455,32 @@ export class UpdateController {
|
|
|
333
455
|
}
|
|
334
456
|
|
|
335
457
|
#notify(): void {
|
|
336
|
-
for (const observer of this.#observers)
|
|
458
|
+
for (const observer of this.#observers) {
|
|
459
|
+
observer();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
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);
|
|
337
484
|
}
|
|
485
|
+
return staged;
|
|
338
486
|
}
|
package/src/update/direct.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { UpdatePort } from "./ports.ts";
|
|
2
2
|
export type DirectUpdateHandlers = UpdatePort;
|
|
3
|
-
export function createDirectUpdatePort(handlers: DirectUpdateHandlers): UpdatePort {
|
|
3
|
+
export function createDirectUpdatePort(handlers: DirectUpdateHandlers): UpdatePort {
|
|
4
|
+
return handlers;
|
|
5
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
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.
|
|
5
5
|
|
|
6
|
-
export const UPDATE_FIELDS
|
|
6
|
+
export const UPDATE_FIELDS = {
|
|
7
7
|
"UpdateDeferralProjection": ["version", "cause"],
|
|
8
8
|
"UpdateStagedArtifactProjection": ["version", "channel", "digest"],
|
|
9
9
|
"UpdateProgressEvent": ["protocolVersion", "authorityEpoch", "progress"],
|
|
@@ -12,7 +12,8 @@ export const UPDATE_FIELDS: Record<string, readonly string[]> = {
|
|
|
12
12
|
"UpdateSelectChannelCommand": ["protocolVersion", "authorityEpoch", "channel"],
|
|
13
13
|
"UpdateDeferCommand": ["protocolVersion", "authorityEpoch", "version", "cause"],
|
|
14
14
|
"UpdatePrepareCommand": ["protocolVersion", "authorityEpoch", "version"],
|
|
15
|
-
"UpdateApplyCommand": ["protocolVersion", "authorityEpoch", "version"],
|
|
15
|
+
"UpdateApplyCommand": ["protocolVersion", "authorityEpoch", "version", "digest"],
|
|
16
16
|
"UpdateCancelCommand": ["protocolVersion", "authorityEpoch"],
|
|
17
17
|
"UpdateChangedEvent": ["protocolVersion", "authorityEpoch", "kind"],
|
|
18
|
-
|
|
18
|
+
"UpdateHostError": ["code", "message", "retryable"],
|
|
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 = ["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
|
/**
|
|
@@ -44,7 +44,7 @@ command: string | null, } | { "cause": "installFailed",
|
|
|
44
44
|
*/
|
|
45
45
|
detail: string, };
|
|
46
46
|
|
|
47
|
-
export type UpdateAvailabilityProjection = { "state": "offer",
|
|
47
|
+
export type UpdateAvailabilityProjection = { "state": "notChecked" } | { "state": "offer",
|
|
48
48
|
/**
|
|
49
49
|
* The version offered.
|
|
50
50
|
*/
|
|
@@ -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
|
*/
|
|
@@ -253,7 +257,11 @@ authorityEpoch: number,
|
|
|
253
257
|
/**
|
|
254
258
|
* The version the caller believes is staged.
|
|
255
259
|
*/
|
|
256
|
-
version: string,
|
|
260
|
+
version: string,
|
|
261
|
+
/**
|
|
262
|
+
* SHA-256 of the staged bytes observed by the caller, lowercase hex.
|
|
263
|
+
*/
|
|
264
|
+
digest: string, };
|
|
257
265
|
|
|
258
266
|
export type UpdateCancelCommand = {
|
|
259
267
|
/**
|
|
@@ -271,7 +279,7 @@ export type UpdateInstallAuthorizationProjection = { "status": "held" } | { "sta
|
|
|
271
279
|
*/
|
|
272
280
|
cause: DeferralCause, };
|
|
273
281
|
|
|
274
|
-
export type UpdateRejectionCode = "staleAuthority" | "noOffer" | "unavailable" | "channelMismatch" | "unreachable" | "signatureRejected" | "notWritable" | "installFailed";
|
|
282
|
+
export type UpdateRejectionCode = "staleAuthority" | "noOffer" | "unavailable" | "channelMismatch" | "unreachable" | "signatureRejected" | "notWritable" | "malformedArtifact" | "installFailed";
|
|
275
283
|
|
|
276
284
|
export type UpdateOutcomeProjection = { "status": "committed",
|
|
277
285
|
/**
|
|
@@ -282,6 +290,10 @@ snapshot: UpdateSnapshot, } | { "status": "rejected",
|
|
|
282
290
|
* What a surface should tell the operator.
|
|
283
291
|
*/
|
|
284
292
|
code: UpdateRejectionCode,
|
|
293
|
+
/**
|
|
294
|
+
* Installer detail with common credential shapes redacted, when supplied.
|
|
295
|
+
*/
|
|
296
|
+
detail: string | null,
|
|
285
297
|
/**
|
|
286
298
|
* The state as it remains.
|
|
287
299
|
*/
|
|
@@ -305,3 +317,7 @@ authorityEpoch: number,
|
|
|
305
317
|
* Coarse invalidation category.
|
|
306
318
|
*/
|
|
307
319
|
kind: UpdateChangedKind, };
|
|
320
|
+
|
|
321
|
+
export type UpdateHostErrorCode = "authorityUnavailable" | "stateUnavailable" | "eventPublication";
|
|
322
|
+
|
|
323
|
+
export type UpdateHostError = { "code": UpdateHostErrorCode, "message": string, "retryable": boolean, };
|