@testsprite/testsprite-cli 0.15.0 → 0.17.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 +53 -141
- package/dist/commands/agent.d.ts +12 -4
- package/dist/commands/agent.js +55 -65
- package/dist/commands/auth.d.ts +6 -10
- package/dist/commands/auth.js +44 -56
- package/dist/commands/ci.d.ts +23 -100
- package/dist/commands/ci.js +297 -489
- package/dist/commands/completion.js +2 -1
- package/dist/commands/conversation.d.ts +27 -0
- package/dist/commands/conversation.js +702 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +130 -34
- package/dist/commands/init.d.ts +4 -45
- package/dist/commands/init.js +116 -68
- package/dist/commands/project-env.d.ts +62 -2
- package/dist/commands/project-env.js +426 -53
- package/dist/commands/project-sign-in.d.ts +0 -48
- package/dist/commands/project-sign-in.js +1 -224
- package/dist/commands/project.d.ts +15 -186
- package/dist/commands/project.js +93 -921
- package/dist/commands/result.d.ts +10 -0
- package/dist/commands/result.js +215 -0
- package/dist/commands/schedule.d.ts +0 -29
- package/dist/commands/schedule.js +47 -97
- package/dist/commands/test.d.ts +315 -1824
- package/dist/commands/test.js +1962 -13733
- package/dist/commands/testlist.d.ts +128 -5
- package/dist/commands/testlist.js +269 -329
- package/dist/commands/tunnel.d.ts +2 -2
- package/dist/commands/tunnel.js +43 -41
- package/dist/commands/usage.d.ts +12 -45
- package/dist/commands/usage.js +51 -131
- package/dist/index.js +189 -108
- package/dist/lib/agent-detect.js +9 -5
- package/dist/lib/agent-targets.d.ts +21 -2
- package/dist/lib/agent-targets.js +88 -11
- package/dist/lib/args.d.ts +13 -0
- package/dist/lib/args.js +49 -0
- package/dist/lib/basic-auth.d.ts +3 -0
- package/dist/lib/basic-auth.js +15 -0
- package/dist/lib/billing-refusal.js +4 -3
- package/dist/lib/ci-linkage.d.ts +4 -82
- package/dist/lib/ci-linkage.js +4 -157
- package/dist/lib/ci-run.js +1 -1
- package/dist/lib/client-factory.d.ts +10 -2
- package/dist/lib/client-factory.js +38 -26
- package/dist/lib/commit-signal.d.ts +65 -0
- package/dist/lib/commit-signal.js +305 -0
- package/dist/lib/concurrency-limiter.d.ts +6 -0
- package/dist/lib/concurrency-limiter.js +29 -0
- package/dist/lib/config.js +10 -5
- package/dist/lib/conflict-reason.d.ts +31 -4
- package/dist/lib/conflict-reason.js +38 -4
- package/dist/lib/conversation/answers.d.ts +9 -0
- package/dist/lib/conversation/answers.js +49 -0
- package/dist/lib/conversation/api.d.ts +71 -0
- package/dist/lib/conversation/api.js +150 -0
- package/dist/lib/conversation/change.d.ts +31 -0
- package/dist/lib/conversation/change.js +124 -0
- package/dist/lib/conversation/context.d.ts +19 -0
- package/dist/lib/conversation/context.js +70 -0
- package/dist/lib/conversation/environment.d.ts +15 -0
- package/dist/lib/conversation/environment.js +33 -0
- package/dist/lib/conversation/follow.d.ts +24 -0
- package/dist/lib/conversation/follow.js +42 -0
- package/dist/lib/conversation/render.d.ts +33 -0
- package/dist/lib/conversation/render.js +315 -0
- package/dist/lib/conversation/title.d.ts +2 -0
- package/dist/lib/conversation/title.js +18 -0
- package/dist/lib/conversation/types.d.ts +156 -0
- package/dist/lib/conversation/types.js +6 -0
- package/dist/lib/credentials.js +67 -11
- package/dist/lib/cron.d.ts +1 -1
- package/dist/lib/cron.js +2 -2
- package/dist/lib/dispatch-stop.d.ts +20 -0
- package/dist/lib/dispatch-stop.js +30 -0
- package/dist/lib/download.d.ts +71 -0
- package/dist/lib/download.js +274 -0
- package/dist/lib/dry-run/fetch.d.ts +10 -0
- package/dist/lib/dry-run/fetch.js +20 -0
- package/dist/lib/dry-run/samples.d.ts +6 -34
- package/dist/lib/dry-run/samples.js +389 -751
- package/dist/lib/environment-tunnel.d.ts +16 -26
- package/dist/lib/environment-tunnel.js +161 -157
- package/dist/lib/errors.d.ts +20 -4
- package/dist/lib/errors.js +36 -16
- package/dist/lib/facade.d.ts +7 -29
- package/dist/lib/facade.js +7 -36
- package/dist/lib/failing-fe-resolver.d.ts +13 -58
- package/dist/lib/failing-fe-resolver.js +47 -132
- package/dist/lib/first-suite-hint.d.ts +16 -22
- package/dist/lib/first-suite-hint.js +38 -47
- package/dist/lib/gh-output.d.ts +76 -21
- package/dist/lib/gh-output.js +171 -90
- package/dist/lib/git-utils.d.ts +56 -0
- package/dist/lib/git-utils.js +212 -0
- package/dist/lib/github-context.d.ts +2 -0
- package/dist/lib/github-context.js +40 -8
- package/dist/lib/history-retention.d.ts +6 -2
- package/dist/lib/history-retention.js +10 -7
- package/dist/lib/http.d.ts +58 -134
- package/dist/lib/http.js +352 -271
- package/dist/lib/interrupt.d.ts +14 -8
- package/dist/lib/interrupt.js +28 -10
- package/dist/lib/junit-report.d.ts +60 -4
- package/dist/lib/junit-report.js +209 -32
- package/dist/lib/local-target.d.ts +3 -3
- package/dist/lib/local-target.js +3 -3
- package/dist/lib/output.d.ts +0 -29
- package/dist/lib/output.js +10 -33
- package/dist/lib/pagination.d.ts +2 -5
- package/dist/lib/pagination.js +2 -5
- package/dist/lib/presigned-url.d.ts +22 -0
- package/dist/lib/presigned-url.js +90 -0
- package/dist/lib/prompt.js +36 -2
- package/dist/lib/proxy.js +2 -1
- package/dist/lib/redact.d.ts +2 -2
- package/dist/lib/redact.js +3 -4
- package/dist/lib/removed-commands.d.ts +18 -0
- package/dist/lib/removed-commands.js +154 -0
- package/dist/lib/render-error.d.ts +31 -6
- package/dist/lib/render-error.js +88 -25
- package/dist/lib/response-schemas.d.ts +38 -30
- package/dist/lib/response-schemas.js +210 -207
- package/dist/lib/result/api.d.ts +24 -0
- package/dist/lib/result/api.js +28 -0
- package/dist/lib/result/evidence.d.ts +71 -0
- package/dist/lib/result/evidence.js +420 -0
- package/dist/lib/result/render.d.ts +20 -0
- package/dist/lib/result/render.js +194 -0
- package/dist/lib/result/types.d.ts +122 -0
- package/dist/lib/result/types.js +19 -0
- package/dist/lib/run-output.d.ts +275 -0
- package/dist/lib/run-output.js +227 -0
- package/dist/lib/run-render.d.ts +101 -0
- package/dist/lib/run-render.js +183 -0
- package/dist/lib/run-wait.d.ts +192 -0
- package/dist/lib/run-wait.js +452 -0
- package/dist/lib/runs.types.d.ts +134 -367
- package/dist/lib/runs.types.js +0 -14
- package/dist/lib/secret-file.d.ts +1 -1
- package/dist/lib/secret-file.js +11 -2
- package/dist/lib/skill-nudge.d.ts +7 -27
- package/dist/lib/skill-nudge.js +9 -37
- package/dist/lib/target-path.d.ts +15 -0
- package/dist/lib/target-path.js +35 -0
- package/dist/lib/target-url-advisory.d.ts +19 -0
- package/dist/lib/target-url-advisory.js +31 -0
- package/dist/lib/target-url-preflight.d.ts +9 -0
- package/dist/lib/target-url-preflight.js +214 -106
- package/dist/lib/target-url.d.ts +1 -1
- package/dist/lib/target-url.js +6 -16
- package/dist/lib/telemetry.d.ts +32 -12
- package/dist/lib/telemetry.js +39 -8
- package/dist/lib/terminal-text.d.ts +41 -0
- package/dist/lib/terminal-text.js +127 -0
- package/dist/lib/testlist.types.d.ts +16 -8
- package/dist/lib/testlist.types.js +1 -1
- package/dist/lib/text-equality.d.ts +2 -0
- package/dist/lib/text-equality.js +5 -0
- package/dist/lib/text-file.d.ts +16 -0
- package/dist/lib/text-file.js +41 -0
- package/dist/lib/text-table.d.ts +46 -0
- package/dist/lib/text-table.js +72 -4
- package/dist/lib/ticker.d.ts +9 -2
- package/dist/lib/ticker.js +16 -3
- package/dist/lib/transport-failure.d.ts +22 -0
- package/dist/lib/transport-failure.js +126 -0
- package/dist/lib/tunnel-session.d.ts +7 -1
- package/dist/lib/tunnel-session.js +22 -9
- package/dist/lib/update-check.js +3 -2
- package/dist/lib/url-template.d.ts +43 -0
- package/dist/lib/url-template.js +151 -0
- package/dist/lib/validate.d.ts +0 -64
- package/dist/lib/validate.js +2 -131
- package/dist/lib/version-notice.js +4 -3
- package/dist/lib/wait-exit.d.ts +37 -2
- package/dist/lib/wait-exit.js +88 -30
- package/dist/lib/workspace-status.js +10 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -4
- package/skills/testsprite-ci.skill.md +48 -18
- package/skills/testsprite-onboard.skill.md +66 -151
- package/skills/testsprite-verify.codex.md +54 -56
- package/skills/testsprite-verify.skill.md +194 -358
- package/dist/lib/browser.d.ts +0 -6
- package/dist/lib/browser.js +0 -54
- package/dist/lib/bundle.d.ts +0 -234
- package/dist/lib/bundle.js +0 -781
- package/dist/lib/deprecate.d.ts +0 -10
- package/dist/lib/deprecate.js +0 -13
- package/dist/lib/flaky.d.ts +0 -91
- package/dist/lib/flaky.js +0 -71
- package/dist/lib/plan-poll.d.ts +0 -171
- package/dist/lib/plan-poll.js +0 -441
- package/dist/lib/plans.types.d.ts +0 -130
- package/dist/lib/plans.types.js +0 -31
- package/dist/lib/poll.d.ts +0 -100
- package/dist/lib/poll.js +0 -290
- package/dist/lib/rate-throttle.d.ts +0 -49
- package/dist/lib/rate-throttle.js +0 -75
- package/dist/lib/run-progress.d.ts +0 -41
- package/dist/lib/run-progress.js +0 -56
- package/dist/lib/v3-advisory.d.ts +0 -55
- package/dist/lib/v3-advisory.js +0 -74
- package/schemas/plan.schema.json +0 -61
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch rejections that no retry can fix.
|
|
3
|
+
*
|
|
4
|
+
* Node's fetch reports almost every network problem as the same opaque
|
|
5
|
+
* `TypeError: fetch failed`; the real reason lives on the `cause` chain. Two
|
|
6
|
+
* causes are terminal: a TLS certificate the CLI does not trust (usually a
|
|
7
|
+
* corporate proxy that re-signs HTTPS) and a proxy that demands credentials
|
|
8
|
+
* (HTTP 407). Retrying re-sends the same request into the same wall, so the
|
|
9
|
+
* caller fails on the first attempt with an error that names the fix.
|
|
10
|
+
* Every other cause keeps the caller's normal retry handling.
|
|
11
|
+
*/
|
|
12
|
+
export interface FatalTransportFailure {
|
|
13
|
+
/** The TLS code, or `PROXY_AUTHENTICATION_REQUIRED` for a proxy 407. */
|
|
14
|
+
cause: string;
|
|
15
|
+
message: string;
|
|
16
|
+
nextAction: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Return the terminal failure behind a fetch rejection, or `undefined` when
|
|
20
|
+
* the cause is anything else (the caller keeps its retry handling).
|
|
21
|
+
*/
|
|
22
|
+
export declare function classifyFatalTransportFailure(error: unknown, targetUrl: string): FatalTransportFailure | undefined;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch rejections that no retry can fix.
|
|
3
|
+
*
|
|
4
|
+
* Node's fetch reports almost every network problem as the same opaque
|
|
5
|
+
* `TypeError: fetch failed`; the real reason lives on the `cause` chain. Two
|
|
6
|
+
* causes are terminal: a TLS certificate the CLI does not trust (usually a
|
|
7
|
+
* corporate proxy that re-signs HTTPS) and a proxy that demands credentials
|
|
8
|
+
* (HTTP 407). Retrying re-sends the same request into the same wall, so the
|
|
9
|
+
* caller fails on the first attempt with an error that names the fix.
|
|
10
|
+
* Every other cause keeps the caller's normal retry handling.
|
|
11
|
+
*/
|
|
12
|
+
const MAX_CAUSE_DEPTH = 6;
|
|
13
|
+
/** Collect `code` values and messages from the whole `cause` / AggregateError graph. */
|
|
14
|
+
function collectErrorEvidence(error) {
|
|
15
|
+
const codes = new Set();
|
|
16
|
+
const messages = [];
|
|
17
|
+
const seen = new Set();
|
|
18
|
+
const walk = (node, depth) => {
|
|
19
|
+
if (node === null || typeof node !== 'object' || depth > MAX_CAUSE_DEPTH)
|
|
20
|
+
return;
|
|
21
|
+
if (seen.has(node))
|
|
22
|
+
return;
|
|
23
|
+
seen.add(node);
|
|
24
|
+
const record = node;
|
|
25
|
+
if (typeof record.code === 'string' && record.code.length > 0)
|
|
26
|
+
codes.add(record.code);
|
|
27
|
+
if (typeof record.message === 'string' && record.message.length > 0) {
|
|
28
|
+
messages.push(record.message);
|
|
29
|
+
}
|
|
30
|
+
walk(record.cause, depth + 1);
|
|
31
|
+
if (Array.isArray(record.errors)) {
|
|
32
|
+
for (const nested of record.errors)
|
|
33
|
+
walk(nested, depth + 1);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
walk(error, 0);
|
|
37
|
+
return { codes, messages };
|
|
38
|
+
}
|
|
39
|
+
function firstMatchingCode(codes, candidates) {
|
|
40
|
+
return candidates.find(candidate => codes.has(candidate));
|
|
41
|
+
}
|
|
42
|
+
const TLS_UNTRUSTED_CODES = [
|
|
43
|
+
'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
|
|
44
|
+
'SELF_SIGNED_CERT_IN_CHAIN',
|
|
45
|
+
'DEPTH_ZERO_SELF_SIGNED_CERT',
|
|
46
|
+
'UNABLE_TO_GET_ISSUER_CERT',
|
|
47
|
+
'UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
|
|
48
|
+
'CERT_SIGNATURE_FAILURE',
|
|
49
|
+
'CERT_UNTRUSTED',
|
|
50
|
+
'CERT_REJECTED',
|
|
51
|
+
'CERT_REVOKED',
|
|
52
|
+
'INVALID_CA',
|
|
53
|
+
'PATH_LENGTH_EXCEEDED',
|
|
54
|
+
];
|
|
55
|
+
const TLS_EXPIRED_CODES = ['CERT_HAS_EXPIRED', 'CERT_NOT_YET_VALID'];
|
|
56
|
+
const TLS_HOSTNAME_CODES = ['ERR_TLS_CERT_ALTNAME_INVALID'];
|
|
57
|
+
/**
|
|
58
|
+
* The two messages undici uses for a proxy 407: the CONNECT tunnel used for
|
|
59
|
+
* HTTPS targets (`Proxy response (407) !== 200 when HTTP Tunneling`) and the
|
|
60
|
+
* forwarding path (`Proxy Authentication Required (407)`).
|
|
61
|
+
*/
|
|
62
|
+
const PROXY_407_MESSAGES = [/Proxy response \(407\)/, /Proxy Authentication Required \(407\)/];
|
|
63
|
+
const TLS_NEXT_ACTION = "If your network re-signs TLS, set NODE_EXTRA_CA_CERTS to your organisation's CA bundle " +
|
|
64
|
+
'(PEM), for example NODE_EXTRA_CA_CERTS=/path/to/ca.pem, then retry. Do not set ' +
|
|
65
|
+
'NODE_TLS_REJECT_UNAUTHORIZED=0: it turns off certificate checks for requests that carry ' +
|
|
66
|
+
'your API key.';
|
|
67
|
+
function hostOf(targetUrl) {
|
|
68
|
+
try {
|
|
69
|
+
return new URL(targetUrl).host;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return 'the API endpoint';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Return the terminal failure behind a fetch rejection, or `undefined` when
|
|
77
|
+
* the cause is anything else (the caller keeps its retry handling).
|
|
78
|
+
*/
|
|
79
|
+
export function classifyFatalTransportFailure(error, targetUrl) {
|
|
80
|
+
const evidence = collectErrorEvidence(error);
|
|
81
|
+
const host = hostOf(targetUrl);
|
|
82
|
+
if (evidence.messages.some(message => PROXY_407_MESSAGES.some(re => re.test(message)))) {
|
|
83
|
+
return {
|
|
84
|
+
cause: 'PROXY_AUTHENTICATION_REQUIRED',
|
|
85
|
+
message: `The HTTP proxy between this machine and ${host} answered 407 Proxy Authentication ` +
|
|
86
|
+
'Required, so the request never reached TestSprite; the API key was not rejected.',
|
|
87
|
+
nextAction: 'Put the proxy credentials in HTTPS_PROXY (for example ' +
|
|
88
|
+
'http://user:password@proxy.example:8080), or ask IT for a proxy that allows outbound ' +
|
|
89
|
+
'HTTPS, then retry.',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const untrusted = firstMatchingCode(evidence.codes, TLS_UNTRUSTED_CODES);
|
|
93
|
+
if (untrusted !== undefined) {
|
|
94
|
+
return {
|
|
95
|
+
cause: untrusted,
|
|
96
|
+
message: `TLS certificate verification failed for ${host} (${untrusted}): the certificate chain ` +
|
|
97
|
+
'is not trusted. Corporate TLS interception is the usual cause; set NODE_EXTRA_CA_CERTS ' +
|
|
98
|
+
"to your organisation's CA bundle if your network re-signs TLS.",
|
|
99
|
+
nextAction: TLS_NEXT_ACTION,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const expired = firstMatchingCode(evidence.codes, TLS_EXPIRED_CODES);
|
|
103
|
+
if (expired !== undefined) {
|
|
104
|
+
return {
|
|
105
|
+
cause: expired,
|
|
106
|
+
message: `TLS certificate verification failed for ${host} (${expired}): the certificate is ` +
|
|
107
|
+
'expired or not yet valid. A wrong system clock or corporate TLS interception is the ' +
|
|
108
|
+
"usual cause; set NODE_EXTRA_CA_CERTS to your organisation's CA bundle if your network " +
|
|
109
|
+
're-signs TLS.',
|
|
110
|
+
nextAction: `Check the system clock. ${TLS_NEXT_ACTION}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const hostname = firstMatchingCode(evidence.codes, TLS_HOSTNAME_CODES);
|
|
114
|
+
if (hostname !== undefined) {
|
|
115
|
+
return {
|
|
116
|
+
cause: hostname,
|
|
117
|
+
message: `TLS certificate verification failed for ${host} (${hostname}): the certificate is not ` +
|
|
118
|
+
'valid for that host. A wrong --endpoint-url / TESTSPRITE_API_URL or corporate TLS ' +
|
|
119
|
+
"interception is the usual cause; set NODE_EXTRA_CA_CERTS to your organisation's CA " +
|
|
120
|
+
'bundle if your network re-signs TLS.',
|
|
121
|
+
nextAction: `Check --endpoint-url / TESTSPRITE_API_URL. ${TLS_NEXT_ACTION}`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=transport-failure.js.map
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
import { ApiError } from './errors.js';
|
|
42
42
|
import type { LogLevel, TunnelClientOptions } from '../vendor/tunnel-client/index.js';
|
|
43
43
|
import type { TunnelMintResponse } from './tunnel.types.js';
|
|
44
|
+
import { type RunRef } from './run-render.js';
|
|
44
45
|
/**
|
|
45
46
|
* How long to wait for the control plane's first successful connection.
|
|
46
47
|
*
|
|
@@ -143,7 +144,12 @@ export interface TunnelSessionDeps {
|
|
|
143
144
|
* the already-started server-side run before deciding whether to retry.
|
|
144
145
|
*/
|
|
145
146
|
export declare class TunnelLostError extends ApiError {
|
|
146
|
-
|
|
147
|
+
/**
|
|
148
|
+
* `run` carries the wire ids of the run that lost its tunnel: `resultId` is the
|
|
149
|
+
* result id and `runId` its launch. Both are absent when the tunnel
|
|
150
|
+
* died before any run was accepted.
|
|
151
|
+
*/
|
|
152
|
+
constructor(reason: TunnelFatalReason, run: RunRef, fatalMessage?: string);
|
|
147
153
|
}
|
|
148
154
|
export declare function formatDataPlaneUnreachableMessage(clientMessage?: string): string;
|
|
149
155
|
export declare function formatDataPlaneUnreachableNextAction(clientMessage: string | undefined, retryAction: string): string;
|
|
@@ -41,6 +41,8 @@
|
|
|
41
41
|
import { ApiError, InterruptError } from './errors.js';
|
|
42
42
|
import { ErrCode, TunnelClient } from '../vendor/tunnel-client/index.js';
|
|
43
43
|
import { DEFAULT_DATA_PLANE_RETRY_DEADLINE_MS } from '../vendor/tunnel-client/config.js';
|
|
44
|
+
import { runLabel, waitCommand } from './run-render.js';
|
|
45
|
+
import { terminalSafeLine } from './terminal-text.js';
|
|
44
46
|
/**
|
|
45
47
|
* How long to wait for the control plane's first successful connection.
|
|
46
48
|
*
|
|
@@ -64,32 +66,42 @@ function isCredentialRevokedMessage(message) {
|
|
|
64
66
|
* the already-started server-side run before deciding whether to retry.
|
|
65
67
|
*/
|
|
66
68
|
export class TunnelLostError extends ApiError {
|
|
67
|
-
|
|
69
|
+
/**
|
|
70
|
+
* `run` carries the wire ids of the run that lost its tunnel: `resultId` is the
|
|
71
|
+
* result id and `runId` its launch. Both are absent when the tunnel
|
|
72
|
+
* died before any run was accepted.
|
|
73
|
+
*/
|
|
74
|
+
constructor(reason, run, fatalMessage) {
|
|
68
75
|
// Two different things go wrong here and they do NOT share a remedy.
|
|
69
76
|
// `--tunnel-client <id>` re-attaches to the same dead id and mints nothing,
|
|
70
77
|
// so a borrower must inspect this run before deciding what to do next.
|
|
71
78
|
// The wait path reports the observed cancellation outcome separately.
|
|
72
79
|
const ownerGone = reason === 'owner-gone';
|
|
73
80
|
const dataPlaneUnreachable = reason === 'data-plane-unreachable';
|
|
81
|
+
const subject = runLabel(run, 'lower');
|
|
82
|
+
// `run wait` takes the launch id; without one no command is offered.
|
|
83
|
+
const wait = waitCommand([run]);
|
|
74
84
|
super({
|
|
75
85
|
code: 'UNAVAILABLE',
|
|
76
86
|
message: ownerGone
|
|
77
|
-
? `The borrowed tunnel for
|
|
87
|
+
? `The borrowed tunnel for ${subject} is no longer registered. It was minted by ` +
|
|
78
88
|
`another process (\`testsprite tunnel start\`), and that process has stopped or its ` +
|
|
79
89
|
`credential expired. The run cannot reach your app through that tunnel.`
|
|
80
90
|
: dataPlaneUnreachable
|
|
81
91
|
? formatDataPlaneUnreachableMessage(fatalMessage)
|
|
82
|
-
: `The tunnel carrying
|
|
92
|
+
: `The tunnel carrying ${subject} was disconnected by the server and cannot be ` +
|
|
83
93
|
`restored for this run (${reason}).`,
|
|
84
94
|
nextAction: ownerGone
|
|
85
|
-
?
|
|
95
|
+
? wait
|
|
96
|
+
? `Check the run before re-running: ${wait}.`
|
|
97
|
+
: 'Check the run before re-running.'
|
|
86
98
|
: dataPlaneUnreachable
|
|
87
|
-
? `Check the cancelled run with
|
|
99
|
+
? (wait ? `Check the cancelled run with ${wait}. ` : '') +
|
|
88
100
|
formatDataPlaneUnreachableNextAction(fatalMessage, 'start a new run')
|
|
89
101
|
: 'This usually means the tunnel service was redeployed mid-run. Start the run again: ' +
|
|
90
102
|
'the retry mints a fresh tunnel.',
|
|
91
103
|
requestId: 'local',
|
|
92
|
-
details: { reason, runId },
|
|
104
|
+
details: { reason, ...{ runId: run.runId, resultId: run.resultId ?? null } },
|
|
93
105
|
});
|
|
94
106
|
this.name = 'TunnelLostError';
|
|
95
107
|
}
|
|
@@ -213,7 +225,7 @@ export async function openTunnelSession(options, deps) {
|
|
|
213
225
|
await deps.destroy(minted.clientId);
|
|
214
226
|
}
|
|
215
227
|
catch (err) {
|
|
216
|
-
sessionLog(`[advisory] could not delete the tunnel credential (${err instanceof Error ? err.message : String(err)}); it expires on its own at ${minted.expiresAt}.`);
|
|
228
|
+
sessionLog(`[advisory] could not delete the tunnel credential (${terminalSafeLine(err instanceof Error ? err.message : String(err))}); it expires on its own at ${terminalSafeLine(minted.expiresAt)}.`);
|
|
217
229
|
}
|
|
218
230
|
};
|
|
219
231
|
try {
|
|
@@ -230,7 +242,8 @@ export async function openTunnelSession(options, deps) {
|
|
|
230
242
|
// a run that pivots into the rest of their network is the failure this
|
|
231
243
|
// rail exists to stop. Loopback and public targets are unaffected.
|
|
232
244
|
allowPrivateNetworkTarget: false,
|
|
233
|
-
|
|
245
|
+
// A client log line can carry a server value (a close reason): one line.
|
|
246
|
+
logSink: (_level, line) => sessionLog(terminalSafeLine(line)),
|
|
234
247
|
onError: e => {
|
|
235
248
|
const terminal = e.code === ErrCode.AuthFailed || e.code === ErrCode.DataPlaneUnreachable;
|
|
236
249
|
if (terminal && fatal === undefined) {
|
|
@@ -251,7 +264,7 @@ export async function openTunnelSession(options, deps) {
|
|
|
251
264
|
}
|
|
252
265
|
if (terminal)
|
|
253
266
|
return;
|
|
254
|
-
sessionLog(`[tunnel] ${e.message}`);
|
|
267
|
+
sessionLog(`[tunnel] ${terminalSafeLine(e.message)}`);
|
|
255
268
|
},
|
|
256
269
|
});
|
|
257
270
|
}
|
package/dist/lib/update-check.js
CHANGED
|
@@ -38,6 +38,7 @@ import { homedir } from 'node:os';
|
|
|
38
38
|
import { dirname, join } from 'node:path';
|
|
39
39
|
import * as v from 'valibot';
|
|
40
40
|
import { VERSION } from '../version.js';
|
|
41
|
+
import { terminalSafeLine, terminalSafeWriter } from './terminal-text.js';
|
|
41
42
|
/** Re-check interval: 24 hours, expressed in milliseconds. */
|
|
42
43
|
export const UPDATE_CHECK_TTL_MS = 24 * 60 * 60 * 1000;
|
|
43
44
|
/**
|
|
@@ -79,7 +80,7 @@ function resolveUpdateCheckDeps(deps) {
|
|
|
79
80
|
mkdirSync(dir, { recursive: true });
|
|
80
81
|
}),
|
|
81
82
|
isTTY: deps.isTTY ?? process.stderr.isTTY === true,
|
|
82
|
-
stderr: deps.stderr
|
|
83
|
+
stderr: terminalSafeWriter(deps.stderr),
|
|
83
84
|
currentVersion: deps.currentVersion ?? VERSION,
|
|
84
85
|
};
|
|
85
86
|
}
|
|
@@ -234,7 +235,7 @@ export async function maybeNotifyUpdate(deps = {}) {
|
|
|
234
235
|
return;
|
|
235
236
|
// User-facing advisory copy (exact format specified by issue #122), not a
|
|
236
237
|
// diagnostic log line; stderr keeps stdout parseable for scripts.
|
|
237
|
-
resolved.stderr(`A new version of testsprite-cli is available: ${resolved.currentVersion} -> ${latest}. ` +
|
|
238
|
+
resolved.stderr(`A new version of testsprite-cli is available: ${resolved.currentVersion} -> ${terminalSafeLine(latest)}. ` +
|
|
238
239
|
`Run npm install -g @testsprite/testsprite-cli to update. ` +
|
|
239
240
|
`(Disable with ${UPDATE_CHECK_OPT_OUT_ENV}=1)`);
|
|
240
241
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ci run --target-url-template`: a pull request's preview address written
|
|
3
|
+
* once, as a pattern, and filled in on the runner from the facts the job
|
|
4
|
+
* already has (PR number, head branch, head sha).
|
|
5
|
+
*
|
|
6
|
+
* The placeholders and the branch slug are the GitHub App's — its PR triggers
|
|
7
|
+
* take the same `urlTemplate` and render it from the webhook payload
|
|
8
|
+
* (backend `trigger-url.util.ts`) — so a pattern copied between the Portal
|
|
9
|
+
* and a workflow file renders the same URL. `url-template.spec.ts` pins the
|
|
10
|
+
* App's own cases alongside the platform shapes this exists for (Vercel's
|
|
11
|
+
* `<project>-git-{branch-slug}-<team>.vercel.app`, Cloudflare Pages'
|
|
12
|
+
* `{branch-slug}.<project>.pages.dev`, Netlify's `deploy-preview-{pr}--<site>`).
|
|
13
|
+
*/
|
|
14
|
+
export declare const URL_TEMPLATE_PLACEHOLDERS: readonly ["{pr}", "{pr-number}", "{branch}", "{branch-slug}", "{sha}", "{short-sha}"];
|
|
15
|
+
export interface UrlTemplateVars {
|
|
16
|
+
pr?: number | null;
|
|
17
|
+
branch?: string | null;
|
|
18
|
+
sha?: string | null;
|
|
19
|
+
}
|
|
20
|
+
/** A branch name as the preview platforms spell it in a hostname: lowercased, runs of anything else collapsed to one `-`, none at the ends. */
|
|
21
|
+
export declare function branchSlug(branch: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Fill the template. `null` when a referenced placeholder has no value, or
|
|
24
|
+
* when one inside the host part renders to something that is not a hostname
|
|
25
|
+
* label (see `HOST_SAFE_RE`) — the caller refuses the run rather than guessing
|
|
26
|
+
* (never a production fallback) and names the placeholder with
|
|
27
|
+
* `missingPlaceholders` / `unsafeHostPlaceholders`. Text that merely looks
|
|
28
|
+
* like a placeholder (`{unknown}`) is left as is.
|
|
29
|
+
*/
|
|
30
|
+
export declare function renderUrlTemplate(template: string, vars: UrlTemplateVars): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* The placeholders in the template's host part whose value would not stay a
|
|
33
|
+
* hostname label — the ones that make `renderUrlTemplate` refuse although
|
|
34
|
+
* every value is present. Each entry is `{placeholder} = "value"`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function unsafeHostPlaceholders(template: string, vars: UrlTemplateVars): string[];
|
|
37
|
+
/** The placeholders in `template` that `vars` cannot fill — for the refusal message. */
|
|
38
|
+
export declare function missingPlaceholders(template: string, vars: UrlTemplateVars): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Shape check before any network call: with every placeholder filled by a
|
|
41
|
+
* sample value the template must be an http(s) URL. `null` when it is.
|
|
42
|
+
*/
|
|
43
|
+
export declare function validateUrlTemplate(template: string): string | null;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ci run --target-url-template`: a pull request's preview address written
|
|
3
|
+
* once, as a pattern, and filled in on the runner from the facts the job
|
|
4
|
+
* already has (PR number, head branch, head sha).
|
|
5
|
+
*
|
|
6
|
+
* The placeholders and the branch slug are the GitHub App's — its PR triggers
|
|
7
|
+
* take the same `urlTemplate` and render it from the webhook payload
|
|
8
|
+
* (backend `trigger-url.util.ts`) — so a pattern copied between the Portal
|
|
9
|
+
* and a workflow file renders the same URL. `url-template.spec.ts` pins the
|
|
10
|
+
* App's own cases alongside the platform shapes this exists for (Vercel's
|
|
11
|
+
* `<project>-git-{branch-slug}-<team>.vercel.app`, Cloudflare Pages'
|
|
12
|
+
* `{branch-slug}.<project>.pages.dev`, Netlify's `deploy-preview-{pr}--<site>`).
|
|
13
|
+
*/
|
|
14
|
+
const PLACEHOLDER_RE = /\{(pr|pr-number|branch|branch-slug|sha|short-sha)\}/g;
|
|
15
|
+
/**
|
|
16
|
+
* What a placeholder may render to inside the template's authority (the host
|
|
17
|
+
* part): hostname-label characters only. `{branch-slug}`, `{pr}` and the sha
|
|
18
|
+
* placeholders always satisfy this; a raw `{branch}` does not when the branch
|
|
19
|
+
* is named `attacker.example/x` — substituted verbatim into
|
|
20
|
+
* `https://{branch}.preview.example.com` that renders to host
|
|
21
|
+
* `attacker.example`, and the run would be dispatched there with the
|
|
22
|
+
* environment's sign-in. Such a value is refused, never dispatched.
|
|
23
|
+
*/
|
|
24
|
+
const HOST_SAFE_RE = /^[A-Za-z0-9-]+$/;
|
|
25
|
+
export const URL_TEMPLATE_PLACEHOLDERS = [
|
|
26
|
+
'{pr}',
|
|
27
|
+
'{pr-number}',
|
|
28
|
+
'{branch}',
|
|
29
|
+
'{branch-slug}',
|
|
30
|
+
'{sha}',
|
|
31
|
+
'{short-sha}',
|
|
32
|
+
];
|
|
33
|
+
/** A branch name as the preview platforms spell it in a hostname: lowercased, runs of anything else collapsed to one `-`, none at the ends. */
|
|
34
|
+
export function branchSlug(branch) {
|
|
35
|
+
return branch
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
38
|
+
.replace(/^-+|-+$/g, '');
|
|
39
|
+
}
|
|
40
|
+
/** The value a placeholder renders to, or `null` when `vars` has none for it. */
|
|
41
|
+
function placeholderValue(name, vars) {
|
|
42
|
+
switch (name) {
|
|
43
|
+
case 'pr':
|
|
44
|
+
case 'pr-number':
|
|
45
|
+
return vars.pr == null ? null : String(vars.pr);
|
|
46
|
+
case 'branch':
|
|
47
|
+
return vars.branch || null;
|
|
48
|
+
case 'branch-slug':
|
|
49
|
+
return vars.branch ? branchSlug(vars.branch) : null;
|
|
50
|
+
case 'sha':
|
|
51
|
+
return vars.sha || null;
|
|
52
|
+
case 'short-sha':
|
|
53
|
+
return vars.sha ? vars.sha.slice(0, 7) : null;
|
|
54
|
+
default:
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The `[start, end)` of the template's authority — from after `scheme://` to
|
|
60
|
+
* the first `/`, `?` or `#` — or `null` when the template has no scheme.
|
|
61
|
+
*/
|
|
62
|
+
function authoritySpan(template) {
|
|
63
|
+
const scheme = /^[a-z][a-z0-9+.-]*:\/\//i.exec(template);
|
|
64
|
+
if (!scheme)
|
|
65
|
+
return null;
|
|
66
|
+
const start = scheme[0].length;
|
|
67
|
+
const end = template.slice(start).search(/[/?#]/);
|
|
68
|
+
return [start, end === -1 ? template.length : start + end];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Fill the template. `null` when a referenced placeholder has no value, or
|
|
72
|
+
* when one inside the host part renders to something that is not a hostname
|
|
73
|
+
* label (see `HOST_SAFE_RE`) — the caller refuses the run rather than guessing
|
|
74
|
+
* (never a production fallback) and names the placeholder with
|
|
75
|
+
* `missingPlaceholders` / `unsafeHostPlaceholders`. Text that merely looks
|
|
76
|
+
* like a placeholder (`{unknown}`) is left as is.
|
|
77
|
+
*/
|
|
78
|
+
export function renderUrlTemplate(template, vars) {
|
|
79
|
+
const authority = authoritySpan(template);
|
|
80
|
+
let refused = false;
|
|
81
|
+
const rendered = template.replace(PLACEHOLDER_RE, (_m, name, offset) => {
|
|
82
|
+
const value = placeholderValue(name, vars);
|
|
83
|
+
if (value === null) {
|
|
84
|
+
refused = true;
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
if (authority && offset >= authority[0] && offset < authority[1] && !HOST_SAFE_RE.test(value)) {
|
|
88
|
+
refused = true;
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
});
|
|
93
|
+
return refused ? null : rendered;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The placeholders in the template's host part whose value would not stay a
|
|
97
|
+
* hostname label — the ones that make `renderUrlTemplate` refuse although
|
|
98
|
+
* every value is present. Each entry is `{placeholder} = "value"`.
|
|
99
|
+
*/
|
|
100
|
+
export function unsafeHostPlaceholders(template, vars) {
|
|
101
|
+
const authority = authoritySpan(template);
|
|
102
|
+
if (!authority)
|
|
103
|
+
return [];
|
|
104
|
+
const unsafe = new Set();
|
|
105
|
+
for (const match of template.matchAll(PLACEHOLDER_RE)) {
|
|
106
|
+
const offset = match.index ?? -1;
|
|
107
|
+
if (offset < authority[0] || offset >= authority[1])
|
|
108
|
+
continue;
|
|
109
|
+
const value = placeholderValue(match[1], vars);
|
|
110
|
+
if (value !== null && !HOST_SAFE_RE.test(value)) {
|
|
111
|
+
unsafe.add(`{${match[1]}} = ${JSON.stringify(value)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return [...unsafe];
|
|
115
|
+
}
|
|
116
|
+
/** The placeholders in `template` that `vars` cannot fill — for the refusal message. */
|
|
117
|
+
export function missingPlaceholders(template, vars) {
|
|
118
|
+
const missing = new Set();
|
|
119
|
+
for (const match of template.matchAll(PLACEHOLDER_RE)) {
|
|
120
|
+
const name = match[1];
|
|
121
|
+
const absent = name === 'pr' || name === 'pr-number'
|
|
122
|
+
? vars.pr == null
|
|
123
|
+
: name === 'branch' || name === 'branch-slug'
|
|
124
|
+
? !vars.branch
|
|
125
|
+
: !vars.sha;
|
|
126
|
+
if (absent)
|
|
127
|
+
missing.add(`{${name}}`);
|
|
128
|
+
}
|
|
129
|
+
return [...missing];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Shape check before any network call: with every placeholder filled by a
|
|
133
|
+
* sample value the template must be an http(s) URL. `null` when it is.
|
|
134
|
+
*/
|
|
135
|
+
export function validateUrlTemplate(template) {
|
|
136
|
+
const rendered = renderUrlTemplate(template, { pr: 1, branch: 'main', sha: 'a'.repeat(40) });
|
|
137
|
+
if (!rendered)
|
|
138
|
+
return 'the template contains an unknown placeholder';
|
|
139
|
+
let parsed;
|
|
140
|
+
try {
|
|
141
|
+
parsed = new URL(rendered);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return `the template does not render to a valid URL (placeholders: ${URL_TEMPLATE_PLACEHOLDERS.join(', ')})`;
|
|
145
|
+
}
|
|
146
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
147
|
+
return 'the template must render to an http(s) URL';
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=url-template.js.map
|
package/dist/lib/validate.d.ts
CHANGED
|
@@ -1,48 +1,3 @@
|
|
|
1
|
-
/** Shared option bag for helpers that accept both flag and field paths. */
|
|
2
|
-
interface KindOpts {
|
|
3
|
-
/** Controls how `nextAction` is phrased in the error envelope. */
|
|
4
|
-
kind?: 'flag' | 'field';
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Assert that `value` is a string, throwing a typed VALIDATION_ERROR
|
|
8
|
-
* envelope on failure.
|
|
9
|
-
*
|
|
10
|
-
* @param field Field name (used in the error envelope `details.field`
|
|
11
|
-
* and the `nextAction` line).
|
|
12
|
-
* @param value The raw value to check.
|
|
13
|
-
* @param opts.kind `'field'` (default) or `'flag'`.
|
|
14
|
-
* @param opts.minLength When set, rejects strings shorter than this length
|
|
15
|
-
* (default: 1, i.e. non-empty unless allowEmpty).
|
|
16
|
-
* @param opts.maxLength When set, rejects strings longer than this length.
|
|
17
|
-
* @param opts.allowEmpty When `true`, a zero-length string is accepted.
|
|
18
|
-
* Overrides `minLength` — if both are set, the string
|
|
19
|
-
* is accepted as long as it is a string (length ≥ 0).
|
|
20
|
-
* Defaults to `false`. Whitespace-only strings (e.g.
|
|
21
|
-
* `" "`) are treated as empty when `allowEmpty` is
|
|
22
|
-
* false — they are rejected the same as `""` so junk
|
|
23
|
-
* records cannot reach the backend (dogfood P1 fix).
|
|
24
|
-
*/
|
|
25
|
-
export declare function requireString(field: string, value: unknown, opts?: KindOpts & {
|
|
26
|
-
minLength?: number;
|
|
27
|
-
maxLength?: number;
|
|
28
|
-
allowEmpty?: boolean;
|
|
29
|
-
}): asserts value is string;
|
|
30
|
-
/**
|
|
31
|
-
* Assert that `value` is one of the accepted enum members, throwing a
|
|
32
|
-
* typed VALIDATION_ERROR envelope on failure.
|
|
33
|
-
*
|
|
34
|
-
* The error message format is:
|
|
35
|
-
* `must be one of: "v1", "v2", ...`
|
|
36
|
-
*
|
|
37
|
-
* with each accepted value quoted, comma-separated. This is the canonical
|
|
38
|
-
* format for agent-facing JSON paths (dogfood L625 option 2).
|
|
39
|
-
*
|
|
40
|
-
* @param field Field name used in the error envelope.
|
|
41
|
-
* @param value The raw value to check.
|
|
42
|
-
* @param accepted Tuple/array of the accepted string literals.
|
|
43
|
-
* @param opts.kind `'field'` (default) or `'flag'`.
|
|
44
|
-
*/
|
|
45
|
-
export declare function requireEnum<T extends string>(field: string, value: unknown, accepted: readonly T[], opts?: KindOpts): asserts value is T;
|
|
46
1
|
/**
|
|
47
2
|
* Validate a caller-supplied `--idempotency-key` value before it is sent as
|
|
48
3
|
* an HTTP header. The HTTP spec (RFC 7230) requires header values to be ASCII
|
|
@@ -61,22 +16,3 @@ export declare function requireEnum<T extends string>(field: string, value: unkn
|
|
|
61
16
|
* @param key The raw flag value, or `undefined` when the key is auto-minted.
|
|
62
17
|
*/
|
|
63
18
|
export declare function assertIdempotencyKey(key: string | undefined): void;
|
|
64
|
-
/**
|
|
65
|
-
* Assert that `arr` is an Array and that its length is within the given
|
|
66
|
-
* bounds, throwing a typed VALIDATION_ERROR envelope on failure.
|
|
67
|
-
*
|
|
68
|
-
* @param field Field name used in the error envelope.
|
|
69
|
-
* @param arr The raw value to check.
|
|
70
|
-
* @param opts.min Minimum length (inclusive). Defaults to 0.
|
|
71
|
-
* @param opts.max Maximum length (inclusive). Omit for no upper cap.
|
|
72
|
-
* @param opts.kind `'field'` (default) or `'flag'`.
|
|
73
|
-
* @param opts.itemNoun Singular noun used in min/max messages (e.g. `'step'`).
|
|
74
|
-
* Defaults to `'item'`. The helper pluralises to `<noun>s`
|
|
75
|
-
* for the max message.
|
|
76
|
-
*/
|
|
77
|
-
export declare function requireArrayLength(field: string, arr: unknown, opts: KindOpts & {
|
|
78
|
-
min?: number;
|
|
79
|
-
max?: number;
|
|
80
|
-
itemNoun?: string;
|
|
81
|
-
}): asserts arr is unknown[];
|
|
82
|
-
export {};
|