@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
|
@@ -41,6 +41,13 @@
|
|
|
41
41
|
* string; the resolved-address check only covers *this* URL's host),
|
|
42
42
|
* so following it would hand an attacker-controlled Location header a
|
|
43
43
|
* live SSRF primitive running on the caller's machine or CI runner.
|
|
44
|
+
*
|
|
45
|
+
* One redirect is refused: Vercel Deployment Protection's login wall. Its
|
|
46
|
+
* Location is parsed as a string and never fetched, so the guarantee above
|
|
47
|
+
* holds. Unlike the app's own login page, no test credential gets past
|
|
48
|
+
* Vercel's wall. The honest limitation above (the probe runs here, not on
|
|
49
|
+
* the Lambda) does not apply either: Vercel sends every visitor without a
|
|
50
|
+
* Vercel session there, the Lambda included.
|
|
44
51
|
*/
|
|
45
52
|
import * as dns from 'node:dns';
|
|
46
53
|
import { isIP } from 'node:net';
|
|
@@ -48,9 +55,16 @@ import { ApiError, InterruptError } from './errors.js';
|
|
|
48
55
|
import { globalShutdown } from './interrupt.js';
|
|
49
56
|
import { isProxyAgentActive } from './proxy.js';
|
|
50
57
|
import { disallowedIpReason } from './target-url.js';
|
|
51
|
-
/**
|
|
58
|
+
/** Shared DNS + HTTP budget, matching the MCP plugin's ~8s probe budget. */
|
|
52
59
|
const PREFLIGHT_TIMEOUT_MS = 8_000;
|
|
53
60
|
const GATEWAY_ERROR_STATUSES = new Set([502, 503, 504]);
|
|
61
|
+
/**
|
|
62
|
+
* Where Vercel Deployment Protection redirects a visitor with no Vercel
|
|
63
|
+
* session. A protected preview answers `302` with
|
|
64
|
+
* `location: https://vercel.com/sso-api?url=<preview>&nonce=<nonce>`.
|
|
65
|
+
*/
|
|
66
|
+
const VERCEL_LOGIN_WALL_HOST = 'vercel.com';
|
|
67
|
+
const VERCEL_LOGIN_WALL_PATH = '/sso-api';
|
|
54
68
|
/** Pulls the string addresses out of a `dns.lookup` result, whether it's a
|
|
55
69
|
* single `{ address, family }` object (the no-options default) or an array
|
|
56
70
|
* of them (the `{ all: true }` shape the real default below requests, so a
|
|
@@ -88,10 +102,45 @@ function isTimeoutError(err) {
|
|
|
88
102
|
const name = err?.name;
|
|
89
103
|
return name === 'AbortError' || name === 'TimeoutError';
|
|
90
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* True when a redirect's Location points at Vercel's login wall. The value
|
|
107
|
+
* is resolved against the probed URL as a string only; it is never fetched.
|
|
108
|
+
* A missing or unparseable Location is not the wall, and a relative one
|
|
109
|
+
* resolves to the probed host.
|
|
110
|
+
*/
|
|
111
|
+
function isVercelLoginWall(location, probedUrl) {
|
|
112
|
+
if (location === null)
|
|
113
|
+
return false;
|
|
114
|
+
let target;
|
|
115
|
+
try {
|
|
116
|
+
target = new URL(location, probedUrl);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return target.hostname === VERCEL_LOGIN_WALL_HOST && target.pathname === VERCEL_LOGIN_WALL_PATH;
|
|
122
|
+
}
|
|
91
123
|
/** Strips the `[...]` bracket notation the WHATWG `URL.hostname` getter uses for IPv6 literals. */
|
|
92
124
|
function bareHost(hostname) {
|
|
93
125
|
return hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;
|
|
94
126
|
}
|
|
127
|
+
/** Stop waiting even though the system resolver itself cannot be cancelled. */
|
|
128
|
+
async function lookupWithSignal(hostname, lookup, signal) {
|
|
129
|
+
signal.throwIfAborted();
|
|
130
|
+
let onAbort;
|
|
131
|
+
try {
|
|
132
|
+
return await new Promise((resolve, reject) => {
|
|
133
|
+
onAbort = () => reject(signal.reason);
|
|
134
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
135
|
+
// Both handlers remain attached after an abort: a late DNS result cannot
|
|
136
|
+
// resume the probe, and a late rejection must not become unhandled.
|
|
137
|
+
lookup(hostname).then(resolve, reject);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
signal.removeEventListener('abort', onAbort);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
95
144
|
/**
|
|
96
145
|
* Probe `rawUrl` for the narrow refusal set described in the module
|
|
97
146
|
* docstring. Network failures classify to `warn` or `refuse`, while a process
|
|
@@ -107,135 +156,182 @@ export async function probeTargetUrl(rawUrl, deps = {}) {
|
|
|
107
156
|
catch {
|
|
108
157
|
return { verdict: 'warn', reason: 'could not parse --target-url for the reachability probe' };
|
|
109
158
|
}
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
159
|
+
const shutdownSignal = deps.shutdownSignal ?? globalShutdown.signal;
|
|
160
|
+
const shutdown = deps.shutdown ?? globalShutdown;
|
|
161
|
+
return shutdown.runCriticalOperation(async () => {
|
|
162
|
+
shutdownSignal.throwIfAborted();
|
|
163
|
+
const deadline = new AbortController();
|
|
164
|
+
const timer = setTimeout(() => {
|
|
165
|
+
deadline.abort(new DOMException('Target URL preflight timed out', 'TimeoutError'));
|
|
166
|
+
}, PREFLIGHT_TIMEOUT_MS);
|
|
167
|
+
timer.unref?.();
|
|
168
|
+
const signal = AbortSignal.any([deadline.signal, shutdownSignal]);
|
|
116
169
|
try {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
170
|
+
const host = bareHost(parsed.hostname);
|
|
171
|
+
// Step 1 — DNS. Skipped for a literal IP host (nothing to resolve, and
|
|
172
|
+
// dns.lookup on a literal is a needless round trip through the resolver).
|
|
173
|
+
if (isIP(host) === 0) {
|
|
174
|
+
const dnsLookup = deps.dnsLookup ?? ((hostname) => dns.promises.lookup(hostname, { all: true }));
|
|
175
|
+
let lookupResult;
|
|
176
|
+
try {
|
|
177
|
+
lookupResult = await lookupWithSignal(host, dnsLookup, signal);
|
|
178
|
+
signal.throwIfAborted();
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
if (shutdownSignal.aborted)
|
|
182
|
+
throw shutdownSignal.reason;
|
|
183
|
+
if (err instanceof InterruptError)
|
|
184
|
+
throw err;
|
|
185
|
+
if (signal.aborted) {
|
|
186
|
+
return {
|
|
187
|
+
verdict: 'warn',
|
|
188
|
+
reason: `DNS lookup for "${host}" did not finish within ${PREFLIGHT_TIMEOUT_MS / 1000}s`,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const code = err?.code;
|
|
192
|
+
if (code === 'ENOTFOUND' || code === 'EAI_NONAME') {
|
|
193
|
+
if (proxied) {
|
|
194
|
+
return {
|
|
195
|
+
verdict: 'warn',
|
|
196
|
+
reason: `DNS lookup for "${host}" failed locally (${code}) — not conclusive behind a configured proxy`,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
verdict: 'refuse',
|
|
201
|
+
refusal: 'target-unreachable',
|
|
202
|
+
reason: `--target-url host "${host}" does not resolve (${code})`,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
// Anything else (e.g. EAI_AGAIN — a transient resolver hiccup) is
|
|
206
|
+
// ambiguous, not a confirmed dead target — warn, never refuse.
|
|
123
207
|
return {
|
|
124
208
|
verdict: 'warn',
|
|
125
|
-
reason: `DNS lookup for "${host}" failed
|
|
209
|
+
reason: `DNS lookup for "${host}" failed (${typeof code === 'string' ? code : 'unknown error'})`,
|
|
126
210
|
};
|
|
127
211
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// "can't tell from here" result, and a false positive has a documented
|
|
149
|
-
// escape hatch (`--skip-preflight`) rather than a broken workflow.
|
|
150
|
-
for (const address of resolvedAddresses(lookupResult)) {
|
|
151
|
-
const blocked = disallowedIpReason(address);
|
|
152
|
-
if (blocked !== undefined) {
|
|
153
|
-
return {
|
|
154
|
-
verdict: 'refuse',
|
|
155
|
-
reason: `--target-url host "${host}" resolves to ${address} (${blocked.reason})`,
|
|
156
|
-
};
|
|
212
|
+
// DNS rebinding: a public-looking hostname (e.g. an attacker-controlled
|
|
213
|
+
// domain, or a tunnel host with attacker-influenced DNS) whose A/AAAA
|
|
214
|
+
// record actually points at a private, loopback, link-local, or
|
|
215
|
+
// metadata-service address. `assertNotLocal` never catches this — it
|
|
216
|
+
// only ever inspected the literal `--target-url` *string*, and this
|
|
217
|
+
// hostname passed that check honestly (it doesn't LOOK private). Unlike
|
|
218
|
+
// the DNS-failure branch above, there is no proxy carve-out: resolving
|
|
219
|
+
// locally to a private address is a security signal, not an ambiguous
|
|
220
|
+
// "can't tell from here" result, and a false positive has a documented
|
|
221
|
+
// escape hatch (`--skip-preflight`) rather than a broken workflow.
|
|
222
|
+
for (const address of resolvedAddresses(lookupResult)) {
|
|
223
|
+
const blocked = disallowedIpReason(address);
|
|
224
|
+
if (blocked !== undefined) {
|
|
225
|
+
return {
|
|
226
|
+
verdict: 'refuse',
|
|
227
|
+
refusal: 'target-unreachable',
|
|
228
|
+
reason: `--target-url host "${host}" resolves to ${address} (${blocked.reason})`,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
157
232
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
233
|
+
// Step 2 — HTTP probe. Runs through the global `fetch`, which picks up
|
|
234
|
+
// the proxy dispatcher `proxy.ts` installs at startup when one is
|
|
235
|
+
// configured — so this step (unlike the DNS step above) is proxy-aware
|
|
236
|
+
// by construction, not just proxy-tolerant.
|
|
237
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
238
|
+
try {
|
|
239
|
+
signal.throwIfAborted();
|
|
240
|
+
const resp = await fetchImpl(rawUrl, {
|
|
241
|
+
method: 'GET',
|
|
242
|
+
// Never follow — see the module docstring. A 3xx is reachability
|
|
243
|
+
// proof on its own (handled immediately below); the redirect target
|
|
244
|
+
// is unvalidated and must not be dereferenced.
|
|
245
|
+
redirect: 'manual',
|
|
246
|
+
signal,
|
|
247
|
+
});
|
|
248
|
+
// Never read the body — only the status matters here. Cancel it so the
|
|
249
|
+
// connection is released promptly instead of buffering a full page.
|
|
250
|
+
await resp.body?.cancel().catch(() => undefined);
|
|
251
|
+
if (shutdownSignal.aborted)
|
|
252
|
+
throw shutdownSignal.reason;
|
|
253
|
+
if (resp.status >= 300 && resp.status < 400) {
|
|
254
|
+
// A redirect is a live-server signal (e.g. a real app 302ing an
|
|
255
|
+
// unauthenticated GET to a login page) — reachable, not refused. The
|
|
256
|
+
// Location header is never dereferenced; it is only parsed to spot
|
|
257
|
+
// Vercel's login wall (see the module docstring). `headers?.` because
|
|
258
|
+
// an injected fetch may answer without headers.
|
|
259
|
+
if (isVercelLoginWall(resp.headers?.get('location') ?? null, rawUrl)) {
|
|
260
|
+
return {
|
|
261
|
+
verdict: 'refuse',
|
|
262
|
+
refusal: 'target-protected',
|
|
263
|
+
reason: `--target-url redirects to Vercel's login wall (${VERCEL_LOGIN_WALL_HOST}${VERCEL_LOGIN_WALL_PATH})`,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return { verdict: 'ok' };
|
|
267
|
+
}
|
|
268
|
+
if (GATEWAY_ERROR_STATUSES.has(resp.status)) {
|
|
269
|
+
if (proxied) {
|
|
270
|
+
return {
|
|
271
|
+
verdict: 'warn',
|
|
272
|
+
reason: `--target-url responded HTTP ${resp.status} — not conclusive behind a configured proxy`,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
verdict: 'refuse',
|
|
277
|
+
refusal: 'target-unreachable',
|
|
278
|
+
reason: `--target-url responded HTTP ${resp.status} (gateway error — the target is unreachable)`,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (resp.status >= 400) {
|
|
282
|
+
return { verdict: 'warn', reason: `--target-url responded HTTP ${resp.status}` };
|
|
283
|
+
}
|
|
186
284
|
return { verdict: 'ok' };
|
|
187
285
|
}
|
|
188
|
-
|
|
189
|
-
if (
|
|
286
|
+
catch (err) {
|
|
287
|
+
if (shutdownSignal.aborted)
|
|
288
|
+
throw shutdownSignal.reason;
|
|
289
|
+
if (err instanceof InterruptError)
|
|
290
|
+
throw err;
|
|
291
|
+
if (errorHasCode(err, ['ECONNREFUSED'])) {
|
|
292
|
+
if (proxied) {
|
|
293
|
+
return {
|
|
294
|
+
verdict: 'warn',
|
|
295
|
+
reason: 'connection to --target-url was refused — not conclusive behind a configured proxy',
|
|
296
|
+
};
|
|
297
|
+
}
|
|
190
298
|
return {
|
|
191
|
-
verdict: '
|
|
192
|
-
|
|
299
|
+
verdict: 'refuse',
|
|
300
|
+
refusal: 'target-unreachable',
|
|
301
|
+
reason: 'connection to --target-url was refused (ECONNREFUSED)',
|
|
193
302
|
};
|
|
194
303
|
}
|
|
195
|
-
|
|
196
|
-
verdict: 'refuse',
|
|
197
|
-
reason: `--target-url responded HTTP ${resp.status} (gateway error — the target is unreachable)`,
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
if (resp.status >= 400) {
|
|
201
|
-
return { verdict: 'warn', reason: `--target-url responded HTTP ${resp.status}` };
|
|
202
|
-
}
|
|
203
|
-
return { verdict: 'ok' };
|
|
204
|
-
}
|
|
205
|
-
catch (err) {
|
|
206
|
-
if (shutdownSignal.aborted)
|
|
207
|
-
throw shutdownSignal.reason;
|
|
208
|
-
if (err instanceof InterruptError)
|
|
209
|
-
throw err;
|
|
210
|
-
if (errorHasCode(err, ['ECONNREFUSED'])) {
|
|
211
|
-
if (proxied) {
|
|
304
|
+
if (isTimeoutError(err)) {
|
|
212
305
|
return {
|
|
213
306
|
verdict: 'warn',
|
|
214
|
-
reason:
|
|
307
|
+
reason: `--target-url did not respond within ${PREFLIGHT_TIMEOUT_MS / 1000}s`,
|
|
215
308
|
};
|
|
216
309
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
reason: 'connection to --target-url was refused (ECONNREFUSED)',
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
if (isTimeoutError(err)) {
|
|
310
|
+
// TLS errors and anything else unclassified: warn only — the refusal
|
|
311
|
+
// set stays narrow to exactly what that analysis measured.
|
|
223
312
|
return {
|
|
224
313
|
verdict: 'warn',
|
|
225
|
-
reason:
|
|
314
|
+
reason: `could not reach --target-url (${err instanceof Error ? err.message : String(err)})`,
|
|
226
315
|
};
|
|
227
316
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
verdict: 'warn',
|
|
232
|
-
reason: `could not reach --target-url (${err instanceof Error ? err.message : String(err)})`,
|
|
233
|
-
};
|
|
317
|
+
}
|
|
318
|
+
finally {
|
|
319
|
+
clearTimeout(timer);
|
|
234
320
|
}
|
|
235
321
|
});
|
|
236
322
|
}
|
|
237
323
|
/** Shared wording so `--help` and every refuse/warn message agree on the escape hatch. */
|
|
238
324
|
const SKIP_HINT = 'Skip this check entirely with --skip-preflight.';
|
|
325
|
+
/**
|
|
326
|
+
* The two ways past Vercel Deployment Protection. The query parameters come
|
|
327
|
+
* from Vercel's "Protection Bypass for Automation" docs, which accept them as
|
|
328
|
+
* headers or query parameters (sourceRef:
|
|
329
|
+
* https://vercel.com/docs/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation).
|
|
330
|
+
*/
|
|
331
|
+
const VERCEL_PROTECTION_HINT = "Turn off Vercel Authentication for preview deployments in the Vercel project's Deployment " +
|
|
332
|
+
'Protection settings, or create a Protection Bypass for Automation secret and pass it in the ' +
|
|
333
|
+
'URL: --target-url "<preview>?x-vercel-protection-bypass=<secret>&x-vercel-set-bypass-cookie=true" ' +
|
|
334
|
+
'(use "&" instead of "?" when the preview URL already has a query).';
|
|
239
335
|
/**
|
|
240
336
|
* Run the preflight and either throw (refuse), print an `[advisory]` line
|
|
241
337
|
* (warn), or no-op (ok / skipped). This is the call-site integration point
|
|
@@ -249,6 +345,18 @@ export async function assertTargetUrlReachable(targetUrl, opts, deps, stderrFn)
|
|
|
249
345
|
if (opts.skipPreflight === true)
|
|
250
346
|
return;
|
|
251
347
|
const outcome = await probeTargetUrl(targetUrl, deps);
|
|
348
|
+
if (outcome.verdict === 'refuse' && outcome.refusal === 'target-protected') {
|
|
349
|
+
throw ApiError.fromEnvelope({
|
|
350
|
+
error: {
|
|
351
|
+
code: 'VALIDATION_ERROR',
|
|
352
|
+
message: `${outcome.reason}: the preview is behind Vercel Deployment Protection, so every test ` +
|
|
353
|
+
`would run against Vercel's login page instead of your app.`,
|
|
354
|
+
nextAction: `${VERCEL_PROTECTION_HINT} ${SKIP_HINT}`,
|
|
355
|
+
requestId: 'local',
|
|
356
|
+
details: { field: 'targetUrl', reason: 'target-protected', probeReason: outcome.reason },
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
}
|
|
252
360
|
if (outcome.verdict === 'refuse') {
|
|
253
361
|
throw ApiError.fromEnvelope({
|
|
254
362
|
error: {
|
package/dist/lib/target-url.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* - Reject IPv6 link-local (`fe80::/10`), unique-local (`fc00::/7`), and
|
|
25
25
|
* deprecated site-local (`fec0::/10`)
|
|
26
26
|
*/
|
|
27
|
-
type TargetUrlHintContext = 'runtime' | '
|
|
27
|
+
type TargetUrlHintContext = 'runtime' | 'local-project-create';
|
|
28
28
|
export interface TargetUrlCaller {
|
|
29
29
|
/** CLI flag name without the leading `--`, used in the error envelope. */
|
|
30
30
|
field: string;
|
package/dist/lib/target-url.js
CHANGED
|
@@ -33,17 +33,7 @@ import { ApiError } from './errors.js';
|
|
|
33
33
|
// on `127.0.0.1`/`::1`, so `--local`'s default dial reaches it) — NOT for
|
|
34
34
|
// the rest of `127.0.0.0/8`, which `--local` cannot dial by name at all. See
|
|
35
35
|
// `'loopback-other'` below for that distinction.
|
|
36
|
-
const LOCAL_DEV_RUNTIME_HINT = "This looks like a local-dev target. Save `--url http://localhost:<port>` on an environment, then run `testsprite
|
|
37
|
-
// Creation-time callers that take a per-run target (`test create
|
|
38
|
-
// --target-url`, which only applies with `--run`). A project or environment
|
|
39
|
-
// that names an app on this machine is created with `--local <port>`, so this
|
|
40
|
-
// says that instead of sending the reader after a public URL they may not have.
|
|
41
|
-
// It also serves the bind-all addresses (`0.0.0.0` / `::`), which are not
|
|
42
|
-
// loopback and are refused everywhere.
|
|
43
|
-
const LOCAL_DEV_BOOTSTRAP_HINT = 'TestSprite executes tests from the cloud, so the runner needs an address it can reach: ' +
|
|
44
|
-
'a deployed or staging URL. For an app that only runs on this machine, create the project ' +
|
|
45
|
-
'or environment with `--url http://localhost:<port>`, then run with ' +
|
|
46
|
-
'`testsprite test run <test-id> --env <name>`.';
|
|
36
|
+
const LOCAL_DEV_RUNTIME_HINT = "This looks like a local-dev target. Save `--url http://localhost:<port>` on an environment, then run `testsprite run <test-id> --env <name>` — it tunnels this machine's loopback address to the test runner (frontend tests only; requires an API key with the `run:tunnel` scope).";
|
|
47
37
|
/**
|
|
48
38
|
* `0.0.0.0` / `::` bind every interface, so an app listening there IS reachable
|
|
49
39
|
* on loopback — but the address itself is not loopback and the server refuses
|
|
@@ -51,10 +41,10 @@ const LOCAL_DEV_BOOTSTRAP_HINT = 'TestSprite executes tests from the cloud, so t
|
|
|
51
41
|
*/
|
|
52
42
|
const UNSPECIFIED_ADDRESS_REASON = 'the unspecified address (0.0.0.0 / ::) is not allowed — use 127.0.0.1 or ::1 instead';
|
|
53
43
|
const LOCAL_PROJECT_CREATE_HINT = 'Use --url http://localhost:<port> for an app on this machine. ' +
|
|
54
|
-
'Local projects are frontend-only
|
|
44
|
+
'Local projects are frontend-only.';
|
|
55
45
|
const DEFAULT_TARGET_URL_CALLER = {
|
|
56
46
|
field: 'target-url',
|
|
57
|
-
helpCommand: 'testsprite
|
|
47
|
+
helpCommand: 'testsprite run',
|
|
58
48
|
hintContext: 'runtime',
|
|
59
49
|
};
|
|
60
50
|
// Private, reserved, link-local, and metadata addresses are network-reachable from
|
|
@@ -107,9 +97,9 @@ export function assertNotLocal(rawUrl, caller = DEFAULT_TARGET_URL_CALLER) {
|
|
|
107
97
|
}
|
|
108
98
|
}
|
|
109
99
|
function localDevHintFor(hintContext) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
return hintContext === 'local-project-create'
|
|
101
|
+
? LOCAL_PROJECT_CREATE_HINT
|
|
102
|
+
: LOCAL_DEV_RUNTIME_HINT;
|
|
113
103
|
}
|
|
114
104
|
/**
|
|
115
105
|
* Map a classification's `hintKind` to the hint text `assertNotLocal` attaches
|
package/dist/lib/telemetry.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface WaitTimeoutTelemetry {
|
|
|
12
12
|
cancelOutcome?: 'cancelled' | 'already_terminal' | 'failed' | 'skipped';
|
|
13
13
|
}
|
|
14
14
|
export interface TelemetryOutcomeInput extends Partial<WaitTimeoutTelemetry> {
|
|
15
|
-
/** Leaf command path that ran, e.g. `
|
|
15
|
+
/** Leaf command path that ran, e.g. `run`. Empty → skip (no command). */
|
|
16
16
|
command: string;
|
|
17
17
|
outcome: TelemetryOutcome;
|
|
18
18
|
exitCode: number;
|
|
@@ -100,7 +100,7 @@ export declare function buildCiContext(env: NodeJS.ProcessEnv): {
|
|
|
100
100
|
* `conflict-reason.ts`'s rendering type: `tunnel-required` is a server reason
|
|
101
101
|
* this CLI has no label for yet, and `not_found` is rendered but not counted.
|
|
102
102
|
*/
|
|
103
|
-
export type TelemetryConflictReason = 'in_flight' | 'insufficient_credits' | 'paused' | 'billing_hold' | 'mcp_view_only' | 'local_address' | 'tunnel-required' | 'error';
|
|
103
|
+
export type TelemetryConflictReason = 'in_flight' | 'insufficient_credits' | 'paused' | 'billing_hold' | 'mcp_view_only' | 'local_address' | 'tunnel-required' | 'no_producer' | 'producer_in_flight' | 'error';
|
|
104
104
|
/**
|
|
105
105
|
* Low-cardinality facts a command records about its own outcome before it
|
|
106
106
|
* returns, merged into the one event `index.ts` fires. Counts are non-negative
|
|
@@ -110,7 +110,7 @@ export type TelemetryConflictReason = 'in_flight' | 'insufficient_credits' | 'pa
|
|
|
110
110
|
*/
|
|
111
111
|
export interface TelemetryExtras {
|
|
112
112
|
local?: boolean;
|
|
113
|
-
/** Batch dispatch accounting (`
|
|
113
|
+
/** Batch dispatch accounting (`run --project`, `run --testlist`). */
|
|
114
114
|
accepted?: number;
|
|
115
115
|
conflicts?: number;
|
|
116
116
|
deferred?: number;
|
|
@@ -120,9 +120,8 @@ export interface TelemetryExtras {
|
|
|
120
120
|
failed?: number;
|
|
121
121
|
blocked?: number;
|
|
122
122
|
timedOut?: number;
|
|
123
|
-
/**
|
|
123
|
+
/** The requested server cap (1–15) for each local execution. */
|
|
124
124
|
localConcurrencyLimit?: number;
|
|
125
|
-
localPeakInFlight?: number;
|
|
126
125
|
/** The most frequent conflict reason of the batch. */
|
|
127
126
|
conflictReason?: TelemetryConflictReason;
|
|
128
127
|
/** `ci init` facts. */
|
|
@@ -138,10 +137,14 @@ export interface TelemetryExtras {
|
|
|
138
137
|
/**
|
|
139
138
|
* What a `ci run` invocation ended up doing. `gated` = tests were dispatched
|
|
140
139
|
* and the exit code is the verdict; `skipped_*` = nothing to gate (exit 0, no
|
|
141
|
-
* summary
|
|
142
|
-
*
|
|
140
|
+
* summary — `skipped_no_preview` is `--wait-for-status` learning the preview
|
|
141
|
+
* was never built); `refused_*` = refused before or at dispatch
|
|
142
|
+
* (`refused_url_template` = the pattern could not be filled for this run);
|
|
143
|
+
* `timeout_preview` = `--wait-for-status` saw nothing terminal in time;
|
|
144
|
+
* `empty` = nothing selected. The funnel step "`ci init` → first gated run" is
|
|
145
|
+
* computed from it.
|
|
143
146
|
*/
|
|
144
|
-
export type CiRunTelemetryOutcome = 'gated' | 'skipped_draft' | 'skipped_no_pr' | 'refused_admission' | 'refused_env' | 'refused_preview_name' | 'refused_loopback' | 'refused_billing' | 'refused_other' | 'empty';
|
|
147
|
+
export type CiRunTelemetryOutcome = 'gated' | 'skipped_draft' | 'skipped_no_pr' | 'skipped_no_preview' | 'timeout_preview' | 'refused_url_template' | 'refused_admission' | 'refused_env' | 'refused_preview_name' | 'refused_loopback' | 'refused_billing' | 'refused_other' | 'empty';
|
|
145
148
|
/**
|
|
146
149
|
* The `ci run` outcome for an API refusal — at the environment pre-check or at
|
|
147
150
|
* the batch dispatch. Every refusal gets a value, so `refused_other` really is
|
|
@@ -174,8 +177,8 @@ export declare function recordTelemetryTunnelOpened(opened: boolean): void;
|
|
|
174
177
|
/** Return everything recorded so far and clear the sink (one event per process). */
|
|
175
178
|
export declare function takeTelemetryExtras(): TelemetryExtras;
|
|
176
179
|
/**
|
|
177
|
-
* Disjoint verdict counts over
|
|
178
|
-
*
|
|
180
|
+
* Disjoint verdict counts over finished polls. A test still running when the
|
|
181
|
+
* wait ends has no verdict. Unlike the CI summary's `failed` (which folds
|
|
179
182
|
* blocked in), `blocked` is split out here because it is the signal that
|
|
180
183
|
* separates a broken target from a failing assertion.
|
|
181
184
|
*/
|
|
@@ -189,7 +192,7 @@ export declare function batchOutcomeCounts(results: ReadonlyArray<{
|
|
|
189
192
|
};
|
|
190
193
|
/**
|
|
191
194
|
* Record a batch command's dispatch accounting (and, under `--wait`, its
|
|
192
|
-
* verdict counts) in one call, so `
|
|
195
|
+
* verdict counts) in one call, so `run --project` and `run --testlist` cannot
|
|
193
196
|
* drift in how they count. `conflictReason` is the dominant reason of the
|
|
194
197
|
* batch; `results` are the polled runs (omit for a non-wait dispatch).
|
|
195
198
|
*/
|
|
@@ -231,7 +234,7 @@ export interface TelemetryEvent extends Partial<WaitTimeoutTelemetry>, Telemetry
|
|
|
231
234
|
*
|
|
232
235
|
* Every branch below now fills `errorCode` — the two fallback branches
|
|
233
236
|
* (`CLIError`, and the final catch-all for a non-CLIError throw) previously
|
|
234
|
-
* left it `undefined`, which is why a meaningful share of `
|
|
237
|
+
* left it `undefined`, which is why a meaningful share of `run`
|
|
235
238
|
* invocations and `setup` failures landed in telemetry with `errorCode=None`.
|
|
236
239
|
*
|
|
237
240
|
* `errorOrigin` ('client' | 'server') resolves a real UNSUPPORTED
|
|
@@ -288,6 +291,23 @@ export declare function resolveTelemetryAuth(opts: {
|
|
|
288
291
|
env?: NodeJS.ProcessEnv;
|
|
289
292
|
credentialsPath?: string;
|
|
290
293
|
}): ResolvedTelemetryAuth;
|
|
294
|
+
/**
|
|
295
|
+
* {@link resolveTelemetryAuth} for the pre-action hook, which runs before every
|
|
296
|
+
* command: never throws. An unreadable credentials file (EPERM/EACCES — the
|
|
297
|
+
* Windows ACL lock-out `doctor` diagnoses — or any other read/parse failure)
|
|
298
|
+
* returns `undefined` so the caller can skip the beacon and let the command run
|
|
299
|
+
* and report the problem its own way, as the module contract requires
|
|
300
|
+
* (telemetry never changes a command's behavior, output, or exit code).
|
|
301
|
+
* `onError` receives the swallowed error, for `--debug`.
|
|
302
|
+
*/
|
|
303
|
+
export declare function tryResolveTelemetryAuth(opts: {
|
|
304
|
+
profile?: string;
|
|
305
|
+
endpointUrl?: string;
|
|
306
|
+
}, deps?: {
|
|
307
|
+
env?: NodeJS.ProcessEnv;
|
|
308
|
+
credentialsPath?: string;
|
|
309
|
+
onError?: (error: unknown) => void;
|
|
310
|
+
}): ResolvedTelemetryAuth | undefined;
|
|
291
311
|
/**
|
|
292
312
|
* Fire one command-outcome event to the beacon. Awaited by `index.ts` before
|
|
293
313
|
* `process.exit` (the flush) — bounded and fully best-effort, so it can neither
|