@gjsify/cli 0.64.44 → 0.64.45
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/dist/cli.gjs.mjs +14 -11
- package/lib/commands/webext/index.js +3 -2
- package/lib/commands/webext/subcommands.d.ts +9 -0
- package/lib/commands/webext/subcommands.js +54 -0
- package/lib/utils/webext/stores/poll.d.ts +167 -0
- package/lib/utils/webext/stores/poll.js +450 -0
- package/lib/utils/webext/submit.d.ts +41 -0
- package/lib/utils/webext/submit.js +146 -0
- package/package.json +20 -20
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
// The bounded poll/retry layer of `gjsify webext submit`: ONE drive over a
|
|
2
|
+
// {@link StoreBackend} that carries a version from upload to a CLASSIFIED end
|
|
3
|
+
// state, and returns a pure value the subcommand only has to print.
|
|
4
|
+
//
|
|
5
|
+
// WHY A LAYER AND NOT A LOOP PER BACKEND. Both store APIs answer a write before
|
|
6
|
+
// they have done it (ADR 0077 § Amendment 1): Chrome's `:upload` answers a
|
|
7
|
+
// `uploadState` and the real account is `:fetchStatus`'s `lastAsyncUploadState`,
|
|
8
|
+
// which is only set for uploads from the past 24 h; Edge answers `202 Accepted`
|
|
9
|
+
// with an operation id in `Location` and nothing in the body at all. That is the
|
|
10
|
+
// same shape as npm's accepted-but-not-durable PUT, and `utils/publish-readback.ts`'s
|
|
11
|
+
// rule carries over unchanged: NEVER claim what was not established. A store
|
|
12
|
+
// that said "accepted" and then never resolved is its OWN outcome here — not a
|
|
13
|
+
// success, and not a rejection either.
|
|
14
|
+
//
|
|
15
|
+
// So the backends poll nothing (both files say so in their headers) and this
|
|
16
|
+
// file owns every wait: one deadline, one backoff, an injected clock, and no
|
|
17
|
+
// `setTimeout` anywhere a test can reach.
|
|
18
|
+
//
|
|
19
|
+
// THE END STATES AND THEIR EXIT CODES — the table the ADR amendment repeats:
|
|
20
|
+
//
|
|
21
|
+
// code | verdict | what it means | re-run?
|
|
22
|
+
// -----+----------------+-------------------------------------------------+--------
|
|
23
|
+
// 0 | uploaded | the draft holds this version; no publish asked | —
|
|
24
|
+
// 0 | submitted | the store confirms a submission for this version | —
|
|
25
|
+
// 0 | published | the store reports this version live | —
|
|
26
|
+
// 0 | already-there | the store was ALREADY on this version | —
|
|
27
|
+
// 0 | in-review | a submission is in review; this run changed none | later
|
|
28
|
+
// 1 | rejected | the store refused it (4xx, a failed operation) | no
|
|
29
|
+
// 1 | failed | a repeatable failure that did not stop repeating | yes
|
|
30
|
+
// 3 | unresolved | accepted and never resolved inside the deadline | yes
|
|
31
|
+
// 4 | unverifiable | the store gave a handle this client cannot read | no
|
|
32
|
+
//
|
|
33
|
+
// `0` for `in-review` is a DECISION, argued at {@link SUBMIT_EXIT_CODES}.
|
|
34
|
+
// `2` is deliberately absent: `cli-fail.ts` owns it for a usage error, and an
|
|
35
|
+
// exit code that means two things is one nobody can branch on.
|
|
36
|
+
//
|
|
37
|
+
// WHICH FAILURES MAY BE REPEATED — two independent questions, and collapsing
|
|
38
|
+
// them is how a release submits twice:
|
|
39
|
+
//
|
|
40
|
+
// 1. IS THE FAILURE CLASS REPEATABLE? ({@link isRepeatableFailure})
|
|
41
|
+
// transport, no HTTP answer nothing was established → repeatable
|
|
42
|
+
// 408, 429 the store asked for later → repeatable
|
|
43
|
+
// 5xx the store's side failed → repeatable
|
|
44
|
+
// 4xx except 408/429 its VERDICT on this request → never
|
|
45
|
+
// a failed operation its verdict on this package → never
|
|
46
|
+
// (Edge reports the last one as a 2xx body with `status: Failed`, which the
|
|
47
|
+
// backend already turns into a `StoreApiError` carrying HTTP 200 — not a
|
|
48
|
+
// repeatable class, which is the right answer for a package the store
|
|
49
|
+
// looked at and rejected.)
|
|
50
|
+
//
|
|
51
|
+
// 2. MAY THIS VERB REPEAT IT? ({@link retryDecision})
|
|
52
|
+
// a `status`/`operation` GET a read; a repeat costs one request
|
|
53
|
+
// the `upload` POST writes the DRAFT, a slot and not a queue
|
|
54
|
+
// entry: the same zip twice leaves the same
|
|
55
|
+
// draft, so a repeat costs bytes and nothing
|
|
56
|
+
// else
|
|
57
|
+
// the `publish` POST CREATES a submission. After a transport
|
|
58
|
+
// failure it is NEVER repeated blind — only
|
|
59
|
+
// `status()` may decide whether it arrived,
|
|
60
|
+
// and only a status that PROVES it did not
|
|
61
|
+
// (the store still holds a draft) buys one
|
|
62
|
+
// replay. A status that establishes nothing
|
|
63
|
+
// ends the drive at `unresolved`, because a
|
|
64
|
+
// re-run of the whole command starts from a
|
|
65
|
+
// status read and is therefore the safe retry.
|
|
66
|
+
//
|
|
67
|
+
// Nothing in here has been run against a live store. Every transition is read
|
|
68
|
+
// off the two vendor references (ADR 0077 § Amendment 1, `DOCUMENTED`), so the
|
|
69
|
+
// states this file does not recognise end at `unresolved` or `unverifiable`
|
|
70
|
+
// rather than at a guess.
|
|
71
|
+
import { isIdempotentSkip, redactSecrets, StoreApiError, StoreInReviewError, StoreVersionAlreadyThereError, } from './index.js';
|
|
72
|
+
/**
|
|
73
|
+
* Exit code per verdict. The three decisions in it:
|
|
74
|
+
*
|
|
75
|
+
* **`in-review` exits 0.** The alternative — its own non-zero code — was
|
|
76
|
+
* considered and rejected. The state means the PREVIOUS submit worked and the
|
|
77
|
+
* store is busy with it; nothing in this run failed, nothing was corrupted, and
|
|
78
|
+
* the way out (Chrome's `:cancelSubmission`; Edge documents none) is the
|
|
79
|
+
* person's decision and never this command's. The step that calls `submit` sits
|
|
80
|
+
* behind a GitHub Environment with a required reviewer, so a red there costs a
|
|
81
|
+
* human a re-run of a workflow that did its job — and a check that cries wolf
|
|
82
|
+
* is one somebody switches off, the lesson `publish-readback.ts` paid for. What
|
|
83
|
+
* keeps that honest is that exit 0 here never CLAIMS a submission: the verdict
|
|
84
|
+
* is its own value, `detail` names which version is blocking, and a caller that
|
|
85
|
+
* wants a red can read `verdict` and decide. The plan behind this slice and
|
|
86
|
+
* ADR 0077 § Amendment 1 both say the same ("three outcomes, not one non-zero
|
|
87
|
+
* exit"), so this is also the already-recorded decision.
|
|
88
|
+
*
|
|
89
|
+
* **`failed` and `rejected` share exit 1** — the operator's next move is the
|
|
90
|
+
* same, look at `detail` — while `unresolved` gets its own code, because its
|
|
91
|
+
* next move is the opposite one: call again later, unchanged, and expect
|
|
92
|
+
* progress. Those two must never be one number.
|
|
93
|
+
*
|
|
94
|
+
* **`2` is not in this table.** `cli-app.ts`'s `.fail()` handler exits 2 for a
|
|
95
|
+
* usage error, so a store outcome spelled 2 would be indistinguishable from a
|
|
96
|
+
* mistyped flag.
|
|
97
|
+
*/
|
|
98
|
+
export const SUBMIT_EXIT_CODES = {
|
|
99
|
+
uploaded: 0,
|
|
100
|
+
submitted: 0,
|
|
101
|
+
published: 0,
|
|
102
|
+
'already-there': 0,
|
|
103
|
+
'in-review': 0,
|
|
104
|
+
rejected: 1,
|
|
105
|
+
failed: 1,
|
|
106
|
+
unresolved: 3,
|
|
107
|
+
unverifiable: 4,
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Verdicts where calling again later can make progress on its own.
|
|
111
|
+
*
|
|
112
|
+
* `rejected` is absent on purpose: the package or the listing has to change
|
|
113
|
+
* first. `unverifiable` is absent too — a re-run meets the same missing
|
|
114
|
+
* capability; what has to change is the backend.
|
|
115
|
+
*/
|
|
116
|
+
const RETRYABLE_VERDICTS = ['in-review', 'failed', 'unresolved'];
|
|
117
|
+
/* ---------------------------------------------------------------------- budgets */
|
|
118
|
+
/**
|
|
119
|
+
* Default deadline for the whole drive: 600 s.
|
|
120
|
+
*
|
|
121
|
+
* What this waits for is INGESTION and the resolution of an operation, never a
|
|
122
|
+
* review verdict — a review takes days at both stores and no CI job may sit on
|
|
123
|
+
* one. 600 s is `publish-readback.ts`'s budget, chosen there against measured
|
|
124
|
+
* registry lag; nothing comparable has been measured against a store, so the
|
|
125
|
+
* number is borrowed rather than derived, and `--timeout` is what a real
|
|
126
|
+
* observation changes. A non-positive value waits not at all: every async step
|
|
127
|
+
* is read exactly once and an unfinished one ends the drive at `unresolved`.
|
|
128
|
+
*/
|
|
129
|
+
export const DEFAULT_SUBMIT_TIMEOUT_MS = 600_000;
|
|
130
|
+
/**
|
|
131
|
+
* Delay before poll `round + 2`; past the end the last value repeats.
|
|
132
|
+
*
|
|
133
|
+
* Same shape and same reason as `publish-readback.ts`'s table: an ingest that is
|
|
134
|
+
* already done answers on the first read, so the first wait is short, and a tail
|
|
135
|
+
* measured in minutes is not worth probing finely.
|
|
136
|
+
*/
|
|
137
|
+
const POLL_BACKOFF_MS = [2_000, 4_000, 8_000, 15_000, 30_000];
|
|
138
|
+
/** Delay before retry `round + 1` of a repeatable failure. */
|
|
139
|
+
const RETRY_BACKOFF_MS = [1_000, 2_000, 4_000];
|
|
140
|
+
/**
|
|
141
|
+
* Delay before retry `round + 1` of a THROTTLED request.
|
|
142
|
+
*
|
|
143
|
+
* A 429 answered after one second is still a 429: retrying on the ordinary
|
|
144
|
+
* table would spend all three attempts inside the window the store asked us to
|
|
145
|
+
* stay out of. Neither backend reads `Retry-After` today, so this table is the
|
|
146
|
+
* only thing standing in for it — the header is the obvious next refinement and
|
|
147
|
+
* is written down here rather than left to be rediscovered.
|
|
148
|
+
*/
|
|
149
|
+
const THROTTLE_BACKOFF_MS = [5_000, 15_000, 30_000];
|
|
150
|
+
/** How often a repeatable failure of one call is repeated before the drive gives up. */
|
|
151
|
+
export const MAX_SAFE_RETRIES = 3;
|
|
152
|
+
/**
|
|
153
|
+
* How often a `publish` POST may be sent again after a transport failure —
|
|
154
|
+
* once, and only on a `status()` that PROVED the first one did not arrive.
|
|
155
|
+
*/
|
|
156
|
+
const MAX_PUBLISH_REPLAYS = 1;
|
|
157
|
+
const stepFrom = (table, round) => table[Math.min(Math.max(round, 0), table.length - 1)] ?? table[table.length - 1] ?? 0;
|
|
158
|
+
/** Delay before the poll after `round` (0-based). */
|
|
159
|
+
export function pollBackoffFor(round) {
|
|
160
|
+
return stepFrom(POLL_BACKOFF_MS, round);
|
|
161
|
+
}
|
|
162
|
+
/** Delay before retry `round` (0-based) of a repeatable failure; throttling gets its own, longer table. */
|
|
163
|
+
export function retryBackoffFor(round, throttled) {
|
|
164
|
+
return stepFrom(throttled ? THROTTLE_BACKOFF_MS : RETRY_BACKOFF_MS, round);
|
|
165
|
+
}
|
|
166
|
+
/** HTTP statuses that mean "later", not "no". */
|
|
167
|
+
const RETRY_AFTER_STATUSES = [408, 429];
|
|
168
|
+
/**
|
|
169
|
+
* Is this failure's CLASS one that a repeat of the same request could survive?
|
|
170
|
+
*
|
|
171
|
+
* Only {@link StoreApiError} can be: the two idempotent skips are answers, not
|
|
172
|
+
* failures, and anything else reaching here is a defect in this client, which a
|
|
173
|
+
* repeat cannot fix.
|
|
174
|
+
*/
|
|
175
|
+
export function isRepeatableFailure(error) {
|
|
176
|
+
if (!(error instanceof StoreApiError))
|
|
177
|
+
return false;
|
|
178
|
+
const status = error.httpStatus;
|
|
179
|
+
// No status at all: the request never produced an HTTP answer, so nothing
|
|
180
|
+
// about it was established — including, for a write, whether it arrived.
|
|
181
|
+
if (status === undefined)
|
|
182
|
+
return true;
|
|
183
|
+
if (RETRY_AFTER_STATUSES.includes(status))
|
|
184
|
+
return true;
|
|
185
|
+
return status >= 500 && status < 600;
|
|
186
|
+
}
|
|
187
|
+
/** True for the failure class whose remedy is specifically "wait longer than usual". */
|
|
188
|
+
export function isThrottled(error) {
|
|
189
|
+
return error instanceof StoreApiError && error.httpStatus === 429;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* What to do about `error` from `verb`.
|
|
193
|
+
*
|
|
194
|
+
* The asymmetry between the two POSTs is the whole point: an `upload` writes the
|
|
195
|
+
* draft, which is a SLOT — sending the same zip twice leaves the same draft, so
|
|
196
|
+
* a repeat costs bytes. A `publish` CREATES a submission, so a repeat after a
|
|
197
|
+
* transport failure risks a second one against a store that already took the
|
|
198
|
+
* first; `status()` is the only thing allowed to decide that.
|
|
199
|
+
*/
|
|
200
|
+
export function retryDecision(error, verb) {
|
|
201
|
+
if (!isRepeatableFailure(error))
|
|
202
|
+
return 'fatal';
|
|
203
|
+
if (verb !== 'publish')
|
|
204
|
+
return 'retry';
|
|
205
|
+
// A publish whose failure carries an HTTP status DID reach the store and was
|
|
206
|
+
// answered (429, 503): nothing was created, so the same request is safe.
|
|
207
|
+
// One with no status may or may not have arrived.
|
|
208
|
+
return error instanceof StoreApiError && error.httpStatus === undefined ? 'verify-first' : 'retry';
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Drive one version into one store and say what the store ended up at.
|
|
212
|
+
*
|
|
213
|
+
* upload → wait for the ingest → publish → wait for the submission, each step
|
|
214
|
+
* bounded by ONE shared deadline: two budgets would make the wall clock twice
|
|
215
|
+
* what `--timeout` promises, the same mistake `probeTimeoutFor` was written to
|
|
216
|
+
* stop in the read-back.
|
|
217
|
+
*/
|
|
218
|
+
export async function driveSubmission(input, options = {}) {
|
|
219
|
+
const { backend } = input;
|
|
220
|
+
const version = input.upload.version;
|
|
221
|
+
const now = options.now ?? (() => Date.now());
|
|
222
|
+
const sleep = options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
223
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_SUBMIT_TIMEOUT_MS;
|
|
224
|
+
const secrets = options.secrets ?? [];
|
|
225
|
+
const started = now();
|
|
226
|
+
const phases = [];
|
|
227
|
+
let requests = 0;
|
|
228
|
+
let retries = 0;
|
|
229
|
+
let phaseRequests = 0;
|
|
230
|
+
const clean = (text) => redactSecrets(text, secrets);
|
|
231
|
+
const note = (msg) => options.log?.(clean(`gjsify webext submit: ${msg}`));
|
|
232
|
+
const remaining = () => timeoutMs - (now() - started);
|
|
233
|
+
const endPhase = (phase, detail) => {
|
|
234
|
+
phases.push({ phase, requests: phaseRequests, elapsedMs: now() - started, detail: clean(detail) });
|
|
235
|
+
phaseRequests = 0;
|
|
236
|
+
};
|
|
237
|
+
const finish = (verdict, detail) => ({
|
|
238
|
+
store: backend.store,
|
|
239
|
+
version,
|
|
240
|
+
verdict,
|
|
241
|
+
exitCode: SUBMIT_EXIT_CODES[verdict],
|
|
242
|
+
detail: clean(detail),
|
|
243
|
+
phases,
|
|
244
|
+
elapsedMs: now() - started,
|
|
245
|
+
requests,
|
|
246
|
+
retries,
|
|
247
|
+
retryable: RETRYABLE_VERDICTS.includes(verdict),
|
|
248
|
+
});
|
|
249
|
+
/** The terminal verdict for an error, after every retry it was entitled to. */
|
|
250
|
+
const fromError = (phase, error, exhausted) => {
|
|
251
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
252
|
+
endPhase(phase, message);
|
|
253
|
+
if (error instanceof StoreVersionAlreadyThereError)
|
|
254
|
+
return finish('already-there', message);
|
|
255
|
+
if (error instanceof StoreInReviewError)
|
|
256
|
+
return finish('in-review', message);
|
|
257
|
+
if (exhausted) {
|
|
258
|
+
return finish('failed', `${message} — repeated ${MAX_SAFE_RETRIES}x or until the ${timeoutMs} ms deadline; the failure class is repeatable, so calling again later may work.`);
|
|
259
|
+
}
|
|
260
|
+
return finish('rejected', message);
|
|
261
|
+
};
|
|
262
|
+
/** One call to the backend, with the retries its verb and the failure's class allow. */
|
|
263
|
+
const call = async (verb, run) => {
|
|
264
|
+
for (let round = 0;; round++) {
|
|
265
|
+
requests++;
|
|
266
|
+
phaseRequests++;
|
|
267
|
+
try {
|
|
268
|
+
return { kind: 'value', value: await run() };
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
if (isIdempotentSkip(error))
|
|
272
|
+
return { kind: 'error', error, exhausted: false };
|
|
273
|
+
const decision = retryDecision(error, verb);
|
|
274
|
+
if (decision === 'fatal')
|
|
275
|
+
return { kind: 'error', error, exhausted: false };
|
|
276
|
+
if (decision === 'verify-first')
|
|
277
|
+
return { kind: 'lost', error };
|
|
278
|
+
const left = remaining();
|
|
279
|
+
if (round >= MAX_SAFE_RETRIES || left <= 0)
|
|
280
|
+
return { kind: 'error', error, exhausted: true };
|
|
281
|
+
const wait = Math.min(retryBackoffFor(round, isThrottled(error)), left);
|
|
282
|
+
note(`${verb} failed with a repeatable error, retry ${round + 1} of ${MAX_SAFE_RETRIES} in ${wait} ms — ` +
|
|
283
|
+
(error instanceof Error ? error.message : String(error)));
|
|
284
|
+
retries++;
|
|
285
|
+
await sleep(wait);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Does a status answer speak about OUR version?
|
|
291
|
+
*
|
|
292
|
+
* A store reporting `published` for some other version says nothing about
|
|
293
|
+
* this one, and reporting it as ours would be exactly the claim neither this
|
|
294
|
+
* file nor `publish-readback.ts` is allowed to make. A status that names no
|
|
295
|
+
* version at all is accepted: Edge's `status()` answers about the operation
|
|
296
|
+
* this run created, so there is no other submission it could be about.
|
|
297
|
+
*/
|
|
298
|
+
const aboutOurVersion = (status) => status.version === undefined || status.version === version;
|
|
299
|
+
/**
|
|
300
|
+
* Wait for an asynchronous step to resolve, through whichever account the
|
|
301
|
+
* backend has of it.
|
|
302
|
+
*
|
|
303
|
+
* `operation()` when the backend declares one — Edge's two operation GETs —
|
|
304
|
+
* else `status()`, which is what Chrome's `lastAsyncUploadState` needs. A
|
|
305
|
+
* backend with neither account of a HANDLE the store issued cannot resolve
|
|
306
|
+
* it at all; that is `unverifiable` and is decided before a single poll, not
|
|
307
|
+
* after a deadline, because waiting would only make a capability gap look
|
|
308
|
+
* like a slow store.
|
|
309
|
+
*/
|
|
310
|
+
const waitFor = async (kind, phase, operationId, seed) => {
|
|
311
|
+
const readOperation = backend.operation;
|
|
312
|
+
if (readOperation === undefined && operationId !== undefined && kind === 'publish') {
|
|
313
|
+
// `status()` can only speak about the product's own state. A store
|
|
314
|
+
// that answers a publish with an operation id AND NOTHING ELSE
|
|
315
|
+
// (Edge's `202`) therefore leaves a backend without `operation()`
|
|
316
|
+
// with nothing to read — and the publish was ACCEPTED, so this is
|
|
317
|
+
// neither a success nor a failure.
|
|
318
|
+
endPhase(phase, seed);
|
|
319
|
+
return {
|
|
320
|
+
kind: 'end',
|
|
321
|
+
result: finish('unverifiable', `${seed} The publish was accepted and the ${backend.store} backend declares no operation() to read ${operationId} with, ` +
|
|
322
|
+
`so whether a submission exists cannot be established from here. It may well be in review — check the dashboard; the fix is operation() on that backend.`),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
for (let round = 0;; round++) {
|
|
326
|
+
if (readOperation !== undefined && operationId !== undefined) {
|
|
327
|
+
const read = await call('read', () => readOperation.call(backend, kind, operationId, version));
|
|
328
|
+
if (read.kind === 'error')
|
|
329
|
+
return { kind: 'end', result: fromError(phase, read.error, read.exhausted) };
|
|
330
|
+
if (read.kind === 'value' && read.value.state === 'succeeded') {
|
|
331
|
+
return { kind: 'done', detail: read.value.detail };
|
|
332
|
+
}
|
|
333
|
+
if (read.kind === 'value')
|
|
334
|
+
note(`${kind} operation ${operationId}: ${read.value.detail}`);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
const read = await call('read', () => backend.status());
|
|
338
|
+
if (read.kind === 'error')
|
|
339
|
+
return { kind: 'end', result: fromError(phase, read.error, read.exhausted) };
|
|
340
|
+
if (read.kind === 'value') {
|
|
341
|
+
const status = read.value;
|
|
342
|
+
if (status.state === 'rejected') {
|
|
343
|
+
endPhase(phase, status.detail);
|
|
344
|
+
return { kind: 'end', result: finish('rejected', status.detail) };
|
|
345
|
+
}
|
|
346
|
+
if (kind === 'upload' && status.ingesting !== true) {
|
|
347
|
+
return { kind: 'done', detail: status.detail };
|
|
348
|
+
}
|
|
349
|
+
if (kind === 'publish' && aboutOurVersion(status)) {
|
|
350
|
+
if (status.state === 'published' || status.state === 'in-review') {
|
|
351
|
+
return { kind: 'done', detail: status.detail };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
note(`status while waiting for the ${kind}: ${status.detail}`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
const left = remaining();
|
|
358
|
+
if (left <= 0) {
|
|
359
|
+
const detail = `the ${kind} was accepted and had not resolved after ${now() - started} ms` +
|
|
360
|
+
(operationId === undefined ? '' : ` (operation ${operationId})`) +
|
|
361
|
+
`. Nothing is lost: call \`gjsify webext submit\` again — it reads the store's state first and will report ` +
|
|
362
|
+
`"already there" or "in review" if this one landed meanwhile. Raise --timeout to wait longer.`;
|
|
363
|
+
endPhase(phase, detail);
|
|
364
|
+
return { kind: 'end', result: finish('unresolved', detail) };
|
|
365
|
+
}
|
|
366
|
+
await sleep(Math.min(pollBackoffFor(round), left));
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
/* ----------------------------------------------------------------- upload */
|
|
370
|
+
note(`${backend.store}: uploading ${version} from ${input.upload.zipPath}`);
|
|
371
|
+
const uploaded = await call('upload', () => backend.upload(input.upload));
|
|
372
|
+
if (uploaded.kind === 'error')
|
|
373
|
+
return fromError('upload', uploaded.error, uploaded.exhausted);
|
|
374
|
+
if (uploaded.kind === 'lost') {
|
|
375
|
+
// Unreachable: `retryDecision` only answers `verify-first` for `publish`.
|
|
376
|
+
// Kept as a type-level total case, not as a runtime guard.
|
|
377
|
+
return fromError('upload', uploaded.error, false);
|
|
378
|
+
}
|
|
379
|
+
endPhase('upload', uploaded.value.detail);
|
|
380
|
+
if (!uploaded.value.ingested) {
|
|
381
|
+
const ingest = await waitFor('upload', 'await-upload', uploaded.value.operationId, uploaded.value.detail);
|
|
382
|
+
if (ingest.kind === 'end')
|
|
383
|
+
return ingest.result;
|
|
384
|
+
endPhase('await-upload', ingest.detail);
|
|
385
|
+
}
|
|
386
|
+
if (input.publish === undefined) {
|
|
387
|
+
return finish('uploaded', `${version} is in the ${backend.store} draft and was NOT submitted — pass --submit to ask for review.`);
|
|
388
|
+
}
|
|
389
|
+
/* ---------------------------------------------------------------- publish */
|
|
390
|
+
const publishInput = input.publish;
|
|
391
|
+
let replays = 0;
|
|
392
|
+
for (;;) {
|
|
393
|
+
note(`${backend.store}: asking for review of ${version}`);
|
|
394
|
+
const published = await call('publish', () => backend.publish(publishInput));
|
|
395
|
+
if (published.kind === 'error')
|
|
396
|
+
return fromError('publish', published.error, published.exhausted);
|
|
397
|
+
if (published.kind === 'lost') {
|
|
398
|
+
// THE ONE PLACE A WRITE'S OUTCOME IS UNKNOWN. No resend until the
|
|
399
|
+
// store itself says the first one is not there.
|
|
400
|
+
const message = published.error instanceof Error ? published.error.message : String(published.error);
|
|
401
|
+
note(`the publish request got no answer (${message}) — asking the store whether it arrived`);
|
|
402
|
+
const confirm = await call('read', () => backend.status());
|
|
403
|
+
if (confirm.kind !== 'value') {
|
|
404
|
+
// `lost` cannot happen for a read — `retryDecision` answers
|
|
405
|
+
// `verify-first` only for `publish`. Narrowed, not guarded.
|
|
406
|
+
return fromError('publish', confirm.error, confirm.kind === 'error' && confirm.exhausted);
|
|
407
|
+
}
|
|
408
|
+
const status = confirm.value;
|
|
409
|
+
if (status.state === 'rejected') {
|
|
410
|
+
endPhase('publish', status.detail);
|
|
411
|
+
return finish('rejected', status.detail);
|
|
412
|
+
}
|
|
413
|
+
if (aboutOurVersion(status) && (status.state === 'in-review' || status.state === 'published')) {
|
|
414
|
+
endPhase('publish', status.detail);
|
|
415
|
+
return finish(status.state === 'published' ? 'published' : 'submitted', `the publish request got no answer, and the store reports it arrived: ${status.detail}`);
|
|
416
|
+
}
|
|
417
|
+
if (status.state === 'draft' &&
|
|
418
|
+
aboutOurVersion(status) &&
|
|
419
|
+
replays < MAX_PUBLISH_REPLAYS &&
|
|
420
|
+
remaining() > 0) {
|
|
421
|
+
// PROVEN not to have arrived: the store still holds a draft and
|
|
422
|
+
// no submission for it. One replay, counted as a retry.
|
|
423
|
+
replays++;
|
|
424
|
+
retries++;
|
|
425
|
+
note(`the store still holds a draft (${status.detail}) — sending the publish request once more`);
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
const detail = `the publish request got no answer (${message}) and the store's own state does not say whether it arrived: ` +
|
|
429
|
+
`${status.detail}. The request was NOT repeated — a second one would risk a second submission. ` +
|
|
430
|
+
`Call \`gjsify webext submit\` again once the store settles; it reads the state first.`;
|
|
431
|
+
endPhase('publish', detail);
|
|
432
|
+
return finish('unresolved', detail);
|
|
433
|
+
}
|
|
434
|
+
const result = published.value;
|
|
435
|
+
endPhase('publish', result.detail);
|
|
436
|
+
if (result.state === 'rejected')
|
|
437
|
+
return finish('rejected', result.detail);
|
|
438
|
+
if (result.state === 'published')
|
|
439
|
+
return finish('published', result.detail);
|
|
440
|
+
if (result.state === 'in-review')
|
|
441
|
+
return finish('submitted', result.detail);
|
|
442
|
+
// `draft` or `unknown`: Edge always answers this way (its `202` carries
|
|
443
|
+
// no state at all), and Chrome's `:publish` may answer without one.
|
|
444
|
+
const settled = await waitFor('publish', 'await-publish', result.operationId, result.detail);
|
|
445
|
+
if (settled.kind === 'end')
|
|
446
|
+
return settled.result;
|
|
447
|
+
endPhase('await-publish', settled.detail);
|
|
448
|
+
return finish('submitted', settled.detail);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type EnvLike, type StoreBackend, type StoreBackendOptions, type StoreId } from './stores/index.js';
|
|
2
|
+
import type { WebextTarget } from './targets.js';
|
|
3
|
+
/** The slice of `ResolvedWebext` this command reads, so a spec needs no project on disk. */
|
|
4
|
+
export interface SubmitProject {
|
|
5
|
+
readonly root: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly version: string;
|
|
8
|
+
readonly outDir: string;
|
|
9
|
+
readonly targets: readonly WebextTarget[];
|
|
10
|
+
}
|
|
11
|
+
export interface SubmitCommandInput {
|
|
12
|
+
readonly store: string;
|
|
13
|
+
/** Absolute or cwd-relative zip; default is what `webext zip` writes for the store's target. */
|
|
14
|
+
readonly zip?: string;
|
|
15
|
+
readonly dryRun: boolean;
|
|
16
|
+
readonly submit: boolean;
|
|
17
|
+
readonly timeoutSeconds?: number;
|
|
18
|
+
/** Where `webext listing` wrote its output (default `dist/listing` under the project root). */
|
|
19
|
+
readonly listingDir?: string;
|
|
20
|
+
readonly project: SubmitProject;
|
|
21
|
+
readonly env: EnvLike;
|
|
22
|
+
readonly createBackend?: (store: StoreId, env: EnvLike, options?: StoreBackendOptions) => StoreBackend;
|
|
23
|
+
readonly fetchImpl?: typeof fetch;
|
|
24
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
25
|
+
readonly now?: () => number;
|
|
26
|
+
readonly out: (line: string) => void;
|
|
27
|
+
readonly err: (line: string) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare function isTagRef(ref: string | undefined): boolean;
|
|
30
|
+
/** The zip `webext zip` writes for this store's target (see `buildWebext`). */
|
|
31
|
+
export declare function defaultZipPath(project: SubmitProject, store: StoreId): string;
|
|
32
|
+
export interface StoreJsonPreflight {
|
|
33
|
+
/** Reasons to stop. Empty = go. */
|
|
34
|
+
readonly problems: readonly string[];
|
|
35
|
+
/** Fields only the person can fill in the dashboard; informational. */
|
|
36
|
+
readonly manual: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
/** Checks a `store.json` text against what `StoreManifest` promises; pure so a spec needs no disk. */
|
|
39
|
+
export declare function preflightStoreJson(text: string, listingStore: string, path: string): StoreJsonPreflight;
|
|
40
|
+
/** Runs the command and returns its exit code (`SUBMIT_EXIT_CODES` for a drive, 1 for any refusal). */
|
|
41
|
+
export declare function runSubmit(input: SubmitCommandInput): Promise<number>;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// The logic of `gjsify webext submit` (ADR 0077 § Amendment 1): every refusal that
|
|
2
|
+
// needs no network, in the order that keeps a bad run away from the store, then
|
|
3
|
+
// ONE call into the poll layer. The subcommand in `commands/webext/subcommands.ts`
|
|
4
|
+
// only builds a {@link SubmitProject} and prints nothing itself.
|
|
5
|
+
//
|
|
6
|
+
// ORDER, because a refusal after a network call is a refusal too late:
|
|
7
|
+
// store known and implemented → `--submit` only on a tag → `store.json`
|
|
8
|
+
// preflight → zip exists (upload only) → credentials → [dry-run: one read]
|
|
9
|
+
// or [drive: upload, optionally publish].
|
|
10
|
+
//
|
|
11
|
+
// `store.json` is a PREFLIGHT, never a payload (ADR 0135): neither store takes
|
|
12
|
+
// listing text through its API, so nothing from it is sent. It only stops a
|
|
13
|
+
// release whose listing the dashboard would refuse a day later.
|
|
14
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
15
|
+
import { join, resolve } from 'node:path';
|
|
16
|
+
import { asStoreId, createStoreBackend, redactSecrets, STORE_CREDENTIALS, StoreUnsupportedError, STORES, } from './stores/index.js';
|
|
17
|
+
import { driveSubmission, SUBMIT_EXIT_CODES } from './stores/poll.js';
|
|
18
|
+
/** `webext listing` names the Chrome store `cws`. */
|
|
19
|
+
const LISTING_STORE = { chrome: 'cws', edge: 'edge' };
|
|
20
|
+
export function isTagRef(ref) {
|
|
21
|
+
return ref !== undefined && ref.startsWith('refs/tags/') && ref.length > 'refs/tags/'.length;
|
|
22
|
+
}
|
|
23
|
+
/** The zip `webext zip` writes for this store's target (see `buildWebext`). */
|
|
24
|
+
export function defaultZipPath(project, store) {
|
|
25
|
+
const target = project.targets.find((t) => t.browser === store);
|
|
26
|
+
if (target === undefined) {
|
|
27
|
+
throw new Error(`gjsify webext submit: gjsify.webext.targets has no ${store} target, so there is no zip to derive. ` +
|
|
28
|
+
`Add ${store}-mv3 or pass --zip.`);
|
|
29
|
+
}
|
|
30
|
+
return join(project.outDir, `${project.name}-${project.version}-${target.id}.zip`);
|
|
31
|
+
}
|
|
32
|
+
/** Checks a `store.json` text against what `StoreManifest` promises; pure so a spec needs no disk. */
|
|
33
|
+
export function preflightStoreJson(text, listingStore, path) {
|
|
34
|
+
let json;
|
|
35
|
+
try {
|
|
36
|
+
json = JSON.parse(text);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return { problems: [`${path} is not valid JSON — regenerate it with \`gjsify webext listing\`.`], manual: [] };
|
|
40
|
+
}
|
|
41
|
+
const doc = json;
|
|
42
|
+
if (doc.version !== 1 || !Array.isArray(doc.fields)) {
|
|
43
|
+
return {
|
|
44
|
+
problems: [`${path} is not a store.json (version 1) — regenerate it with \`gjsify webext listing\`.`],
|
|
45
|
+
manual: [],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (doc.store !== listingStore) {
|
|
49
|
+
return { problems: [`${path} is for store "${String(doc.store)}", expected "${listingStore}".`], manual: [] };
|
|
50
|
+
}
|
|
51
|
+
const problems = [];
|
|
52
|
+
const manual = [];
|
|
53
|
+
for (const field of doc.fields) {
|
|
54
|
+
const name = field.label ?? field.key ?? '(unnamed field)';
|
|
55
|
+
if (field.status === 'manual')
|
|
56
|
+
manual.push(name);
|
|
57
|
+
else if (field.required === true && field.status === 'missing') {
|
|
58
|
+
problems.push(`required field "${name}" is missing in ${path}.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { problems, manual };
|
|
62
|
+
}
|
|
63
|
+
function secretsOf(store, env) {
|
|
64
|
+
return STORE_CREDENTIALS[store]
|
|
65
|
+
.filter((field) => field.secret)
|
|
66
|
+
.map((field) => env[field.env])
|
|
67
|
+
.filter((value) => value !== undefined && value !== '');
|
|
68
|
+
}
|
|
69
|
+
function describeResult(result, label) {
|
|
70
|
+
const lines = [`${label} ${result.version}: ${result.verdict} — ${result.detail}`];
|
|
71
|
+
for (const phase of result.phases) {
|
|
72
|
+
lines.push(` ${phase.phase}: ${phase.detail} (${phase.requests} request(s), ${phase.elapsedMs} ms)`);
|
|
73
|
+
}
|
|
74
|
+
if (result.retryable)
|
|
75
|
+
lines.push(' Calling again later, unchanged, can make progress.');
|
|
76
|
+
return lines;
|
|
77
|
+
}
|
|
78
|
+
/** Runs the command and returns its exit code (`SUBMIT_EXIT_CODES` for a drive, 1 for any refusal). */
|
|
79
|
+
export async function runSubmit(input) {
|
|
80
|
+
const { env, project } = input;
|
|
81
|
+
const store = asStoreId(input.store);
|
|
82
|
+
const secrets = store === null ? [] : secretsOf(store, env);
|
|
83
|
+
const clean = (text) => redactSecrets(text, secrets);
|
|
84
|
+
const out = (line) => input.out(clean(line));
|
|
85
|
+
const err = (line) => input.err(clean(line));
|
|
86
|
+
try {
|
|
87
|
+
if (store === null)
|
|
88
|
+
throw new Error(`gjsify webext submit: unknown store "${input.store}".`);
|
|
89
|
+
const descriptor = STORES[store];
|
|
90
|
+
if (!descriptor.implemented) {
|
|
91
|
+
throw new StoreUnsupportedError(store, 'use `gjsify webext sign` for AMO; Firefox is distributed by the project itself');
|
|
92
|
+
}
|
|
93
|
+
if (input.submit && !isTagRef(env['GITHUB_REF'])) {
|
|
94
|
+
throw new Error('gjsify webext submit: --submit asks the store for review and runs only on a tag ' +
|
|
95
|
+
'($GITHUB_REF must start with refs/tags/). Without --submit the zip is uploaded as a draft.');
|
|
96
|
+
}
|
|
97
|
+
let timeoutMs;
|
|
98
|
+
if (input.timeoutSeconds !== undefined) {
|
|
99
|
+
if (!Number.isFinite(input.timeoutSeconds) || input.timeoutSeconds < 0) {
|
|
100
|
+
throw new Error('gjsify webext submit: --timeout is a number of seconds, 0 or more.');
|
|
101
|
+
}
|
|
102
|
+
timeoutMs = input.timeoutSeconds * 1000;
|
|
103
|
+
}
|
|
104
|
+
const listingStore = LISTING_STORE[store];
|
|
105
|
+
const storeJson = join(resolve(project.root, input.listingDir ?? 'dist/listing'), listingStore, 'store.json');
|
|
106
|
+
if (!existsSync(storeJson)) {
|
|
107
|
+
throw new Error(`gjsify webext submit: ${storeJson} does not exist. Run \`gjsify webext listing --store ${listingStore}\` first; ` +
|
|
108
|
+
'it is the preflight for the listing the dashboard will ask about.');
|
|
109
|
+
}
|
|
110
|
+
const pre = preflightStoreJson(readFileSync(storeJson, 'utf8'), listingStore, storeJson);
|
|
111
|
+
if (pre.problems.length > 0) {
|
|
112
|
+
throw new Error(`gjsify webext submit: preflight failed, nothing was sent:\n ${pre.problems.join('\n ')}`);
|
|
113
|
+
}
|
|
114
|
+
if (pre.manual.length > 0)
|
|
115
|
+
out(` by hand in the dashboard: ${pre.manual.join(', ')}`);
|
|
116
|
+
const zipPath = resolve(input.zip ?? defaultZipPath(project, store));
|
|
117
|
+
if (!input.dryRun && !existsSync(zipPath)) {
|
|
118
|
+
throw new Error(`gjsify webext submit: ${zipPath} does not exist. Run \`gjsify webext zip\` first or pass --zip.`);
|
|
119
|
+
}
|
|
120
|
+
const log = env['GJSIFY_WEBEXT_DEBUG'] ? (msg) => err(msg) : undefined;
|
|
121
|
+
const options = { fetchImpl: input.fetchImpl, sleep: input.sleep, now: input.now, log };
|
|
122
|
+
const backend = (input.createBackend ?? createStoreBackend)(store, env, options);
|
|
123
|
+
if (input.dryRun) {
|
|
124
|
+
if (backend.verifyCredentials === undefined) {
|
|
125
|
+
out(`${descriptor.label}: dry run — credentials are set; this backend has no read-only check, so they are unverified. Nothing was uploaded.`);
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
await backend.verifyCredentials();
|
|
129
|
+
out(`${descriptor.label}: dry run — credentials accepted (one read). ${existsSync(zipPath) ? 'The zip exists' : `No zip at ${zipPath} yet`}. Nothing was uploaded.`);
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
const result = await driveSubmission({
|
|
133
|
+
backend,
|
|
134
|
+
upload: { zipPath, version: project.version },
|
|
135
|
+
publish: input.submit ? { version: project.version } : undefined,
|
|
136
|
+
}, { timeoutMs, sleep: input.sleep, now: input.now, log, secrets });
|
|
137
|
+
const write = result.exitCode === 0 ? out : err;
|
|
138
|
+
for (const line of describeResult(result, descriptor.label))
|
|
139
|
+
write(line);
|
|
140
|
+
return SUBMIT_EXIT_CODES[result.verdict];
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
err(error instanceof Error ? error.message : String(error));
|
|
144
|
+
return 1;
|
|
145
|
+
}
|
|
146
|
+
}
|