@testsprite/testsprite-cli 0.14.0 → 0.16.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 +27 -17
- package/dist/commands/agent.js +7 -2
- package/dist/commands/auth.js +7 -3
- package/dist/commands/ci.d.ts +66 -17
- package/dist/commands/ci.js +486 -122
- package/dist/commands/completion.js +2 -1
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.js +52 -10
- package/dist/commands/init.js +25 -5
- package/dist/commands/project-env.js +39 -17
- package/dist/commands/project-sign-in.js +9 -4
- package/dist/commands/project.js +43 -22
- package/dist/commands/schedule.js +24 -15
- package/dist/commands/test.d.ts +105 -36
- package/dist/commands/test.js +1494 -847
- package/dist/commands/testlist.js +13 -3
- package/dist/commands/tunnel.js +23 -25
- package/dist/commands/usage.js +1 -0
- package/dist/index.js +14 -7
- package/dist/lib/agent-targets.d.ts +8 -3
- package/dist/lib/agent-targets.js +15 -4
- package/dist/lib/ci-run.d.ts +11 -0
- package/dist/lib/ci-run.js +34 -0
- package/dist/lib/client-factory.d.ts +23 -0
- package/dist/lib/client-factory.js +7 -6
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.js +1 -1
- package/dist/lib/conflict-reason.d.ts +24 -3
- package/dist/lib/conflict-reason.js +33 -2
- package/dist/lib/credentials.d.ts +0 -1
- package/dist/lib/credentials.js +51 -14
- package/dist/lib/deprecate.d.ts +22 -0
- package/dist/lib/deprecate.js +26 -0
- package/dist/lib/dry-run/samples.js +56 -5
- package/dist/lib/environment-tunnel.d.ts +2 -1
- package/dist/lib/environment-tunnel.js +1 -4
- package/dist/lib/first-suite-hint.d.ts +55 -0
- package/dist/lib/first-suite-hint.js +101 -0
- package/dist/lib/gh-output.d.ts +62 -4
- package/dist/lib/gh-output.js +149 -7
- package/dist/lib/github-context.d.ts +21 -0
- package/dist/lib/github-context.js +153 -0
- package/dist/lib/http.d.ts +10 -1
- package/dist/lib/http.js +29 -3
- package/dist/lib/junit-report.d.ts +3 -0
- package/dist/lib/junit-report.js +8 -1
- package/dist/lib/output.d.ts +11 -1
- package/dist/lib/output.js +17 -2
- package/dist/lib/plans.types.d.ts +1 -1
- package/dist/lib/response-schemas.d.ts +5 -1
- package/dist/lib/response-schemas.js +57 -0
- package/dist/lib/runs.types.d.ts +122 -0
- package/dist/lib/telemetry.d.ts +26 -2
- package/dist/lib/telemetry.js +47 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/schemas/plan.schema.json +2 -2
- package/skills/testsprite-ci.skill.md +154 -0
- package/skills/testsprite-verify.codex.md +7 -7
- package/skills/testsprite-verify.skill.md +24 -21
package/dist/commands/test.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { recordTelemetryTunnelOpened } from '../lib/telemetry.js';
|
|
2
2
|
import { parseLoopbackTargetUrl } from '../lib/local-target.js';
|
|
3
|
-
import { resolveEnvironmentRunTarget, readEnvironmentPreflight, ENVIRONMENT_PREFLIGHT_TIMEOUT_MS, assertNoTunnelOptions,
|
|
3
|
+
import { resolveEnvironmentRunTarget, readEnvironmentPreflight, ENVIRONMENT_PREFLIGHT_TIMEOUT_MS, assertNoTunnelOptions, quoteEnvironmentName, groupEnvironmentTargets, emitEnvironmentDispatchPartial, tunnelScopeError, withEnvironmentTunnel, } from '../lib/environment-tunnel.js';
|
|
4
4
|
import { closeSync, createWriteStream, existsSync, fstatSync, openSync, readFileSync, readSync, readdirSync, statSync, } from 'node:fs';
|
|
5
5
|
import { rename, stat, unlink } from 'node:fs/promises';
|
|
6
6
|
import { basename, dirname, extname, isAbsolute, join, resolve } from 'node:path';
|
|
7
|
-
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
8
8
|
import { Command } from 'commander';
|
|
9
9
|
import { openInBrowser } from '../lib/browser.js';
|
|
10
10
|
import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, resolveRequestTimeoutMs, } from '../lib/client-factory.js';
|
|
@@ -12,20 +12,23 @@ import { assertContextIntegrity, buildMeta, pickCodeExtension, pickVideoExtensio
|
|
|
12
12
|
import { findSample, findSampleOrThrow, sampleJUnitReportXml } from '../lib/dry-run/samples.js';
|
|
13
13
|
import { assertJUnitReportOptions, buildJUnitReport, durationSecondsBetween, resolveBatchReportProjectId, skippedJUnitResultsFromSummary, writeJUnitReportFile, parseJUnitReportFormat, } from '../lib/junit-report.js';
|
|
14
14
|
import { ApiError, CLIError, InterruptError, RequestTimeoutError, TransportError, isAuthCode, localValidationError, } from '../lib/errors.js';
|
|
15
|
+
import { emptyProjectHint, emptyProjectNextStep } from '../lib/first-suite-hint.js';
|
|
15
16
|
import { globalShutdown } from '../lib/interrupt.js';
|
|
16
|
-
import { defaultSleep } from '../lib/poll-support.js';
|
|
17
|
+
import { defaultSleep, sleepUnlessInterrupted } from '../lib/poll-support.js';
|
|
17
18
|
import { assertIdempotencyKey, requireArrayLength, requireEnum, requireString, } from '../lib/validate.js';
|
|
18
19
|
import { isStandingRateLimit, REQUEST_TIMEOUT_DEFAULT_MS, REQUEST_TIMEOUT_MAX_MS, } from '../lib/http.js';
|
|
19
20
|
import { VERSION } from '../version.js';
|
|
21
|
+
import { emitDeprecationEntry, REMOVED_IN, TEST_FLAKY_DEPRECATION, TEST_RERUN_DEPRECATION, } from '../lib/deprecate.js';
|
|
20
22
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
21
23
|
import { fetchSinglePage, paginate, validatePaginationFlags, } from '../lib/pagination.js';
|
|
22
24
|
import { isTerminalStatus, pollRunUntilTerminal, TimeoutError } from '../lib/poll.js';
|
|
23
|
-
import { batchOutcomeCounts, recordBatchOutcome, recordTelemetryExtras, } from '../lib/telemetry.js';
|
|
25
|
+
import { batchOutcomeCounts, ciRefusalOutcome, recordBatchOutcome, recordTelemetryExtras, } from '../lib/telemetry.js';
|
|
24
26
|
import { PlanGenerationTimeoutError, runGenerationLadder } from '../lib/plan-poll.js';
|
|
25
27
|
import { resolveWaitFailure, waitMemberError } from '../lib/wait-exit.js';
|
|
28
|
+
import { resolveCiRunFailure } from '../lib/ci-run.js';
|
|
26
29
|
import { RUN_SOURCES } from '../lib/runs.types.js';
|
|
27
30
|
import { classifyBillingRefusal } from '../lib/billing-refusal.js';
|
|
28
|
-
import { allConflictsInFlight, billingConflictLink, insufficientCreditsConflictError, isAllCreditsRefusal, isPausedRefusal, pausedConflictError, summarizeConflicts, } from '../lib/conflict-reason.js';
|
|
31
|
+
import { allConflictsInFlight, billingConflictLink, conflictNextAction, insufficientCreditsConflictError, isAllCreditsRefusal, isPausedRefusal, isProducerBlock, pausedConflictError, summarizeConflicts, } from '../lib/conflict-reason.js';
|
|
29
32
|
import { isProxyAgentActive } from '../lib/proxy.js';
|
|
30
33
|
import { assertNotLocal } from '../lib/target-url.js';
|
|
31
34
|
import { assertTargetUrlReachable } from '../lib/target-url-preflight.js';
|
|
@@ -38,7 +41,7 @@ import { createTicker } from '../lib/ticker.js';
|
|
|
38
41
|
import { RateThrottle } from '../lib/rate-throttle.js';
|
|
39
42
|
import { resolvePortalBase, resolvePortalUrl } from '../lib/facade.js';
|
|
40
43
|
import { emitTargetUrlMismatchAdvisory } from '../lib/v3-advisory.js';
|
|
41
|
-
import { emitCiArtifacts, isNonDispatchedStatus, summarizeAcceptedPayload, summarizeSingleRun, } from '../lib/gh-output.js';
|
|
44
|
+
import { emitCiArtifacts, isNonDispatchedStatus, emitCiStepOutputs, reconcileExecutionReportMarkdown, summarizeAcceptedPayload, summarizeSingleRun, emitExecutionReportOutputs, } from '../lib/gh-output.js';
|
|
42
45
|
import { loadConfig, resolveProfileName } from '../lib/config.js';
|
|
43
46
|
import { historyRetentionNote } from '../lib/history-retention.js';
|
|
44
47
|
import { flakyExitCode, renderFlakyText, summarizeFlaky, } from '../lib/flaky.js';
|
|
@@ -368,7 +371,7 @@ export async function runList(opts, deps = {}) {
|
|
|
368
371
|
// sending. Friendlier error than waiting for the server's 400 with
|
|
369
372
|
// a list of accepted tokens — and lets the user fix typos without
|
|
370
373
|
// a round trip.
|
|
371
|
-
|
|
374
|
+
validateListStatusFilter(opts.status);
|
|
372
375
|
const out = makeOutput(opts.output, deps);
|
|
373
376
|
if (opts.output === 'text') {
|
|
374
377
|
resolveTextColumns(opts.columns, TEST_LIST_COLUMNS);
|
|
@@ -383,7 +386,7 @@ export async function runList(opts, deps = {}) {
|
|
|
383
386
|
projectId,
|
|
384
387
|
type: opts.type,
|
|
385
388
|
createdFrom: opts.createdFrom,
|
|
386
|
-
status: opts.status,
|
|
389
|
+
status: opts.status === undefined ? undefined : expandNotRun(opts.status),
|
|
387
390
|
...(environment !== undefined ? { environment } : {}),
|
|
388
391
|
};
|
|
389
392
|
let page;
|
|
@@ -400,53 +403,68 @@ export async function runList(opts, deps = {}) {
|
|
|
400
403
|
catch (err) {
|
|
401
404
|
if (err instanceof InterruptError)
|
|
402
405
|
throw err;
|
|
403
|
-
|
|
404
|
-
err.code === 'VALIDATION_ERROR' &&
|
|
405
|
-
err.getDetail('field') === 'environment' &&
|
|
406
|
-
Array.isArray(err.getDetail('available')) &&
|
|
407
|
-
environment !== undefined) {
|
|
408
|
-
const available = err.getDetail('available').filter((name) => typeof name === 'string');
|
|
409
|
-
if (available.length > 0 && !err.nextAction.includes(available.join(', '))) {
|
|
410
|
-
const hint = `Flag \`--env\` is invalid: unknown environment '${environment}'; use one of: ${available.join(', ')}.`;
|
|
411
|
-
throw new ApiError({
|
|
412
|
-
code: err.code,
|
|
413
|
-
message: err.message,
|
|
414
|
-
nextAction: err.nextAction ? `${hint} ${err.nextAction}` : hint,
|
|
415
|
-
requestId: err.requestId,
|
|
416
|
-
details: err.details,
|
|
417
|
-
}, err.httpStatus, err.retryAfterMs);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
throw err;
|
|
406
|
+
throw withUnknownEnvironmentHint(err, environment);
|
|
421
407
|
}
|
|
422
408
|
if (environment !== undefined) {
|
|
423
409
|
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
424
410
|
if (opts.output === 'text' && opts.noHeader) {
|
|
425
411
|
stderr(`Frontend test status requested for environment '${environment}'.`);
|
|
426
412
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
throw ApiError.fromEnvelope({
|
|
432
|
-
error: {
|
|
433
|
-
code: 'UNSUPPORTED',
|
|
434
|
-
message: 'This server does not support `test list --env` yet.',
|
|
435
|
-
nextAction: 'Run the command without --env, or retry after the server is upgraded.',
|
|
436
|
-
requestId: 'local',
|
|
437
|
-
details: {},
|
|
438
|
-
},
|
|
439
|
-
});
|
|
440
|
-
}
|
|
413
|
+
assertEnvironmentStatusesPresent(page.items, {
|
|
414
|
+
message: 'This server does not support `test list --env` yet.',
|
|
415
|
+
nextAction: 'Run the command without --env, or retry after the server is upgraded.',
|
|
416
|
+
});
|
|
441
417
|
}
|
|
442
418
|
out.print(page, data => renderTestListText(data, {
|
|
443
419
|
columns: opts.columns,
|
|
444
420
|
noHeader: opts.noHeader,
|
|
445
421
|
environment,
|
|
446
422
|
}));
|
|
423
|
+
// An EMPTY project — nothing narrowed the page, no further page —
|
|
424
|
+
// is where a new user without a coding agent stalls. One stderr hint, text
|
|
425
|
+
// mode only, so stdout stays exactly "No tests." for pipes.
|
|
426
|
+
if (opts.output !== 'json' &&
|
|
427
|
+
page.items.length === 0 &&
|
|
428
|
+
!page.nextToken &&
|
|
429
|
+
opts.startingToken === undefined &&
|
|
430
|
+
opts.type === undefined &&
|
|
431
|
+
opts.createdFrom === undefined &&
|
|
432
|
+
opts.status === undefined) {
|
|
433
|
+
const stderrFn = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
434
|
+
stderrFn(emptyProjectHint(projectId));
|
|
435
|
+
}
|
|
447
436
|
return page;
|
|
448
437
|
}
|
|
449
438
|
export const CLI_CREATE_PRIORITIES = ['p0', 'p1', 'p2', 'p3'];
|
|
439
|
+
/** Priority spellings accepted as input; reads return High/Medium/Low. */
|
|
440
|
+
export const CLI_PRIORITY_INPUTS = [...CLI_CREATE_PRIORITIES, 'high', 'medium', 'low'];
|
|
441
|
+
const PRIORITY_WIRE = {
|
|
442
|
+
p0: 'p0',
|
|
443
|
+
high: 'p0',
|
|
444
|
+
p1: 'p1',
|
|
445
|
+
medium: 'p1',
|
|
446
|
+
p2: 'p2',
|
|
447
|
+
low: 'p2',
|
|
448
|
+
p3: 'p2',
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* Normalise a priority input (p0-p3 or high/medium/low, any case) to the
|
|
452
|
+
* p0/p1/p2 wire value every backend accepts; p3 folds into p2 (Low).
|
|
453
|
+
* Returns undefined for anything else.
|
|
454
|
+
*/
|
|
455
|
+
export function normalizePriority(raw) {
|
|
456
|
+
if (typeof raw !== 'string')
|
|
457
|
+
return undefined;
|
|
458
|
+
const key = raw.trim().toLowerCase();
|
|
459
|
+
// Own-property lookup: inherited names such as `constructor` must not pass as priorities.
|
|
460
|
+
return Object.hasOwn(PRIORITY_WIRE, key) ? PRIORITY_WIRE[key] : undefined;
|
|
461
|
+
}
|
|
462
|
+
/** Throws the standard enum error unless `raw` is an accepted priority input. */
|
|
463
|
+
function assertPriorityInput(field, raw, kind = 'field') {
|
|
464
|
+
if (normalizePriority(raw) === undefined) {
|
|
465
|
+
throw localValidationError(field, `must be one of: ${CLI_PRIORITY_INPUTS.join(', ')} (case-insensitive)`, [...CLI_PRIORITY_INPUTS], kind);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
450
468
|
/**
|
|
451
469
|
* 350 KB inline-code cap. Mirrors `MAX_INLINE_CODE_BYTES` in the backend
|
|
452
470
|
* (`CliTestsController`), which is sized to fit a full test row inside
|
|
@@ -647,11 +665,8 @@ export async function runCreate(opts, deps = {}) {
|
|
|
647
665
|
'backend',
|
|
648
666
|
]);
|
|
649
667
|
}
|
|
650
|
-
if (opts.priority !== undefined
|
|
651
|
-
|
|
652
|
-
...CLI_CREATE_PRIORITIES,
|
|
653
|
-
]);
|
|
654
|
-
}
|
|
668
|
+
if (opts.priority !== undefined)
|
|
669
|
+
assertPriorityInput('priority', opts.priority);
|
|
655
670
|
// M4 piece-2: --produces/--needs/--category are backend-only. FE plans have
|
|
656
671
|
// no wave model; fail-fast client-side to match the backend's 400 reject and
|
|
657
672
|
// save a round-trip.
|
|
@@ -695,7 +710,7 @@ export async function runCreate(opts, deps = {}) {
|
|
|
695
710
|
type: opts.type,
|
|
696
711
|
name: opts.name,
|
|
697
712
|
description: opts.description,
|
|
698
|
-
priority: opts.priority,
|
|
713
|
+
priority: normalizePriority(opts.priority),
|
|
699
714
|
code,
|
|
700
715
|
};
|
|
701
716
|
if (opts.stepTimeoutMs !== undefined) {
|
|
@@ -1004,10 +1019,9 @@ const MAX_PLAN_STEPS_BODY_BYTES = 256 * 1024;
|
|
|
1004
1019
|
* trip and matches the piece-6 spec's "server-side routing" decision.
|
|
1005
1020
|
*
|
|
1006
1021
|
* Concurrency: FE has no `codeVersion`, so updates are last-writer-
|
|
1007
|
-
* wins
|
|
1008
|
-
* `If-Match-Step-Count`; the server rejects with 412 if the
|
|
1009
|
-
*
|
|
1010
|
-
* detect concurrent edits without a separate read.
|
|
1022
|
+
* wins unless `--expected-step-count <N>` is passed, which sets
|
|
1023
|
+
* `If-Match-Step-Count`; the server rejects with 412 if the array length
|
|
1024
|
+
* differs.
|
|
1011
1025
|
*
|
|
1012
1026
|
* Idempotency: `cli-plan-put-<uuid>` is the default key, surfaced to
|
|
1013
1027
|
* stderr so a transport retry can pin it.
|
|
@@ -1050,10 +1064,25 @@ export async function runPlanPut(opts, deps = {}) {
|
|
|
1050
1064
|
},
|
|
1051
1065
|
}, 412);
|
|
1052
1066
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1067
|
+
let response;
|
|
1068
|
+
try {
|
|
1069
|
+
response = await client.put(`/tests/${encodeURIComponent(opts.testId)}/plan-steps`, {
|
|
1070
|
+
body: opts.force === true ? { planSteps, force: true } : { planSteps },
|
|
1071
|
+
headers,
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
catch (err) {
|
|
1075
|
+
if (err instanceof ApiError && err.getDetail('reason') === 'structured_loss') {
|
|
1076
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
1077
|
+
const losing = err.getDetail('losing');
|
|
1078
|
+
const indexes = err.getDetail('stepIndexes');
|
|
1079
|
+
const where = Array.isArray(indexes)
|
|
1080
|
+
? ` (step ${indexes.map(i => (typeof i === 'number' ? i + 1 : String(i))).join(', ')})`
|
|
1081
|
+
: '';
|
|
1082
|
+
stderr(`${typeof losing === 'number' ? losing : 'Some'} step(s) would lose their structured fields${where}.`);
|
|
1083
|
+
}
|
|
1084
|
+
throw err;
|
|
1085
|
+
}
|
|
1057
1086
|
out.print(response, data => renderPlanPutText(data));
|
|
1058
1087
|
return response;
|
|
1059
1088
|
}
|
|
@@ -1356,11 +1385,8 @@ export async function runUpdate(opts, deps = {}) {
|
|
|
1356
1385
|
if (opts.description !== undefined && opts.description.length > 2000) {
|
|
1357
1386
|
throw localValidationError('description', 'must be at most 2000 characters');
|
|
1358
1387
|
}
|
|
1359
|
-
if (opts.priority !== undefined
|
|
1360
|
-
|
|
1361
|
-
...CLI_CREATE_PRIORITIES,
|
|
1362
|
-
]);
|
|
1363
|
-
}
|
|
1388
|
+
if (opts.priority !== undefined)
|
|
1389
|
+
assertPriorityInput('priority', opts.priority);
|
|
1364
1390
|
if (opts.stepTimeoutMs !== undefined && opts.clearStepTimeout === true) {
|
|
1365
1391
|
throw localValidationError('step-timeout', '--step-timeout and --clear-step-timeout are mutually exclusive');
|
|
1366
1392
|
}
|
|
@@ -1410,7 +1436,7 @@ export async function runUpdate(opts, deps = {}) {
|
|
|
1410
1436
|
if (hasDescription)
|
|
1411
1437
|
body.description = opts.description;
|
|
1412
1438
|
if (hasPriority)
|
|
1413
|
-
body.priority = opts.priority;
|
|
1439
|
+
body.priority = normalizePriority(opts.priority);
|
|
1414
1440
|
if (hasProduces)
|
|
1415
1441
|
body.produces = opts.produces;
|
|
1416
1442
|
if (hasNeeds)
|
|
@@ -1532,9 +1558,11 @@ export async function runDeleteBatch(opts, deps = {}) {
|
|
|
1532
1558
|
throw localValidationError('status', '--status only applies with --all (it filters which project tests get deleted). ' +
|
|
1533
1559
|
'Remove --status, or add --all --project <id>.');
|
|
1534
1560
|
}
|
|
1535
|
-
// Validate --status filter.
|
|
1561
|
+
// Validate --status filter. An empty value is refused: read as "no filter",
|
|
1562
|
+
// `--status ''` would delete every test in the project.
|
|
1536
1563
|
if (opts.statusFilter !== undefined) {
|
|
1537
|
-
|
|
1564
|
+
assertStatusSelectorNotEmpty(opts.statusFilter, RUN_STATUS_VALUES);
|
|
1565
|
+
validateListStatusFilter(opts.statusFilter);
|
|
1538
1566
|
}
|
|
1539
1567
|
const client = makeClient(opts, deps);
|
|
1540
1568
|
let testIds = opts.testIds;
|
|
@@ -1555,8 +1583,8 @@ export async function runDeleteBatch(opts, deps = {}) {
|
|
|
1555
1583
|
}), {});
|
|
1556
1584
|
let allTests = allPage.items;
|
|
1557
1585
|
// --status filter.
|
|
1558
|
-
if (opts.statusFilter !== undefined
|
|
1559
|
-
const allowed = new Set(opts.statusFilter
|
|
1586
|
+
if (opts.statusFilter !== undefined) {
|
|
1587
|
+
const allowed = new Set(expandNotRun(opts.statusFilter)
|
|
1560
1588
|
.split(',')
|
|
1561
1589
|
.map(s => s.trim())
|
|
1562
1590
|
.filter(s => s.length > 0));
|
|
@@ -1717,10 +1745,8 @@ export const PLAN_TEMPLATE_TEXT = JSON.stringify(PLAN_TEMPLATE_WITH_SCHEMA, null
|
|
|
1717
1745
|
/** `test create --help` after-text. Wraps `PLAN_TEMPLATE_TEXT` unmodified. */
|
|
1718
1746
|
const PLAN_TEMPLATE_HELP_TEXT = '\nPlan file format (--plan-from <file>) — minimal valid example:\n\n' +
|
|
1719
1747
|
`${PLAN_TEMPLATE_TEXT}\n\n` +
|
|
1720
|
-
'
|
|
1721
|
-
'
|
|
1722
|
-
'Multiple tests: test create-batch --plans <file.jsonl> | --plan-from-dir <dir>\n' +
|
|
1723
|
-
'Full field reference: DOCUMENTATION.md -> "Plan file format"\n';
|
|
1748
|
+
'Validate offline: testsprite test create --plan-from <file> --dry-run\n' +
|
|
1749
|
+
'Many tests: testsprite test create-batch --plans <file.jsonl>\n';
|
|
1724
1750
|
/**
|
|
1725
1751
|
* 200-step + 256 KB caps on a single plan body. The CLI
|
|
1726
1752
|
* enforces both client-side as a pre-flight guard so an obvious
|
|
@@ -1741,10 +1767,119 @@ const MAX_BATCH_BODY_BYTES = 5 * 1024 * 1024;
|
|
|
1741
1767
|
* than this, the CLI splits into chunks and aggregates the results.
|
|
1742
1768
|
*/
|
|
1743
1769
|
const MAX_BATCH_RERUN_IDS = 50;
|
|
1770
|
+
/**
|
|
1771
|
+
* Maximum testIds per `POST /tests/batch/run` request. A larger selection is
|
|
1772
|
+
* sent as several sequential requests, one project at a time (the endpoint
|
|
1773
|
+
* refuses ids from different projects in one request).
|
|
1774
|
+
*/
|
|
1775
|
+
const MAX_BATCH_RUN_IDS = 50;
|
|
1776
|
+
/**
|
|
1777
|
+
* Group `ids` by project in first-seen order and cut each group into windows
|
|
1778
|
+
* of `MAX_BATCH_RUN_IDS`. `chunk: false` keeps one request per project, for a
|
|
1779
|
+
* caller whose contract is a single request (`ci run`).
|
|
1780
|
+
*/
|
|
1781
|
+
function planBatchRunUnits(ids, projectOf, chunk) {
|
|
1782
|
+
const byProject = new Map();
|
|
1783
|
+
for (const id of ids) {
|
|
1784
|
+
const project = projectOf(id);
|
|
1785
|
+
const group = byProject.get(project);
|
|
1786
|
+
if (group)
|
|
1787
|
+
group.push(id);
|
|
1788
|
+
else
|
|
1789
|
+
byProject.set(project, [id]);
|
|
1790
|
+
}
|
|
1791
|
+
const units = [];
|
|
1792
|
+
for (const [projectId, group] of byProject) {
|
|
1793
|
+
if (!chunk) {
|
|
1794
|
+
units.push({ projectId, testIds: group });
|
|
1795
|
+
continue;
|
|
1796
|
+
}
|
|
1797
|
+
for (let i = 0; i < group.length; i += MAX_BATCH_RUN_IDS) {
|
|
1798
|
+
units.push({ projectId, testIds: group.slice(i, i + MAX_BATCH_RUN_IDS) });
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
return units;
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* Append `suffix` to an idempotency key within 256 chars. A base that does not
|
|
1805
|
+
* fit is cut and tagged with a digest of the whole key, so two long keys that
|
|
1806
|
+
* differ only in their tail still get different request keys.
|
|
1807
|
+
*/
|
|
1808
|
+
function suffixedIdempotencyKey(base, suffix) {
|
|
1809
|
+
const room = 256 - suffix.length;
|
|
1810
|
+
if (base.length <= room)
|
|
1811
|
+
return `${base}${suffix}`;
|
|
1812
|
+
const digest = createHash('sha256').update(base).digest('hex').slice(0, 16);
|
|
1813
|
+
return `${base.slice(0, room - digest.length - 1)}~${digest}${suffix}`;
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Fold the responses of a request sequence into the one response the rest of
|
|
1817
|
+
* the command reads. A single response is returned untouched.
|
|
1818
|
+
*/
|
|
1819
|
+
function mergeBatchRunResponses(responses, suppressDashboardUrl) {
|
|
1820
|
+
const first = responses[0];
|
|
1821
|
+
if (responses.length === 1 && !suppressDashboardUrl)
|
|
1822
|
+
return first;
|
|
1823
|
+
const integrations = responses.flatMap(r => (r.integration ? [r.integration] : []));
|
|
1824
|
+
return {
|
|
1825
|
+
...first,
|
|
1826
|
+
accepted: responses.flatMap(r => r.accepted),
|
|
1827
|
+
conflicts: responses.flatMap(r => r.conflicts),
|
|
1828
|
+
deferred: responses.flatMap(r => r.deferred),
|
|
1829
|
+
skippedFrontend: responses.flatMap(r => r.skippedFrontend),
|
|
1830
|
+
skippedIntegration: responses.flatMap(r => r.skippedIntegration),
|
|
1831
|
+
...(integrations.length > 0
|
|
1832
|
+
? {
|
|
1833
|
+
integration: {
|
|
1834
|
+
existing: integrations.reduce((n, i) => n + i.existing, 0),
|
|
1835
|
+
runsAfterWave: integrations.some(i => i.runsAfterWave),
|
|
1836
|
+
mayGenerate: integrations.some(i => i.mayGenerate),
|
|
1837
|
+
},
|
|
1838
|
+
}
|
|
1839
|
+
: {}),
|
|
1840
|
+
// A project-level link names one project (and one execution); once the
|
|
1841
|
+
// batch spans several requests or projects no single page is right.
|
|
1842
|
+
...(suppressDashboardUrl || (responses.length > 1 && 'dashboardUrl' in first)
|
|
1843
|
+
? { dashboardUrl: null }
|
|
1844
|
+
: {}),
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Resolve the owning project of every id with an authoritative `GET /tests/<id>`
|
|
1849
|
+
* (a handful in flight at a time). An unknown id fails the whole call with its
|
|
1850
|
+
* own NOT_FOUND before anything is dispatched, so an id in a later chunk cannot
|
|
1851
|
+
* be discovered after an earlier chunk already ran.
|
|
1852
|
+
*/
|
|
1853
|
+
async function resolveTestProjects(client, ids, known) {
|
|
1854
|
+
const resolved = new Map();
|
|
1855
|
+
const pending = [];
|
|
1856
|
+
for (const id of ids) {
|
|
1857
|
+
const projectId = known?.get(id)?.projectId;
|
|
1858
|
+
if (projectId)
|
|
1859
|
+
resolved.set(id, projectId);
|
|
1860
|
+
else
|
|
1861
|
+
pending.push(id);
|
|
1862
|
+
}
|
|
1863
|
+
let next = 0;
|
|
1864
|
+
const worker = async () => {
|
|
1865
|
+
for (;;) {
|
|
1866
|
+
const id = pending[next++];
|
|
1867
|
+
if (id === undefined)
|
|
1868
|
+
return;
|
|
1869
|
+
const test = await client.get(`/tests/${encodeURIComponent(id)}`);
|
|
1870
|
+
if (!test.projectId) {
|
|
1871
|
+
throw localValidationError('test-id', `could not determine the project of test ${id}`);
|
|
1872
|
+
}
|
|
1873
|
+
resolved.set(id, test.projectId);
|
|
1874
|
+
}
|
|
1875
|
+
};
|
|
1876
|
+
await Promise.all(Array.from({ length: Math.min(8, pending.length) }, worker));
|
|
1877
|
+
return resolved;
|
|
1878
|
+
}
|
|
1744
1879
|
/**
|
|
1745
1880
|
* Dedupe `RerunAdvisory[]` by `feature`+`message`. Used to aggregate
|
|
1746
1881
|
* `advisories` across chunked batch-rerun dispatch requests (initial dispatch
|
|
1747
|
-
*
|
|
1882
|
+
* dispatch) into a single list, and to collapse repeated
|
|
1748
1883
|
* per-attempt advisories in `test flaky` into a single summary line.
|
|
1749
1884
|
*/
|
|
1750
1885
|
function dedupeRerunAdvisories(entries) {
|
|
@@ -1876,22 +2011,6 @@ function mergeBatchRerunClosureByProject(entries) {
|
|
|
1876
2011
|
export const DEFAULT_BATCH_RUN_CONCURRENCY = 50;
|
|
1877
2012
|
/** Hard upper bound for --max-concurrency. Values above this are rejected with exit 5 (VALIDATION_ERROR). */
|
|
1878
2013
|
export const MAX_BATCH_CONCURRENCY = 100;
|
|
1879
|
-
/**
|
|
1880
|
-
* The server's DEFAULT in-flight run cap. Runs from every source count
|
|
1881
|
-
* toward it (CLI, portal, schedules, CI), but only CLI run triggers are
|
|
1882
|
-
* refused on it; a portal or schedule run over the cap is not. Exceeding it
|
|
1883
|
-
* answers RATE_LIMITED with `details.reason: "inflight_cap"`, whose details
|
|
1884
|
-
* carry the account's real `cap` and `current`.
|
|
1885
|
-
*
|
|
1886
|
-
* Quoted in help text only — the server owns the real number and rejects on
|
|
1887
|
-
* its own value, so this is documentation, never a client-side gate.
|
|
1888
|
-
*
|
|
1889
|
-
* Distinct from `--max-concurrency`, whose meaning differs per command: on
|
|
1890
|
-
* `create --run` it bounds in-flight triggers, and with `--wait` a slot is
|
|
1891
|
-
* held until that run finishes, so lowering it there does bound how many runs
|
|
1892
|
-
* are in flight. On `run --all` it bounds the `--wait` poll fan-out only.
|
|
1893
|
-
*/
|
|
1894
|
-
export const SERVER_INFLIGHT_RUN_CAP = 50;
|
|
1895
2014
|
/** Client-side run-trigger throttle: 50 triggers per 60-second rolling window per key (sits just under the server's 60/min/key cap). */
|
|
1896
2015
|
export const BATCH_RUN_RATE_LIMIT = 50;
|
|
1897
2016
|
/** Rolling window duration (ms) for the client-side trigger rate throttle. */
|
|
@@ -1953,15 +2072,6 @@ export function resolveRateLimitRetryMs(err) {
|
|
|
1953
2072
|
const retryAfterSec = err.getDetail('retryAfterSeconds', (v) => typeof v === 'number' && v > 0);
|
|
1954
2073
|
return Math.min((retryAfterSec ?? 60) * 1000, 120_000);
|
|
1955
2074
|
}
|
|
1956
|
-
/**
|
|
1957
|
-
* D3: max automatic retry attempts for deferred tests under `--wait`.
|
|
1958
|
-
* Each attempt is preceded by a Retry-After-aware sleep (server value if
|
|
1959
|
-
* present, else 61s default), clamped to the remaining `--timeout` budget.
|
|
1960
|
-
* Only active under `--wait`; the non-wait path is unchanged.
|
|
1961
|
-
*/
|
|
1962
|
-
export const MAX_DEFERRED_RETRIES = 3;
|
|
1963
|
-
/** D3: default deferred-retry sleep when no Retry-After is available (ms). */
|
|
1964
|
-
export const DEFERRED_RETRY_DEFAULT_SLEEP_MS = 61_000;
|
|
1965
2075
|
/**
|
|
1966
2076
|
* Returns `true` when a `RATE_LIMITED` error is the **transient per-minute**
|
|
1967
2077
|
* rate limit from `RunRateLimiterGuard` — the one worth retrying.
|
|
@@ -2134,7 +2244,7 @@ export async function runCreateFromPlan(opts, deps = {}) {
|
|
|
2134
2244
|
type: plan.type,
|
|
2135
2245
|
name: plan.name,
|
|
2136
2246
|
description: plan.description,
|
|
2137
|
-
priority: plan.priority,
|
|
2247
|
+
priority: normalizePriority(plan.priority),
|
|
2138
2248
|
planSteps: plan.planSteps,
|
|
2139
2249
|
};
|
|
2140
2250
|
// Pre-charge reachability preflight — before the create POST
|
|
@@ -2349,7 +2459,7 @@ function assertPlanShape(parsed, context = {}) {
|
|
|
2349
2459
|
throw localValidationError(`${prefix}description`, 'must be a string when present', undefined, 'field');
|
|
2350
2460
|
}
|
|
2351
2461
|
if (obj.priority !== undefined) {
|
|
2352
|
-
|
|
2462
|
+
assertPriorityInput(`${prefix}priority`, obj.priority);
|
|
2353
2463
|
}
|
|
2354
2464
|
// `planSteps` missing is the single most common agent
|
|
2355
2465
|
// hallucination: LLMs (Copilot included) reliably nest steps under
|
|
@@ -2413,7 +2523,7 @@ function collectPlanIssues(parsed, context = {}) {
|
|
|
2413
2523
|
issues.push({ field: `${prefix}description`, reason: 'must be a string when present' });
|
|
2414
2524
|
}
|
|
2415
2525
|
if (obj.priority !== undefined) {
|
|
2416
|
-
check(() =>
|
|
2526
|
+
check(() => assertPriorityInput(`${prefix}priority`, obj.priority));
|
|
2417
2527
|
}
|
|
2418
2528
|
check(() => requireArrayLength(`${prefix}planSteps`, obj.planSteps, {
|
|
2419
2529
|
min: 1,
|
|
@@ -2522,7 +2632,9 @@ export async function runCreateBatch(opts, deps = {}) {
|
|
|
2522
2632
|
const stderrFn = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
2523
2633
|
stderrFn(`idempotency-key: ${idempotencyKey}`);
|
|
2524
2634
|
}
|
|
2525
|
-
const body = {
|
|
2635
|
+
const body = {
|
|
2636
|
+
tests: specs.map(spec => spec.priority === undefined ? spec : { ...spec, priority: normalizePriority(spec.priority) }),
|
|
2637
|
+
};
|
|
2526
2638
|
const bodyBytes = Buffer.byteLength(JSON.stringify(body), 'utf8');
|
|
2527
2639
|
if (bodyBytes > MAX_BATCH_BODY_BYTES) {
|
|
2528
2640
|
throw ApiError.fromEnvelope({
|
|
@@ -5170,7 +5282,7 @@ function withRunDashboardUrl(run, apiUrl) {
|
|
|
5170
5282
|
* atomic — no per-step breakdown exists; showing `0/0 (passed=0, failed=0)`
|
|
5171
5283
|
* reads like a no-op rather than a passing/failing atomic result).
|
|
5172
5284
|
*/
|
|
5173
|
-
function renderRunResponseText(run, { isBackend = false } = {}) {
|
|
5285
|
+
export function renderRunResponseText(run, { isBackend = false } = {}) {
|
|
5174
5286
|
// P2-9: omit null fields (codeVersion/targetUrl) to match renderResultText
|
|
5175
5287
|
// convention — literal "null" in text output confuses human operators.
|
|
5176
5288
|
const lines = [
|
|
@@ -5219,6 +5331,9 @@ function renderRunResponseText(run, { isBackend = false } = {}) {
|
|
|
5219
5331
|
// is an absent breakdown, not a breakdown of zero steps, so say that.
|
|
5220
5332
|
lines.push(`steps n/a (no per-step breakdown reported)`);
|
|
5221
5333
|
}
|
|
5334
|
+
if (run.replay?.path === 'refused') {
|
|
5335
|
+
lines.push(`replay refused${run.replay.reason ? ` (${run.replay.reason})` : ''}`);
|
|
5336
|
+
}
|
|
5222
5337
|
// Closing pointer: where to inspect this run in the Portal (video, steps,
|
|
5223
5338
|
// screenshots). Present only when withRunDashboardUrl could resolve it.
|
|
5224
5339
|
if (run.dashboardUrl)
|
|
@@ -5355,13 +5470,10 @@ function parseStepTimeoutFlag(raw, flagName) {
|
|
|
5355
5470
|
function warnIfOptOutIgnored(requested, echoed, stderrFn, label,
|
|
5356
5471
|
/**
|
|
5357
5472
|
* States already reported by an earlier dispatch in the same invocation.
|
|
5358
|
-
* `test run --all`
|
|
5359
|
-
*
|
|
5360
|
-
*
|
|
5361
|
-
*
|
|
5362
|
-
* rollout, which is why this dedupes on the OUTCOME rather than firing once:
|
|
5363
|
-
* a retry whose echo disagrees with the first attempt's is new information and
|
|
5364
|
-
* still warns.
|
|
5473
|
+
* `test run --all` dispatches one request per project and window of ids, and
|
|
5474
|
+
* during a rollout they can land on differently-configured instances, which is
|
|
5475
|
+
* why this dedupes on the OUTCOME rather than firing once: a request whose
|
|
5476
|
+
* echo disagrees with an earlier one is new information and still warns.
|
|
5365
5477
|
*/
|
|
5366
5478
|
reported) {
|
|
5367
5479
|
if (requested !== false)
|
|
@@ -5394,6 +5506,56 @@ function isSameLoopbackPort(url, port) {
|
|
|
5394
5506
|
return false;
|
|
5395
5507
|
}
|
|
5396
5508
|
}
|
|
5509
|
+
/**
|
|
5510
|
+
* The environment half of the 409 auto-resume gate, shared by the single run
|
|
5511
|
+
* and the `--all` batch: may the in-flight run stand in for the run this
|
|
5512
|
+
* invocation asked for? Resolves to the `--env` flag naming the verified
|
|
5513
|
+
* environment for a later retry (undefined when the run recorded none), or
|
|
5514
|
+
* throws `incompatibleRun(reason)`.
|
|
5515
|
+
*
|
|
5516
|
+
* `undefined` (no key at all) is a V2 run or a backend that predates
|
|
5517
|
+
* environments on run reads; `null` is a V3 row that explicitly names no
|
|
5518
|
+
* environment, OR one whose environment lookup failed and was swallowed
|
|
5519
|
+
* server-side. Only the former may attach unverified — treating `null` the
|
|
5520
|
+
* same way would let a failed lookup slip through the gate it exists to
|
|
5521
|
+
* enforce.
|
|
5522
|
+
*/
|
|
5523
|
+
async function verifyInFlightRunEnvironment(inFlightRun, environment, listEnvironments, incompatibleRun) {
|
|
5524
|
+
const inFlightEnvironment = inFlightRun.environment;
|
|
5525
|
+
if (inFlightEnvironment === undefined) {
|
|
5526
|
+
if (environment !== undefined) {
|
|
5527
|
+
// --env was requested but this in-flight run has nothing recorded to
|
|
5528
|
+
// verify it against.
|
|
5529
|
+
throw incompatibleRun('its environment could not be verified');
|
|
5530
|
+
}
|
|
5531
|
+
// Restored 0.12.0 path: no environment recorded, none requested — attach.
|
|
5532
|
+
return undefined;
|
|
5533
|
+
}
|
|
5534
|
+
if (inFlightEnvironment === null ||
|
|
5535
|
+
typeof inFlightEnvironment.id !== 'string' ||
|
|
5536
|
+
inFlightEnvironment.id.length === 0) {
|
|
5537
|
+
throw incompatibleRun('its environment could not be verified');
|
|
5538
|
+
}
|
|
5539
|
+
let currentEnvironment;
|
|
5540
|
+
try {
|
|
5541
|
+
const listing = await listEnvironments(inFlightRun.projectId);
|
|
5542
|
+
currentEnvironment = listing.environments.find(row => environment === undefined ? row.isDefault : row.name === environment);
|
|
5543
|
+
}
|
|
5544
|
+
catch (listErr) {
|
|
5545
|
+
if (listErr instanceof InterruptError)
|
|
5546
|
+
throw listErr;
|
|
5547
|
+
throw incompatibleRun('its environment could not be verified');
|
|
5548
|
+
}
|
|
5549
|
+
if (typeof currentEnvironment?.id !== 'string' || currentEnvironment.id.length === 0) {
|
|
5550
|
+
// The listing succeeded but named nothing we can compare against — that
|
|
5551
|
+
// is unverified, not a proven mismatch.
|
|
5552
|
+
throw incompatibleRun('its environment could not be verified');
|
|
5553
|
+
}
|
|
5554
|
+
if (currentEnvironment.id !== inFlightEnvironment.id) {
|
|
5555
|
+
throw incompatibleRun('its environment does not match the requested environment');
|
|
5556
|
+
}
|
|
5557
|
+
return `--env ${currentEnvironment.name}`;
|
|
5558
|
+
}
|
|
5397
5559
|
export async function runTestRun(opts, deps = {}) {
|
|
5398
5560
|
assertIdempotencyKey(opts.idempotencyKey);
|
|
5399
5561
|
const environment = normalizeEnvironmentName(opts.environment);
|
|
@@ -5481,6 +5643,7 @@ export async function runTestRun(opts, deps = {}) {
|
|
|
5481
5643
|
// handle, the same reason `dashboardUrl` is suppressed under
|
|
5482
5644
|
// --dry-run rather than pointing at the canned sample id.
|
|
5483
5645
|
...(isTunnelRun ? { tunnelClientId: '<minted at run time>' } : {}),
|
|
5646
|
+
...(opts.skipDependencies ? { skipDependencies: true } : {}),
|
|
5484
5647
|
...(environment !== undefined ? { environment } : {}),
|
|
5485
5648
|
},
|
|
5486
5649
|
idempotencyKey,
|
|
@@ -5647,6 +5810,8 @@ export async function runTestRun(opts, deps = {}) {
|
|
|
5647
5810
|
// Present ONLY as `false`. Omission is how the protected
|
|
5648
5811
|
// default is requested — see `TriggerRunBody.autoHeal`.
|
|
5649
5812
|
...(opts.autoHeal === false ? { autoHeal: false } : {}),
|
|
5813
|
+
// Present only when asked for; an older backend strips it.
|
|
5814
|
+
...(opts.skipDependencies ? { skipDependencies: true } : {}),
|
|
5650
5815
|
// The client ID only. The secret stays in this process and never
|
|
5651
5816
|
// reaches a request body, an idempotency row, or an audit line.
|
|
5652
5817
|
...(tunnelSession ? { tunnelClientId: tunnelSession.clientId } : {}),
|
|
@@ -5691,7 +5856,6 @@ export async function runTestRun(opts, deps = {}) {
|
|
|
5691
5856
|
const stderrFn = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
5692
5857
|
// Set only when a verified environment names a concrete retry — the
|
|
5693
5858
|
// no-environment-recorded attach path has nothing to name.
|
|
5694
|
-
let retryFlags;
|
|
5695
5859
|
const incompatibleRun = (reason) => new ApiError({
|
|
5696
5860
|
code: 'CONFLICT',
|
|
5697
5861
|
message: `Conflict: run ${currentRunId} is already in flight; ${reason}. This invocation cannot attach to it.`,
|
|
@@ -5708,47 +5872,7 @@ export async function runTestRun(opts, deps = {}) {
|
|
|
5708
5872
|
throw readErr;
|
|
5709
5873
|
throw incompatibleRun('its environment could not be verified');
|
|
5710
5874
|
}
|
|
5711
|
-
const
|
|
5712
|
-
// `undefined` (no key at all) is a V2 run or a backend that predates
|
|
5713
|
-
// environments on run reads; `null` is a V3 row that explicitly names no
|
|
5714
|
-
// environment, OR one whose environment lookup failed and was
|
|
5715
|
-
// swallowed server-side. Only the former may attach unverified —
|
|
5716
|
-
// treating `null` the same way would let a failed lookup slip
|
|
5717
|
-
// through the gate it exists to enforce.
|
|
5718
|
-
if (inFlightEnvironment === undefined) {
|
|
5719
|
-
if (environment !== undefined) {
|
|
5720
|
-
// --env was requested but this in-flight run has nothing
|
|
5721
|
-
// recorded to verify it against.
|
|
5722
|
-
throw incompatibleRun('its environment could not be verified');
|
|
5723
|
-
}
|
|
5724
|
-
// Restored 0.12.0 path: no environment recorded, none requested — attach.
|
|
5725
|
-
}
|
|
5726
|
-
else if (inFlightEnvironment === null ||
|
|
5727
|
-
typeof inFlightEnvironment.id !== 'string' ||
|
|
5728
|
-
inFlightEnvironment.id.length === 0) {
|
|
5729
|
-
throw incompatibleRun('its environment could not be verified');
|
|
5730
|
-
}
|
|
5731
|
-
else {
|
|
5732
|
-
let currentEnvironment;
|
|
5733
|
-
try {
|
|
5734
|
-
const listing = await client.get(`/projects/${encodeURIComponent(inFlightRun.projectId)}/env`);
|
|
5735
|
-
currentEnvironment = listing.environments.find(row => environment === undefined ? row.isDefault : row.name === environment);
|
|
5736
|
-
}
|
|
5737
|
-
catch (listErr) {
|
|
5738
|
-
if (listErr instanceof InterruptError)
|
|
5739
|
-
throw listErr;
|
|
5740
|
-
throw incompatibleRun('its environment could not be verified');
|
|
5741
|
-
}
|
|
5742
|
-
if (typeof currentEnvironment?.id !== 'string' || currentEnvironment.id.length === 0) {
|
|
5743
|
-
// The listing succeeded but named nothing we can compare against —
|
|
5744
|
-
// that is unverified, not a proven mismatch.
|
|
5745
|
-
throw incompatibleRun('its environment could not be verified');
|
|
5746
|
-
}
|
|
5747
|
-
if (currentEnvironment.id !== inFlightEnvironment.id) {
|
|
5748
|
-
throw incompatibleRun('its environment does not match the requested environment');
|
|
5749
|
-
}
|
|
5750
|
-
retryFlags = `--env ${currentEnvironment.name}`;
|
|
5751
|
-
}
|
|
5875
|
+
const retryFlags = await verifyInFlightRunEnvironment(inFlightRun, environment, projectId => client.get(`/projects/${encodeURIComponent(projectId)}/env`), incompatibleRun);
|
|
5752
5876
|
// If the caller supplied --target-url, verify the in-flight run targets
|
|
5753
5877
|
// the same URL. A mismatch means we would be reporting a different
|
|
5754
5878
|
// environment's results as if our requested environment was tested.
|
|
@@ -5849,6 +5973,15 @@ export async function runTestRun(opts, deps = {}) {
|
|
|
5849
5973
|
isSameLoopbackPort(triggerResponse.targetUrl, resolvedTarget?.port ?? opts.localPort))) {
|
|
5850
5974
|
emitTargetUrlMismatchAdvisory(stderrFn, effectiveTargetUrl, triggerResponse.targetUrl);
|
|
5851
5975
|
}
|
|
5976
|
+
// Like the target URL above, an unconfirmed field is reported, not fatal: an
|
|
5977
|
+
// older backend strips it and the run goes ahead with the test cases it depends on,
|
|
5978
|
+
// as a Portal run does.
|
|
5979
|
+
// A run joined from a 409 was not started by this request, so it has no echo.
|
|
5980
|
+
if (opts.skipDependencies &&
|
|
5981
|
+
!resumedFromConflict &&
|
|
5982
|
+
triggerResponse.skipDependencies !== true) {
|
|
5983
|
+
stderrFn('[advisory] This backend did not confirm --skip-dependencies, so the run may also include the test cases this one depends on, as a Portal run does.');
|
|
5984
|
+
}
|
|
5852
5985
|
if (!opts.wait) {
|
|
5853
5986
|
printRunOrChain(out, triggerResponse, opts.createContext, data => renderTriggerRunText(data));
|
|
5854
5987
|
if (triggerRequestId && (opts.output === 'json' || opts.verbose || opts.debug))
|
|
@@ -6640,17 +6773,18 @@ export function createTestCancelCommand(deps) {
|
|
|
6640
6773
|
const cancel = new Command('cancel');
|
|
6641
6774
|
cancel
|
|
6642
6775
|
.argument('<run-id...>', 'one or more run ids to cancel')
|
|
6776
|
+
.summary('Cancel queued/running runs (refunds an unfinished FE V3 run)')
|
|
6643
6777
|
.description('Cancel one or more queued/running runs.\n' +
|
|
6644
|
-
'\nCtrl-C during --wait only detaches
|
|
6645
|
-
'run. This is the real stop button
|
|
6646
|
-
'terminal state has its
|
|
6647
|
-
'
|
|
6648
|
-
'finishes on its own and its result is discarded once cancelled.\n' +
|
|
6778
|
+
'\nCtrl-C during an ordinary --wait only detaches; it does NOT cancel the run (owned-tunnel\n' +
|
|
6779
|
+
'runs are cancelled on interrupt, see `test run --help`). This is the real stop button.\n' +
|
|
6780
|
+
'A frontend V3 run cancelled before a terminal state has its charge returned; backend and\n' +
|
|
6781
|
+
'V2 runs keep their billing, and an in-flight Lambda finishes with its result discarded.\n' +
|
|
6649
6782
|
'\nExit codes:\n' +
|
|
6650
6783
|
' 0 cancelled (fresh or already-cancelled — naturally idempotent)\n' +
|
|
6651
|
-
'
|
|
6652
|
-
'
|
|
6653
|
-
'
|
|
6784
|
+
' 1 multi-id: a cancel request failed (auth/transport/server error; see summary.errors)\n' +
|
|
6785
|
+
' 4 run id not found (single id), or ANY id not found (multi-id; outranks conflict)\n' +
|
|
6786
|
+
' 6 run already terminal (passed/failed/blocked); multi-id: any conflict\n' +
|
|
6787
|
+
'\nMulti-id output is a summary: {cancelled, alreadyCancelled, conflicts, notFound, errors}.')
|
|
6654
6788
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
6655
6789
|
.action(async (runIds, _cmdOpts, command) => {
|
|
6656
6790
|
await runTestCancel({
|
|
@@ -6879,6 +7013,7 @@ export async function writeBatchJUnitReportIfRequested(opts, results, nameByTest
|
|
|
6879
7013
|
const enriched = results.map(r => ({
|
|
6880
7014
|
...r,
|
|
6881
7015
|
name: nameByTestId?.get(r.testId) ?? (r.testTitle?.trim() ? r.testTitle : undefined) ?? r.name,
|
|
7016
|
+
classname: r.classname ?? opts.projectIdByTestId?.get(r.testId),
|
|
6882
7017
|
durationSeconds: r.durationSeconds ?? durationSecondsBetween(r.startedAt, r.finishedAt, r.createdAt),
|
|
6883
7018
|
}));
|
|
6884
7019
|
const xml = buildJUnitReport({
|
|
@@ -6888,11 +7023,20 @@ export async function writeBatchJUnitReportIfRequested(opts, results, nameByTest
|
|
|
6888
7023
|
});
|
|
6889
7024
|
await writeJUnitReportFile(opts.reportFile, xml);
|
|
6890
7025
|
}
|
|
7026
|
+
/** `buildTestNameMap` over several projects, merged. */
|
|
7027
|
+
async function buildTestNameMapForProjects(client, projectIds) {
|
|
7028
|
+
const merged = new Map();
|
|
7029
|
+
for (const projectId of projectIds) {
|
|
7030
|
+
for (const [id, name] of await buildTestNameMap(client, projectId))
|
|
7031
|
+
merged.set(id, name);
|
|
7032
|
+
}
|
|
7033
|
+
return merged;
|
|
7034
|
+
}
|
|
6891
7035
|
/**
|
|
6892
7036
|
* Cancel runs the caller can no longer use, without letting the cleanup itself
|
|
6893
7037
|
* become the failure. Used when a batch dispatched successfully but the CLI
|
|
6894
|
-
* then discovered the dispatch was wrong to keep (the backend did not confirm
|
|
6895
|
-
*
|
|
7038
|
+
* then discovered the dispatch was wrong to keep (the backend did not confirm a
|
|
7039
|
+
* field it was sent, such as `--target-url` or `--skip-dependencies`).
|
|
6896
7040
|
* Leaving them would bill the user for a verdict nobody asked for.
|
|
6897
7041
|
*
|
|
6898
7042
|
* Every error is swallowed to a warning on purpose: the caller is already about
|
|
@@ -6902,7 +7046,7 @@ export async function writeBatchJUnitReportIfRequested(opts, results, nameByTest
|
|
|
6902
7046
|
async function cancelRunsBestEffort(client, runIds, stderrFn, label) {
|
|
6903
7047
|
if (runIds.length === 0)
|
|
6904
7048
|
return;
|
|
6905
|
-
stderrFn(`[${label}] cancelling ${runIds.length} run${runIds.length !== 1 ? 's' : ''}
|
|
7049
|
+
stderrFn(`[${label}] cancelling ${runIds.length} run${runIds.length !== 1 ? 's' : ''} the backend did not confirm…`);
|
|
6906
7050
|
for (const runId of runIds) {
|
|
6907
7051
|
try {
|
|
6908
7052
|
const response = await client.cancelRun(runId);
|
|
@@ -6913,6 +7057,154 @@ async function cancelRunsBestEffort(client, runIds, stderrFn, label) {
|
|
|
6913
7057
|
}
|
|
6914
7058
|
}
|
|
6915
7059
|
}
|
|
7060
|
+
/**
|
|
7061
|
+
* One line telling a backend-project batch what the integration phase will do
|
|
7062
|
+
* after the wave. Undefined when the backend sent no summary (older backend,
|
|
7063
|
+
* frontend project, or nothing to say).
|
|
7064
|
+
*/
|
|
7065
|
+
function formatIntegrationSummary(integration) {
|
|
7066
|
+
if (integration === undefined || !integration.runsAfterWave)
|
|
7067
|
+
return undefined;
|
|
7068
|
+
const parts = [];
|
|
7069
|
+
if (integration.existing > 0) {
|
|
7070
|
+
parts.push(`${integration.existing} existing integration test${integration.existing !== 1 ? 's' : ''} run after this wave (0.2 credits each)`);
|
|
7071
|
+
}
|
|
7072
|
+
if (integration.mayGenerate)
|
|
7073
|
+
parts.push('new ones may be generated on a first run');
|
|
7074
|
+
if (parts.length === 0)
|
|
7075
|
+
return undefined;
|
|
7076
|
+
return `Integration phase: ${parts.join('; ')}.`;
|
|
7077
|
+
}
|
|
7078
|
+
const EXECUTION_REPORT_DEFAULT_TIMEOUT_SECONDS = 60;
|
|
7079
|
+
const EXECUTION_REPORT_DEFAULT_RETRY_SECONDS = 5;
|
|
7080
|
+
/**
|
|
7081
|
+
* Fetch the execution report — the content the GitHub App posts as its PR
|
|
7082
|
+
* comment — for the one execution this CI batch dispatched into.
|
|
7083
|
+
*
|
|
7084
|
+
* Best-effort by contract: the local results table is the fallback, so an
|
|
7085
|
+
* older backend (404), a report that is not ready within the budget, a
|
|
7086
|
+
* report for some other execution, or any other failure returns `undefined`
|
|
7087
|
+
* with one stderr line. An interrupt while waiting (the request or the retry
|
|
7088
|
+
* sleep — the scope is armed across both, so a first signal is a graceful
|
|
7089
|
+
* stop, not an immediate exit) also falls back, and is handed back in
|
|
7090
|
+
* `interrupted`: the batch is already finished, so its summary and outputs are
|
|
7091
|
+
* written first, then the caller rethrows it so the exit is the signal's
|
|
7092
|
+
* code. Reads nothing when `--no-execution-report`
|
|
7093
|
+
* was passed, when a run timed out (the execution is not terminal, so the
|
|
7094
|
+
* report could only arrive late), or unless EVERY accepted row names the same
|
|
7095
|
+
* execution (an older backend omits the id; a batch spanning several
|
|
7096
|
+
* executions gets one report per execution as a follow-up — a report for one
|
|
7097
|
+
* of them would read as the whole batch's).
|
|
7098
|
+
*/
|
|
7099
|
+
async function fetchExecutionReport(client, accepted, results, opts, deps, stderrFn) {
|
|
7100
|
+
if (opts.ci?.executionReport === false || accepted.length === 0)
|
|
7101
|
+
return {};
|
|
7102
|
+
const executionIds = new Set(accepted.map(a => a.executionId));
|
|
7103
|
+
if (executionIds.size !== 1)
|
|
7104
|
+
return {};
|
|
7105
|
+
const executionId = [...executionIds][0];
|
|
7106
|
+
if (typeof executionId !== 'string' || executionId.length === 0)
|
|
7107
|
+
return {};
|
|
7108
|
+
if (results.some(r => r.status === 'timeout')) {
|
|
7109
|
+
stderrFn('[ci run] a run timed out, so the execution is not finished; the job summary uses the local results table');
|
|
7110
|
+
return {};
|
|
7111
|
+
}
|
|
7112
|
+
const timeoutSeconds = opts.ci?.executionReportTimeoutSeconds ?? EXECUTION_REPORT_DEFAULT_TIMEOUT_SECONDS;
|
|
7113
|
+
const deadlineMs = Date.now() + timeoutSeconds * 1000;
|
|
7114
|
+
const ac = new AbortController();
|
|
7115
|
+
const timer = setTimeout(() => ac.abort(), timeoutSeconds * 1000);
|
|
7116
|
+
const sleepFn = deps.sleep ?? defaultSleep;
|
|
7117
|
+
const shutdown = shutdownOf(deps);
|
|
7118
|
+
// Every `pollRunUntilTerminal` has disarmed by now, so without this scope a
|
|
7119
|
+
// SIGINT/SIGTERM during the retry sleep would take the signal handler's
|
|
7120
|
+
// disarmed path and exit at once — no summary, no outputs.
|
|
7121
|
+
const disarm = shutdown.arm();
|
|
7122
|
+
try {
|
|
7123
|
+
for (;;) {
|
|
7124
|
+
// No automatic retries: the deadline below is the only retry policy.
|
|
7125
|
+
const res = await client.getExecutionReport(executionId, { signal: ac.signal, retry: false });
|
|
7126
|
+
if (res.ready && res.report && typeof res.markdown === 'string') {
|
|
7127
|
+
if (res.report.executionId !== executionId) {
|
|
7128
|
+
stderrFn(`[ci run] execution report names execution ${res.report.executionId}, not ${executionId}; the job summary uses the local results table`);
|
|
7129
|
+
return {};
|
|
7130
|
+
}
|
|
7131
|
+
return { ready: { report: res.report, markdown: res.markdown } };
|
|
7132
|
+
}
|
|
7133
|
+
const remainingMs = deadlineMs - Date.now();
|
|
7134
|
+
if (remainingMs <= 0)
|
|
7135
|
+
break;
|
|
7136
|
+
const retrySeconds = Math.max(1, res.retryAfterSeconds ?? EXECUTION_REPORT_DEFAULT_RETRY_SECONDS);
|
|
7137
|
+
// Interruptible: a SIGINT/SIGTERM here means "stop waiting for the
|
|
7138
|
+
// report", not "drop the finished batch's summary and outputs".
|
|
7139
|
+
await sleepUnlessInterrupted(sleepFn, Math.min(remainingMs, retrySeconds * 1000), shutdown.signal);
|
|
7140
|
+
if (Date.now() >= deadlineMs)
|
|
7141
|
+
break;
|
|
7142
|
+
}
|
|
7143
|
+
stderrFn(`[ci run] execution report not ready within ${timeoutSeconds}s; the job summary uses the local results table`);
|
|
7144
|
+
}
|
|
7145
|
+
catch (err) {
|
|
7146
|
+
if (err instanceof InterruptError) {
|
|
7147
|
+
stderrFn('[ci run] interrupted while waiting for the execution report; the job summary uses the local results table');
|
|
7148
|
+
return { interrupted: err };
|
|
7149
|
+
}
|
|
7150
|
+
stderrFn(`[ci run] execution report unavailable (${err instanceof Error ? err.message : String(err)}); the job summary uses the local results table`);
|
|
7151
|
+
}
|
|
7152
|
+
finally {
|
|
7153
|
+
clearTimeout(timer);
|
|
7154
|
+
disarm();
|
|
7155
|
+
}
|
|
7156
|
+
return {};
|
|
7157
|
+
}
|
|
7158
|
+
/** Publish all CI surfaces from one summary before applying the CI gate. */
|
|
7159
|
+
async function finishCiBatch(payload, opts, deps, nameByTestId, executionError,
|
|
7160
|
+
/** The accepted rows with poll timing, for the JUnit report only. */
|
|
7161
|
+
junitResults = payload.accepted,
|
|
7162
|
+
/** The server's execution report, when the backend provided one in time. */
|
|
7163
|
+
executionReport) {
|
|
7164
|
+
// A CI gate that dispatched nothing is its own funnel outcome (green only
|
|
7165
|
+
// with --allow-empty); the gated case is recorded by the caller, which holds
|
|
7166
|
+
// the execution id.
|
|
7167
|
+
if (payload.accepted.length === 0)
|
|
7168
|
+
recordTelemetryExtras({ ciRunOutcome: 'empty' });
|
|
7169
|
+
const summary = summarizeAcceptedPayload(JSON.stringify(payload), {
|
|
7170
|
+
foldSkippedBuckets: true,
|
|
7171
|
+
notFoundNote: 'test not found (not dispatched)',
|
|
7172
|
+
});
|
|
7173
|
+
if (executionReport)
|
|
7174
|
+
summary.executionReport = executionReport.report;
|
|
7175
|
+
const io = {
|
|
7176
|
+
env: deps.env ?? process.env,
|
|
7177
|
+
stdout: deps.stdout ?? ((line) => process.stdout.write(`${line}\n`)),
|
|
7178
|
+
stderr: deps.stderr ?? ((line) => process.stderr.write(`${line}\n`)),
|
|
7179
|
+
};
|
|
7180
|
+
makeOutput(opts.output, deps).print({ ...payload, summary }, () => `CI run: ${summary.passed}/${summary.total} passed, ${summary.failed} failed, ` +
|
|
7181
|
+
`${summary.skipped} skipped, ${summary.timedOut} timed out`);
|
|
7182
|
+
emitCiArtifacts(summary, opts, io, 'ci run', {
|
|
7183
|
+
markdown: executionReport
|
|
7184
|
+
? reconcileExecutionReportMarkdown(summary, executionReport)
|
|
7185
|
+
: undefined,
|
|
7186
|
+
});
|
|
7187
|
+
emitCiStepOutputs(summary, io);
|
|
7188
|
+
if (executionReport)
|
|
7189
|
+
emitExecutionReportOutputs(executionReport, io);
|
|
7190
|
+
let reportError;
|
|
7191
|
+
try {
|
|
7192
|
+
// Same rows as `test run --all`: every non-dispatched member is a skipped
|
|
7193
|
+
// testcase, so the report never claims a partial batch ran in full.
|
|
7194
|
+
await writeBatchJUnitReportIfRequested(opts, [...junitResults, ...skippedJUnitResultsFromSummary(summary, payload.accepted)], nameByTestId);
|
|
7195
|
+
}
|
|
7196
|
+
catch (err) {
|
|
7197
|
+
reportError = err;
|
|
7198
|
+
io.stderr(`[ci run] could not write the JUnit report: ${err instanceof Error ? err.message : String(err)}`);
|
|
7199
|
+
}
|
|
7200
|
+
if (executionError)
|
|
7201
|
+
throw executionError;
|
|
7202
|
+
const failure = resolveCiRunFailure(summary, payload.accepted, { ...opts, failOnSkipped: opts.ci?.failOnSkipped }, payload.conflicts);
|
|
7203
|
+
if (failure)
|
|
7204
|
+
throw failure;
|
|
7205
|
+
if (reportError)
|
|
7206
|
+
throw reportError;
|
|
7207
|
+
}
|
|
6916
7208
|
/** Human explanation for a zero-dispatch batch, from what the engine skipped. */
|
|
6917
7209
|
function zeroDispatchReason(skippedFrontend, skippedIntegration) {
|
|
6918
7210
|
const parts = [];
|
|
@@ -6940,7 +7232,12 @@ function zeroDispatchReason(skippedFrontend, skippedIntegration) {
|
|
|
6940
7232
|
* `reason` is the human explanation shown in the annotation and the throw.
|
|
6941
7233
|
*/
|
|
6942
7234
|
async function finishZeroDispatchBatch(params) {
|
|
6943
|
-
const { reason, skipped, allowEmpty, opts, deps, stderrFn, label = 'run' } = params;
|
|
7235
|
+
const { reason, skipped, allowEmpty, opts, deps, stderrFn, label = 'run', emptyProject = false, projectId, local, } = params;
|
|
7236
|
+
// Text mode only: under --output json neither the error envelope's message
|
|
7237
|
+
// nor stderr carries the sentence (review feedback).
|
|
7238
|
+
const nextStep = emptyProject && projectId !== undefined && opts.output !== 'json'
|
|
7239
|
+
? emptyProjectNextStep(projectId, local)
|
|
7240
|
+
: undefined;
|
|
6944
7241
|
const runs = skipped.length > 0
|
|
6945
7242
|
? skipped.map(testId => ({ testId, status: 'skipped', error: reason }))
|
|
6946
7243
|
: [{ testId: '(no tests)', status: 'no_tests', error: reason }];
|
|
@@ -6977,10 +7274,15 @@ async function finishZeroDispatchBatch(params) {
|
|
|
6977
7274
|
}
|
|
6978
7275
|
if (allowEmpty) {
|
|
6979
7276
|
stderrFn(`[${label}] 0 tests dispatched (${reason}); --allow-empty set — exiting 0.`);
|
|
7277
|
+
if (nextStep !== undefined)
|
|
7278
|
+
stderrFn(`[hint] ${nextStep}`);
|
|
6980
7279
|
return;
|
|
6981
7280
|
}
|
|
7281
|
+
// The pointer rides inside the message so it prints AFTER "Error:", in
|
|
7282
|
+
// reading order — a CLIError has no nextAction slot of its own.
|
|
6982
7283
|
throw new CLIError(`No tests were dispatched — ${reason}. A CI gate that passes on zero tests is unsafe; ` +
|
|
6983
|
-
`pass --allow-empty to exit 0 intentionally
|
|
7284
|
+
`pass --allow-empty to exit 0 intentionally.` +
|
|
7285
|
+
(nextStep !== undefined ? ` ${nextStep}` : ''), 5);
|
|
6984
7286
|
}
|
|
6985
7287
|
/**
|
|
6986
7288
|
* `test run --all --project <id>` — M4 piece-2.
|
|
@@ -6991,9 +7293,19 @@ async function finishZeroDispatchBatch(params) {
|
|
|
6991
7293
|
*/
|
|
6992
7294
|
export async function runTestRunAll(opts, deps = {}) {
|
|
6993
7295
|
assertIdempotencyKey(opts.idempotencyKey);
|
|
7296
|
+
validateStatusSelector(opts.statusFilter);
|
|
6994
7297
|
const environment = normalizeEnvironmentName(opts.environment);
|
|
6995
|
-
|
|
6996
|
-
|
|
7298
|
+
// Explicit ids carry their own projects, read once the client exists; an
|
|
7299
|
+
// `--all` run needs the one project up front.
|
|
7300
|
+
const explicitIds = (opts.testIds?.length ?? 0) > 0;
|
|
7301
|
+
let projectId = '<resolved per test>';
|
|
7302
|
+
if (!explicitIds) {
|
|
7303
|
+
const resolvedProjectId = resolveProjectId(opts.projectId, deps);
|
|
7304
|
+
requireProjectId(resolvedProjectId);
|
|
7305
|
+
projectId = resolvedProjectId;
|
|
7306
|
+
}
|
|
7307
|
+
// Carry the resolved id into reports, including when it came from the env.
|
|
7308
|
+
opts = { ...opts, projectId: explicitIds ? undefined : projectId };
|
|
6997
7309
|
if (!Number.isInteger(opts.maxConcurrency) ||
|
|
6998
7310
|
opts.maxConcurrency < 1 ||
|
|
6999
7311
|
opts.maxConcurrency > MAX_BATCH_CONCURRENCY) {
|
|
@@ -7008,7 +7320,7 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7008
7320
|
});
|
|
7009
7321
|
const stderrFn = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
7010
7322
|
const out = makeOutput(opts.output, deps);
|
|
7011
|
-
if (opts.dryRun && opts.targetUrl === undefined && !opts.noWait) {
|
|
7323
|
+
if (opts.dryRun && opts.targetUrl === undefined && !opts.noWait && !explicitIds) {
|
|
7012
7324
|
let target;
|
|
7013
7325
|
try {
|
|
7014
7326
|
target = await resolveEnvironmentRunTarget({
|
|
@@ -7051,19 +7363,30 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7051
7363
|
path: '/api/cli/v1/tests/batch/run',
|
|
7052
7364
|
body: {
|
|
7053
7365
|
projectId,
|
|
7054
|
-
testIds:
|
|
7366
|
+
testIds: explicitIds
|
|
7367
|
+
? [...new Set(opts.testIds)]
|
|
7368
|
+
: opts.nameFilter || opts.statusFilter !== undefined
|
|
7369
|
+
? [
|
|
7370
|
+
opts.statusFilter !== undefined
|
|
7371
|
+
? '<filtered by --filter/--status>'
|
|
7372
|
+
: '<filtered by --filter>',
|
|
7373
|
+
]
|
|
7374
|
+
: undefined,
|
|
7055
7375
|
source: 'cli',
|
|
7056
7376
|
...(opts.autoHeal === false ? { autoHeal: false } : {}),
|
|
7377
|
+
...(opts.skipDependencies ? { skipDependencies: true } : {}),
|
|
7057
7378
|
...(environment !== undefined ? { environment } : {}),
|
|
7058
7379
|
...(opts.targetUrl !== undefined ? { targetUrl: opts.targetUrl } : {}),
|
|
7059
7380
|
},
|
|
7060
7381
|
idempotencyKey,
|
|
7061
7382
|
...(opts.wait ? { thenPoll: '/api/cli/v1/runs/<run-id>?waitSeconds=25' } : {}),
|
|
7062
7383
|
};
|
|
7063
|
-
if (opts.report === 'junit' && opts.reportFile !== undefined) {
|
|
7384
|
+
if (!opts.ci && opts.report === 'junit' && opts.reportFile !== undefined) {
|
|
7064
7385
|
await writeJUnitReportFile(opts.reportFile, sampleJUnitReportXml(opts.projectId, opts.reportSuiteName));
|
|
7065
7386
|
}
|
|
7066
|
-
out.print(opts.targetUrl !== undefined
|
|
7387
|
+
out.print(opts.ci || opts.targetUrl !== undefined || explicitIds || opts.skipDependencies
|
|
7388
|
+
? envelope
|
|
7389
|
+
: (batchRunSample ?? envelope));
|
|
7067
7390
|
return undefined;
|
|
7068
7391
|
}
|
|
7069
7392
|
// Probe once before dispatch. A preview still warming up can use
|
|
@@ -7076,7 +7399,7 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7076
7399
|
// `--env` gate — see `runTestRun`. Before the test-set enumeration so a
|
|
7077
7400
|
// gated batch makes no billable call at all.
|
|
7078
7401
|
const environmentCache = deps.environmentCache ?? new Map();
|
|
7079
|
-
const automaticTarget = opts.environmentResolutionComplete
|
|
7402
|
+
const automaticTarget = opts.environmentResolutionComplete || explicitIds
|
|
7080
7403
|
? undefined
|
|
7081
7404
|
: await resolveEnvironmentRunTarget({
|
|
7082
7405
|
client,
|
|
@@ -7108,8 +7431,27 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7108
7431
|
}
|
|
7109
7432
|
assertNoTunnelOptions(opts);
|
|
7110
7433
|
assertFreshRunWaitOptions(opts, true);
|
|
7111
|
-
//
|
|
7112
|
-
//
|
|
7434
|
+
// Explicit ids: read each id's project before anything is dispatched. The
|
|
7435
|
+
// batch endpoint refuses a request whose ids span projects, and refuses it
|
|
7436
|
+
// whole for an unknown id, so grouping and existence have to be settled here.
|
|
7437
|
+
const projectOf = new Map();
|
|
7438
|
+
const explicitTestIds = explicitIds ? [...new Set(opts.testIds)] : [];
|
|
7439
|
+
if (explicitIds) {
|
|
7440
|
+
for (const [id, project] of await resolveTestProjects(client, explicitTestIds, opts.knownTests)) {
|
|
7441
|
+
projectOf.set(id, project);
|
|
7442
|
+
}
|
|
7443
|
+
projectId = projectOf.get(explicitTestIds[0]);
|
|
7444
|
+
const several = new Set(projectOf.values()).size > 1;
|
|
7445
|
+
opts = {
|
|
7446
|
+
...opts,
|
|
7447
|
+
projectId: several ? undefined : projectId,
|
|
7448
|
+
projectIdByTestId: projectOf,
|
|
7449
|
+
};
|
|
7450
|
+
}
|
|
7451
|
+
const multiProject = new Set(projectOf.values()).size > 1;
|
|
7452
|
+
const projectOfTest = (testId) => projectOf.get(testId) ?? projectId;
|
|
7453
|
+
// Portal deep links for batch output: a test belongs to its own project
|
|
7454
|
+
// (opts.projectId for `--all`), so per-item dashboardUrl needs no extra wire data. The
|
|
7113
7455
|
// project-level URL closes out text-mode output ("watch the wave here").
|
|
7114
7456
|
// Both stay undefined for unknown API hosts (resolvePortalBase contract).
|
|
7115
7457
|
const batchApiUrl = resolveApiUrl(opts, deps);
|
|
@@ -7131,25 +7473,77 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7131
7473
|
// shipped in every environment — it only serves runs from an older backend.
|
|
7132
7474
|
if (typeof item.dashboardUrl === 'string')
|
|
7133
7475
|
return item;
|
|
7134
|
-
const dashboardUrl = resolvePortalUrl(batchApiUrl,
|
|
7476
|
+
const dashboardUrl = resolvePortalUrl(batchApiUrl, projectOfTest(item.testId), item.testId);
|
|
7135
7477
|
return dashboardUrl !== undefined ? { ...item, dashboardUrl } : item;
|
|
7136
7478
|
};
|
|
7137
7479
|
const idempotencyKey = opts.idempotencyKey ?? `cli-batch-run-fresh-${randomUUID()}`;
|
|
7138
7480
|
if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
|
|
7139
7481
|
stderrFn(`idempotency-key: ${idempotencyKey}`);
|
|
7140
7482
|
}
|
|
7141
|
-
// Every dispatch
|
|
7483
|
+
// Every dispatch request sends the same fields.
|
|
7142
7484
|
// `autoHeal` is present ONLY as `false`; omission requests the protected default.
|
|
7143
7485
|
const dispatchFields = {
|
|
7144
7486
|
source: 'cli',
|
|
7145
7487
|
...(opts.autoHeal === false ? { autoHeal: false } : {}),
|
|
7488
|
+
...(opts.skipDependencies ? { skipDependencies: true } : {}),
|
|
7146
7489
|
...(environment !== undefined ? { environment } : {}),
|
|
7147
7490
|
...(opts.targetUrl !== undefined ? { targetUrl: opts.targetUrl } : {}),
|
|
7491
|
+
...(opts.admission !== undefined ? { admission: opts.admission } : {}),
|
|
7492
|
+
...(opts.previewName !== undefined ? { previewName: opts.previewName } : {}),
|
|
7493
|
+
...(opts.githubTrigger !== undefined ? { githubTrigger: opts.githubTrigger } : {}),
|
|
7148
7494
|
};
|
|
7149
|
-
|
|
7150
|
-
|
|
7495
|
+
/**
|
|
7496
|
+
* The fields a dispatch leg must see echoed back. An older backend strips
|
|
7497
|
+
* what it does not know and runs anyway — against the wrong target, with a
|
|
7498
|
+
* cut batch, or as a plain override where a preview environment was asked
|
|
7499
|
+
* for — so each is confirmed exactly, on every leg.
|
|
7500
|
+
*/
|
|
7501
|
+
function unhonoredDispatchFields(response) {
|
|
7502
|
+
const out = [];
|
|
7503
|
+
if (opts.targetUrl !== undefined && response.targetUrl !== opts.targetUrl) {
|
|
7504
|
+
out.push({
|
|
7505
|
+
field: 'targetUrl',
|
|
7506
|
+
reason: 'target-url-not-honored',
|
|
7507
|
+
message: 'This backend did not confirm --target-url on the batch run; the accepted runs may have used another URL.',
|
|
7508
|
+
nextAction: 'Use a backend that supports batch target URL overrides, or retry without --target-url.',
|
|
7509
|
+
});
|
|
7510
|
+
}
|
|
7511
|
+
if (opts.skipDependencies && response.skipDependencies !== true) {
|
|
7512
|
+
out.push({
|
|
7513
|
+
field: 'skipDependencies',
|
|
7514
|
+
reason: 'skip-dependencies-not-honored',
|
|
7515
|
+
message: 'This backend did not confirm --skip-dependencies, so the accepted runs may also include the test cases they depend on.',
|
|
7516
|
+
nextAction: 'Use a backend that supports --skip-dependencies on batch runs, or retry without --skip-dependencies.',
|
|
7517
|
+
});
|
|
7518
|
+
}
|
|
7519
|
+
if (opts.admission !== undefined && response.admission !== opts.admission) {
|
|
7520
|
+
out.push({
|
|
7521
|
+
field: 'admission',
|
|
7522
|
+
reason: 'admission-not-honored',
|
|
7523
|
+
message: 'This backend did not confirm the single-execution admission mode; the batch may have been cut to the per-key budget.',
|
|
7524
|
+
nextAction: 'Use a backend that supports ci run (v0.20.0 or later).',
|
|
7525
|
+
});
|
|
7526
|
+
}
|
|
7527
|
+
if (opts.previewName !== undefined && response.previewName !== opts.previewName) {
|
|
7528
|
+
out.push({
|
|
7529
|
+
field: 'previewName',
|
|
7530
|
+
reason: 'preview-not-honored',
|
|
7531
|
+
message: 'This backend did not confirm the CI preview environment; the accepted runs may have run as a plain target override instead of in github-pr-<N>.',
|
|
7532
|
+
nextAction: 'Use a backend that supports ci run (v0.20.0 or later).',
|
|
7533
|
+
});
|
|
7534
|
+
}
|
|
7535
|
+
return out;
|
|
7536
|
+
}
|
|
7537
|
+
async function assertBatchTargetEcho(response, previouslyAccepted,
|
|
7538
|
+
/** A later request: the caller reports or awaits the stopped dispatch, so no artifacts are written here. */
|
|
7539
|
+
stoppedDispatch = false) {
|
|
7540
|
+
const unhonored = unhonoredDispatchFields(response);
|
|
7541
|
+
if (unhonored.length === 0)
|
|
7151
7542
|
return;
|
|
7152
|
-
const
|
|
7543
|
+
const { field, reason, message, nextAction } = unhonored[0];
|
|
7544
|
+
// Every unhonored echo means a backend that predates the CI contract.
|
|
7545
|
+
if (opts.ci)
|
|
7546
|
+
recordTelemetryExtras({ ciRunOutcome: 'refused_admission' });
|
|
7153
7547
|
// Only this response's runs are unconfirmed. Runs an earlier leg confirmed
|
|
7154
7548
|
// keep running against the right URL; they are reported as not awaited,
|
|
7155
7549
|
// never cancelled.
|
|
@@ -7157,8 +7551,8 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7157
7551
|
const unconfirmedIds = new Set(unconfirmed.map(item => item.runId));
|
|
7158
7552
|
const confirmed = dedupeBatchRunFreshAccepted([...previouslyAccepted]).deduped.filter(item => !unconfirmedIds.has(item.runId));
|
|
7159
7553
|
await cancelRunsBestEffort(client, unconfirmed.map(item => item.runId), stderrFn, 'run');
|
|
7160
|
-
if (opts.wait) {
|
|
7161
|
-
const notAwaited =
|
|
7554
|
+
if (opts.wait && !stoppedDispatch) {
|
|
7555
|
+
const notAwaited = `Not awaited: the batch stopped because a later dispatch did not confirm ${field}. ` +
|
|
7162
7556
|
'This run was confirmed and is still running; read it with testsprite test wait <run-id>.';
|
|
7163
7557
|
const summary = summarizeAcceptedPayload(JSON.stringify({
|
|
7164
7558
|
accepted: [
|
|
@@ -7177,11 +7571,15 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7177
7571
|
summary.failed = 1;
|
|
7178
7572
|
summary.runs.push({ testId: '(batch)', status: 'error', error: message });
|
|
7179
7573
|
}
|
|
7180
|
-
|
|
7574
|
+
const io = {
|
|
7181
7575
|
env: deps.env ?? process.env,
|
|
7182
7576
|
stdout: deps.stdout ?? (line => process.stdout.write(`${line}\n`)),
|
|
7183
7577
|
stderr: stderrFn,
|
|
7184
|
-
}
|
|
7578
|
+
};
|
|
7579
|
+
emitCiArtifacts(summary, opts, io, 'run');
|
|
7580
|
+
// `ci run` promises its step outputs before the exit code, refusal included.
|
|
7581
|
+
if (opts.ci)
|
|
7582
|
+
emitCiStepOutputs(summary, io);
|
|
7185
7583
|
try {
|
|
7186
7584
|
await writeBatchJUnitReportIfRequested(opts, summary.runs.map(row => ({
|
|
7187
7585
|
testId: row.testId,
|
|
@@ -7200,41 +7598,47 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7200
7598
|
error: {
|
|
7201
7599
|
code: 'UNSUPPORTED',
|
|
7202
7600
|
message,
|
|
7203
|
-
nextAction
|
|
7601
|
+
nextAction,
|
|
7204
7602
|
requestId: 'local',
|
|
7205
|
-
details: { field
|
|
7603
|
+
details: { field, reason },
|
|
7206
7604
|
},
|
|
7207
7605
|
});
|
|
7208
7606
|
}
|
|
7209
7607
|
// Resolve testIds: fetch all tests in the project, apply --filter.
|
|
7210
|
-
let testIds;
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
}
|
|
7608
|
+
let testIds = explicitIds ? explicitTestIds : undefined;
|
|
7609
|
+
const nameFiltered = opts.nameFilter !== undefined && opts.nameFilter !== '';
|
|
7610
|
+
const statusFiltered = opts.statusFilter !== undefined;
|
|
7611
|
+
if (!explicitIds && (nameFiltered || statusFiltered)) {
|
|
7612
|
+
// The name and status filters are applied here, so the full test set is read.
|
|
7613
|
+
const filtered = await resolveAllProjectTests({
|
|
7614
|
+
client,
|
|
7615
|
+
projectId,
|
|
7616
|
+
statusFilter: opts.statusFilter,
|
|
7617
|
+
nameFilter: opts.nameFilter,
|
|
7618
|
+
stderr: stderrFn,
|
|
7619
|
+
latestStatus: true,
|
|
7620
|
+
});
|
|
7223
7621
|
testIds = filtered.map(t => t.id);
|
|
7224
7622
|
if (testIds.length === 0) {
|
|
7225
|
-
|
|
7226
|
-
|
|
7623
|
+
const selectors = describeRunSelectors(opts);
|
|
7624
|
+
stderrFn(`No tests found in project ${projectId} matching ${selectors} — nothing to run.`);
|
|
7625
|
+
const emptyResponse = {
|
|
7227
7626
|
accepted: [],
|
|
7228
7627
|
conflicts: [],
|
|
7229
7628
|
deferred: [],
|
|
7230
7629
|
skippedFrontend: [],
|
|
7231
7630
|
skippedIntegration: [],
|
|
7232
|
-
}
|
|
7631
|
+
};
|
|
7632
|
+
if (opts.ci) {
|
|
7633
|
+
await finishCiBatch({ ...emptyResponse, accepted: [] }, opts, deps);
|
|
7634
|
+
return undefined;
|
|
7635
|
+
}
|
|
7636
|
+
out.print(emptyResponse);
|
|
7233
7637
|
// Zero-dispatch (a --filter that matched nothing): emit the CI artifacts
|
|
7234
7638
|
// and fail unless --allow-empty, so a renamed test can't turn a filtered
|
|
7235
7639
|
// gate permanently green. Returns here only under --allow-empty.
|
|
7236
7640
|
await finishZeroDispatchBatch({
|
|
7237
|
-
reason:
|
|
7641
|
+
reason: `${selectors} matched no tests in project ${projectId}`,
|
|
7238
7642
|
skipped: [],
|
|
7239
7643
|
allowEmpty: opts.allowEmpty === true,
|
|
7240
7644
|
opts,
|
|
@@ -7247,15 +7651,187 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7247
7651
|
}
|
|
7248
7652
|
// When no --filter, omit testIds → server runs ALL tests in the project
|
|
7249
7653
|
// (BE tests on the legacy V2 wave engine; FE + BE on the V3 unified engine).
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
}, { idempotencyKey });
|
|
7654
|
+
// One request per project and window of MAX_BATCH_RUN_IDS ids, sent one at a
|
|
7655
|
+
// time. `--all` without a filter names no ids and stays a single request, and
|
|
7656
|
+
// `ci run` keeps its one-request contract whatever the filter matched.
|
|
7657
|
+
const dispatchUnits = testIds !== undefined ? planBatchRunUnits(testIds, projectOfTest, !opts.ci) : [{ projectId }];
|
|
7255
7658
|
// Shared across every dispatch this invocation makes — see the `reported` param.
|
|
7256
7659
|
const optOutReported = new Set();
|
|
7257
|
-
|
|
7258
|
-
|
|
7660
|
+
/**
|
|
7661
|
+
* Report a dispatch that stopped part-way and is not awaited: no `--wait`, a
|
|
7662
|
+
* first request that failed, or an interrupt (under `--wait` a later failure
|
|
7663
|
+
* is awaited instead — see `stoppedError`). The runs earlier requests
|
|
7664
|
+
* accepted keep executing (and billing) and nothing polls them from here, so
|
|
7665
|
+
* their ids and the ids never sent are what the caller needs; the error keeps
|
|
7666
|
+
* its own code and so its own exit code.
|
|
7667
|
+
*/
|
|
7668
|
+
async function reportStoppedDispatch(err, done, undispatched) {
|
|
7669
|
+
const { deduped: acceptedDone, dropped: droppedDone } = dedupeBatchRunFreshAccepted(done.flatMap(r => r.accepted));
|
|
7670
|
+
// A producer two requests both accepted is polled once elsewhere; here
|
|
7671
|
+
// nothing is polled, but the extra run is still executing and must be named.
|
|
7672
|
+
warnDroppedDuplicateRuns(acceptedDone, droppedDone, stderrFn);
|
|
7673
|
+
const keptRunIds = new Map(acceptedDone.map(r => [r.testId, r.runId]));
|
|
7674
|
+
const extraRunIds = droppedDone
|
|
7675
|
+
.filter(r => r.runId !== keptRunIds.get(r.testId))
|
|
7676
|
+
.map(r => r.runId);
|
|
7677
|
+
const waitRunIds = [...acceptedDone.map(r => r.runId), ...new Set(extraRunIds)];
|
|
7678
|
+
const conflictsDone = done.flatMap(r => r.conflicts);
|
|
7679
|
+
const deferredDone = done.flatMap(r => r.deferred);
|
|
7680
|
+
const skippedFrontendDone = done.flatMap(r => r.skippedFrontend);
|
|
7681
|
+
const skippedIntegrationDone = done.flatMap(r => r.skippedIntegration);
|
|
7682
|
+
const notRunTestIds = undispatched.flatMap(u => u.testIds ?? []);
|
|
7683
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
7684
|
+
const partial = {
|
|
7685
|
+
accepted: acceptedDone.map(withBatchDashboardUrl),
|
|
7686
|
+
conflicts: conflictsDone,
|
|
7687
|
+
deferred: deferredDone,
|
|
7688
|
+
...(skippedFrontendDone.length > 0 ? { skippedFrontend: skippedFrontendDone } : {}),
|
|
7689
|
+
...(skippedIntegrationDone.length > 0 ? { skippedIntegration: skippedIntegrationDone } : {}),
|
|
7690
|
+
notRunTestIds,
|
|
7691
|
+
};
|
|
7692
|
+
if (opts.output === 'json' || acceptedDone.length > 0) {
|
|
7693
|
+
out.print(partial, () => acceptedDone.map(r => `${r.runId} accepted`).join('\n'));
|
|
7694
|
+
}
|
|
7695
|
+
const waitHint = waitRunIds.length > 0
|
|
7696
|
+
? `${waitRunIds.length} accepted run${waitRunIds.length !== 1 ? 's are' : ' is'} still executing and not awaited: testsprite test wait ${waitRunIds.join(' ')}`
|
|
7697
|
+
: undefined;
|
|
7698
|
+
const notRunHint = `${notRunTestIds.length} test${notRunTestIds.length !== 1 ? 's were' : ' was'} not dispatched: ${notRunTestIds.join(' ')}`;
|
|
7699
|
+
stderrFn(`[run] Dispatch stopped (${reason}). ${[waitHint, notRunHint].join('. ')}.`);
|
|
7700
|
+
if (opts.wait) {
|
|
7701
|
+
// Best effort: the artifacts must never mask the error that stopped the dispatch.
|
|
7702
|
+
try {
|
|
7703
|
+
const notAwaited = 'Not awaited: the dispatch stopped before every test was sent. This run was accepted and is still running; read it with testsprite test wait <run-id>.';
|
|
7704
|
+
const summary = summarizeAcceptedPayload(JSON.stringify({
|
|
7705
|
+
accepted: acceptedDone.map(item => ({
|
|
7706
|
+
...item,
|
|
7707
|
+
status: 'error',
|
|
7708
|
+
error: { message: notAwaited },
|
|
7709
|
+
})),
|
|
7710
|
+
deferred: deferredDone,
|
|
7711
|
+
conflicts: conflictsDone,
|
|
7712
|
+
skippedFrontend: skippedFrontendDone,
|
|
7713
|
+
skippedIntegration: skippedIntegrationDone,
|
|
7714
|
+
skipped: notRunTestIds.map(testId => ({
|
|
7715
|
+
testId,
|
|
7716
|
+
reason: `not dispatched: ${reason}`,
|
|
7717
|
+
})),
|
|
7718
|
+
}), { foldSkippedBuckets: true });
|
|
7719
|
+
emitCiArtifacts(summary, opts, {
|
|
7720
|
+
env: deps.env ?? process.env,
|
|
7721
|
+
stdout: deps.stdout ?? (line => process.stdout.write(`${line}\n`)),
|
|
7722
|
+
stderr: stderrFn,
|
|
7723
|
+
}, 'run');
|
|
7724
|
+
await writeBatchJUnitReportIfRequested(opts, summary.runs.map(row => ({
|
|
7725
|
+
testId: row.testId,
|
|
7726
|
+
runId: row.runId,
|
|
7727
|
+
status: isNonDispatchedStatus(row.status) ? 'skipped' : 'error',
|
|
7728
|
+
...(isNonDispatchedStatus(row.status)
|
|
7729
|
+
? { skipReason: row.error }
|
|
7730
|
+
: { error: { code: 'UNSUPPORTED', message: row.error ?? reason, exitCode: 7 } }),
|
|
7731
|
+
})));
|
|
7732
|
+
}
|
|
7733
|
+
catch (artifactErr) {
|
|
7734
|
+
if (artifactErr instanceof InterruptError)
|
|
7735
|
+
throw artifactErr;
|
|
7736
|
+
stderrFn(`[run] could not write the CI artifacts: ${artifactErr instanceof Error ? artifactErr.message : String(artifactErr)}; continuing`);
|
|
7737
|
+
}
|
|
7738
|
+
}
|
|
7739
|
+
return withDispatchHints(err, [waitHint, notRunHint]);
|
|
7740
|
+
}
|
|
7741
|
+
/** The failed request's own error (so its exit code stands), with what the caller needs to do next prepended. */
|
|
7742
|
+
function withDispatchHints(err, hints) {
|
|
7743
|
+
if (!(err instanceof ApiError))
|
|
7744
|
+
return err;
|
|
7745
|
+
return new ApiError({
|
|
7746
|
+
code: err.code,
|
|
7747
|
+
message: err.message,
|
|
7748
|
+
nextAction: [...hints, err.nextAction].filter(Boolean).join('. '),
|
|
7749
|
+
requestId: err.requestId,
|
|
7750
|
+
details: err.details,
|
|
7751
|
+
}, err.httpStatus, err.retryAfterMs, err.apiUrl, err.serverNextAction);
|
|
7752
|
+
}
|
|
7753
|
+
/**
|
|
7754
|
+
* Under --wait, a request that fails once earlier requests were accepted
|
|
7755
|
+
* does not abandon those runs: nothing further is sent, they are polled to
|
|
7756
|
+
* their verdicts, and this error — the failed request's own — is what the
|
|
7757
|
+
* invocation exits with, ahead of any verdict-derived code.
|
|
7758
|
+
*/
|
|
7759
|
+
let stoppedError;
|
|
7760
|
+
/** Ids a stopped dispatch never sent (the requests after the failed one). */
|
|
7761
|
+
let notRunTestIds = [];
|
|
7762
|
+
const dispatchResponses = [];
|
|
7763
|
+
for (const [unitIndex, unit] of dispatchUnits.entries()) {
|
|
7764
|
+
let unitResp;
|
|
7765
|
+
try {
|
|
7766
|
+
unitResp = await client.triggerBatchRunFresh({
|
|
7767
|
+
projectId: unit.projectId,
|
|
7768
|
+
...(unit.testIds !== undefined ? { testIds: unit.testIds } : {}),
|
|
7769
|
+
...dispatchFields,
|
|
7770
|
+
}, {
|
|
7771
|
+
idempotencyKey: dispatchUnits.length === 1
|
|
7772
|
+
? idempotencyKey
|
|
7773
|
+
: suffixedIdempotencyKey(idempotencyKey, `:chunk${unitIndex}`),
|
|
7774
|
+
});
|
|
7775
|
+
}
|
|
7776
|
+
catch (err) {
|
|
7777
|
+
// A whole-batch refusal under `ci run` is a funnel outcome — every API
|
|
7778
|
+
// refusal gets one (validation by the server's `details.reason`, 402/403
|
|
7779
|
+
// as billing, the rest as other).
|
|
7780
|
+
if (opts.ci && err instanceof ApiError) {
|
|
7781
|
+
recordTelemetryExtras({ ciRunOutcome: ciRefusalOutcome(err) });
|
|
7782
|
+
}
|
|
7783
|
+
if (opts.wait && dispatchResponses.length > 0 && !(err instanceof InterruptError)) {
|
|
7784
|
+
stoppedError = err;
|
|
7785
|
+
notRunTestIds = dispatchUnits.slice(unitIndex).flatMap(u => u.testIds ?? []);
|
|
7786
|
+
break;
|
|
7787
|
+
}
|
|
7788
|
+
if (dispatchUnits.length > 1) {
|
|
7789
|
+
throw await reportStoppedDispatch(err, dispatchResponses, dispatchUnits.slice(unitIndex));
|
|
7790
|
+
}
|
|
7791
|
+
throw err;
|
|
7792
|
+
}
|
|
7793
|
+
warnIfOptOutIgnored(opts.autoHeal, unitResp.autoHeal, stderrFn, 'these runs', optOutReported);
|
|
7794
|
+
try {
|
|
7795
|
+
await assertBatchTargetEcho(unitResp, dispatchResponses.flatMap(r => r.accepted), unitIndex > 0);
|
|
7796
|
+
}
|
|
7797
|
+
catch (err) {
|
|
7798
|
+
// The unconfirmed chunk is already cancelled; earlier chunks' runs keep
|
|
7799
|
+
// executing and need reporting like any other later-chunk failure.
|
|
7800
|
+
if (unitIndex > 0) {
|
|
7801
|
+
if (opts.wait && !(err instanceof InterruptError)) {
|
|
7802
|
+
stoppedError = err;
|
|
7803
|
+
notRunTestIds = dispatchUnits.slice(unitIndex).flatMap(u => u.testIds ?? []);
|
|
7804
|
+
break;
|
|
7805
|
+
}
|
|
7806
|
+
throw await reportStoppedDispatch(err, dispatchResponses, dispatchUnits.slice(unitIndex));
|
|
7807
|
+
}
|
|
7808
|
+
throw err;
|
|
7809
|
+
}
|
|
7810
|
+
dispatchResponses.push(unitResp);
|
|
7811
|
+
}
|
|
7812
|
+
let batchResp = mergeBatchRunResponses(dispatchResponses, multiProject);
|
|
7813
|
+
if (dispatchResponses.length > 1) {
|
|
7814
|
+
// Producers the server adds per request can land in two requests; the
|
|
7815
|
+
// repeated test is polled once and the extra run is named, as on a retry.
|
|
7816
|
+
const { deduped, dropped } = dedupeBatchRunFreshAccepted(batchResp.accepted);
|
|
7817
|
+
if (dropped.length > 0) {
|
|
7818
|
+
warnDroppedDuplicateRuns(deduped, dropped, stderrFn);
|
|
7819
|
+
batchResp = { ...batchResp, accepted: deduped };
|
|
7820
|
+
}
|
|
7821
|
+
}
|
|
7822
|
+
if (opts.ci && batchResp.accepted.length > 0) {
|
|
7823
|
+
// Recorded as soon as the dispatch is confirmed, not after the wait: a job
|
|
7824
|
+
// cancelled mid-wait (a re-push under shape B's concurrency group, a manual
|
|
7825
|
+
// cancel, the runner's timeout) exits through InterruptError, and the
|
|
7826
|
+
// `abort` event must still say the gate dispatched and which execution
|
|
7827
|
+
// keeps running. `reportReady` is added once the report wait finishes.
|
|
7828
|
+
const dispatchedExecutionIds = new Set(batchResp.accepted.map(a => a.executionId));
|
|
7829
|
+
const dispatchedExecutionId = dispatchedExecutionIds.size === 1 ? [...dispatchedExecutionIds][0] : undefined;
|
|
7830
|
+
recordTelemetryExtras({
|
|
7831
|
+
ciRunOutcome: 'gated',
|
|
7832
|
+
...(typeof dispatchedExecutionId === 'string' ? { executionId: dispatchedExecutionId } : {}),
|
|
7833
|
+
});
|
|
7834
|
+
}
|
|
7259
7835
|
// Project-level "watch it here" link. A V3 backend sends it (string, or
|
|
7260
7836
|
// `null` when no single page exists — e.g. a `--all` that fanned out over
|
|
7261
7837
|
// several sibling projects); an older backend / the V2 engine omits the key,
|
|
@@ -7263,12 +7839,11 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7263
7839
|
// template apply — for a V3 reader that shape bounced onto a route that does
|
|
7264
7840
|
// not exist, which is why the server took it over.
|
|
7265
7841
|
const { dashboardUrl: projectDashboardUrl } = resolveDashboardUrl(batchResp, legacyProjectDashboardUrl);
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
let accepted = batchResp.accepted.slice();
|
|
7269
|
-
let deferred = batchResp.deferred.slice();
|
|
7842
|
+
const accepted = batchResp.accepted.slice();
|
|
7843
|
+
const deferred = batchResp.deferred.slice();
|
|
7270
7844
|
let conflicts = batchResp.conflicts.slice();
|
|
7271
|
-
const
|
|
7845
|
+
const skippedFrontend = batchResp.skippedFrontend.slice();
|
|
7846
|
+
const skippedIntegration = batchResp.skippedIntegration.slice();
|
|
7272
7847
|
// Print advisory for skipped FE tests.
|
|
7273
7848
|
if (skippedFrontend.length > 0) {
|
|
7274
7849
|
stderrFn(`[advisory] ${skippedFrontend.length} frontend test${skippedFrontend.length !== 1 ? 's' : ''} skipped — the batch run endpoint uses the BE-only wave engine. ` +
|
|
@@ -7285,6 +7860,9 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7285
7860
|
if (deferred.length > 0) {
|
|
7286
7861
|
stderrFn(`Rate-deferred testIds (retry later): ${deferred.map(d => d.testId).join(' ')}`);
|
|
7287
7862
|
}
|
|
7863
|
+
const integrationLine = formatIntegrationSummary(batchResp.integration);
|
|
7864
|
+
if (integrationLine !== undefined)
|
|
7865
|
+
stderrFn(integrationLine);
|
|
7288
7866
|
stderrFn(`Dispatched ${accepted.length} test${accepted.length !== 1 ? 's' : ''}` +
|
|
7289
7867
|
`${skippedFrontend.length > 0 ? ` (${skippedFrontend.length} FE skipped)` : ''}` +
|
|
7290
7868
|
`${conflicts.length > 0 ? ` (${conflicts.length} conflict${conflicts.length !== 1 ? 's' : ''})` : ''}` +
|
|
@@ -7303,6 +7881,7 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7303
7881
|
deferred,
|
|
7304
7882
|
skippedFrontend,
|
|
7305
7883
|
skippedIntegration,
|
|
7884
|
+
...(batchResp.integration !== undefined ? { integration: batchResp.integration } : {}),
|
|
7306
7885
|
};
|
|
7307
7886
|
out.print(printResp, data => {
|
|
7308
7887
|
const r = data;
|
|
@@ -7359,7 +7938,7 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7359
7938
|
// replacing it — accepted.length is 0 in this whole branch, so the
|
|
7360
7939
|
// advisory printed earlier (guarded on accepted.length > 0) never
|
|
7361
7940
|
// showed the link, and this is the only place it can.
|
|
7362
|
-
nextAction:
|
|
7941
|
+
nextAction: `${conflictNextAction(conflicts, () => 'Wait for the in-flight runs to complete, then retry, or use: testsprite test wait <run-id>')}${billingConflictLink(conflicts, batchApiUrl)}`,
|
|
7363
7942
|
requestId: 'local',
|
|
7364
7943
|
details: { conflicts: conflicts.map(c => c.testId) },
|
|
7365
7944
|
},
|
|
@@ -7375,122 +7954,48 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7375
7954
|
opts,
|
|
7376
7955
|
deps,
|
|
7377
7956
|
stderrFn,
|
|
7957
|
+
emptyProject: skippedFrontend.length === 0 &&
|
|
7958
|
+
skippedIntegration.length === 0 &&
|
|
7959
|
+
opts.nameFilter === undefined &&
|
|
7960
|
+
opts.statusFilter === undefined &&
|
|
7961
|
+
!explicitIds,
|
|
7962
|
+
projectId,
|
|
7378
7963
|
});
|
|
7379
7964
|
}
|
|
7380
7965
|
// [P2] Return post-retry state so programmatic callers and the create-chain
|
|
7381
7966
|
// JSON merge reflect what was actually dispatched, not the stale initial resp.
|
|
7382
7967
|
return { ...batchResp, accepted, deferred, conflicts };
|
|
7383
7968
|
}
|
|
7384
|
-
//
|
|
7385
|
-
//
|
|
7386
|
-
// budget is exhausted — a busy pool (the in-flight concurrency cap folds
|
|
7387
|
-
// overflow into `deferred[]`) drains within the user's own timeout instead of
|
|
7388
|
-
// giving up after a fixed few tries and failing the run. Each attempt sleeps
|
|
7389
|
-
// 61s (clamped to the remaining budget); newly-accepted runs merge into
|
|
7390
|
-
// `accepted`; if still deferred when the budget runs out, fall through to the
|
|
7391
|
-
// existing exit-7 path. `maxDeferredAttempts` is a pure runaway backstop (the
|
|
7392
|
-
// deadline check below is the real stop), scaled to the timeout so it never
|
|
7393
|
-
// caps a legitimate long wait.
|
|
7394
|
-
const sleepFn = deps.sleep ?? ((ms) => new Promise(r => setTimeout(r, ms)));
|
|
7969
|
+
// A deferred id (rare: a busy project lock or a case that went in flight) was
|
|
7970
|
+
// not dispatched and is not resent: it is reported below and exits 7.
|
|
7395
7971
|
const batchDeadlineMs = deps.environmentTunnel?.deadlineMs ?? Date.now() + opts.timeoutSeconds * 1000;
|
|
7396
|
-
//
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
// §1: clamp to what's left ABOVE the reserve so the sleep itself can't run
|
|
7409
|
-
// the budget to zero (the loop only reaches here when remainingMs >
|
|
7410
|
-
// POLL_RESERVE_MS, so the difference is always positive).
|
|
7411
|
-
const sleepMs = Math.min(DEFERRED_RETRY_DEFAULT_SLEEP_MS, remainingMs - POLL_RESERVE_MS);
|
|
7412
|
-
stderrFn(`[deferred-retry] attempt ${attempt} — retrying ${deferred.length} deferred test${deferred.length !== 1 ? 's' : ''} in ${Math.round(sleepMs / 1000)}s`);
|
|
7413
|
-
await sleepFn(sleepMs);
|
|
7414
|
-
const remainingAfterSleep = batchDeadlineMs - Date.now();
|
|
7415
|
-
if (remainingAfterSleep <= POLL_RESERVE_MS) {
|
|
7416
|
-
stderrFn(`[deferred-retry] reserving the remaining budget to poll dispatched runs — ${deferred.length} test${deferred.length !== 1 ? 's' : ''} still deferred.`);
|
|
7417
|
-
break;
|
|
7418
|
-
}
|
|
7419
|
-
const retryIds = deferred.map(d => d.testId);
|
|
7420
|
-
// [P2] Bound the derived key to ≤256 chars. Caller-supplied keys may be up
|
|
7421
|
-
// to 256 chars; appending `:deferred-retryN` (≤16 chars) could push past
|
|
7422
|
-
// the server's 256-char limit and cause every retry to be rejected. Truncate
|
|
7423
|
-
// the base key to leave room for the suffix before concatenating.
|
|
7424
|
-
const retrySuffix = `:deferred-retry${attempt}`;
|
|
7425
|
-
const retryBase = idempotencyKey.length + retrySuffix.length > 256
|
|
7426
|
-
? idempotencyKey.slice(0, 256 - retrySuffix.length)
|
|
7427
|
-
: idempotencyKey;
|
|
7428
|
-
const retryKey = `${retryBase}${retrySuffix}`;
|
|
7429
|
-
let retryResp;
|
|
7430
|
-
try {
|
|
7431
|
-
// The retry dispatch POST is deliberately NOT bound to the batch deadline
|
|
7432
|
-
// via an AbortSignal. It is a state-CREATING call (it seeds runs); if the
|
|
7433
|
-
// deadline fired mid-flight the abort would only cancel the CLIENT wait,
|
|
7434
|
-
// leaving the server having possibly created the runs while this loop
|
|
7435
|
-
// reports them as still-deferred — the user then retries with a fresh
|
|
7436
|
-
// idempotency key and DUPLICATES the execution + charge. The per-request
|
|
7437
|
-
// timeout (`--request-timeout`, default 120s) still bounds the call, and
|
|
7438
|
-
// the sleeps + fan-out poll below remain deadline-aware; only this single
|
|
7439
|
-
// dispatch may overrun the budget slightly, which is strictly safer than
|
|
7440
|
-
// an indeterminate aborted-but-maybe-dispatched batch.
|
|
7441
|
-
retryResp = await client.triggerBatchRunFresh({
|
|
7442
|
-
projectId,
|
|
7443
|
-
testIds: retryIds,
|
|
7444
|
-
...dispatchFields,
|
|
7445
|
-
}, { idempotencyKey: retryKey });
|
|
7446
|
-
}
|
|
7447
|
-
catch (err) {
|
|
7448
|
-
if (err instanceof InterruptError)
|
|
7449
|
-
throw err;
|
|
7450
|
-
if (err instanceof ApiError &&
|
|
7451
|
-
(err.code === 'UNSUPPORTED' || err.code === 'PRECONDITION_FAILED'))
|
|
7452
|
-
throw err;
|
|
7453
|
-
// If the retry itself errors, surface it and stop retrying.
|
|
7454
|
-
stderrFn(`[deferred-retry] attempt ${attempt} failed with error: ${err instanceof Error ? err.message : String(err)}`);
|
|
7455
|
-
break;
|
|
7456
|
-
}
|
|
7457
|
-
await assertBatchTargetEcho(retryResp, accepted);
|
|
7458
|
-
// The retry re-sent the opt-out (see the dispatch above), so its echo has to
|
|
7459
|
-
// be read as well; otherwise the tests a rate limit pushed into this leg are
|
|
7460
|
-
// the only ones that run unwarned.
|
|
7461
|
-
warnIfOptOutIgnored(opts.autoHeal, retryResp.autoHeal, stderrFn, 'the retried runs', optOutReported);
|
|
7462
|
-
const newlyAccepted = retryResp.accepted;
|
|
7463
|
-
const newlyDeferred = retryResp.deferred;
|
|
7464
|
-
const newlyConflicted = retryResp.conflicts;
|
|
7465
|
-
if (newlyAccepted.length > 0) {
|
|
7466
|
-
stderrFn(`[deferred-retry] attempt ${attempt}: ${newlyAccepted.length} test${newlyAccepted.length !== 1 ? 's' : ''} now accepted.`);
|
|
7467
|
-
// A retry asks only for the still-deferred ids but can come back with
|
|
7468
|
-
// tests the first dispatch already ran. Keeping both would poll the
|
|
7469
|
-
// same test twice and overstate `summary.total`.
|
|
7470
|
-
const { deduped, dropped } = dedupeBatchRunFreshAccepted(accepted.concat(newlyAccepted));
|
|
7471
|
-
accepted = deduped;
|
|
7472
|
-
warnDroppedDuplicateRuns(accepted, dropped, stderrFn);
|
|
7473
|
-
}
|
|
7474
|
-
if (newlyConflicted.length > 0) {
|
|
7475
|
-
// [P1] Merge retry-returned conflicts into the running conflicts collection
|
|
7476
|
-
// so the final summary, stderr output, and exit-code logic reflect them.
|
|
7477
|
-
// Without this merge, tests deferred-then-conflicted on retry are invisible
|
|
7478
|
-
// to the final accounting and can cause a false-zero conflicts count.
|
|
7479
|
-
stderrFn(`[deferred-retry] attempt ${attempt}: ${newlyConflicted.length} test${newlyConflicted.length !== 1 ? 's' : ''} in-flight (conflict).`);
|
|
7480
|
-
conflicts = conflicts.concat(newlyConflicted);
|
|
7481
|
-
}
|
|
7482
|
-
deferred = newlyDeferred;
|
|
7483
|
-
if (deferred.length === 0) {
|
|
7484
|
-
stderrFn(`[deferred-retry] attempt ${attempt}: all previously-deferred tests accepted.`);
|
|
7485
|
-
}
|
|
7972
|
+
// A stopped dispatch: say what was never sent, then carry on to await what was accepted.
|
|
7973
|
+
const neverSent = stoppedError === undefined
|
|
7974
|
+
? []
|
|
7975
|
+
: notRunTestIds.length > 0
|
|
7976
|
+
? notRunTestIds
|
|
7977
|
+
: deferred.map(d => d.testId);
|
|
7978
|
+
const stoppedFailure = () => withDispatchHints(stoppedError, [
|
|
7979
|
+
`${neverSent.length} test${neverSent.length !== 1 ? 's were' : ' was'} not dispatched: ${neverSent.join(' ')}`,
|
|
7980
|
+
]);
|
|
7981
|
+
if (stoppedError !== undefined) {
|
|
7982
|
+
stderrFn(`[run] Dispatch stopped (${stoppedError instanceof Error ? stoppedError.message : String(stoppedError)}); awaiting the runs already accepted. ` +
|
|
7983
|
+
`${neverSent.length} test${neverSent.length !== 1 ? 's were' : ' was'} not dispatched: ${neverSent.join(' ')}.`);
|
|
7486
7984
|
}
|
|
7487
7985
|
// Gap B: an already-running case is not a dead end under --wait. A conflict
|
|
7488
7986
|
// carrying `currentRunId` has an EXISTING run we can poll to a verdict
|
|
7489
7987
|
// (auto-resume) — the "concurrent job already started this test" case should
|
|
7490
7988
|
// wait for that run's result, not fail the batch. Conflicts without a
|
|
7491
7989
|
// resolvable in-flight run stay hard (nothing to wait on).
|
|
7492
|
-
|
|
7493
|
-
|
|
7990
|
+
// An in-flight run may belong to another deployment/environment. CI can
|
|
7991
|
+
// only use runs accepted by this invocation to judge its own change.
|
|
7992
|
+
// A `no_producer` / `producer_in_flight` conflict's `currentRunId` is the
|
|
7993
|
+
// result the server seeded BLOCKED before dispatch. It is reported with the
|
|
7994
|
+
// server's reason and exit 6, as a single `test run` reports it, not polled.
|
|
7995
|
+
// Every other conflict with a run id is polled as before.
|
|
7996
|
+
const isResumable = (c) => !opts.ci && Boolean(c.currentRunId) && !isProducerBlock(c);
|
|
7997
|
+
const resumableConflicts = conflicts.filter(isResumable);
|
|
7998
|
+
const hardConflicts = conflicts.filter(c => !isResumable(c));
|
|
7494
7999
|
// Only hard conflicts remain "conflicts" for the final accounting/exit; the
|
|
7495
8000
|
// resumable ones become polled results below.
|
|
7496
8001
|
conflicts = hardConflicts;
|
|
@@ -7507,14 +8012,38 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7507
8012
|
// many-in-flight-conflicts scenario finding 1 is about, so a serial N round-trip
|
|
7508
8013
|
// fetch (with no deadline bound) would eat the budget finding 1's fix protects.
|
|
7509
8014
|
const resolveSignal = AbortSignal.timeout(Math.max(1, batchDeadlineMs - Date.now()));
|
|
7510
|
-
|
|
8015
|
+
// One environment listing per project for the whole batch (the gate below
|
|
8016
|
+
// compares environment ids, not names, so it needs the project's list).
|
|
8017
|
+
const envListings = new Map();
|
|
8018
|
+
const listEnvironments = (projectId) => {
|
|
8019
|
+
let listing = envListings.get(projectId);
|
|
8020
|
+
if (!listing) {
|
|
8021
|
+
listing = client.get(`/projects/${encodeURIComponent(projectId)}/env`, { signal: resolveSignal });
|
|
8022
|
+
envListings.set(projectId, listing);
|
|
8023
|
+
}
|
|
8024
|
+
return listing;
|
|
8025
|
+
};
|
|
8026
|
+
const resumedOrRefused = await Promise.all(resumableConflicts.map(async (c) => {
|
|
7511
8027
|
const inFlightRunId = c.currentRunId;
|
|
8028
|
+
// The same gate the single run applies before adopting a 409: an
|
|
8029
|
+
// in-flight run on another environment (a PR gate's `github-pr-N`
|
|
8030
|
+
// clone, say) or another target URL is somebody else's run, and its
|
|
8031
|
+
// verdict must not be reported as this invocation's. Refused runs stay
|
|
8032
|
+
// hard conflicts — polled by nobody here — instead of being attached.
|
|
8033
|
+
const refused = (reason) => ({
|
|
8034
|
+
refused: {
|
|
8035
|
+
...c,
|
|
8036
|
+
reason: 'in_flight',
|
|
8037
|
+
message: `not attached: ${reason}`,
|
|
8038
|
+
},
|
|
8039
|
+
});
|
|
7512
8040
|
// Conservative default if the run can't be read: floor at NOW (never the
|
|
7513
8041
|
// epoch) so the fallback still can't accept an older run's result.
|
|
7514
8042
|
let notBefore = new Date().toISOString();
|
|
7515
8043
|
let startedBy;
|
|
8044
|
+
let inFlight;
|
|
7516
8045
|
try {
|
|
7517
|
-
|
|
8046
|
+
inFlight = await client.getRun(inFlightRunId, { signal: resolveSignal });
|
|
7518
8047
|
if (inFlight.createdAt)
|
|
7519
8048
|
notBefore = inFlight.createdAt;
|
|
7520
8049
|
startedBy = inFlight.source || inFlight.createdFrom || undefined;
|
|
@@ -7524,9 +8053,46 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7524
8053
|
throw err;
|
|
7525
8054
|
// keep the conservative now() floor (fetch failed or the signal aborted)
|
|
7526
8055
|
}
|
|
8056
|
+
if (inFlight) {
|
|
8057
|
+
try {
|
|
8058
|
+
await verifyInFlightRunEnvironment(inFlight, opts.environment, listEnvironments, reason => new ApiError({
|
|
8059
|
+
code: 'CONFLICT',
|
|
8060
|
+
message: reason,
|
|
8061
|
+
nextAction: `testsprite test wait ${inFlightRunId}`,
|
|
8062
|
+
requestId: '',
|
|
8063
|
+
details: { reason: 'run_in_flight', currentRunId: inFlightRunId },
|
|
8064
|
+
}));
|
|
8065
|
+
}
|
|
8066
|
+
catch (err) {
|
|
8067
|
+
if (err instanceof InterruptError)
|
|
8068
|
+
throw err;
|
|
8069
|
+
if (err instanceof ApiError && err.code === 'CONFLICT')
|
|
8070
|
+
return refused(err.message);
|
|
8071
|
+
throw err;
|
|
8072
|
+
}
|
|
8073
|
+
if (opts.targetUrl !== undefined && inFlight.targetUrl !== opts.targetUrl) {
|
|
8074
|
+
return refused(`it targets ${inFlight.targetUrl || 'an unreported URL'}, not ${opts.targetUrl}`);
|
|
8075
|
+
}
|
|
8076
|
+
}
|
|
8077
|
+
else if (opts.environment !== undefined || opts.targetUrl !== undefined) {
|
|
8078
|
+
// An environment or target was asked for and the run could not be
|
|
8079
|
+
// read: unverified, so not ours to attach to (fail closed, as the
|
|
8080
|
+
// single run does).
|
|
8081
|
+
return refused('its environment could not be verified');
|
|
8082
|
+
}
|
|
7527
8083
|
stderrFn(`[auto-resume] ${c.testId} — polling in-flight run ${inFlightRunId}${startedBy ? ` (started by ${startedBy})` : ''} to a verdict instead of failing`);
|
|
7528
|
-
return { testId: c.testId, runId: inFlightRunId, enqueuedAt: notBefore };
|
|
8084
|
+
return { entry: { testId: c.testId, runId: inFlightRunId, enqueuedAt: notBefore } };
|
|
7529
8085
|
}));
|
|
8086
|
+
const resumableEntries = [];
|
|
8087
|
+
for (const outcome of resumedOrRefused) {
|
|
8088
|
+
if ('entry' in outcome) {
|
|
8089
|
+
resumableEntries.push(outcome.entry);
|
|
8090
|
+
}
|
|
8091
|
+
else {
|
|
8092
|
+
stderrFn(`[auto-resume] ${outcome.refused.testId} — in-flight run ${outcome.refused.currentRunId} ${outcome.refused.message?.replace(/^not attached: /, '')}; not attaching (testsprite test wait ${outcome.refused.currentRunId} to follow it)`);
|
|
8093
|
+
conflicts.push(outcome.refused);
|
|
8094
|
+
}
|
|
8095
|
+
}
|
|
7530
8096
|
// --wait: fan-out poll each accepted run by its runId, PLUS each auto-resumed
|
|
7531
8097
|
// in-flight run. Every accepted entry carries a real runId (the backend routes
|
|
7532
8098
|
// slot-claim failures to conflicts[]); the resumed entries reuse the existing
|
|
@@ -7541,27 +8107,40 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7541
8107
|
]);
|
|
7542
8108
|
warnDroppedDuplicateRuns(pollable, droppedFromMerge, stderrFn);
|
|
7543
8109
|
if (pollable.length === 0) {
|
|
7544
|
-
// Build final response
|
|
8110
|
+
// Build final response from the dispatch result.
|
|
7545
8111
|
const finalResp = {
|
|
7546
8112
|
accepted,
|
|
7547
8113
|
conflicts,
|
|
7548
8114
|
deferred,
|
|
7549
8115
|
skippedFrontend,
|
|
7550
8116
|
skippedIntegration,
|
|
8117
|
+
...(batchResp.integration !== undefined ? { integration: batchResp.integration } : {}),
|
|
7551
8118
|
};
|
|
7552
|
-
|
|
8119
|
+
if (!opts.ci) {
|
|
8120
|
+
out.print(notRunTestIds.length > 0 ? { ...finalResp, notRunTestIds } : finalResp);
|
|
8121
|
+
}
|
|
7553
8122
|
recordBatchOutcome({
|
|
7554
8123
|
accepted: accepted.length,
|
|
7555
8124
|
conflicts,
|
|
7556
8125
|
deferred: deferred.length,
|
|
7557
8126
|
skipped: skippedFrontend.length + skippedIntegration.length,
|
|
7558
8127
|
});
|
|
8128
|
+
if (opts.ci) {
|
|
8129
|
+
await finishCiBatch({ ...finalResp, accepted: [] }, opts, deps, undefined);
|
|
8130
|
+
return { ...batchResp, ...finalResp };
|
|
8131
|
+
}
|
|
7559
8132
|
// Nothing to poll: surface deferred (rate-limit → exit 7) or all-conflict (exit 6),
|
|
7560
8133
|
// mirroring the non-wait path so `--wait` never silently exits 0 on a no-op batch.
|
|
7561
8134
|
// Emit the deferred/conflict summary + annotations first so CI shows them (the
|
|
7562
8135
|
// pure zero-dispatch fall-through emits its OWN skipped-rows summary below).
|
|
7563
|
-
if (deferred.length > 0 || conflicts.length > 0) {
|
|
7564
|
-
const summary = summarizeAcceptedPayload(JSON.stringify(
|
|
8136
|
+
if (deferred.length > 0 || conflicts.length > 0 || stoppedError !== undefined) {
|
|
8137
|
+
const summary = summarizeAcceptedPayload(JSON.stringify({
|
|
8138
|
+
...finalResp,
|
|
8139
|
+
skipped: notRunTestIds.map(testId => ({
|
|
8140
|
+
testId,
|
|
8141
|
+
reason: 'not dispatched: the dispatch stopped before this test was sent',
|
|
8142
|
+
})),
|
|
8143
|
+
}), { foldSkippedBuckets: explicitIds });
|
|
7565
8144
|
await writeBatchJUnitReportIfRequested(opts, skippedJUnitResultsFromSummary(summary));
|
|
7566
8145
|
emitCiArtifacts(summary, opts, {
|
|
7567
8146
|
env: deps.env ?? process.env,
|
|
@@ -7569,6 +8148,8 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7569
8148
|
stderr: stderrFn,
|
|
7570
8149
|
}, 'run');
|
|
7571
8150
|
}
|
|
8151
|
+
if (stoppedError !== undefined)
|
|
8152
|
+
throw stoppedFailure();
|
|
7572
8153
|
if (deferred.length > 0) {
|
|
7573
8154
|
throw new CLIError(`Batch run incomplete: ${deferred.length} test${deferred.length !== 1 ? 's' : ''} rate-deferred (per-key run budget) — retry these individually after ~60s: ${deferred.map(d => d.testId).join(' ')}`, 7);
|
|
7574
8155
|
}
|
|
@@ -7587,7 +8168,7 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7587
8168
|
message: `Batch run: nothing was queued — ${allConflictsInFlight(conflicts)
|
|
7588
8169
|
? `${conflicts.length} test${conflicts.length !== 1 ? 's' : ''} already in flight`
|
|
7589
8170
|
: summarizeConflicts(conflicts)}.`,
|
|
7590
|
-
nextAction:
|
|
8171
|
+
nextAction: `${conflictNextAction(conflicts, () => 'Wait for the in-flight runs to complete, then retry, or use: testsprite test wait <run-id>')}${billingConflictLink(conflicts, batchApiUrl)}`,
|
|
7591
8172
|
requestId: 'local',
|
|
7592
8173
|
details: { conflicts: conflicts.map(c => c.testId) },
|
|
7593
8174
|
},
|
|
@@ -7603,6 +8184,12 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7603
8184
|
opts,
|
|
7604
8185
|
deps,
|
|
7605
8186
|
stderrFn,
|
|
8187
|
+
emptyProject: skippedFrontend.length === 0 &&
|
|
8188
|
+
skippedIntegration.length === 0 &&
|
|
8189
|
+
opts.nameFilter === undefined &&
|
|
8190
|
+
opts.statusFilter === undefined &&
|
|
8191
|
+
!explicitIds,
|
|
8192
|
+
projectId,
|
|
7606
8193
|
});
|
|
7607
8194
|
// [P2] Return post-retry state (reached only under --allow-empty).
|
|
7608
8195
|
return { ...batchResp, accepted, deferred, conflicts };
|
|
@@ -7616,12 +8203,12 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7616
8203
|
// `timeoutSeconds`. Without this, runs that wait behind `--max-concurrency`
|
|
7617
8204
|
// could push total wall-clock to ~ceil(N/concurrency) × timeout instead of
|
|
7618
8205
|
// the documented `--timeout` ceiling.
|
|
7619
|
-
// NOTE: batchDeadlineMs is set
|
|
8206
|
+
// NOTE: batchDeadlineMs is set after the dispatch above and reused here.
|
|
7620
8207
|
async function pollFreshAccepted(entry) {
|
|
7621
8208
|
const runId = entry.runId;
|
|
7622
8209
|
const remainingMs = batchDeadlineMs - Date.now();
|
|
7623
8210
|
if (remainingMs <= 0) {
|
|
7624
|
-
// §1/§4:
|
|
8211
|
+
// §1/§4: a slow fan-out can
|
|
7625
8212
|
// still land here past the deadline. Do ONE bounded poll (1s) THROUGH the
|
|
7626
8213
|
// backend wait-fallback before declaring timeout — a run that already
|
|
7627
8214
|
// reached a verdict resolves for ~one request instead of a false timeout
|
|
@@ -7659,11 +8246,22 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7659
8246
|
...(typeof finalRun.executionUrl === 'string'
|
|
7660
8247
|
? { executionUrl: finalRun.executionUrl }
|
|
7661
8248
|
: {}),
|
|
8249
|
+
...(opts.ci && finalRun.error
|
|
8250
|
+
? { error: { code: 'INTERNAL', message: finalRun.error, exitCode: 1 } }
|
|
8251
|
+
: {}),
|
|
7662
8252
|
};
|
|
7663
8253
|
}
|
|
7664
8254
|
catch (err) {
|
|
7665
8255
|
if (err instanceof InterruptError)
|
|
7666
8256
|
throw err;
|
|
8257
|
+
if (opts.ci && err instanceof ApiError) {
|
|
8258
|
+
return {
|
|
8259
|
+
testId: entry.testId,
|
|
8260
|
+
runId,
|
|
8261
|
+
status: 'error',
|
|
8262
|
+
error: { code: err.code, message: err.message, exitCode: err.exitCode },
|
|
8263
|
+
};
|
|
8264
|
+
}
|
|
7667
8265
|
if (err instanceof TimeoutError)
|
|
7668
8266
|
deps.onWaitTimeout?.({ reason: 'wait_timeout' });
|
|
7669
8267
|
// fall through to the timeout result below
|
|
@@ -7712,6 +8310,9 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7712
8310
|
...(typeof finalRun.executionUrl === 'string'
|
|
7713
8311
|
? { executionUrl: finalRun.executionUrl }
|
|
7714
8312
|
: {}),
|
|
8313
|
+
...(opts.ci && finalRun.error
|
|
8314
|
+
? { error: { code: 'INTERNAL', message: finalRun.error, exitCode: 1 } }
|
|
8315
|
+
: {}),
|
|
7715
8316
|
startedAt: finalRun.startedAt,
|
|
7716
8317
|
finishedAt: finalRun.finishedAt,
|
|
7717
8318
|
};
|
|
@@ -7821,6 +8422,8 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7821
8422
|
deferred,
|
|
7822
8423
|
skippedFrontend,
|
|
7823
8424
|
skippedIntegration,
|
|
8425
|
+
...(batchResp.integration !== undefined ? { integration: batchResp.integration } : {}),
|
|
8426
|
+
...(notRunTestIds.length > 0 ? { notRunTestIds } : {}),
|
|
7824
8427
|
summary: {
|
|
7825
8428
|
passed,
|
|
7826
8429
|
failed,
|
|
@@ -7831,17 +8434,27 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7831
8434
|
},
|
|
7832
8435
|
};
|
|
7833
8436
|
const freshNameMap = opts.report === 'junit' && opts.reportFile !== undefined
|
|
7834
|
-
?
|
|
8437
|
+
? explicitIds
|
|
8438
|
+
? await buildTestNameMapForProjects(client, [...new Set(projectOf.values())])
|
|
8439
|
+
: await buildTestNameMap(client, opts.projectId)
|
|
7835
8440
|
: undefined;
|
|
7836
|
-
const ciSummary = summarizeAcceptedPayload(JSON.stringify(
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
8441
|
+
const ciSummary = summarizeAcceptedPayload(JSON.stringify({
|
|
8442
|
+
...jsonPayload,
|
|
8443
|
+
// Never-sent ids are rows of their own, so the artifacts do not read as a complete batch.
|
|
8444
|
+
skipped: notRunTestIds.map(testId => ({
|
|
8445
|
+
testId,
|
|
8446
|
+
reason: 'not dispatched: the dispatch stopped before this test was sent',
|
|
7841
8447
|
})),
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
8448
|
+
}), { foldSkippedBuckets: explicitIds });
|
|
8449
|
+
// JUnit rows carry the poll timing the stdout envelope deliberately omits.
|
|
8450
|
+
const timedResults = freshRunResults.map(r => ({
|
|
8451
|
+
...r,
|
|
8452
|
+
...(r.runId ? reportTiming.get(r.runId) : {}),
|
|
8453
|
+
}));
|
|
8454
|
+
if (!opts.ci) {
|
|
8455
|
+
await writeBatchJUnitReportIfRequested(opts, [...timedResults, ...skippedJUnitResultsFromSummary(ciSummary, freshRunResults)], freshNameMap);
|
|
8456
|
+
out.print(jsonPayload);
|
|
8457
|
+
}
|
|
7845
8458
|
recordBatchOutcome({
|
|
7846
8459
|
accepted: accepted.length,
|
|
7847
8460
|
conflicts,
|
|
@@ -7849,6 +8462,38 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7849
8462
|
skipped: skippedFrontend.length + skippedIntegration.length,
|
|
7850
8463
|
results: freshRunResults,
|
|
7851
8464
|
});
|
|
8465
|
+
if (opts.ci) {
|
|
8466
|
+
// The report is read before the envelope prints so it lands in `--output
|
|
8467
|
+
// json`, `--summary-file` and the job summary alike.
|
|
8468
|
+
const { ready: executionReport, interrupted } = await fetchExecutionReport(client, accepted, freshRunResults, opts, deps, stderrFn);
|
|
8469
|
+
// Telemetry: the gate ran; name the execution (when the batch names exactly
|
|
8470
|
+
// one) so the event joins to the server's report, and whether that report
|
|
8471
|
+
// made it into the job summary.
|
|
8472
|
+
const gatedExecutionIds = new Set(accepted.map(a => a.executionId));
|
|
8473
|
+
const gatedExecutionId = gatedExecutionIds.size === 1 ? [...gatedExecutionIds][0] : undefined;
|
|
8474
|
+
if (accepted.length > 0) {
|
|
8475
|
+
recordTelemetryExtras({
|
|
8476
|
+
ciRunOutcome: 'gated',
|
|
8477
|
+
...(typeof gatedExecutionId === 'string' ? { executionId: gatedExecutionId } : {}),
|
|
8478
|
+
reportReady: executionReport !== undefined,
|
|
8479
|
+
});
|
|
8480
|
+
}
|
|
8481
|
+
let gateError;
|
|
8482
|
+
try {
|
|
8483
|
+
await finishCiBatch(jsonPayload, opts, deps, freshNameMap, undefined, timedResults, executionReport);
|
|
8484
|
+
}
|
|
8485
|
+
catch (err) {
|
|
8486
|
+
gateError = err;
|
|
8487
|
+
}
|
|
8488
|
+
// The summary and outputs are written either way; a signal that cut the
|
|
8489
|
+
// report wait short still ends the process with its own exit code (130/143),
|
|
8490
|
+
// never the gate's 0.
|
|
8491
|
+
if (interrupted)
|
|
8492
|
+
throw interrupted;
|
|
8493
|
+
if (gateError !== undefined)
|
|
8494
|
+
throw gateError;
|
|
8495
|
+
return { ...batchResp, accepted, deferred, conflicts, skippedFrontend, skippedIntegration };
|
|
8496
|
+
}
|
|
7852
8497
|
// CI-native output layer (issue #99): emitted before the gate throws below so
|
|
7853
8498
|
// the artifacts land even when the batch exits non-zero. The summary file is a
|
|
7854
8499
|
// machine artifact written regardless of --output mode; stdout stays owned by
|
|
@@ -7858,6 +8503,10 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7858
8503
|
stdout: deps.stdout ?? ((line) => process.stdout.write(`${line}\n`)),
|
|
7859
8504
|
stderr: stderrFn,
|
|
7860
8505
|
}, 'run');
|
|
8506
|
+
// The failed request outranks every code below (deferred 7, failed verdict 1,
|
|
8507
|
+
// credits 12, conflict 6): the runs it left behind have been awaited and reported.
|
|
8508
|
+
if (stoppedError !== undefined)
|
|
8509
|
+
throw stoppedFailure();
|
|
7861
8510
|
// Rate-deferred tests were never dispatched → the batch is incomplete (exit 7),
|
|
7862
8511
|
// mirroring `test rerun --all`. Checked before the failed-run throw so the
|
|
7863
8512
|
// operator learns to retry the deferred set.
|
|
@@ -7893,7 +8542,6 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7893
8542
|
// Pure unresumed in-flight keeps the original "already in flight and could
|
|
7894
8543
|
// not be resumed" wording; a paused-workspace refusal mixed in here isn't
|
|
7895
8544
|
// something that "could not be resumed" — it was never resumable to begin with.
|
|
7896
|
-
const ids = conflicts.map(c => c.testId).join(' ');
|
|
7897
8545
|
// This is the one CONFLICT throw where `accepted` can be non-empty (a
|
|
7898
8546
|
// mixed batch with some runs dispatched/resumed) — the advisory printed
|
|
7899
8547
|
// earlier already showed the link in that case (guarded the same way), so
|
|
@@ -7904,16 +8552,16 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7904
8552
|
code: 'CONFLICT',
|
|
7905
8553
|
message: allConflictsInFlight(conflicts)
|
|
7906
8554
|
? `${conflicts.length} test${conflicts.length !== 1 ? 's' : ''} already in flight and could not be resumed — not run.`
|
|
7907
|
-
: `${summarizeConflicts(conflicts)} — not run.`,
|
|
7908
|
-
nextAction: `Wait for the in-flight run(s) to finish, then retry: ${ids}${link}`,
|
|
8555
|
+
: `${summarizeConflicts(conflicts)} — ${conflicts.every(isProducerBlock) ? 'blocked before dispatch' : 'not run'}.`,
|
|
8556
|
+
nextAction: `${conflictNextAction(conflicts, ids => `Wait for the in-flight run(s) to finish, then retry: ${ids.join(' ')}`)}${link}`,
|
|
7909
8557
|
requestId: 'local',
|
|
7910
8558
|
details: { conflicts: conflicts.map(c => c.testId) },
|
|
7911
8559
|
},
|
|
7912
8560
|
});
|
|
7913
8561
|
}
|
|
7914
|
-
//
|
|
7915
|
-
//
|
|
7916
|
-
//
|
|
8562
|
+
// Return object reconstructed from the dispatch result (accepted, deferred,
|
|
8563
|
+
// conflicts) so the caller always sees what was actually dispatched.
|
|
8564
|
+
// accepted here still holds the original
|
|
7917
8565
|
// BatchRunFreshAccepted entries (with runId + enqueuedAt); the freshRunResults
|
|
7918
8566
|
// fan-out is for exit-code logic only and is not part of the returned type.
|
|
7919
8567
|
return { ...batchResp, accepted, deferred, conflicts };
|
|
@@ -7921,6 +8569,7 @@ export async function runTestRunAll(opts, deps = {}) {
|
|
|
7921
8569
|
/** One bounded trigger-and-wait pool shares one local tunnel for its full lifetime. */
|
|
7922
8570
|
export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
7923
8571
|
assertIdempotencyKey(opts.idempotencyKey);
|
|
8572
|
+
validateStatusSelector(opts.statusFilter);
|
|
7924
8573
|
const environment = normalizeEnvironmentName(opts.environment);
|
|
7925
8574
|
if (!Number.isInteger(opts.maxConcurrency) ||
|
|
7926
8575
|
opts.maxConcurrency < 1 ||
|
|
@@ -7941,12 +8590,27 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
7941
8590
|
const projectId = opts.all ? resolveProjectId(opts.projectId, deps) : opts.projectId;
|
|
7942
8591
|
if (opts.all)
|
|
7943
8592
|
requireProjectId(projectId);
|
|
8593
|
+
// Ids the tunnel path cannot carry (public targets, backend tests, no
|
|
8594
|
+
// loopback environment) go out as batch runs. Their tests are read at most
|
|
8595
|
+
// once here, so the batch resolver is handed what is already known.
|
|
8596
|
+
const preflightKnown = new Map();
|
|
8597
|
+
const batchRunOptions = () => ({
|
|
8598
|
+
...opts,
|
|
8599
|
+
projectId,
|
|
8600
|
+
wait: opts.wait === true,
|
|
8601
|
+
// The tunnel default (longer) only applies when a tunnel carries the runs.
|
|
8602
|
+
...(!opts.all && opts.timeoutIsDefault ? { timeoutSeconds: DEFAULT_RUN_TIMEOUT_SECONDS } : {}),
|
|
8603
|
+
environmentResolutionComplete: true,
|
|
8604
|
+
testIds: opts.all ? undefined : opts.testIds,
|
|
8605
|
+
knownTests: preflightKnown,
|
|
8606
|
+
});
|
|
7944
8607
|
if (opts.localPort === undefined &&
|
|
7945
8608
|
targetUrl !== undefined &&
|
|
7946
8609
|
!parseLoopbackTargetUrl(targetUrl)) {
|
|
7947
|
-
if (!opts.all)
|
|
7948
|
-
severalIdsWithoutTunnel();
|
|
7949
8610
|
assertNoTunnelOptions(opts);
|
|
8611
|
+
// A public --target-url needs no tunnel, so the ids go out as one batch run.
|
|
8612
|
+
if (!opts.all)
|
|
8613
|
+
return void (await runTestRunAll(batchRunOptions(), deps));
|
|
7950
8614
|
}
|
|
7951
8615
|
const dryRunTargets = new Map();
|
|
7952
8616
|
const automaticDryRun = opts.dryRun && targetUrl === undefined;
|
|
@@ -7993,7 +8657,7 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
7993
8657
|
}
|
|
7994
8658
|
if (!targets.length) {
|
|
7995
8659
|
assertNoTunnelOptions(opts);
|
|
7996
|
-
|
|
8660
|
+
return void (await runTestRunAll(batchRunOptions(), deps));
|
|
7997
8661
|
}
|
|
7998
8662
|
targetUrl = targets[0].targetUrl;
|
|
7999
8663
|
}
|
|
@@ -8011,6 +8675,7 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
8011
8675
|
tunnelClientId: opts.tunnelClientId ?? '<minted at run time>',
|
|
8012
8676
|
}),
|
|
8013
8677
|
...(opts.autoHeal === false ? { autoHeal: false } : {}),
|
|
8678
|
+
...(opts.skipDependencies ? { skipDependencies: true } : {}),
|
|
8014
8679
|
...(environment !== undefined ? { environment } : {}),
|
|
8015
8680
|
},
|
|
8016
8681
|
}));
|
|
@@ -8035,16 +8700,14 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
8035
8700
|
let tests = opts.testIds.map(id => ({ id }));
|
|
8036
8701
|
const knownTests = new Map();
|
|
8037
8702
|
if (opts.all) {
|
|
8038
|
-
const
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
:
|
|
8045
|
-
|
|
8046
|
-
if (omitted > 0)
|
|
8047
|
-
stderrFn(`--filter: skipped ${omitted} test${omitted !== 1 ? 's' : ''} whose name does not contain "${opts.nameFilter}".`);
|
|
8703
|
+
const filtered = await resolveAllProjectTests({
|
|
8704
|
+
client,
|
|
8705
|
+
projectId: projectId,
|
|
8706
|
+
statusFilter: opts.statusFilter,
|
|
8707
|
+
nameFilter: opts.nameFilter,
|
|
8708
|
+
stderr: stderrFn,
|
|
8709
|
+
latestStatus: true,
|
|
8710
|
+
});
|
|
8048
8711
|
tests = filtered.map(t => {
|
|
8049
8712
|
knownTests.set(t.id, { type: t.type, projectId: t.projectId ?? projectId });
|
|
8050
8713
|
return { id: t.id, name: t.name };
|
|
@@ -8064,6 +8727,8 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
8064
8727
|
if (opts.localPort !== undefined)
|
|
8065
8728
|
throw err;
|
|
8066
8729
|
}
|
|
8730
|
+
if (known?.projectId !== undefined)
|
|
8731
|
+
preflightKnown.set(test.id, known);
|
|
8067
8732
|
}
|
|
8068
8733
|
const target = (known?.projectId === projectId && known?.type !== 'backend'
|
|
8069
8734
|
? opts.resolvedTarget
|
|
@@ -8091,16 +8756,12 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
8091
8756
|
targets.set(test.id, target);
|
|
8092
8757
|
}
|
|
8093
8758
|
const firstTarget = targets.values().next().value;
|
|
8094
|
-
|
|
8759
|
+
// Several ids with no tunnel target at all (public environment, or backend
|
|
8760
|
+
// tests that never use one) are an ordinary batch run, skipped backend tests
|
|
8761
|
+
// included.
|
|
8762
|
+
if (!firstTarget && (!opts.all || (tests.length > 0 && skipped.length === 0))) {
|
|
8095
8763
|
assertNoTunnelOptions(opts);
|
|
8096
|
-
|
|
8097
|
-
severalIdsWithoutTunnel();
|
|
8098
|
-
return void (await runTestRunAll({
|
|
8099
|
-
...opts,
|
|
8100
|
-
projectId: projectId,
|
|
8101
|
-
wait: opts.wait === true,
|
|
8102
|
-
environmentResolutionComplete: true,
|
|
8103
|
-
}, deps));
|
|
8764
|
+
return void (await runTestRunAll(batchRunOptions(), deps));
|
|
8104
8765
|
}
|
|
8105
8766
|
if (skipped.length)
|
|
8106
8767
|
stderrFn(`[advisory] ${skipped.length} backend test(s) skipped — tunnel runs frontend tests only.`);
|
|
@@ -8219,14 +8880,28 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
8219
8880
|
if (results.length === 0) {
|
|
8220
8881
|
printResults();
|
|
8221
8882
|
await finishZeroDispatchBatch({
|
|
8222
|
-
reason: opts.nameFilter
|
|
8223
|
-
?
|
|
8883
|
+
reason: opts.nameFilter || opts.statusFilter !== undefined
|
|
8884
|
+
? `${describeRunSelectors(opts)} matched no frontend tests in project ${projectId}`
|
|
8224
8885
|
: 'no runnable frontend tests in the project',
|
|
8225
8886
|
skipped: skipped.map(s => s.testId),
|
|
8226
8887
|
allowEmpty: opts.allowEmpty,
|
|
8227
8888
|
opts,
|
|
8228
8889
|
deps,
|
|
8229
8890
|
stderrFn,
|
|
8891
|
+
// A project with only backend tests is not empty: they were skipped, not absent.
|
|
8892
|
+
emptyProject: opts.all &&
|
|
8893
|
+
skipped.length === 0 &&
|
|
8894
|
+
opts.nameFilter === undefined &&
|
|
8895
|
+
opts.statusFilter === undefined,
|
|
8896
|
+
projectId,
|
|
8897
|
+
local: {
|
|
8898
|
+
// An automatic target was resolved from a saved environment; its port
|
|
8899
|
+
// is that environment's, so the suggestion names the environment.
|
|
8900
|
+
...(opts.resolvedTarget?.automatic ? {} : { host: opts.localHost, port: opts.localPort }),
|
|
8901
|
+
targetUrl: opts.targetUrl,
|
|
8902
|
+
environment: opts.environment ??
|
|
8903
|
+
(opts.resolvedTarget?.automatic ? opts.resolvedTarget.environmentName : undefined),
|
|
8904
|
+
},
|
|
8230
8905
|
});
|
|
8231
8906
|
return;
|
|
8232
8907
|
}
|
|
@@ -8255,6 +8930,7 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
8255
8930
|
// Trigger requests are uninterruptible (the server may already have charged
|
|
8256
8931
|
// the run), so an abort waits for them before cancelling and closing.
|
|
8257
8932
|
const pendingTriggers = new Set();
|
|
8933
|
+
let skipDependenciesUnconfirmedShown = false;
|
|
8258
8934
|
const ticker = createTicker(stderrFn, opts.output === 'json' ? false : undefined);
|
|
8259
8935
|
const setAbort = (reason, lost) => {
|
|
8260
8936
|
if (abortReason === undefined) {
|
|
@@ -8329,6 +9005,7 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
8329
9005
|
}
|
|
8330
9006
|
: {}),
|
|
8331
9007
|
...(opts.autoHeal === false ? { autoHeal: false } : {}),
|
|
9008
|
+
...(opts.skipDependencies ? { skipDependencies: true } : {}),
|
|
8332
9009
|
...(environment !== undefined ? { environment } : {}),
|
|
8333
9010
|
}, { idempotencyKey: key }));
|
|
8334
9011
|
pendingTriggers.add(triggering);
|
|
@@ -8338,6 +9015,12 @@ export async function runTestRunLocalBatch(opts, deps = {}) {
|
|
|
8338
9015
|
finally {
|
|
8339
9016
|
pendingTriggers.delete(triggering);
|
|
8340
9017
|
}
|
|
9018
|
+
if (opts.skipDependencies &&
|
|
9019
|
+
response.skipDependencies !== true &&
|
|
9020
|
+
!skipDependenciesUnconfirmedShown) {
|
|
9021
|
+
skipDependenciesUnconfirmedShown = true;
|
|
9022
|
+
stderrFn('[advisory] This backend did not confirm --skip-dependencies, so the runs may also include the test cases they depend on, as a Portal run does.');
|
|
9023
|
+
}
|
|
8341
9024
|
row.runId = response.runId;
|
|
8342
9025
|
row.status = 'running';
|
|
8343
9026
|
activeRows.add(index);
|
|
@@ -8699,6 +9382,7 @@ function validateRerunOptions(opts) {
|
|
|
8699
9382
|
throw localValidationError('status', '--status only applies with --all (it narrows which project tests get reran). ' +
|
|
8700
9383
|
'Remove --status, or add --all --project <id>.');
|
|
8701
9384
|
}
|
|
9385
|
+
assertStatusSelectorNotEmpty(opts.statusFilter);
|
|
8702
9386
|
if (opts.skipTerminal && !opts.all) {
|
|
8703
9387
|
throw localValidationError('skip-terminal', '--skip-terminal only applies with --all (it narrows which project tests get reran). ' +
|
|
8704
9388
|
'Remove --skip-terminal, or add --all --project <id>.');
|
|
@@ -9466,47 +10150,16 @@ async function runTestRerunCore(opts, deps = {}) {
|
|
|
9466
10150
|
if (opts.statusFilter !== undefined) {
|
|
9467
10151
|
validateStatusFilter(opts.statusFilter);
|
|
9468
10152
|
}
|
|
9469
|
-
//
|
|
9470
|
-
//
|
|
9471
|
-
const
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
allTests = allTests.filter(t => !TERMINAL_PUBLIC_STATUSES.has(t.status));
|
|
9480
|
-
const skipped = before - allTests.length;
|
|
9481
|
-
if (skipped > 0) {
|
|
9482
|
-
stderrFn(`--skip-terminal: skipped ${skipped} already-terminal test${skipped !== 1 ? 's' : ''} (passed|failed|blocked|cancelled).`);
|
|
9483
|
-
}
|
|
9484
|
-
}
|
|
9485
|
-
// --status <list>: only dispatch tests whose status matches one of the
|
|
9486
|
-
// listed values. Tokens are already validated above.
|
|
9487
|
-
if (opts.statusFilter !== undefined && opts.statusFilter !== '') {
|
|
9488
|
-
const allowed = new Set(opts.statusFilter
|
|
9489
|
-
.split(',')
|
|
9490
|
-
.map(s => s.trim())
|
|
9491
|
-
.filter(s => s.length > 0));
|
|
9492
|
-
const before = allTests.length;
|
|
9493
|
-
allTests = allTests.filter(t => allowed.has(t.status));
|
|
9494
|
-
const skipped = before - allTests.length;
|
|
9495
|
-
if (skipped > 0) {
|
|
9496
|
-
stderrFn(`--status filter: skipped ${skipped} test${skipped !== 1 ? 's' : ''} not matching status=${opts.statusFilter}.`);
|
|
9497
|
-
}
|
|
9498
|
-
}
|
|
9499
|
-
// --filter <substr>: only dispatch tests whose name contains the
|
|
9500
|
-
// substring (case-insensitive). Applied after --skip-terminal and --status.
|
|
9501
|
-
if (opts.nameFilter !== undefined && opts.nameFilter !== '') {
|
|
9502
|
-
const needle = opts.nameFilter.toLowerCase();
|
|
9503
|
-
const before = allTests.length;
|
|
9504
|
-
allTests = allTests.filter(t => t.name.toLowerCase().includes(needle));
|
|
9505
|
-
const skipped = before - allTests.length;
|
|
9506
|
-
if (skipped > 0) {
|
|
9507
|
-
stderrFn(`--filter: skipped ${skipped} test${skipped !== 1 ? 's' : ''} whose name does not contain "${opts.nameFilter}".`);
|
|
9508
|
-
}
|
|
9509
|
-
}
|
|
10153
|
+
// Follows nextToken until exhausted so projects with >1 service page
|
|
10154
|
+
// (>25 tests) are fully covered.
|
|
10155
|
+
const allTests = await resolveAllProjectTests({
|
|
10156
|
+
client,
|
|
10157
|
+
projectId: opts.projectId,
|
|
10158
|
+
statusFilter: opts.statusFilter,
|
|
10159
|
+
skipTerminal: opts.skipTerminal,
|
|
10160
|
+
nameFilter: opts.nameFilter,
|
|
10161
|
+
stderr: stderrFn,
|
|
10162
|
+
});
|
|
9510
10163
|
testIds = allTests.map(t => t.id);
|
|
9511
10164
|
knownTests = new Map(allTests.map(t => [t.id, { type: t.type, projectId: t.projectId ?? opts.projectId }]));
|
|
9512
10165
|
if (testIds.length === 0) {
|
|
@@ -9653,20 +10306,11 @@ async function runTestRerunCore(opts, deps = {}) {
|
|
|
9653
10306
|
advisories: dedupeRerunAdvisories(chunkResponses.flatMap(r => r.advisories ?? [])),
|
|
9654
10307
|
};
|
|
9655
10308
|
// Print dispatch summary
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
let deferred = batchResp.deferred.slice();
|
|
9662
|
-
let conflicts = batchResp.conflicts.slice();
|
|
9663
|
-
// [P2] `notFound` is mutable: a deferred test may become un-replayable during
|
|
9664
|
-
// the retry window; the retry response's notFound[] is merged into this set so
|
|
9665
|
-
// the test is never reported as "resolved" when it actually vanished.
|
|
9666
|
-
let notFound = (batchResp.notFound ?? []).slice();
|
|
9667
|
-
// Mutable so a D3 deferred-retry response can contribute an
|
|
9668
|
-
// advisory the initial dispatch didn't carry (defensive; see comment above).
|
|
9669
|
-
let advisories = (batchResp.advisories ?? []).slice();
|
|
10309
|
+
const accepted = batchResp.accepted.slice();
|
|
10310
|
+
const deferred = batchResp.deferred.slice();
|
|
10311
|
+
const conflicts = batchResp.conflicts.slice();
|
|
10312
|
+
const notFound = (batchResp.notFound ?? []).slice();
|
|
10313
|
+
const advisories = (batchResp.advisories ?? []).slice();
|
|
9670
10314
|
const closureByProject = batchResp.closure.byProject;
|
|
9671
10315
|
const addedProducersTotal = closureByProject.reduce((n, p) => n + p.addedProducers.length, 0);
|
|
9672
10316
|
const summaryParts = [
|
|
@@ -9701,180 +10345,9 @@ async function runTestRerunCore(opts, deps = {}) {
|
|
|
9701
10345
|
const deferredIds = deferred.map(d => d.testId).join(' ');
|
|
9702
10346
|
stderrFn(`nextAction: testsprite test rerun ${deferredIds}`);
|
|
9703
10347
|
}
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
return;
|
|
9707
|
-
const retried = new Set(responses
|
|
9708
|
-
.flatMap(response => [...response.accepted, ...response.conflicts, ...response.deferred])
|
|
9709
|
-
.map(row => row.testId));
|
|
9710
|
-
await emitEnvironmentDispatchPartial([
|
|
9711
|
-
{
|
|
9712
|
-
accepted,
|
|
9713
|
-
conflicts,
|
|
9714
|
-
deferred: deferred.filter(row => !retried.has(row.testId)),
|
|
9715
|
-
notFound,
|
|
9716
|
-
},
|
|
9717
|
-
...responses,
|
|
9718
|
-
], testIds, opts, deps, 'rerun', error, deps.environmentTunnel);
|
|
9719
|
-
};
|
|
9720
|
-
// D3: budget-driven deferred-retry loop for rerun --all (only under --wait).
|
|
9721
|
-
// Re-dispatches still-deferred tests until they all clear OR the --timeout
|
|
9722
|
-
// budget is exhausted — a busy pool drains within the user's own timeout
|
|
9723
|
-
// instead of giving up after a fixed few tries and failing the run. Each
|
|
9724
|
-
// attempt sleeps 61s (clamped to the remaining budget); newly-accepted runs
|
|
9725
|
-
// merge into `accepted`; if still deferred when the budget runs out, fall
|
|
9726
|
-
// through to the existing exit-7 path. `maxDeferredAttempts` is a pure runaway
|
|
9727
|
-
// backstop (the deadline check below is the real stop), scaled to the timeout.
|
|
9728
|
-
const sleepFn = deps.sleep ?? ((ms) => new Promise(r => setTimeout(r, ms)));
|
|
10348
|
+
// A deferred id (rare: a busy project lock or a case that went in flight) was
|
|
10349
|
+
// not dispatched and is not resent: it is reported below and exits 7.
|
|
9729
10350
|
const batchDeadlineMs = deps.environmentTunnel?.deadlineMs ?? Date.now() + opts.timeoutSeconds * 1000;
|
|
9730
|
-
// finding 1: reserve a poll window so the deferred-retry loop can't consume the
|
|
9731
|
-
// ENTIRE --timeout and leave the fan-out poll with nothing — which would report
|
|
9732
|
-
// already-finished runs as timeouts (exit 7) instead of their real verdicts
|
|
9733
|
-
// (a genuine failure is exit 1, not 7). One third of the budget, capped at 60s.
|
|
9734
|
-
const POLL_RESERVE_MS = Math.min(60_000, Math.floor((opts.timeoutSeconds * 1000) / 3));
|
|
9735
|
-
const maxDeferredAttempts = Math.max(MAX_DEFERRED_RETRIES, Math.ceil(opts.timeoutSeconds / 60) + 2);
|
|
9736
|
-
if (opts.wait) {
|
|
9737
|
-
for (let attempt = 1; attempt <= maxDeferredAttempts && deferred.length > 0; attempt++) {
|
|
9738
|
-
const remainingMs = batchDeadlineMs - Date.now();
|
|
9739
|
-
if (remainingMs <= POLL_RESERVE_MS) {
|
|
9740
|
-
stderrFn(`[deferred-retry] reserving the remaining budget to poll dispatched runs — ${deferred.length} test${deferred.length !== 1 ? 's' : ''} still deferred.`);
|
|
9741
|
-
break;
|
|
9742
|
-
}
|
|
9743
|
-
// §1: clamp to what's left ABOVE the reserve so the sleep itself can't run
|
|
9744
|
-
// the budget to zero (the loop only reaches here when remainingMs >
|
|
9745
|
-
// POLL_RESERVE_MS, so the difference is always positive).
|
|
9746
|
-
const sleepMs = Math.min(DEFERRED_RETRY_DEFAULT_SLEEP_MS, remainingMs - POLL_RESERVE_MS);
|
|
9747
|
-
stderrFn(`[deferred-retry] attempt ${attempt} — retrying ${deferred.length} deferred test${deferred.length !== 1 ? 's' : ''} in ${Math.round(sleepMs / 1000)}s`);
|
|
9748
|
-
try {
|
|
9749
|
-
if (deps.environmentTunnel)
|
|
9750
|
-
await sleepUntilOrInterrupt(sleepMs, shutdownOf(deps).signal, sleepFn);
|
|
9751
|
-
else
|
|
9752
|
-
await sleepFn(sleepMs);
|
|
9753
|
-
}
|
|
9754
|
-
catch (err) {
|
|
9755
|
-
await emitRetryPartial(err);
|
|
9756
|
-
throw err;
|
|
9757
|
-
}
|
|
9758
|
-
const remainingAfterSleep = batchDeadlineMs - Date.now();
|
|
9759
|
-
if (remainingAfterSleep <= POLL_RESERVE_MS) {
|
|
9760
|
-
stderrFn(`[deferred-retry] reserving the remaining budget to poll dispatched runs — ${deferred.length} test${deferred.length !== 1 ? 's' : ''} still deferred.`);
|
|
9761
|
-
break;
|
|
9762
|
-
}
|
|
9763
|
-
// Chunk the retry ids to stay within MAX_BATCH_RERUN_IDS cap.
|
|
9764
|
-
const retryIds = deferred.map(d => d.testId);
|
|
9765
|
-
const retryChunks = [];
|
|
9766
|
-
for (let i = 0; i < retryIds.length; i += MAX_BATCH_RERUN_IDS) {
|
|
9767
|
-
retryChunks.push(retryIds.slice(i, i + MAX_BATCH_RERUN_IDS));
|
|
9768
|
-
}
|
|
9769
|
-
if (deps.environmentTunnel?.targets) {
|
|
9770
|
-
const grouped = retryChunks.flatMap(chunk => groupEnvironmentTargets(chunk, deps.environmentTunnel.targets, deps.environmentTunnel.maxConcurrency));
|
|
9771
|
-
retryChunks.splice(0, retryChunks.length, ...grouped);
|
|
9772
|
-
}
|
|
9773
|
-
const retryChunkResponses = [];
|
|
9774
|
-
try {
|
|
9775
|
-
// Sequential, same reason as the initial dispatch above: concurrent
|
|
9776
|
-
// chunks racing on per-request server-side closure dedup can
|
|
9777
|
-
// double-trigger a shared BE producer/teardown.
|
|
9778
|
-
for (let idx = 0; idx < retryChunks.length; idx++) {
|
|
9779
|
-
const chunk = retryChunks[idx];
|
|
9780
|
-
// [P2] Bound the derived key to ≤256 chars. Caller-supplied keys may
|
|
9781
|
-
// be up to 256 chars; appending the suffix could exceed the server
|
|
9782
|
-
// limit and cause every retry to be rejected. Truncate the base key
|
|
9783
|
-
// to leave room for the longest possible suffix before concatenating.
|
|
9784
|
-
const retrySuffix = retryChunks.length === 1
|
|
9785
|
-
? `:deferred-retry${attempt}`
|
|
9786
|
-
: `:deferred-retry${attempt}:chunk${idx}`;
|
|
9787
|
-
const retryBase = idempotencyKey.length + retrySuffix.length > 256
|
|
9788
|
-
? idempotencyKey.slice(0, 256 - retrySuffix.length)
|
|
9789
|
-
: idempotencyKey;
|
|
9790
|
-
const retryKey = `${retryBase}${retrySuffix}`;
|
|
9791
|
-
// The retry chunk POST is deliberately NOT bound to the batch
|
|
9792
|
-
// deadline via an AbortSignal — same reasoning as the fresh-run retry
|
|
9793
|
-
// above: it seeds runs, so a mid-flight abort would leave the server
|
|
9794
|
-
// possibly having dispatched while this loop reports the chunk as
|
|
9795
|
-
// still-deferred, inviting a duplicate rerun on the user's next
|
|
9796
|
-
// invocation. The per-request timeout still bounds it; the sleeps +
|
|
9797
|
-
// poll stay deadline-aware.
|
|
9798
|
-
if (deps.environmentTunnel?.targets?.has(chunk[0]))
|
|
9799
|
-
await deps.environmentTunnel.waitForCapacity(chunk.length);
|
|
9800
|
-
const retryChunkResp = await client.triggerBatchRerun({
|
|
9801
|
-
source: 'cli',
|
|
9802
|
-
testIds: chunk,
|
|
9803
|
-
...(environment !== undefined ? { environment } : {}),
|
|
9804
|
-
...(deps.environmentTunnel?.targets?.has(chunk[0])
|
|
9805
|
-
? {
|
|
9806
|
-
tunnelClientId: deps.environmentTunnel.clientId,
|
|
9807
|
-
targetUrl: deps.environmentTunnel.targets.get(chunk[0]).targetUrl,
|
|
9808
|
-
}
|
|
9809
|
-
: {}),
|
|
9810
|
-
// Always send the effective boolean, including an explicit
|
|
9811
|
-
// `false` opt-out — see the matching comment on the initial
|
|
9812
|
-
// dispatch call site above.
|
|
9813
|
-
autoHeal: effectiveAutoHeal,
|
|
9814
|
-
...(opts.skipDependencies ? { skipDependencies: true } : {}),
|
|
9815
|
-
}, { idempotencyKey: retryKey });
|
|
9816
|
-
retryChunkResponses.push(retryChunkResp);
|
|
9817
|
-
if (deps.environmentTunnel?.targets?.has(chunk[0]))
|
|
9818
|
-
await deps.environmentTunnel.confirm(retryChunkResp, retryChunkResp.accepted.map(row => row.runId));
|
|
9819
|
-
}
|
|
9820
|
-
}
|
|
9821
|
-
catch (err) {
|
|
9822
|
-
if (deps.environmentTunnel) {
|
|
9823
|
-
await emitRetryPartial(err, retryChunkResponses);
|
|
9824
|
-
throw err;
|
|
9825
|
-
}
|
|
9826
|
-
if (err instanceof InterruptError)
|
|
9827
|
-
throw err;
|
|
9828
|
-
stderrFn(`[deferred-retry] attempt ${attempt} failed with error: ${err instanceof Error ? err.message : String(err)}`);
|
|
9829
|
-
break;
|
|
9830
|
-
}
|
|
9831
|
-
const { deduped: newlyAccepted, dropped: newlyDuplicate } = dedupeBatchRerunAccepted(retryChunkResponses.flatMap(r => r.accepted));
|
|
9832
|
-
const newlyDeferred = retryChunkResponses.flatMap(r => r.deferred);
|
|
9833
|
-
const newlyConflicted = retryChunkResponses.flatMap(r => r.conflicts);
|
|
9834
|
-
// [P2] Collect notFound[] from the retry response. A deferred test may be
|
|
9835
|
-
// un-replayable by the time we retry (e.g. the test was deleted). Merge
|
|
9836
|
-
// into the running notFound set and remove from deferred so it isn't
|
|
9837
|
-
// reported as "resolved" in the final output.
|
|
9838
|
-
const newlyNotFound = retryChunkResponses.flatMap(r => r.notFound ?? []);
|
|
9839
|
-
// Merge any advisories the retry response carries into the
|
|
9840
|
-
// running set (deduped — see the initial-dispatch comment above).
|
|
9841
|
-
const newlyAdvisories = retryChunkResponses.flatMap(r => r.advisories ?? []);
|
|
9842
|
-
if (newlyAdvisories.length > 0) {
|
|
9843
|
-
advisories = dedupeRerunAdvisories(advisories.concat(newlyAdvisories));
|
|
9844
|
-
}
|
|
9845
|
-
warnDroppedDuplicateRuns(newlyAccepted, newlyDuplicate, stderrFn);
|
|
9846
|
-
if (newlyAccepted.length > 0) {
|
|
9847
|
-
stderrFn(`[deferred-retry] attempt ${attempt}: ${newlyAccepted.length} test${newlyAccepted.length !== 1 ? 's' : ''} now accepted.`);
|
|
9848
|
-
// A retry asks only for the still-deferred ids but can come back with
|
|
9849
|
-
// a test an earlier attempt already ran; the extra run is reported.
|
|
9850
|
-
const { deduped: mergedAccepted, dropped: droppedAcrossAttempts } = dedupeBatchRerunAccepted(accepted.concat(newlyAccepted));
|
|
9851
|
-
accepted = mergedAccepted;
|
|
9852
|
-
warnDroppedDuplicateRuns(accepted, droppedAcrossAttempts, stderrFn);
|
|
9853
|
-
}
|
|
9854
|
-
if (newlyConflicted.length > 0) {
|
|
9855
|
-
// [P1] Merge retry-returned conflicts into the running conflicts collection
|
|
9856
|
-
// so the final summary, stderr output, and exit-code logic reflect them.
|
|
9857
|
-
stderrFn(`[deferred-retry] attempt ${attempt}: ${newlyConflicted.length} test${newlyConflicted.length !== 1 ? 's' : ''} in-flight (conflict).`);
|
|
9858
|
-
conflicts = conflicts.concat(newlyConflicted);
|
|
9859
|
-
}
|
|
9860
|
-
if (newlyNotFound.length > 0) {
|
|
9861
|
-
// [P2] Merge retry-discovered notFound ids and warn so the operator knows
|
|
9862
|
-
// which tests vanished. Remove the now-un-replayable ids from `deferred`
|
|
9863
|
-
// (newlyDeferred is the authoritative post-retry deferred set — it won't
|
|
9864
|
-
// include these ids — but be explicit so the logic is clear).
|
|
9865
|
-
stderrFn(`[deferred-retry] attempt ${attempt}: ${newlyNotFound.length} test id${newlyNotFound.length !== 1 ? 's' : ''} not found on retry (deleted or never ran cleanly): ${newlyNotFound.join(' ')}`);
|
|
9866
|
-
notFound = notFound.concat(newlyNotFound);
|
|
9867
|
-
// Warn via the standard notFound stderr block (mirrors the initial dispatch).
|
|
9868
|
-
for (const id of newlyNotFound)
|
|
9869
|
-
stderrFn(` ${id}`);
|
|
9870
|
-
stderrFn(` Skipped ids have no replayable run. Use 'testsprite test run <id>' for a first (fresh) run.`);
|
|
9871
|
-
}
|
|
9872
|
-
deferred = newlyDeferred;
|
|
9873
|
-
if (deferred.length === 0) {
|
|
9874
|
-
stderrFn(`[deferred-retry] attempt ${attempt}: all previously-deferred tests accepted.`);
|
|
9875
|
-
}
|
|
9876
|
-
}
|
|
9877
|
-
}
|
|
9878
10351
|
/**
|
|
9879
10352
|
* Every requested id landed in `notFound` and nothing was queued. A rerun
|
|
9880
10353
|
* where every id was unusable is not a success: exit 4 (NOT_FOUND), the same
|
|
@@ -9894,8 +10367,6 @@ async function runTestRerunCore(opts, deps = {}) {
|
|
|
9894
10367
|
// had a chance to contribute one, not once per chunk/attempt.
|
|
9895
10368
|
emitRerunAdvisories(stderrFn, advisories);
|
|
9896
10369
|
if (!opts.wait) {
|
|
9897
|
-
// [P2] Build output from post-retry mutable state so deferred/conflicts/notFound
|
|
9898
|
-
// reflect what the D3 loop discovered, not just the initial batchResp.
|
|
9899
10370
|
out.print({ ...batchResp, accepted, deferred, conflicts, notFound, advisories });
|
|
9900
10371
|
if (deferred.length > 0) {
|
|
9901
10372
|
throw new CLIError(`Batch rerun incomplete: ${deferred.length} test${deferred.length !== 1 ? 's' : ''} were rate-deferred. Retry with: testsprite test rerun ${deferred.map(d => d.testId).join(' ')}`, 7);
|
|
@@ -9999,7 +10470,6 @@ async function runTestRerunCore(opts, deps = {}) {
|
|
|
9999
10470
|
const concurrencyLimit = opts.maxConcurrency;
|
|
10000
10471
|
const rerunResults = [];
|
|
10001
10472
|
const reportTiming = new Map();
|
|
10002
|
-
// sleepFn is declared above in the D3 deferred-retry section (shared by fan-out).
|
|
10003
10473
|
async function pollAccepted(entry) {
|
|
10004
10474
|
const resolveAlternate = makeBackendWaitFallback({
|
|
10005
10475
|
client,
|
|
@@ -10434,13 +10904,11 @@ function renderArtifactGetWrittenText(data) {
|
|
|
10434
10904
|
* test, so the probe is a heuristic, not a guarantee — hence the full
|
|
10435
10905
|
* opt-out.
|
|
10436
10906
|
*/
|
|
10437
|
-
const SKIP_PREFLIGHT_HELP = 'skip the pre-charge reachability probe
|
|
10438
|
-
'
|
|
10439
|
-
|
|
10440
|
-
'calls when set.';
|
|
10441
|
-
const TARGET_URL_HELP = "frontend tests only: use the environment already pointing at this URL's origin, or a temporary one TestSprite deletes when the run finishes; with --env, use its settings against this URL; loopback URLs open a tunnel automatically";
|
|
10907
|
+
const SKIP_PREFLIGHT_HELP = 'skip the pre-charge reachability probe of the target URL (it runs from this machine, not the ' +
|
|
10908
|
+
'cloud, so it can be wrong, e.g. behind an IP allowlist)';
|
|
10909
|
+
const TARGET_URL_HELP = "frontend tests only: run against this URL, using the environment for its origin (else a temporary one deleted after the run); with --env, that environment's settings; loopback URLs open a tunnel";
|
|
10442
10910
|
export function createTestCommand(deps = {}) {
|
|
10443
|
-
const test = new Command('test').description('
|
|
10911
|
+
const test = new Command('test').description('Create, run and inspect tests');
|
|
10444
10912
|
test
|
|
10445
10913
|
.command('list')
|
|
10446
10914
|
.description('List tests in a project')
|
|
@@ -10450,12 +10918,12 @@ export function createTestCommand(deps = {}) {
|
|
|
10450
10918
|
// the CLI error spec §2 ("missing required field"). `requireProjectId`
|
|
10451
10919
|
// below raises `ApiError(VALIDATION_ERROR)` so JSON consumers can read
|
|
10452
10920
|
// `error.code` and the exit code matches the catalog.
|
|
10453
|
-
.option('--project <id>', 'project id (
|
|
10921
|
+
.option('--project <id>', 'project id (required unless TESTSPRITE_PROJECT_ID is set)')
|
|
10454
10922
|
.option('--env <name>', 'show frontend test statuses for the named project environment')
|
|
10455
10923
|
.option('--type <type>', 'filter by test type (frontend|backend)')
|
|
10456
10924
|
.option('--created-from <source>', 'filter by where the test was authored (portal|mcp|cli)')
|
|
10457
|
-
.option('--status <list>',
|
|
10458
|
-
.option('--page-size <n>', '
|
|
10925
|
+
.option('--status <list>', `filter by the status of each test case's latest result (comma-separated; accepted: ${RUN_STATUS_VALUES.join('|')}; not_run = never ran)`)
|
|
10926
|
+
.option('--page-size <n>', 'fetch ONE page of N items (1-100) and print the next token (default: follow every page; --max-items caps that)')
|
|
10459
10927
|
.option('--starting-token <token>', 'opaque cursor from a previous list response')
|
|
10460
10928
|
.option('--cursor <token>', 'alias for --starting-token; accepted for parity with `test result --history`')
|
|
10461
10929
|
.option('--max-items <n>', 'stop after this many items across auto-paged pages')
|
|
@@ -10494,34 +10962,30 @@ export function createTestCommand(deps = {}) {
|
|
|
10494
10962
|
});
|
|
10495
10963
|
test
|
|
10496
10964
|
.command('create')
|
|
10965
|
+
.summary('Create a test from code (--code-file) or a plan (--plan-from)')
|
|
10497
10966
|
.description('Create a test from saved code (--code-file) or an agent-supplied plan (--plan-from, FE-only)')
|
|
10498
|
-
.option('--project <id>', 'project id (
|
|
10967
|
+
.option('--project <id>', 'project id (see `testsprite project list`)')
|
|
10499
10968
|
.option('--type <type>', 'frontend|backend')
|
|
10500
|
-
.option('--name <name>', 'human-readable test name
|
|
10969
|
+
.option('--name <name>', 'human-readable test name')
|
|
10501
10970
|
.option('--description <text>', 'optional human description (≤ 2000 chars)')
|
|
10502
|
-
.option('--priority <prio>', 'optional priority
|
|
10503
|
-
.option('--step-timeout <ms>', 'per-test step timeout in milliseconds (1-60000)
|
|
10971
|
+
.option('--priority <prio>', 'optional priority: p0/high, p1/medium, p2/low (p3 = low)')
|
|
10972
|
+
.option('--step-timeout <ms>', 'per-test step timeout in milliseconds (1-60000)')
|
|
10504
10973
|
.option('--code-file <path>', 'file containing the test code (≤ 350 KB)')
|
|
10505
|
-
.option('--plan-from <path>', 'JSON file with the full FE test definition
|
|
10506
|
-
'
|
|
10507
|
-
.option('--plan-template', 'print a
|
|
10508
|
-
'
|
|
10509
|
-
.option('--run', 'after create, trigger the test. Combine with --wait to block until terminal.', false)
|
|
10974
|
+
.option('--plan-from <path>', 'JSON file with the full FE test definition (≤ 256 KB; excludes --code-file); ' +
|
|
10975
|
+
'--project/--type/--name/--description/--priority/--step-timeout are ignored')
|
|
10976
|
+
.option('--plan-template', 'print a plan-file skeleton to stdout and exit (local; ignores every other flag)', false)
|
|
10977
|
+
.option('--run', 'after create, trigger the test', false)
|
|
10510
10978
|
.option('--wait', 'with --run, poll until terminal status', false)
|
|
10511
|
-
.option('--no-wait', 'detach
|
|
10512
|
-
.option('--timeout <s>', 'with --run --wait, max seconds to wait')
|
|
10979
|
+
.option('--no-wait', 'with --run, detach: no waiting and no automatic tunnel (a loopback target is unreachable from the cloud)')
|
|
10980
|
+
.option('--timeout <s>', 'with --run --wait, max seconds to wait (1-3600; default 600, or 1200 through a tunnel)')
|
|
10513
10981
|
.option('--target-url <url>', TARGET_URL_HELP)
|
|
10514
10982
|
.option('--env <name>', 'with --run, select the named project environment; loopback URLs open a tunnel automatically')
|
|
10515
10983
|
.option('--skip-preflight', SKIP_PREFLIGHT_HELP, false)
|
|
10516
|
-
.option('--idempotency-key <token>', '
|
|
10517
|
-
.option('--produces <var>', 'BE only: variable
|
|
10518
|
-
.option('--needs <var>', 'BE only: variable
|
|
10519
|
-
.option('--category <str>', "BE only: test category
|
|
10984
|
+
.option('--idempotency-key <token>', 'idempotency token (1-256 ASCII chars; default: random UUID per invocation, pin one for safe retries)')
|
|
10985
|
+
.option('--produces <var>', 'BE only: variable this test captures (repeatable); orders waves in `test run --all`', (val, prev) => [...(prev ?? []), val], [])
|
|
10986
|
+
.option('--needs <var>', 'BE only: variable this test consumes (repeatable); declares the upstream producer', (val, prev) => [...(prev ?? []), val], [])
|
|
10987
|
+
.option('--category <str>', "BE only: test category; 'teardown' or 'cleanup' marks a final-wave cleanup test (BE-only flags with --type frontend exit 5)")
|
|
10520
10988
|
.addHelpText('after', PLAN_TEMPLATE_HELP_TEXT)
|
|
10521
|
-
.addHelpText('after', '\nBE dependency authoring:\n' +
|
|
10522
|
-
' --produces/--needs drive wave ordering on `test rerun` + `test run --all`.\n' +
|
|
10523
|
-
' --category teardown marks a final-wave cleanup test.\n' +
|
|
10524
|
-
' These flags are backend-only; supplying with --type frontend is an error (exit 5).')
|
|
10525
10989
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10526
10990
|
.action(async (cmdOpts, command) => {
|
|
10527
10991
|
if (cmdOpts.env !== undefined && cmdOpts.run !== true) {
|
|
@@ -10596,7 +11060,7 @@ export function createTestCommand(deps = {}) {
|
|
|
10596
11060
|
type: parseEnumFlag(cmdOpts.type, 'type', TEST_TYPES),
|
|
10597
11061
|
name: cmdOpts.name,
|
|
10598
11062
|
description: cmdOpts.description,
|
|
10599
|
-
priority:
|
|
11063
|
+
priority: parsePriorityFlag(cmdOpts.priority),
|
|
10600
11064
|
stepTimeoutMs: parseStepTimeoutFlag(cmdOpts.stepTimeout, 'step-timeout'),
|
|
10601
11065
|
codeFile: cmdOpts.codeFile,
|
|
10602
11066
|
idempotencyKey: cmdOpts.idempotencyKey,
|
|
@@ -10620,19 +11084,23 @@ export function createTestCommand(deps = {}) {
|
|
|
10620
11084
|
});
|
|
10621
11085
|
test
|
|
10622
11086
|
.command('create-batch')
|
|
10623
|
-
.
|
|
11087
|
+
.summary('Create multiple FE tests from JSONL plan specs')
|
|
11088
|
+
.description('Create multiple FE tests from a JSONL of plan specs (FE-only).\n' +
|
|
11089
|
+
'Each JSONL line (or --plan-from-dir file) is a `test create --plan-from` plan; see `test scaffold`.')
|
|
10624
11090
|
.option('--plans <path>', 'JSONL file with one plan-from spec per line (≤ 50 specs, ≤ 5 MB)')
|
|
10625
11091
|
.option('--plan-from-dir <dir>', 'directory of *.json plan files — each file is one plan spec (≤ 50 files, ≤ 5 MB total). Sorted by filename for determinism. Mutually exclusive with --plans.')
|
|
10626
11092
|
.option('--run', 'after create, trigger each created test as a run', false)
|
|
10627
|
-
.option('--max-concurrency <n>', 'with --run
|
|
10628
|
-
|
|
11093
|
+
.option('--max-concurrency <n>', 'with --run: max in-flight triggers (1-100, default 50; through a tunnel 1-10, default 5). ' +
|
|
11094
|
+
'Triggers are throttled to 50/min (server cap 60/min/key) and retried on rate limits. ' +
|
|
11095
|
+
'With --wait a slot is held until each run finishes; without --wait this only paces dispatch. Runs beyond what the account executes at once queue on the server.')
|
|
10629
11096
|
.option('--wait', 'with --run, poll each run until terminal status', false)
|
|
10630
11097
|
.option('--no-wait', 'detach without opening an automatic environment tunnel')
|
|
10631
11098
|
.option('--timeout <s>', 'with --run --wait, per-run max seconds to wait (1-3600, default 600)')
|
|
10632
|
-
.option('--target-url <url>', TARGET_URL_HELP)
|
|
10633
|
-
.option('--env <name>', 'with --run,
|
|
10634
|
-
.option('--skip-preflight', SKIP_PREFLIGHT_HELP
|
|
10635
|
-
.option('--idempotency-key <token>', '
|
|
11099
|
+
.option('--target-url <url>', `with --run: ${TARGET_URL_HELP}`)
|
|
11100
|
+
.option('--env <name>', 'with --run, run each test in the named project environment; loopback URLs open a tunnel')
|
|
11101
|
+
.option('--skip-preflight', `with --run: ${SKIP_PREFLIGHT_HELP}`, false)
|
|
11102
|
+
.option('--idempotency-key <token>', 'idempotency token for the batch (1-256 ASCII chars; default: random UUID, pin one for safe retries)')
|
|
11103
|
+
.addHelpText('after', '\nExample:\n testsprite test create-batch --plans plans.jsonl --run --wait')
|
|
10636
11104
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10637
11105
|
.action(async (cmdOpts, command) => {
|
|
10638
11106
|
await runCreateBatch({
|
|
@@ -10652,14 +11120,15 @@ export function createTestCommand(deps = {}) {
|
|
|
10652
11120
|
});
|
|
10653
11121
|
test
|
|
10654
11122
|
.command('scaffold')
|
|
10655
|
-
.
|
|
11123
|
+
.summary('Emit a starter FE plan or BE skeleton (local)')
|
|
11124
|
+
.description('Emit a starter test definition (frontend plan JSON by default, or a backend Python skeleton). Local: no network or credentials.\n' +
|
|
11125
|
+
"The plan's projectId comes from TESTSPRITE_PROJECT_ID if set, else a placeholder to replace.")
|
|
10656
11126
|
.option('--type <type>', 'frontend|backend (default: frontend)')
|
|
10657
11127
|
.option('--out <path>', 'write the scaffold to a file instead of stdout')
|
|
10658
11128
|
.option('--force', 'overwrite an existing --out file', false)
|
|
10659
11129
|
.addHelpText('after', '\nExamples:\n' +
|
|
10660
|
-
' testsprite test scaffold
|
|
10661
|
-
' testsprite test scaffold --type backend --out
|
|
10662
|
-
' testsprite test scaffold --out plan.json # then edit, and create with --plan-from plan.json')
|
|
11130
|
+
' testsprite test scaffold --out plan.json # edit, then: test create --plan-from plan.json\n' +
|
|
11131
|
+
' testsprite test scaffold --type backend --out health.py')
|
|
10663
11132
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10664
11133
|
.action(async (cmdOpts, command) => {
|
|
10665
11134
|
await runScaffold({
|
|
@@ -10671,7 +11140,7 @@ export function createTestCommand(deps = {}) {
|
|
|
10671
11140
|
});
|
|
10672
11141
|
test
|
|
10673
11142
|
.command('open <test-id>')
|
|
10674
|
-
.description('Open the test in the TestSprite dashboard
|
|
11143
|
+
.description('Open the test in the TestSprite dashboard (prints the URL, then opens your browser)')
|
|
10675
11144
|
.option('--no-browser', 'print the URL only (SSH, headless, CI, agents)')
|
|
10676
11145
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10677
11146
|
.action(async (testId, cmdOpts, command) => {
|
|
@@ -10684,9 +11153,9 @@ export function createTestCommand(deps = {}) {
|
|
|
10684
11153
|
test
|
|
10685
11154
|
.command('steps <test-id>')
|
|
10686
11155
|
.description('List the steps of the latest run (use --run-id for a specific run)')
|
|
10687
|
-
.option('--page-size <n>', '
|
|
10688
|
-
.option('--max-items <n>', 'stop after this many items across auto-paged pages')
|
|
10689
|
-
.option('--starting-token <token>', 'opaque cursor from a previous response')
|
|
11156
|
+
.option('--page-size <n>', 'fetch ONE page of N steps (1-100) and print the next token (default: follow every page); ignored with --run-id')
|
|
11157
|
+
.option('--max-items <n>', 'stop after this many items across auto-paged pages; ignored with --run-id')
|
|
11158
|
+
.option('--starting-token <token>', 'opaque cursor from a previous response; ignored with --run-id')
|
|
10690
11159
|
.option('--run-id <id>', 'Show steps of the specified run instead of the latest run.')
|
|
10691
11160
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10692
11161
|
.action(async (testId, cmdOpts, command) => {
|
|
@@ -10701,18 +11170,23 @@ export function createTestCommand(deps = {}) {
|
|
|
10701
11170
|
});
|
|
10702
11171
|
test
|
|
10703
11172
|
.command('diff <run-a> <run-b>')
|
|
10704
|
-
.
|
|
11173
|
+
.summary('Compare two runs; exit 1 if their verdicts differ')
|
|
11174
|
+
.description('Compare two runs (run ids, see `test result --history`) and print what regressed: verdict, failureKind, failedStepIndex, per-step status flips, codeVersion drift. ' +
|
|
11175
|
+
'Exit 0 when verdicts match, 1 when they differ, 3 auth, 4 run not found, 10 transport.')
|
|
10705
11176
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10706
11177
|
.action(async (runA, runB, _cmdOpts, command) => {
|
|
10707
11178
|
await runDiff({ ...resolveCommonOptions(command, deps.env), runA, runB }, deps);
|
|
10708
11179
|
});
|
|
10709
11180
|
test
|
|
10710
11181
|
.command('lint')
|
|
10711
|
-
.
|
|
11182
|
+
.summary('Validate plan/steps files offline')
|
|
11183
|
+
.description('Validate plan/steps files offline with the same validators `create` runs, reporting EVERY problem. No network or credentials. Exit 0 when valid, 5 otherwise.\n' +
|
|
11184
|
+
'Pass exactly one input flag.')
|
|
10712
11185
|
.option('--plan-from <file>', 'single plan JSON file')
|
|
10713
|
-
.option('--plan-from-dir <dir>', 'directory of *.json plan files (
|
|
11186
|
+
.option('--plan-from-dir <dir>', 'directory of *.json plan files (non-recursive)')
|
|
10714
11187
|
.option('--plans <file>', 'JSONL file with one plan spec per line (each line checked)')
|
|
10715
11188
|
.option('--steps <file>', 'plan-steps JSON file (the shape `test plan put` ingests)')
|
|
11189
|
+
.addHelpText('after', '\nExample:\n testsprite test lint --plan-from plan.json')
|
|
10716
11190
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10717
11191
|
.action(async (cmdOpts, command) => {
|
|
10718
11192
|
await runLint({
|
|
@@ -10725,10 +11199,11 @@ export function createTestCommand(deps = {}) {
|
|
|
10725
11199
|
});
|
|
10726
11200
|
test
|
|
10727
11201
|
.command('result <test-id>')
|
|
11202
|
+
.summary('Get the latest result, or list prior runs (--history)')
|
|
10728
11203
|
.description('Get the latest result for a test (default) or list prior runs (--history).\n' +
|
|
10729
|
-
'
|
|
10730
|
-
'
|
|
10731
|
-
'
|
|
11204
|
+
'"with --history" flags are ignored without --history (--env is rejected, exit 5).\n' +
|
|
11205
|
+
'\n--output json: a single CliLatestResult, or with --history\n' +
|
|
11206
|
+
'{ runs: RunHistoryItem[], nextCursor: string|null, meta: RunHistoryMeta }.\n' +
|
|
10732
11207
|
'\nPer-run detail: testsprite test wait <run-id>\n' +
|
|
10733
11208
|
'Failure bundle: testsprite test artifact get <run-id>')
|
|
10734
11209
|
.option('--include-analysis', 'attach the inline `analysis` block (rootCauseHypothesis, recommendedFixTarget, failureKind, snapshotId)', false)
|
|
@@ -10777,16 +11252,17 @@ export function createTestCommand(deps = {}) {
|
|
|
10777
11252
|
});
|
|
10778
11253
|
test
|
|
10779
11254
|
.command('update <test-id>')
|
|
10780
|
-
.
|
|
10781
|
-
.
|
|
11255
|
+
.summary('Update name, description, priority or step timeout')
|
|
11256
|
+
.description('Update test metadata — name, description, priority, step timeout. At least one field is required.')
|
|
11257
|
+
.option('--name <name>', 'new human-readable test name (≤ 200 chars)')
|
|
10782
11258
|
.option('--description <text>', 'new human description (≤ 2000 chars)')
|
|
10783
|
-
.option('--priority <prio>', 'new priority
|
|
10784
|
-
.option('--step-timeout <ms>', 'per-test step timeout in milliseconds (1-60000)
|
|
10785
|
-
.option('--clear-step-timeout', 'clear the per-test step timeout
|
|
11259
|
+
.option('--priority <prio>', 'new priority: p0/high, p1/medium, p2/low (p3 = low)')
|
|
11260
|
+
.option('--step-timeout <ms>', 'per-test step timeout in milliseconds (1-60000)')
|
|
11261
|
+
.option('--clear-step-timeout', 'clear the per-test step timeout, restoring the default (cannot combine with --step-timeout)', false)
|
|
10786
11262
|
.option('--produces <var>', 'BE only: variable name this test captures (repeatable). Drives dependency-aware wave ordering.', (val, prev) => [...(prev ?? []), val], [])
|
|
10787
11263
|
.option('--needs <var>', 'BE only: variable name this test consumes (repeatable). Declares an upstream producer dependency.', (val, prev) => [...(prev ?? []), val], [])
|
|
10788
11264
|
.option('--category <str>', "BE only: test category. Use 'teardown' or 'cleanup' to mark a final-wave cleanup test.")
|
|
10789
|
-
.option('--idempotency-key <token>', '
|
|
11265
|
+
.option('--idempotency-key <token>', 'idempotency token (1-256 ASCII chars; default: random UUID per invocation, pin one for safe retries)')
|
|
10790
11266
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10791
11267
|
.action(async (testId, cmdOpts, command) => {
|
|
10792
11268
|
if (cmdOpts.stepTimeout !== undefined && cmdOpts.clearStepTimeout === true) {
|
|
@@ -10797,7 +11273,7 @@ export function createTestCommand(deps = {}) {
|
|
|
10797
11273
|
testId,
|
|
10798
11274
|
name: cmdOpts.name,
|
|
10799
11275
|
description: cmdOpts.description,
|
|
10800
|
-
priority:
|
|
11276
|
+
priority: parsePriorityFlag(cmdOpts.priority),
|
|
10801
11277
|
stepTimeoutMs: parseStepTimeoutFlag(cmdOpts.stepTimeout, 'step-timeout'),
|
|
10802
11278
|
clearStepTimeout: cmdOpts.clearStepTimeout === true,
|
|
10803
11279
|
produces: cmdOpts.produces,
|
|
@@ -10808,9 +11284,11 @@ export function createTestCommand(deps = {}) {
|
|
|
10808
11284
|
});
|
|
10809
11285
|
test
|
|
10810
11286
|
.command('delete <test-id>')
|
|
10811
|
-
.
|
|
10812
|
-
.
|
|
10813
|
-
|
|
11287
|
+
.summary('Permanently delete a test (requires --confirm)')
|
|
11288
|
+
.description('Permanently delete a test. Requires --confirm.\n' +
|
|
11289
|
+
'Also removes it from test lists and deletes its steps and stored code; cannot be undone. Exit 4 if it does not exist.')
|
|
11290
|
+
.option('--confirm', 'required: confirm the destructive operation', false)
|
|
11291
|
+
.option('--idempotency-key <token>', 'idempotency token (1-256 ASCII chars; default: random UUID per invocation, pin one for safe retries)')
|
|
10814
11292
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10815
11293
|
.action(async (testId, cmdOpts, command) => {
|
|
10816
11294
|
await runDelete({
|
|
@@ -10825,18 +11303,20 @@ export function createTestCommand(deps = {}) {
|
|
|
10825
11303
|
// -------------------------------------------------------------------------
|
|
10826
11304
|
test
|
|
10827
11305
|
.command('delete-batch [test-ids...]')
|
|
10828
|
-
.
|
|
10829
|
-
'
|
|
10830
|
-
'\nPrints a per-test summary (Deleted N, Skipped M, Failed K)
|
|
11306
|
+
.summary('Permanently delete several tests (requires --confirm)')
|
|
11307
|
+
.description('Permanently delete multiple tests. Requires --confirm. With --all --project <id>, deletes every test in the project (optionally filtered by --status).\n' +
|
|
11308
|
+
'\nPrints a per-test summary (Deleted N, Skipped M, Failed K); a not-found test counts as skipped.\n' +
|
|
10831
11309
|
'\nExit codes:\n' +
|
|
10832
11310
|
' 0 all targeted tests deleted (or --dry-run)\n' +
|
|
10833
|
-
' 1 one or more deletions failed
|
|
10834
|
-
' 5 validation error (missing --confirm,
|
|
10835
|
-
'
|
|
10836
|
-
.option('--confirm', 'required: explicit confirmation for the destructive operation', false)
|
|
11311
|
+
' 1 one or more deletions failed\n' +
|
|
11312
|
+
' 5 validation error (e.g. missing --confirm, or --all without --project)')
|
|
11313
|
+
.option('--confirm', 'required: confirm the destructive operation', false)
|
|
10837
11314
|
.option('--all', 'delete all tests in the resolved project (requires --project)', false)
|
|
10838
|
-
.option('--project <id>', 'project id (required with --all
|
|
10839
|
-
.option('--status <list>', `with --all: only delete tests whose status matches these values (comma-separated; accepted: ${
|
|
11315
|
+
.option('--project <id>', 'project id (required with --all)')
|
|
11316
|
+
.option('--status <list>', `with --all: only delete tests whose latest status matches one of these values (comma-separated; accepted: ${RUN_STATUS_VALUES.join('|')}; not_run = never ran)`)
|
|
11317
|
+
.addHelpText('after', '\nExamples:\n' +
|
|
11318
|
+
' testsprite test delete-batch <id> <id> --confirm\n' +
|
|
11319
|
+
' testsprite test delete-batch --all --project <id> --status failed --confirm')
|
|
10840
11320
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10841
11321
|
.action(async (testIdsArg, cmdOpts, command) => {
|
|
10842
11322
|
await runDeleteBatch({
|
|
@@ -10853,8 +11333,9 @@ export function createTestCommand(deps = {}) {
|
|
|
10853
11333
|
// -------------------------------------------------------------------------
|
|
10854
11334
|
test
|
|
10855
11335
|
.command('run [test-id...]')
|
|
10856
|
-
.
|
|
10857
|
-
'
|
|
11336
|
+
.summary('Run a test, or a whole project (--all)')
|
|
11337
|
+
.description('Trigger a run of one or more test cases. Saved loopback environments open a tunnel automatically and wait for a verdict.\n' +
|
|
11338
|
+
'Pass several <test-id>s, or use --all --project <id> [--filter <substr>], for a batch run (ids are grouped per project and sent 50 per request). Loopback environments share one tunnel.\n' +
|
|
10858
11339
|
'\nExit codes:\n' +
|
|
10859
11340
|
' 0 passed (or queued without --wait)\n' +
|
|
10860
11341
|
' 1 failed / blocked / cancelled\n' +
|
|
@@ -10865,85 +11346,64 @@ export function createTestCommand(deps = {}) {
|
|
|
10865
11346
|
' 7 timeout — resume with: testsprite test wait <run-id>, ' +
|
|
10866
11347
|
'or stop it with: testsprite test cancel <run-id>\n' +
|
|
10867
11348
|
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
10868
|
-
' 11 rate limited — honor Retry-After
|
|
10869
|
-
'
|
|
11349
|
+
' 11 rate limited — honor Retry-After\n' +
|
|
11350
|
+
' 12 insufficient credits (non-retriable; top up)\n' +
|
|
11351
|
+
' 13 feature gated / workspace paused\n' +
|
|
10870
11352
|
'\nOn failure/blocked/cancelled, run: testsprite test artifact get <run-id>\n' +
|
|
10871
11353
|
'\nCtrl-C during an ordinary --wait detaches; an owned tunnel cancels unfinished runs by default.\n' +
|
|
10872
11354
|
'Stop a detached run with: testsprite test cancel <run-id>\n' +
|
|
10873
|
-
'
|
|
10874
|
-
'For a heavy dev server, test a built server: npm run build, then your framework preview/start command.')
|
|
11355
|
+
'Dev servers can take a minute per page through a tunnel; prefer a built server (npm run build, then start).')
|
|
10875
11356
|
.option('--target-url <url>', TARGET_URL_HELP)
|
|
10876
11357
|
.option('--skip-preflight', SKIP_PREFLIGHT_HELP, false)
|
|
10877
|
-
.option('--local <port>', 'run against an app on THIS machine
|
|
10878
|
-
'
|
|
10879
|
-
'
|
|
10880
|
-
'
|
|
10881
|
-
|
|
10882
|
-
'
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
.option('--
|
|
10887
|
-
'
|
|
10888
|
-
|
|
10889
|
-
.option('--no-cancel-on-interrupt', 'with a tunnel, skip automatic cancellation when an owned tunnel is about to close or a ' +
|
|
10890
|
-
"borrowed tunnel's owner disappears. An ordinary interrupt of a borrowed run never " +
|
|
10891
|
-
'cancels it because its tunnel remains alive.')
|
|
10892
|
-
.option('--env <name>', 'run against the named project environment — its test-account credentials, auto-auth and ' +
|
|
10893
|
-
'OTP settings (names: `testsprite project env list <project-id>`). A loopback environment opens a tunnel automatically. The run opens ' +
|
|
10894
|
-
"that environment's URL. Omit --env to keep using " +
|
|
10895
|
-
"the project's default environment. Also applies with --all.")
|
|
11358
|
+
.option('--local <port>', 'run against an app on THIS machine through a TestSprite tunnel (the runner opens ' +
|
|
11359
|
+
'http://localhost:<port>). Implies --wait. Frontend tests only; several ids or --all share one ' +
|
|
11360
|
+
'tunnel (5 concurrent, max 10). A dead port is refused before anything is billed.')
|
|
11361
|
+
.option('--local-host <host>', `with --local, loopback address in the target URL: ${LOOPBACK_HOSTS.join(', ')} ` +
|
|
11362
|
+
`(default: saved matching host, else ${DEFAULT_LOCAL_HOST}). Use localhost if your app only answers on that name, ::1 for IPv6-only.`)
|
|
11363
|
+
.option('--tunnel-client <id>', 'for a loopback environment or --local, attach to a tunnel already running under `testsprite tunnel start` ' +
|
|
11364
|
+
'(use the id it prints) instead of opening one; that process keeps the tunnel open afterwards.')
|
|
11365
|
+
.option('--no-cancel-on-interrupt', 'with a tunnel, do not auto-cancel runs when an owned tunnel closes or a ' +
|
|
11366
|
+
"borrowed tunnel's owner disappears")
|
|
11367
|
+
.option('--env <name>', 'run against the named project environment — its credentials, auto-auth and OTP settings ' +
|
|
11368
|
+
'(see `testsprite project env list <project-id>`); a loopback one opens a tunnel. ' +
|
|
11369
|
+
"Default: the project's default environment. Also applies with --all.")
|
|
10896
11370
|
.option('--wait', 'poll until terminal status or --timeout elapses', false)
|
|
10897
11371
|
.option('--no-wait', 'detach without opening an automatic environment tunnel')
|
|
10898
11372
|
.option('--timeout <s>', 'with --wait, max seconds per run (1–3600; default 600, or 1200 through a tunnel)')
|
|
10899
|
-
.option('--idempotency-key <key>', 'opaque key for safe retries (1–256 chars); local batches append each test id
|
|
10900
|
-
.option('--all', 'run all tests in the project
|
|
10901
|
-
.option('--project <id>', 'project id
|
|
11373
|
+
.option('--idempotency-key <key>', 'opaque key for safe retries (1–256 chars); local batches append each test id')
|
|
11374
|
+
.option('--all', 'run all tests in the project in wave order (uses --project or TESTSPRITE_PROJECT_ID); excludes <test-id>', false)
|
|
11375
|
+
.option('--project <id>', 'project id for --all (overrides TESTSPRITE_PROJECT_ID)')
|
|
10902
11376
|
.option('--filter <substr>', 'with --all: only run tests whose name contains this substring (case-insensitive)')
|
|
10903
|
-
.option('--
|
|
11377
|
+
.option('--status <list>', 'with --all: only run tests whose latest status matches one of these values (comma-separated; accepted: passed|failed|blocked|cancelled|not_run; not_run = never ran); --env only picks where to run')
|
|
11378
|
+
.option('--max-concurrency <n>', `with a tunnel, max runs in flight through one tunnel (1-10, default 5); with --all or several ids and --wait without a tunnel, max polls (1-100, default ${DEFAULT_BATCH_RUN_CONCURRENCY})`)
|
|
10904
11379
|
.option('--report <format>', 'with a --wait batch (--all or several ids): write a JUnit XML sidecar report after polling (accepted: junit)')
|
|
10905
11380
|
.option('--report-file <path>', 'output path for --report (atomic write)')
|
|
10906
11381
|
.option('--report-suite-name <name>', 'optional JUnit <testsuite name=...> override (default: testsprite:<projectId>)')
|
|
10907
|
-
.option('--gh-output', 'with --wait
|
|
10908
|
-
.option('--summary-file <path>', 'with --wait
|
|
10909
|
-
.option('--allow-empty', 'with --all: exit 0 when
|
|
10910
|
-
.option('--no-auto-heal', '
|
|
10911
|
-
'
|
|
10912
|
-
'
|
|
10913
|
-
'
|
|
10914
|
-
'
|
|
10915
|
-
'
|
|
10916
|
-
'
|
|
10917
|
-
'
|
|
10918
|
-
'
|
|
10919
|
-
|
|
10920
|
-
' testsprite test run --all --
|
|
10921
|
-
'
|
|
10922
|
-
'
|
|
10923
|
-
'
|
|
10924
|
-
'
|
|
10925
|
-
'
|
|
10926
|
-
'
|
|
10927
|
-
'
|
|
10928
|
-
'
|
|
10929
|
-
'
|
|
10930
|
-
'
|
|
10931
|
-
'
|
|
10932
|
-
"reported under skippedFrontend with an advisory; run those with 'test run <id>'.\n" +
|
|
10933
|
-
'\nConcurrency limits:\n' +
|
|
10934
|
-
` - CLI run triggers are refused once ${SERVER_INFLIGHT_RUN_CAP} of your runs are already in\n` +
|
|
10935
|
-
' flight (server default; the refusal reports your real cap). Runs from every\n' +
|
|
10936
|
-
' source count toward it (CLI, portal, schedules, CI), but only CLI triggers\n' +
|
|
10937
|
-
' are refused on it.\n' +
|
|
10938
|
-
' At the cap this command accepts nothing and returns every id deferred,\n' +
|
|
10939
|
-
' which exits 7; resume with the printed ids once runs finish. (A single\n' +
|
|
10940
|
-
' `test run <id>` over the cap exits 11 with details.reason "inflight_cap",\n' +
|
|
10941
|
-
' and is not auto-retried — runs have to finish first.)\n' +
|
|
10942
|
-
' Poll what is already running with: testsprite test wait <run-id...>\n' +
|
|
10943
|
-
' - Separately, run triggers are throttled per minute. That one does clear on\n' +
|
|
10944
|
-
' its own and is retried for you.\n' +
|
|
10945
|
-
' - --max-concurrency here bounds the --wait poll fan-out, not dispatch, so it\n' +
|
|
10946
|
-
' has no effect on the cap. A smaller batch does.')
|
|
11382
|
+
.option('--gh-output', 'with --wait: emit GitHub annotations (::error:: failed/timed-out, ::warning:: never dispatched) and a job-summary table when $GITHUB_STEP_SUMMARY is set; auto-enabled when GITHUB_ACTIONS=true')
|
|
11383
|
+
.option('--summary-file <path>', 'with --wait: also write summary JSON {total, passed, failed, skipped, timedOut, runs[]} to this file')
|
|
11384
|
+
.option('--allow-empty', 'with --all: exit 0 when ZERO test cases are dispatched (default: exit 5, so an empty run is not a CI false-green)')
|
|
11385
|
+
.option('--no-auto-heal', 'request strict replay of stored test code instead of letting the agent heal drifted ' +
|
|
11386
|
+
'generated code (the server decides the default); use for regression gates and bisects. ' +
|
|
11387
|
+
'Code you wrote yourself is never re-authored. The server rejects the flag where replay is ' +
|
|
11388
|
+
'unavailable and may refuse a test with no replayable code; the CLI prints an [advisory] ' +
|
|
11389
|
+
'if the opt-out did not take.')
|
|
11390
|
+
.option('--skip-dependencies', 'Backend test cases only: run without the test cases they depend on', false)
|
|
11391
|
+
.addHelpText('after', '\nExamples:\n' +
|
|
11392
|
+
' testsprite test run --all --project <id> all test cases in the project, in wave order\n' +
|
|
11393
|
+
' testsprite test run <id> <id> <id> several test cases in one run (any number of ids; sent 50 per request)\n' +
|
|
11394
|
+
' testsprite test run <id> <id> --local 3000 several local test cases, one tunnel\n' +
|
|
11395
|
+
' testsprite test run --all --status failed --env staging test cases whose latest status is failed, run in staging\n' +
|
|
11396
|
+
' testsprite test run --all --filter <substr> --wait --report junit --report-file ./results.xml\n' +
|
|
11397
|
+
'\nOn the legacy backend-only engine, FE test cases are skipped (reported under skippedFrontend);\n' +
|
|
11398
|
+
'run them with `test run <id>`. BE test cases can declare --produces/--needs at create time to order waves.\n' +
|
|
11399
|
+
'\nQueueing and limits:\n' +
|
|
11400
|
+
' - Each request starts one run; its results show queued until they start,\n' +
|
|
11401
|
+
' as in the Portal.\n' +
|
|
11402
|
+
' - A test case that already has a run in flight is a conflict (exit 6), not queued.\n' +
|
|
11403
|
+
' - Run triggers are limited to 60 per minute per API key; that limit clears on\n' +
|
|
11404
|
+
' its own and is retried for you. An older backend may still answer with\n' +
|
|
11405
|
+
' deferred ids: they are reported, not resent, and exit 7.\n' +
|
|
11406
|
+
' - --max-concurrency here bounds the --wait poll fan-out, not dispatch.')
|
|
10947
11407
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
10948
11408
|
.action(async (testIdArgs, cmdOpts, command) => {
|
|
10949
11409
|
// A literal `testsprite test run list` is someone guessing at a
|
|
@@ -10973,6 +11433,12 @@ export function createTestCommand(deps = {}) {
|
|
|
10973
11433
|
if (cmdOpts.filter !== undefined && cmdOpts.filter !== '' && !isAll) {
|
|
10974
11434
|
throw localValidationError('filter', '--filter only applies with --all (it narrows which project tests run). Remove --filter, or add --all with --project <id> or TESTSPRITE_PROJECT_ID.');
|
|
10975
11435
|
}
|
|
11436
|
+
// --status narrows the --all set exactly as --filter does, with the same
|
|
11437
|
+
// silent-ignore failure mode without --all.
|
|
11438
|
+
if (cmdOpts.status !== undefined && !isAll) {
|
|
11439
|
+
throw localValidationError('status', '--status only applies with --all (it narrows which project tests run). Remove --status, or add --all with --project <id> or TESTSPRITE_PROJECT_ID.');
|
|
11440
|
+
}
|
|
11441
|
+
validateStatusSelector(cmdOpts.status);
|
|
10976
11442
|
// --local resolution. Every one of these refuses BEFORE any network
|
|
10977
11443
|
// call, which is the contract `--local` is sold on: a mistake in the
|
|
10978
11444
|
// invocation must never reach a run row, a credit spend, or a minted
|
|
@@ -10990,8 +11456,6 @@ export function createTestCommand(deps = {}) {
|
|
|
10990
11456
|
!explicitLoopbackTarget &&
|
|
10991
11457
|
((command.getOptionValueSource('wait') === 'cli' && cmdOpts.wait === false) ||
|
|
10992
11458
|
cmdOpts.targetUrl !== undefined)) {
|
|
10993
|
-
if (!isAll && testIdArgs.length >= 2)
|
|
10994
|
-
severalIdsWithoutTunnel();
|
|
10995
11459
|
assertNoTunnelOptions({
|
|
10996
11460
|
tunnelClientId: cmdOpts.tunnelClient,
|
|
10997
11461
|
cancelOnInterrupt: cmdOpts.cancelOnInterrupt,
|
|
@@ -11066,6 +11530,7 @@ export function createTestCommand(deps = {}) {
|
|
|
11066
11530
|
...resolveCommonOptions(command, deps.env),
|
|
11067
11531
|
projectId,
|
|
11068
11532
|
nameFilter: cmdOpts.filter,
|
|
11533
|
+
statusFilter: cmdOpts.status,
|
|
11069
11534
|
wait: effectiveWait,
|
|
11070
11535
|
noWait: command.getOptionValueSource('wait') === 'cli' && cmdOpts.wait === false,
|
|
11071
11536
|
concurrencyIsDefault: cmdOpts.maxConcurrency === undefined,
|
|
@@ -11093,6 +11558,7 @@ export function createTestCommand(deps = {}) {
|
|
|
11093
11558
|
? { targetUrl: cmdOpts.targetUrl }
|
|
11094
11559
|
: {}),
|
|
11095
11560
|
skipPreflight: cmdOpts.skipPreflight === true,
|
|
11561
|
+
...(cmdOpts.skipDependencies === true ? { skipDependencies: true } : {}),
|
|
11096
11562
|
}, deps);
|
|
11097
11563
|
return;
|
|
11098
11564
|
}
|
|
@@ -11123,11 +11589,13 @@ export function createTestCommand(deps = {}) {
|
|
|
11123
11589
|
all: isAll,
|
|
11124
11590
|
projectId: cmdOpts.project,
|
|
11125
11591
|
nameFilter: cmdOpts.filter,
|
|
11592
|
+
statusFilter: cmdOpts.status,
|
|
11126
11593
|
localPort,
|
|
11127
11594
|
localHost,
|
|
11128
11595
|
targetUrl: cmdOpts.targetUrl,
|
|
11129
11596
|
noWait: command.getOptionValueSource('wait') === 'cli' && cmdOpts.wait === false,
|
|
11130
11597
|
concurrencyIsDefault: cmdOpts.maxConcurrency === undefined,
|
|
11598
|
+
timeoutIsDefault: cmdOpts.timeout === undefined,
|
|
11131
11599
|
skipPreflight: cmdOpts.skipPreflight === true,
|
|
11132
11600
|
tunnelClientId: cmdOpts.tunnelClient,
|
|
11133
11601
|
cancelOnInterrupt: cmdOpts.cancelOnInterrupt !== false,
|
|
@@ -11144,6 +11612,7 @@ export function createTestCommand(deps = {}) {
|
|
|
11144
11612
|
allowEmpty: cmdOpts.allowEmpty === true,
|
|
11145
11613
|
...(cmdOpts.autoHeal === false ? { autoHeal: false } : {}),
|
|
11146
11614
|
environment: cmdOpts.env,
|
|
11615
|
+
...(cmdOpts.skipDependencies === true ? { skipDependencies: true } : {}),
|
|
11147
11616
|
}, deps);
|
|
11148
11617
|
return;
|
|
11149
11618
|
}
|
|
@@ -11170,28 +11639,25 @@ export function createTestCommand(deps = {}) {
|
|
|
11170
11639
|
// See the matching comment on the --all path above.
|
|
11171
11640
|
...(cmdOpts.autoHeal === false ? { autoHeal: false } : {}),
|
|
11172
11641
|
environment: cmdOpts.env,
|
|
11642
|
+
...(cmdOpts.skipDependencies === true ? { skipDependencies: true } : {}),
|
|
11173
11643
|
}, deps);
|
|
11174
11644
|
});
|
|
11175
11645
|
test
|
|
11176
11646
|
.command('wait <run-id...>')
|
|
11647
|
+
.summary('Wait for one or more runs to finish')
|
|
11177
11648
|
.description('Wait for one or more runs to reach a terminal status.\n' +
|
|
11178
|
-
'\
|
|
11179
|
-
'
|
|
11180
|
-
'the exit code), so every re-attach hint the CLI prints can be pasted as\n' +
|
|
11181
|
-
'ONE command.\n' +
|
|
11649
|
+
'\nSeveral run-ids are polled concurrently under one shared --timeout and a\n' +
|
|
11650
|
+
'{results, summary} envelope is printed (worst status wins the exit code).\n' +
|
|
11182
11651
|
'\nExit codes:\n' +
|
|
11183
11652
|
' 0 passed\n' +
|
|
11184
11653
|
' 1 failed / blocked / cancelled\n' +
|
|
11185
11654
|
' 3 auth error\n' +
|
|
11186
|
-
' 4 run not found (single run-id; with several
|
|
11655
|
+
' 4 run not found (single run-id; with several, a per-member poll error\n' +
|
|
11187
11656
|
' is recorded as error:<CODE> in its row and folded into exit 7)\n' +
|
|
11188
11657
|
' 7 timeout or per-member poll error — resume with: testsprite test wait <run-id...>\n' +
|
|
11189
11658
|
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
11190
|
-
' 11 rate limited
|
|
11191
|
-
'
|
|
11192
|
-
' outlasted that budget while the runs were still fine. Back off, then\n' +
|
|
11193
|
-
' re-attach with test wait. (A throttle that instead consumes the whole\n' +
|
|
11194
|
-
' --timeout reports 7, and any real timeout or failure keeps 7 / 1.)\n' +
|
|
11659
|
+
' 11 rate limited past the automatic Retry-After retries, runs still fine — back off,\n' +
|
|
11660
|
+
' then re-attach (a throttle that consumes the whole --timeout reports 7)\n' +
|
|
11195
11661
|
'\nOn failure/blocked/cancelled, run: testsprite test artifact get <run-id>\n' +
|
|
11196
11662
|
'\nCtrl-C detaches only (the run keeps executing and billing); stop it for\n' +
|
|
11197
11663
|
'real with: testsprite test cancel <run-id...>')
|
|
@@ -11224,9 +11690,11 @@ export function createTestCommand(deps = {}) {
|
|
|
11224
11690
|
// M3.4 piece-3 — `test rerun`
|
|
11225
11691
|
// -------------------------------------------------------------------------
|
|
11226
11692
|
test
|
|
11227
|
-
.command('rerun [test-ids...]')
|
|
11228
|
-
.description('
|
|
11229
|
-
|
|
11693
|
+
.command('rerun [test-ids...]', { hidden: true })
|
|
11694
|
+
.description('[deprecated] Use `testsprite test run` instead; removed in ' +
|
|
11695
|
+
`${REMOVED_IN}. ` +
|
|
11696
|
+
'Re-execute a test case (or several) as a replay — FE replays the saved script, BE re-runs the dependency closure. ' +
|
|
11697
|
+
'Billed like a fresh run on V3 workspaces (0.5 credits per FE case, 0.2 per BE case). Legacy V2 accounts: reruns are free.\n' +
|
|
11230
11698
|
'\nExit codes:\n' +
|
|
11231
11699
|
' 0 passed (or queued without --wait)\n' +
|
|
11232
11700
|
' 1 failed / blocked / cancelled\n' +
|
|
@@ -11241,7 +11709,7 @@ export function createTestCommand(deps = {}) {
|
|
|
11241
11709
|
'\nCtrl-C during --wait detaches only (the run keeps executing and billing);\n' +
|
|
11242
11710
|
'stop it for real with: testsprite test cancel <run-id>')
|
|
11243
11711
|
.option('--all', 'rerun all tests in the resolved project (requires --project)', false)
|
|
11244
|
-
.option('--project <id>', 'project id (required with --all
|
|
11712
|
+
.option('--project <id>', 'project id (required with --all)')
|
|
11245
11713
|
.option('--skip-terminal', 'with --all: skip tests already in a terminal status (passed|failed|blocked|cancelled)', false)
|
|
11246
11714
|
.option('--status <list>', `with --all: only dispatch tests whose status matches one of these values (comma-separated; accepted: ${PUBLIC_STATUSES.join('|')})`)
|
|
11247
11715
|
.option('--filter <substr>', 'with --all: only rerun tests whose name contains this substring (case-insensitive)')
|
|
@@ -11249,39 +11717,34 @@ export function createTestCommand(deps = {}) {
|
|
|
11249
11717
|
.option('--no-wait', 'detach without opening an automatic environment tunnel')
|
|
11250
11718
|
.option('--skip-preflight', 'skip the loopback port probe before opening a tunnel')
|
|
11251
11719
|
.option('--timeout <s>', `with --wait, max seconds to wait (1–3600, default ${DEFAULT_RUN_TIMEOUT_SECONDS})`)
|
|
11252
|
-
.option('--no-auto-heal', 'replay the saved script verbatim instead of letting the agent repair it (default: ' +
|
|
11253
|
-
'
|
|
11254
|
-
'the new code replaces the stored version. Ignored for backend reruns. ' +
|
|
11255
|
-
'Costs: `testsprite usage`.')
|
|
11720
|
+
.option('--no-auto-heal', 'replay the saved script verbatim instead of letting the agent repair it (default: auto-heal ' +
|
|
11721
|
+
'is ON for FE reruns; a heal replaces the stored code). Ignored for backend reruns.')
|
|
11256
11722
|
.option('--skip-dependencies', 'BE only: rerun only the named test without expanding the producer/teardown closure', false)
|
|
11257
|
-
.option('--env <name>', 'replay against the named project environment — its
|
|
11258
|
-
'
|
|
11259
|
-
"project's default environment.
|
|
11723
|
+
.option('--env <name>', 'replay against the named project environment — its credentials, auto-auth and OTP settings ' +
|
|
11724
|
+
'(see `testsprite project env list <project-id>`); loopback URLs open a tunnel. ' +
|
|
11725
|
+
"Default: the project's default environment. Applies to every test of a batch.")
|
|
11260
11726
|
.option('--max-concurrency <n>', `with a tunnel, max runs in flight (1-10, default 5); otherwise with --wait, max polls (1-100, default ${DEFAULT_BATCH_RUN_CONCURRENCY})`)
|
|
11261
|
-
.option('--idempotency-key <key>', 'opaque key for safe retries (1–256 chars)
|
|
11727
|
+
.option('--idempotency-key <key>', 'opaque key for safe retries (1–256 chars)')
|
|
11262
11728
|
.option('--report <format>', 'with batch --wait: write a JUnit XML sidecar report after polling (accepted: junit)')
|
|
11263
11729
|
.option('--report-file <path>', 'output path for --report (atomic write)')
|
|
11264
11730
|
.option('--report-suite-name <name>', 'optional JUnit <testsuite name=...> override (default: testsprite:<projectId>)')
|
|
11265
|
-
.option('--gh-output', 'with batch --wait: emit GitHub
|
|
11266
|
-
.option('--summary-file <path>', 'with batch --wait: also write
|
|
11267
|
-
.option('--allow-empty', 'with --all: exit 0 when
|
|
11731
|
+
.option('--gh-output', 'with batch --wait: emit GitHub annotations (::error:: failed/timed-out, ::warning:: never dispatched) and a job-summary table when $GITHUB_STEP_SUMMARY is set; auto-enabled when GITHUB_ACTIONS=true')
|
|
11732
|
+
.option('--summary-file <path>', 'with batch --wait: also write summary JSON {total, passed, failed, skipped, timedOut, runs[]} to this file')
|
|
11733
|
+
.option('--allow-empty', 'with --all: exit 0 when no tests match (default: exit 5, so an empty rerun is not a CI false-green)')
|
|
11268
11734
|
.addHelpText('after', '\nNotes:\n' +
|
|
11269
|
-
' •
|
|
11270
|
-
'
|
|
11271
|
-
' •
|
|
11272
|
-
'
|
|
11273
|
-
' • Under --wait the per-request HTTP timeout is auto-raised to cover --timeout so a\n' +
|
|
11274
|
-
' slow trigger/poll under load is not cut at the 120s default (see --request-timeout).\n' +
|
|
11275
|
-
' • Batch --wait: rate-deferred tests appear in `deferred[]` and `summary.deferred`,\n' +
|
|
11276
|
-
' and force a non-zero exit — they are NOT counted in `summary.total` (dispatched only).\n' +
|
|
11277
|
-
' • rerun gets no server echo of the effective auto-heal decision, so a dropped\n' +
|
|
11278
|
-
' opt-out cannot be detected here the way `test run --no-auto-heal` detects it.')
|
|
11279
|
-
.addHelpText('after', '\nDry-run shape notes:\n' +
|
|
11280
|
-
' • --dry-run shows the BE rerun wire shape (includes `closure{}`); FE rerun responses\n' +
|
|
11281
|
-
' omit `closure` (or return it as null) since there is no dependency expansion.\n' +
|
|
11282
|
-
' • `autoHeal` defaults true for FE reruns; BE reruns ignore the field entirely.')
|
|
11735
|
+
' • A rerun replays a SAVED run/script, so one must exist; `test run` starts fresh.\n' +
|
|
11736
|
+
' A BE rerun also expands the dependency closure.\n' +
|
|
11737
|
+
' • Batch --wait: rate-deferred tests appear in `deferred[]` / `summary.deferred` and force a\n' +
|
|
11738
|
+
' non-zero exit; they are not counted in `summary.total`.')
|
|
11283
11739
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
11284
11740
|
.action(async (testIdsArg, cmdOpts, command) => {
|
|
11741
|
+
// First statement, before any validation, so the notice precedes a usage error and
|
|
11742
|
+
// appears exactly once per invocation (also under --dry-run and in both output modes).
|
|
11743
|
+
const rerunDeprecation = TEST_RERUN_DEPRECATION;
|
|
11744
|
+
emitDeprecationEntry(rerunDeprecation, deps.stderr, 'Use `testsprite test run` with the same ids and flags, except: ' +
|
|
11745
|
+
'--skip-terminal becomes --status not_run, and --status takes only ' +
|
|
11746
|
+
`${RUN_STATUS_VALUES.join(', ')}.`);
|
|
11747
|
+
const rerunDeps = { ...deps, deprecations: [rerunDeprecation] };
|
|
11285
11748
|
// Commander's `--no-auto-heal` pattern makes `cmdOpts.autoHeal` default
|
|
11286
11749
|
// `true` (unchanged by the user) and `false` when the user passes
|
|
11287
11750
|
// `--no-auto-heal`. There is no explicit `--auto-heal` flag, so
|
|
@@ -11335,15 +11798,17 @@ export function createTestCommand(deps = {}) {
|
|
|
11335
11798
|
ghOutput: cmdOpts.ghOutput === true,
|
|
11336
11799
|
summaryFile: cmdOpts.summaryFile,
|
|
11337
11800
|
allowEmpty: cmdOpts.allowEmpty === true,
|
|
11338
|
-
},
|
|
11801
|
+
}, rerunDeps);
|
|
11339
11802
|
});
|
|
11340
11803
|
// -------------------------------------------------------------------------
|
|
11341
11804
|
// `test flaky` — repeat-run flaky-test detector
|
|
11342
11805
|
// -------------------------------------------------------------------------
|
|
11343
11806
|
test
|
|
11344
|
-
.command('flaky <test-id>')
|
|
11345
|
-
.description('
|
|
11346
|
-
|
|
11807
|
+
.command('flaky <test-id>', { hidden: true })
|
|
11808
|
+
.description('[deprecated] No replacement; run `testsprite test run <test-id>` again to sample a test case; ' +
|
|
11809
|
+
`removed in ${REMOVED_IN}.\n` +
|
|
11810
|
+
'Repeatedly replay a test case to measure stability.\n' +
|
|
11811
|
+
'Replays run with auto-heal OFF (strict verbatim) so healing cannot mask a flaky pass/fail.\n' +
|
|
11347
11812
|
'\nExit codes:\n' +
|
|
11348
11813
|
' 0 stable (every attempt passed)\n' +
|
|
11349
11814
|
' 1 flaky or failing (at least one attempt did not pass)\n' +
|
|
@@ -11354,23 +11819,21 @@ export function createTestCommand(deps = {}) {
|
|
|
11354
11819
|
.option('--until-fail', 'stop at the first non-passing attempt (fast "is it flaky at all?" check)', false)
|
|
11355
11820
|
.option('--timeout <s>', `per-attempt max seconds to wait (1-${MAX_RUN_TIMEOUT_SECONDS}, default ${DEFAULT_RUN_TIMEOUT_SECONDS})`)
|
|
11356
11821
|
.addHelpText('after', '\nNotes:\n' +
|
|
11357
|
-
' • Each replay is billed as a rerun
|
|
11358
|
-
'
|
|
11359
|
-
'
|
|
11360
|
-
' frontend test (legacy V2 accounts: FE rerun remains free). A one-line advisory\n' +
|
|
11361
|
-
' is printed before a backend replay.\n' +
|
|
11362
|
-
' • Replays use auto-heal OFF so a flaky test is not silently "healed" into a pass;\n' +
|
|
11363
|
-
' this measures replay stability of the saved script against the configured URL.\n' +
|
|
11364
|
-
' • `--output json` emits a machine-readable stability report for CI gating.')
|
|
11822
|
+
' • Each replay is billed as a rerun (0.5 credits per FE replay, 0.2 per BE replay), so\n' +
|
|
11823
|
+
' `--runs N` costs about N×0.5 for a frontend test (legacy V2 accounts: FE rerun is free).\n' +
|
|
11824
|
+
' • `--output json` emits a stability report for CI gating.')
|
|
11365
11825
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
11366
11826
|
.action(async (testIdArg, cmdOpts, command) => {
|
|
11827
|
+
const flakyDeprecation = TEST_FLAKY_DEPRECATION;
|
|
11828
|
+
emitDeprecationEntry(flakyDeprecation, deps.stderr, `To sample a test again, run \`testsprite test run ${testIdArg}\`.`, true);
|
|
11829
|
+
const flakyDeps = { ...deps, deprecations: [flakyDeprecation] };
|
|
11367
11830
|
await runFlaky({
|
|
11368
11831
|
...resolveCommonOptions(command, deps.env),
|
|
11369
11832
|
testId: testIdArg,
|
|
11370
11833
|
runs: parseNumericFlag(cmdOpts.runs, 'runs') ?? DEFAULT_FLAKY_RUNS,
|
|
11371
11834
|
untilFail: cmdOpts.untilFail === true,
|
|
11372
11835
|
timeoutSeconds: parseTimeoutFlag(cmdOpts.timeout, 'timeout'),
|
|
11373
|
-
},
|
|
11836
|
+
}, flakyDeps);
|
|
11374
11837
|
});
|
|
11375
11838
|
test.addCommand(createTestCodeCommand(deps));
|
|
11376
11839
|
test.addCommand(createTestPlanCommand(deps));
|
|
@@ -11597,6 +12060,166 @@ function validateStatusFilter(raw) {
|
|
|
11597
12060
|
}
|
|
11598
12061
|
}
|
|
11599
12062
|
}
|
|
12063
|
+
/**
|
|
12064
|
+
* `--status` for `test list` and `test delete-batch`: the five latest-status
|
|
12065
|
+
* values of `test run`, where `not_run` is the test cases that never ran. The
|
|
12066
|
+
* older public values still work but are no longer advertised.
|
|
12067
|
+
*/
|
|
12068
|
+
function validateListStatusFilter(raw) {
|
|
12069
|
+
if (raw === undefined || raw === '')
|
|
12070
|
+
return;
|
|
12071
|
+
for (const token of raw.split(',')) {
|
|
12072
|
+
const trimmed = token.trim();
|
|
12073
|
+
if (trimmed === '' || trimmed === 'not_run')
|
|
12074
|
+
continue;
|
|
12075
|
+
if (!PUBLIC_STATUSES.includes(trimmed)) {
|
|
12076
|
+
throw localValidationError('status', `must be one of: ${RUN_STATUS_VALUES.join(', ')} (comma-separated for multiple)`, [...RUN_STATUS_VALUES]);
|
|
12077
|
+
}
|
|
12078
|
+
}
|
|
12079
|
+
}
|
|
12080
|
+
/**
|
|
12081
|
+
* A `--status` list with `not_run` spelled as the server's draft and ready.
|
|
12082
|
+
* A list without `not_run` is returned unchanged.
|
|
12083
|
+
*/
|
|
12084
|
+
function expandNotRun(raw) {
|
|
12085
|
+
const tokens = raw.split(',').map(s => s.trim());
|
|
12086
|
+
if (!tokens.includes('not_run'))
|
|
12087
|
+
return raw;
|
|
12088
|
+
const expanded = tokens
|
|
12089
|
+
.filter(s => s.length > 0)
|
|
12090
|
+
.flatMap(s => (s === 'not_run' ? ['draft', 'ready'] : [s]));
|
|
12091
|
+
return [...new Set(expanded)].join(',');
|
|
12092
|
+
}
|
|
12093
|
+
/**
|
|
12094
|
+
* Strict `--status` selector for the run family. `validateStatusFilter` reads
|
|
12095
|
+
* an empty value as "no filter", which is right for `test list`, but a run
|
|
12096
|
+
* selector that selects nothing would silently dispatch the whole project (or
|
|
12097
|
+
* filter every test out), so an empty or commas-only value is a usage error.
|
|
12098
|
+
*/
|
|
12099
|
+
function assertStatusSelectorNotEmpty(raw, accepted = PUBLIC_STATUSES) {
|
|
12100
|
+
if (raw === undefined)
|
|
12101
|
+
return;
|
|
12102
|
+
if (raw.split(',').every(token => token.trim() === '')) {
|
|
12103
|
+
throw localValidationError('status', `--status needs at least one status (accepted: ${accepted.join(', ')}); remove --status to select every test`, [...accepted]);
|
|
12104
|
+
}
|
|
12105
|
+
}
|
|
12106
|
+
/**
|
|
12107
|
+
* `test run --status` selects test cases by the status of their latest result.
|
|
12108
|
+
* `not_run` is the test cases that never produced one (draft or ready).
|
|
12109
|
+
*/
|
|
12110
|
+
const RUN_STATUS_VALUES = ['passed', 'failed', 'blocked', 'cancelled', 'not_run'];
|
|
12111
|
+
function validateStatusSelector(raw) {
|
|
12112
|
+
assertStatusSelectorNotEmpty(raw, RUN_STATUS_VALUES);
|
|
12113
|
+
if (raw === undefined)
|
|
12114
|
+
return;
|
|
12115
|
+
for (const token of raw.split(',')) {
|
|
12116
|
+
const trimmed = token.trim();
|
|
12117
|
+
if (trimmed === '')
|
|
12118
|
+
continue;
|
|
12119
|
+
if (!RUN_STATUS_VALUES.includes(trimmed)) {
|
|
12120
|
+
throw localValidationError('status', `--status selects test cases by the status of their latest result, so '${trimmed}' is not accepted; ` +
|
|
12121
|
+
`use one of: ${RUN_STATUS_VALUES.join(', ')} (comma-separated for multiple). ` +
|
|
12122
|
+
'Use not_run for test cases that never ran; queued and running are not a latest status.', [...RUN_STATUS_VALUES]);
|
|
12123
|
+
}
|
|
12124
|
+
}
|
|
12125
|
+
}
|
|
12126
|
+
/** Add the available environment names to an unknown-environment rejection. */
|
|
12127
|
+
function withUnknownEnvironmentHint(err, environment) {
|
|
12128
|
+
if (err instanceof ApiError &&
|
|
12129
|
+
err.code === 'VALIDATION_ERROR' &&
|
|
12130
|
+
err.getDetail('field') === 'environment' &&
|
|
12131
|
+
Array.isArray(err.getDetail('available')) &&
|
|
12132
|
+
environment !== undefined) {
|
|
12133
|
+
const available = err.getDetail('available').filter((name) => typeof name === 'string');
|
|
12134
|
+
if (available.length > 0 && !err.nextAction.includes(available.join(', '))) {
|
|
12135
|
+
const hint = `Flag \`--env\` is invalid: unknown environment '${environment}'; use one of: ${available.join(', ')}.`;
|
|
12136
|
+
return new ApiError({
|
|
12137
|
+
code: err.code,
|
|
12138
|
+
message: err.message,
|
|
12139
|
+
nextAction: err.nextAction ? `${hint} ${err.nextAction}` : hint,
|
|
12140
|
+
requestId: err.requestId,
|
|
12141
|
+
details: err.details,
|
|
12142
|
+
}, err.httpStatus, err.retryAfterMs);
|
|
12143
|
+
}
|
|
12144
|
+
}
|
|
12145
|
+
return err;
|
|
12146
|
+
}
|
|
12147
|
+
/**
|
|
12148
|
+
* An older server ignores `environment` and returns unfiltered statuses;
|
|
12149
|
+
* acting on them would look like an environment-scoped answer.
|
|
12150
|
+
*/
|
|
12151
|
+
function assertEnvironmentStatusesPresent(items, copy) {
|
|
12152
|
+
if (items.length > 0 &&
|
|
12153
|
+
!items.some(test => test.headlineEnvironment !== undefined || test.statusByEnvironment !== undefined)) {
|
|
12154
|
+
throw ApiError.fromEnvelope({
|
|
12155
|
+
error: {
|
|
12156
|
+
code: 'UNSUPPORTED',
|
|
12157
|
+
message: copy.message,
|
|
12158
|
+
nextAction: copy.nextAction,
|
|
12159
|
+
requestId: 'local',
|
|
12160
|
+
details: {},
|
|
12161
|
+
},
|
|
12162
|
+
});
|
|
12163
|
+
}
|
|
12164
|
+
}
|
|
12165
|
+
/**
|
|
12166
|
+
* Every test of one project, narrowed client-side by `--skip-terminal`,
|
|
12167
|
+
* `--status` and `--filter` in that order. The status of a test case is its
|
|
12168
|
+
* headline `status` from an environment-free listing; `--env` only picks where
|
|
12169
|
+
* a run goes. `latestStatus` reads `--status` as the run selector does
|
|
12170
|
+
* (`not_run` = draft or ready); otherwise it is the public status set.
|
|
12171
|
+
*/
|
|
12172
|
+
async function resolveAllProjectTests(args) {
|
|
12173
|
+
const { client, projectId, statusFilter, nameFilter, stderr } = args;
|
|
12174
|
+
const statusSelected = statusFilter !== undefined && statusFilter !== '';
|
|
12175
|
+
let items = (await paginate(async ({ pageSize, cursor }) => client.get('/tests', {
|
|
12176
|
+
query: { projectId, pageSize, cursor },
|
|
12177
|
+
}), {})).items;
|
|
12178
|
+
const statusOf = (test) => test.status;
|
|
12179
|
+
if (args.skipTerminal) {
|
|
12180
|
+
const before = items.length;
|
|
12181
|
+
items = items.filter(t => !TERMINAL_PUBLIC_STATUSES.has(statusOf(t)));
|
|
12182
|
+
const skipped = before - items.length;
|
|
12183
|
+
if (skipped > 0) {
|
|
12184
|
+
stderr(`--skip-terminal: skipped ${skipped} already-terminal test${skipped !== 1 ? 's' : ''} (passed|failed|blocked|cancelled).`);
|
|
12185
|
+
}
|
|
12186
|
+
}
|
|
12187
|
+
if (statusSelected) {
|
|
12188
|
+
const allowed = new Set(statusFilter
|
|
12189
|
+
.split(',')
|
|
12190
|
+
.map(s => s.trim())
|
|
12191
|
+
.filter(s => s.length > 0)
|
|
12192
|
+
.flatMap(s => (args.latestStatus && s === 'not_run' ? ['draft', 'ready'] : [s])));
|
|
12193
|
+
const before = items.length;
|
|
12194
|
+
items = items.filter(t => allowed.has(statusOf(t)));
|
|
12195
|
+
const skipped = before - items.length;
|
|
12196
|
+
if (skipped > 0) {
|
|
12197
|
+
stderr(args.latestStatus
|
|
12198
|
+
? `--status filter: skipped ${skipped} test${skipped !== 1 ? 's' : ''} whose latest status is not ${statusFilter}.`
|
|
12199
|
+
: `--status filter: skipped ${skipped} test${skipped !== 1 ? 's' : ''} not matching status=${statusFilter}.`);
|
|
12200
|
+
}
|
|
12201
|
+
}
|
|
12202
|
+
if (nameFilter !== undefined && nameFilter !== '') {
|
|
12203
|
+
const needle = nameFilter.toLowerCase();
|
|
12204
|
+
const before = items.length;
|
|
12205
|
+
items = items.filter(t => t.name.toLowerCase().includes(needle));
|
|
12206
|
+
const skipped = before - items.length;
|
|
12207
|
+
if (skipped > 0) {
|
|
12208
|
+
stderr(`--filter: skipped ${skipped} test${skipped !== 1 ? 's' : ''} whose name does not contain "${nameFilter}".`);
|
|
12209
|
+
}
|
|
12210
|
+
}
|
|
12211
|
+
return items;
|
|
12212
|
+
}
|
|
12213
|
+
/** The selectors a zero-match message names, in the order they are applied. */
|
|
12214
|
+
function describeRunSelectors(opts) {
|
|
12215
|
+
const parts = [];
|
|
12216
|
+
if (opts.statusFilter !== undefined)
|
|
12217
|
+
parts.push(`--status ${opts.statusFilter}`);
|
|
12218
|
+
if (opts.nameFilter !== undefined && opts.nameFilter !== '') {
|
|
12219
|
+
parts.push(`--filter "${opts.nameFilter}"`);
|
|
12220
|
+
}
|
|
12221
|
+
return parts.join(' ');
|
|
12222
|
+
}
|
|
11600
12223
|
function parseEnumFlag(raw, flagName, accepted) {
|
|
11601
12224
|
if (raw === undefined)
|
|
11602
12225
|
return undefined;
|
|
@@ -11605,6 +12228,12 @@ function parseEnumFlag(raw, flagName, accepted) {
|
|
|
11605
12228
|
}
|
|
11606
12229
|
return raw;
|
|
11607
12230
|
}
|
|
12231
|
+
function parsePriorityFlag(raw) {
|
|
12232
|
+
if (raw === undefined)
|
|
12233
|
+
return undefined;
|
|
12234
|
+
assertPriorityInput('priority', raw, 'flag');
|
|
12235
|
+
return raw;
|
|
12236
|
+
}
|
|
11608
12237
|
function parseNumericFlag(raw, flagName) {
|
|
11609
12238
|
if (raw === undefined)
|
|
11610
12239
|
return undefined;
|
|
@@ -11766,7 +12395,7 @@ function makeOutput(mode, deps) {
|
|
|
11766
12395
|
stdout: deps.stdout,
|
|
11767
12396
|
stderr: deps.stderr,
|
|
11768
12397
|
rawStdout: deps.rawStdout,
|
|
11769
|
-
});
|
|
12398
|
+
}, { deprecations: deps.deprecations });
|
|
11770
12399
|
}
|
|
11771
12400
|
/**
|
|
11772
12401
|
* Open a temp file next to the `--out` target before any network I/O so
|
|
@@ -12006,6 +12635,9 @@ async function readPresignedBody(url, out, deps, shutdownSignal) {
|
|
|
12006
12635
|
throw new TransportError(`Failed mid-download of presigned code body: ${message}`);
|
|
12007
12636
|
}
|
|
12008
12637
|
}
|
|
12638
|
+
function renderTestTypeCell(test) {
|
|
12639
|
+
return test.isIntegration === true ? `${test.type}/int` : test.type;
|
|
12640
|
+
}
|
|
12009
12641
|
const TEST_LIST_COLUMNS = [
|
|
12010
12642
|
{
|
|
12011
12643
|
header: 'ID',
|
|
@@ -12017,7 +12649,11 @@ const TEST_LIST_COLUMNS = [
|
|
|
12017
12649
|
width: rows => Math.max(4, ...rows.map(test => test.name.length)),
|
|
12018
12650
|
render: test => test.name,
|
|
12019
12651
|
},
|
|
12020
|
-
{
|
|
12652
|
+
{
|
|
12653
|
+
header: 'TYPE',
|
|
12654
|
+
width: rows => Math.max(8, ...rows.map(test => renderTestTypeCell(test).length)),
|
|
12655
|
+
render: renderTestTypeCell,
|
|
12656
|
+
},
|
|
12021
12657
|
{ header: 'FROM', width: 6, render: test => test.createdFrom },
|
|
12022
12658
|
{ header: 'STATUS', width: 9, render: test => test.status },
|
|
12023
12659
|
{
|
|
@@ -12031,7 +12667,7 @@ const TEST_LIST_COLUMNS = [
|
|
|
12031
12667
|
render: test => test.headlineEnvironment?.name ?? '-',
|
|
12032
12668
|
},
|
|
12033
12669
|
];
|
|
12034
|
-
function renderTestListText(page, options = {}) {
|
|
12670
|
+
export function renderTestListText(page, options = {}) {
|
|
12035
12671
|
const note = options.environment === undefined || options.noHeader
|
|
12036
12672
|
? []
|
|
12037
12673
|
: [`Frontend test status requested for environment '${options.environment}'.`];
|
|
@@ -12091,8 +12727,13 @@ function renderTestText(t) {
|
|
|
12091
12727
|
const fields = step;
|
|
12092
12728
|
const type = typeof fields.type === 'string' ? fields.type : 'step';
|
|
12093
12729
|
const description = typeof fields.description === 'string' ? fields.description : '(no description)';
|
|
12094
|
-
|
|
12730
|
+
const mark = fields.structured === true ? '*' : ' ';
|
|
12731
|
+
lines.push(`${mark} ${index + 1}. [${type}] ${description}`);
|
|
12095
12732
|
});
|
|
12733
|
+
const structuredCount = planSteps.filter(step => typeof step === 'object' && step !== null && step.structured === true).length;
|
|
12734
|
+
if (structuredCount > 0) {
|
|
12735
|
+
lines.push(`* ${structuredCount} step(s) carry structured fields; \`plan put\` keeps them only for unchanged steps.`);
|
|
12736
|
+
}
|
|
12096
12737
|
}
|
|
12097
12738
|
if (typeof t.stepTimeoutMs === 'number') {
|
|
12098
12739
|
lines.push(`stepTimeout: ${t.stepTimeoutMs} ms (applies to every step)`);
|
|
@@ -12478,16 +13119,14 @@ function createTestCodeCommand(deps) {
|
|
|
12478
13119
|
code
|
|
12479
13120
|
.command('put <test-id>')
|
|
12480
13121
|
.description('Replace test code with etag-guarded optimistic concurrency')
|
|
12481
|
-
.option('--code-file <path>', '
|
|
12482
|
-
.option('--expected-version <v>', 'expected current codeVersion (e.g. v3)
|
|
12483
|
-
|
|
12484
|
-
.option('--
|
|
12485
|
-
.option('--
|
|
12486
|
-
.option('--
|
|
12487
|
-
.
|
|
12488
|
-
'
|
|
12489
|
-
'\n' +
|
|
12490
|
-
GLOBAL_OPTS_HINT)
|
|
13122
|
+
.option('--code-file <path>', 'new test code: required, a .py file, ≤ 350 KB')
|
|
13123
|
+
.option('--expected-version <v>', 'expected current codeVersion (e.g. v3), sent as `If-Match`; excludes --force. ' +
|
|
13124
|
+
'Omit both to auto-fetch the current version (no protection against concurrent edits; pass it in scripts).')
|
|
13125
|
+
.option('--force', 'send `If-Match: *` to skip the etag check (audit-logged); excludes --expected-version', false)
|
|
13126
|
+
.option('--language <lang>', 'stored code language; only "python" is supported (default: the existing language)')
|
|
13127
|
+
.option('--idempotency-key <token>', 'idempotency token (1-256 ASCII chars; default: random UUID per invocation, pin one for safe retries)')
|
|
13128
|
+
.option('--dry-run-simulate-error <code>', 'with --dry-run: preview the 412 error path (supported: PRECONDITION_FAILED); without it --dry-run shows the success shape')
|
|
13129
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
12491
13130
|
.action(async (testId, cmdOpts, command) => {
|
|
12492
13131
|
const simulateError = cmdOpts.dryRunSimulateError;
|
|
12493
13132
|
if (simulateError !== undefined && simulateError !== 'PRECONDITION_FAILED') {
|
|
@@ -13364,12 +14003,17 @@ function createTestPlanCommand(deps) {
|
|
|
13364
14003
|
plan
|
|
13365
14004
|
.command('put <test-id>')
|
|
13366
14005
|
.description("Replace an FE test's planSteps[] (BE tests return 400 → use 'test code put')")
|
|
13367
|
-
.option('--steps <path>', 'JSON file with { planSteps: [...] } (FE-only, ≤ 200 steps, ≤ 256 KB)')
|
|
13368
|
-
.option('--expected-step-count <n>', '
|
|
13369
|
-
.option('--
|
|
13370
|
-
.option('--
|
|
13371
|
-
.
|
|
13372
|
-
'
|
|
14006
|
+
.option('--steps <path>', 'required: JSON file with { planSteps: [...] } (FE-only, ≤ 200 steps, ≤ 256 KB)')
|
|
14007
|
+
.option('--expected-step-count <n>', 'pin the step count the server must still have; 412 when it differs')
|
|
14008
|
+
.option('--force', 'replace even if steps edited in the Portal would lose their structured fields')
|
|
14009
|
+
.option('--idempotency-key <token>', 'idempotency token (1-256 ASCII chars; default: random UUID per invocation, pin one for safe retries)')
|
|
14010
|
+
.option('--dry-run-simulate-error <code>', 'with --dry-run: preview the 412 error path (supported: PRECONDITION_FAILED); without it --dry-run shows the success shape')
|
|
14011
|
+
.addHelpText('after', '\nExit codes:\n' +
|
|
14012
|
+
' 0 steps replaced\n' +
|
|
14013
|
+
' 3 authentication error\n' +
|
|
14014
|
+
' 4 test not found\n' +
|
|
14015
|
+
' 5 validation error (e.g. missing --steps, unreadable or invalid file)\n' +
|
|
14016
|
+
' 6 step-count mismatch with --expected-step-count (HTTP 412)\n' +
|
|
13373
14017
|
'\n' +
|
|
13374
14018
|
GLOBAL_OPTS_HINT)
|
|
13375
14019
|
.action(async (testId, cmdOpts, command) => {
|
|
@@ -13382,31 +14026,33 @@ function createTestPlanCommand(deps) {
|
|
|
13382
14026
|
testId,
|
|
13383
14027
|
stepsFile: cmdOpts.steps,
|
|
13384
14028
|
expectedStepCount: parseNumericFlag(cmdOpts.expectedStepCount, 'expected-step-count'),
|
|
14029
|
+
force: cmdOpts.force === true ? true : undefined,
|
|
13385
14030
|
idempotencyKey: cmdOpts.idempotencyKey,
|
|
13386
14031
|
dryRunSimulateError: simulateError === 'PRECONDITION_FAILED' ? 'PRECONDITION_FAILED' : undefined,
|
|
13387
14032
|
}, deps);
|
|
13388
14033
|
});
|
|
13389
14034
|
plan
|
|
13390
14035
|
.command('generate')
|
|
13391
|
-
.
|
|
14036
|
+
.summary('Generate AI test-case proposals for review')
|
|
14037
|
+
.description('Generate AI test-case proposals for a project: runs only the missing pipeline ' +
|
|
13392
14038
|
'stages and stages the results server-side for review (nothing is written locally)')
|
|
13393
|
-
.option('--project <id>', 'project id (
|
|
14039
|
+
.option('--project <id>', 'project id (or set TESTSPRITE_PROJECT_ID)')
|
|
13394
14040
|
.option('--timeout <seconds>', `total wait budget in seconds (1-3600, default ${PLAN_GENERATE_DEFAULT_TIMEOUT_SECONDS}; ` +
|
|
13395
|
-
'exploration
|
|
13396
|
-
.option('--idempotency-key <token>', '
|
|
13397
|
-
.addHelpText('after', '\
|
|
13398
|
-
'
|
|
13399
|
-
'
|
|
13400
|
-
'
|
|
13401
|
-
'
|
|
13402
|
-
'
|
|
13403
|
-
'
|
|
13404
|
-
'
|
|
13405
|
-
'
|
|
13406
|
-
'
|
|
13407
|
-
'
|
|
13408
|
-
'\n' +
|
|
13409
|
-
'
|
|
14041
|
+
'exploration of a fresh frontend project takes minutes)')
|
|
14042
|
+
.option('--idempotency-key <token>', 'idempotency token (1-256 ASCII chars; default: random UUID per invocation, pin one for safe retries)')
|
|
14043
|
+
.addHelpText('after', '\nStages that run: exploration (frontend), strategy, proposals. On interrupt (exit 130/143/129)\n' +
|
|
14044
|
+
'or timeout (exit 7) the running stage finishes on its own; re-run the same command to continue.\n' +
|
|
14045
|
+
'A completed stage is never charged again. Workspace credits are spent per stage that runs;\n' +
|
|
14046
|
+
'the result line reports what THIS run charged. `testsprite usage` shows your balance.\n' +
|
|
14047
|
+
'\nNext: review the printed table, then `testsprite test plan accept`.\n' +
|
|
14048
|
+
'\nExit codes:\n' +
|
|
14049
|
+
' 0 proposals staged for review\n' +
|
|
14050
|
+
' 1 a pipeline stage failed server-side (re-run to retry it)\n' +
|
|
14051
|
+
' 3 authentication error\n' +
|
|
14052
|
+
' 5 validation error\n' +
|
|
14053
|
+
' 7 timeout (re-run to continue)\n' +
|
|
14054
|
+
' 11 rate limited\n' +
|
|
14055
|
+
' 12 insufficient credits\n' +
|
|
13410
14056
|
'\n' +
|
|
13411
14057
|
GLOBAL_OPTS_HINT)
|
|
13412
14058
|
.action(async (cmdOpts, command) => {
|
|
@@ -13421,18 +14067,15 @@ function createTestPlanCommand(deps) {
|
|
|
13421
14067
|
});
|
|
13422
14068
|
plan
|
|
13423
14069
|
.command('accept')
|
|
14070
|
+
.summary('Turn staged proposals into test cases (free)')
|
|
13424
14071
|
.description('Convert staged proposals into real test cases (free) — all of them, or a subset with --only')
|
|
13425
|
-
.option('--project <id>', 'project id (
|
|
13426
|
-
.option('--only <ids...>', 'accept only these proposal ids (space- or comma-separated;
|
|
13427
|
-
'
|
|
13428
|
-
'
|
|
13429
|
-
.
|
|
13430
|
-
|
|
13431
|
-
'
|
|
13432
|
-
' - API test code is generated when the tests first run, not at accept.\n' +
|
|
13433
|
-
' - Accepting a subset discards the remaining staged proposals (the staging\n' +
|
|
13434
|
-
' area is cleared either way) — the output says how many were discarded.\n' +
|
|
13435
|
-
' - Nothing staged → exit 6 with a pointer at `test plan generate`.\n' +
|
|
14072
|
+
.option('--project <id>', 'project id (or set TESTSPRITE_PROJECT_ID)')
|
|
14073
|
+
.option('--only <ids...>', 'accept only these proposal ids from the `test plan generate` table (space- or comma-separated); ' +
|
|
14074
|
+
'the rest are discarded. Any id matching no staged proposal is a validation error.')
|
|
14075
|
+
.option('--idempotency-key <token>', 'idempotency token (1-256 ASCII chars; default: random UUID per invocation, pin one for safe retries)')
|
|
14076
|
+
.addHelpText('after', '\nAccepting adds no charge. API test code is generated when the tests first run. The staging\n' +
|
|
14077
|
+
'area is cleared either way (the output says how many proposals were discarded).\n' +
|
|
14078
|
+
'Nothing staged: exit 6, pointing at `test plan generate`.\n' +
|
|
13436
14079
|
'\n' +
|
|
13437
14080
|
GLOBAL_OPTS_HINT)
|
|
13438
14081
|
.action(async (cmdOpts, command) => {
|
|
@@ -13453,10 +14096,9 @@ export function createTestArtifactCommand(deps) {
|
|
|
13453
14096
|
// mirror the flat `test result/steps/get <id>` forms). Run-id semantics are
|
|
13454
14097
|
// preserved: the positional is still a run-id, not a test-id.
|
|
13455
14098
|
.command('get <run-id>', { isDefault: true })
|
|
14099
|
+
.summary('Download the failure bundle for a run')
|
|
13456
14100
|
.description([
|
|
13457
|
-
'Download the
|
|
13458
|
-
'',
|
|
13459
|
-
'Default <dir>: ./.testsprite/runs/<run-id>/',
|
|
14101
|
+
'Download the failure bundle for a run (result.json, failure.json, code, video, steps/, meta.json).',
|
|
13460
14102
|
'',
|
|
13461
14103
|
'Exit codes:',
|
|
13462
14104
|
' 0 bundle written successfully',
|
|
@@ -13466,12 +14108,8 @@ export function createTestArtifactCommand(deps) {
|
|
|
13466
14108
|
' 6 conflict — snapshot in flight (retried once)',
|
|
13467
14109
|
' 10 transport failure (.partial left on disk)',
|
|
13468
14110
|
].join('\n'))
|
|
13469
|
-
.option('--out <dir>',
|
|
13470
|
-
'
|
|
13471
|
-
'Parent must exist. The bundle dir itself is created if absent.',
|
|
13472
|
-
].join(' '))
|
|
13473
|
-
.option('--failed-only', 'Trim to the failed step ±1. The bundle is already failure-focused server-side, ' +
|
|
13474
|
-
'so this is usually a no-op; use `test steps <id>` for the full run trail.')
|
|
14111
|
+
.option('--out <dir>', 'directory to write the bundle into (default: ./.testsprite/runs/<run-id>/); the parent must exist')
|
|
14112
|
+
.option('--failed-only', 'trim to the failed step ±1 (usually a no-op; `test steps <id>` has the full trail)')
|
|
13475
14113
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
13476
14114
|
.action(async (runId, cmdOpts, command) => {
|
|
13477
14115
|
await runArtifactGet({
|
|
@@ -13490,10 +14128,19 @@ function createTestFailureCommand(deps) {
|
|
|
13490
14128
|
// `test failure get <test-id>` (grammar consistency). `failure summary`
|
|
13491
14129
|
// still routes explicitly; only the bare-noun form falls through to `get`.
|
|
13492
14130
|
.command('get <test-id>', { isDefault: true })
|
|
13493
|
-
.
|
|
13494
|
-
.
|
|
13495
|
-
|
|
13496
|
-
'
|
|
14131
|
+
.summary("Write the failure bundle for a test's latest failing run")
|
|
14132
|
+
.description([
|
|
14133
|
+
"Write the failure bundle for a test's latest failing run (same layout as `test artifact get`).",
|
|
14134
|
+
'',
|
|
14135
|
+
'Exit codes:',
|
|
14136
|
+
' 0 success',
|
|
14137
|
+
' 3 authentication error',
|
|
14138
|
+
' 4 test not found, or it has no failing run',
|
|
14139
|
+
' 5 validation error (bad --out)',
|
|
14140
|
+
' 10 transport failure',
|
|
14141
|
+
].join('\n'))
|
|
14142
|
+
.option('--out <dir>', 'directory to write the bundle into (default: print the envelope to stdout)')
|
|
14143
|
+
.option('--failed-only', 'with --out: trim to the failed step ±1 (usually a no-op; `test steps <id>` has the full trail)')
|
|
13497
14144
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
13498
14145
|
.action(async (testId, cmdOpts, command) => {
|
|
13499
14146
|
await runFailureGet({
|