@testsprite/testsprite-cli 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +53 -141
  2. package/dist/commands/agent.d.ts +12 -4
  3. package/dist/commands/agent.js +55 -65
  4. package/dist/commands/auth.d.ts +6 -10
  5. package/dist/commands/auth.js +44 -56
  6. package/dist/commands/ci.d.ts +23 -100
  7. package/dist/commands/ci.js +297 -489
  8. package/dist/commands/completion.js +2 -1
  9. package/dist/commands/conversation.d.ts +27 -0
  10. package/dist/commands/conversation.js +702 -0
  11. package/dist/commands/doctor.d.ts +5 -1
  12. package/dist/commands/doctor.js +130 -34
  13. package/dist/commands/init.d.ts +4 -45
  14. package/dist/commands/init.js +116 -68
  15. package/dist/commands/project-env.d.ts +62 -2
  16. package/dist/commands/project-env.js +426 -53
  17. package/dist/commands/project-sign-in.d.ts +0 -48
  18. package/dist/commands/project-sign-in.js +1 -224
  19. package/dist/commands/project.d.ts +15 -186
  20. package/dist/commands/project.js +93 -921
  21. package/dist/commands/result.d.ts +10 -0
  22. package/dist/commands/result.js +215 -0
  23. package/dist/commands/schedule.d.ts +0 -29
  24. package/dist/commands/schedule.js +47 -97
  25. package/dist/commands/test.d.ts +315 -1824
  26. package/dist/commands/test.js +1962 -13733
  27. package/dist/commands/testlist.d.ts +128 -5
  28. package/dist/commands/testlist.js +269 -329
  29. package/dist/commands/tunnel.d.ts +2 -2
  30. package/dist/commands/tunnel.js +43 -41
  31. package/dist/commands/usage.d.ts +12 -45
  32. package/dist/commands/usage.js +51 -131
  33. package/dist/index.js +189 -108
  34. package/dist/lib/agent-detect.js +9 -5
  35. package/dist/lib/agent-targets.d.ts +21 -2
  36. package/dist/lib/agent-targets.js +88 -11
  37. package/dist/lib/args.d.ts +13 -0
  38. package/dist/lib/args.js +49 -0
  39. package/dist/lib/basic-auth.d.ts +3 -0
  40. package/dist/lib/basic-auth.js +15 -0
  41. package/dist/lib/billing-refusal.js +4 -3
  42. package/dist/lib/ci-linkage.d.ts +4 -82
  43. package/dist/lib/ci-linkage.js +4 -157
  44. package/dist/lib/ci-run.js +1 -1
  45. package/dist/lib/client-factory.d.ts +10 -2
  46. package/dist/lib/client-factory.js +38 -26
  47. package/dist/lib/commit-signal.d.ts +65 -0
  48. package/dist/lib/commit-signal.js +305 -0
  49. package/dist/lib/concurrency-limiter.d.ts +6 -0
  50. package/dist/lib/concurrency-limiter.js +29 -0
  51. package/dist/lib/config.js +10 -5
  52. package/dist/lib/conflict-reason.d.ts +31 -4
  53. package/dist/lib/conflict-reason.js +38 -4
  54. package/dist/lib/conversation/answers.d.ts +9 -0
  55. package/dist/lib/conversation/answers.js +49 -0
  56. package/dist/lib/conversation/api.d.ts +71 -0
  57. package/dist/lib/conversation/api.js +150 -0
  58. package/dist/lib/conversation/change.d.ts +31 -0
  59. package/dist/lib/conversation/change.js +124 -0
  60. package/dist/lib/conversation/context.d.ts +19 -0
  61. package/dist/lib/conversation/context.js +70 -0
  62. package/dist/lib/conversation/environment.d.ts +15 -0
  63. package/dist/lib/conversation/environment.js +33 -0
  64. package/dist/lib/conversation/follow.d.ts +24 -0
  65. package/dist/lib/conversation/follow.js +42 -0
  66. package/dist/lib/conversation/render.d.ts +33 -0
  67. package/dist/lib/conversation/render.js +315 -0
  68. package/dist/lib/conversation/title.d.ts +2 -0
  69. package/dist/lib/conversation/title.js +18 -0
  70. package/dist/lib/conversation/types.d.ts +156 -0
  71. package/dist/lib/conversation/types.js +6 -0
  72. package/dist/lib/credentials.js +67 -11
  73. package/dist/lib/cron.d.ts +1 -1
  74. package/dist/lib/cron.js +2 -2
  75. package/dist/lib/dispatch-stop.d.ts +20 -0
  76. package/dist/lib/dispatch-stop.js +30 -0
  77. package/dist/lib/download.d.ts +71 -0
  78. package/dist/lib/download.js +274 -0
  79. package/dist/lib/dry-run/fetch.d.ts +10 -0
  80. package/dist/lib/dry-run/fetch.js +20 -0
  81. package/dist/lib/dry-run/samples.d.ts +6 -34
  82. package/dist/lib/dry-run/samples.js +389 -751
  83. package/dist/lib/environment-tunnel.d.ts +16 -26
  84. package/dist/lib/environment-tunnel.js +161 -157
  85. package/dist/lib/errors.d.ts +20 -4
  86. package/dist/lib/errors.js +36 -16
  87. package/dist/lib/facade.d.ts +7 -29
  88. package/dist/lib/facade.js +7 -36
  89. package/dist/lib/failing-fe-resolver.d.ts +13 -58
  90. package/dist/lib/failing-fe-resolver.js +47 -132
  91. package/dist/lib/first-suite-hint.d.ts +16 -22
  92. package/dist/lib/first-suite-hint.js +38 -47
  93. package/dist/lib/gh-output.d.ts +76 -21
  94. package/dist/lib/gh-output.js +171 -90
  95. package/dist/lib/git-utils.d.ts +56 -0
  96. package/dist/lib/git-utils.js +212 -0
  97. package/dist/lib/github-context.d.ts +2 -0
  98. package/dist/lib/github-context.js +40 -8
  99. package/dist/lib/history-retention.d.ts +6 -2
  100. package/dist/lib/history-retention.js +10 -7
  101. package/dist/lib/http.d.ts +58 -134
  102. package/dist/lib/http.js +352 -271
  103. package/dist/lib/interrupt.d.ts +14 -8
  104. package/dist/lib/interrupt.js +28 -10
  105. package/dist/lib/junit-report.d.ts +60 -4
  106. package/dist/lib/junit-report.js +209 -32
  107. package/dist/lib/local-target.d.ts +3 -3
  108. package/dist/lib/local-target.js +3 -3
  109. package/dist/lib/output.d.ts +0 -29
  110. package/dist/lib/output.js +10 -33
  111. package/dist/lib/pagination.d.ts +2 -5
  112. package/dist/lib/pagination.js +2 -5
  113. package/dist/lib/presigned-url.d.ts +22 -0
  114. package/dist/lib/presigned-url.js +90 -0
  115. package/dist/lib/prompt.js +36 -2
  116. package/dist/lib/proxy.js +2 -1
  117. package/dist/lib/redact.d.ts +2 -2
  118. package/dist/lib/redact.js +3 -4
  119. package/dist/lib/removed-commands.d.ts +18 -0
  120. package/dist/lib/removed-commands.js +154 -0
  121. package/dist/lib/render-error.d.ts +31 -6
  122. package/dist/lib/render-error.js +88 -25
  123. package/dist/lib/response-schemas.d.ts +38 -30
  124. package/dist/lib/response-schemas.js +210 -207
  125. package/dist/lib/result/api.d.ts +24 -0
  126. package/dist/lib/result/api.js +28 -0
  127. package/dist/lib/result/evidence.d.ts +71 -0
  128. package/dist/lib/result/evidence.js +420 -0
  129. package/dist/lib/result/render.d.ts +20 -0
  130. package/dist/lib/result/render.js +194 -0
  131. package/dist/lib/result/types.d.ts +122 -0
  132. package/dist/lib/result/types.js +19 -0
  133. package/dist/lib/run-output.d.ts +275 -0
  134. package/dist/lib/run-output.js +227 -0
  135. package/dist/lib/run-render.d.ts +101 -0
  136. package/dist/lib/run-render.js +183 -0
  137. package/dist/lib/run-wait.d.ts +192 -0
  138. package/dist/lib/run-wait.js +452 -0
  139. package/dist/lib/runs.types.d.ts +134 -367
  140. package/dist/lib/runs.types.js +0 -14
  141. package/dist/lib/secret-file.d.ts +1 -1
  142. package/dist/lib/secret-file.js +11 -2
  143. package/dist/lib/skill-nudge.d.ts +7 -27
  144. package/dist/lib/skill-nudge.js +9 -37
  145. package/dist/lib/target-path.d.ts +15 -0
  146. package/dist/lib/target-path.js +35 -0
  147. package/dist/lib/target-url-advisory.d.ts +19 -0
  148. package/dist/lib/target-url-advisory.js +31 -0
  149. package/dist/lib/target-url-preflight.d.ts +9 -0
  150. package/dist/lib/target-url-preflight.js +214 -106
  151. package/dist/lib/target-url.d.ts +1 -1
  152. package/dist/lib/target-url.js +6 -16
  153. package/dist/lib/telemetry.d.ts +32 -12
  154. package/dist/lib/telemetry.js +39 -8
  155. package/dist/lib/terminal-text.d.ts +41 -0
  156. package/dist/lib/terminal-text.js +127 -0
  157. package/dist/lib/testlist.types.d.ts +16 -8
  158. package/dist/lib/testlist.types.js +1 -1
  159. package/dist/lib/text-equality.d.ts +2 -0
  160. package/dist/lib/text-equality.js +5 -0
  161. package/dist/lib/text-file.d.ts +16 -0
  162. package/dist/lib/text-file.js +41 -0
  163. package/dist/lib/text-table.d.ts +46 -0
  164. package/dist/lib/text-table.js +72 -4
  165. package/dist/lib/ticker.d.ts +9 -2
  166. package/dist/lib/ticker.js +16 -3
  167. package/dist/lib/transport-failure.d.ts +22 -0
  168. package/dist/lib/transport-failure.js +126 -0
  169. package/dist/lib/tunnel-session.d.ts +7 -1
  170. package/dist/lib/tunnel-session.js +22 -9
  171. package/dist/lib/update-check.js +3 -2
  172. package/dist/lib/url-template.d.ts +43 -0
  173. package/dist/lib/url-template.js +151 -0
  174. package/dist/lib/validate.d.ts +0 -64
  175. package/dist/lib/validate.js +2 -131
  176. package/dist/lib/version-notice.js +4 -3
  177. package/dist/lib/wait-exit.d.ts +37 -2
  178. package/dist/lib/wait-exit.js +88 -30
  179. package/dist/lib/workspace-status.js +10 -2
  180. package/dist/version.d.ts +1 -1
  181. package/dist/version.js +1 -1
  182. package/package.json +3 -4
  183. package/skills/testsprite-ci.skill.md +48 -18
  184. package/skills/testsprite-onboard.skill.md +66 -151
  185. package/skills/testsprite-verify.codex.md +54 -56
  186. package/skills/testsprite-verify.skill.md +194 -358
  187. package/dist/lib/browser.d.ts +0 -6
  188. package/dist/lib/browser.js +0 -54
  189. package/dist/lib/bundle.d.ts +0 -234
  190. package/dist/lib/bundle.js +0 -781
  191. package/dist/lib/deprecate.d.ts +0 -10
  192. package/dist/lib/deprecate.js +0 -13
  193. package/dist/lib/flaky.d.ts +0 -91
  194. package/dist/lib/flaky.js +0 -71
  195. package/dist/lib/plan-poll.d.ts +0 -171
  196. package/dist/lib/plan-poll.js +0 -441
  197. package/dist/lib/plans.types.d.ts +0 -130
  198. package/dist/lib/plans.types.js +0 -31
  199. package/dist/lib/poll.d.ts +0 -100
  200. package/dist/lib/poll.js +0 -290
  201. package/dist/lib/rate-throttle.d.ts +0 -49
  202. package/dist/lib/rate-throttle.js +0 -75
  203. package/dist/lib/run-progress.d.ts +0 -41
  204. package/dist/lib/run-progress.js +0 -56
  205. package/dist/lib/v3-advisory.d.ts +0 -55
  206. package/dist/lib/v3-advisory.js +0 -74
  207. package/schemas/plan.schema.json +0 -61
@@ -46,42 +46,13 @@ export interface OutputStreams {
46
46
  */
47
47
  stdout?: (line: string) => void;
48
48
  stderr?: (line: string) => void;
49
- /**
50
- * Raw byte-oriented stdout writer. Each call writes its argument
51
- * verbatim, no trailing newline. Use {@link Output.writeChunk} to
52
- * stream content where preserving the exact byte stream matters —
53
- * e.g. dumping presigned source code to stdout for `> file.ts`
54
- * piping.
55
- *
56
- * Returning a `Promise` is the contract for honoring backpressure:
57
- * the default implementation returns a promise that resolves when
58
- * `process.stdout.write` returns `true` synchronously, or when the
59
- * stream's `'drain'` event fires if the kernel buffer was full.
60
- * Callers (e.g. the streaming loop in `streamPresignedBody`) MUST
61
- * `await` `writeChunk` so the upstream reader pauses instead of
62
- * silently piling chunks into V8's heap. Tests that ignore
63
- * backpressure may pass a sync `(text) => void` impl — the
64
- * `void | Promise<void>` return type is intentionally loose so
65
- * trivial in-memory test sinks don't have to manufacture
66
- * Promises.
67
- */
68
- rawStdout?: (text: string) => void | Promise<void>;
69
49
  }
70
50
  export declare class Output {
71
51
  private readonly mode;
72
52
  private readonly stdoutWrite;
73
53
  private readonly stderrWrite;
74
- private readonly rawStdoutWrite;
75
54
  constructor(mode?: OutputMode, streams?: OutputStreams);
76
55
  print(data: unknown, textRenderer?: (data: unknown) => string): void;
77
- /**
78
- * Write a chunk of bytes to stdout verbatim. Awaits any
79
- * Promise the rawStdout writer returns so a slow downstream
80
- * consumer pauses the upstream reader instead of buffering chunks
81
- * in memory. See `OutputStreams.rawStdout` for the backpressure
82
- * contract.
83
- */
84
- writeChunk(text: string): Promise<void>;
85
56
  /**
86
57
  * Render a terminal error. JSON mode always emits the SAME 5-key envelope
87
58
  * shape as the ApiError / InterruptError / RequestTimeoutError branches
@@ -1,5 +1,6 @@
1
1
  import { localValidationError } from './errors.js';
2
2
  import { redactDeep } from './redact.js';
3
+ import { jsonForTerminal, terminalSafe, terminalSafeLine } from './terminal-text.js';
3
4
  /**
4
5
  * Help-text footer pointing at the global options surface so users
5
6
  * looking at any subcommand `--help` don't miss `--dry-run`, `--output`,
@@ -35,7 +36,6 @@ export class Output {
35
36
  mode;
36
37
  stdoutWrite;
37
38
  stderrWrite;
38
- rawStdoutWrite;
39
39
  constructor(mode = 'text', streams = {}) {
40
40
  this.mode = mode;
41
41
  this.stdoutWrite =
@@ -48,12 +48,10 @@ export class Output {
48
48
  (line => {
49
49
  console.error(line);
50
50
  });
51
- this.rawStdoutWrite = streams.rawStdout ?? defaultRawStdout;
52
51
  }
53
52
  print(data, textRenderer) {
54
53
  // Success data is the caller's OWN content — generated test code, plans,
55
- // backend-test fixtures — and must round-trip byte-identical (`test code
56
- // get --output json` -> edit -> `test code put`), even when it
54
+ // backend-test fixtures — and JSON must round-trip it unchanged, even when it
57
55
  // legitimately contains a literal `Authorization: Bearer …` header or a
58
56
  // `password` fixture key. Never redacted here, in either mode. Secret
59
57
  // redaction (see `redact.ts`) applies only at error and request-trace
@@ -61,20 +59,12 @@ export class Output {
61
59
  // `index.ts`, and `--debug` tracing in `client-factory.ts` — never to a
62
60
  // success payload.
63
61
  if (this.mode === 'json' || !textRenderer) {
64
- this.stdoutWrite(JSON.stringify(data, null, 2));
62
+ this.stdoutWrite(jsonForTerminal(data, 2));
65
63
  return;
66
64
  }
67
- this.stdoutWrite(textRenderer(data));
68
- }
69
- /**
70
- * Write a chunk of bytes to stdout verbatim. Awaits any
71
- * Promise the rawStdout writer returns so a slow downstream
72
- * consumer pauses the upstream reader instead of buffering chunks
73
- * in memory. See `OutputStreams.rawStdout` for the backpressure
74
- * contract.
75
- */
76
- async writeChunk(text) {
77
- await this.rawStdoutWrite(text);
65
+ // Every text renderer prints server values (titles, names, errors, URLs):
66
+ // on a terminal they carry no escape sequence or control character.
67
+ this.stdoutWrite(terminalSafe(textRenderer(data)));
78
68
  }
79
69
  /**
80
70
  * Render a terminal error. JSON mode always emits the SAME 5-key envelope
@@ -101,25 +91,12 @@ export class Output {
101
91
  details: redactDeep(input.details ?? {}),
102
92
  },
103
93
  };
104
- this.stderrWrite(JSON.stringify(envelope, null, 2));
94
+ this.stderrWrite(jsonForTerminal(envelope, 2));
105
95
  return;
106
96
  }
107
- this.stderrWrite(`Error: ${input.message}`);
97
+ // A message may embed a server value: on a terminal it prints on one line
98
+ // with no escape sequence. The JSON envelope above keeps it as it is.
99
+ this.stderrWrite(`Error: ${terminalSafeLine(input.message)}`);
108
100
  }
109
101
  }
110
- /**
111
- * Default rawStdout writer. Honors stdout backpressure: when
112
- * `process.stdout.write` returns `false` the OS buffer is full, so
113
- * resolve only when `'drain'` fires. Without this an upstream stream
114
- * reader keeps pulling chunks into memory — the documented streaming
115
- * guarantee for `test code get` would silently degrade into "buffered
116
- * download piped to a slow consumer."
117
- */
118
- function defaultRawStdout(text) {
119
- if (process.stdout.write(text))
120
- return;
121
- return new Promise(resolve => {
122
- process.stdout.once('drain', () => resolve());
123
- });
124
- }
125
102
  //# sourceMappingURL=output.js.map
@@ -1,3 +1,4 @@
1
+ import type * as v from 'valibot';
1
2
  import type { HttpClient } from './http.js';
2
3
  /**
3
4
  * Page shape returned by every list endpoint per
@@ -24,10 +25,6 @@ export declare const MAX_AUTO_PAGES = 1000;
24
25
  * callers fast feedback that their flag value is out of range. Fractional,
25
26
  * sub-1, and NaN values also throw. `maxItems` is validated but not capped
26
27
  * (it is a client-side cursor, not a server parameter).
27
- *
28
- * NOTE: `runResultHistory` previously did its own silent clamp via
29
- * `Math.min(Math.max(1, n), 100)` — that was unified to this path by the
30
- * same fix wave (B-E2E-01 fix 7).
31
28
  */
32
29
  export declare function validatePaginationFlags(flags: PaginationFlags): PaginationFlags;
33
30
  export interface FetchPageArgs {
@@ -54,4 +51,4 @@ export declare function paginate<T>(fetchPage: FetchPage<T>, flags?: PaginationF
54
51
  * the cursor verbatim (no auto-follow). Used when the caller passed
55
52
  * an explicit `--page-size` and didn't ask for `--max-items`.
56
53
  */
57
- export declare function fetchSinglePage<T>(client: HttpClient, path: string, pageSize: number, cursor: string | undefined, extraQuery?: Record<string, string | number | boolean | undefined>): Promise<Page<T>>;
54
+ export declare function fetchSinglePage<T>(client: HttpClient, path: string, pageSize: number, cursor: string | undefined, extraQuery?: Record<string, string | number | boolean | undefined>, schema?: v.GenericSchema<unknown, Page<T>>): Promise<Page<T>>;
@@ -9,10 +9,6 @@ export const MAX_AUTO_PAGES = 1000;
9
9
  * callers fast feedback that their flag value is out of range. Fractional,
10
10
  * sub-1, and NaN values also throw. `maxItems` is validated but not capped
11
11
  * (it is a client-side cursor, not a server parameter).
12
- *
13
- * NOTE: `runResultHistory` previously did its own silent clamp via
14
- * `Math.min(Math.max(1, n), 100)` — that was unified to this path by the
15
- * same fix wave (B-E2E-01 fix 7).
16
12
  */
17
13
  export function validatePaginationFlags(flags) {
18
14
  const out = { ...flags };
@@ -101,9 +97,10 @@ function paginationSafetyError(reason, details) {
101
97
  * the cursor verbatim (no auto-follow). Used when the caller passed
102
98
  * an explicit `--page-size` and didn't ask for `--max-items`.
103
99
  */
104
- export async function fetchSinglePage(client, path, pageSize, cursor, extraQuery = {}) {
100
+ export async function fetchSinglePage(client, path, pageSize, cursor, extraQuery = {}, schema) {
105
101
  return client.get(path, {
106
102
  query: { ...extraQuery, pageSize, cursor },
103
+ ...(schema !== undefined ? { schema } : {}),
107
104
  });
108
105
  }
109
106
  //# sourceMappingURL=pagination.js.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Defense-in-depth on the server-minted presigned URL.
3
+ *
4
+ * A REMOTE facade must mint a non-local `https:` URL; a localhost/private or
5
+ * plain-http mint from a remote facade is exactly the anomaly to reject
6
+ * (compromised/misconfigured facade or an active MITM) — the PUT would
7
+ * otherwise send the user's file wherever that URL points, before any bytes
8
+ * leave the machine. A facade that is ITSELF loopback (dev rig, localhost
9
+ * e2e) is a deliberate operator configuration and is trusted to mint local
10
+ * URLs — and ONLY loopback qualifies: the gate is a positive, fail-closed
11
+ * check, because gating on "anything `assertNotLocal` dislikes" would
12
+ * silently disable the guard for an unparsable base URL or a user-settable
13
+ * private-range endpoint (`--endpoint-url https://10.1.2.3`). Literal checks
14
+ * only (same scope as `assertNotLocal`); no host allow-listing by design.
15
+ *
16
+ * Known residual: a loopback facade that is really a TUNNEL to a remote
17
+ * backend (`ssh -L`, a localhost corporate proxy) is trusted here even though
18
+ * the real conversation is remote and MITM-able upstream. This is inherent to
19
+ * "loopback facade = trusted dev rig" and accepted — the CLI cannot tell a
20
+ * dev rig from a tunnel by the base URL alone.
21
+ */
22
+ export declare function assertSafePresignedUploadUrl(uploadUrl: string, facadeBaseUrl: string): void;
@@ -0,0 +1,90 @@
1
+ import { ApiError } from './errors.js';
2
+ import { assertNotLocal } from './target-url.js';
3
+ /**
4
+ * Defense-in-depth on the server-minted presigned URL.
5
+ *
6
+ * A REMOTE facade must mint a non-local `https:` URL; a localhost/private or
7
+ * plain-http mint from a remote facade is exactly the anomaly to reject
8
+ * (compromised/misconfigured facade or an active MITM) — the PUT would
9
+ * otherwise send the user's file wherever that URL points, before any bytes
10
+ * leave the machine. A facade that is ITSELF loopback (dev rig, localhost
11
+ * e2e) is a deliberate operator configuration and is trusted to mint local
12
+ * URLs — and ONLY loopback qualifies: the gate is a positive, fail-closed
13
+ * check, because gating on "anything `assertNotLocal` dislikes" would
14
+ * silently disable the guard for an unparsable base URL or a user-settable
15
+ * private-range endpoint (`--endpoint-url https://10.1.2.3`). Literal checks
16
+ * only (same scope as `assertNotLocal`); no host allow-listing by design.
17
+ *
18
+ * Known residual: a loopback facade that is really a TUNNEL to a remote
19
+ * backend (`ssh -L`, a localhost corporate proxy) is trusted here even though
20
+ * the real conversation is remote and MITM-able upstream. This is inherent to
21
+ * "loopback facade = trusted dev rig" and accepted — the CLI cannot tell a
22
+ * dev rig from a tunnel by the base URL alone.
23
+ */
24
+ export function assertSafePresignedUploadUrl(uploadUrl, facadeBaseUrl) {
25
+ if (isLoopbackFacade(facadeBaseUrl))
26
+ return;
27
+ const reject = (reason) => {
28
+ throw ApiError.fromEnvelope({
29
+ error: {
30
+ code: 'VALIDATION_ERROR',
31
+ message: `Refusing the presigned upload URL the server returned: ${reason}.`,
32
+ nextAction: 'No bytes were uploaded. This can indicate a misconfigured or intercepted API ' +
33
+ 'endpoint — verify --endpoint-url / TESTSPRITE_API_URL and retry.',
34
+ requestId: 'local',
35
+ details: { field: 'uploadUrl', reason: 'unsafe_presigned_url' },
36
+ },
37
+ });
38
+ };
39
+ let parsed;
40
+ try {
41
+ parsed = new URL(uploadUrl);
42
+ }
43
+ catch {
44
+ return reject('it is not a valid URL');
45
+ }
46
+ if (parsed.protocol !== 'https:')
47
+ return reject('it is not https');
48
+ if (isLocalUrl(uploadUrl))
49
+ return reject('it points at a local/private address');
50
+ }
51
+ /** True when `assertNotLocal` rejects the URL (localhost, RFC1918, link-local,
52
+ * metadata, non-http(s), unparsable). Fail-closed in the REJECTION direction
53
+ * only — used to refuse a suspicious mint, never to grant trust (that side
54
+ * is `isLoopbackFacade`). */
55
+ function isLocalUrl(url) {
56
+ try {
57
+ assertNotLocal(url, {
58
+ field: 'upload-url',
59
+ helpCommand: 'testsprite plan',
60
+ });
61
+ return false;
62
+ }
63
+ catch {
64
+ return true;
65
+ }
66
+ }
67
+ /**
68
+ * The facade-trust gate for `assertSafePresignedUploadUrl`.
69
+ * Positive and narrow — only an explicitly-loopback facade (`localhost`,
70
+ * a `127.0.0.0/8` literal, or `[::1]`) is trusted to mint local upload URLs.
71
+ * Anything else — including an unparsable base URL or a private-range
72
+ * endpoint — leaves the guard ON.
73
+ */
74
+ function isLoopbackFacade(url) {
75
+ let parsed;
76
+ try {
77
+ parsed = new URL(url);
78
+ }
79
+ catch {
80
+ return false;
81
+ }
82
+ // `localhost.` is the fully-qualified form of `localhost` (RFC 6761).
83
+ const host = parsed.hostname.toLowerCase().replace(/\.$/, '');
84
+ if (host === 'localhost')
85
+ return true;
86
+ if (/^127\.\d+\.\d+\.\d+$/.test(host))
87
+ return true;
88
+ return host === '[::1]';
89
+ }
90
+ //# sourceMappingURL=presigned-url.js.map
@@ -1,3 +1,4 @@
1
+ import { terminalSafe } from './terminal-text.js';
1
2
  const pendingPromptInput = new WeakMap();
2
3
  export async function promptText(question, streams = {}) {
3
4
  const input = streams.input ?? process.stdin;
@@ -7,14 +8,16 @@ export async function promptText(question, streams = {}) {
7
8
  // setup / configure path (§8.1 stdout purity). stderr is still the user's
8
9
  // TTY, so the prompt remains visible.
9
10
  const output = streams.output ?? process.stderr;
10
- output.write(question);
11
+ // A question can name a server value (an environment the agent proposed):
12
+ // the terminal is shown it with no escape sequence or control character.
13
+ output.write(terminalSafe(question));
11
14
  return readLine(input, output, false);
12
15
  }
13
16
  export async function promptSecret(question, streams = {}) {
14
17
  const input = streams.input ?? process.stdin;
15
18
  // See promptText: interactive prompt + masking go to stderr, not stdout.
16
19
  const output = streams.output ?? process.stderr;
17
- output.write(question);
20
+ output.write(terminalSafe(question));
18
21
  const inputAsTTY = input;
19
22
  const useRawMode = inputAsTTY.isTTY === true && typeof inputAsTTY.setRawMode === 'function';
20
23
  if (useRawMode)
@@ -32,6 +35,13 @@ function readLine(input, output, mask) {
32
35
  let buffer = '';
33
36
  let resolved = false;
34
37
  let listening = false;
38
+ // Where we are inside a terminal escape sequence. Arrow/Home/End/Delete
39
+ // keys and bracketed-paste markers arrive as ESC-prefixed sequences
40
+ // (`ESC [ D`, `ESC [ 3 ~`, `ESC [ 200 ~`, `ESC O H`). Dropping only the
41
+ // ESC byte would keep the printable tail (`[D`) in the answer — in the
42
+ // API-key prompt that silently corrupts the key. Kept across chunks so a
43
+ // sequence split between two `data` events is still dropped whole.
44
+ let escape = 'none';
35
45
  const onData = (chunk) => {
36
46
  const str = typeof chunk === 'string' ? chunk : chunk.toString('utf-8');
37
47
  processText(str);
@@ -60,6 +70,30 @@ function readLine(input, output, mask) {
60
70
  }
61
71
  return;
62
72
  }
73
+ // Terminal escape sequences: drop the whole sequence, not just ESC.
74
+ if (escape === 'esc') {
75
+ // `ESC [` starts a CSI sequence, `ESC O` an SS3 one; any other byte
76
+ // completes a two-byte escape (e.g. Alt+key).
77
+ // A second ESC (Alt+arrow prefix) starts the next sequence.
78
+ escape = code === 0x5b ? 'csi' : code === 0x4f ? 'ss3' : code === 27 ? 'esc' : 'none';
79
+ continue;
80
+ }
81
+ if (escape === 'csi') {
82
+ // Parameter / intermediate bytes continue it; a final byte ends it.
83
+ if (code >= 0x40 && code <= 0x7e)
84
+ escape = 'none';
85
+ continue;
86
+ }
87
+ if (escape === 'ss3') {
88
+ // Parameterized SS3 (ESC O 1;5P): read through the final byte.
89
+ if (code >= 0x40 && code <= 0x7e)
90
+ escape = 'none';
91
+ continue;
92
+ }
93
+ if (code === 27) {
94
+ escape = 'esc';
95
+ continue;
96
+ }
63
97
  // Backspace / DEL
64
98
  if (code === 127 || code === 8) {
65
99
  if (buffer.length > 0) {
package/dist/lib/proxy.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { EnvHttpProxyAgent, getGlobalDispatcher, setGlobalDispatcher } from 'undici';
2
+ import { terminalSafeWriter } from './terminal-text.js';
2
3
  /**
3
4
  * Install the env-driven proxy dispatcher when any proxy variable is set
4
5
  * (both canonical upper-case and conventional lower-case spellings).
@@ -22,7 +23,7 @@ export function maybeInstallProxyAgent(deps = {}) {
22
23
  return true;
23
24
  }
24
25
  catch (error) {
25
- const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
26
+ const stderr = terminalSafeWriter(deps.stderr);
26
27
  stderr(`warning: ignoring proxy environment (could not initialize proxy agent): ${error instanceof Error ? error.message : String(error)}`);
27
28
  return false;
28
29
  }
@@ -11,8 +11,7 @@
11
11
  *
12
12
  * Deliberately NOT applied to `Output.print`'s success data: generated test
13
13
  * code, plans and backend-test fixtures are the user's OWN content and must
14
- * round-trip byte-identical (`test code get --output json` -> edit ->
15
- * `test code put`), even when they legitimately contain a literal
14
+ * round-trip byte-identical, even when they legitimately contain a literal
16
15
  * `Authorization: Bearer …` header or a `password` fixture key — that is
17
16
  * not a secret the CLI is leaking, it is the value the user is asking to see
18
17
  * back. Applied instead at `Output.error`'s `details`, the hand-built
@@ -24,6 +23,7 @@
24
23
  * `hasCredentials`, field names), so they never carry a secret to redact.
25
24
  */
26
25
  export declare const REDACTED = "[REDACTED]";
26
+ export declare function isSecretKey(key: string): boolean;
27
27
  /**
28
28
  * Deep-walk `value`, replacing:
29
29
  * - the string value of any object key matching {@link isSecretKey}, at any
@@ -11,8 +11,7 @@
11
11
  *
12
12
  * Deliberately NOT applied to `Output.print`'s success data: generated test
13
13
  * code, plans and backend-test fixtures are the user's OWN content and must
14
- * round-trip byte-identical (`test code get --output json` -> edit ->
15
- * `test code put`), even when they legitimately contain a literal
14
+ * round-trip byte-identical, even when they legitimately contain a literal
16
15
  * `Authorization: Bearer …` header or a `password` fixture key — that is
17
16
  * not a secret the CLI is leaking, it is the value the user is asking to see
18
17
  * back. Applied instead at `Output.error`'s `details`, the hand-built
@@ -58,7 +57,7 @@ const SECRET_KEY_SUFFIXES = [
58
57
  * suffix rule like the list above. This CLI's own pagination continuation
59
58
  * handles are also literally named "...Token" (`nextToken`, `startingToken`)
60
59
  * and are opaque cursors, not secrets; a suffix match on "token" would blank
61
- * them (`test result --history`'s `nextToken`, `project list`'s
60
+ * them (`test list`'s and `project list`'s
62
61
  * `startingToken`/`nextToken`). Add a new compound auth-token name here, not
63
62
  * to the suffix list above.
64
63
  */
@@ -76,7 +75,7 @@ const SECRET_TOKEN_KEYS = new Set([
76
75
  function normalizeKey(key) {
77
76
  return key.replace(/[^a-z0-9]/gi, '').toLowerCase();
78
77
  }
79
- function isSecretKey(key) {
78
+ export function isSecretKey(key) {
80
79
  const normalized = normalizeKey(key);
81
80
  if (SECRET_TOKEN_KEYS.has(normalized))
82
81
  return true;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The commands and options removed in 0.17.0, and where each one went.
3
+ * Calling one is still an unknown command or option (exit 5); the error adds
4
+ * this line, and the JSON envelope carries it as `nextAction`, so a script or
5
+ * an installed agent skill that still calls one is told what to run instead.
6
+ * The CHANGELOG's "Removed" tables are the source for every row.
7
+ */
8
+ /**
9
+ * Where an unknown command went, scoped to the group it was looked up in
10
+ * (`''` for the root).
11
+ */
12
+ export declare function removedCommandPointer(groupPath: string, name: string): string | undefined;
13
+ /**
14
+ * Where an unknown option went, from Commander's own message for it and the
15
+ * command it was given to. Only the option's name is read: it ends at `=`, so a
16
+ * value given with it (a password, from an older script) is never in the line.
17
+ */
18
+ export declare function removedOptionPointer(commandPath: string, message: string): string | undefined;
@@ -0,0 +1,154 @@
1
+ /**
2
+ * The commands and options removed in 0.17.0, and where each one went.
3
+ * Calling one is still an unknown command or option (exit 5); the error adds
4
+ * this line, and the JSON envelope carries it as `nextAction`, so a script or
5
+ * an installed agent skill that still calls one is told what to run instead.
6
+ * The CHANGELOG's "Removed" tables are the source for every row.
7
+ */
8
+ const READ_RESULTS = 'read results with: testsprite result list --test <test-id> | --run <run-id>, and testsprite result get <result-id>';
9
+ const WRITE_TESTS = 'tests are written by the project\'s agent: testsprite plan "<what to test>", then testsprite apply';
10
+ const PLAN_TESTS = 'tests are written and changed by the project\'s agent: testsprite plan "<what to test>" (or testsprite reply in an open conversation), then testsprite apply';
11
+ const CHANGE_TESTS = 'change or remove a test through the project\'s agent: testsprite plan "<test> should ..." (or testsprite reply in an open conversation), then testsprite apply';
12
+ const NO_CI_REPLACEMENT = 'there is no replacement; read deployment history with gh api repos/<owner>/<repo>/deployments and link the platform with its CLI';
13
+ /**
14
+ * Each removed command, under the group it was looked up in (`''` is the
15
+ * root), and what replaced it. Only the first unknown name is looked up, so a
16
+ * removed group's line holds for every command it had.
17
+ */
18
+ const REMOVED_COMMANDS = {
19
+ test: new Map([
20
+ ['result', READ_RESULTS],
21
+ ['steps', READ_RESULTS],
22
+ ['failure', READ_RESULTS],
23
+ ['artifact', READ_RESULTS],
24
+ ['diff', 'there is no replacement; compare two `result get` outputs'],
25
+ [
26
+ 'code',
27
+ 'view the stored test code in the Portal; change it through the project\'s agent: testsprite plan "<test> should ...", then testsprite apply',
28
+ ],
29
+ ['create', WRITE_TESTS],
30
+ ['create-batch', WRITE_TESTS],
31
+ ['scaffold', WRITE_TESTS],
32
+ ['lint', WRITE_TESTS],
33
+ ['plan', PLAN_TESTS],
34
+ ['update', CHANGE_TESTS],
35
+ ['delete', CHANGE_TESTS],
36
+ ['delete-batch', CHANGE_TESTS],
37
+ [
38
+ 'rerun',
39
+ 'use testsprite run <test-id...>, or testsprite run --project <project-id> for `--all`; `run` takes no `--status` or `--skip-terminal`',
40
+ ],
41
+ ['flaky', 'there is no replacement; run testsprite run <test-id> again'],
42
+ ['open', 'open the Dashboard: link that testsprite run prints'],
43
+ ]),
44
+ project: new Map([
45
+ ['docs', 'attach the document to the request: testsprite plan --file <path>'],
46
+ [
47
+ 'sign-in',
48
+ "an existing environment's sign-in is set in the Portal; testsprite project env create still takes the sign-in flags",
49
+ ],
50
+ [
51
+ 'credential',
52
+ 'use testsprite project env create <project-id> or testsprite project env update <project-id> <name> with --auth and --credential-file',
53
+ ],
54
+ [
55
+ 'auto-auth',
56
+ 'use testsprite project env update <project-id> <name> --auto-auth-file <json>; --auth switches it off',
57
+ ],
58
+ ]),
59
+ ci: new Map([
60
+ ['doctor', NO_CI_REPLACEMENT],
61
+ ['connect', NO_CI_REPLACEMENT],
62
+ ]),
63
+ auth: new Map([
64
+ ['configure', 'use testsprite setup'],
65
+ ['whoami', 'use testsprite auth status'],
66
+ ['logout', 'use testsprite auth remove'],
67
+ ]),
68
+ '': new Map([['init', 'use testsprite setup']]),
69
+ };
70
+ /**
71
+ * Where an unknown command went, scoped to the group it was looked up in
72
+ * (`''` for the root).
73
+ */
74
+ export function removedCommandPointer(groupPath, name) {
75
+ if (groupPath === 'test' && name === 'run')
76
+ return '`test run` was removed; use testsprite run <test-id...> or testsprite run --project <project-id>';
77
+ if (groupPath === 'test' && (name === 'wait' || name === 'cancel'))
78
+ return `\`test ${name}\` was removed; use testsprite run ${name} <run-id...>`;
79
+ if (groupPath === 'testlist' && name === 'run')
80
+ return '`testlist run` was removed; use testsprite run --testlist <list-id>; select a subset with testsprite run <test-id...> --testlist <list-id>';
81
+ if (groupPath === 'schedule' && name === 'run') {
82
+ return '`schedule run list` was removed in 0.17.0; view schedule runs in the Portal';
83
+ }
84
+ const replacement = Object.hasOwn(REMOVED_COMMANDS, groupPath)
85
+ ? REMOVED_COMMANDS[groupPath].get(name)
86
+ : undefined;
87
+ if (replacement === undefined)
88
+ return undefined;
89
+ const path = groupPath === '' ? name : `${groupPath} ${name}`;
90
+ return `\`${path}\` was removed in 0.17.0; ${replacement}`;
91
+ }
92
+ const ENV_CREATE = 'set it on an environment: testsprite project env create <project-id> --name default --url <url> (or --local <port>), which takes the sign-in flags';
93
+ const ENV_UPDATE = 'set it on an environment: testsprite project env update <project-id> <name> with the same flag';
94
+ const NO_RESULT_ON_A_CASE = 'a test case carries no result; read its results with testsprite result list --test <test-id> (--limit 1 for the latest)';
95
+ const ENVIRONMENT_OPTIONS = [
96
+ '--url',
97
+ '--local',
98
+ '--username',
99
+ '--password',
100
+ '--password-file',
101
+ '--skip-preflight',
102
+ ];
103
+ /** Each removed option, by the command that took it, and what replaced it. */
104
+ const REMOVED_OPTIONS = new Map([
105
+ ...ENVIRONMENT_OPTIONS.map((option) => [
106
+ `project create ${option}`,
107
+ ENV_CREATE,
108
+ ]),
109
+ ...ENVIRONMENT_OPTIONS.map((option) => [
110
+ `project update ${option}`,
111
+ ENV_UPDATE,
112
+ ]),
113
+ [
114
+ 'project create --description',
115
+ 'there is no replacement: a project has no description, so omit it',
116
+ ],
117
+ ['test list --status', NO_RESULT_ON_A_CASE],
118
+ ['test list --env', NO_RESULT_ON_A_CASE],
119
+ ['test list --created-from', NO_RESULT_ON_A_CASE],
120
+ ]);
121
+ /**
122
+ * The options `test run`, `test rerun` and `testlist run` took that root `run`
123
+ * never did.
124
+ */
125
+ const NOT_ON_RUN = new Map([
126
+ [
127
+ '--status',
128
+ 'name the tests: testsprite run <test-id...> with the caseKey of each result that testsprite result list --run <run-id> --status failed,blocked lists',
129
+ ],
130
+ [
131
+ '--skip-terminal',
132
+ 'there is no replacement: name the tests to run, testsprite run <test-id...>',
133
+ ],
134
+ ['--all', 'run a whole project with testsprite run --project <project-id>'],
135
+ ['--case', 'name the tests: testsprite run <test-id...> --testlist <list-id>'],
136
+ ]);
137
+ /**
138
+ * Where an unknown option went, from Commander's own message for it and the
139
+ * command it was given to. Only the option's name is read: it ends at `=`, so a
140
+ * value given with it (a password, from an older script) is never in the line.
141
+ */
142
+ export function removedOptionPointer(commandPath, message) {
143
+ const option = /unknown option '(--[^='\s]+)/.exec(message)?.[1];
144
+ if (option === undefined)
145
+ return undefined;
146
+ const notOnRun = commandPath === 'run' ? NOT_ON_RUN.get(option) : undefined;
147
+ if (notOnRun !== undefined)
148
+ return `\`run\` takes no \`${option}\`; ${notOnRun}`;
149
+ const replacement = REMOVED_OPTIONS.get(`${commandPath} ${option}`);
150
+ return replacement === undefined
151
+ ? undefined
152
+ : `\`${commandPath} ${option}\` was removed in 0.17.0; ${replacement}`;
153
+ }
154
+ //# sourceMappingURL=removed-commands.js.map
@@ -1,5 +1,6 @@
1
1
  import type { InterruptError } from './errors.js';
2
2
  import type { OutputMode } from './output.js';
3
+ import { type RunRef } from './run-render.js';
3
4
  /** The JSON-mode stderr envelope for a signal detach (errors.md §8.1). */
4
5
  export interface InterruptEnvelope {
5
6
  error: {
@@ -10,13 +11,20 @@ export interface InterruptEnvelope {
10
11
  details: Record<string, unknown>;
11
12
  };
12
13
  }
14
+ /**
15
+ * Record on an interrupt that it cut a run wait short, and which results the
16
+ * wait was still following. The envelope's hint is built from them, so it
17
+ * names the same launches as the stderr line the command prints, and says what
18
+ * cancelling stops where the command only joined a run.
19
+ */
20
+ export declare function markRunWaitInterrupt(err: InterruptError, waitedRuns: ReadonlyArray<RunRef>): void;
13
21
  /**
14
22
  * Build the `INTERRUPTED` envelope from whatever the interrupted command
15
- * attached to the error. A tunnel run attaches `tunnelDetach` and
16
- * `test plan generate` attaches `planDetach`; each carries its own
17
- * `nextAction` so the envelope never contradicts the text line the catch
18
- * block already printed. Otherwise a run wait gets the run-detach story
19
- * (`test wait`) and any other request gets the generic check-state hint.
23
+ * attached to the error. A tunnel run attaches `tunnelDetach`, which carries
24
+ * its own `nextAction` so the envelope never contradicts the text line the
25
+ * catch block already printed. Otherwise a run wait gets the run-detach story
26
+ * (`run wait` / `run cancel`, naming the launches when they are known) and
27
+ * any other request gets the generic check-state hint.
20
28
  */
21
29
  export declare function buildInterruptEnvelope(err: InterruptError): InterruptEnvelope;
22
30
  /**
@@ -37,8 +45,12 @@ export declare function buildInterruptEnvelope(err: InterruptError): InterruptEn
37
45
  * first calling outputError (should not happen for parse errors).
38
46
  * fallbackMsg: err.message from CommanderError, used when pendingMsg is null.
39
47
  * mode: the output mode resolved from --output (or argv fallback).
48
+ * removedPointer: where a removed command or option went: a line after the
49
+ * message in text, the `nextAction` in JSON. It takes the place
50
+ * of Commander's "(Did you mean …?)" line, which names a
51
+ * similarly spelled command that is not the replacement.
40
52
  */
41
- export declare function renderCommanderError(pendingMsg: string | null, fallbackMsg: string, mode: OutputMode): string;
53
+ export declare function renderCommanderError(pendingMsg: string | null, fallbackMsg: string, mode: OutputMode, removedPointer?: string): string;
42
54
  /**
43
55
  * Text-mode rendering for the `AMBIGUOUS_ORG` conflict (`details.candidates[]`
44
56
  * — an array of `{ projectId, orgId }` pairs the same testId resolved to,
@@ -55,4 +67,17 @@ export declare function renderCommanderError(pendingMsg: string | null, fallback
55
67
  export declare function renderAmbiguousOrgCandidates(candidates: unknown): string[];
56
68
  /** Text-mode recovery handles for the account's tunnel binding limit. */
57
69
  export declare function renderTunnelBindingLimitIds(details: unknown): string[];
70
+ /**
71
+ * Commander quotes the whole token in "unknown option '--password=hunter2'".
72
+ * A flag this CLI no longer registers can still arrive with a secret from an
73
+ * older script, so the value is hidden before the message is buffered. So is
74
+ * a URL that carries credentials (`https://user:password@host`), whatever the
75
+ * flag is called.
76
+ *
77
+ * The value runs to the quote Commander closes the token with, which is the
78
+ * last `'` in the message: all Commander adds after it is its "(Did you mean
79
+ * …?)" line, and an option name holds no quote. A quote or a line break
80
+ * inside the value therefore never ends what is hidden.
81
+ */
82
+ export declare function redactUnknownOptionValue(raw: string): string;
58
83
  export declare function rephraseUnknownOption(raw: string): string | null;