@testsprite/testsprite-cli 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -30
- package/dist/commands/agent.js +44 -42
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.js +4 -7
- package/dist/commands/project.js +3 -2
- package/dist/commands/schedule.d.ts +120 -0
- package/dist/commands/schedule.js +487 -0
- package/dist/commands/test.d.ts +55 -1
- package/dist/commands/test.js +714 -183
- package/dist/commands/testlist.d.ts +88 -0
- package/dist/commands/testlist.js +747 -0
- package/dist/index.js +6 -2
- package/dist/lib/agent-targets.d.ts +13 -4
- package/dist/lib/agent-targets.js +11 -2
- package/dist/lib/conflict-reason.d.ts +30 -0
- package/dist/lib/conflict-reason.js +45 -0
- package/dist/lib/credentials.js +42 -1
- package/dist/lib/cron.d.ts +40 -0
- package/dist/lib/cron.js +190 -0
- package/dist/lib/dry-run/samples.js +177 -55
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.js +11 -0
- package/dist/lib/gh-output.d.ts +51 -4
- package/dist/lib/gh-output.js +149 -19
- package/dist/lib/http.d.ts +25 -0
- package/dist/lib/http.js +201 -3
- package/dist/lib/junit-report.d.ts +20 -2
- package/dist/lib/junit-report.js +38 -5
- package/dist/lib/poll.js +72 -36
- package/dist/lib/proxy.d.ts +16 -0
- package/dist/lib/proxy.js +19 -1
- package/dist/lib/response-schemas.d.ts +7 -0
- package/dist/lib/response-schemas.js +46 -14
- package/dist/lib/runs.types.d.ts +8 -3
- package/dist/lib/secret-file.d.ts +15 -0
- package/dist/lib/secret-file.js +82 -0
- package/dist/lib/target-url-preflight.d.ts +91 -0
- package/dist/lib/target-url-preflight.js +259 -0
- package/dist/lib/target-url.d.ts +22 -5
- package/dist/lib/target-url.js +60 -28
- package/dist/lib/testlist.types.d.ts +77 -0
- package/dist/lib/testlist.types.js +9 -0
- package/dist/lib/v3-advisory.d.ts +37 -4
- package/dist/lib/v3-advisory.js +47 -4
- package/dist/lib/wait-exit.d.ts +29 -0
- package/dist/lib/wait-exit.js +103 -0
- package/dist/version-guard.d.ts +10 -7
- package/dist/version-guard.js +37 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
|
@@ -7,6 +7,12 @@ const SAMPLE_TEST_ID_FAILED = 'test_8f2a4d10';
|
|
|
7
7
|
const SAMPLE_TEST_ID_PASSED = 'test_3a91bb02';
|
|
8
8
|
const SAMPLE_TEST_ID_BLOCKED = 'test_blocked_4f7a';
|
|
9
9
|
export const SAMPLE_RUN_ID = 'run_abc';
|
|
10
|
+
const SAMPLE_SCHEDULE_ID = 'sch_7d21ac48';
|
|
11
|
+
const SAMPLE_SCHEDULE_RUN_ID = 'exec_5c08f1b2';
|
|
12
|
+
// Documented sentinel for `test steps --run-id run_failed_sample --dry-run`:
|
|
13
|
+
// keeps wait flows on the default passed sample while still demonstrating a
|
|
14
|
+
// run-scoped failed step offline.
|
|
15
|
+
const SAMPLE_FAILED_RUN_ID = 'run_failed_sample';
|
|
10
16
|
// M3.4 rerun dry-run sample IDs
|
|
11
17
|
const SAMPLE_RERUN_ID_BE_NAMED = 'run_rerun_be_named';
|
|
12
18
|
const SAMPLE_RERUN_ID_BE_PRODUCER = 'run_rerun_be_producer';
|
|
@@ -87,6 +93,34 @@ const projects = [
|
|
|
87
93
|
updatedAt: '2026-05-04T19:30:00.000Z',
|
|
88
94
|
},
|
|
89
95
|
];
|
|
96
|
+
const schedule = {
|
|
97
|
+
scheduleId: SAMPLE_SCHEDULE_ID,
|
|
98
|
+
name: 'Nightly checkout',
|
|
99
|
+
enabled: true,
|
|
100
|
+
targetType: 'project',
|
|
101
|
+
targetId: SAMPLE_PROJECT_ID,
|
|
102
|
+
cron: '0 3 * * *',
|
|
103
|
+
timezone: 'UTC',
|
|
104
|
+
startAt: '2026-05-01T00:00:00.000Z',
|
|
105
|
+
endAt: null,
|
|
106
|
+
sendTo: null,
|
|
107
|
+
autoPausedAt: null,
|
|
108
|
+
lastRunId: SAMPLE_SCHEDULE_RUN_ID,
|
|
109
|
+
createdAt: '2026-05-01T00:00:00.000Z',
|
|
110
|
+
updatedAt: '2026-05-02T00:00:00.000Z',
|
|
111
|
+
};
|
|
112
|
+
// A finished run with one failure — more instructive for a dry-run learner than
|
|
113
|
+
// an all-green one, since it shows how the per-status counts relate to `status`.
|
|
114
|
+
const scheduleRun = {
|
|
115
|
+
runId: SAMPLE_SCHEDULE_RUN_ID,
|
|
116
|
+
scheduleId: SAMPLE_SCHEDULE_ID,
|
|
117
|
+
status: 'failed',
|
|
118
|
+
projectId: SAMPLE_PROJECT_ID,
|
|
119
|
+
testListId: null,
|
|
120
|
+
stats: { total: 4, passed: 3, failed: 1, blocked: 0, running: 0, cancelled: 0 },
|
|
121
|
+
createdAt: '2026-05-02T03:00:00.000Z',
|
|
122
|
+
updatedAt: '2026-05-02T03:06:41.000Z',
|
|
123
|
+
};
|
|
90
124
|
const tests = [
|
|
91
125
|
{
|
|
92
126
|
id: SAMPLE_TEST_ID_FAILED,
|
|
@@ -293,6 +327,116 @@ const failureSummary = {
|
|
|
293
327
|
rootCauseHypothesis: failureContext.failure.rootCauseHypothesis,
|
|
294
328
|
recommendedFixTarget: failureContext.failure.recommendedFixTarget,
|
|
295
329
|
};
|
|
330
|
+
const passedRunSample = {
|
|
331
|
+
runId: SAMPLE_RUN_ID,
|
|
332
|
+
testId: SAMPLE_TEST_ID_PASSED,
|
|
333
|
+
projectId: SAMPLE_PROJECT_ID,
|
|
334
|
+
userId: SAMPLE_USER_ID,
|
|
335
|
+
status: 'passed',
|
|
336
|
+
source: 'cli',
|
|
337
|
+
createdAt: '2026-05-15T19:32:00.000Z',
|
|
338
|
+
startedAt: '2026-05-15T19:32:05.000Z',
|
|
339
|
+
finishedAt: '2026-05-15T19:34:00.000Z',
|
|
340
|
+
codeVersion: 'v1',
|
|
341
|
+
targetUrl: SAMPLE_TARGET_URL,
|
|
342
|
+
createdFrom: null,
|
|
343
|
+
failedStepIndex: null,
|
|
344
|
+
failureKind: null,
|
|
345
|
+
error: null,
|
|
346
|
+
videoUrl: null,
|
|
347
|
+
stepSummary: {
|
|
348
|
+
total: 2,
|
|
349
|
+
completed: 2,
|
|
350
|
+
passedCount: 2,
|
|
351
|
+
failedCount: 0,
|
|
352
|
+
},
|
|
353
|
+
// Representative per-run steps so `test steps --run-id <id> --dry-run`
|
|
354
|
+
// demonstrates real output instead of an empty list (the generic
|
|
355
|
+
// `/runs/{runId}` sample is also used by `test wait`, which ignores steps).
|
|
356
|
+
steps: [
|
|
357
|
+
{
|
|
358
|
+
stepIndex: '0001',
|
|
359
|
+
type: 'action',
|
|
360
|
+
action: 'navigate',
|
|
361
|
+
status: 'passed',
|
|
362
|
+
description: 'Open the target URL',
|
|
363
|
+
error: null,
|
|
364
|
+
screenshotUrl: null,
|
|
365
|
+
htmlSnapshotUrl: null,
|
|
366
|
+
createdAt: '2026-05-15T19:32:10.000Z',
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
stepIndex: '0002',
|
|
370
|
+
type: 'assertion',
|
|
371
|
+
action: 'assert_visible',
|
|
372
|
+
status: 'passed',
|
|
373
|
+
description: 'Dashboard heading is visible',
|
|
374
|
+
error: null,
|
|
375
|
+
screenshotUrl: null,
|
|
376
|
+
htmlSnapshotUrl: null,
|
|
377
|
+
createdAt: '2026-05-15T19:32:20.000Z',
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
};
|
|
381
|
+
const failedRunSample = {
|
|
382
|
+
runId: SAMPLE_FAILED_RUN_ID,
|
|
383
|
+
testId: SAMPLE_TEST_ID_FAILED,
|
|
384
|
+
projectId: SAMPLE_PROJECT_ID,
|
|
385
|
+
userId: SAMPLE_USER_ID,
|
|
386
|
+
status: 'failed',
|
|
387
|
+
source: 'cli',
|
|
388
|
+
createdAt: '2026-05-15T19:32:00.000Z',
|
|
389
|
+
startedAt: '2026-05-15T19:32:05.000Z',
|
|
390
|
+
finishedAt: '2026-05-15T19:34:00.000Z',
|
|
391
|
+
codeVersion: 'v1',
|
|
392
|
+
targetUrl: SAMPLE_TARGET_URL,
|
|
393
|
+
createdFrom: null,
|
|
394
|
+
failedStepIndex: 3,
|
|
395
|
+
failureKind: 'assertion',
|
|
396
|
+
error: 'Expected billing status badge to be visible, but it was not found.',
|
|
397
|
+
videoUrl: null,
|
|
398
|
+
stepSummary: {
|
|
399
|
+
total: 3,
|
|
400
|
+
completed: 3,
|
|
401
|
+
passedCount: 2,
|
|
402
|
+
failedCount: 1,
|
|
403
|
+
},
|
|
404
|
+
steps: [
|
|
405
|
+
{
|
|
406
|
+
stepIndex: '0001',
|
|
407
|
+
type: 'action',
|
|
408
|
+
action: 'navigate',
|
|
409
|
+
status: 'passed',
|
|
410
|
+
description: 'Open the target URL',
|
|
411
|
+
error: null,
|
|
412
|
+
screenshotUrl: null,
|
|
413
|
+
htmlSnapshotUrl: null,
|
|
414
|
+
createdAt: '2026-05-15T19:32:10.000Z',
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
stepIndex: '0002',
|
|
418
|
+
type: 'assertion',
|
|
419
|
+
action: 'assert_visible',
|
|
420
|
+
status: 'passed',
|
|
421
|
+
description: 'Dashboard heading is visible',
|
|
422
|
+
error: null,
|
|
423
|
+
screenshotUrl: null,
|
|
424
|
+
htmlSnapshotUrl: null,
|
|
425
|
+
createdAt: '2026-05-15T19:32:20.000Z',
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
stepIndex: '0003',
|
|
429
|
+
type: 'assertion',
|
|
430
|
+
action: 'assert_visible',
|
|
431
|
+
status: 'failed',
|
|
432
|
+
description: 'Billing status badge is visible',
|
|
433
|
+
error: 'Expected billing status badge to be visible, but it was not found.',
|
|
434
|
+
screenshotUrl: null,
|
|
435
|
+
htmlSnapshotUrl: null,
|
|
436
|
+
createdAt: '2026-05-15T19:32:30.000Z',
|
|
437
|
+
},
|
|
438
|
+
],
|
|
439
|
+
};
|
|
296
440
|
const PATH_PREFIX = '/api/cli/v1';
|
|
297
441
|
const ENTRIES = [
|
|
298
442
|
entry('whoami', 'GET', '/me', me),
|
|
@@ -623,57 +767,8 @@ const ENTRIES = [
|
|
|
623
767
|
// fix(2026-05-21): a duplicate failed-shape entry that appeared before
|
|
624
768
|
// this entry was removed; findSample first-match-wins was always
|
|
625
769
|
// returning status: "failed" for `test wait --dry-run`.
|
|
626
|
-
entry('getRun', 'GET',
|
|
627
|
-
|
|
628
|
-
testId: SAMPLE_TEST_ID_PASSED,
|
|
629
|
-
projectId: SAMPLE_PROJECT_ID,
|
|
630
|
-
userId: SAMPLE_USER_ID,
|
|
631
|
-
status: 'passed',
|
|
632
|
-
source: 'cli',
|
|
633
|
-
createdAt: '2026-05-15T19:32:00.000Z',
|
|
634
|
-
startedAt: '2026-05-15T19:32:05.000Z',
|
|
635
|
-
finishedAt: '2026-05-15T19:34:00.000Z',
|
|
636
|
-
codeVersion: 'v1',
|
|
637
|
-
targetUrl: SAMPLE_TARGET_URL,
|
|
638
|
-
createdFrom: null,
|
|
639
|
-
failedStepIndex: null,
|
|
640
|
-
failureKind: null,
|
|
641
|
-
error: null,
|
|
642
|
-
videoUrl: null,
|
|
643
|
-
stepSummary: {
|
|
644
|
-
total: 8,
|
|
645
|
-
completed: 8,
|
|
646
|
-
passedCount: 8,
|
|
647
|
-
failedCount: 0,
|
|
648
|
-
},
|
|
649
|
-
// Representative per-run steps so `test steps --run-id <id> --dry-run`
|
|
650
|
-
// demonstrates real output instead of an empty list (the generic
|
|
651
|
-
// `/runs/{runId}` sample is also used by `test wait`, which ignores steps).
|
|
652
|
-
steps: [
|
|
653
|
-
{
|
|
654
|
-
stepIndex: '0001',
|
|
655
|
-
type: 'action',
|
|
656
|
-
action: 'navigate',
|
|
657
|
-
status: 'passed',
|
|
658
|
-
description: 'Open the target URL',
|
|
659
|
-
error: null,
|
|
660
|
-
screenshotUrl: null,
|
|
661
|
-
htmlSnapshotUrl: null,
|
|
662
|
-
createdAt: '2026-05-15T19:32:10.000Z',
|
|
663
|
-
},
|
|
664
|
-
{
|
|
665
|
-
stepIndex: '0002',
|
|
666
|
-
type: 'assertion',
|
|
667
|
-
action: 'assert_visible',
|
|
668
|
-
status: 'passed',
|
|
669
|
-
description: 'Dashboard heading is visible',
|
|
670
|
-
error: null,
|
|
671
|
-
screenshotUrl: null,
|
|
672
|
-
htmlSnapshotUrl: null,
|
|
673
|
-
createdAt: '2026-05-15T19:32:20.000Z',
|
|
674
|
-
},
|
|
675
|
-
],
|
|
676
|
-
}),
|
|
770
|
+
entry('getRun', 'GET', `/runs/${SAMPLE_FAILED_RUN_ID}`, failedRunSample),
|
|
771
|
+
entry('getRun', 'GET', '/runs/{runId}', passedRunSample),
|
|
677
772
|
// DEV-331 piece 3 — POST /runs/{runId}/cancel. Method-guarded in
|
|
678
773
|
// `findSample` (POST vs `getRun`'s GET), so this can't be shadowed by the
|
|
679
774
|
// broader `/runs/{runId}` pattern above despite sharing its path prefix.
|
|
@@ -704,6 +799,35 @@ const ENTRIES = [
|
|
|
704
799
|
},
|
|
705
800
|
alreadyCancelled: false,
|
|
706
801
|
}),
|
|
802
|
+
// Schedules. The `/schedules/{id}/runs` entry MUST come before the
|
|
803
|
+
// `/schedules/{id}` entries so the more specific path wins the regex match
|
|
804
|
+
// (first-match-wins).
|
|
805
|
+
entry('listScheduleRuns', 'GET', '/schedules/{scheduleId}/runs', {
|
|
806
|
+
runs: [scheduleRun],
|
|
807
|
+
}),
|
|
808
|
+
entry('listSchedules', 'GET', '/schedules', { schedules: [schedule] }),
|
|
809
|
+
// `schedule create --dry-run` exits before the HTTP client is built, so this
|
|
810
|
+
// sample is not fetched. Registered as a shape-guard only, same as
|
|
811
|
+
// `deleteBatch` above.
|
|
812
|
+
entry('createSchedule', 'POST', '/schedules', { scheduleId: 'sch_dryrun_2026' }),
|
|
813
|
+
entry('getSchedule', 'GET', '/schedules/{scheduleId}', schedule),
|
|
814
|
+
// Echoes the requested change so a caller can confirm the flags they passed
|
|
815
|
+
// reached the body, rather than showing an unrelated canned schedule.
|
|
816
|
+
entry('updateSchedule', 'PATCH', '/schedules/{scheduleId}', (req) => {
|
|
817
|
+
const patch = req != null && typeof req === 'object' ? req : {};
|
|
818
|
+
return {
|
|
819
|
+
...schedule,
|
|
820
|
+
...(typeof patch.name === 'string' ? { name: patch.name } : {}),
|
|
821
|
+
...(typeof patch.enabled === 'boolean' ? { enabled: patch.enabled } : {}),
|
|
822
|
+
...(typeof patch.cron === 'string' ? { cron: patch.cron } : {}),
|
|
823
|
+
...(typeof patch.timezone === 'string' ? { timezone: patch.timezone } : {}),
|
|
824
|
+
...(typeof patch.sendTo === 'string' ? { sendTo: patch.sendTo } : {}),
|
|
825
|
+
updatedAt: '2026-05-16T00:00:00.000Z',
|
|
826
|
+
};
|
|
827
|
+
}),
|
|
828
|
+
entry('deleteSchedule', 'DELETE', '/schedules/{scheduleId}', {
|
|
829
|
+
scheduleId: SAMPLE_SCHEDULE_ID,
|
|
830
|
+
}),
|
|
707
831
|
];
|
|
708
832
|
function entry(operationId, method, pathTemplate, body) {
|
|
709
833
|
// Convert `/tests/{testId}/code` → /^\/tests\/[^/]+\/code$/
|
|
@@ -742,10 +866,8 @@ export function findSample(method, url, requestBody) {
|
|
|
742
866
|
const pathOnly = extractPath(url);
|
|
743
867
|
for (const e of ENTRIES) {
|
|
744
868
|
if (e.method === upper && e.pattern.test(pathOnly)) {
|
|
745
|
-
// Rebind body so
|
|
746
|
-
//
|
|
747
|
-
// code can keep calling `e.body` as-before (no API break for tests
|
|
748
|
-
// that call `findSample` directly).
|
|
869
|
+
// Rebind body so downstream code can call `e.body` as before while
|
|
870
|
+
// still preserving the original lazy factory semantics.
|
|
749
871
|
return { ...e, body: () => e.body(requestBody) };
|
|
750
872
|
}
|
|
751
873
|
}
|
package/dist/lib/errors.d.ts
CHANGED
|
@@ -11,6 +11,15 @@ export declare function isErrorCode(value: unknown): value is ErrorCode;
|
|
|
11
11
|
* not by exit code.
|
|
12
12
|
*/
|
|
13
13
|
export declare function exitCodeFor(code: ErrorCode): number;
|
|
14
|
+
/**
|
|
15
|
+
* Whether an error code is an authentication failure. DERIVED from the single
|
|
16
|
+
* `exitCodeFor` mapping (auth === exit 3) rather than a second hand-maintained
|
|
17
|
+
* list of code strings: a future `AUTH_*` code gets classified as auth the
|
|
18
|
+
* moment it is given an exit-3 row, so it can never be present in one place and
|
|
19
|
+
* missing in the other. The `ERROR_CODES` membership check keeps `exitCodeFor`
|
|
20
|
+
* off unknown/out-of-contract strings (its switch has no default).
|
|
21
|
+
*/
|
|
22
|
+
export declare function isAuthCode(code: string): boolean;
|
|
14
23
|
export declare class CLIError extends Error {
|
|
15
24
|
readonly exitCode: number;
|
|
16
25
|
constructor(message: string, exitCode?: number);
|
package/dist/lib/errors.js
CHANGED
|
@@ -102,6 +102,17 @@ export function exitCodeFor(code) {
|
|
|
102
102
|
return 1;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Whether an error code is an authentication failure. DERIVED from the single
|
|
107
|
+
* `exitCodeFor` mapping (auth === exit 3) rather than a second hand-maintained
|
|
108
|
+
* list of code strings: a future `AUTH_*` code gets classified as auth the
|
|
109
|
+
* moment it is given an exit-3 row, so it can never be present in one place and
|
|
110
|
+
* missing in the other. The `ERROR_CODES` membership check keeps `exitCodeFor`
|
|
111
|
+
* off unknown/out-of-contract strings (its switch has no default).
|
|
112
|
+
*/
|
|
113
|
+
export function isAuthCode(code) {
|
|
114
|
+
return ERROR_CODES.includes(code) && exitCodeFor(code) === 3;
|
|
115
|
+
}
|
|
105
116
|
export class CLIError extends Error {
|
|
106
117
|
exitCode;
|
|
107
118
|
constructor(message, exitCode = 1) {
|
package/dist/lib/gh-output.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CI-native output layer for the
|
|
3
|
-
* the withdrawn top-level `ci` command per the #264 review).
|
|
2
|
+
* CI-native output layer for the run path (issue #99, reshaped from
|
|
3
|
+
* the withdrawn top-level `ci` command per the #264 review). Covers both a
|
|
4
|
+
* single `test run <test-id> --wait` and the `test run --all --wait` batch.
|
|
4
5
|
*
|
|
5
|
-
* `
|
|
6
|
+
* A `--wait` run presents its result in the formats CI consumes:
|
|
6
7
|
* (a) a stable machine summary `{total, passed, failed, timedOut, runs[]}`
|
|
7
8
|
* written to `--summary-file <path>` when requested,
|
|
8
9
|
* (b) a Markdown results table appended to `$GITHUB_STEP_SUMMARY` when
|
|
@@ -33,8 +34,31 @@ export interface CiSummary {
|
|
|
33
34
|
* defensive: it reads the same `accepted[]` rows the automation contract
|
|
34
35
|
* documents, and anything unparseable (dry-run envelope, partial output
|
|
35
36
|
* after a timeout) reduces to an empty run list rather than a crash.
|
|
37
|
+
*
|
|
38
|
+
* Non-dispatched work (`deferred` / `conflicts` / `notFound`) is folded in as
|
|
39
|
+
* non-passed rows: those buckets already force a non-zero exit (deferred /
|
|
40
|
+
* timeout → 7, all-conflict → 6) but were previously absent from the summary,
|
|
41
|
+
* so a partial batch like `1 accepted passed + 1 deferred` read as "1/1 passed"
|
|
42
|
+
* with no annotation. (`skippedFrontend` / `skippedIntegration` are NOT folded
|
|
43
|
+
* in — they exit 0 and are the Action layer's allow-partial concern.)
|
|
44
|
+
*/
|
|
45
|
+
export declare function summarizeAcceptedPayload(capturedJson: string, opts?: {
|
|
46
|
+
notFoundNote?: string;
|
|
47
|
+
}): CiSummary;
|
|
48
|
+
/**
|
|
49
|
+
* Reduce a single `test run <test-id> --wait` result into the same CI summary
|
|
50
|
+
* shape as the batch path, so `--gh-output` / `--summary-file` behave
|
|
51
|
+
* identically for a one-test CI job. Unlike the batch envelope, a single
|
|
52
|
+
* RunResponse carries `error` as a raw string (not `{ message }`) and
|
|
53
|
+
* `dashboardUrl` as `string | null`; both are normalized here.
|
|
36
54
|
*/
|
|
37
|
-
export declare function
|
|
55
|
+
export declare function summarizeSingleRun(run: {
|
|
56
|
+
testId?: string;
|
|
57
|
+
runId?: string;
|
|
58
|
+
status?: string;
|
|
59
|
+
dashboardUrl?: string | null;
|
|
60
|
+
error?: string | null;
|
|
61
|
+
}): CiSummary;
|
|
38
62
|
/** Markdown table for the GitHub job summary. */
|
|
39
63
|
export declare function renderJobSummaryMarkdown(summary: CiSummary): string;
|
|
40
64
|
/**
|
|
@@ -59,4 +83,27 @@ export declare function emitGithubOutputs(summary: CiSummary, env: NodeJS.Proces
|
|
|
59
83
|
annotations?: (line: string) => void;
|
|
60
84
|
}, opts?: {
|
|
61
85
|
force?: boolean;
|
|
86
|
+
label?: string;
|
|
62
87
|
}): void;
|
|
88
|
+
/**
|
|
89
|
+
* Emit the CI artifacts for a `--wait` run: the machine summary file (when
|
|
90
|
+
* `--summary-file` is set) and the GitHub-native annotations + job-summary table
|
|
91
|
+
* (when `--gh-output` or `GITHUB_ACTIONS=true`). One shared implementation for
|
|
92
|
+
* every `--wait` command — `test run` (single + `--all`), `test rerun`, and
|
|
93
|
+
* `testlist run` — so the four copies of this block can no longer drift (a
|
|
94
|
+
* per-copy fix like the `notFound` fold reaching only one of them is what this
|
|
95
|
+
* consolidates away). The caller reduces its own envelope to a `CiSummary` first
|
|
96
|
+
* (`summarizeAcceptedPayload` for a batch, `summarizeSingleRun` for one run);
|
|
97
|
+
* this owns only the two sinks and their best-effort writes. `label` names the
|
|
98
|
+
* command in the failure messages (`[run]` / `[rerun]` / `[testlist run]`).
|
|
99
|
+
* Both writes are best-effort — a sink throwing must never change the exit code.
|
|
100
|
+
*/
|
|
101
|
+
export declare function emitCiArtifacts(summary: CiSummary, opts: {
|
|
102
|
+
ghOutput?: boolean;
|
|
103
|
+
summaryFile?: string;
|
|
104
|
+
output?: string;
|
|
105
|
+
}, io: {
|
|
106
|
+
env: NodeJS.ProcessEnv;
|
|
107
|
+
stdout: (line: string) => void;
|
|
108
|
+
stderr: (line: string) => void;
|
|
109
|
+
}, label: string): void;
|
package/dist/lib/gh-output.js
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
|
+
import { appendFileSync, writeFileSync } from 'node:fs';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* (a) a stable machine summary `{total, passed, failed, timedOut, runs[]}`
|
|
7
|
-
* written to `--summary-file <path>` when requested,
|
|
8
|
-
* (b) a Markdown results table appended to `$GITHUB_STEP_SUMMARY` when
|
|
9
|
-
* running under GitHub Actions,
|
|
10
|
-
* (c) one `::error::` workflow-command line per non-passed run so failures
|
|
11
|
-
* annotate the PR checks tab.
|
|
12
|
-
* Activation: `GITHUB_ACTIONS=true` in the environment, or the explicit
|
|
13
|
-
* `--gh-output` flag (which forces the annotations even off-Actions, so the
|
|
14
|
-
* behavior is previewable locally). All writes are best-effort: a broken
|
|
15
|
-
* summary file must never mask the batch gate's exit code.
|
|
3
|
+
* Reduce a non-dispatched bucket (`deferred` / `conflicts` / `notFound`) into
|
|
4
|
+
* CI rows. Items are either bare testId strings (`notFound`) or
|
|
5
|
+
* `{ testId, currentRunId? }` objects; both shapes are handled. `note` becomes
|
|
6
|
+
* the row's error text so the annotation explains why the item did not run.
|
|
16
7
|
*/
|
|
8
|
+
function bucketRows(bucket, status, note) {
|
|
9
|
+
if (!Array.isArray(bucket))
|
|
10
|
+
return [];
|
|
11
|
+
return bucket.map(item => {
|
|
12
|
+
const rec = item !== null && typeof item === 'object' ? item : undefined;
|
|
13
|
+
const testId = typeof item === 'string' ? item : typeof rec?.testId === 'string' ? rec.testId : '';
|
|
14
|
+
const currentRunId = typeof rec?.currentRunId === 'string' ? rec.currentRunId : undefined;
|
|
15
|
+
return {
|
|
16
|
+
testId,
|
|
17
|
+
status,
|
|
18
|
+
...(currentRunId ? { runId: currentRunId } : {}),
|
|
19
|
+
error: note,
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
}
|
|
17
23
|
/**
|
|
18
24
|
* Reduce the batch command's JSON payload into the CI summary. The parse is
|
|
19
25
|
* defensive: it reads the same `accepted[]` rows the automation contract
|
|
20
26
|
* documents, and anything unparseable (dry-run envelope, partial output
|
|
21
27
|
* after a timeout) reduces to an empty run list rather than a crash.
|
|
28
|
+
*
|
|
29
|
+
* Non-dispatched work (`deferred` / `conflicts` / `notFound`) is folded in as
|
|
30
|
+
* non-passed rows: those buckets already force a non-zero exit (deferred /
|
|
31
|
+
* timeout → 7, all-conflict → 6) but were previously absent from the summary,
|
|
32
|
+
* so a partial batch like `1 accepted passed + 1 deferred` read as "1/1 passed"
|
|
33
|
+
* with no annotation. (`skippedFrontend` / `skippedIntegration` are NOT folded
|
|
34
|
+
* in — they exit 0 and are the Action layer's allow-partial concern.)
|
|
22
35
|
*/
|
|
23
|
-
export function summarizeAcceptedPayload(capturedJson) {
|
|
36
|
+
export function summarizeAcceptedPayload(capturedJson, opts = {}) {
|
|
24
37
|
let parsed;
|
|
25
38
|
try {
|
|
26
39
|
parsed = JSON.parse(capturedJson);
|
|
@@ -32,7 +45,7 @@ export function summarizeAcceptedPayload(capturedJson) {
|
|
|
32
45
|
// `JSON.parse('null')` and non-object payloads are valid JSON but carry no
|
|
33
46
|
// batch envelope — treat them like unparseable input instead of crashing.
|
|
34
47
|
const payload = parsed !== null && typeof parsed === 'object' ? parsed : {};
|
|
35
|
-
const
|
|
48
|
+
const acceptedRows = Array.isArray(payload.accepted)
|
|
36
49
|
? payload.accepted
|
|
37
50
|
.filter((entry) => entry !== null && typeof entry === 'object')
|
|
38
51
|
.map(row => {
|
|
@@ -48,11 +61,62 @@ export function summarizeAcceptedPayload(capturedJson) {
|
|
|
48
61
|
};
|
|
49
62
|
})
|
|
50
63
|
: [];
|
|
64
|
+
const rows = [
|
|
65
|
+
...acceptedRows,
|
|
66
|
+
...bucketRows(payload.deferred, 'deferred', 'rate-deferred (not dispatched)'),
|
|
67
|
+
...bucketRows(payload.conflicts, 'conflict', 'already in flight (not dispatched)'),
|
|
68
|
+
// Default note is `test rerun`'s cause (a not-found id has no replayable
|
|
69
|
+
// run). `testlist run` passes its own — a not-found `--case` id is one that
|
|
70
|
+
// is not a member of the list — so the annotation/artifact don't state the
|
|
71
|
+
// wrong reason on the surface this whole layer exists to serve.
|
|
72
|
+
...bucketRows(payload.notFound, 'not_found', opts.notFoundNote ?? 'no replayable run (not dispatched)'),
|
|
73
|
+
];
|
|
51
74
|
const passed = rows.filter(row => row.status === 'passed').length;
|
|
52
75
|
const timedOut = rows.filter(row => row.status === 'timeout').length;
|
|
53
76
|
const failed = rows.length - passed - timedOut;
|
|
54
77
|
return { total: rows.length, passed, failed, timedOut, runs: rows };
|
|
55
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Reduce a single `test run <test-id> --wait` result into the same CI summary
|
|
81
|
+
* shape as the batch path, so `--gh-output` / `--summary-file` behave
|
|
82
|
+
* identically for a one-test CI job. Unlike the batch envelope, a single
|
|
83
|
+
* RunResponse carries `error` as a raw string (not `{ message }`) and
|
|
84
|
+
* `dashboardUrl` as `string | null`; both are normalized here.
|
|
85
|
+
*/
|
|
86
|
+
export function summarizeSingleRun(run) {
|
|
87
|
+
const row = {
|
|
88
|
+
testId: String(run.testId ?? ''),
|
|
89
|
+
...(typeof run.runId === 'string' ? { runId: run.runId } : {}),
|
|
90
|
+
status: String(run.status ?? 'unknown'),
|
|
91
|
+
...(typeof run.dashboardUrl === 'string' ? { dashboardUrl: run.dashboardUrl } : {}),
|
|
92
|
+
...(typeof run.error === 'string' && run.error.length > 0 ? { error: run.error } : {}),
|
|
93
|
+
};
|
|
94
|
+
const passed = row.status === 'passed' ? 1 : 0;
|
|
95
|
+
const timedOut = row.status === 'timeout' ? 1 : 0;
|
|
96
|
+
const failed = 1 - passed - timedOut;
|
|
97
|
+
return { total: 1, passed, failed, timedOut, runs: [row] };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Escape a value for a Markdown table cell. A raw `|` would break the column
|
|
101
|
+
* layout and a CR/LF would inject extra Markdown lines (rows are newline-joined)
|
|
102
|
+
* — the same injection class the annotation escaping guards against, on the
|
|
103
|
+
* step-summary surface.
|
|
104
|
+
*/
|
|
105
|
+
function escapeTableCell(value) {
|
|
106
|
+
return value.replace(/\|/g, '\\|').replace(/[\r\n]+/g, ' ');
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Escape a URL for a Markdown `[text](url)` link: a literal `)` closes the link
|
|
110
|
+
* early and whitespace / `|` / CR-LF break the link or the surrounding cell.
|
|
111
|
+
*/
|
|
112
|
+
function escapeMarkdownUrl(url) {
|
|
113
|
+
return url
|
|
114
|
+
.replace(/[\r\n]+/g, '')
|
|
115
|
+
.replace(/ /g, '%20')
|
|
116
|
+
.replace(/\(/g, '%28')
|
|
117
|
+
.replace(/\)/g, '%29')
|
|
118
|
+
.replace(/\|/g, '%7C');
|
|
119
|
+
}
|
|
56
120
|
/** Markdown table for the GitHub job summary. */
|
|
57
121
|
export function renderJobSummaryMarkdown(summary) {
|
|
58
122
|
return [
|
|
@@ -62,10 +126,33 @@ export function renderJobSummaryMarkdown(summary) {
|
|
|
62
126
|
'',
|
|
63
127
|
'| Test | Status | Run |',
|
|
64
128
|
'| --- | --- | --- |',
|
|
65
|
-
...summary.runs.map(row =>
|
|
129
|
+
...summary.runs.map(row => {
|
|
130
|
+
const run = row.dashboardUrl
|
|
131
|
+
? `[dashboard](${escapeMarkdownUrl(row.dashboardUrl)})`
|
|
132
|
+
: escapeTableCell(row.runId ?? '');
|
|
133
|
+
return `| ${escapeTableCell(row.testId)} | ${escapeTableCell(row.status)} | ${run} |`;
|
|
134
|
+
}),
|
|
66
135
|
'',
|
|
67
136
|
].join('\n');
|
|
68
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Escape a value destined for the DATA half of a workflow command (the text
|
|
140
|
+
* after `::`). Per GitHub's rules, `%`, CR and LF are percent-encoded so a raw
|
|
141
|
+
* multiline run error can never introduce a newline that starts a second
|
|
142
|
+
* `::command::` line in the Actions output stream (`%` first, so the encodings
|
|
143
|
+
* we add are not themselves re-encoded).
|
|
144
|
+
*/
|
|
145
|
+
function escapeCommandData(value) {
|
|
146
|
+
return value.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Escape a value destined for a command PROPERTY (e.g. `title=...`). Beyond the
|
|
150
|
+
* data rules, `:` and `,` are encoded so the value cannot terminate the
|
|
151
|
+
* property list or the command header.
|
|
152
|
+
*/
|
|
153
|
+
function escapeCommandProperty(value) {
|
|
154
|
+
return escapeCommandData(value).replace(/:/g, '%3A').replace(/,/g, '%2C');
|
|
155
|
+
}
|
|
69
156
|
/**
|
|
70
157
|
* Emit the GitHub-native surfaces. Self-gating on the standard env vars:
|
|
71
158
|
* `$GITHUB_STEP_SUMMARY` (a file path Actions provides) receives the Markdown
|
|
@@ -76,13 +163,14 @@ export function renderJobSummaryMarkdown(summary) {
|
|
|
76
163
|
* Both writes are best-effort: a broken summary file must not mask the gate.
|
|
77
164
|
*/
|
|
78
165
|
export function emitGithubOutputs(summary, env, sinks, opts = {}) {
|
|
166
|
+
const label = opts.label ?? 'run';
|
|
79
167
|
const summaryPath = env.GITHUB_STEP_SUMMARY;
|
|
80
168
|
if (typeof summaryPath === 'string' && summaryPath.length > 0) {
|
|
81
169
|
try {
|
|
82
170
|
sinks.appendFile(summaryPath, renderJobSummaryMarkdown(summary));
|
|
83
171
|
}
|
|
84
172
|
catch {
|
|
85
|
-
sinks.stderr(
|
|
173
|
+
sinks.stderr(`[${label}] could not append to GITHUB_STEP_SUMMARY; continuing`);
|
|
86
174
|
}
|
|
87
175
|
}
|
|
88
176
|
if (env.GITHUB_ACTIONS === 'true' || opts.force === true) {
|
|
@@ -92,8 +180,50 @@ export function emitGithubOutputs(summary, env, sinks, opts = {}) {
|
|
|
92
180
|
continue;
|
|
93
181
|
const detail = row.error !== undefined ? ` ${row.error}` : '';
|
|
94
182
|
const link = row.dashboardUrl !== undefined ? ` ${row.dashboardUrl}` : '';
|
|
95
|
-
|
|
183
|
+
// Escape both halves: a raw multiline run error (or a testId) must not be
|
|
184
|
+
// able to smuggle a second workflow command into the Actions stream.
|
|
185
|
+
const title = `TestSprite ${escapeCommandProperty(row.testId)}`;
|
|
186
|
+
const message = escapeCommandData(`status=${row.status}${detail}${link}`);
|
|
187
|
+
annotate(`::error title=${title}::${message}`);
|
|
96
188
|
}
|
|
97
189
|
}
|
|
98
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Emit the CI artifacts for a `--wait` run: the machine summary file (when
|
|
193
|
+
* `--summary-file` is set) and the GitHub-native annotations + job-summary table
|
|
194
|
+
* (when `--gh-output` or `GITHUB_ACTIONS=true`). One shared implementation for
|
|
195
|
+
* every `--wait` command — `test run` (single + `--all`), `test rerun`, and
|
|
196
|
+
* `testlist run` — so the four copies of this block can no longer drift (a
|
|
197
|
+
* per-copy fix like the `notFound` fold reaching only one of them is what this
|
|
198
|
+
* consolidates away). The caller reduces its own envelope to a `CiSummary` first
|
|
199
|
+
* (`summarizeAcceptedPayload` for a batch, `summarizeSingleRun` for one run);
|
|
200
|
+
* this owns only the two sinks and their best-effort writes. `label` names the
|
|
201
|
+
* command in the failure messages (`[run]` / `[rerun]` / `[testlist run]`).
|
|
202
|
+
* Both writes are best-effort — a sink throwing must never change the exit code.
|
|
203
|
+
*/
|
|
204
|
+
export function emitCiArtifacts(summary, opts, io, label) {
|
|
205
|
+
const ghEnabled = opts.ghOutput === true || io.env.GITHUB_ACTIONS === 'true';
|
|
206
|
+
if (!ghEnabled && opts.summaryFile === undefined)
|
|
207
|
+
return;
|
|
208
|
+
if (opts.summaryFile !== undefined) {
|
|
209
|
+
try {
|
|
210
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- `--summary-file` is an explicit operator-supplied CI-artifact output path; best-effort in try/catch.
|
|
211
|
+
writeFileSync(opts.summaryFile, `${JSON.stringify(summary, null, 2)}\n`, 'utf8');
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
io.stderr(`[${label}] could not write --summary-file ${opts.summaryFile}; continuing`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (ghEnabled) {
|
|
218
|
+
emitGithubOutputs(summary, io.env, {
|
|
219
|
+
stdout: io.stdout,
|
|
220
|
+
stderr: io.stderr,
|
|
221
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- `path` is the CI-provided `$GITHUB_STEP_SUMMARY` env path, never external input.
|
|
222
|
+
appendFile: (path, content) => appendFileSync(path, content, 'utf8'),
|
|
223
|
+
// Under --output json the run envelope owns stdout; workflow commands go
|
|
224
|
+
// to stderr instead (the Actions runner parses both streams).
|
|
225
|
+
annotations: opts.output === 'json' ? io.stderr : io.stdout,
|
|
226
|
+
}, { force: opts.ghOutput === true, label });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
99
229
|
//# sourceMappingURL=gh-output.js.map
|
package/dist/lib/http.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
2
|
import type { ErrorCode } from './errors.js';
|
|
3
3
|
import { ApiError } from './errors.js';
|
|
4
|
+
import type { CliTestListRunResponse } from './testlist.types.js';
|
|
4
5
|
import type { TriggerRunBody, TriggerRunResponse, RunResponse, RerunRequest, RerunResponse, BatchRerunRequest, BatchRerunResponse, BatchRunFreshRequest, BatchRunFreshResponse, ListRunsQuery, ListRunsResponse, CancelRunResponse } from './runs.types.js';
|
|
5
6
|
export type FetchImpl = typeof globalThis.fetch;
|
|
6
7
|
export type DebugEventKind = 'request' | 'response' | 'retry' | 'error';
|
|
@@ -87,6 +88,14 @@ export interface HttpClientOptions {
|
|
|
87
88
|
* `globalShutdown.signal` via the client factory.
|
|
88
89
|
*/
|
|
89
90
|
shutdownSignal?: AbortSignal;
|
|
91
|
+
/**
|
|
92
|
+
* Upper bound (bytes) on a successful JSON response body the client will
|
|
93
|
+
* buffer before parsing. A response whose declared `Content-Length` — or
|
|
94
|
+
* actual streamed size — exceeds this fails fast with a typed
|
|
95
|
+
* `PAYLOAD_TOO_LARGE` error instead of growing the heap without limit.
|
|
96
|
+
* Defaults to {@link MAX_RESPONSE_BYTES_DEFAULT} (64 MiB).
|
|
97
|
+
*/
|
|
98
|
+
maxResponseBytes?: number;
|
|
90
99
|
}
|
|
91
100
|
export interface RequestOptions<T = unknown> {
|
|
92
101
|
query?: Record<string, string | number | boolean | undefined>;
|
|
@@ -166,6 +175,7 @@ export declare class HttpClient {
|
|
|
166
175
|
private readonly onServerVersion?;
|
|
167
176
|
private readonly requestTimeoutMs;
|
|
168
177
|
private readonly shutdownSignal?;
|
|
178
|
+
private readonly maxResponseBytes;
|
|
169
179
|
constructor(options: HttpClientOptions);
|
|
170
180
|
/**
|
|
171
181
|
* Read the backend's supported-floor header off a response and forward it to
|
|
@@ -253,6 +263,21 @@ export declare class HttpClient {
|
|
|
253
263
|
idempotencyKey: string;
|
|
254
264
|
signal?: AbortSignal;
|
|
255
265
|
}): Promise<BatchRunFreshResponse>;
|
|
266
|
+
/**
|
|
267
|
+
* POST /api/cli/v1/testlist/{listId}/run
|
|
268
|
+
* Dispatch a test list's cases (optionally a `testIds` subset) per project
|
|
269
|
+
* with their configured environments; returns pollable runIds. `--wait` polls
|
|
270
|
+
* each `accepted[].runId`.
|
|
271
|
+
*
|
|
272
|
+
* `retryOnConflict: false` — a 409 here (every dispatched project is an
|
|
273
|
+
* MCP-mirrored view-only mirror) is a permanent condition, not a transient one.
|
|
274
|
+
*/
|
|
275
|
+
triggerTestListRun(listId: string, body: {
|
|
276
|
+
testIds?: string[];
|
|
277
|
+
}, options: {
|
|
278
|
+
idempotencyKey: string;
|
|
279
|
+
signal?: AbortSignal;
|
|
280
|
+
}): Promise<CliTestListRunResponse>;
|
|
256
281
|
/**
|
|
257
282
|
* GET /api/cli/v1/tests/{testId}/runs
|
|
258
283
|
* List a test's prior run history, newest-first.
|