@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
@@ -1,107 +1,9 @@
1
1
  /**
2
- * Thin internal validation helpers shared across JSON-body validation
3
- * paths (assertPlanShape, assertPlanStepsShape, and future agent-facing
4
- * JSON input). Implemented with valibot (tree-shakeable, ~1.5 KB gzipped)
5
- * for structural detection; error envelope construction delegates to the
6
- * existing `localValidationError` helper so wording and exit codes stay
2
+ * Validation helpers for caller-supplied values that commands share. Error
3
+ * envelopes come from `localValidationError`, so wording and exit codes stay
7
4
  * consistent with the rest of the CLI.
8
- *
9
- * Design notes:
10
- * - `kind` defaults to `'field'` on every helper because these are all
11
- * JSON body paths, not CLI flags. Pass `kind: 'flag'` when validating
12
- * a real `--flag` value (e.g. in runList / runCreate input guards).
13
- * - These helpers are assertion-style (`asserts value is T`) so
14
- * TypeScript narrows the type at the call site without a cast.
15
- * - Valibot is used purely as the structural detector (safeParse). Custom
16
- * message strings are composed here so error envelope text matches the
17
- * legacy inline checks byte-for-byte — never valibot's built-in messages.
18
- * - Implements dogfood L625 option 2: valibot adoption on the plan-input
19
- * path. Future schemas can use raw `v.object({...})` directly when
20
- * more complex shape validation is needed.
21
- *
22
- * Precedence rules (documented here to prevent ambiguity):
23
- * - `allowEmpty: true` overrides `minLength` — if `allowEmpty` is set,
24
- * a zero-length string is always accepted regardless of `minLength`.
25
- * - `allowEmpty: true` and `minLength > 0` are mutually exclusive in
26
- * intent; the type system permits both but `allowEmpty` wins.
27
5
  */
28
- import * as v from 'valibot';
29
6
  import { localValidationError } from './errors.js';
30
- /**
31
- * Assert that `value` is a string, throwing a typed VALIDATION_ERROR
32
- * envelope on failure.
33
- *
34
- * @param field Field name (used in the error envelope `details.field`
35
- * and the `nextAction` line).
36
- * @param value The raw value to check.
37
- * @param opts.kind `'field'` (default) or `'flag'`.
38
- * @param opts.minLength When set, rejects strings shorter than this length
39
- * (default: 1, i.e. non-empty unless allowEmpty).
40
- * @param opts.maxLength When set, rejects strings longer than this length.
41
- * @param opts.allowEmpty When `true`, a zero-length string is accepted.
42
- * Overrides `minLength` — if both are set, the string
43
- * is accepted as long as it is a string (length ≥ 0).
44
- * Defaults to `false`. Whitespace-only strings (e.g.
45
- * `" "`) are treated as empty when `allowEmpty` is
46
- * false — they are rejected the same as `""` so junk
47
- * records cannot reach the backend (dogfood P1 fix).
48
- */
49
- export function requireString(field, value, opts = {}) {
50
- const { kind = 'field', allowEmpty = false, minLength, maxLength } = opts;
51
- // Structural check: must be a string.
52
- const typeResult = v.safeParse(v.string(), value);
53
- if (!typeResult.success) {
54
- throw localValidationError(field, 'is required and must be a non-empty string', undefined, kind);
55
- }
56
- // Whitespace-only rejection: a string composed solely of spaces/tabs/
57
- // newlines is treated as empty unless `allowEmpty` is set. This catches
58
- // cases like `--name " "` that pass the type check but produce junk
59
- // records in the backend (dogfood P1 fix #1).
60
- if (!allowEmpty && typeof value === 'string' && value.trim().length === 0 && value.length > 0) {
61
- throw localValidationError(field, 'is required and must be a non-empty string', undefined, kind);
62
- }
63
- // Length lower bound. `allowEmpty` overrides `minLength` per the
64
- // documented precedence above.
65
- const effectiveMin = allowEmpty ? 0 : (minLength ?? 1);
66
- if (effectiveMin > 0) {
67
- const minResult = v.safeParse(v.pipe(v.string(), v.minLength(effectiveMin)), value);
68
- if (!minResult.success) {
69
- throw localValidationError(field, 'is required and must be a non-empty string', undefined, kind);
70
- }
71
- }
72
- // Length upper bound.
73
- if (maxLength !== undefined) {
74
- const maxResult = v.safeParse(v.pipe(v.string(), v.maxLength(maxLength)), value);
75
- if (!maxResult.success) {
76
- throw localValidationError(field, `must be at most ${maxLength} characters`, undefined, kind);
77
- }
78
- }
79
- }
80
- /**
81
- * Assert that `value` is one of the accepted enum members, throwing a
82
- * typed VALIDATION_ERROR envelope on failure.
83
- *
84
- * The error message format is:
85
- * `must be one of: "v1", "v2", ...`
86
- *
87
- * with each accepted value quoted, comma-separated. This is the canonical
88
- * format for agent-facing JSON paths (dogfood L625 option 2).
89
- *
90
- * @param field Field name used in the error envelope.
91
- * @param value The raw value to check.
92
- * @param accepted Tuple/array of the accepted string literals.
93
- * @param opts.kind `'field'` (default) or `'flag'`.
94
- */
95
- export function requireEnum(field, value, accepted, opts = {}) {
96
- const { kind = 'field' } = opts;
97
- // Use valibot picklist for structural detection. Custom message is
98
- // composed here so the envelope text is explicit and stable.
99
- const result = v.safeParse(v.picklist(accepted), value);
100
- if (!result.success) {
101
- const acceptedList = accepted.map(a => `"${a}"`).join(', ');
102
- throw localValidationError(field, `must be one of: ${acceptedList}`, [...accepted], kind);
103
- }
104
- }
105
7
  /**
106
8
  * Validate a caller-supplied `--idempotency-key` value before it is sent as
107
9
  * an HTTP header. The HTTP spec (RFC 7230) requires header values to be ASCII
@@ -131,35 +33,4 @@ export function assertIdempotencyKey(key) {
131
33
  throw localValidationError('idempotencyKey', 'must be at most 256 characters', undefined, 'flag');
132
34
  }
133
35
  }
134
- /**
135
- * Assert that `arr` is an Array and that its length is within the given
136
- * bounds, throwing a typed VALIDATION_ERROR envelope on failure.
137
- *
138
- * @param field Field name used in the error envelope.
139
- * @param arr The raw value to check.
140
- * @param opts.min Minimum length (inclusive). Defaults to 0.
141
- * @param opts.max Maximum length (inclusive). Omit for no upper cap.
142
- * @param opts.kind `'field'` (default) or `'flag'`.
143
- * @param opts.itemNoun Singular noun used in min/max messages (e.g. `'step'`).
144
- * Defaults to `'item'`. The helper pluralises to `<noun>s`
145
- * for the max message.
146
- */
147
- export function requireArrayLength(field, arr, opts) {
148
- const { kind = 'field', min = 0, max, itemNoun = 'item' } = opts;
149
- // Structural check: must be an array.
150
- const typeResult = v.safeParse(v.array(v.unknown()), arr);
151
- if (!typeResult.success) {
152
- throw localValidationError(field, 'is required and must be an array', undefined, kind);
153
- }
154
- const arrVal = arr;
155
- // Lower bound.
156
- if (arrVal.length < min) {
157
- const minLabel = min === 1 ? `one ${itemNoun}` : `${min} ${itemNoun}s`;
158
- throw localValidationError(field, `must contain at least ${minLabel}`, undefined, kind);
159
- }
160
- // Upper bound.
161
- if (max !== undefined && arrVal.length > max) {
162
- throw localValidationError(field, `must contain at most ${max} ${itemNoun}s (got ${arrVal.length})`, undefined, kind);
163
- }
164
- }
165
36
  //# sourceMappingURL=validate.js.map
@@ -29,6 +29,7 @@
29
29
  */
30
30
  import { compareSemver, UPDATE_CHECK_OPT_OUT_ENV } from './update-check.js';
31
31
  import { VERSION } from '../version.js';
32
+ import { terminalSafeLine, terminalSafeWriter } from './terminal-text.js';
32
33
  /**
33
34
  * The gates every advisory shares: opt-out env, dry-run, a present + parseable
34
35
  * floor, and the running version strictly below it. Pure.
@@ -81,7 +82,7 @@ export function shouldWarnPinnedInActions(info, deps = {}) {
81
82
  * update-notice is the single source of truth for the newest version.
82
83
  */
83
84
  export function formatBelowFloorNotice(currentVersion, minVersion) {
84
- return (`Your testsprite-cli (${currentVersion}) is below the minimum supported version ${minVersion}. ` +
85
+ return (`Your testsprite-cli (${currentVersion}) is below the minimum supported version ${terminalSafeLine(minVersion)}. ` +
85
86
  `Upgrade: npm install -g @testsprite/testsprite-cli ` +
86
87
  `(disable this notice with ${UPDATE_CHECK_OPT_OUT_ENV}=1).`);
87
88
  }
@@ -94,7 +95,7 @@ export function formatBelowFloorNotice(currentVersion, minVersion) {
94
95
  */
95
96
  export function formatPinnedVersionWarning(currentVersion, minVersion) {
96
97
  return (`::warning title=TestSprite::testsprite-cli ${currentVersion} is pinned in this workflow ` +
97
- `and is below the minimum supported version ${minVersion}. ` +
98
+ `and is below the minimum supported version ${terminalSafeLine(minVersion)}. ` +
98
99
  `Regenerate with testsprite ci init github --force.`);
99
100
  }
100
101
  /** Module-level guard: at most one below-floor advisory per process. */
@@ -121,7 +122,7 @@ export function noteServerVersion(info, deps = {}) {
121
122
  if (!minVersion)
122
123
  return;
123
124
  const currentVersion = deps.currentVersion ?? VERSION;
124
- const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
125
+ const stderr = terminalSafeWriter(deps.stderr);
125
126
  stderr(inActions
126
127
  ? formatPinnedVersionWarning(currentVersion, minVersion)
127
128
  : formatBelowFloorNotice(currentVersion, minVersion));
@@ -8,7 +8,18 @@ import { ApiError, CLIError } from './errors.js';
8
8
  */
9
9
  export interface WaitMemberResult {
10
10
  testId?: string;
11
+ /** The result id (wire name). Printed as `resultId`. */
12
+ resultId?: string;
13
+ /** The launch the result belongs to (wire name); absent on an older backend. Printed as `runId`. */
11
14
  runId?: string;
15
+ /** True for a run this invocation joined instead of starting; see `RunRef.joined`. */
16
+ joined?: boolean;
17
+ /**
18
+ * What happened when the CLI tried to stop this run (a tunnel run it stopped
19
+ * waiting for). `'cancelled'` means the result is cancelled: result lists
20
+ * leave it out, so a later lookup has to name the result itself.
21
+ */
22
+ cancel?: string;
12
23
  status: string;
13
24
  error?: {
14
25
  code: string;
@@ -24,10 +35,34 @@ export interface WaitMemberResult {
24
35
  export declare function waitMemberError(err: ApiError): NonNullable<WaitMemberResult['error']> & {
25
36
  exitCode: number;
26
37
  };
38
+ /**
39
+ * Exit-code precedence for a `--wait` fan-out, highest first. Ordered
40
+ * batch-wide-non-retriable → per-run → transient → timeout → generic:
41
+ * - auth (3) and CLIENT_TOO_OLD (14): a bad credential / too-old client fails
42
+ * EVERY poll and retrying can never succeed — batch-wide, so they top the
43
+ * table (a transient `RATE_LIMITED` "retry later" must never outrank them).
44
+ * - INSUFFICIENT_CREDITS (12) / FEATURE_GATED (13): per-run, non-retriable.
45
+ * - NOT_FOUND (4) / VALIDATION_ERROR (5) / CONFLICT (6): per-run.
46
+ * - RATE_LIMITED (11) / UNAVAILABLE (10): transient — a retry may help.
47
+ * - timeout (7): outranks only a generic failure.
48
+ * - generic (1): the floor (genuine test-fail / INTERNAL).
49
+ * A code NOT in this table folds into the generic bucket (never surfaced as an
50
+ * operational error), so an out-of-contract exit (0, 99, a leaked signal code)
51
+ * can neither preempt a real verdict nor produce a printed-failure-green-exit.
52
+ */
53
+ export declare const WAIT_EXIT_PRIORITY: readonly [3, 14, 12, 13, 4, 5, 6, 11, 10, 7, 1];
54
+ /**
55
+ * How to get back to results a wait let go of while they may still be
56
+ * running: `run wait` / `run cancel` take the launch, so each launch is
57
+ * named once. A result the CLI cancelled (an owned tunnel's, when the wait
58
+ * gave up) cannot be resumed: it is looked up itself. With no launch id from
59
+ * the backend neither command can be given; what can still be looked up is
60
+ * each test's own results.
61
+ */
62
+ export declare function unfinishedHint(rows: readonly WaitMemberResult[]): string;
27
63
  /**
28
64
  * Resolve the process-level failure for a completed `--wait` fan-out, or `null`
29
- * when every member passed. Shared by `test run --all` / `test rerun` and
30
- * `testlist run` so their exit-code semantics can't drift.
65
+ * when every member passed. Shared by `run --project` and `run --testlist` so their exit-code semantics can't drift.
31
66
  *
32
67
  * Precedence (see {@link WAIT_EXIT_PRIORITY}): auth / client-too-old → typed
33
68
  * operational ApiError → timeout (7) → generic test-failure (1).
@@ -1,5 +1,6 @@
1
1
  import { ApiError, CLIError, isAuthCode, isErrorCode } from './errors.js';
2
2
  import { classifyBillingRefusal, isPausedReason } from './billing-refusal.js';
3
+ import { cancelCommand, checkLaterHint, launchIds, resultCount, waitCommand, } from './run-render.js';
3
4
  /**
4
5
  * Envelope metadata for a billing/feature-gate member error, keyed by the
5
6
  * IDENTITY of the object `waitMemberError` returns. The enumerable shape of
@@ -13,7 +14,8 @@ import { classifyBillingRefusal, isPausedReason } from './billing-refusal.js';
13
14
  */
14
15
  const memberEnvelopeMeta = new WeakMap();
15
16
  export function waitMemberError(err) {
16
- const memberError = { code: err.code, message: err.message, exitCode: err.exitCode };
17
+ const { message } = err;
18
+ const memberError = { code: err.code, message, exitCode: err.exitCode };
17
19
  if (err.code === 'FEATURE_GATED' || classifyBillingRefusal(err)) {
18
20
  memberEnvelopeMeta.set(memberError, {
19
21
  nextAction: err.nextAction,
@@ -57,7 +59,7 @@ function memberMeta(error) {
57
59
  * operational error), so an out-of-contract exit (0, 99, a leaked signal code)
58
60
  * can neither preempt a real verdict nor produce a printed-failure-green-exit.
59
61
  */
60
- const WAIT_EXIT_PRIORITY = [3, 14, 12, 13, 4, 5, 6, 11, 10, 7, 1];
62
+ export const WAIT_EXIT_PRIORITY = [3, 14, 12, 13, 4, 5, 6, 11, 10, 7, 1];
61
63
  /**
62
64
  * A "typed operational" code is one that sits in the precedence table above the
63
65
  * generic floor — known AND not the generic `1`. Everything else (unknown
@@ -74,10 +76,32 @@ function isOperationalCode(exitCode) {
74
76
  function priorityOf(exitCode) {
75
77
  return WAIT_EXIT_PRIORITY.indexOf(exitCode);
76
78
  }
79
+ /**
80
+ * How to get back to results a wait let go of while they may still be
81
+ * running: `run wait` / `run cancel` take the launch, so each launch is
82
+ * named once. A result the CLI cancelled (an owned tunnel's, when the wait
83
+ * gave up) cannot be resumed: it is looked up itself. With no launch id from
84
+ * the backend neither command can be given; what can still be looked up is
85
+ * each test's own results.
86
+ */
87
+ export function unfinishedHint(rows) {
88
+ const cancelled = rows.filter(r => r.cancel === 'cancelled');
89
+ const live = rows.filter(r => r.cancel !== 'cancelled');
90
+ const resume = waitCommand(live);
91
+ const cancel = cancelCommand(live);
92
+ const resumable = resume !== undefined && cancel !== undefined;
93
+ const later = checkLaterHint([...cancelled, ...(resumable ? [] : live)].map(r => ({
94
+ testId: r.testId,
95
+ resultId: r.resultId,
96
+ byResult: r.cancel === 'cancelled',
97
+ })));
98
+ return [...(resumable ? [`Resume: ${resume}`, `Cancel: ${cancel}`] : []), later]
99
+ .filter(line => line.length > 0)
100
+ .join('\n');
101
+ }
77
102
  /**
78
103
  * Resolve the process-level failure for a completed `--wait` fan-out, or `null`
79
- * when every member passed. Shared by `test run --all` / `test rerun` and
80
- * `testlist run` so their exit-code semantics can't drift.
104
+ * when every member passed. Shared by `run --project` and `run --testlist` so their exit-code semantics can't drift.
81
105
  *
82
106
  * Precedence (see {@link WAIT_EXIT_PRIORITY}): auth / client-too-old → typed
83
107
  * operational ApiError → timeout (7) → generic test-failure (1).
@@ -85,18 +109,19 @@ function priorityOf(exitCode) {
85
109
  export function resolveWaitFailure(results, opts) {
86
110
  const timedOut = results.filter(r => r.status === 'timeout');
87
111
  const errored = results.filter((r) => r.status === 'error' && r.error !== undefined);
88
- // A genuine test failure: terminal-not-passed, and not one of the synthesized
89
- // timeout/typed-error members above.
90
- const failed = results.filter(r => r.status !== 'passed' && r.status !== 'timeout' && !(r.status === 'error' && r.error));
91
- // How many runs did NOT pass — used for the auth failure count so the message
92
- // agrees with the "N failed/blocked" summary printed just above it.
93
- const notPassed = results.filter(r => r.status !== 'passed').length;
112
+ const nonPassed = results.filter(r => r.status !== 'passed');
94
113
  // 1) Auth wins over everything — the credential is bad, not the test.
95
114
  // Classified via the single `isAuthCode` source (derived from `exitCodeFor`)
96
115
  // rather than a local `=== 3` so a future AUTH_* code can't be missed here.
97
116
  const authErr = errored.find(r => isAuthCode(r.error.code));
98
117
  if (authErr) {
99
- return new CLIError(`${notPassed} run${notPassed !== 1 ? 's' : ''} failed — auth error (${authErr.error.code}): ${authErr.error.message}`, 3);
118
+ return new CLIError(`${resultCount(nonPassed.length)} did not pass — auth error (${authErr.error.code}): ${authErr.error.message}`, 3,
119
+ // Carry the member's real catalog code (AUTH_REQUIRED / AUTH_INVALID /
120
+ // AUTH_FORBIDDEN — `isAuthCode` above guarantees one of them) so the
121
+ // JSON envelope's `error.code` and telemetry's `errorCode` classify
122
+ // this as auth instead of falling into the generic 'CLI_ERROR'
123
+ // bucket — agreeing with the exit code and the message.
124
+ authErr.error.code);
100
125
  }
101
126
  // 2) Any other typed operational ApiError, highest-priority first. Only codes
102
127
  // IN the precedence table qualify — an unknown / out-of-contract code folds
@@ -121,10 +146,10 @@ export function resolveWaitFailure(results, opts) {
121
146
  if (operational) {
122
147
  const meta = memberMeta(operational.error);
123
148
  if (meta.details && isErrorCode(operational.error.code)) {
124
- // Merge the server's own details with the local runId/testId (never the
125
- // reverse) so automation reading `error.details.runId`/`testId` keeps
126
- // working for a billing refusal exactly as it does for any other typed
127
- // error, while `reason` (billing_hold / rollout / …) survives untouched.
149
+ // Merge the server's own details with the local ids (never the reverse)
150
+ // so automation reading `error.details.resultId`/`testId` keeps working
151
+ // for a billing refusal exactly as it does for any other typed error,
152
+ // while `reason` (billing_hold / rollout / …) survives untouched.
128
153
  return new ApiError({
129
154
  code: operational.error.code,
130
155
  message: operational.error.message,
@@ -132,43 +157,76 @@ export function resolveWaitFailure(results, opts) {
132
157
  requestId: meta.requestId ?? 'local',
133
158
  details: {
134
159
  ...meta.details,
135
- runId: operational.runId ?? null,
160
+ ...(operational.runId ? { runId: operational.runId } : {}),
161
+ resultId: operational.resultId ?? null,
136
162
  testId: operational.testId ?? null,
137
163
  },
138
164
  }, undefined, undefined, meta.apiUrl, meta.serverNextAction);
139
165
  }
166
+ // An outage that outlasted --timeout (UNAVAILABLE): the results not seen
167
+ // to finish keep executing, and billing, so the hint re-attaches to their
168
+ // runs. Without it the exit-10 advice is to retry, which starts and bills
169
+ // a second batch beside the first.
170
+ const unreachable = operational.error.code === 'UNAVAILABLE';
140
171
  return ApiError.fromEnvelope({
141
172
  error: {
142
173
  code: operational.error.code,
143
174
  message: operational.error.message,
144
- nextAction: '',
175
+ nextAction: unreachable
176
+ ? unfinishedHint(results.filter(r => r.status === 'timeout' ||
177
+ (r.status === 'error' && r.error?.code === 'UNAVAILABLE')))
178
+ : '',
145
179
  requestId: 'local',
146
- details: { runId: operational.runId ?? null, testId: operational.testId ?? null },
180
+ details: {
181
+ ...(operational.runId ? { runId: operational.runId } : {}),
182
+ resultId: operational.resultId ?? null,
183
+ testId: operational.testId ?? null,
184
+ },
147
185
  },
148
186
  });
149
187
  }
150
188
  // 3) Timeout — outranks a generic failure so the operator gets resume/cancel
151
189
  // guidance for the runs that didn't finish.
152
190
  if (timedOut.length > 0) {
153
- const runIds = timedOut.map(r => r.runId).filter((id) => Boolean(id));
191
+ const resultIds = timedOut.map(r => r.resultId).filter((id) => Boolean(id));
192
+ const live = timedOut.filter(r => r.cancel !== 'cancelled');
193
+ const launches = launchIds(live);
194
+ const n = timedOut.length;
154
195
  return ApiError.fromEnvelope({
155
196
  error: {
156
197
  code: 'UNSUPPORTED',
157
- message: `${timedOut.length} run${timedOut.length !== 1 ? 's' : ''} timed out.`,
158
- nextAction: [
159
- ...runIds.map(rid => `Resume: testsprite test wait ${rid}`),
160
- ...runIds.map(rid => `Cancel: testsprite test cancel ${rid}`),
161
- ].join('\n'),
198
+ message: live.length === 0
199
+ ? `${resultCount(n)} timed out and ${n === 1 ? 'was' : 'were'} cancelled.`
200
+ : `${resultCount(n)} timed out.`,
201
+ nextAction: unfinishedHint(timedOut),
162
202
  requestId: 'local',
163
- details: { timedOutRunIds: runIds, timeoutSeconds: opts.timeoutSeconds },
203
+ details: {
204
+ // The runs to resume, under the keys `run wait`'s own timeout uses.
205
+ runId: launches.length === 1 ? launches[0] : null,
206
+ runIds: launches,
207
+ timedOutResultIds: resultIds,
208
+ timeoutSeconds: opts.timeoutSeconds,
209
+ },
164
210
  },
165
211
  });
166
212
  }
167
- // 4) Generic test failures — genuine test-fails, INTERNAL (1), and any
168
- // unknown / out-of-contract error code folded here.
169
- const genericCount = failed.length + errored.filter(r => !isOperationalCode(r.error.exitCode ?? 1)).length;
170
- if (genericCount > 0) {
171
- return new CLIError(`${genericCount} run${genericCount !== 1 ? 's' : ''} failed.`, 1);
213
+ // The remaining rows are result verdicts or generic errors. Multiple
214
+ // results can belong to the same run.
215
+ if (nonPassed.length > 0) {
216
+ const failed = nonPassed.filter(row => row.status === 'failed').length;
217
+ const subject = resultCount(nonPassed.length);
218
+ if (failed === nonPassed.length)
219
+ return new CLIError(`${subject} failed.`, 1);
220
+ const blocked = nonPassed.filter(row => row.status === 'blocked').length;
221
+ const cancelled = nonPassed.filter(row => row.status === 'cancelled').length;
222
+ const other = nonPassed.length - failed - blocked - cancelled;
223
+ const detail = [
224
+ ...(failed ? [`${failed} failed`] : []),
225
+ ...(blocked ? [`${blocked} blocked`] : []),
226
+ ...(cancelled ? [`${cancelled} cancelled`] : []),
227
+ ...(other ? [`${other} unresolved`] : []),
228
+ ].join(', ');
229
+ return new CLIError(`${subject} did not pass (${detail}).`, 1);
172
230
  }
173
231
  return null;
174
232
  }
@@ -1,3 +1,11 @@
1
+ /**
2
+ * The workspace's billing standing, as `GET /me` reports it under
3
+ * `activeOrg.workspace` (backend `WorkspaceGateService.status`). `state` is
4
+ * what the FE banners key on; `notice` is the refusal every write will get
5
+ * while the workspace is paused, already worded — it is null while the
6
+ * workspace can be written to.
7
+ */
8
+ import { terminalSafeLine } from './terminal-text.js';
1
9
  /**
2
10
  * One line for the text renderers (`auth status`, `usage`) — undefined when
3
11
  * the workspace is simply on its plan, so the callers print nothing then.
@@ -7,9 +15,9 @@ export function formatWorkspaceStatus(ws) {
7
15
  if (!ws || ws.state === 'ok')
8
16
  return undefined;
9
17
  if (ws.notice)
10
- return `${ws.state} — ${ws.notice.message} ${ws.notice.cta}: ${ws.notice.billingUrl}`;
18
+ return `${terminalSafeLine(ws.state)} — ${terminalSafeLine(ws.notice.message)} ${terminalSafeLine(ws.notice.cta)}: ${terminalSafeLine(ws.notice.billingUrl)}`;
11
19
  if (ws.state === 'pending')
12
20
  return 'pending — a scheduled plan change or a payment retry is in progress; the workspace keeps working meanwhile';
13
- return ws.state;
21
+ return terminalSafeLine(ws.state);
14
22
  }
15
23
  //# sourceMappingURL=workspace-status.js.map
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.16.0";
1
+ export declare const VERSION = "0.18.0";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // AUTO-GENERATED by scripts/generate-version.mjs — do not edit by hand.
2
2
  // Run `npm run build` (or `npm run generate:version`) to regenerate.
3
- export const VERSION = '0.16.0';
3
+ export const VERSION = '0.18.0';
4
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testsprite/testsprite-cli",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Official TestSprite command-line interface",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -10,7 +10,6 @@
10
10
  "files": [
11
11
  "dist",
12
12
  "skills",
13
- "schemas",
14
13
  "!dist/**/*.map"
15
14
  ],
16
15
  "scripts": {
@@ -71,7 +70,7 @@
71
70
  "ajv": "^8.20.0",
72
71
  "eslint": "^10.7.0",
73
72
  "eslint-config-prettier": "^9.1.0",
74
- "eslint-plugin-security": "4.2.0",
73
+ "eslint-plugin-security": "4.2.1",
75
74
  "globals": "^17.7.0",
76
75
  "msw": "^2.14.3",
77
76
  "prettier": "^3.3.3",
@@ -38,17 +38,28 @@ Decide from configuration. Read `.github/workflows/` and the repo root, in this
38
38
  - No workflow deploys, and `vercel.json` / `.vercel/` / `netlify.toml` or the platform's
39
39
  git integration is present: **A — the platform deploys every PR**. Trigger:
40
40
  `on: deployment_status`.
41
+ - The platform is connected but writes **no deployment**, only a status or check on
42
+ the PR (Vercel with its `deployment_status` events switched off, Cloudflare Pages):
43
+ **C — wait for the check and derive the URL**. Trigger: `on: pull_request`.
41
44
  - Neither is clear: ask the user who deploys their pull-request previews.
42
45
 
43
- Deployment history is a reference, not the decision:
46
+ Tell A from C on a recent pull request (`<sha>` = its head commit):
44
47
 
45
48
  ```bash
46
- gh api repos/{owner}/{repo}/deployments --jq '.[] | "\(.environment) \(.ref[0:8]) \(.created_at)"'
49
+ gh api "repos/{owner}/{repo}/deployments?sha=<sha>" --jq 'length' # > 0 → A
50
+ gh api repos/{owner}/{repo}/commits/<sha>/status --jq '.statuses[].context' # the status name → C
51
+ gh api repos/{owner}/{repo}/commits/<sha>/check-runs --jq '.check_runs[].name' # or the check name → C
52
+ gh api repos/{owner}/{repo}/issues/<pr>/comments --jq '.[].body' | grep -o 'https://[a-z0-9.-]*' # the preview URL
47
53
  ```
48
54
 
49
- Recent **preview** records support A; production-only records mean preview deploys are
50
- off on the platform. History is evidence, not configuration — the proof is a real pull
51
- request (step 5).
55
+ For C, turn the URL the platform's bot posted into a pattern by replacing the per-PR
56
+ part: Vercel `https://<project>-git-{branch-slug}-<team>.vercel.app`, Cloudflare Pages
57
+ `https://{branch-slug}.<project>.pages.dev`, Netlify
58
+ `https://deploy-preview-{pr}--<site>.netlify.app` (`{branch-slug}` = the branch
59
+ lowercased, runs of other characters → `-`). Then `curl -sI` the real URL: a `302` to
60
+ `vercel.com/sso-api` is Deployment Protection — the user must disable it for previews
61
+ or create a Protection Bypass secret first. History is evidence, not configuration —
62
+ the proof is a real pull request (step 5).
52
63
 
53
64
  Not linked but the user wants A: connect the repository to the platform's git
54
65
  integration (Vercel: project → Settings → Git, or `npx vercel git connect` with the
@@ -82,13 +93,20 @@ This writes `.github/workflows/testsprite.yml` with one step marked `REPLACE ME`
82
93
  - **B:** replace the placeholder's `run:` with the deploy commands, ending in
83
94
  `echo "url=<preview address>" >> "$GITHUB_OUTPUT"`. The platform token goes in its
84
95
  own repo secret.
96
+ - **C:** keep `pull_request:`, delete the placeholder step, add
97
+ `statuses: read` and `checks: read` under `permissions:`, and extend the `ci run`
98
+ line with `--wait-for-status "<name from step 1>" --target-url-template "<pattern>"`
99
+ (drop `--target-url "$PREVIEW_URL"`). `ci run` polls the status/check for up to
100
+ `--status-timeout` (default 900 s), skips with exit 0 when the build failed or was
101
+ ignored, and refuses a pattern it cannot fill — never a production fallback.
85
102
 
86
103
  Keep what the template fixes: `testsprite ci run … --target-url "$PREVIEW_URL"
87
104
  --fail-on-skipped --summary-file`, `npm i -g @testsprite/testsprite-cli@latest` (no
88
- version pin — verdicts come from the backend), fork and draft PRs skipped, the upload
89
- step on `if: always()`, and `concurrency` on the **job** (keyed by PR number in B, by
90
- commit in A). Never re-judge pass/fail in YAML (`jq` + `exit 1`): `ci run`'s exit code
91
- is the gate. Regenerate with `--force`; the previous file is kept as `.bak`.
105
+ version pin — verdicts come from the backend), fork, Dependabot and draft PRs skipped,
106
+ the upload step on `if: always()`, and `concurrency` on the **job** (keyed by the
107
+ workflow's filename plus the PR number in B, the commit in A). Never re-judge pass/fail
108
+ in YAML (`jq` + `exit 1`): `ci run`'s exit code is the gate. Regenerate with `--force`;
109
+ the previous file is kept as `.bak`.
92
110
 
93
111
  ## 4. Secrets
94
112
 
@@ -97,8 +115,7 @@ gh secret set TESTSPRITE_API_KEY # paste when prompted, or pipe on stdin
97
115
  ```
98
116
 
99
117
  (`ci init github --set-secret` does the same.) Never put the key in argv, YAML or
100
- logs. A non-production endpoint goes in the workflow `env:` as `TESTSPRITE_API_URL`.
101
- B also needs the platform's deploy token as a secret.
118
+ logs. B also needs the platform's deploy token as a secret.
102
119
 
103
120
  ## 5. Preflight, then prove it on one real pull request
104
121
 
@@ -113,7 +130,7 @@ actionlint .github/workflows/testsprite.yml # the file parses — or `gh wor
113
130
 
114
131
  Commit and push the workflow on a branch, open a PR that is **not a draft** and has
115
132
  **no merge conflicts**, and watch the `TestSprite / testsprite-tests` check. The log shows
116
- `Dispatched N tests.` then `CI run: x/y passed …`; the job summary is the execution
133
+ `Dispatched N tests.`, `Run <runId>`, then `CI run: x/y passed …`; the job summary is the execution
117
134
  report (the same content as the App's PR comment); a `testsprite-results` artifact
118
135
  holds `testsprite-summary.json`. Then suggest making the check **required** in branch
119
136
  protection. In shape A the workflow file runs **at the deployed commit**, so the PR
@@ -132,18 +149,29 @@ deployments are filtered out by the `if:`).
132
149
 
133
150
  - The check is `ci run`'s exit code: 1 = a test failed, 7 = timeout or an unsupported
134
151
  backend, 5 = configuration. A summary opening with a **CI gate** warning means the
135
- CLI's own counts differ from the report (a run it could not read, a timeout) — the
136
- check is right, the report is the server's view of the execution.
137
- - `exit 7` with "did not confirm the single-execution admission mode" = the backend is
138
- too old for `ci run`; the dispatched runs were cancelled and refunded.
139
- - Screenshots in the report are capped at 12 per execution; later rows show `—`.
152
+ CLI's own counts differ from the report (a test result it could not read, a timeout) —
153
+ the check is right, the report is the server's view of the run.
154
+ - `exit 7` with "did not confirm the single-run admission mode" = the backend is
155
+ too old for `ci run`; the dispatched tests were cancelled (the server attempts a refund).
156
+ - `exit 5` with `target-protected` = the preview is behind Vercel Deployment Protection,
157
+ so nothing was dispatched. Ask the user to turn off Vercel Authentication for previews,
158
+ or to add a Protection Bypass for Automation secret as a repo secret and append
159
+ `?x-vercel-protection-bypass=<secret>&x-vercel-set-bypass-cookie=true` to the URL.
160
+ - Screenshots in the report are capped at 12 per run; later rows show `—`.
140
161
  - Shape A is per commit: a new push starts its own run against its own preview, and
141
- cancelling the job only stops the CLI — the execution keeps running and reports in
142
- the Portal.
143
- - Backend tests use the URL baked into their code, not `--target-url`.
144
- - Testing `ci run` locally: a shell that exports `TESTSPRITE_API_URL` or
145
- `TESTSPRITE_API_KEY` overrides `--profile` — a `fetch failed` against a healthy API is
146
- usually that. Check `env | grep TESTSPRITE_` first.
162
+ cancelling the job only stops the CLI — the run keeps running and reports in the
163
+ Portal.
164
+ - Shape C: `No preview for this commit — tests not run` with exit 0 means the platform's
165
+ check failed or the build was ignored — not a TestSprite problem; `exit 7` naming the
166
+ checks it saw means `--wait-for-status` has the wrong name — copy one from that list.
167
+ - Backend tests follow `--target-url` only where their code reads the base URL from
168
+ `VAR_{url}` (`BASE_URL = "VAR_{url}"`, replaced server-side with the run's environment
169
+ URL) — which in a pull request is the preview, because `ci run --env X --target-url U`
170
+ runs in a `github-pr-<N>` clone of X at U. Outside a pull request they use the environment's
171
+ own URL (`--env`'s, or the default's). A hard-coded URL is left as is and always tests that address.
172
+ - Testing `ci run` locally: a shell that exports `TESTSPRITE_API_KEY` overrides the
173
+ key `--profile` selects — an unexpected auth failure is usually that. Check
174
+ which are set first, without printing the key: `env | grep -o '^TESTSPRITE_[A-Z_]*'`.
147
175
 
148
176
  ## Don'ts
149
177
 
@@ -151,4 +179,5 @@ deployments are filtered out by the `if:`).
151
179
  - Don't run `vercel link --yes`; don't pass secrets as arguments.
152
180
  - Don't pin the CLI version in the workflow; don't parse the summary to decide the verdict.
153
181
  - Don't commit a loopback or private `--target-url` (`ci run` refuses it).
182
+ - Don't script a production fallback for a missing preview; `ci run` skips, on purpose.
154
183
  - Don't skip step 5: a workflow that has not run on a real PR is not onboarded.