@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
@@ -16,8 +16,7 @@ export const ERROR_CODES = [
16
16
  // `nextAction` points the operator at the Portal upload flow.
17
17
  'PAYLOAD_TOO_LARGE',
18
18
  'CONFLICT',
19
- // M3.2 piece-1 / piece-4 — `If-Match: <codeVersion>` etag mismatch on
20
- // `test code put`. Exit 6, same family as CONFLICT (the caller should
19
+ // HTTP 412 precondition failure. Exit 6, same family as CONFLICT (the caller should
21
20
  // re-fetch and retry); kept distinct so machine consumers can route on
22
21
  // it without parsing message strings.
23
22
  'PRECONDITION_FAILED',
@@ -350,9 +349,15 @@ export class ApiError extends CLIError {
350
349
  * second period produced a doubled `..` at the end of the rendered message.
351
350
  */
352
351
  export function localValidationError(field, reason, accepted, kind = 'flag') {
352
+ let argName = field;
353
+ if (kind === 'argument' && !field.startsWith('<') && !field.startsWith('[')) {
354
+ argName = `<${field.replace(/[A-Z]/g, ch => `-${ch.toLowerCase()}`)}>`;
355
+ }
353
356
  const subject = kind === 'flag'
354
357
  ? `Flag \`--${field.replace(/[A-Z]/g, ch => `-${ch.toLowerCase()}`)}\``
355
- : `Field \`${field}\``;
358
+ : kind === 'argument'
359
+ ? `Argument \`${argName}\``
360
+ : `Field \`${field}\``;
356
361
  const punctuatedReason = reason.endsWith('.') ? reason : `${reason}.`;
357
362
  return ApiError.fromEnvelope({
358
363
  error: {
@@ -369,13 +374,14 @@ export function localValidationError(field, reason, accepted, kind = 'flag') {
369
374
  * as `UNAVAILABLE` for exit-code purposes per design §8.2.
370
375
  */
371
376
  export class TransportError extends ApiError {
372
- constructor(message, requestId = 'local') {
377
+ constructor(message, requestId = 'local', options = {}) {
373
378
  super({
374
379
  code: 'UNAVAILABLE',
375
380
  message,
376
- nextAction: 'Service is temporarily unavailable. The CLI retries with exponential backoff; if this persists, report it.',
381
+ nextAction: options.nextAction ??
382
+ 'Service is temporarily unavailable. The CLI retries with exponential backoff; if this persists, report it.',
377
383
  requestId,
378
- details: {},
384
+ details: options.details ?? {},
379
385
  });
380
386
  this.name = 'TransportError';
381
387
  }
@@ -388,25 +394,39 @@ export class TransportError extends ApiError {
388
394
  * as `TimeoutError` from the polling path. Use `--request-timeout <s>` or
389
395
  * `TESTSPRITE_REQUEST_TIMEOUT_MS` to extend the deadline when targeting a
390
396
  * slow backend.
397
+ *
398
+ * A caller working against a fixed internal deadline the `--request-timeout`
399
+ * flag does not govern (e.g. the environment preflight read) passes
400
+ * `message` / `nextAction` overrides so the rendered guidance names that
401
+ * deadline instead of pointing at the flag.
391
402
  */
392
403
  export class RequestTimeoutError extends CLIError {
393
404
  requestId;
394
405
  timeoutMs;
395
- constructor(timeoutMs, requestId = 'local') {
406
+ /** Caller-specific envelope guidance; unset keeps the generic advice. */
407
+ nextAction;
408
+ constructor(timeoutMs, requestId = 'local', options = {}) {
396
409
  const timeoutSec = Math.round(timeoutMs / 1000);
397
- super(`Request timed out after ${timeoutSec}s (client-side). ` +
398
- `Use --request-timeout <seconds> or TESTSPRITE_REQUEST_TIMEOUT_MS to extend the deadline.`, 7, 'REQUEST_TIMEOUT');
410
+ super(options.message ??
411
+ `Request timed out after ${timeoutSec}s (client-side). ` +
412
+ `Use --request-timeout <seconds> or TESTSPRITE_REQUEST_TIMEOUT_MS to extend the deadline.`, 7, 'REQUEST_TIMEOUT');
399
413
  this.name = 'RequestTimeoutError';
400
414
  this.requestId = requestId;
401
415
  this.timeoutMs = timeoutMs;
416
+ if (options.nextAction !== undefined)
417
+ this.nextAction = options.nextAction;
402
418
  }
403
419
  }
404
420
  /**
405
421
  * Every facade-emitted HTTP status maps to a
406
422
  * known error code. When the envelope is missing or its `code` field is
407
- * unrecognized (proxy returned an empty body, content was mangled), we fall
408
- * back to the status-derived code so the retry budget and exit code match
409
- * what the contract promises.
423
+ * unrecognized (content was mangled), we fall back to the status-derived code
424
+ * so the retry budget and exit code match what the contract promises.
425
+ *
426
+ * `HttpClient` never routes a 4xx (other than 408/429) whose body is not JSON,
427
+ * including an empty one, through this mapping: that answer came from
428
+ * something between the CLI and the API (a proxy or firewall page), so it is
429
+ * reported as such instead of as a bad key, missing credits or an old CLI.
410
430
  */
411
431
  function codeFromHttpStatus(status) {
412
432
  switch (status) {
@@ -468,7 +488,7 @@ function isInsufficientCredits(rawCode, message, details) {
468
488
  * prod portals live on different domains); an unknown host gets the route only —
469
489
  * a hardcoded domain would point at the wrong environment.
470
490
  *
471
- * V3 API keys are membership-bound: a key minted for a team org spends THAT
491
+ * API keys are membership-bound: a key minted for a team org spends THAT
472
492
  * org's wallet, not the holder's personal one, and there is no request-scoped
473
493
  * signal at this layer to tell which kind of key just failed. So the hint
474
494
  * deliberately does NOT assert "top up your (personal) credits" as the only
@@ -480,8 +500,8 @@ function isInsufficientCredits(rawCode, message, details) {
480
500
  export function insufficientCreditsNextAction(apiUrl) {
481
501
  const portalBase = apiUrl === undefined ? undefined : resolvePortalBase(apiUrl);
482
502
  return ((portalBase !== undefined
483
- ? `Top up credits at ${portalBase}/dashboard/settings/billing (personal keys) — ask an org admin if this key is organization-bound — or upgrade your plan at ${portalBase}/pricing.`
484
- : 'Top up credits on the portal Billing page (/dashboard/settings/billing) if this is a personal key — ask an org admin if it is organization-bound — or upgrade your plan (/pricing).') +
503
+ ? `Top up credits at ${portalBase}/dashboard-v3/settings/billing (personal keys) — ask an org admin if this key is organization-bound — or upgrade your plan at ${portalBase}/pricing.`
504
+ : 'Top up credits on the portal Billing page (/dashboard-v3/settings/billing) if this is a personal key — ask an org admin if it is organization-bound — or upgrade your plan (/pricing).') +
485
505
  ' Run `testsprite usage` to check your current balance before the next run.');
486
506
  }
487
507
  /**
@@ -615,7 +635,7 @@ function parseEnvelopeBody(raw, httpStatus, apiUrl) {
615
635
  // prod portals live on different domains); unknown hosts get the route
616
636
  // only — a hardcoded domain would point at the wrong environment.
617
637
  //
618
- // V3 API keys are membership-bound: a key minted for a team org spends
638
+ // API keys are membership-bound: a key minted for a team org spends
619
639
  // THAT org's wallet, not the holder's personal one, and there is no
620
640
  // request-scoped signal here (this branch fires client-side, purely
621
641
  // from the HTTP status/body) to tell which kind of key just failed. So
@@ -7,26 +7,9 @@
7
7
  export declare const FACADE_PATH = "/api/cli/v1";
8
8
  export declare function facadeBaseUrl(endpointUrl: string): string;
9
9
  /**
10
- * Resolve the Portal dashboard deep-link for a test, given the API endpoint URL
11
- * already known to the CLI (from the user's credential profile).
12
- *
13
- * Coverage rule: only emit a dashboardUrl where BOTH projectId AND testId are
14
- * already known client-side from the create/run response — no extra network calls.
15
- * Currently covered commands:
16
- * - `test create` / `test create-batch` (projectId from opts/spec — or, on the
17
- * `--plan-from` path, from the validated plan body; testId from response).
18
- * - `test run --wait`, `test wait`, `test rerun --wait` terminal output —
19
- * `GET /runs/{runId}` carries both projectId and testId on the wire.
20
- * - `test run --all` accepted items (projectId from opts, testId per item).
21
- * NOT covered (wire gap, no lookup round-trip allowed): no-wait `test run` /
22
- * `test rerun` trigger output (TriggerRunResponse lacks projectId) and
23
- * `test result` (CliLatestResult lacks projectId).
24
- *
25
- * Normalization uses `new URL()` semantics (R2):
26
- * - Protocol and hostname are lowercased.
27
- * - An explicit `:443` on https is treated as the default port (omitted).
28
- * - Trailing slashes and FACADE_PATH suffix are stripped before parsing.
29
- * - URL parse failures → undefined (no crash).
10
+ * Map the configured API endpoint to the matching Portal origin (no path).
11
+ * Returns undefined for unknown hosts so callers emit nothing rather than a
12
+ * wrong-environment link.
30
13
  *
31
14
  * Mapping (match on normalized protocol, hostname, and port):
32
15
  * TESTSPRITE_PORTAL_URL env var set → that origin verbatim (highest
@@ -35,14 +18,9 @@ export declare function facadeBaseUrl(endpointUrl: string): string;
35
18
  * https://api.testsprite.com (port absent or 443) → https://www.testsprite.com
36
19
  * anything else (unknown host, non-https on prod, parse failure) → undefined
37
20
  *
38
- * Deep-link path: {portalBase}/dashboard/tests/{projectId}/test/{testId}
39
- */
40
- export declare function resolvePortalUrl(apiUrl: string, projectId: string, testId: string): string | undefined;
41
- /**
42
- * Map the configured API endpoint to the matching Portal origin (no path).
43
- * Honors the TESTSPRITE_PORTAL_URL override first; otherwise same
44
- * normalization and host mapping as `resolvePortalUrl` (which delegates
45
- * here); returns undefined for unknown hosts so callers emit nothing rather
46
- * than a wrong-environment link.
21
+ * Normalization uses `new URL()` semantics: protocol and hostname are
22
+ * lowercased, an explicit `:443` on https is the default port, trailing
23
+ * slashes and the FACADE_PATH suffix are stripped before parsing, and a parse
24
+ * failure → undefined (no crash).
47
25
  */
48
26
  export declare function resolvePortalBase(apiUrl: string): string | undefined;
@@ -12,26 +12,9 @@ export function facadeBaseUrl(endpointUrl) {
12
12
  return `${trimmed}${FACADE_PATH}`;
13
13
  }
14
14
  /**
15
- * Resolve the Portal dashboard deep-link for a test, given the API endpoint URL
16
- * already known to the CLI (from the user's credential profile).
17
- *
18
- * Coverage rule: only emit a dashboardUrl where BOTH projectId AND testId are
19
- * already known client-side from the create/run response — no extra network calls.
20
- * Currently covered commands:
21
- * - `test create` / `test create-batch` (projectId from opts/spec — or, on the
22
- * `--plan-from` path, from the validated plan body; testId from response).
23
- * - `test run --wait`, `test wait`, `test rerun --wait` terminal output —
24
- * `GET /runs/{runId}` carries both projectId and testId on the wire.
25
- * - `test run --all` accepted items (projectId from opts, testId per item).
26
- * NOT covered (wire gap, no lookup round-trip allowed): no-wait `test run` /
27
- * `test rerun` trigger output (TriggerRunResponse lacks projectId) and
28
- * `test result` (CliLatestResult lacks projectId).
29
- *
30
- * Normalization uses `new URL()` semantics (R2):
31
- * - Protocol and hostname are lowercased.
32
- * - An explicit `:443` on https is treated as the default port (omitted).
33
- * - Trailing slashes and FACADE_PATH suffix are stripped before parsing.
34
- * - URL parse failures → undefined (no crash).
15
+ * Map the configured API endpoint to the matching Portal origin (no path).
16
+ * Returns undefined for unknown hosts so callers emit nothing rather than a
17
+ * wrong-environment link.
35
18
  *
36
19
  * Mapping (match on normalized protocol, hostname, and port):
37
20
  * TESTSPRITE_PORTAL_URL env var set → that origin verbatim (highest
@@ -40,22 +23,10 @@ export function facadeBaseUrl(endpointUrl) {
40
23
  * https://api.testsprite.com (port absent or 443) → https://www.testsprite.com
41
24
  * anything else (unknown host, non-https on prod, parse failure) → undefined
42
25
  *
43
- * Deep-link path: {portalBase}/dashboard/tests/{projectId}/test/{testId}
44
- */
45
- export function resolvePortalUrl(apiUrl, projectId, testId) {
46
- const portalBase = resolvePortalBase(apiUrl);
47
- if (portalBase === undefined)
48
- return undefined;
49
- // R4: encode path segments so future opaque ids (e.g. containing '#' or '?')
50
- // produce a valid URL without breaking the path structure.
51
- return `${portalBase}/dashboard/tests/${encodeURIComponent(projectId)}/test/${encodeURIComponent(testId)}`;
52
- }
53
- /**
54
- * Map the configured API endpoint to the matching Portal origin (no path).
55
- * Honors the TESTSPRITE_PORTAL_URL override first; otherwise same
56
- * normalization and host mapping as `resolvePortalUrl` (which delegates
57
- * here); returns undefined for unknown hosts so callers emit nothing rather
58
- * than a wrong-environment link.
26
+ * Normalization uses `new URL()` semantics: protocol and hostname are
27
+ * lowercased, an explicit `:443` on https is the default port, trailing
28
+ * slashes and the FACADE_PATH suffix are stripped before parsing, and a parse
29
+ * failure → undefined (no crash).
59
30
  */
60
31
  export function resolvePortalBase(apiUrl) {
61
32
  // Operator override: lets any non-prod environment point dashboard links at
@@ -1,75 +1,30 @@
1
1
  /**
2
- * Auto-discovery helper for `failingFrontendTestId`.
2
+ * Dev-e2e fixture resolver: confirms that the pinned `failingFrontendTestId`
3
+ * from `fixtures.local.json` is still failing, by its latest result. The
4
+ * suite's failing-path assertions need a test whose larun is red; a pin
5
+ * that went green is reported, never silently used.
3
6
  *
4
- * Queries the dev backend's test-list endpoint for the most recently
5
- * updated frontend test with status `failed`, scoped to the project
6
- * declared in fixtures.local.json (`paginationProjectId`). Returns the
7
- * discovered id on success, or `null` when no Failed test is found, the
8
- * API call fails, or the required env / fixture preconditions are absent.
9
- *
10
- * The `null` path is intentionally non-throwing: callers fall back to the
11
- * static `fixtures.local.json` value so the suite degrades gracefully on
12
- * transient network issues.
13
- *
14
- * @see test/dev-e2e/global-setup.ts — invokes this at suite start and
15
- * writes the result to `process.env.TESTSPRITE_DEV_FAILING_FE_TEST_ID`.
16
- * @see test/dev-e2e/_shared.ts — `loadFixtures()` reads that env var and
17
- * prefers it over the static fixture file value.
18
- */
19
- /**
20
- * Minimal shape of an item returned by GET /tests.
21
- * Only the fields we need for discovery; the full shape is in tests.dev-e2e.test.ts.
7
+ * `test list` says nothing about results, so there is no scan for "the
8
+ * freshest failed test": the pin is the one source, as the README asks for a
9
+ * dedicated, permanently-red fixture.
22
10
  */
23
- export interface TestListItem {
24
- id: string;
25
- type: 'frontend' | 'backend';
26
- status: string;
27
- updatedAt: string;
28
- }
29
11
  export interface ResolverOptions {
30
12
  /** Base URL for the CLI v1 API (e.g. https://api.testsprite.com/api/cli/v1) */
31
13
  baseUrl: string;
32
14
  /** API key sent as x-api-key header */
33
15
  apiKey: string;
34
- /** Project to search within */
35
- projectId: string;
36
- /**
37
- * Optional fetch override for unit tests.
38
- * Defaults to the global `fetch` when not provided.
39
- */
40
- fetchImpl?: typeof fetch;
41
- /**
42
- * Maximum number of pages to walk (safety guard, default 5).
43
- * Each page uses pageSize=50, so 5 pages = 250 tests scanned.
44
- */
45
- maxPages?: number;
46
- /**
47
- * The operator's pinned `failingFrontendTestId` (the static value
48
- * from fixtures.local.json). "Freshest failed" alone is fragile in a shared
49
- * project: any OTHER FE test that fails more recently than a dedicated,
50
- * permanently-red fixture silently steals the slot (live-reproduced
51
- * 2026-07-16 — a `passingFrontendTestId` fresh-run flip immediately
52
- * outranked the dedicated fixture on `updatedAt`). When set, the pinned id
53
- * is probed directly first (one GET /tests/{id} — immune to the maxPages
54
- * list-scan cap); if it is currently `status:failed` it wins outright,
55
- * regardless of timestamp. If the probe errors, the list scan below still
56
- * prefers the pinned id when it appears among the candidates. Falls through
57
- * to the existing freshest-wins behavior when unset or no longer failing —
58
- * fully backward compatible.
59
- */
16
+ /** The static `failingFrontendTestId` from fixtures.local.json. */
60
17
  preferredId?: string;
18
+ /** Injectable fetch (tests). */
19
+ fetchImpl?: typeof fetch;
61
20
  }
62
21
  export interface ResolverResult {
63
- /** The resolved failing frontend test id, or null if none found. */
64
22
  testId: string | null;
65
- /** Human-readable description of how the result was obtained. */
66
23
  reason: string;
67
24
  }
68
25
  /**
69
- * Walk up to `maxPages` pages of GET /tests?projectId=...&type=frontend&status=failed
70
- * and return the item with the greatest `updatedAt` timestamp.
71
- *
72
- * Returns `{ testId: null, reason: <explanation> }` on any error or
73
- * when no Failed test exists — never throws.
26
+ * A test's newest result, as `result list --test <test-id> --limit 1` reads
27
+ * it: newest first, cancelled results left out.
74
28
  */
29
+ export declare function latestResultPath(testId: string): string;
75
30
  export declare function resolveFailingFrontendTestId(opts: ResolverOptions): Promise<ResolverResult>;
@@ -1,151 +1,66 @@
1
1
  /**
2
- * Auto-discovery helper for `failingFrontendTestId`.
2
+ * Dev-e2e fixture resolver: confirms that the pinned `failingFrontendTestId`
3
+ * from `fixtures.local.json` is still failing, by its latest result. The
4
+ * suite's failing-path assertions need a test whose larun is red; a pin
5
+ * that went green is reported, never silently used.
3
6
  *
4
- * Queries the dev backend's test-list endpoint for the most recently
5
- * updated frontend test with status `failed`, scoped to the project
6
- * declared in fixtures.local.json (`paginationProjectId`). Returns the
7
- * discovered id on success, or `null` when no Failed test is found, the
8
- * API call fails, or the required env / fixture preconditions are absent.
9
- *
10
- * The `null` path is intentionally non-throwing: callers fall back to the
11
- * static `fixtures.local.json` value so the suite degrades gracefully on
12
- * transient network issues.
13
- *
14
- * @see test/dev-e2e/global-setup.ts — invokes this at suite start and
15
- * writes the result to `process.env.TESTSPRITE_DEV_FAILING_FE_TEST_ID`.
16
- * @see test/dev-e2e/_shared.ts — `loadFixtures()` reads that env var and
17
- * prefers it over the static fixture file value.
7
+ * `test list` says nothing about results, so there is no scan for "the
8
+ * freshest failed test": the pin is the one source, as the README asks for a
9
+ * dedicated, permanently-red fixture.
18
10
  */
19
11
  /**
20
- * Walk up to `maxPages` pages of GET /tests?projectId=...&type=frontend&status=failed
21
- * and return the item with the greatest `updatedAt` timestamp.
22
- *
23
- * Returns `{ testId: null, reason: <explanation> }` on any error or
24
- * when no Failed test exists — never throws.
12
+ * A test's newest result, as `result list --test <test-id> --limit 1` reads
13
+ * it: newest first, cancelled results left out.
25
14
  */
15
+ export function latestResultPath(testId) {
16
+ return `/results?test=${encodeURIComponent(testId)}&limit=1`;
17
+ }
26
18
  export async function resolveFailingFrontendTestId(opts) {
27
- const { baseUrl, apiKey, projectId, maxPages = 5, preferredId } = opts;
19
+ const { baseUrl, apiKey, preferredId } = opts;
28
20
  const fetchImpl = opts.fetchImpl ?? fetch;
29
- // Probe the pinned fixture directly first, so the
30
- // preference cannot be defeated by the maxPages list-scan cap (a pinned
31
- // fixture beyond page `maxPages` would otherwise silently lose the slot to
32
- // an incidental fresher failure). Any probe error or non-failed status
33
- // falls through to the list scan; the in-candidates preference there
34
- // remains as a second chance after a transient probe failure.
35
- if (preferredId) {
36
- try {
37
- const resp = await fetchImpl(`${baseUrl}/tests/${encodeURIComponent(preferredId)}`, {
38
- headers: {
39
- 'x-api-key': apiKey,
40
- 'x-request-id': `dev-e2e-resolver-preferred-${Date.now()}`,
41
- accept: 'application/json',
42
- },
43
- signal: AbortSignal.timeout(10_000),
44
- });
45
- if (resp.ok) {
46
- const test = (await resp.json());
47
- // The probe must honor the resolver's project scope:
48
- // the list path filters by projectId server-side, so a pin that
49
- // points at a failed FE test in a DIFFERENT project must not win
50
- // here either. A response without a matching projectId (absent or
51
- // mismatched) falls through to the project-scoped list scan.
52
- if (test.type === 'frontend' && test.status === 'failed' && test.projectId === projectId) {
53
- return {
54
- testId: preferredId,
55
- reason: `Preferred pinned failingFrontendTestId (${preferredId}) confirmed status:failed ` +
56
- `via direct GET (updatedAt=${test.updatedAt ?? 'unknown'}); list scan skipped`,
57
- };
58
- }
59
- }
60
- }
61
- catch {
62
- // Transient probe failure — fall through to the list scan below.
63
- }
21
+ if (!preferredId) {
22
+ return { testId: null, reason: 'no failingFrontendTestId pinned in fixtures.local.json' };
64
23
  }
65
- const candidates = [];
66
- let cursor;
67
- let pagesFetched = 0;
24
+ const path = latestResultPath(preferredId);
68
25
  try {
69
- do {
70
- const url = new URL(`${baseUrl}/tests`);
71
- url.searchParams.set('projectId', projectId);
72
- url.searchParams.set('type', 'frontend');
73
- url.searchParams.set('status', 'failed');
74
- url.searchParams.set('pageSize', '50');
75
- if (cursor)
76
- url.searchParams.set('cursor', cursor);
77
- const resp = await fetchImpl(url.toString(), {
78
- headers: {
79
- 'x-api-key': apiKey,
80
- 'x-request-id': `dev-e2e-resolver-page${pagesFetched}-${Date.now()}`,
81
- accept: 'application/json',
82
- },
83
- signal: AbortSignal.timeout(10_000),
84
- });
85
- if (!resp.ok) {
86
- return {
87
- testId: null,
88
- reason: `GET /tests returned HTTP ${resp.status}; falling back to static fixture`,
89
- };
90
- }
91
- const body = (await resp.json());
92
- if (!Array.isArray(body.items)) {
93
- return {
94
- testId: null,
95
- reason: 'GET /tests response missing items array; falling back to static fixture',
96
- };
97
- }
98
- // Only keep frontend+failed items (the query params should filter, but be defensive)
99
- for (const item of body.items) {
100
- if (item.type === 'frontend' && item.status === 'failed') {
101
- candidates.push(item);
102
- }
103
- }
104
- cursor = body.nextToken ?? undefined;
105
- pagesFetched++;
106
- } while (cursor && pagesFetched < maxPages);
107
- }
108
- catch (err) {
109
- const message = err instanceof Error ? err.message : String(err);
26
+ const resp = await fetchImpl(`${baseUrl}${path}`, {
27
+ headers: {
28
+ 'x-api-key': apiKey,
29
+ 'x-request-id': `dev-e2e-resolver-${Date.now()}`,
30
+ accept: 'application/json',
31
+ },
32
+ signal: AbortSignal.timeout(10_000),
33
+ });
34
+ if (!resp.ok) {
35
+ return {
36
+ testId: null,
37
+ reason: `GET ${path} returned HTTP ${resp.status}; static fixture used as-is`,
38
+ };
39
+ }
40
+ const latest = (await resp.json()).results?.[0];
41
+ if (!latest) {
42
+ return {
43
+ testId: null,
44
+ reason: `pinned failingFrontendTestId (${preferredId}) has no result yet; run it, or re-pin a red fixture`,
45
+ };
46
+ }
47
+ const status = latest.testStatus?.toLowerCase() ?? 'unknown';
48
+ if (status === 'failed') {
49
+ return {
50
+ testId: preferredId,
51
+ reason: `pinned failingFrontendTestId (${preferredId}) is still failing (latest result created ${latest.created ?? 'unknown'})`,
52
+ };
53
+ }
110
54
  return {
111
55
  testId: null,
112
- reason: `GET /tests threw: ${message}; falling back to static fixture`,
56
+ reason: `pinned failingFrontendTestId (${preferredId}) has latest result ${status}, not failed; re-pin a red fixture`,
113
57
  };
114
58
  }
115
- if (candidates.length === 0) {
59
+ catch (err) {
116
60
  return {
117
61
  testId: null,
118
- reason: 'No frontend tests with status=failed found in project; falling back to static fixture',
62
+ reason: `probe of the pinned failingFrontendTestId failed: ${err instanceof Error ? err.message : String(err)}`,
119
63
  };
120
64
  }
121
- // A pinned, dedicated "always red" fixture wins over freshest
122
- // whenever it is still in the failed set — see the doc comment on
123
- // ResolverOptions.preferredId for why "freshest" alone is not enough.
124
- if (preferredId) {
125
- const pinned = candidates.find(c => c.id === preferredId);
126
- if (pinned) {
127
- return {
128
- testId: pinned.id,
129
- reason: `Preferred pinned failingFrontendTestId (${pinned.id}) is still status:failed (updatedAt=${pinned.updatedAt}); took priority over freshest-updatedAt candidate`,
130
- };
131
- }
132
- }
133
- // Pick the most recently updated candidate — freshest failure is the
134
- // most likely to have a valid failure bundle attached.
135
- candidates.sort((a, b) => {
136
- const ta = new Date(a.updatedAt).getTime();
137
- const tb = new Date(b.updatedAt).getTime();
138
- return tb - ta; // descending: freshest first
139
- });
140
- const best = candidates[0];
141
- if (!best) {
142
- // Unreachable: the early return above guards candidates.length === 0,
143
- // but TypeScript requires the narrowing here due to noUncheckedIndexedAccess.
144
- return { testId: null, reason: 'No candidates after sort (unexpected)' };
145
- }
146
- return {
147
- testId: best.id,
148
- reason: `Discovered from ${pagesFetched} page(s) of GET /tests; freshest failed test updatedAt=${best.updatedAt}`,
149
- };
150
65
  }
151
66
  //# sourceMappingURL=failing-fe-resolver.js.map
@@ -1,28 +1,26 @@
1
1
  /**
2
2
  * "You have a project, but no tests yet" signposts.
3
3
  *
4
- * A user who is not driving a coding agent otherwise never learns that
5
- * `test plan generate` exists: `project create` used to print the record and
6
- * stop, and the empty-project outputs said only "No tests." Every variant also
7
- * names the hand-authored fallback, because an account not yet on the new
8
- * platform is refused by generate and pointed at the Portal.
4
+ * Tests are written by the project's agent: `testsprite plan` asks it for
5
+ * tests and `testsprite apply` saves what it proposes. A user who is not
6
+ * driving a coding agent otherwise never learns that: `project create` would
7
+ * print the record and stop, and the empty-project outputs would say only
8
+ * "No tests."
9
9
  *
10
10
  * Text mode only at every call site: a JSON caller already holds the project
11
11
  * id, and stdout and the JSON error envelope must stay unchanged. Never under
12
12
  * --dry-run (the id there is the canned sample). Printing a hint runs and
13
- * charges nothing; the generation it points at does use credits.
13
+ * charges nothing.
14
14
  *
15
15
  * Zero requests: each call site branches only on what it already knows.
16
- * `project create` knows the type and whether the app is local; `test run
17
- * --all --local` knows it is local. `test list` and a cloud `test run --all`
18
- * know neither, so their sentence names the backend prerequisite as a clause
19
- * and leaves a local project to the backend's own pre-charge refusal, which
20
- * carries the same hand-written-plan next step.
16
+ * `project create` knows the type; `run --project --local` knows the app is
17
+ * on this machine. `test list` and a cloud `run --project` know neither, so
18
+ * their sentence names the backend API spec as a clause.
21
19
  */
22
20
  import { type StoredLocalTarget } from './local-target.js';
23
21
  /**
24
22
  * How the run that found the project empty chose its local target, so the
25
- * suggested `test run` reaches the same app with the same environment:
23
+ * suggested `run` reaches the same app with the same environment:
26
24
  * `port`/`host` only for an explicit `--local`, `targetUrl` for an explicit
27
25
  * `--target-url`, and `environment` for `--env` or the saved environment the
28
26
  * tunnel was resolved from.
@@ -33,23 +31,19 @@ export type LocalHint = {
33
31
  targetUrl?: string;
34
32
  environment?: string;
35
33
  };
36
- export declare const FIRST_SUITE_FALLBACK = "testsprite test create --plan-template";
37
34
  /**
38
- * Multi-line `[hint]` block for stderr after a real `project create` of a
39
- * deployed (non-`--local`) project. A `--local` project gets no hint here:
40
- * its text record already ends with the hand-written-plan next steps (plan
41
- * generation explores from the cloud with no tunnel, and the backend refuses
42
- * it for a local-origin project before any charge), and two "Next" blocks
43
- * would disagree.
35
+ * Multi-line `[hint]` block for stderr after a real `project create` (text
36
+ * mode): a new project has no environment and no tests, so it names both
37
+ * steps.
44
38
  */
45
- export declare function firstSuiteNextSteps(projectId: string, type: string): string;
39
+ export declare function firstSuiteNextSteps(wireProjectId: string, type: string): string;
46
40
  /**
47
41
  * One sentence for an EMPTY project; folded into an error message or a hint.
48
42
  *
49
43
  * Pass `local` only where the caller knows the project runs on this machine
50
- * (`test run --all --local`); see the module comment for why the other
44
+ * (`run --project --local`); see the module comment for why the other
51
45
  * callers cannot.
52
46
  */
53
- export declare function emptyProjectNextStep(projectId: string, local?: LocalHint | null): string;
47
+ export declare function emptyProjectNextStep(wireProjectId: string, local?: LocalHint | null): string;
54
48
  /** The same sentence as a stderr `[hint]` line. */
55
49
  export declare function emptyProjectHint(projectId: string, local?: LocalHint | null): string;