@testsprite/testsprite-cli 0.11.0 → 0.13.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 -44
- package/dist/commands/agent.js +16 -13
- package/dist/commands/auth.d.ts +19 -0
- package/dist/commands/auth.js +60 -24
- package/dist/commands/ci.d.ts +86 -1
- package/dist/commands/ci.js +470 -9
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +22 -9
- package/dist/commands/init.js +14 -11
- package/dist/commands/project-env.d.ts +90 -0
- package/dist/commands/project-env.js +486 -0
- package/dist/commands/project.d.ts +15 -5
- package/dist/commands/project.js +88 -92
- package/dist/commands/schedule.d.ts +2 -0
- package/dist/commands/schedule.js +18 -10
- package/dist/commands/test.d.ts +102 -30
- package/dist/commands/test.js +1949 -419
- package/dist/commands/testlist.js +77 -21
- package/dist/commands/tunnel.d.ts +26 -3
- package/dist/commands/tunnel.js +211 -14
- package/dist/commands/usage.d.ts +3 -0
- package/dist/commands/usage.js +12 -5
- package/dist/index.js +47 -23
- package/dist/lib/agent-targets.d.ts +3 -3
- package/dist/lib/agent-targets.js +2 -2
- package/dist/lib/billing-refusal.d.ts +43 -0
- package/dist/lib/billing-refusal.js +171 -0
- package/dist/lib/bundle.d.ts +5 -0
- package/dist/lib/bundle.js +43 -13
- package/dist/lib/ci-linkage.d.ts +90 -0
- package/dist/lib/ci-linkage.js +181 -0
- package/dist/lib/client-factory.d.ts +4 -1
- package/dist/lib/client-factory.js +25 -2
- package/dist/lib/client-tag.d.ts +13 -0
- package/dist/lib/client-tag.js +44 -0
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.js +20 -1
- package/dist/lib/conflict-reason.d.ts +67 -2
- package/dist/lib/conflict-reason.js +148 -13
- package/dist/lib/credentials.js +56 -14
- package/dist/lib/cron.js +8 -1
- package/dist/lib/dry-run/samples.d.ts +13 -1
- package/dist/lib/dry-run/samples.js +51 -7
- package/dist/lib/errors.d.ts +62 -12
- package/dist/lib/errors.js +180 -25
- package/dist/lib/failing-fe-resolver.d.ts +1 -1
- package/dist/lib/failing-fe-resolver.js +3 -3
- package/dist/lib/gh-output.d.ts +26 -11
- package/dist/lib/gh-output.js +47 -15
- package/dist/lib/history-retention.d.ts +8 -0
- package/dist/lib/history-retention.js +24 -0
- package/dist/lib/http.d.ts +44 -19
- package/dist/lib/http.js +53 -26
- package/dist/lib/interrupt.d.ts +21 -13
- package/dist/lib/interrupt.js +32 -21
- package/dist/lib/junit-report.d.ts +11 -1
- package/dist/lib/junit-report.js +15 -3
- package/dist/lib/local-target.d.ts +33 -1
- package/dist/lib/local-target.js +78 -1
- package/dist/lib/output.d.ts +27 -1
- package/dist/lib/output.js +22 -3
- package/dist/lib/plan-poll.d.ts +11 -11
- package/dist/lib/plan-poll.js +12 -12
- package/dist/lib/plans.types.d.ts +9 -9
- package/dist/lib/plans.types.js +3 -3
- package/dist/lib/poll.d.ts +2 -2
- package/dist/lib/poll.js +9 -3
- package/dist/lib/render-error.d.ts +2 -0
- package/dist/lib/render-error.js +13 -0
- package/dist/lib/response-schemas.d.ts +54 -12
- package/dist/lib/response-schemas.js +106 -7
- package/dist/lib/runs.types.d.ts +92 -6
- package/dist/lib/secret-file.js +72 -14
- package/dist/lib/skill-nudge.d.ts +6 -1
- package/dist/lib/skill-nudge.js +32 -5
- package/dist/lib/target-url-preflight.d.ts +6 -4
- package/dist/lib/target-url-preflight.js +64 -51
- package/dist/lib/target-url.js +31 -12
- package/dist/lib/telemetry.d.ts +172 -3
- package/dist/lib/telemetry.js +276 -15
- package/dist/lib/ticker.js +93 -4
- package/dist/lib/tunnel-session.d.ts +13 -0
- package/dist/lib/tunnel-session.js +4 -1
- package/dist/lib/tunnel.types.d.ts +12 -2
- package/dist/lib/tunnel.types.js +2 -2
- package/dist/lib/version-notice.d.ts +20 -1
- package/dist/lib/version-notice.js +59 -12
- package/dist/lib/wait-exit.d.ts +8 -0
- package/dist/lib/wait-exit.js +76 -4
- package/dist/lib/workspace-status.d.ts +23 -0
- package/dist/lib/workspace-status.js +15 -0
- package/dist/version-guard.d.ts +7 -1
- package/dist/version-guard.js +19 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/skills/testsprite-onboard.skill.md +4 -4
- package/skills/testsprite-verify.codex.md +59 -57
- package/skills/testsprite-verify.skill.md +53 -36
package/dist/lib/errors.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolvePortalBase } from './facade.js';
|
|
2
|
+
import { classifyBillingRefusal, gateRefusalOf } from './billing-refusal.js';
|
|
2
3
|
/**
|
|
3
4
|
* Error codes shared with the backend facade and the MCP plugin.
|
|
4
5
|
* Must stay in sync across all three.
|
|
@@ -115,12 +116,44 @@ export function isAuthCode(code) {
|
|
|
115
116
|
}
|
|
116
117
|
export class CLIError extends Error {
|
|
117
118
|
exitCode;
|
|
118
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Stable machine error code — mirrored into telemetry's `errorCode` field
|
|
121
|
+
* and into the `--output json` error envelope (`{error:{code,...}}`).
|
|
122
|
+
* Defaults to the generic, deliberately out-of-catalog `'CLI_ERROR'`
|
|
123
|
+
* bucket for a plain `CLIError` (same convention as `InterruptError`'s
|
|
124
|
+
* `'INTERRUPTED'` and `RequestTimeoutError`'s `'REQUEST_TIMEOUT'` below —
|
|
125
|
+
* none of these are backend-issued codes, so they don't belong in
|
|
126
|
+
* `ERROR_CODES`). `ApiError` overrides this with the real catalog
|
|
127
|
+
* `ErrorCode` parsed from the server envelope.
|
|
128
|
+
*
|
|
129
|
+
* Before this field existed, `classifyCliError()`'s plain-`CLIError`
|
|
130
|
+
* fallback branch had nothing to report and telemetry events landed with
|
|
131
|
+
* `errorCode=None` — the same silent gap the final uncaught-exception
|
|
132
|
+
* branch had.
|
|
133
|
+
*/
|
|
134
|
+
code;
|
|
135
|
+
constructor(message, exitCode = 1, code = 'CLI_ERROR') {
|
|
119
136
|
super(message);
|
|
120
137
|
this.name = 'CLIError';
|
|
121
138
|
this.exitCode = exitCode;
|
|
139
|
+
this.code = code;
|
|
122
140
|
}
|
|
123
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Best-effort extraction of a `.code` string off an arbitrary thrown value —
|
|
144
|
+
* covers Node built-in errors (`ENOENT`, `ECONNREFUSED`, …) that reach the
|
|
145
|
+
* top-level catch without ever being wrapped in a `CLIError`. Used by the
|
|
146
|
+
* genuinely-uncaught-exception fallback in both `classifyCliError()` and
|
|
147
|
+
* `index.ts`'s final catch branch, so a filesystem/network error reports its
|
|
148
|
+
* real code instead of falling into the generic `'UNCAUGHT_EXCEPTION'`
|
|
149
|
+
* bucket.
|
|
150
|
+
*/
|
|
151
|
+
export function extractNodeErrorCode(err) {
|
|
152
|
+
if (typeof err !== 'object' || err === null || !('code' in err))
|
|
153
|
+
return undefined;
|
|
154
|
+
const code = err.code;
|
|
155
|
+
return typeof code === 'string' && code.length > 0 ? code : undefined;
|
|
156
|
+
}
|
|
124
157
|
/**
|
|
125
158
|
* Termination signals with graceful handling, mapped to their conventional
|
|
126
159
|
* `128 + signum` exit code. sourceRef: POSIX signal numbers (SIGHUP=1,
|
|
@@ -133,10 +166,9 @@ export const TERMINATION_EXIT_CODES = {
|
|
|
133
166
|
SIGHUP: 129, // 128 + 1
|
|
134
167
|
};
|
|
135
168
|
/**
|
|
136
|
-
* User-initiated interrupt (SIGINT/SIGTERM/SIGHUP) observed
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* honest partial envelope + re-attach hint, then rethrow to `index.ts`.
|
|
169
|
+
* User-initiated interrupt (SIGINT/SIGTERM/SIGHUP) observed during an armed
|
|
170
|
+
* wait or a disarmed request. Run/wait paths mark the error so `index.ts` can give
|
|
171
|
+
* recovery guidance only when there is a run to re-attach to.
|
|
140
172
|
*
|
|
141
173
|
* Deliberately NOT in `ERROR_CODES` — on a signal the CLI
|
|
142
174
|
* exits 130/143 without consulting the error catalog. The JSON-mode stderr
|
|
@@ -145,31 +177,41 @@ export const TERMINATION_EXIT_CODES = {
|
|
|
145
177
|
*/
|
|
146
178
|
export class InterruptError extends CLIError {
|
|
147
179
|
signal;
|
|
180
|
+
runWaitContext = false;
|
|
148
181
|
constructor(signal) {
|
|
149
|
-
super(`Interrupted by ${signal}.`, TERMINATION_EXIT_CODES[signal]);
|
|
182
|
+
super(`Interrupted by ${signal}.`, TERMINATION_EXIT_CODES[signal], 'INTERRUPTED');
|
|
150
183
|
this.name = 'InterruptError';
|
|
151
184
|
this.signal = signal;
|
|
152
185
|
}
|
|
153
186
|
}
|
|
154
187
|
export class NotImplementedError extends CLIError {
|
|
155
188
|
constructor(commandPath) {
|
|
156
|
-
super(`Command not yet implemented: ${commandPath}`, 2);
|
|
189
|
+
super(`Command not yet implemented: ${commandPath}`, 2, 'NOT_IMPLEMENTED');
|
|
157
190
|
this.name = 'NotImplementedError';
|
|
158
191
|
}
|
|
159
192
|
}
|
|
160
193
|
/**
|
|
161
|
-
* Server-returned API error. The CLI
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* constructs an envelope with the same shape so the user sees identical
|
|
165
|
-
* wording across paths).
|
|
194
|
+
* Server-returned API error. The CLI preserves the facade's nonempty
|
|
195
|
+
* `nextAction` and synthesizes one for billing refusals that omit it.
|
|
196
|
+
* Locally-detected pre-flight conditions use the same envelope shape.
|
|
166
197
|
*/
|
|
167
198
|
export class ApiError extends CLIError {
|
|
199
|
+
// `override`: CLIError now declares its own `code: string` (defaulting
|
|
200
|
+
// 'CLI_ERROR'), so `noImplicitOverride` requires this modifier on the
|
|
201
|
+
// narrowed redeclaration. Under useDefineForClassFields (the default at
|
|
202
|
+
// this tsconfig's ES2022 target) this field IS re-initialized to
|
|
203
|
+
// `undefined` right after `super(...)` returns — but the constructor body
|
|
204
|
+
// below unconditionally reassigns `this.code = envelope.code` afterward,
|
|
205
|
+
// so the final value is always the envelope's code, never the CLIError
|
|
206
|
+
// base default. See the pinned regression test in errors.test.ts
|
|
207
|
+
// ("ApiError.code overrides the CLIError base default").
|
|
168
208
|
code;
|
|
169
209
|
requestId;
|
|
170
210
|
nextAction;
|
|
211
|
+
serverNextAction;
|
|
171
212
|
details;
|
|
172
213
|
httpStatus;
|
|
214
|
+
apiUrl;
|
|
173
215
|
/**
|
|
174
216
|
* Parsed `Retry-After` header value in milliseconds, when present on the
|
|
175
217
|
* HTTP response. Only set for `RATE_LIMITED` (429) responses where the
|
|
@@ -178,14 +220,16 @@ export class ApiError extends CLIError {
|
|
|
178
220
|
* absent or unparseable.
|
|
179
221
|
*/
|
|
180
222
|
retryAfterMs;
|
|
181
|
-
constructor(envelope, httpStatus, retryAfterMs) {
|
|
223
|
+
constructor(envelope, httpStatus, retryAfterMs, apiUrl, serverNextAction) {
|
|
182
224
|
super(envelope.message, exitCodeFor(envelope.code));
|
|
183
225
|
this.name = 'ApiError';
|
|
184
226
|
this.code = envelope.code;
|
|
185
227
|
this.requestId = envelope.requestId;
|
|
186
228
|
this.nextAction = envelope.nextAction;
|
|
229
|
+
this.serverNextAction = serverNextAction ?? envelope.nextAction;
|
|
187
230
|
this.details = envelope.details;
|
|
188
231
|
this.httpStatus = httpStatus;
|
|
232
|
+
this.apiUrl = apiUrl;
|
|
189
233
|
this.retryAfterMs = retryAfterMs;
|
|
190
234
|
}
|
|
191
235
|
/**
|
|
@@ -195,7 +239,17 @@ export class ApiError extends CLIError {
|
|
|
195
239
|
*/
|
|
196
240
|
static fromEnvelope(raw, httpStatus, retryAfterMs, apiUrl) {
|
|
197
241
|
const envelope = parseEnvelopeBody(raw, httpStatus, apiUrl);
|
|
198
|
-
|
|
242
|
+
const serverNextAction = envelope.nextAction;
|
|
243
|
+
if (!envelope.nextAction) {
|
|
244
|
+
const refusal = classifyBillingRefusal({ ...envelope, apiUrl });
|
|
245
|
+
if (refusal) {
|
|
246
|
+
envelope.nextAction =
|
|
247
|
+
envelope.code === 'INSUFFICIENT_CREDITS'
|
|
248
|
+
? insufficientCreditsNextAction(apiUrl)
|
|
249
|
+
: refusal.nextAction;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return new ApiError(envelope, httpStatus, retryAfterMs, apiUrl, serverNextAction);
|
|
199
253
|
}
|
|
200
254
|
/**
|
|
201
255
|
* Type-safe accessor for a single key inside `details`. Avoids the
|
|
@@ -229,7 +283,31 @@ export class ApiError extends CLIError {
|
|
|
229
283
|
* AUTH_REQUIRED template so the user sees the same thing whether the
|
|
230
284
|
* miss was detected before or after sending the request.
|
|
231
285
|
*/
|
|
232
|
-
|
|
286
|
+
/**
|
|
287
|
+
* `profile` is supplied only when a NON-default profile was selected — by
|
|
288
|
+
* `--profile` or by `TESTSPRITE_PROFILE`. Naming it matters because the
|
|
289
|
+
* selection is invisible otherwise: a typo in either one picks a profile
|
|
290
|
+
* that has no credentials, and the generic message sends the reader off to
|
|
291
|
+
* configure the default profile they already have.
|
|
292
|
+
*/
|
|
293
|
+
static authRequired(requestId = 'local', profile) {
|
|
294
|
+
if (profile !== undefined) {
|
|
295
|
+
return new ApiError({
|
|
296
|
+
code: 'AUTH_REQUIRED',
|
|
297
|
+
// `message` stays byte-identical to the default-profile case: the
|
|
298
|
+
// wording is stable per error code, so callers can pattern-match on it.
|
|
299
|
+
// The profile belongs in the remediation and in `details`, which are
|
|
300
|
+
// the per-error context.
|
|
301
|
+
message: 'Authentication is required.',
|
|
302
|
+
nextAction: `No credentials are stored for profile "${profile}". Run \`testsprite setup --profile ${profile}\`` +
|
|
303
|
+
' to configure it, or drop the profile selection if you did not mean to use one' +
|
|
304
|
+
' (`--profile` flag, TESTSPRITE_PROFILE env var). `testsprite doctor` prints the profile in use.',
|
|
305
|
+
requestId,
|
|
306
|
+
// Safe to echo: every credential read passes the profile name through
|
|
307
|
+
// `assertValidProfileName` first, so it matches /^[A-Za-z0-9._-]+$/.
|
|
308
|
+
details: { profile },
|
|
309
|
+
});
|
|
310
|
+
}
|
|
233
311
|
return new ApiError({
|
|
234
312
|
code: 'AUTH_REQUIRED',
|
|
235
313
|
message: 'Authentication is required.',
|
|
@@ -306,7 +384,7 @@ export class RequestTimeoutError extends CLIError {
|
|
|
306
384
|
constructor(timeoutMs, requestId = 'local') {
|
|
307
385
|
const timeoutSec = Math.round(timeoutMs / 1000);
|
|
308
386
|
super(`Request timed out after ${timeoutSec}s (client-side). ` +
|
|
309
|
-
`Use --request-timeout <seconds> or TESTSPRITE_REQUEST_TIMEOUT_MS to extend the deadline.`, 7);
|
|
387
|
+
`Use --request-timeout <seconds> or TESTSPRITE_REQUEST_TIMEOUT_MS to extend the deadline.`, 7, 'REQUEST_TIMEOUT');
|
|
310
388
|
this.name = 'RequestTimeoutError';
|
|
311
389
|
this.requestId = requestId;
|
|
312
390
|
this.timeoutMs = timeoutMs;
|
|
@@ -372,6 +450,29 @@ function isInsufficientCredits(rawCode, message, details) {
|
|
|
372
450
|
const hasCreditsMessage = /insufficient credits/i.test(message);
|
|
373
451
|
return hasRequiredField || hasCreditsMessage;
|
|
374
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* The synthesized `nextAction` for an INSUFFICIENT_CREDITS refusal when the
|
|
455
|
+
* backend supplied none (older backends; the CLI's own all-credits batch
|
|
456
|
+
* refusal). Portal links resolve per environment from the API endpoint (dev and
|
|
457
|
+
* prod portals live on different domains); an unknown host gets the route only —
|
|
458
|
+
* a hardcoded domain would point at the wrong environment.
|
|
459
|
+
*
|
|
460
|
+
* V3 API keys are membership-bound: a key minted for a team org spends THAT
|
|
461
|
+
* org's wallet, not the holder's personal one, and there is no request-scoped
|
|
462
|
+
* signal at this layer to tell which kind of key just failed. So the hint
|
|
463
|
+
* deliberately does NOT assert "top up your (personal) credits" as the only
|
|
464
|
+
* path — it offers the personal-key link (still correct for the common case)
|
|
465
|
+
* alongside an honest org-bound alternative, rather than guessing. The
|
|
466
|
+
* `testsprite usage` pointer is the CLI-native way to check the balance before
|
|
467
|
+
* a large run fan-out.
|
|
468
|
+
*/
|
|
469
|
+
export function insufficientCreditsNextAction(apiUrl) {
|
|
470
|
+
const portalBase = apiUrl === undefined ? undefined : resolvePortalBase(apiUrl);
|
|
471
|
+
return ((portalBase !== undefined
|
|
472
|
+
? `Top up credits at ${portalBase}/dashboard/settings/billing (personal keys) — ask an org admin if this key is organization-bound — or upgrade your plan at ${portalBase}/pricing.`
|
|
473
|
+
: 'Top up credits on the portal Billing page (/dashboard/settings/billing) if this is a personal key — ask an org admin if it is organization-bound — or upgrade your plan (/pricing).') +
|
|
474
|
+
' Run `testsprite usage` to check your current balance before the next run.');
|
|
475
|
+
}
|
|
375
476
|
/**
|
|
376
477
|
* Detect the "ambiguous org" sub-case of a CONFLICT (409) envelope: a
|
|
377
478
|
* membership-key caller's testId resolved to projects in more than one of
|
|
@@ -398,6 +499,67 @@ function parseEnvelopeBody(raw, httpStatus, apiUrl) {
|
|
|
398
499
|
};
|
|
399
500
|
}
|
|
400
501
|
const obj = raw;
|
|
502
|
+
const wireCode = typeof obj.code === 'string' ? obj.code : '';
|
|
503
|
+
// The exact wire codes the workspace-gate body can send — checked on their
|
|
504
|
+
// own (not just the open-ended `_limit_exceeded` suffix) so a body with no
|
|
505
|
+
// HTTP status attached still has something narrow to match against.
|
|
506
|
+
const isKnownGateWireCode = wireCode === 'feature_not_entitled' ||
|
|
507
|
+
wireCode === 'workspace_paused' ||
|
|
508
|
+
wireCode === 'environment_limit_exceeded' ||
|
|
509
|
+
wireCode === 'testlist_limit_exceeded' ||
|
|
510
|
+
wireCode === 'schedule_limit_exceeded' ||
|
|
511
|
+
wireCode === 'github_repo_limit_exceeded' ||
|
|
512
|
+
wireCode === 'fixture_limit_exceeded' ||
|
|
513
|
+
wireCode === 'project_limit_exceeded';
|
|
514
|
+
// Only take this raw shape for the HTTP statuses the gate actually answers
|
|
515
|
+
// with (402/403) — matching purely on `code` let an unrelated 429 body that
|
|
516
|
+
// happens to end in `_limit_exceeded` (e.g. a future `rate_limit_exceeded`)
|
|
517
|
+
// get reclassified as a non-retriable FEATURE_GATED and stop being retried.
|
|
518
|
+
// With no status at all, only the exact known codes above qualify: the
|
|
519
|
+
// open-ended suffix match is too permissive without a status to corroborate it.
|
|
520
|
+
const takesRawGateShape = httpStatus === 402 || httpStatus === 403
|
|
521
|
+
? isKnownGateWireCode || /_limit_exceeded$/.test(wireCode)
|
|
522
|
+
: httpStatus === undefined && isKnownGateWireCode;
|
|
523
|
+
if (takesRawGateShape) {
|
|
524
|
+
// A `reason` on the body is the server's and passes through as-is.
|
|
525
|
+
// Otherwise the wire code says which gate refusal it is, named as the
|
|
526
|
+
// gate names it.
|
|
527
|
+
const reason = typeof obj.reason === 'string' && obj.reason !== ''
|
|
528
|
+
? obj.reason
|
|
529
|
+
: wireCode.endsWith('_limit_exceeded')
|
|
530
|
+
? 'limit_exceeded'
|
|
531
|
+
: wireCode === 'workspace_paused'
|
|
532
|
+
? 'paused'
|
|
533
|
+
: 'not_entitled';
|
|
534
|
+
const details = { reason };
|
|
535
|
+
for (const key of [
|
|
536
|
+
'feature',
|
|
537
|
+
'plan',
|
|
538
|
+
'limit',
|
|
539
|
+
'current',
|
|
540
|
+
'requiredPlan',
|
|
541
|
+
'orgId',
|
|
542
|
+
'billingUrl',
|
|
543
|
+
'action',
|
|
544
|
+
'pauseKind',
|
|
545
|
+
'pauseTarget',
|
|
546
|
+
]) {
|
|
547
|
+
if (obj[key] !== undefined && obj[key] !== null)
|
|
548
|
+
details[key] = obj[key];
|
|
549
|
+
}
|
|
550
|
+
if (gateRefusalOf(reason) === 'limit_exceeded' && details.feature === undefined) {
|
|
551
|
+
details.feature = wireCode.slice(0, -'_limit_exceeded'.length);
|
|
552
|
+
}
|
|
553
|
+
return {
|
|
554
|
+
code: 'FEATURE_GATED',
|
|
555
|
+
message: typeof obj.message === 'string'
|
|
556
|
+
? obj.message
|
|
557
|
+
: 'This action is unavailable on the current plan.',
|
|
558
|
+
nextAction: typeof obj.nextAction === 'string' ? obj.nextAction : '',
|
|
559
|
+
requestId: typeof obj.requestId === 'string' ? obj.requestId : 'unknown',
|
|
560
|
+
details,
|
|
561
|
+
};
|
|
562
|
+
}
|
|
401
563
|
// Raw Nest/Express 404 shape: `{ message, error: "Not Found", statusCode }`.
|
|
402
564
|
// The current parser was matching `obj.error` (a string) and falling to
|
|
403
565
|
// `Server error.` while losing the actual `message` from the body
|
|
@@ -414,7 +576,7 @@ function parseEnvelopeBody(raw, httpStatus, apiUrl) {
|
|
|
414
576
|
? `${message} — endpoint not available on the current backend deployment.`
|
|
415
577
|
: message,
|
|
416
578
|
nextAction: isRouteMissing404
|
|
417
|
-
? 'Verify the CLI is targeting the right environment (check `testsprite auth status` for `env`), and confirm
|
|
579
|
+
? 'Verify the CLI is targeting the right environment (check `testsprite auth status` for `env`), and confirm that backend deployment includes this endpoint — it may need a newer backend release.'
|
|
418
580
|
: '',
|
|
419
581
|
requestId: 'unknown',
|
|
420
582
|
details: { statusCode: obj.statusCode },
|
|
@@ -450,17 +612,10 @@ function parseEnvelopeBody(raw, httpStatus, apiUrl) {
|
|
|
450
612
|
// (personal) credits" as the only path — it offers the personal-key
|
|
451
613
|
// link (still correct for the common case) alongside an honest
|
|
452
614
|
// org-bound alternative, rather than guessing.
|
|
453
|
-
const portalBase = apiUrl === undefined ? undefined : resolvePortalBase(apiUrl);
|
|
454
|
-
const billingNextAction = nextAction !== ''
|
|
455
|
-
? nextAction
|
|
456
|
-
: (portalBase !== undefined
|
|
457
|
-
? `Top up credits at ${portalBase}/dashboard/settings/billing (personal keys) — ask an org admin if this key is organization-bound — or upgrade your plan at ${portalBase}/pricing.`
|
|
458
|
-
: 'Top up credits on the portal Billing page (/dashboard/settings/billing) if this is a personal key — ask an org admin if it is organization-bound — or upgrade your plan (/pricing).') +
|
|
459
|
-
' Run `testsprite usage` to check your current balance before the next run.';
|
|
460
615
|
return {
|
|
461
616
|
code: 'INSUFFICIENT_CREDITS',
|
|
462
617
|
message,
|
|
463
|
-
nextAction:
|
|
618
|
+
nextAction: nextAction !== '' ? nextAction : insufficientCreditsNextAction(apiUrl),
|
|
464
619
|
requestId,
|
|
465
620
|
details,
|
|
466
621
|
};
|
|
@@ -44,7 +44,7 @@ export interface ResolverOptions {
|
|
|
44
44
|
*/
|
|
45
45
|
maxPages?: number;
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
* The operator's pinned `failingFrontendTestId` (the static value
|
|
48
48
|
* from fixtures.local.json). "Freshest failed" alone is fragile in a shared
|
|
49
49
|
* project: any OTHER FE test that fails more recently than a dedicated,
|
|
50
50
|
* permanently-red fixture silently steals the slot (live-reproduced
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
export async function resolveFailingFrontendTestId(opts) {
|
|
27
27
|
const { baseUrl, apiKey, projectId, maxPages = 5, preferredId } = opts;
|
|
28
28
|
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
29
|
-
//
|
|
29
|
+
// Probe the pinned fixture directly first, so the
|
|
30
30
|
// preference cannot be defeated by the maxPages list-scan cap (a pinned
|
|
31
31
|
// fixture beyond page `maxPages` would otherwise silently lose the slot to
|
|
32
32
|
// an incidental fresher failure). Any probe error or non-failed status
|
|
@@ -44,7 +44,7 @@ export async function resolveFailingFrontendTestId(opts) {
|
|
|
44
44
|
});
|
|
45
45
|
if (resp.ok) {
|
|
46
46
|
const test = (await resp.json());
|
|
47
|
-
// The probe must honor the resolver's project scope
|
|
47
|
+
// The probe must honor the resolver's project scope:
|
|
48
48
|
// the list path filters by projectId server-side, so a pin that
|
|
49
49
|
// points at a failed FE test in a DIFFERENT project must not win
|
|
50
50
|
// here either. A response without a matching projectId (absent or
|
|
@@ -118,7 +118,7 @@ export async function resolveFailingFrontendTestId(opts) {
|
|
|
118
118
|
reason: 'No frontend tests with status=failed found in project; falling back to static fixture',
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
//
|
|
121
|
+
// A pinned, dedicated "always red" fixture wins over freshest
|
|
122
122
|
// whenever it is still in the failed set — see the doc comment on
|
|
123
123
|
// ResolverOptions.preferredId for why "freshest" alone is not enough.
|
|
124
124
|
if (preferredId) {
|
package/dist/lib/gh-output.d.ts
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* single `test run <test-id> --wait` and the `test run --all --wait` batch.
|
|
5
5
|
*
|
|
6
6
|
* A `--wait` run presents its result in the formats CI consumes:
|
|
7
|
-
* (a) a stable machine summary `{total, passed, failed, timedOut,
|
|
8
|
-
* written to `--summary-file <path>` when requested,
|
|
7
|
+
* (a) a stable machine summary `{total, passed, failed, skipped, timedOut,
|
|
8
|
+
* runs[]}` written to `--summary-file <path>` when requested,
|
|
9
9
|
* (b) a Markdown results table appended to `$GITHUB_STEP_SUMMARY` when
|
|
10
10
|
* running under GitHub Actions,
|
|
11
|
-
* (c) one
|
|
12
|
-
*
|
|
11
|
+
* (c) one workflow-command line per non-passed run so it annotates the PR
|
|
12
|
+
* checks tab — `::error::` for a dispatched run that failed or timed
|
|
13
|
+
* out, `::warning::` for a test that never dispatched.
|
|
13
14
|
* Activation: `GITHUB_ACTIONS=true` in the environment, or the explicit
|
|
14
15
|
* `--gh-output` flag (which forces the annotations even off-Actions, so the
|
|
15
16
|
* behavior is previewable locally). All writes are best-effort: a broken
|
|
@@ -31,9 +32,18 @@ export interface CiSummary {
|
|
|
31
32
|
total: number;
|
|
32
33
|
passed: number;
|
|
33
34
|
failed: number;
|
|
35
|
+
/**
|
|
36
|
+
* Requested tests that never dispatched (deferred / conflict / not_found /
|
|
37
|
+
* skipped / no_tests rows). Kept OUT of `failed`: `failed` claiming
|
|
38
|
+
* a test failed while the exit code says otherwise is the artifacts-disagree
|
|
39
|
+
* bug this field fixes. Non-dispatch still gates the exit where it should
|
|
40
|
+
* (deferred → 7, all-conflict → 6, all-not-found rerun → 4, zero-dispatch → 5).
|
|
41
|
+
*/
|
|
42
|
+
skipped: number;
|
|
34
43
|
timedOut: number;
|
|
35
44
|
runs: CiRunRow[];
|
|
36
45
|
}
|
|
46
|
+
export declare function isNonDispatchedStatus(status: string): boolean;
|
|
37
47
|
/**
|
|
38
48
|
* Reduce the batch command's JSON payload into the CI summary. The parse is
|
|
39
49
|
* defensive: it reads the same `accepted[]` rows the automation contract
|
|
@@ -41,11 +51,13 @@ export interface CiSummary {
|
|
|
41
51
|
* after a timeout) reduces to an empty run list rather than a crash.
|
|
42
52
|
*
|
|
43
53
|
* Non-dispatched work (`deferred` / `conflicts` / `notFound`) is folded in as
|
|
44
|
-
* non-passed rows
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
54
|
+
* non-passed rows so a partial batch like `1 accepted passed + 1 deferred`
|
|
55
|
+
* cannot read as "1/1 passed" with no annotation — but it counts as `skipped`,
|
|
56
|
+
* never `failed`: whether non-dispatch fails the job is the exit-code
|
|
57
|
+
* gates' call, and a `failed` count the gates disagree with is exactly the
|
|
58
|
+
* artifacts-contradict-the-exit bug. (`skippedFrontend` / `skippedIntegration`
|
|
59
|
+
* are NOT folded in — they exit 0 and are the Action layer's allow-partial
|
|
60
|
+
* concern.)
|
|
49
61
|
*/
|
|
50
62
|
export declare function summarizeAcceptedPayload(capturedJson: string, opts?: {
|
|
51
63
|
notFoundNote?: string;
|
|
@@ -71,8 +83,11 @@ export declare function renderJobSummaryMarkdown(summary: CiSummary): string;
|
|
|
71
83
|
/**
|
|
72
84
|
* Emit the GitHub-native surfaces. Self-gating on the standard env vars:
|
|
73
85
|
* `$GITHUB_STEP_SUMMARY` (a file path Actions provides) receives the Markdown
|
|
74
|
-
* table; `GITHUB_ACTIONS=true` enables one
|
|
75
|
-
*
|
|
86
|
+
* table; `GITHUB_ACTIONS=true` enables one workflow command per non-passed run
|
|
87
|
+
* on stdout (Actions parses workflow commands from stdout) — `::error::` for a
|
|
88
|
+
* dispatched run that failed or timed out, `::warning::` for a test that never
|
|
89
|
+
* ran (deferred / conflict / not_found / skipped), so a red annotation always
|
|
90
|
+
* means a red-worthy outcome and never contradicts the exit code.
|
|
76
91
|
* `force` (the `--gh-output` flag) emits the annotations even off-Actions;
|
|
77
92
|
* the step summary still requires the env-provided file path to exist.
|
|
78
93
|
* Both writes are best-effort: a broken summary file must not mask the gate.
|
package/dist/lib/gh-output.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { appendFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { describeConflict } from './conflict-reason.js';
|
|
3
|
+
/**
|
|
4
|
+
* Row statuses that mean "this test never ran" as opposed to "this run did not
|
|
5
|
+
* pass". They count as `skipped` in the summary (not `failed`) and annotate as
|
|
6
|
+
* `::warning::` (not `::error::`) so every CI surface tells the same story as
|
|
7
|
+
* the exit code.
|
|
8
|
+
*/
|
|
9
|
+
const NON_DISPATCHED_STATUSES = new Set([
|
|
10
|
+
'deferred',
|
|
11
|
+
'conflict',
|
|
12
|
+
'not_found',
|
|
13
|
+
'skipped',
|
|
14
|
+
'no_tests',
|
|
15
|
+
]);
|
|
16
|
+
export function isNonDispatchedStatus(status) {
|
|
17
|
+
return NON_DISPATCHED_STATUSES.has(status);
|
|
18
|
+
}
|
|
2
19
|
/**
|
|
3
20
|
* Reduce a non-dispatched bucket (`deferred` / `conflicts` / `notFound`) into
|
|
4
21
|
* CI rows. Items are either bare testId strings (`notFound`) or
|
|
@@ -16,7 +33,7 @@ function bucketRows(bucket, status, note) {
|
|
|
16
33
|
testId,
|
|
17
34
|
status,
|
|
18
35
|
...(currentRunId ? { runId: currentRunId } : {}),
|
|
19
|
-
error: note,
|
|
36
|
+
error: typeof note === 'string' ? note : note(item),
|
|
20
37
|
};
|
|
21
38
|
});
|
|
22
39
|
}
|
|
@@ -27,11 +44,13 @@ function bucketRows(bucket, status, note) {
|
|
|
27
44
|
* after a timeout) reduces to an empty run list rather than a crash.
|
|
28
45
|
*
|
|
29
46
|
* Non-dispatched work (`deferred` / `conflicts` / `notFound`) is folded in as
|
|
30
|
-
* non-passed rows
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
47
|
+
* non-passed rows so a partial batch like `1 accepted passed + 1 deferred`
|
|
48
|
+
* cannot read as "1/1 passed" with no annotation — but it counts as `skipped`,
|
|
49
|
+
* never `failed`: whether non-dispatch fails the job is the exit-code
|
|
50
|
+
* gates' call, and a `failed` count the gates disagree with is exactly the
|
|
51
|
+
* artifacts-contradict-the-exit bug. (`skippedFrontend` / `skippedIntegration`
|
|
52
|
+
* are NOT folded in — they exit 0 and are the Action layer's allow-partial
|
|
53
|
+
* concern.)
|
|
35
54
|
*/
|
|
36
55
|
export function summarizeAcceptedPayload(capturedJson, opts = {}) {
|
|
37
56
|
let parsed;
|
|
@@ -66,7 +85,12 @@ export function summarizeAcceptedPayload(capturedJson, opts = {}) {
|
|
|
66
85
|
const rows = [
|
|
67
86
|
...acceptedRows,
|
|
68
87
|
...bucketRows(payload.deferred, 'deferred', 'rate-deferred (not dispatched)'),
|
|
69
|
-
...bucketRows(payload.conflicts, 'conflict',
|
|
88
|
+
...bucketRows(payload.conflicts, 'conflict', item => {
|
|
89
|
+
const conflict = item;
|
|
90
|
+
return conflict && typeof conflict.testId === 'string' && conflict.reason
|
|
91
|
+
? `${describeConflict(conflict)} (not dispatched)`
|
|
92
|
+
: 'already in flight (not dispatched)';
|
|
93
|
+
}),
|
|
70
94
|
// Default note is `test rerun`'s cause (a not-found id has no replayable
|
|
71
95
|
// run). `testlist run` passes its own — a not-found `--case` id is one that
|
|
72
96
|
// is not a member of the list — so the annotation/artifact don't state the
|
|
@@ -75,8 +99,9 @@ export function summarizeAcceptedPayload(capturedJson, opts = {}) {
|
|
|
75
99
|
];
|
|
76
100
|
const passed = rows.filter(row => row.status === 'passed').length;
|
|
77
101
|
const timedOut = rows.filter(row => row.status === 'timeout').length;
|
|
78
|
-
const
|
|
79
|
-
|
|
102
|
+
const skipped = rows.filter(row => isNonDispatchedStatus(row.status)).length;
|
|
103
|
+
const failed = rows.length - passed - timedOut - skipped;
|
|
104
|
+
return { total: rows.length, passed, failed, skipped, timedOut, runs: rows };
|
|
80
105
|
}
|
|
81
106
|
/**
|
|
82
107
|
* Reduce a single `test run <test-id> --wait` result into the same CI summary
|
|
@@ -97,8 +122,9 @@ export function summarizeSingleRun(run) {
|
|
|
97
122
|
};
|
|
98
123
|
const passed = row.status === 'passed' ? 1 : 0;
|
|
99
124
|
const timedOut = row.status === 'timeout' ? 1 : 0;
|
|
100
|
-
const
|
|
101
|
-
|
|
125
|
+
const skipped = isNonDispatchedStatus(row.status) ? 1 : 0;
|
|
126
|
+
const failed = 1 - passed - timedOut - skipped;
|
|
127
|
+
return { total: 1, passed, failed, skipped, timedOut, runs: [row] };
|
|
102
128
|
}
|
|
103
129
|
/**
|
|
104
130
|
* Escape a value for a Markdown table cell. A raw `|` would break the column
|
|
@@ -147,7 +173,7 @@ export function renderJobSummaryMarkdown(summary) {
|
|
|
147
173
|
return [
|
|
148
174
|
'## TestSprite results',
|
|
149
175
|
'',
|
|
150
|
-
`**${summary.passed}/${summary.total} passed** (${summary.failed} failed, ${summary.timedOut} timed out)`,
|
|
176
|
+
`**${summary.passed}/${summary.total} passed** (${summary.failed} failed, ${summary.skipped} skipped, ${summary.timedOut} timed out)`,
|
|
151
177
|
'',
|
|
152
178
|
'| Test | Status | Run |',
|
|
153
179
|
'| --- | --- | --- |',
|
|
@@ -195,8 +221,11 @@ function escapeCommandProperty(value) {
|
|
|
195
221
|
/**
|
|
196
222
|
* Emit the GitHub-native surfaces. Self-gating on the standard env vars:
|
|
197
223
|
* `$GITHUB_STEP_SUMMARY` (a file path Actions provides) receives the Markdown
|
|
198
|
-
* table; `GITHUB_ACTIONS=true` enables one
|
|
199
|
-
*
|
|
224
|
+
* table; `GITHUB_ACTIONS=true` enables one workflow command per non-passed run
|
|
225
|
+
* on stdout (Actions parses workflow commands from stdout) — `::error::` for a
|
|
226
|
+
* dispatched run that failed or timed out, `::warning::` for a test that never
|
|
227
|
+
* ran (deferred / conflict / not_found / skipped), so a red annotation always
|
|
228
|
+
* means a red-worthy outcome and never contradicts the exit code.
|
|
200
229
|
* `force` (the `--gh-output` flag) emits the annotations even off-Actions;
|
|
201
230
|
* the step summary still requires the env-provided file path to exist.
|
|
202
231
|
* Both writes are best-effort: a broken summary file must not mask the gate.
|
|
@@ -227,7 +256,10 @@ export function emitGithubOutputs(summary, env, sinks, opts = {}) {
|
|
|
227
256
|
// able to smuggle a second workflow command into the Actions stream.
|
|
228
257
|
const title = `TestSprite ${escapeCommandProperty(row.title?.trim() || row.testId)}`;
|
|
229
258
|
const message = escapeCommandData(`status=${row.status}${detail}${link}`);
|
|
230
|
-
|
|
259
|
+
// Severity mirrors the summary counters: never-dispatched rows are
|
|
260
|
+
// warnings (they may not even gate the exit), real failures are errors.
|
|
261
|
+
const severity = NON_DISPATCHED_STATUSES.has(row.status) ? 'warning' : 'error';
|
|
262
|
+
annotate(`::${severity} title=${title}::${message}`);
|
|
231
263
|
}
|
|
232
264
|
}
|
|
233
265
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface HistoryRetentionMeta {
|
|
2
|
+
tier?: string;
|
|
3
|
+
retentionDays?: number | null;
|
|
4
|
+
hiddenCount?: number;
|
|
5
|
+
billingUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Returns no text for older backends, unlimited history, or an unhidden page. */
|
|
8
|
+
export declare function historyRetentionNote(meta: HistoryRetentionMeta | undefined, apiUrl: string, derived?: boolean): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { resolveBillingLinks } from './billing-refusal.js';
|
|
2
|
+
/** Returns no text for older backends, unlimited history, or an unhidden page. */
|
|
3
|
+
export function historyRetentionNote(meta, apiUrl, derived = false) {
|
|
4
|
+
if (!meta || !Number.isFinite(meta.hiddenCount) || !meta.hiddenCount || meta.hiddenCount <= 0) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
if (meta.retentionDays == null || !Number.isFinite(meta.retentionDays))
|
|
8
|
+
return undefined;
|
|
9
|
+
const { pricing, billing } = resolveBillingLinks({
|
|
10
|
+
apiUrl,
|
|
11
|
+
billingUrl: meta.billingUrl,
|
|
12
|
+
});
|
|
13
|
+
const count = meta.hiddenCount;
|
|
14
|
+
const runs = `${count} run${count === 1 ? '' : 's'}`;
|
|
15
|
+
const plan = meta.tier ? `the ${meta.tier} plan` : 'your plan';
|
|
16
|
+
const prefix = derived ? "This suggestion only covers the plan's visible history. " : '';
|
|
17
|
+
// Paused is a plan tier whose window is zero days: every run is hidden, not
|
|
18
|
+
// just older ones, and "keeps 0 days" would read oddly.
|
|
19
|
+
const reason = meta.tier === 'Paused' || meta.retentionDays === 0
|
|
20
|
+
? `${runs} hidden — this workspace is on the Paused plan, which keeps no run history.`
|
|
21
|
+
: `${count} older run${count === 1 ? '' : 's'} hidden — ${plan} keeps ${meta.retentionDays} day${meta.retentionDays === 1 ? '' : 's'} of run history.`;
|
|
22
|
+
return `${prefix}${reason}\n` + ` upgrade: ${pricing}\n` + ` billing: ${billing}`;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=history-retention.js.map
|