@testsprite/testsprite-cli 0.16.0 → 0.18.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 +52 -147
- package/dist/commands/agent.d.ts +12 -4
- package/dist/commands/agent.js +48 -63
- package/dist/commands/auth.d.ts +6 -10
- package/dist/commands/auth.js +40 -56
- package/dist/commands/ci.d.ts +23 -100
- package/dist/commands/ci.js +293 -487
- package/dist/commands/conversation.d.ts +27 -0
- package/dist/commands/conversation.js +741 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +129 -34
- package/dist/commands/init.d.ts +4 -45
- package/dist/commands/init.js +108 -66
- package/dist/commands/project-env.d.ts +62 -2
- package/dist/commands/project-env.js +434 -43
- package/dist/commands/project-sign-in.d.ts +0 -48
- package/dist/commands/project-sign-in.js +1 -229
- package/dist/commands/project.d.ts +19 -186
- package/dist/commands/project.js +108 -926
- package/dist/commands/result.d.ts +10 -0
- package/dist/commands/result.js +216 -0
- package/dist/commands/schedule.d.ts +0 -29
- package/dist/commands/schedule.js +28 -87
- package/dist/commands/test.d.ts +301 -1838
- package/dist/commands/test.js +1880 -13917
- package/dist/commands/testlist.d.ts +130 -5
- package/dist/commands/testlist.js +300 -342
- package/dist/commands/tunnel.d.ts +3 -3
- package/dist/commands/tunnel.js +23 -20
- package/dist/commands/usage.d.ts +12 -45
- package/dist/commands/usage.js +50 -131
- package/dist/index.js +191 -110
- package/dist/lib/agent-detect.js +9 -5
- package/dist/lib/agent-targets.d.ts +21 -2
- package/dist/lib/agent-targets.js +88 -11
- package/dist/lib/args.d.ts +13 -0
- package/dist/lib/args.js +49 -0
- package/dist/lib/basic-auth.d.ts +3 -0
- package/dist/lib/basic-auth.js +15 -0
- package/dist/lib/billing-refusal.js +4 -3
- package/dist/lib/ci-linkage.d.ts +4 -82
- package/dist/lib/ci-linkage.js +4 -157
- package/dist/lib/ci-run.js +1 -1
- package/dist/lib/client-factory.d.ts +12 -4
- package/dist/lib/client-factory.js +41 -30
- package/dist/lib/commit-signal.d.ts +65 -0
- package/dist/lib/commit-signal.js +305 -0
- package/dist/lib/concurrency-limiter.d.ts +6 -0
- package/dist/lib/concurrency-limiter.js +29 -0
- package/dist/lib/config.js +10 -5
- package/dist/lib/conflict-reason.d.ts +9 -3
- package/dist/lib/conflict-reason.js +6 -3
- package/dist/lib/conversation/answers.d.ts +9 -0
- package/dist/lib/conversation/answers.js +49 -0
- package/dist/lib/conversation/api.d.ts +75 -0
- package/dist/lib/conversation/api.js +151 -0
- package/dist/lib/conversation/change.d.ts +31 -0
- package/dist/lib/conversation/change.js +124 -0
- package/dist/lib/conversation/context.d.ts +29 -0
- package/dist/lib/conversation/context.js +82 -0
- package/dist/lib/conversation/environment.d.ts +16 -0
- package/dist/lib/conversation/environment.js +21 -0
- package/dist/lib/conversation/follow.d.ts +24 -0
- package/dist/lib/conversation/follow.js +42 -0
- package/dist/lib/conversation/render.d.ts +33 -0
- package/dist/lib/conversation/render.js +318 -0
- package/dist/lib/conversation/title.d.ts +2 -0
- package/dist/lib/conversation/title.js +18 -0
- package/dist/lib/conversation/types.d.ts +158 -0
- package/dist/lib/conversation/types.js +6 -0
- package/dist/lib/credentials.js +67 -11
- package/dist/lib/cron.d.ts +1 -1
- package/dist/lib/cron.js +2 -2
- package/dist/lib/dispatch-stop.d.ts +20 -0
- package/dist/lib/dispatch-stop.js +30 -0
- package/dist/lib/download.d.ts +100 -0
- package/dist/lib/download.js +408 -0
- package/dist/lib/dry-run/fetch.d.ts +10 -0
- package/dist/lib/dry-run/fetch.js +20 -0
- package/dist/lib/dry-run/samples.d.ts +6 -34
- package/dist/lib/dry-run/samples.js +375 -747
- package/dist/lib/environment-tunnel.d.ts +19 -30
- package/dist/lib/environment-tunnel.js +168 -202
- package/dist/lib/errors.d.ts +20 -4
- package/dist/lib/errors.js +36 -16
- package/dist/lib/facade.d.ts +7 -29
- package/dist/lib/facade.js +7 -36
- package/dist/lib/failing-fe-resolver.d.ts +13 -58
- package/dist/lib/failing-fe-resolver.js +47 -132
- package/dist/lib/first-suite-hint.d.ts +20 -30
- package/dist/lib/first-suite-hint.js +57 -72
- package/dist/lib/gh-output.d.ts +76 -21
- package/dist/lib/gh-output.js +171 -90
- package/dist/lib/git-utils.d.ts +56 -0
- package/dist/lib/git-utils.js +212 -0
- package/dist/lib/github-context.d.ts +2 -0
- package/dist/lib/github-context.js +40 -8
- package/dist/lib/history-retention.d.ts +6 -2
- package/dist/lib/history-retention.js +10 -7
- package/dist/lib/http.d.ts +58 -134
- package/dist/lib/http.js +354 -291
- package/dist/lib/interrupt.d.ts +14 -8
- package/dist/lib/interrupt.js +28 -10
- package/dist/lib/junit-report.d.ts +57 -4
- package/dist/lib/junit-report.js +202 -32
- package/dist/lib/local-target.d.ts +8 -7
- package/dist/lib/local-target.js +14 -13
- package/dist/lib/output.d.ts +2 -41
- package/dist/lib/output.js +13 -51
- package/dist/lib/pagination.d.ts +2 -5
- package/dist/lib/pagination.js +2 -5
- package/dist/lib/presigned-url.d.ts +22 -0
- package/dist/lib/presigned-url.js +90 -0
- package/dist/lib/prompt.js +36 -2
- package/dist/lib/proxy.js +2 -1
- package/dist/lib/redact.d.ts +2 -2
- package/dist/lib/redact.js +3 -4
- package/dist/lib/removed-commands.d.ts +18 -0
- package/dist/lib/removed-commands.js +170 -0
- package/dist/lib/render-error.d.ts +31 -6
- package/dist/lib/render-error.js +88 -25
- package/dist/lib/response-schemas.d.ts +38 -30
- package/dist/lib/response-schemas.js +207 -207
- package/dist/lib/result/api.d.ts +24 -0
- package/dist/lib/result/api.js +28 -0
- package/dist/lib/result/evidence.d.ts +73 -0
- package/dist/lib/result/evidence.js +422 -0
- package/dist/lib/result/render.d.ts +20 -0
- package/dist/lib/result/render.js +194 -0
- package/dist/lib/result/types.d.ts +122 -0
- package/dist/lib/result/types.js +19 -0
- package/dist/lib/run-output.d.ts +275 -0
- package/dist/lib/run-output.js +227 -0
- package/dist/lib/run-render.d.ts +101 -0
- package/dist/lib/run-render.js +183 -0
- package/dist/lib/run-wait.d.ts +192 -0
- package/dist/lib/run-wait.js +452 -0
- package/dist/lib/runs.types.d.ts +118 -367
- package/dist/lib/runs.types.js +0 -14
- package/dist/lib/secret-file.d.ts +1 -1
- package/dist/lib/secret-file.js +11 -2
- package/dist/lib/skill-nudge.d.ts +7 -27
- package/dist/lib/skill-nudge.js +9 -37
- package/dist/lib/target-path.d.ts +15 -0
- package/dist/lib/target-path.js +35 -0
- package/dist/lib/target-url-advisory.d.ts +19 -0
- package/dist/lib/target-url-advisory.js +31 -0
- package/dist/lib/target-url-preflight.d.ts +9 -0
- package/dist/lib/target-url-preflight.js +214 -106
- package/dist/lib/target-url.d.ts +8 -8
- package/dist/lib/target-url.js +14 -24
- package/dist/lib/telemetry.d.ts +35 -15
- package/dist/lib/telemetry.js +38 -9
- package/dist/lib/terminal-text.d.ts +41 -0
- package/dist/lib/terminal-text.js +127 -0
- package/dist/lib/testlist.types.d.ts +16 -8
- package/dist/lib/testlist.types.js +1 -1
- package/dist/lib/text-equality.d.ts +2 -0
- package/dist/lib/text-equality.js +5 -0
- package/dist/lib/text-file.d.ts +16 -0
- package/dist/lib/text-file.js +41 -0
- package/dist/lib/text-table.d.ts +46 -0
- package/dist/lib/text-table.js +72 -4
- package/dist/lib/ticker.d.ts +9 -2
- package/dist/lib/ticker.js +16 -3
- package/dist/lib/transport-failure.d.ts +22 -0
- package/dist/lib/transport-failure.js +126 -0
- package/dist/lib/tunnel-session.d.ts +8 -2
- package/dist/lib/tunnel-session.js +24 -11
- package/dist/lib/update-check.js +3 -2
- package/dist/lib/url-template.d.ts +43 -0
- package/dist/lib/url-template.js +151 -0
- package/dist/lib/validate.d.ts +0 -64
- package/dist/lib/validate.js +2 -131
- package/dist/lib/version-notice.js +4 -3
- package/dist/lib/wait-exit.d.ts +37 -2
- package/dist/lib/wait-exit.js +88 -30
- package/dist/lib/workspace-status.js +10 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -3
- package/skills/testsprite-ci.skill.md +52 -23
- package/skills/testsprite-onboard.skill.md +70 -153
- package/skills/testsprite-verify.codex.md +54 -58
- package/skills/testsprite-verify.skill.md +189 -358
- package/dist/lib/browser.d.ts +0 -6
- package/dist/lib/browser.js +0 -54
- package/dist/lib/bundle.d.ts +0 -234
- package/dist/lib/bundle.js +0 -781
- package/dist/lib/deprecate.d.ts +0 -32
- package/dist/lib/deprecate.js +0 -39
- package/dist/lib/flaky.d.ts +0 -91
- package/dist/lib/flaky.js +0 -71
- package/dist/lib/plan-poll.d.ts +0 -171
- package/dist/lib/plan-poll.js +0 -441
- package/dist/lib/plans.types.d.ts +0 -130
- package/dist/lib/plans.types.js +0 -31
- package/dist/lib/poll.d.ts +0 -100
- package/dist/lib/poll.js +0 -290
- package/dist/lib/rate-throttle.d.ts +0 -49
- package/dist/lib/rate-throttle.js +0 -75
- package/dist/lib/run-progress.d.ts +0 -41
- package/dist/lib/run-progress.js +0 -56
- package/dist/lib/v3-advisory.d.ts +0 -55
- package/dist/lib/v3-advisory.js +0 -74
- package/schemas/plan.schema.json +0 -61
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
* Shared `HttpClient` factory used by every M2 command. Two reasons for
|
|
3
|
-
* the extraction:
|
|
4
|
-
*
|
|
5
|
-
* 1. Three command files (`auth`, `project`, `test`) had byte-equivalent
|
|
6
|
-
* `makeClient` helpers — drift between them would silently change
|
|
7
|
-
* behavior depending on which command you called.
|
|
8
|
-
* 2. P6's `--dry-run` branch needs to bypass `loadConfig` (so it works
|
|
9
|
-
* with no `~/.testsprite/credentials`) and substitute a canned-fetch
|
|
10
|
-
* impl. Doing that once here is safer than three near-copies.
|
|
11
|
-
*
|
|
12
|
-
* The factory is intentionally narrow: it only takes the HTTP-relevant
|
|
13
|
-
* deps. Per-command deps (auth's `prompt`, test's `rawStdout`) stay
|
|
14
|
-
* with the command.
|
|
15
|
-
*/
|
|
16
|
-
import { loadConfig } from './config.js';
|
|
1
|
+
import { loadConfig, resolveProfileName } from './config.js';
|
|
17
2
|
import { DEFAULT_PROFILE, defaultCredentialsPath } from './credentials.js';
|
|
18
3
|
import { ApiError, localValidationError } from './errors.js';
|
|
19
4
|
import { facadeBaseUrl } from './facade.js';
|
|
20
5
|
import { HttpClient, REQUEST_TIMEOUT_DEFAULT_MS, REQUEST_TIMEOUT_MAX_MS, REQUEST_TIMEOUT_MIN_MS, } from './http.js';
|
|
21
6
|
import { globalShutdown } from './interrupt.js';
|
|
22
|
-
import {
|
|
7
|
+
import { resolveOutputMode } from './output.js';
|
|
8
|
+
import { createDryRunFetch, withDryRunBannerOnce } from './dry-run/fetch.js';
|
|
23
9
|
import { redactDeep } from './redact.js';
|
|
24
10
|
import { noteServerVersion } from './version-notice.js';
|
|
25
11
|
import { VERSION } from '../version.js';
|
|
12
|
+
import { jsonForTerminal, terminalSafeWriter, verboseWriter } from './terminal-text.js';
|
|
26
13
|
/**
|
|
27
14
|
* Accepted TestSprite API-key prefixes, in the order they are reported to the
|
|
28
15
|
* user. Three families exist today and all three authenticate:
|
|
@@ -110,8 +97,8 @@ function clampRequestTimeout(ms) {
|
|
|
110
97
|
* retry-and-backoff cycle.
|
|
111
98
|
*
|
|
112
99
|
* The value can originate from `--endpoint-url`, `TESTSPRITE_API_URL`, or the
|
|
113
|
-
* credentials file `api_url
|
|
114
|
-
*
|
|
100
|
+
* credentials file `api_url`. The message names none of them: they are for
|
|
101
|
+
* TestSprite's own use and no user-facing text mentions them.
|
|
115
102
|
*/
|
|
116
103
|
export function assertValidEndpointUrl(rawUrl) {
|
|
117
104
|
let parsed;
|
|
@@ -119,8 +106,7 @@ export function assertValidEndpointUrl(rawUrl) {
|
|
|
119
106
|
parsed = new URL(rawUrl);
|
|
120
107
|
}
|
|
121
108
|
catch {
|
|
122
|
-
throw localValidationError('endpoint-url', `"${rawUrl}" is not a valid URL — provide an http(s) URL (e.g. https://api.testsprite.com)
|
|
123
|
-
`via --endpoint-url, TESTSPRITE_API_URL, or the credentials file`, undefined, 'field');
|
|
109
|
+
throw localValidationError('endpoint-url', `"${rawUrl}" is not a valid URL — provide an http(s) URL (e.g. https://api.testsprite.com)`, undefined, 'field');
|
|
124
110
|
}
|
|
125
111
|
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
126
112
|
throw localValidationError('endpoint-url', `scheme "${parsed.protocol.replace(/:$/, '')}" is not supported — use http or https ` +
|
|
@@ -191,6 +177,24 @@ export function parseRequestTimeoutFlag(raw) {
|
|
|
191
177
|
}
|
|
192
178
|
return Math.round(n * 1000); // seconds → milliseconds
|
|
193
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* The global flags as a command reads them (`--profile`, `--output`,
|
|
182
|
+
* `--dry-run`, `--endpoint-url`, `--debug`, `--verbose`, `--request-timeout`).
|
|
183
|
+
* An invalid `--output` or `--request-timeout` is a validation error (exit 5),
|
|
184
|
+
* never a silent fall-back.
|
|
185
|
+
*/
|
|
186
|
+
export function resolveCommonOptions(command, env) {
|
|
187
|
+
const globals = command.optsWithGlobals();
|
|
188
|
+
return {
|
|
189
|
+
profile: resolveProfileName(globals.profile, env),
|
|
190
|
+
output: resolveOutputMode(globals.output),
|
|
191
|
+
dryRun: globals.dryRun ?? false,
|
|
192
|
+
endpointUrl: globals.endpointUrl,
|
|
193
|
+
debug: globals.debug ?? false,
|
|
194
|
+
verbose: globals.verbose ?? false,
|
|
195
|
+
requestTimeoutMs: parseRequestTimeoutFlag(globals.requestTimeout),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
194
198
|
/**
|
|
195
199
|
* The profile name to echo in a missing-key error, or `undefined` to keep the
|
|
196
200
|
* generic wording.
|
|
@@ -219,22 +223,29 @@ export function createHttpClientFactory(opts, deps = {}) {
|
|
|
219
223
|
return overrides => new HttpClient({ ...snapshot, ...overrides });
|
|
220
224
|
}
|
|
221
225
|
function resolveHttpClientOptions(opts, deps) {
|
|
222
|
-
const stderr = deps.stderr
|
|
226
|
+
const stderr = terminalSafeWriter(deps.stderr);
|
|
223
227
|
const env = deps.env ?? process.env;
|
|
224
228
|
const requestTimeoutMs = resolveRequestTimeoutMs(opts, env);
|
|
225
229
|
if (opts.dryRun) {
|
|
226
230
|
const dryRunEndpoint = opts.endpointUrl ?? DRY_RUN_DEFAULT_ENDPOINT;
|
|
227
231
|
// Validate even under --dry-run so a typo in --endpoint-url is caught
|
|
228
|
-
// offline (no creds, no network).
|
|
229
|
-
//
|
|
232
|
+
// offline (no creds, no network). A rejected endpoint throws here, before
|
|
233
|
+
// any dry-run response is produced, so no banner is announced first.
|
|
230
234
|
assertValidEndpointUrl(dryRunEndpoint);
|
|
231
|
-
|
|
235
|
+
// The banner is emitted lazily the first time a dry-run request
|
|
236
|
+
// actually returns a canned sample (via the fetch wrapper below),
|
|
237
|
+
// not at client construction — so a command that fails local
|
|
238
|
+
// validation after building the client never announces a "sample
|
|
239
|
+
// response" it will not produce. The wrapper applies to the injected
|
|
240
|
+
// test fetch too, so it behaves the same way.
|
|
241
|
+
const baseFetch = deps.fetchImpl ?? createDryRunFetch();
|
|
242
|
+
const fetchImpl = withDryRunBannerOnce(baseFetch, () => emitDryRunBanner(stderr));
|
|
232
243
|
return {
|
|
233
244
|
baseUrl: facadeBaseUrl(dryRunEndpoint),
|
|
234
245
|
apiKey: DRY_RUN_API_KEY,
|
|
235
|
-
fetchImpl
|
|
246
|
+
fetchImpl,
|
|
236
247
|
onDebug: opts.debug ? (event) => stderr(formatDryRunDebug(event)) : undefined,
|
|
237
|
-
onTransition: opts.verbose ? (
|
|
248
|
+
onTransition: opts.verbose ? verboseWriter(stderr) : undefined,
|
|
238
249
|
env,
|
|
239
250
|
requestTimeoutMs,
|
|
240
251
|
shutdownSignal: deps.shutdownSignal ?? globalShutdown.signal,
|
|
@@ -261,7 +272,7 @@ function resolveHttpClientOptions(opts, deps) {
|
|
|
261
272
|
apiKey: config.apiKey,
|
|
262
273
|
fetchImpl: deps.fetchImpl,
|
|
263
274
|
onDebug: opts.debug ? (event) => stderr(formatDebug(event)) : undefined,
|
|
264
|
-
onTransition: opts.verbose ? (
|
|
275
|
+
onTransition: opts.verbose ? verboseWriter(stderr) : undefined,
|
|
265
276
|
// Warn once if the backend advertises a minimum supported version above
|
|
266
277
|
// this binary's. Gating (opt-out env, TTY, output mode, dry-run) lives in
|
|
267
278
|
// noteServerVersion; the client just forwards the observed headers.
|
|
@@ -289,9 +300,9 @@ function resolveHttpClientOptions(opts, deps) {
|
|
|
289
300
|
* forward-compatibility contract.
|
|
290
301
|
*/
|
|
291
302
|
export function formatDebug(event) {
|
|
292
|
-
return `[debug ${new Date().toISOString()}] ${
|
|
303
|
+
return `[debug ${new Date().toISOString()}] ${jsonForTerminal(redactDeep(event))}`;
|
|
293
304
|
}
|
|
294
305
|
export function formatDryRunDebug(event) {
|
|
295
|
-
return `[debug ${new Date().toISOString()}] ${
|
|
306
|
+
return `[debug ${new Date().toISOString()}] ${jsonForTerminal(redactDeep({ ...event, mode: 'dry-run' }))}`;
|
|
296
307
|
}
|
|
297
308
|
//# sourceMappingURL=client-factory.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { FetchImpl } from './http.js';
|
|
2
|
+
import type { ShutdownHandle } from './interrupt.js';
|
|
3
|
+
export type CommitSignalState = 'pending' | 'success' | 'failure' | 'skip';
|
|
4
|
+
export interface CommitSignal {
|
|
5
|
+
via: 'status' | 'check_run';
|
|
6
|
+
name: string;
|
|
7
|
+
state: CommitSignalState;
|
|
8
|
+
description: string;
|
|
9
|
+
/** When the platform last wrote it; decides between a status and a check run of the same name. */
|
|
10
|
+
updatedAt: number;
|
|
11
|
+
}
|
|
12
|
+
export type CommitSignalVerdict = {
|
|
13
|
+
kind: 'ready';
|
|
14
|
+
signal: CommitSignal;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'skip';
|
|
17
|
+
signal: CommitSignal;
|
|
18
|
+
reason: string;
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'timeout';
|
|
21
|
+
waitedMs: number;
|
|
22
|
+
seen: string[];
|
|
23
|
+
};
|
|
24
|
+
export interface CommitSignalTarget {
|
|
25
|
+
repoOwner: string;
|
|
26
|
+
repoName: string;
|
|
27
|
+
/** The pull request's head commit — never the merge commit `GITHUB_SHA`. */
|
|
28
|
+
sha: string;
|
|
29
|
+
/** Matched exactly against `statuses[].context` and `check_runs[].name`. */
|
|
30
|
+
name: string;
|
|
31
|
+
}
|
|
32
|
+
export interface CommitSignalDeps {
|
|
33
|
+
env: NodeJS.ProcessEnv;
|
|
34
|
+
fetchImpl: FetchImpl;
|
|
35
|
+
sleep: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
36
|
+
shutdown?: ShutdownHandle;
|
|
37
|
+
stderr?: (line: string) => void;
|
|
38
|
+
}
|
|
39
|
+
/** Backoff between polls: a build is minutes, not milliseconds. */
|
|
40
|
+
export declare const COMMIT_SIGNAL_BACKOFF_MS: readonly [5000, 10000, 20000, 30000];
|
|
41
|
+
export declare function normalizeStatus(record: Record<string, unknown>): CommitSignal | null;
|
|
42
|
+
export declare function normalizeCheckRun(record: Record<string, unknown>): CommitSignal | null;
|
|
43
|
+
/**
|
|
44
|
+
* The verdict one round of reads yields, or `null` to keep waiting. Of a
|
|
45
|
+
* status and a check run with the same name, the newer one speaks.
|
|
46
|
+
*/
|
|
47
|
+
export declare function decideCommitSignal(signals: CommitSignal[]): Exclude<CommitSignalVerdict, {
|
|
48
|
+
kind: 'timeout';
|
|
49
|
+
}> | null;
|
|
50
|
+
/** Pages followed per endpoint per round; a preview check is never past this. */
|
|
51
|
+
export declare const COMMIT_SIGNAL_MAX_PAGES = 10;
|
|
52
|
+
/**
|
|
53
|
+
* Poll both endpoints until `target.name` is terminal or `timeoutMs` passes.
|
|
54
|
+
* The deadline bounds everything: each GitHub read (request and body) gets
|
|
55
|
+
* the remaining budget as its own timeout, so a stalled connection cannot
|
|
56
|
+
* outlive `--status-timeout` and no success can arrive after it. Every sleep
|
|
57
|
+
* is clamped to the deadline and cut short by a termination signal (the
|
|
58
|
+
* graceful-detach scope is armed for the wait).
|
|
59
|
+
*/
|
|
60
|
+
export declare function waitForCommitSignal(target: CommitSignalTarget, opts: {
|
|
61
|
+
token: string;
|
|
62
|
+
timeoutMs: number;
|
|
63
|
+
}, deps: CommitSignalDeps): Promise<CommitSignalVerdict>;
|
|
64
|
+
/** The `rel="next"` URL of a `Link` header, or `null` on the last page. */
|
|
65
|
+
export declare function nextLink(link: string | null): string | null;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ci run --wait-for-status <name>`: hold the run until the deploy platform
|
|
3
|
+
* says this commit's preview exists.
|
|
4
|
+
*
|
|
5
|
+
* With a `pull_request` trigger the workflow starts the moment the platform
|
|
6
|
+
* starts building, so a run dispatched at once tests an address that is not
|
|
7
|
+
* serving yet — or one that was never going to be built (an ignored build, a
|
|
8
|
+
* failed deploy). The platform does write one signal on the head commit, and
|
|
9
|
+
* GitHub has two APIs for it, chosen by the platform's integration: a
|
|
10
|
+
* **commit status** (`GET /commits/{sha}/status`, keyed by `context`; Vercel,
|
|
11
|
+
* Netlify, Render) or a **check run** (`GET /commits/{sha}/check-runs`, keyed
|
|
12
|
+
* by `name`; Cloudflare Pages, every Actions job). They render identically on
|
|
13
|
+
* the pull request, so the CLI keeps no table of who writes which: every poll
|
|
14
|
+
* reads both, matches `<name>` exactly against either key, and normalizes
|
|
15
|
+
* whichever answered. The only platform-specific input is the name itself,
|
|
16
|
+
* copied off a recent pull request at setup time.
|
|
17
|
+
*
|
|
18
|
+
* Verdicts: `ready` (success, nothing says the build was skipped), `skip`
|
|
19
|
+
* (failed, errored, or success-but-Ignored/Canceled/Skipped — Vercel's Ignored
|
|
20
|
+
* Build Step writes success + "Canceled"), `timeout` (nothing terminal before
|
|
21
|
+
* the deadline, with every name seen on the commit so a misspelling is
|
|
22
|
+
* obvious). A `skip` is "no preview, tests not run" — the caller exits 0 and
|
|
23
|
+
* never falls back to production or the environment URL.
|
|
24
|
+
*/
|
|
25
|
+
import { CLIError, InterruptError } from './errors.js';
|
|
26
|
+
/** Backoff between polls: a build is minutes, not milliseconds. */
|
|
27
|
+
export const COMMIT_SIGNAL_BACKOFF_MS = [5_000, 10_000, 20_000, 30_000];
|
|
28
|
+
/** Descriptions a platform writes on a `success` that produced no preview. */
|
|
29
|
+
const NO_PREVIEW_RE = /\b(ignored|canceled|cancelled|skipped)\b/i;
|
|
30
|
+
export function normalizeStatus(record) {
|
|
31
|
+
const name = typeof record.context === 'string' ? record.context : null;
|
|
32
|
+
if (name === null)
|
|
33
|
+
return null;
|
|
34
|
+
const raw = typeof record.state === 'string' ? record.state : 'pending';
|
|
35
|
+
const state = raw === 'success' ? 'success' : raw === 'failure' || raw === 'error' ? 'failure' : 'pending';
|
|
36
|
+
return {
|
|
37
|
+
via: 'status',
|
|
38
|
+
name,
|
|
39
|
+
state,
|
|
40
|
+
description: typeof record.description === 'string' ? record.description : '',
|
|
41
|
+
updatedAt: parseTime(record.updated_at),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function normalizeCheckRun(record) {
|
|
45
|
+
const name = typeof record.name === 'string' ? record.name : null;
|
|
46
|
+
if (name === null)
|
|
47
|
+
return null;
|
|
48
|
+
const output = asRecord(record.output);
|
|
49
|
+
const description = typeof output?.title === 'string' ? output.title : '';
|
|
50
|
+
const updatedAt = parseTime(record.completed_at) || parseTime(record.started_at);
|
|
51
|
+
if (record.status !== 'completed') {
|
|
52
|
+
return { via: 'check_run', name, state: 'pending', description, updatedAt };
|
|
53
|
+
}
|
|
54
|
+
const conclusion = typeof record.conclusion === 'string' ? record.conclusion : '';
|
|
55
|
+
const state = conclusion === 'success' || conclusion === 'neutral'
|
|
56
|
+
? 'success'
|
|
57
|
+
: conclusion === 'skipped' || conclusion === 'cancelled'
|
|
58
|
+
? 'skip'
|
|
59
|
+
: 'failure';
|
|
60
|
+
return { via: 'check_run', name, state, description, updatedAt };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The verdict one round of reads yields, or `null` to keep waiting. Of a
|
|
64
|
+
* status and a check run with the same name, the newer one speaks.
|
|
65
|
+
*/
|
|
66
|
+
export function decideCommitSignal(signals) {
|
|
67
|
+
const newest = signals.reduce((best, s) => (best === null || s.updatedAt > best.updatedAt ? s : best), null);
|
|
68
|
+
if (newest === null || newest.state === 'pending')
|
|
69
|
+
return null;
|
|
70
|
+
const what = newest.via === 'status' ? 'status' : 'check';
|
|
71
|
+
const detail = newest.description ? `: ${newest.description}` : '';
|
|
72
|
+
if (newest.state === 'failure') {
|
|
73
|
+
return { kind: 'skip', signal: newest, reason: `the ${what} "${newest.name}" failed${detail}` };
|
|
74
|
+
}
|
|
75
|
+
if (newest.state === 'skip' || NO_PREVIEW_RE.test(newest.description)) {
|
|
76
|
+
return {
|
|
77
|
+
kind: 'skip',
|
|
78
|
+
signal: newest,
|
|
79
|
+
reason: `the ${what} "${newest.name}" reports no preview build${detail}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return { kind: 'ready', signal: newest };
|
|
83
|
+
}
|
|
84
|
+
/** Pages followed per endpoint per round; a preview check is never past this. */
|
|
85
|
+
export const COMMIT_SIGNAL_MAX_PAGES = 10;
|
|
86
|
+
/**
|
|
87
|
+
* Poll both endpoints until `target.name` is terminal or `timeoutMs` passes.
|
|
88
|
+
* The deadline bounds everything: each GitHub read (request and body) gets
|
|
89
|
+
* the remaining budget as its own timeout, so a stalled connection cannot
|
|
90
|
+
* outlive `--status-timeout` and no success can arrive after it. Every sleep
|
|
91
|
+
* is clamped to the deadline and cut short by a termination signal (the
|
|
92
|
+
* graceful-detach scope is armed for the wait).
|
|
93
|
+
*/
|
|
94
|
+
export async function waitForCommitSignal(target, opts, deps) {
|
|
95
|
+
const startedAt = Date.now();
|
|
96
|
+
const deadline = startedAt + opts.timeoutMs;
|
|
97
|
+
const seen = new Set();
|
|
98
|
+
const timedOut = () => ({
|
|
99
|
+
kind: 'timeout',
|
|
100
|
+
waitedMs: Date.now() - startedAt,
|
|
101
|
+
seen: [...seen].sort(),
|
|
102
|
+
});
|
|
103
|
+
const disarm = deps.shutdown?.arm();
|
|
104
|
+
try {
|
|
105
|
+
for (let attempt = 0;; attempt++) {
|
|
106
|
+
let remaining = deadline - Date.now();
|
|
107
|
+
if (remaining <= 0)
|
|
108
|
+
return timedOut();
|
|
109
|
+
const round = await readCommitSignals(target, opts.token, deps, remaining);
|
|
110
|
+
for (const name of round.names)
|
|
111
|
+
seen.add(name);
|
|
112
|
+
// A round with a failed read decides nothing: the endpoint that did
|
|
113
|
+
// answer may hold an older record of the same name, and the newer one
|
|
114
|
+
// speaks. The next round, inside the same deadline, reads both again.
|
|
115
|
+
if (round.complete) {
|
|
116
|
+
const verdict = decideCommitSignal(round.matched);
|
|
117
|
+
if (verdict)
|
|
118
|
+
return verdict;
|
|
119
|
+
}
|
|
120
|
+
remaining = deadline - Date.now();
|
|
121
|
+
if (remaining <= 0)
|
|
122
|
+
return timedOut();
|
|
123
|
+
const backoff = COMMIT_SIGNAL_BACKOFF_MS[Math.min(attempt, COMMIT_SIGNAL_BACKOFF_MS.length - 1)];
|
|
124
|
+
// A rate-limited answer names its own cooldown; honor it, inside the deadline.
|
|
125
|
+
await sleepOrInterrupt(Math.min(Math.max(backoff, round.retryAfterMs ?? 0), remaining), deps);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
disarm?.();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* One round: both endpoints (every page), the records named `target.name`,
|
|
134
|
+
* every name seen, and whether both reads answered. `retryAfterMs` is the
|
|
135
|
+
* longest cooldown a rate-limited answer asked for.
|
|
136
|
+
*/
|
|
137
|
+
async function readCommitSignals(target, token, deps, budgetMs) {
|
|
138
|
+
const base = (deps.env.GITHUB_API_URL ?? 'https://api.github.com').replace(/\/+$/, '');
|
|
139
|
+
const repo = `${base}/repos/${encodeURIComponent(target.repoOwner)}/${encodeURIComponent(target.repoName)}/commits/${target.sha}`;
|
|
140
|
+
const [statuses, checks] = await Promise.all([
|
|
141
|
+
githubList(`${repo}/status?per_page=100`, 'statuses', token, deps, budgetMs),
|
|
142
|
+
githubList(`${repo}/check-runs?per_page=100`, 'check_runs', token, deps, budgetMs),
|
|
143
|
+
]);
|
|
144
|
+
const matched = [];
|
|
145
|
+
const names = [];
|
|
146
|
+
const collect = (rows, normalize) => {
|
|
147
|
+
for (const row of rows ?? []) {
|
|
148
|
+
const record = asRecord(row);
|
|
149
|
+
const signal = record ? normalize(record) : null;
|
|
150
|
+
if (!signal)
|
|
151
|
+
continue;
|
|
152
|
+
names.push(signal.name);
|
|
153
|
+
if (signal.name === target.name)
|
|
154
|
+
matched.push(signal);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
collect(statuses.rows, normalizeStatus);
|
|
158
|
+
collect(checks.rows, normalizeCheckRun);
|
|
159
|
+
const retryAfterMs = Math.max(statuses.retryAfterMs ?? 0, checks.retryAfterMs ?? 0);
|
|
160
|
+
return {
|
|
161
|
+
matched,
|
|
162
|
+
names,
|
|
163
|
+
complete: statuses.rows !== null && checks.rows !== null,
|
|
164
|
+
...(retryAfterMs > 0 ? { retryAfterMs } : {}),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/** A paginated list: follows `Link: rel="next"` up to `COMMIT_SIGNAL_MAX_PAGES`, inside `budgetMs`. */
|
|
168
|
+
async function githubList(url, key, token, deps, budgetMs) {
|
|
169
|
+
const startedAt = Date.now();
|
|
170
|
+
const rows = [];
|
|
171
|
+
let next = url;
|
|
172
|
+
for (let page = 0; next !== null && page < COMMIT_SIGNAL_MAX_PAGES; page++) {
|
|
173
|
+
const left = budgetMs - (Date.now() - startedAt);
|
|
174
|
+
if (left <= 0)
|
|
175
|
+
return { rows: null };
|
|
176
|
+
const read = await githubGet(next, token, deps, left);
|
|
177
|
+
if (!read.ok) {
|
|
178
|
+
return {
|
|
179
|
+
rows: null,
|
|
180
|
+
...(read.retryAfterMs !== undefined ? { retryAfterMs: read.retryAfterMs } : {}),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const list = asRecord(read.body)?.[key];
|
|
184
|
+
if (Array.isArray(list))
|
|
185
|
+
rows.push(...list);
|
|
186
|
+
next = read.next;
|
|
187
|
+
}
|
|
188
|
+
return { rows };
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* One GitHub read, bounded by `budgetMs` (request and body). A permission
|
|
192
|
+
* answer is a configuration error, named with the permission the job token
|
|
193
|
+
* lacks; a rate-limited 403/429 is transient with its cooldown; anything else
|
|
194
|
+
* transient (network, the budget, 5xx) is `ok: false` — this round learns
|
|
195
|
+
* nothing and the next one tries again, inside the same deadline.
|
|
196
|
+
*/
|
|
197
|
+
async function githubGet(url, token, deps, budgetMs) {
|
|
198
|
+
const budget = AbortSignal.timeout(Math.max(1, budgetMs));
|
|
199
|
+
const signal = deps.shutdown ? AbortSignal.any([deps.shutdown.signal, budget]) : budget;
|
|
200
|
+
const interrupted = () => {
|
|
201
|
+
throw deps.shutdown.signal.reason;
|
|
202
|
+
};
|
|
203
|
+
let response;
|
|
204
|
+
try {
|
|
205
|
+
response = await deps.fetchImpl(url, {
|
|
206
|
+
method: 'GET',
|
|
207
|
+
headers: {
|
|
208
|
+
accept: 'application/vnd.github+json',
|
|
209
|
+
authorization: `Bearer ${token}`,
|
|
210
|
+
'x-github-api-version': '2022-11-28',
|
|
211
|
+
},
|
|
212
|
+
signal,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
if (err instanceof InterruptError)
|
|
217
|
+
throw err;
|
|
218
|
+
if (deps.shutdown?.signal.aborted)
|
|
219
|
+
interrupted();
|
|
220
|
+
deps.stderr?.(budget.aborted
|
|
221
|
+
? '[ci run] GitHub did not answer within the remaining --status-timeout budget'
|
|
222
|
+
: `[ci run] could not read the commit's checks (${err instanceof Error ? err.message : String(err)}); retrying`);
|
|
223
|
+
return { ok: false };
|
|
224
|
+
}
|
|
225
|
+
if (isRateLimited(response)) {
|
|
226
|
+
const retryAfterMs = rateLimitCooldownMs(response.headers);
|
|
227
|
+
deps.stderr?.(`[ci run] GitHub rate limit reached reading the commit's checks; retrying${retryAfterMs !== undefined ? ` after ${Math.ceil(retryAfterMs / 1000)}s` : ''}`);
|
|
228
|
+
return { ok: false, ...(retryAfterMs !== undefined ? { retryAfterMs } : {}) };
|
|
229
|
+
}
|
|
230
|
+
if (response.status === 401 || response.status === 403 || response.status === 404) {
|
|
231
|
+
throw new CLIError(`Could not read the checks on this commit: GitHub answered ${response.status} — the job token needs \`statuses: read\` and \`checks: read\` (add them under \`permissions:\`, and keep \`GITHUB_TOKEN: \${{ github.token }}\` in the step env).`, 5);
|
|
232
|
+
}
|
|
233
|
+
if (!response.ok) {
|
|
234
|
+
deps.stderr?.(`[ci run] GitHub answered ${response.status} reading the commit's checks; retrying`);
|
|
235
|
+
return { ok: false };
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
const body = (await response.json());
|
|
239
|
+
return { ok: true, body, next: nextLink(response.headers.get('link')) };
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
if (deps.shutdown?.signal.aborted)
|
|
243
|
+
interrupted();
|
|
244
|
+
return { ok: false };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/** GitHub throttles with 403 or 429 plus `retry-after` or an exhausted `x-ratelimit-remaining`. */
|
|
248
|
+
function isRateLimited(response) {
|
|
249
|
+
if (response.status !== 403 && response.status !== 429)
|
|
250
|
+
return false;
|
|
251
|
+
return (response.headers.has('retry-after') || response.headers.get('x-ratelimit-remaining') === '0');
|
|
252
|
+
}
|
|
253
|
+
/** The cooldown a throttled answer asks for: `retry-after` seconds, else until `x-ratelimit-reset`. */
|
|
254
|
+
function rateLimitCooldownMs(headers) {
|
|
255
|
+
const retryAfter = Number(headers.get('retry-after'));
|
|
256
|
+
if (Number.isFinite(retryAfter) && retryAfter > 0)
|
|
257
|
+
return retryAfter * 1000;
|
|
258
|
+
const reset = Number(headers.get('x-ratelimit-reset'));
|
|
259
|
+
if (Number.isFinite(reset) && reset > 0) {
|
|
260
|
+
const ms = reset * 1000 - Date.now();
|
|
261
|
+
if (ms > 0)
|
|
262
|
+
return ms;
|
|
263
|
+
}
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
/** The `rel="next"` URL of a `Link` header, or `null` on the last page. */
|
|
267
|
+
export function nextLink(link) {
|
|
268
|
+
if (!link)
|
|
269
|
+
return null;
|
|
270
|
+
const match = /<([^>]+)>\s*;\s*rel="next"/.exec(link);
|
|
271
|
+
return match ? match[1] : null;
|
|
272
|
+
}
|
|
273
|
+
function sleepOrInterrupt(ms, deps) {
|
|
274
|
+
const signal = deps.shutdown?.signal;
|
|
275
|
+
if (signal === undefined)
|
|
276
|
+
return deps.sleep(ms);
|
|
277
|
+
if (signal.aborted)
|
|
278
|
+
return Promise.reject(signal.reason);
|
|
279
|
+
return new Promise((resolve, reject) => {
|
|
280
|
+
const onAbort = () => {
|
|
281
|
+
signal.removeEventListener('abort', onAbort);
|
|
282
|
+
reject(signal.reason);
|
|
283
|
+
};
|
|
284
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
285
|
+
deps.sleep(ms, signal).then(() => {
|
|
286
|
+
signal.removeEventListener('abort', onAbort);
|
|
287
|
+
resolve();
|
|
288
|
+
}, err => {
|
|
289
|
+
signal.removeEventListener('abort', onAbort);
|
|
290
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function parseTime(value) {
|
|
295
|
+
if (typeof value !== 'string')
|
|
296
|
+
return 0;
|
|
297
|
+
const t = Date.parse(value);
|
|
298
|
+
return Number.isFinite(t) ? t : 0;
|
|
299
|
+
}
|
|
300
|
+
function asRecord(value) {
|
|
301
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
302
|
+
? value
|
|
303
|
+
: undefined;
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=commit-signal.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run the tasks given to it no more than `limit` at a time, in the order
|
|
3
|
+
* given. A finishing task hands its slot straight to the next waiting one, so
|
|
4
|
+
* a caller that arrives during the hand-over waits too.
|
|
5
|
+
*/
|
|
6
|
+
export declare function concurrencyLimiter(limit: number): <T>(task: () => Promise<T>) => Promise<T>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run the tasks given to it no more than `limit` at a time, in the order
|
|
3
|
+
* given. A finishing task hands its slot straight to the next waiting one, so
|
|
4
|
+
* a caller that arrives during the hand-over waits too.
|
|
5
|
+
*/
|
|
6
|
+
export function concurrencyLimiter(limit) {
|
|
7
|
+
let running = 0;
|
|
8
|
+
const waiting = [];
|
|
9
|
+
const release = () => {
|
|
10
|
+
const next = waiting.shift();
|
|
11
|
+
if (next)
|
|
12
|
+
next();
|
|
13
|
+
else
|
|
14
|
+
running--;
|
|
15
|
+
};
|
|
16
|
+
return async (task) => {
|
|
17
|
+
if (running < limit)
|
|
18
|
+
running++;
|
|
19
|
+
else
|
|
20
|
+
await new Promise(resolve => waiting.push(resolve));
|
|
21
|
+
try {
|
|
22
|
+
return await task();
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
release();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=concurrency-limiter.js.map
|
package/dist/lib/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from 'node:os';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { DEFAULT_PROFILE, defaultCredentialsPath, readProfile } from './credentials.js';
|
|
3
|
+
import { DEFAULT_PROFILE, assertValidProfileName, defaultCredentialsPath, readProfile, } from './credentials.js';
|
|
4
4
|
export const DEFAULT_API_URL = 'https://api.testsprite.com';
|
|
5
5
|
/** Treat empty / whitespace-only env values as unset for `??` resolution chains. */
|
|
6
6
|
export function normalizeEnvVar(value) {
|
|
@@ -42,19 +42,24 @@ export function resolveProfileName(flagValue, env = process.env) {
|
|
|
42
42
|
export function loadConfig(options = {}) {
|
|
43
43
|
const env = options.env ?? process.env;
|
|
44
44
|
const profile = resolveProfileName(options.profile, env);
|
|
45
|
-
|
|
46
|
-
const fileEntry = readProfile(profile, { path: credentialsPath });
|
|
45
|
+
assertValidProfileName(profile);
|
|
47
46
|
// Empty / whitespace-only env vars are treated as unset so they do not
|
|
48
47
|
// short-circuit the `??` chain (e.g. `export TESTSPRITE_API_URL=` or
|
|
49
48
|
// `export TESTSPRITE_PROFILE=` in a shell profile). For the profile this
|
|
50
49
|
// also avoids a confusing VALIDATION_ERROR: an empty name fails the INI
|
|
51
50
|
// section-name guard, so without normalization a blank env var would break
|
|
52
51
|
// every command instead of falling back to the default profile. Matches the
|
|
53
|
-
// normalization in
|
|
52
|
+
// normalization in setup.
|
|
54
53
|
const envApiUrl = normalizeEnvVar(env.TESTSPRITE_API_URL);
|
|
55
54
|
const envApiKey = normalizeEnvVar(env.TESTSPRITE_API_KEY);
|
|
55
|
+
const explicitApiUrl = options.endpointUrl ?? envApiUrl;
|
|
56
|
+
// A complete explicit configuration must not depend on the credentials store.
|
|
57
|
+
// Missing fields still need the profile, including its normal filesystem errors.
|
|
58
|
+
const fileEntry = envApiKey === undefined || explicitApiUrl === undefined
|
|
59
|
+
? readProfile(profile, { path: options.credentialsPath ?? defaultCredentialsPath() })
|
|
60
|
+
: undefined;
|
|
56
61
|
return {
|
|
57
|
-
apiUrl:
|
|
62
|
+
apiUrl: explicitApiUrl ?? fileEntry?.apiUrl ?? DEFAULT_API_URL,
|
|
58
63
|
apiKey: envApiKey ?? fileEntry?.apiKey,
|
|
59
64
|
profile,
|
|
60
65
|
};
|
|
@@ -20,7 +20,7 @@ export type ConflictReason = 'in_flight' | 'mcp_view_only' | 'local_address' | '
|
|
|
20
20
|
| 'billing_hold'
|
|
21
21
|
/**
|
|
22
22
|
* A backend consumer needs a variable no test case in the project captures.
|
|
23
|
-
* Like `producer_in_flight`, its `
|
|
23
|
+
* Like `producer_in_flight`, its `currentResultId` is the result the server
|
|
24
24
|
* seeded BLOCKED for this request, which becomes the test case's latest
|
|
25
25
|
* status: never dispatched, never charged.
|
|
26
26
|
*/
|
|
@@ -32,6 +32,12 @@ export type ConflictReason = 'in_flight' | 'mcp_view_only' | 'local_address' | '
|
|
|
32
32
|
* `producer_in_flight` / `error` (the backend's nextAction). */
|
|
33
33
|
export interface RunConflict {
|
|
34
34
|
testId: string;
|
|
35
|
+
/** The in-flight result (wire name). Printed as `currentResultId`. */
|
|
36
|
+
currentResultId?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The launch the in-flight result belongs to (wire name). Absent on an older
|
|
39
|
+
* backend. Printed as `currentResultId`.
|
|
40
|
+
*/
|
|
35
41
|
currentRunId?: string;
|
|
36
42
|
reason?: ConflictReason;
|
|
37
43
|
message?: string;
|
|
@@ -39,7 +45,7 @@ export interface RunConflict {
|
|
|
39
45
|
/**
|
|
40
46
|
* Short human label for a conflict's cause — the reason a case did NOT dispatch.
|
|
41
47
|
* Absent reason renders as the legacy "already in flight" so an old backend's
|
|
42
|
-
* bare `{testId,
|
|
48
|
+
* bare `{testId, currentResultId?}` conflicts read exactly as they did before.
|
|
43
49
|
*/
|
|
44
50
|
export declare function describeConflict(c: RunConflict): string;
|
|
45
51
|
/**
|
|
@@ -53,7 +59,7 @@ export declare function describeConflict(c: RunConflict): string;
|
|
|
53
59
|
export declare function allConflictsInFlight(conflicts: readonly RunConflict[]): boolean;
|
|
54
60
|
/**
|
|
55
61
|
* A backend consumer blocked before dispatch on a missing or busy producer.
|
|
56
|
-
* The CLI reports it as a refusal (exit 6), as a single `
|
|
62
|
+
* The CLI reports it as a refusal (exit 6), as a single `run` does,
|
|
57
63
|
* rather than polling the result the server seeded for it.
|
|
58
64
|
*/
|
|
59
65
|
export declare function isProducerBlock(c: RunConflict): boolean;
|
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { ApiError, insufficientCreditsNextAction } from './errors.js';
|
|
18
18
|
import { classifyBillingRefusal, isPausedReason } from './billing-refusal.js';
|
|
19
|
+
import { runLabel } from './run-render.js';
|
|
19
20
|
/**
|
|
20
21
|
* Short human label for a conflict's cause — the reason a case did NOT dispatch.
|
|
21
22
|
* Absent reason renders as the legacy "already in flight" so an old backend's
|
|
22
|
-
* bare `{testId,
|
|
23
|
+
* bare `{testId, currentResultId?}` conflicts read exactly as they did before.
|
|
23
24
|
*/
|
|
24
25
|
export function describeConflict(c) {
|
|
25
26
|
switch (c.reason) {
|
|
@@ -42,7 +43,9 @@ export function describeConflict(c) {
|
|
|
42
43
|
return c.message || 'dispatch failed';
|
|
43
44
|
case 'in_flight':
|
|
44
45
|
default:
|
|
45
|
-
return c.
|
|
46
|
+
return c.currentResultId
|
|
47
|
+
? `already in flight (${runLabel({ resultId: c.currentResultId, runId: c.currentRunId }, 'lower')})`
|
|
48
|
+
: 'already in flight';
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
const CONFLICT_LABELS = {
|
|
@@ -79,7 +82,7 @@ function countByReason(conflicts) {
|
|
|
79
82
|
}
|
|
80
83
|
/**
|
|
81
84
|
* A backend consumer blocked before dispatch on a missing or busy producer.
|
|
82
|
-
* The CLI reports it as a refusal (exit 6), as a single `
|
|
85
|
+
* The CLI reports it as a refusal (exit 6), as a single `run` does,
|
|
83
86
|
* rather than polling the result the server seeded for it.
|
|
84
87
|
*/
|
|
85
88
|
export function isProducerBlock(c) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Question } from './types.js';
|
|
2
|
+
export declare const optionLetter: (index: number) => string;
|
|
3
|
+
/**
|
|
4
|
+
* The answers `apply --answer <n>=<choice>` gives a question card, keyed by
|
|
5
|
+
* each question's text as the portal's card sends them: an option's label,
|
|
6
|
+
* several labels joined by ", " when the question takes several, or the
|
|
7
|
+
* user's own words. Every question needs an answer, or the card keeps waiting.
|
|
8
|
+
*/
|
|
9
|
+
export declare function answersFor(questions: Question[], given: string[]): Record<string, string>;
|