@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
package/dist/lib/target-url.js
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
* CLI-side pre-flight guard for `--target-url`.
|
|
3
3
|
*
|
|
4
4
|
* Defense-in-depth: the backend is the trust boundary and performs DNS
|
|
5
|
-
* resolution.
|
|
6
|
-
* fast, friendly error before sending the request
|
|
7
|
-
* DNS rebinding (a public hostname that resolves to a private
|
|
8
|
-
*
|
|
5
|
+
* resolution. `assertNotLocal` below does **string/literal-only** checks
|
|
6
|
+
* to give a fast, friendly error before sending the request — it cannot by
|
|
7
|
+
* itself detect DNS rebinding (a public hostname that resolves to a private
|
|
8
|
+
* IP). That gap is closed one layer up: `target-url-preflight.ts` reuses
|
|
9
|
+
* `disallowedIpReason` (exported below) against the actually-*resolved*
|
|
10
|
+
* address before probing, so the same range list guards both the literal
|
|
11
|
+
* string and the DNS answer — not two drifting copies of it.
|
|
9
12
|
*
|
|
10
13
|
* CLI-side target-url guard (exit 5 on any rejection):
|
|
11
14
|
* - Reject non-http(s) schemes
|
|
@@ -13,7 +16,6 @@
|
|
|
13
16
|
* - Reject `169.254.0.0/16` link-local and the `169.254.169.254` metadata address
|
|
14
17
|
* - Reject RFC1918 literal IPv4 (10.x, 172.16-31.x, 192.168.x)
|
|
15
18
|
* - Reject IPv4-mapped IPv6 (`::ffff:…`), IPv6 link-local (`fe80::/10`), unique-local (`fc00::/7`)
|
|
16
|
-
* - Hostnames that resolve to private IPs are the backend's concern.
|
|
17
19
|
*/
|
|
18
20
|
import { ApiError } from './errors.js';
|
|
19
21
|
const LOCAL_DEV_HINT = 'Local-dev tests are out of scope for the CLI; use testsprite-mcp-plugin for the local tunnel.';
|
|
@@ -44,35 +46,62 @@ export function assertNotLocal(rawUrl) {
|
|
|
44
46
|
// IP literals are already dot-normalized by the WHATWG URL parser, so this
|
|
45
47
|
// only affects named hosts.
|
|
46
48
|
const host = parsed.hostname.toLowerCase().replace(/\.$/, '');
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
+
// 'localhost' is a name, not an IP literal, so it sits outside
|
|
50
|
+
// `disallowedIpReason` below (which classifies IPv4/IPv6 address forms).
|
|
51
|
+
if (host === 'localhost') {
|
|
49
52
|
throw localTargetError('target-url', 'localhost targets are not allowed', LOCAL_DEV_HINT);
|
|
50
53
|
}
|
|
54
|
+
const reason = disallowedIpReason(host);
|
|
55
|
+
if (reason !== undefined) {
|
|
56
|
+
throw localTargetError('target-url', reason, LOCAL_DEV_HINT);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Classify a bare IP-address literal — IPv4 dotted form, or IPv6 optionally
|
|
61
|
+
* wrapped in the `[...]` bracket notation `URL.hostname` uses — against the
|
|
62
|
+
* private/loopback/link-local/metadata blocklist. Returns the disallowed
|
|
63
|
+
* reason string, or `undefined` when the address is allowed.
|
|
64
|
+
*
|
|
65
|
+
* This is the single source of truth for the range list: `assertNotLocal`
|
|
66
|
+
* calls it for the literal `--target-url` string above, and the reachability
|
|
67
|
+
* preflight (`target-url-preflight.ts`) calls it again for a DNS-*resolved*
|
|
68
|
+
* address — a public-looking hostname whose A/AAAA record actually points
|
|
69
|
+
* at a private or metadata IP (DNS rebinding) is a distinct bypass from a
|
|
70
|
+
* literal private IP typed on the command line, and both need the same
|
|
71
|
+
* range list, not two drifting copies of it.
|
|
72
|
+
*/
|
|
73
|
+
export function disallowedIpReason(host) {
|
|
51
74
|
// IPv6 literals. Node's URL parser wraps IPv6 hosts in brackets and
|
|
52
75
|
// normalizes IPv4-mapped forms to hex (`http://[::ffff:127.0.0.1]` →
|
|
53
76
|
// hostname `[::ffff:7f00:1]`). A dotted-form string check alone would miss
|
|
54
77
|
// the normalized variant, so we strip the brackets and classify the
|
|
55
|
-
// address family explicitly.
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
// address family explicitly. A DNS-resolved IPv6 address arrives
|
|
79
|
+
// unbracketed already; stripping is a no-op for that shape.
|
|
80
|
+
const bare = host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host;
|
|
81
|
+
if (bare.includes(':')) {
|
|
82
|
+
return disallowedIpv6Reason(bare);
|
|
83
|
+
}
|
|
84
|
+
// Unspecified.
|
|
85
|
+
if (bare === '0.0.0.0') {
|
|
86
|
+
return 'localhost targets are not allowed';
|
|
58
87
|
}
|
|
59
88
|
// 127.0.0.0/8 loopback range.
|
|
60
|
-
if (/^127\.\d+\.\d+\.\d+$/.test(
|
|
61
|
-
|
|
89
|
+
if (/^127\.\d+\.\d+\.\d+$/.test(bare)) {
|
|
90
|
+
return 'loopback addresses are not allowed';
|
|
62
91
|
}
|
|
63
|
-
// AWS instance-metadata service
|
|
64
|
-
if (
|
|
65
|
-
|
|
92
|
+
// AWS instance-metadata service.
|
|
93
|
+
if (bare === '169.254.169.254') {
|
|
94
|
+
return '169.254.169.254 (AWS metadata service) is not allowed';
|
|
66
95
|
}
|
|
67
96
|
// 169.254.x.x link-local (IPv4).
|
|
68
|
-
if (/^169\.254\.\d+\.\d+$/.test(
|
|
69
|
-
|
|
97
|
+
if (/^169\.254\.\d+\.\d+$/.test(bare)) {
|
|
98
|
+
return 'link-local addresses are not allowed';
|
|
70
99
|
}
|
|
71
|
-
// RFC1918 literal IP addresses
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
throw localTargetError('target-url', 'private/RFC1918 addresses are not allowed', LOCAL_DEV_HINT);
|
|
100
|
+
// RFC1918 literal IP addresses.
|
|
101
|
+
if (isRfc1918Literal(bare)) {
|
|
102
|
+
return 'private/RFC1918 addresses are not allowed';
|
|
75
103
|
}
|
|
104
|
+
return undefined;
|
|
76
105
|
}
|
|
77
106
|
function isRfc1918Literal(host) {
|
|
78
107
|
// 10.0.0.0/8
|
|
@@ -91,32 +120,35 @@ function isRfc1918Literal(host) {
|
|
|
91
120
|
return false;
|
|
92
121
|
}
|
|
93
122
|
/**
|
|
94
|
-
*
|
|
123
|
+
* Classify disallowed IPv6 literals: loopback (`::1`), unspecified (`::`),
|
|
95
124
|
* IPv4-mapped (`::ffff:…`), link-local (`fe80::/10`), and unique-local
|
|
96
|
-
* (`fc00::/7`). `inner` is the bracket-stripped
|
|
125
|
+
* (`fc00::/7`). `inner` is the bracket-stripped host; callers are
|
|
126
|
+
* responsible for lowercasing (the URL parser already lowercases hostnames,
|
|
127
|
+
* a DNS-resolved address is emitted lowercase by Node).
|
|
97
128
|
*
|
|
98
129
|
* The IPv4-mapped class is rejected wholesale rather than decoding the
|
|
99
130
|
* embedded v4 address: no legitimate target is expressed as a mapped
|
|
100
131
|
* literal, and the hex-normalized form (`::ffff:7f00:1`) is error-prone to
|
|
101
132
|
* decode. This closes the `http://[::ffff:127.0.0.1]` SSRF-guard bypass.
|
|
102
133
|
*/
|
|
103
|
-
function
|
|
134
|
+
function disallowedIpv6Reason(inner) {
|
|
104
135
|
// Loopback (::1) and unspecified (::).
|
|
105
136
|
if (inner === '::1' || inner === '::') {
|
|
106
|
-
|
|
137
|
+
return 'localhost targets are not allowed';
|
|
107
138
|
}
|
|
108
139
|
// IPv4-mapped IPv6 (`::ffff:a.b.c.d`, normalized to `::ffff:hhhh:hhhh`).
|
|
109
140
|
if (inner.startsWith('::ffff:')) {
|
|
110
|
-
|
|
141
|
+
return 'IPv4-mapped IPv6 addresses are not allowed; use the IPv4 form or a hostname';
|
|
111
142
|
}
|
|
112
143
|
// Link-local fe80::/10 (first hextet fe80–febf).
|
|
113
144
|
if (/^fe[89ab][0-9a-f]:/.test(inner)) {
|
|
114
|
-
|
|
145
|
+
return 'link-local addresses are not allowed';
|
|
115
146
|
}
|
|
116
147
|
// Unique-local fc00::/7 (first hextet fc00–fdff).
|
|
117
148
|
if (/^f[cd][0-9a-f]{2}:/.test(inner)) {
|
|
118
|
-
|
|
149
|
+
return 'unique-local (private) addresses are not allowed';
|
|
119
150
|
}
|
|
151
|
+
return undefined;
|
|
120
152
|
}
|
|
121
153
|
function localTargetError(field, reason, hint) {
|
|
122
154
|
return ApiError.fromEnvelope({
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire shapes for the `/api/cli/v1/testlist/*` surface (CRUD).
|
|
3
|
+
*
|
|
4
|
+
* `testId` on a case IS the test's logical id (`test_case.key`) — the same id
|
|
5
|
+
* `test list` / `test get` return and `test run` accepts, so a case can be added
|
|
6
|
+
* to a list with no translation.
|
|
7
|
+
*/
|
|
8
|
+
import type { RunConflict } from './conflict-reason.js';
|
|
9
|
+
export interface CliProjectEnvironment {
|
|
10
|
+
projectId: string;
|
|
11
|
+
environmentName: string;
|
|
12
|
+
}
|
|
13
|
+
/** A test-list row (no cases) — `testlist list`. */
|
|
14
|
+
export interface CliTestList {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
orgId: string;
|
|
18
|
+
caseCount: number;
|
|
19
|
+
projectEnvironments: CliProjectEnvironment[];
|
|
20
|
+
lastExecutionId: string | null;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
}
|
|
24
|
+
/** One case inside a list — `testlist get`. */
|
|
25
|
+
export interface CliTestListCase {
|
|
26
|
+
/** The test's logical id (== `test_case.key`). */
|
|
27
|
+
testId: string;
|
|
28
|
+
type: 'frontend' | 'backend';
|
|
29
|
+
projectId: string;
|
|
30
|
+
projectName: string;
|
|
31
|
+
title: string | null;
|
|
32
|
+
category: string | null;
|
|
33
|
+
priority: string | null;
|
|
34
|
+
modified: string | null;
|
|
35
|
+
status: string | null;
|
|
36
|
+
}
|
|
37
|
+
/** Full detail incl. cases + stats — `testlist get` / after a mutation. */
|
|
38
|
+
export interface CliTestListDetail extends CliTestList {
|
|
39
|
+
cases: CliTestListCase[];
|
|
40
|
+
stats: {
|
|
41
|
+
total: number;
|
|
42
|
+
passed: number;
|
|
43
|
+
failed: number;
|
|
44
|
+
blocked: number;
|
|
45
|
+
running: number;
|
|
46
|
+
};
|
|
47
|
+
lastExecutionCreated: string | null;
|
|
48
|
+
}
|
|
49
|
+
export interface CliTestListListResponse {
|
|
50
|
+
items: CliTestList[];
|
|
51
|
+
}
|
|
52
|
+
export interface CliDeleteTestListResponse {
|
|
53
|
+
listId: string;
|
|
54
|
+
}
|
|
55
|
+
/** One dispatched run from `testlist run` — `runId` polls via `GET /runs/{runId}`. */
|
|
56
|
+
export interface CliTestListRunAccepted {
|
|
57
|
+
testId: string;
|
|
58
|
+
runId: string;
|
|
59
|
+
enqueuedAt: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* `testlist run` result. Mirrors the batch-run-fresh envelope so `--wait` reuses
|
|
63
|
+
* the same poll/summary tail. `conflicts[]` carry the in-flight `currentRunId`
|
|
64
|
+
* (poll it instead of retrying). `deferred[]` carries the cases the per-key
|
|
65
|
+
* run-rate budget could not admit this call (retry after ~60s). `notFound[]` is
|
|
66
|
+
* present on a PARTIAL `--case` miss — ids not in this list, skipped (a FULL miss
|
|
67
|
+
* is a 404). `reason` is set only when nothing dispatched (empty list).
|
|
68
|
+
*/
|
|
69
|
+
export interface CliTestListRunResponse {
|
|
70
|
+
accepted: CliTestListRunAccepted[];
|
|
71
|
+
conflicts: RunConflict[];
|
|
72
|
+
deferred: Array<{
|
|
73
|
+
testId: string;
|
|
74
|
+
}>;
|
|
75
|
+
notFound?: string[];
|
|
76
|
+
reason?: 'no_matching_cases' | 'empty_list';
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire shapes for the `/api/cli/v1/testlist/*` surface (CRUD).
|
|
3
|
+
*
|
|
4
|
+
* `testId` on a case IS the test's logical id (`test_case.key`) — the same id
|
|
5
|
+
* `test list` / `test get` return and `test run` accepts, so a case can be added
|
|
6
|
+
* to a list with no translation.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=testlist.types.js.map
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared V3-routing text surfaces
|
|
2
|
+
* Shared V3-routing text surfaces.
|
|
3
3
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `V3_ROUTING_ADVISORY`/`emitV3RoutingAdvisory` back `auth status` and
|
|
5
|
+
* `doctor`: `v3Enabled` on the `/me` response is the authoritative routing
|
|
6
|
+
* bit, and when it is on, some commands behave differently while the V3
|
|
7
|
+
* gaps stay open — the advisory names them. Copy lives here so both
|
|
8
|
+
* commands stay in sync.
|
|
9
|
+
*
|
|
10
|
+
* `targetUrlAdvisoryText`/`emitTargetUrlMismatchAdvisory` back the
|
|
11
|
+
* `--target-url` point-of-use advisory in `commands/test.ts` — a different,
|
|
12
|
+
* response-driven mechanism (see its own docblock below) that does not
|
|
13
|
+
* depend on `v3Enabled` at all.
|
|
7
14
|
*/
|
|
8
15
|
/** One-word routing label for the text card. */
|
|
9
16
|
export declare function routingLabel(v3Enabled: boolean): 'v3' | 'v2';
|
|
@@ -20,3 +27,29 @@ export declare function routingLabel(v3Enabled: boolean): 'v3' | 'v2';
|
|
|
20
27
|
export declare const V3_ROUTING_ADVISORY: string[];
|
|
21
28
|
/** Write the advisory to a stderr sink, one line per call. */
|
|
22
29
|
export declare function emitV3RoutingAdvisory(stderr: (line: string) => void): void;
|
|
30
|
+
/**
|
|
31
|
+
* Point-of-use advisory for `test run --target-url`, redesigned to be
|
|
32
|
+
* response-driven rather than assumption-driven. The original
|
|
33
|
+
* version probed `GET /me` for `v3Enabled` and warned on that ASSUMPTION —
|
|
34
|
+
* but the backend is the ground truth here, not a proxy for it. V3
|
|
35
|
+
* deliberately returns `targetUrl: ''` rather than echoing an override it
|
|
36
|
+
* did not apply ("so the response doesn't claim a target we didn't use"),
|
|
37
|
+
* while V2 echoes the real applied value. So the advisory now fires purely
|
|
38
|
+
* from comparing what the caller asked for against what the trigger
|
|
39
|
+
* response reports — it self-corrects the day the backend applies the
|
|
40
|
+
* override, needs no `v3Enabled` lookup (and so no extra `/me` round trip,
|
|
41
|
+
* no `X-CLI-Command` tagging machinery), and is exact rather than inferred.
|
|
42
|
+
*
|
|
43
|
+
* Deliberately type-agnostic in its wording (no "on the V3 path" claim):
|
|
44
|
+
* a mismatch is reported purely from the observed response, regardless of
|
|
45
|
+
* why the backend didn't apply the override.
|
|
46
|
+
*/
|
|
47
|
+
export declare function targetUrlAdvisoryText(requested: string, applied: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Compare the requested `--target-url` against what the trigger response
|
|
50
|
+
* reports and write the advisory when they differ. No-op when they match
|
|
51
|
+
* (the override was applied, or the caller didn't supply one — callers are
|
|
52
|
+
* expected to gate the `requested` argument on `opts.targetUrl !== undefined`
|
|
53
|
+
* themselves so this stays a pure comparison).
|
|
54
|
+
*/
|
|
55
|
+
export declare function emitTargetUrlMismatchAdvisory(stderr: (line: string) => void, requested: string, applied: string): void;
|
package/dist/lib/v3-advisory.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared V3-routing text surfaces
|
|
2
|
+
* Shared V3-routing text surfaces.
|
|
3
3
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `V3_ROUTING_ADVISORY`/`emitV3RoutingAdvisory` back `auth status` and
|
|
5
|
+
* `doctor`: `v3Enabled` on the `/me` response is the authoritative routing
|
|
6
|
+
* bit, and when it is on, some commands behave differently while the V3
|
|
7
|
+
* gaps stay open — the advisory names them. Copy lives here so both
|
|
8
|
+
* commands stay in sync.
|
|
9
|
+
*
|
|
10
|
+
* `targetUrlAdvisoryText`/`emitTargetUrlMismatchAdvisory` back the
|
|
11
|
+
* `--target-url` point-of-use advisory in `commands/test.ts` — a different,
|
|
12
|
+
* response-driven mechanism (see its own docblock below) that does not
|
|
13
|
+
* depend on `v3Enabled` at all.
|
|
7
14
|
*/
|
|
8
15
|
/** One-word routing label for the text card. */
|
|
9
16
|
export function routingLabel(v3Enabled) {
|
|
@@ -29,4 +36,40 @@ export function emitV3RoutingAdvisory(stderr) {
|
|
|
29
36
|
for (const line of V3_ROUTING_ADVISORY)
|
|
30
37
|
stderr(line);
|
|
31
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Point-of-use advisory for `test run --target-url`, redesigned to be
|
|
41
|
+
* response-driven rather than assumption-driven. The original
|
|
42
|
+
* version probed `GET /me` for `v3Enabled` and warned on that ASSUMPTION —
|
|
43
|
+
* but the backend is the ground truth here, not a proxy for it. V3
|
|
44
|
+
* deliberately returns `targetUrl: ''` rather than echoing an override it
|
|
45
|
+
* did not apply ("so the response doesn't claim a target we didn't use"),
|
|
46
|
+
* while V2 echoes the real applied value. So the advisory now fires purely
|
|
47
|
+
* from comparing what the caller asked for against what the trigger
|
|
48
|
+
* response reports — it self-corrects the day the backend applies the
|
|
49
|
+
* override, needs no `v3Enabled` lookup (and so no extra `/me` round trip,
|
|
50
|
+
* no `X-CLI-Command` tagging machinery), and is exact rather than inferred.
|
|
51
|
+
*
|
|
52
|
+
* Deliberately type-agnostic in its wording (no "on the V3 path" claim):
|
|
53
|
+
* a mismatch is reported purely from the observed response, regardless of
|
|
54
|
+
* why the backend didn't apply the override.
|
|
55
|
+
*/
|
|
56
|
+
export function targetUrlAdvisoryText(requested, applied) {
|
|
57
|
+
const appliedClause = applied.length > 0
|
|
58
|
+
? `the run will use ${applied} instead`
|
|
59
|
+
: 'the run reports no target URL for it';
|
|
60
|
+
return (`[advisory] --target-url ${requested} was not applied to this run — ${appliedClause}. ` +
|
|
61
|
+
`The run used its own configured environment.`);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Compare the requested `--target-url` against what the trigger response
|
|
65
|
+
* reports and write the advisory when they differ. No-op when they match
|
|
66
|
+
* (the override was applied, or the caller didn't supply one — callers are
|
|
67
|
+
* expected to gate the `requested` argument on `opts.targetUrl !== undefined`
|
|
68
|
+
* themselves so this stays a pure comparison).
|
|
69
|
+
*/
|
|
70
|
+
export function emitTargetUrlMismatchAdvisory(stderr, requested, applied) {
|
|
71
|
+
if (applied === requested)
|
|
72
|
+
return;
|
|
73
|
+
stderr(targetUrlAdvisoryText(requested, applied));
|
|
74
|
+
}
|
|
32
75
|
//# sourceMappingURL=v3-advisory.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ApiError, CLIError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* One member of a `--wait` fan-out poll (a single dispatched run's outcome).
|
|
4
|
+
* `status` is the terminal run status (`passed`/`failed`/`blocked`/…), or the
|
|
5
|
+
* synthesized `'timeout'` / `'error'` when the poll itself timed out or the
|
|
6
|
+
* run-read returned a typed `ApiError`. When `status === 'error'`, `error`
|
|
7
|
+
* carries that ApiError's `code` + `exitCode`.
|
|
8
|
+
*/
|
|
9
|
+
export interface WaitMemberResult {
|
|
10
|
+
testId?: string;
|
|
11
|
+
runId?: string;
|
|
12
|
+
status: string;
|
|
13
|
+
error?: {
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
exitCode?: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the process-level failure for a completed `--wait` fan-out, or `null`
|
|
21
|
+
* when every member passed. Shared by `test run --all` / `test rerun` and
|
|
22
|
+
* `testlist run` so their exit-code semantics can't drift.
|
|
23
|
+
*
|
|
24
|
+
* Precedence (see {@link WAIT_EXIT_PRIORITY}): auth / client-too-old → typed
|
|
25
|
+
* operational ApiError → timeout (7) → generic test-failure (1).
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveWaitFailure(results: readonly WaitMemberResult[], opts: {
|
|
28
|
+
timeoutSeconds: number;
|
|
29
|
+
}): CLIError | ApiError | null;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ApiError, CLIError, isAuthCode } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Exit-code precedence for a `--wait` fan-out, highest first. Ordered
|
|
4
|
+
* batch-wide-non-retriable → per-run → transient → timeout → generic:
|
|
5
|
+
* - auth (3) and CLIENT_TOO_OLD (14): a bad credential / too-old client fails
|
|
6
|
+
* EVERY poll and retrying can never succeed — batch-wide, so they top the
|
|
7
|
+
* table (a transient `RATE_LIMITED` "retry later" must never outrank them).
|
|
8
|
+
* - INSUFFICIENT_CREDITS (12) / FEATURE_GATED (13): per-run, non-retriable.
|
|
9
|
+
* - NOT_FOUND (4) / VALIDATION_ERROR (5) / CONFLICT (6): per-run.
|
|
10
|
+
* - RATE_LIMITED (11) / UNAVAILABLE (10): transient — a retry may help.
|
|
11
|
+
* - timeout (7): outranks only a generic failure.
|
|
12
|
+
* - generic (1): the floor (genuine test-fail / INTERNAL).
|
|
13
|
+
* A code NOT in this table folds into the generic bucket (never surfaced as an
|
|
14
|
+
* operational error), so an out-of-contract exit (0, 99, a leaked signal code)
|
|
15
|
+
* can neither preempt a real verdict nor produce a printed-failure-green-exit.
|
|
16
|
+
*/
|
|
17
|
+
const WAIT_EXIT_PRIORITY = [3, 14, 12, 13, 4, 5, 6, 11, 10, 7, 1];
|
|
18
|
+
/**
|
|
19
|
+
* A "typed operational" code is one that sits in the precedence table above the
|
|
20
|
+
* generic floor — known AND not the generic `1`. Everything else (unknown
|
|
21
|
+
* codes, `0`, INTERNAL/1) folds into the generic failure bucket.
|
|
22
|
+
*/
|
|
23
|
+
function isOperationalCode(exitCode) {
|
|
24
|
+
return (exitCode !== 1 && WAIT_EXIT_PRIORITY.includes(exitCode));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Index of `exitCode` in the precedence table (lower = higher priority). Only
|
|
28
|
+
* ever called on operational codes (see `isOperationalCode`), so the index is
|
|
29
|
+
* always valid.
|
|
30
|
+
*/
|
|
31
|
+
function priorityOf(exitCode) {
|
|
32
|
+
return WAIT_EXIT_PRIORITY.indexOf(exitCode);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the process-level failure for a completed `--wait` fan-out, or `null`
|
|
36
|
+
* when every member passed. Shared by `test run --all` / `test rerun` and
|
|
37
|
+
* `testlist run` so their exit-code semantics can't drift.
|
|
38
|
+
*
|
|
39
|
+
* Precedence (see {@link WAIT_EXIT_PRIORITY}): auth / client-too-old → typed
|
|
40
|
+
* operational ApiError → timeout (7) → generic test-failure (1).
|
|
41
|
+
*/
|
|
42
|
+
export function resolveWaitFailure(results, opts) {
|
|
43
|
+
const timedOut = results.filter(r => r.status === 'timeout');
|
|
44
|
+
const errored = results.filter((r) => r.status === 'error' && r.error !== undefined);
|
|
45
|
+
// A genuine test failure: terminal-not-passed, and not one of the synthesized
|
|
46
|
+
// timeout/typed-error members above.
|
|
47
|
+
const failed = results.filter(r => r.status !== 'passed' && r.status !== 'timeout' && !(r.status === 'error' && r.error));
|
|
48
|
+
// How many runs did NOT pass — used for the auth failure count so the message
|
|
49
|
+
// agrees with the "N failed/blocked" summary printed just above it.
|
|
50
|
+
const notPassed = results.filter(r => r.status !== 'passed').length;
|
|
51
|
+
// 1) Auth wins over everything — the credential is bad, not the test.
|
|
52
|
+
// Classified via the single `isAuthCode` source (derived from `exitCodeFor`)
|
|
53
|
+
// rather than a local `=== 3` so a future AUTH_* code can't be missed here.
|
|
54
|
+
const authErr = errored.find(r => isAuthCode(r.error.code));
|
|
55
|
+
if (authErr) {
|
|
56
|
+
return new CLIError(`${notPassed} run${notPassed !== 1 ? 's' : ''} failed — auth error (${authErr.error.code}): ${authErr.error.message}`, 3);
|
|
57
|
+
}
|
|
58
|
+
// 2) Any other typed operational ApiError, highest-priority first. Only codes
|
|
59
|
+
// IN the precedence table qualify — an unknown / out-of-contract code folds
|
|
60
|
+
// into the generic bucket below rather than being surfaced (or leaking a
|
|
61
|
+
// non-1 exit like 0/99). Routed through the ENVELOPE so `--output json`
|
|
62
|
+
// carries `error.code` — the machine-readable field this fix exists for;
|
|
63
|
+
// `ApiError.fromEnvelope` derives the exit via `exitCodeFor(code)`.
|
|
64
|
+
const operational = errored
|
|
65
|
+
.filter(r => isOperationalCode(r.error.exitCode ?? 1))
|
|
66
|
+
.sort((a, b) => priorityOf(a.error.exitCode) - priorityOf(b.error.exitCode))[0];
|
|
67
|
+
if (operational) {
|
|
68
|
+
return ApiError.fromEnvelope({
|
|
69
|
+
error: {
|
|
70
|
+
code: operational.error.code,
|
|
71
|
+
message: operational.error.message,
|
|
72
|
+
nextAction: '',
|
|
73
|
+
requestId: 'local',
|
|
74
|
+
details: { runId: operational.runId ?? null, testId: operational.testId ?? null },
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// 3) Timeout — outranks a generic failure so the operator gets resume/cancel
|
|
79
|
+
// guidance for the runs that didn't finish.
|
|
80
|
+
if (timedOut.length > 0) {
|
|
81
|
+
const runIds = timedOut.map(r => r.runId).filter((id) => Boolean(id));
|
|
82
|
+
return ApiError.fromEnvelope({
|
|
83
|
+
error: {
|
|
84
|
+
code: 'UNSUPPORTED',
|
|
85
|
+
message: `${timedOut.length} run${timedOut.length !== 1 ? 's' : ''} timed out.`,
|
|
86
|
+
nextAction: [
|
|
87
|
+
...runIds.map(rid => `Resume: testsprite test wait ${rid}`),
|
|
88
|
+
...runIds.map(rid => `Cancel: testsprite test cancel ${rid}`),
|
|
89
|
+
].join('\n'),
|
|
90
|
+
requestId: 'local',
|
|
91
|
+
details: { timedOutRunIds: runIds, timeoutSeconds: opts.timeoutSeconds },
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// 4) Generic test failures — genuine test-fails, INTERNAL (1), and any
|
|
96
|
+
// unknown / out-of-contract error code folded here.
|
|
97
|
+
const genericCount = failed.length + errored.filter(r => !isOperationalCode(r.error.exitCode ?? 1)).length;
|
|
98
|
+
if (genericCount > 0) {
|
|
99
|
+
return new CLIError(`${genericCount} run${genericCount !== 1 ? 's' : ''} failed.`, 1);
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=wait-exit.js.map
|
package/dist/version-guard.d.ts
CHANGED
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
* The logic lives here (rather than inline) so it can be unit-tested against the
|
|
10
10
|
* real implementation the entrypoint uses — not a copy.
|
|
11
11
|
*/
|
|
12
|
-
/**
|
|
12
|
+
/** Canonical supported range, pinned to package.json by the unit test. */
|
|
13
|
+
export declare const SUPPORTED_NODE_ENGINE = "^20.19.0 || ^22.13.0 || >=24";
|
|
14
|
+
/** Human-readable form of the supported range for startup errors. */
|
|
15
|
+
export declare const SUPPORTED_NODE_RANGE = "20.19+, 22.13+, or 24+";
|
|
13
16
|
export declare const MIN_SUPPORTED_NODE_MAJOR = 20;
|
|
14
17
|
/**
|
|
15
18
|
* Parse the leading major version number from a Node.js version string.
|
|
@@ -20,14 +23,14 @@ export declare const MIN_SUPPORTED_NODE_MAJOR = 20;
|
|
|
20
23
|
*/
|
|
21
24
|
export declare function parseMajorVersion(nodeVersion: string): number;
|
|
22
25
|
/**
|
|
23
|
-
* Decide whether the given Node.js version is
|
|
26
|
+
* Decide whether the given Node.js version is outside the supported engine range.
|
|
24
27
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* treated as "do not reject" so the guard never blocks on a
|
|
28
|
-
* cannot understand (the runtime would surface any
|
|
28
|
+
* Mirrors `^20.19.0 || ^22.13.0 || >=24`: Node 20 is supported from 20.19,
|
|
29
|
+
* Node 22 from 22.13, odd intermediate majors 21/23 are rejected, and 24+ is supported.
|
|
30
|
+
* An unparseable string is treated as "do not reject" so the guard never blocks on a
|
|
31
|
+
* version string it cannot understand (the runtime would surface any incompatibility).
|
|
29
32
|
*
|
|
30
33
|
* @param nodeVersion - a `process.versions.node` style string (e.g. `"18.19.1"`).
|
|
31
|
-
* @returns `true` when the runtime is
|
|
34
|
+
* @returns `true` when the runtime is unsupported and should be rejected.
|
|
32
35
|
*/
|
|
33
36
|
export declare function shouldRejectNodeVersion(nodeVersion: string): boolean;
|
package/dist/version-guard.js
CHANGED
|
@@ -9,8 +9,13 @@
|
|
|
9
9
|
* The logic lives here (rather than inline) so it can be unit-tested against the
|
|
10
10
|
* real implementation the entrypoint uses — not a copy.
|
|
11
11
|
*/
|
|
12
|
-
/**
|
|
12
|
+
/** Canonical supported range, pinned to package.json by the unit test. */
|
|
13
|
+
export const SUPPORTED_NODE_ENGINE = '^20.19.0 || ^22.13.0 || >=24';
|
|
14
|
+
/** Human-readable form of the supported range for startup errors. */
|
|
15
|
+
export const SUPPORTED_NODE_RANGE = '20.19+, 22.13+, or 24+';
|
|
13
16
|
export const MIN_SUPPORTED_NODE_MAJOR = 20;
|
|
17
|
+
const MIN_NODE_20_MINOR = 19;
|
|
18
|
+
const MIN_NODE_22_MINOR = 13;
|
|
14
19
|
/**
|
|
15
20
|
* Parse the leading major version number from a Node.js version string.
|
|
16
21
|
*
|
|
@@ -21,19 +26,42 @@ export const MIN_SUPPORTED_NODE_MAJOR = 20;
|
|
|
21
26
|
export function parseMajorVersion(nodeVersion) {
|
|
22
27
|
return Number(nodeVersion.split('.')[0]);
|
|
23
28
|
}
|
|
29
|
+
function parseMajorMinor(nodeVersion) {
|
|
30
|
+
const [majorRaw, minorRaw] = nodeVersion.split('.');
|
|
31
|
+
const major = Number(majorRaw);
|
|
32
|
+
// Preserve the old guard's behavior for injectable major-only versions such as "18".
|
|
33
|
+
const minor = minorRaw === undefined ? 0 : Number(minorRaw);
|
|
34
|
+
if (!Number.isInteger(major) || !Number.isInteger(minor) || major < 0 || minor < 0) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return { major, minor };
|
|
38
|
+
}
|
|
24
39
|
/**
|
|
25
|
-
* Decide whether the given Node.js version is
|
|
40
|
+
* Decide whether the given Node.js version is outside the supported engine range.
|
|
26
41
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* treated as "do not reject" so the guard never blocks on a
|
|
30
|
-
* cannot understand (the runtime would surface any
|
|
42
|
+
* Mirrors `^20.19.0 || ^22.13.0 || >=24`: Node 20 is supported from 20.19,
|
|
43
|
+
* Node 22 from 22.13, odd intermediate majors 21/23 are rejected, and 24+ is supported.
|
|
44
|
+
* An unparseable string is treated as "do not reject" so the guard never blocks on a
|
|
45
|
+
* version string it cannot understand (the runtime would surface any incompatibility).
|
|
31
46
|
*
|
|
32
47
|
* @param nodeVersion - a `process.versions.node` style string (e.g. `"18.19.1"`).
|
|
33
|
-
* @returns `true` when the runtime is
|
|
48
|
+
* @returns `true` when the runtime is unsupported and should be rejected.
|
|
34
49
|
*/
|
|
35
50
|
export function shouldRejectNodeVersion(nodeVersion) {
|
|
36
|
-
const
|
|
37
|
-
|
|
51
|
+
const parsed = parseMajorMinor(nodeVersion);
|
|
52
|
+
if (parsed === null)
|
|
53
|
+
return false;
|
|
54
|
+
const { major, minor } = parsed;
|
|
55
|
+
if (major < MIN_SUPPORTED_NODE_MAJOR)
|
|
56
|
+
return true;
|
|
57
|
+
if (major === 20)
|
|
58
|
+
return minor < MIN_NODE_20_MINOR;
|
|
59
|
+
if (major === 21)
|
|
60
|
+
return true;
|
|
61
|
+
if (major === 22)
|
|
62
|
+
return minor < MIN_NODE_22_MINOR;
|
|
63
|
+
if (major === 23)
|
|
64
|
+
return true;
|
|
65
|
+
return false;
|
|
38
66
|
}
|
|
39
67
|
//# sourceMappingURL=version-guard.js.map
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.7.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testsprite/testsprite-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Official TestSprite command-line interface",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"ajv": "^8.20.0",
|
|
71
71
|
"eslint": "^10.7.0",
|
|
72
72
|
"eslint-config-prettier": "^9.1.0",
|
|
73
|
+
"eslint-plugin-security": "4.0.1",
|
|
73
74
|
"globals": "^17.7.0",
|
|
74
75
|
"msw": "^2.14.3",
|
|
75
76
|
"prettier": "^3.3.3",
|