@testsprite/testsprite-cli 0.16.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.
Files changed (206) hide show
  1. package/README.md +51 -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 +38 -54
  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 +702 -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 +388 -37
  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 +15 -186
  19. package/dist/commands/project.js +89 -924
  20. package/dist/commands/result.d.ts +10 -0
  21. package/dist/commands/result.js +215 -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 -1816
  25. package/dist/commands/test.js +1951 -13902
  26. package/dist/commands/testlist.d.ts +128 -5
  27. package/dist/commands/testlist.js +269 -339
  28. package/dist/commands/tunnel.d.ts +2 -2
  29. package/dist/commands/tunnel.js +23 -19
  30. package/dist/commands/usage.d.ts +12 -45
  31. package/dist/commands/usage.js +50 -131
  32. package/dist/index.js +182 -104
  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 +10 -2
  45. package/dist/lib/client-factory.js +38 -26
  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 +71 -0
  56. package/dist/lib/conversation/api.js +150 -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 +19 -0
  60. package/dist/lib/conversation/context.js +70 -0
  61. package/dist/lib/conversation/environment.d.ts +15 -0
  62. package/dist/lib/conversation/environment.js +33 -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 +315 -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 +156 -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 +71 -0
  77. package/dist/lib/download.js +274 -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 +16 -27
  83. package/dist/lib/environment-tunnel.js +161 -154
  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 +16 -22
  91. package/dist/lib/first-suite-hint.js +38 -47
  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 +352 -289
  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 +3 -3
  107. package/dist/lib/local-target.js +3 -3
  108. package/dist/lib/output.d.ts +1 -40
  109. package/dist/lib/output.js +11 -49
  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 +154 -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 +71 -0
  127. package/dist/lib/result/evidence.js +420 -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 +1 -1
  151. package/dist/lib/target-url.js +6 -16
  152. package/dist/lib/telemetry.d.ts +31 -11
  153. package/dist/lib/telemetry.js +37 -8
  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 +7 -1
  169. package/dist/lib/tunnel-session.js +22 -9
  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 +48 -18
  183. package/skills/testsprite-onboard.skill.md +66 -151
  184. package/skills/testsprite-verify.codex.md +50 -52
  185. package/skills/testsprite-verify.skill.md +184 -351
  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;
@@ -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 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,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 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
@@ -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
@@ -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;
@@ -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
@@ -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 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
  */
@@ -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
@@ -27,8 +27,9 @@
27
27
  * Flag-derived values are limited to bounded numeric controls:
28
28
  * `timeoutSeconds` is the operator's timeout (not a URL or free text) and
29
29
  * distinguishes a wait deadline from a slow backend; `localConcurrencyLimit`
30
- * is an integer 1–10 and lets local batch outcomes be grouped by load.
31
- * `localPeakInFlight` is the observed count, also bounded by that limit.
30
+ * is the requested integer 1–15 cap for each local execution and lets local
31
+ * outcomes be grouped by the requested server limit. The CLI
32
+ * does not estimate a server-side peak from client dispatches.
32
33
  *
33
34
  * `errorOrigin` ('client' | 'server') and `timeoutSeconds` are sent by this
34
35
  * revision of the CLI. The telemetry endpoint validates against an allowlist
@@ -142,7 +143,6 @@ const COUNT_KEYS = [
142
143
  'blocked',
143
144
  'timedOut',
144
145
  'localConcurrencyLimit',
145
- 'localPeakInFlight',
146
146
  ];
147
147
  const BOOLEAN_KEYS = ['force', 'workflowExisted', 'local', 'reportReady'];
148
148
  /** Opaque server ids the beacon accepts — a UUID, nothing free-form. */
@@ -167,6 +167,9 @@ const ENUM_KEYS = {
167
167
  'gated',
168
168
  'skipped_draft',
169
169
  'skipped_no_pr',
170
+ 'skipped_no_preview',
171
+ 'timeout_preview',
172
+ 'refused_url_template',
170
173
  'refused_admission',
171
174
  'refused_env',
172
175
  'refused_preview_name',
@@ -231,13 +234,14 @@ export function takeTelemetryExtras() {
231
234
  return taken;
232
235
  }
233
236
  /**
234
- * Disjoint verdict counts over a set of polled runs — `passed` + `failed` +
235
- * `blocked` + `timedOut` = total. Unlike the CI summary's `failed` (which folds
237
+ * Disjoint verdict counts over finished polls. A test still running when the
238
+ * wait ends has no verdict. Unlike the CI summary's `failed` (which folds
236
239
  * blocked in), `blocked` is split out here because it is the signal that
237
240
  * separates a broken target from a failing assertion.
238
241
  */
239
242
  export function batchOutcomeCounts(results) {
240
243
  let passed = 0;
244
+ let failed = 0;
241
245
  let blocked = 0;
242
246
  let timedOut = 0;
243
247
  for (const r of results) {
@@ -247,12 +251,14 @@ export function batchOutcomeCounts(results) {
247
251
  blocked++;
248
252
  else if (r.status === 'timeout')
249
253
  timedOut++;
254
+ else if (r.status !== 'running')
255
+ failed++;
250
256
  }
251
- return { passed, failed: results.length - passed - blocked - timedOut, blocked, timedOut };
257
+ return { passed, failed, blocked, timedOut };
252
258
  }
253
259
  /**
254
260
  * Record a batch command's dispatch accounting (and, under `--wait`, its
255
- * verdict counts) in one call, so `test run --all` and `testlist run` cannot
261
+ * verdict counts) in one call, so `run --project` and `run --testlist` cannot
256
262
  * drift in how they count. `conflictReason` is the dominant reason of the
257
263
  * batch; `results` are the polled runs (omit for a non-wait dispatch).
258
264
  */
@@ -273,7 +279,7 @@ export function recordBatchOutcome(batch) {
273
279
  *
274
280
  * Every branch below now fills `errorCode` — the two fallback branches
275
281
  * (`CLIError`, and the final catch-all for a non-CLIError throw) previously
276
- * left it `undefined`, which is why a meaningful share of `test run`
282
+ * left it `undefined`, which is why a meaningful share of `run`
277
283
  * invocations and `setup` failures landed in telemetry with `errorCode=None`.
278
284
  *
279
285
  * `errorOrigin` ('client' | 'server') resolves a real UNSUPPORTED
@@ -428,6 +434,29 @@ export function resolveTelemetryAuth(opts, deps = {}) {
428
434
  });
429
435
  return { apiKey: config.apiKey, apiUrl: config.apiUrl };
430
436
  }
437
+ /**
438
+ * {@link resolveTelemetryAuth} for the pre-action hook, which runs before every
439
+ * command: never throws. An unreadable credentials file (EPERM/EACCES — the
440
+ * Windows ACL lock-out `doctor` diagnoses — or any other read/parse failure)
441
+ * returns `undefined` so the caller can skip the beacon and let the command run
442
+ * and report the problem its own way, as the module contract requires
443
+ * (telemetry never changes a command's behavior, output, or exit code).
444
+ * `onError` receives the swallowed error, for `--debug`.
445
+ */
446
+ export function tryResolveTelemetryAuth(opts, deps = {}) {
447
+ try {
448
+ return resolveTelemetryAuth(opts, deps);
449
+ }
450
+ catch (error) {
451
+ try {
452
+ deps.onError?.(error);
453
+ }
454
+ catch {
455
+ // A broken diagnostic sink must not turn a skipped beacon into a failure.
456
+ }
457
+ return undefined;
458
+ }
459
+ }
431
460
  /**
432
461
  * Fire one command-outcome event to the beacon. Awaited by `index.ts` before
433
462
  * `process.exit` (the flush) — bounded and fully best-effort, so it can neither