@testsprite/testsprite-cli 0.16.0 → 0.18.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.
Files changed (206) hide show
  1. package/README.md +52 -147
  2. package/dist/commands/agent.d.ts +12 -4
  3. package/dist/commands/agent.js +48 -63
  4. package/dist/commands/auth.d.ts +6 -10
  5. package/dist/commands/auth.js +40 -56
  6. package/dist/commands/ci.d.ts +23 -100
  7. package/dist/commands/ci.js +293 -487
  8. package/dist/commands/conversation.d.ts +27 -0
  9. package/dist/commands/conversation.js +741 -0
  10. package/dist/commands/doctor.d.ts +5 -1
  11. package/dist/commands/doctor.js +129 -34
  12. package/dist/commands/init.d.ts +4 -45
  13. package/dist/commands/init.js +108 -66
  14. package/dist/commands/project-env.d.ts +62 -2
  15. package/dist/commands/project-env.js +434 -43
  16. package/dist/commands/project-sign-in.d.ts +0 -48
  17. package/dist/commands/project-sign-in.js +1 -229
  18. package/dist/commands/project.d.ts +19 -186
  19. package/dist/commands/project.js +108 -926
  20. package/dist/commands/result.d.ts +10 -0
  21. package/dist/commands/result.js +216 -0
  22. package/dist/commands/schedule.d.ts +0 -29
  23. package/dist/commands/schedule.js +28 -87
  24. package/dist/commands/test.d.ts +301 -1838
  25. package/dist/commands/test.js +1880 -13917
  26. package/dist/commands/testlist.d.ts +130 -5
  27. package/dist/commands/testlist.js +300 -342
  28. package/dist/commands/tunnel.d.ts +3 -3
  29. package/dist/commands/tunnel.js +23 -20
  30. package/dist/commands/usage.d.ts +12 -45
  31. package/dist/commands/usage.js +50 -131
  32. package/dist/index.js +191 -110
  33. package/dist/lib/agent-detect.js +9 -5
  34. package/dist/lib/agent-targets.d.ts +21 -2
  35. package/dist/lib/agent-targets.js +88 -11
  36. package/dist/lib/args.d.ts +13 -0
  37. package/dist/lib/args.js +49 -0
  38. package/dist/lib/basic-auth.d.ts +3 -0
  39. package/dist/lib/basic-auth.js +15 -0
  40. package/dist/lib/billing-refusal.js +4 -3
  41. package/dist/lib/ci-linkage.d.ts +4 -82
  42. package/dist/lib/ci-linkage.js +4 -157
  43. package/dist/lib/ci-run.js +1 -1
  44. package/dist/lib/client-factory.d.ts +12 -4
  45. package/dist/lib/client-factory.js +41 -30
  46. package/dist/lib/commit-signal.d.ts +65 -0
  47. package/dist/lib/commit-signal.js +305 -0
  48. package/dist/lib/concurrency-limiter.d.ts +6 -0
  49. package/dist/lib/concurrency-limiter.js +29 -0
  50. package/dist/lib/config.js +10 -5
  51. package/dist/lib/conflict-reason.d.ts +9 -3
  52. package/dist/lib/conflict-reason.js +6 -3
  53. package/dist/lib/conversation/answers.d.ts +9 -0
  54. package/dist/lib/conversation/answers.js +49 -0
  55. package/dist/lib/conversation/api.d.ts +75 -0
  56. package/dist/lib/conversation/api.js +151 -0
  57. package/dist/lib/conversation/change.d.ts +31 -0
  58. package/dist/lib/conversation/change.js +124 -0
  59. package/dist/lib/conversation/context.d.ts +29 -0
  60. package/dist/lib/conversation/context.js +82 -0
  61. package/dist/lib/conversation/environment.d.ts +16 -0
  62. package/dist/lib/conversation/environment.js +21 -0
  63. package/dist/lib/conversation/follow.d.ts +24 -0
  64. package/dist/lib/conversation/follow.js +42 -0
  65. package/dist/lib/conversation/render.d.ts +33 -0
  66. package/dist/lib/conversation/render.js +318 -0
  67. package/dist/lib/conversation/title.d.ts +2 -0
  68. package/dist/lib/conversation/title.js +18 -0
  69. package/dist/lib/conversation/types.d.ts +158 -0
  70. package/dist/lib/conversation/types.js +6 -0
  71. package/dist/lib/credentials.js +67 -11
  72. package/dist/lib/cron.d.ts +1 -1
  73. package/dist/lib/cron.js +2 -2
  74. package/dist/lib/dispatch-stop.d.ts +20 -0
  75. package/dist/lib/dispatch-stop.js +30 -0
  76. package/dist/lib/download.d.ts +100 -0
  77. package/dist/lib/download.js +408 -0
  78. package/dist/lib/dry-run/fetch.d.ts +10 -0
  79. package/dist/lib/dry-run/fetch.js +20 -0
  80. package/dist/lib/dry-run/samples.d.ts +6 -34
  81. package/dist/lib/dry-run/samples.js +375 -747
  82. package/dist/lib/environment-tunnel.d.ts +19 -30
  83. package/dist/lib/environment-tunnel.js +168 -202
  84. package/dist/lib/errors.d.ts +20 -4
  85. package/dist/lib/errors.js +36 -16
  86. package/dist/lib/facade.d.ts +7 -29
  87. package/dist/lib/facade.js +7 -36
  88. package/dist/lib/failing-fe-resolver.d.ts +13 -58
  89. package/dist/lib/failing-fe-resolver.js +47 -132
  90. package/dist/lib/first-suite-hint.d.ts +20 -30
  91. package/dist/lib/first-suite-hint.js +57 -72
  92. package/dist/lib/gh-output.d.ts +76 -21
  93. package/dist/lib/gh-output.js +171 -90
  94. package/dist/lib/git-utils.d.ts +56 -0
  95. package/dist/lib/git-utils.js +212 -0
  96. package/dist/lib/github-context.d.ts +2 -0
  97. package/dist/lib/github-context.js +40 -8
  98. package/dist/lib/history-retention.d.ts +6 -2
  99. package/dist/lib/history-retention.js +10 -7
  100. package/dist/lib/http.d.ts +58 -134
  101. package/dist/lib/http.js +354 -291
  102. package/dist/lib/interrupt.d.ts +14 -8
  103. package/dist/lib/interrupt.js +28 -10
  104. package/dist/lib/junit-report.d.ts +57 -4
  105. package/dist/lib/junit-report.js +202 -32
  106. package/dist/lib/local-target.d.ts +8 -7
  107. package/dist/lib/local-target.js +14 -13
  108. package/dist/lib/output.d.ts +2 -41
  109. package/dist/lib/output.js +13 -51
  110. package/dist/lib/pagination.d.ts +2 -5
  111. package/dist/lib/pagination.js +2 -5
  112. package/dist/lib/presigned-url.d.ts +22 -0
  113. package/dist/lib/presigned-url.js +90 -0
  114. package/dist/lib/prompt.js +36 -2
  115. package/dist/lib/proxy.js +2 -1
  116. package/dist/lib/redact.d.ts +2 -2
  117. package/dist/lib/redact.js +3 -4
  118. package/dist/lib/removed-commands.d.ts +18 -0
  119. package/dist/lib/removed-commands.js +170 -0
  120. package/dist/lib/render-error.d.ts +31 -6
  121. package/dist/lib/render-error.js +88 -25
  122. package/dist/lib/response-schemas.d.ts +38 -30
  123. package/dist/lib/response-schemas.js +207 -207
  124. package/dist/lib/result/api.d.ts +24 -0
  125. package/dist/lib/result/api.js +28 -0
  126. package/dist/lib/result/evidence.d.ts +73 -0
  127. package/dist/lib/result/evidence.js +422 -0
  128. package/dist/lib/result/render.d.ts +20 -0
  129. package/dist/lib/result/render.js +194 -0
  130. package/dist/lib/result/types.d.ts +122 -0
  131. package/dist/lib/result/types.js +19 -0
  132. package/dist/lib/run-output.d.ts +275 -0
  133. package/dist/lib/run-output.js +227 -0
  134. package/dist/lib/run-render.d.ts +101 -0
  135. package/dist/lib/run-render.js +183 -0
  136. package/dist/lib/run-wait.d.ts +192 -0
  137. package/dist/lib/run-wait.js +452 -0
  138. package/dist/lib/runs.types.d.ts +118 -367
  139. package/dist/lib/runs.types.js +0 -14
  140. package/dist/lib/secret-file.d.ts +1 -1
  141. package/dist/lib/secret-file.js +11 -2
  142. package/dist/lib/skill-nudge.d.ts +7 -27
  143. package/dist/lib/skill-nudge.js +9 -37
  144. package/dist/lib/target-path.d.ts +15 -0
  145. package/dist/lib/target-path.js +35 -0
  146. package/dist/lib/target-url-advisory.d.ts +19 -0
  147. package/dist/lib/target-url-advisory.js +31 -0
  148. package/dist/lib/target-url-preflight.d.ts +9 -0
  149. package/dist/lib/target-url-preflight.js +214 -106
  150. package/dist/lib/target-url.d.ts +8 -8
  151. package/dist/lib/target-url.js +14 -24
  152. package/dist/lib/telemetry.d.ts +35 -15
  153. package/dist/lib/telemetry.js +38 -9
  154. package/dist/lib/terminal-text.d.ts +41 -0
  155. package/dist/lib/terminal-text.js +127 -0
  156. package/dist/lib/testlist.types.d.ts +16 -8
  157. package/dist/lib/testlist.types.js +1 -1
  158. package/dist/lib/text-equality.d.ts +2 -0
  159. package/dist/lib/text-equality.js +5 -0
  160. package/dist/lib/text-file.d.ts +16 -0
  161. package/dist/lib/text-file.js +41 -0
  162. package/dist/lib/text-table.d.ts +46 -0
  163. package/dist/lib/text-table.js +72 -4
  164. package/dist/lib/ticker.d.ts +9 -2
  165. package/dist/lib/ticker.js +16 -3
  166. package/dist/lib/transport-failure.d.ts +22 -0
  167. package/dist/lib/transport-failure.js +126 -0
  168. package/dist/lib/tunnel-session.d.ts +8 -2
  169. package/dist/lib/tunnel-session.js +24 -11
  170. package/dist/lib/update-check.js +3 -2
  171. package/dist/lib/url-template.d.ts +43 -0
  172. package/dist/lib/url-template.js +151 -0
  173. package/dist/lib/validate.d.ts +0 -64
  174. package/dist/lib/validate.js +2 -131
  175. package/dist/lib/version-notice.js +4 -3
  176. package/dist/lib/wait-exit.d.ts +37 -2
  177. package/dist/lib/wait-exit.js +88 -30
  178. package/dist/lib/workspace-status.js +10 -2
  179. package/dist/version.d.ts +1 -1
  180. package/dist/version.js +1 -1
  181. package/package.json +2 -3
  182. package/skills/testsprite-ci.skill.md +52 -23
  183. package/skills/testsprite-onboard.skill.md +70 -153
  184. package/skills/testsprite-verify.codex.md +54 -58
  185. package/skills/testsprite-verify.skill.md +189 -358
  186. package/dist/lib/browser.d.ts +0 -6
  187. package/dist/lib/browser.js +0 -54
  188. package/dist/lib/bundle.d.ts +0 -234
  189. package/dist/lib/bundle.js +0 -781
  190. package/dist/lib/deprecate.d.ts +0 -32
  191. package/dist/lib/deprecate.js +0 -39
  192. package/dist/lib/flaky.d.ts +0 -91
  193. package/dist/lib/flaky.js +0 -71
  194. package/dist/lib/plan-poll.d.ts +0 -171
  195. package/dist/lib/plan-poll.js +0 -441
  196. package/dist/lib/plans.types.d.ts +0 -130
  197. package/dist/lib/plans.types.js +0 -31
  198. package/dist/lib/poll.d.ts +0 -100
  199. package/dist/lib/poll.js +0 -290
  200. package/dist/lib/rate-throttle.d.ts +0 -49
  201. package/dist/lib/rate-throttle.js +0 -75
  202. package/dist/lib/run-progress.d.ts +0 -41
  203. package/dist/lib/run-progress.js +0 -56
  204. package/dist/lib/v3-advisory.d.ts +0 -55
  205. package/dist/lib/v3-advisory.js +0 -74
  206. 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
- /** ~8s, matching the MCP plugin's `checkPortListening` TCP-probe budget. */
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 host = bareHost(parsed.hostname);
111
- // Step 1 — DNS. Skipped for a literal IP host (nothing to resolve, and
112
- // dns.lookup on a literal is a needless round trip through the resolver).
113
- if (isIP(host) === 0) {
114
- const dnsLookup = deps.dnsLookup ?? ((hostname) => dns.promises.lookup(hostname, { all: true }));
115
- let lookupResult;
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
- lookupResult = await dnsLookup(host);
118
- }
119
- catch (err) {
120
- const code = err?.code;
121
- if (code === 'ENOTFOUND' || code === 'EAI_NONAME') {
122
- if (proxied) {
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 locally (${code}) — not conclusive behind a configured proxy`,
209
+ reason: `DNS lookup for "${host}" failed (${typeof code === 'string' ? code : 'unknown error'})`,
126
210
  };
127
211
  }
128
- return {
129
- verdict: 'refuse',
130
- reason: `--target-url host "${host}" does not resolve (${code})`,
131
- };
132
- }
133
- // Anything else (e.g. EAI_AGAIN — a transient resolver hiccup) is
134
- // ambiguous, not a confirmed dead target — warn, never refuse.
135
- return {
136
- verdict: 'warn',
137
- reason: `DNS lookup for "${host}" failed (${typeof code === 'string' ? code : 'unknown error'})`,
138
- };
139
- }
140
- // DNS rebinding: a public-looking hostname (e.g. an attacker-controlled
141
- // domain, or a tunnel host with attacker-influenced DNS) whose A/AAAA
142
- // record actually points at a private, loopback, link-local, or
143
- // metadata-service address. `assertNotLocal` never catches this — it
144
- // only ever inspected the literal `--target-url` *string*, and this
145
- // hostname passed that check honestly (it doesn't LOOK private). Unlike
146
- // the DNS-failure branch above, there is no proxy carve-out: resolving
147
- // locally to a private address is a security signal, not an ambiguous
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
- // Step 2 — HTTP probe. Runs through the global `fetch`, which picks up
161
- // the proxy dispatcher `proxy.ts` installs at startup when one is
162
- // configured — so this step (unlike the DNS step above) is proxy-aware
163
- // by construction, not just proxy-tolerant.
164
- const fetchImpl = deps.fetchImpl ?? fetch;
165
- const shutdownSignal = deps.shutdownSignal ?? globalShutdown.signal;
166
- const shutdown = deps.shutdown ?? globalShutdown;
167
- return shutdown.runCriticalOperation(async () => {
168
- try {
169
- const resp = await fetchImpl(rawUrl, {
170
- method: 'GET',
171
- // Never follow — see the module docstring. A 3xx is reachability
172
- // proof on its own (handled immediately below); the redirect target
173
- // is unvalidated and must not be dereferenced.
174
- redirect: 'manual',
175
- signal: AbortSignal.any([AbortSignal.timeout(PREFLIGHT_TIMEOUT_MS), shutdownSignal]),
176
- });
177
- // Never read the body — only the status matters here. Cancel it so the
178
- // connection is released promptly instead of buffering a full page.
179
- await resp.body?.cancel().catch(() => undefined);
180
- if (shutdownSignal.aborted)
181
- throw shutdownSignal.reason;
182
- if (resp.status >= 300 && resp.status < 400) {
183
- // A redirect is a live-server signal (e.g. a real app 302ing an
184
- // unauthenticated GET to a login page) — reachable, not refused. The
185
- // Location header is deliberately never inspected or dereferenced.
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
- if (GATEWAY_ERROR_STATUSES.has(resp.status)) {
189
- if (proxied) {
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: 'warn',
192
- reason: `--target-url responded HTTP ${resp.status} — not conclusive behind a configured proxy`,
299
+ verdict: 'refuse',
300
+ refusal: 'target-unreachable',
301
+ reason: 'connection to --target-url was refused (ECONNREFUSED)',
193
302
  };
194
303
  }
195
- return {
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: 'connection to --target-url was refused — not conclusive behind a configured proxy',
307
+ reason: `--target-url did not respond within ${PREFLIGHT_TIMEOUT_MS / 1000}s`,
215
308
  };
216
309
  }
217
- return {
218
- verdict: 'refuse',
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: `--target-url did not respond within ${PREFLIGHT_TIMEOUT_MS / 1000}s`,
314
+ reason: `could not reach --target-url (${err instanceof Error ? err.message : String(err)})`,
226
315
  };
227
316
  }
228
- // TLS errors and anything else unclassified: warn only — the refusal
229
- // set stays narrow to exactly what that analysis measured.
230
- return {
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: {
@@ -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' | 'bootstrap' | 'local-project-create';
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;
@@ -45,19 +45,19 @@ export declare function assertNotLocal(rawUrl: string, caller?: TargetUrlCaller)
45
45
  * verbatim in the rejection message — unchanged wording, not a new
46
46
  * classification) plus a `hintKind` telling `assertNotLocal` which hint, if
47
47
  * any, is honest to attach:
48
- * - `'loopback'` — exactly the host set `--local-host` accepts
48
+ * - `'loopback'` — exactly the host set a local environment accepts
49
49
  * (`localhost`, `127.0.0.1`, `::1`) plus the two unspecified addresses
50
- * (`0.0.0.0`, `::`), which `--local`'s default dial also reaches because
51
- * binding to "all interfaces" includes the loopback one; hint `--local`.
50
+ * (`0.0.0.0`, `::`), which the tunnel's default dial also reaches because
51
+ * binding to "all interfaces" includes the loopback one; hint the tunnel.
52
52
  * - `'loopback-other'` — the REST of `127.0.0.0/8` (e.g. `127.0.0.2`). This
53
53
  * is loopback-range and unreachable from outside the machine, same as
54
- * `'loopback'` above, but `--local-host` cannot dial it by name — an app
54
+ * `'loopback'` above, but the tunnel cannot dial it by name — an app
55
55
  * bound only to `127.0.0.2` does not answer on `127.0.0.1`. Hinting
56
- * `--local` here would recommend a command that cannot reach the address
56
+ * the tunnel here would recommend a command that cannot reach the address
57
57
  * it was just told about, so this gets no hint (a caller who reads the
58
- * reason can rebind their dev server onto `127.0.0.1` and get `--local`
58
+ * reason can rebind their dev server onto `127.0.0.1` and get the tunnel
59
59
  * to work, but that's their call to make, not a claim this code asserts).
60
- * - `'private'` — `--local` can never reach this class even in principle;
60
+ * - `'private'` — a tunnel can never reach this class even in principle;
61
61
  * hint that plainly, with no tunnel suggestion.
62
62
  * - `'undecided'` — the address genuinely cannot be decoded safely (currently
63
63
  * RFC 8215's `/48` NAT64 local-use range, whose embedded bit position differs
@@ -26,24 +26,14 @@
26
26
  */
27
27
  import * as net from 'node:net';
28
28
  import { ApiError } from './errors.js';
29
- // `--local-host` accepts EXACTLY `localhost`, `127.0.0.1`, `::1` (mirroring
29
+ // A local environment's host is EXACTLY `localhost`, `127.0.0.1` or `::1` (mirroring
30
30
  // the server's `isLoopbackString`) — not "anything loopback-shaped". This
31
31
  // hint is only honest for those three literal hosts (`0.0.0.0` and `::`
32
32
  // join them below because binding to the unspecified address also answers
33
- // on `127.0.0.1`/`::1`, so `--local`'s default dial reaches it) — NOT for
34
- // the rest of `127.0.0.0/8`, which `--local` cannot dial by name at all. See
33
+ // on `127.0.0.1`/`::1`, so the tunnel's default dial reaches it) — NOT for
34
+ // the rest of `127.0.0.0/8`, which the tunnel 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 test 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).";
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,22 +41,22 @@ 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 and require the V3 project platform.';
44
+ 'Local projects are frontend-only.';
55
45
  const DEFAULT_TARGET_URL_CALLER = {
56
46
  field: 'target-url',
57
- helpCommand: 'testsprite test run',
47
+ helpCommand: 'testsprite run',
58
48
  hintContext: 'runtime',
59
49
  };
60
50
  // Private, reserved, link-local, and metadata addresses are network-reachable from
61
51
  // the caller's own machine in general (a LAN or VPN address usually answers)
62
52
  // — what is actually true, and all this hint claims, is that TestSprite's
63
53
  // execution modes cannot target them: `--target-url` refuses them outright,
64
- // and `--local`'s tunnel only ever dials `localhost` / `127.0.0.1` / `::1`
54
+ // and a local environment's tunnel only ever dials `localhost` / `127.0.0.1` / `::1`
65
55
  // on THIS machine, never a LAN/VPC address. Embedded IPv4 addresses inherit
66
56
  // this hint only after their decoded IPv4 address lands in this class.
67
57
  const PRIVATE_NETWORK_HINT = 'This is a private/reserved network address (private, link-local, multicast, or metadata). ' +
68
- 'TestSprite cannot use it as --target-url, and --local cannot tunnel it either — --local only ' +
69
- 'reaches localhost, 127.0.0.1, or ::1 on this machine.';
58
+ "TestSprite cannot use it as --target-url, and a local environment's tunnel cannot reach it either — " +
59
+ 'a tunnel only reaches localhost, 127.0.0.1, or ::1 on this machine.';
70
60
  /**
71
61
  * Throws a local `VALIDATION_ERROR` (exit 5) when `rawUrl` is a
72
62
  * disallowed target — localhost or a private/reserved literal IP. Also rejects
@@ -97,7 +87,7 @@ export function assertNotLocal(rawUrl, caller = DEFAULT_TARGET_URL_CALLER) {
97
87
  const host = parsed.hostname.toLowerCase().replace(/\.$/, '');
98
88
  // 'localhost' is a name, not an IP literal, so it sits outside
99
89
  // `disallowedIpReason` below (which classifies IPv4/IPv6 address forms).
100
- // It is also always loopback — the same class `--local` can reach.
90
+ // It is also always loopback — the same class a tunnel can reach.
101
91
  if (host === 'localhost') {
102
92
  throw localTargetError(field, 'localhost targets are not allowed', helpCommand, localDevHintFor(hintContext));
103
93
  }
@@ -107,9 +97,9 @@ export function assertNotLocal(rawUrl, caller = DEFAULT_TARGET_URL_CALLER) {
107
97
  }
108
98
  }
109
99
  function localDevHintFor(hintContext) {
110
- if (hintContext === 'local-project-create')
111
- return LOCAL_PROJECT_CREATE_HINT;
112
- return hintContext === 'bootstrap' ? LOCAL_DEV_BOOTSTRAP_HINT : LOCAL_DEV_RUNTIME_HINT;
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
@@ -169,7 +159,7 @@ function disallowedIpv4Reason(address) {
169
159
  if (address === '0.0.0.0') {
170
160
  return { reason: UNSPECIFIED_ADDRESS_REASON, hintKind: 'loopback' };
171
161
  }
172
- // Only the literal 127.0.0.1 is in `--local-host`'s exact accepted set.
162
+ // Only the literal 127.0.0.1 is in the loopback host set a tunnel dials.
173
163
  if (ipv4LoopbackBlocklist.check(address, 'ipv4')) {
174
164
  return {
175
165
  reason: 'loopback addresses are not allowed',
@@ -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. `test run`. Empty → skip (no command). */
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;
@@ -42,8 +42,8 @@ export interface TelemetryOutcomeInput extends Partial<WaitTimeoutTelemetry> {
42
42
  output?: string;
43
43
  dryRun?: boolean;
44
44
  /**
45
- * True when --local was present, including refusals and borrowed tunnels,
46
- * or when this invocation automatically opened a saved-environment tunnel.
45
+ * True when --local was present (project env create), including refusals,
46
+ * or when this invocation opened a tunnel to a local environment.
47
47
  */
48
48
  local?: boolean;
49
49
  }
@@ -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 (`test run --all`, `testlist run`). */
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
- /** Local tunnel pool limit (1–10) and observed peak, without ids or target details. */
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); `refused_*` = refused before or at dispatch; `empty` = nothing
142
- * selected. The funnel step "`ci init` → first gated run" is computed from it.
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
@@ -169,13 +172,13 @@ export declare function sanitizeTelemetryExtras(partial: TelemetryExtrasInput):
169
172
  * never widen the wire contract from here.
170
173
  */
171
174
  export declare function recordTelemetryExtras(partial: TelemetryExtrasInput): void;
172
- /** Extend explicit --local telemetry to commands that automatically open a tunnel. */
175
+ /** Extend explicit --local telemetry to commands that open a tunnel to a local environment. */
173
176
  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 a set of polled runs — `passed` + `failed` +
178
- * `blocked` + `timedOut` = total. Unlike the CI summary's `failed` (which folds
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 `test run --all` and `testlist run` cannot
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
  */
@@ -216,7 +219,7 @@ export interface TelemetryEvent extends Partial<WaitTimeoutTelemetry>, Telemetry
216
219
  nodeVersion?: string;
217
220
  output?: string;
218
221
  ci?: boolean;
219
- /** Present (always `true`) for --local attempts or automatically opened tunnels. */
222
+ /** Present (always `true`) for --local attempts or runs that opened a tunnel. */
220
223
  local?: boolean;
221
224
  /** The validated `TESTSPRITE_CLIENT` tag (e.g. `github-action/v1`); absent when unset/invalid. */
222
225
  client?: string;
@@ -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 `test run`
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