@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,5 +1,5 @@
1
1
  /**
2
- * `--local <port>` argument handling and the pre-charge port probe.
2
+ * Loopback target handling (`project env create --local <port>` / `--url`) and the pre-charge port probe.
3
3
  *
4
4
  * Separate from `target-url-preflight.ts` on purpose, even though both answer
5
5
  * "is the thing I am about to bill a run against actually there". They probe
@@ -9,7 +9,7 @@
9
9
  * with `fetch()` (proxy dispatcher and all) is the closest local analogue,
10
10
  * and an ambiguous result downgrades to a warning because the CLI is not
11
11
  * the machine that will do the fetching.
12
- * - `--local <port>` is dialled by the vendored tunnel client running *in
12
+ * - a local environment's address is dialled by the vendored tunnel client running *in
13
13
  * this very process*, with `net.connect`, against the candidate set
14
14
  * {@link resolveDialCandidates} produces. So the probe uses that same
15
15
  * function and the same kind of socket. A pass means at least one TCP
@@ -98,7 +98,7 @@ export function normalizeStoredLocalHost(raw) {
98
98
  throw err;
99
99
  }
100
100
  }
101
- /** Parse a loopback origin that the stored-target API and tunnel can reach. */
101
+ /** Parse a loopback URL the stored-target API and tunnel can reach: host, port and, if any, the app's entry path. */
102
102
  export function parseLoopbackTargetUrl(raw, field = 'target-url') {
103
103
  let parsed;
104
104
  try {
@@ -111,11 +111,11 @@ export function parseLoopbackTargetUrl(raw, field = 'target-url') {
111
111
  if (host === undefined)
112
112
  return undefined;
113
113
  // Read the explicit port from the input: URL.port drops the default :80.
114
- const match = /^http:\/\/(localhost|127\.0\.0\.1|\[::1\]):([0-9]+)\/?$/.exec(raw);
114
+ const match = /^http:\/\/(localhost|127\.0\.0\.1|\[::1\]):([0-9]+)(?:\/[^?#]*)?$/.exec(raw);
115
115
  const port = match === null ? 0 : Number(match[2]);
116
116
  if (match === null || !Number.isInteger(port) || port < 1 || port > 65535) {
117
- throw localValidationError(field, 'loopback URLs must use http://localhost:<port>, http://127.0.0.1:<port>, or http://[::1]:<port>, with a port between 1 and 65535 and no path ' +
118
- '(an optional trailing / is allowed), query, fragment, or credentials');
117
+ throw localValidationError(field, 'loopback URLs must use http://localhost:<port>, http://127.0.0.1:<port>, or http://[::1]:<port>, with a port between 1 and 65535; ' +
118
+ "a path may follow (the app's entry page), a query, fragment or credentials may not");
119
119
  }
120
120
  return { host, port };
121
121
  }
@@ -154,9 +154,9 @@ function flagPairError(message) {
154
154
  });
155
155
  }
156
156
  /**
157
- * Refuse a stored-target write whose loopback port has nothing listening —
158
- * the same check `project create --local` runs, so a typo in the port is
159
- * caught before a row exists anywhere. `skipPreflight` is a pure no-op.
157
+ * Refuse a stored-target write (`project env create` / `project env update`
158
+ * with `--local`) whose loopback port has nothing listening, so a typo in the
159
+ * port is caught before a row exists anywhere. `skipPreflight` is a pure no-op.
160
160
  */
161
161
  export async function assertStoredLocalTargetListening(target, opts, deps = {}) {
162
162
  if (opts.skipPreflight)
@@ -164,14 +164,15 @@ export async function assertStoredLocalTargetListening(target, opts, deps = {})
164
164
  const outcome = await probeLocalPort(target.host, target.port, deps);
165
165
  if (outcome.verdict === 'refuse') {
166
166
  const targetUrl = buildLocalTargetUrl(target.host, target.port);
167
+ const flag = opts.local !== undefined ? 'local' : 'url';
167
168
  throw ApiError.fromEnvelope({
168
169
  error: {
169
170
  code: 'VALIDATION_ERROR',
170
171
  message: `Nothing is listening on ${targetUrl}. Start your app first, or pass --skip-preflight.`,
171
- nextAction: 'Verify --local and --local-host match the app you want to test.',
172
+ nextAction: `Verify --${flag} names the port your app listens on.`,
172
173
  requestId: 'local',
173
174
  details: {
174
- field: 'local',
175
+ field: flag,
175
176
  reason: 'local-port-not-listening',
176
177
  host: target.host,
177
178
  port: target.port,
@@ -261,7 +262,7 @@ const SKIP_HINT = 'Skip this check with --skip-preflight.';
261
262
  * measured 1,003 blocked-with-URL CLI runs, 55.5% of the third-party-tunnel
262
263
  * ones blocked, every one of them charged, because the run row and its credit
263
264
  * spend happen before the Lambda ever discovers the target is dead. A dev
264
- * server that is not running is the single most likely `--local` mistake, and
265
+ * server that is not running is the single most likely local-environment mistake, and
265
266
  * this is the only place it can be caught for free.
266
267
  *
267
268
  * `skipPreflight: true` is a pure no-op with ZERO connection attempts.
@@ -279,7 +280,7 @@ export async function assertLocalPortListening(host, port, opts, _stderrFn, deps
279
280
  : `Nothing is listening on ${host}:${port}, so a tunnel run would fail after being billed.`,
280
281
  nextAction: opts.environmentName !== undefined
281
282
  ? `Start your app on ${host}:${port} (environment "${opts.environmentName}") or run with --skip-preflight.`
282
- : `Start your app on port ${port} first, or point --local at the port it is actually ` +
283
+ : `Start your app on port ${port} first, or point the environment at the port it is actually ` +
283
284
  `serving. ${SKIP_HINT}`,
284
285
  requestId: 'local',
285
286
  details: {
@@ -1,9 +1,8 @@
1
- import type { DeprecationEntry } from './deprecate.js';
2
1
  export type OutputMode = 'json' | 'text';
3
2
  /**
4
3
  * Help-text footer pointing at the global options surface so users
5
4
  * looking at any subcommand `--help` don't miss `--dry-run`, `--output`,
6
- * `--profile`, `--endpoint-url`, `--request-timeout`, `--debug`.
5
+ * `--profile`, `--request-timeout`, `--debug`.
7
6
  */
8
7
  export declare const GLOBAL_OPTS_HINT: string;
9
8
  export declare function isOutputMode(value: unknown): value is OutputMode;
@@ -47,51 +46,13 @@ export interface OutputStreams {
47
46
  */
48
47
  stdout?: (line: string) => void;
49
48
  stderr?: (line: string) => void;
50
- /**
51
- * Raw byte-oriented stdout writer. Each call writes its argument
52
- * verbatim, no trailing newline. Use {@link Output.writeChunk} to
53
- * stream content where preserving the exact byte stream matters —
54
- * e.g. dumping presigned source code to stdout for `> file.ts`
55
- * piping.
56
- *
57
- * Returning a `Promise` is the contract for honoring backpressure:
58
- * the default implementation returns a promise that resolves when
59
- * `process.stdout.write` returns `true` synchronously, or when the
60
- * stream's `'drain'` event fires if the kernel buffer was full.
61
- * Callers (e.g. the streaming loop in `streamPresignedBody`) MUST
62
- * `await` `writeChunk` so the upstream reader pauses instead of
63
- * silently piling chunks into V8's heap. Tests that ignore
64
- * backpressure may pass a sync `(text) => void` impl — the
65
- * `void | Promise<void>` return type is intentionally loose so
66
- * trivial in-memory test sinks don't have to manufacture
67
- * Promises.
68
- */
69
- rawStdout?: (text: string) => void | Promise<void>;
70
49
  }
71
50
  export declare class Output {
72
51
  private readonly mode;
73
52
  private readonly stdoutWrite;
74
53
  private readonly stderrWrite;
75
- private readonly rawStdoutWrite;
76
- private readonly deprecations;
77
- /**
78
- * `options.deprecations` is appended as the LAST key of a JSON object
79
- * payload from `print` (text mode, arrays and error envelopes are never
80
- * touched), so a deprecated command's output stays the same document plus
81
- * one trailing key.
82
- */
83
- constructor(mode?: OutputMode, streams?: OutputStreams, options?: {
84
- deprecations?: readonly DeprecationEntry[];
85
- });
54
+ constructor(mode?: OutputMode, streams?: OutputStreams);
86
55
  print(data: unknown, textRenderer?: (data: unknown) => string): void;
87
- /**
88
- * Write a chunk of bytes to stdout verbatim. Awaits any
89
- * Promise the rawStdout writer returns so a slow downstream
90
- * consumer pauses the upstream reader instead of buffering chunks
91
- * in memory. See `OutputStreams.rawStdout` for the backpressure
92
- * contract.
93
- */
94
- writeChunk(text: string): Promise<void>;
95
56
  /**
96
57
  * Render a terminal error. JSON mode always emits the SAME 5-key envelope
97
58
  * shape as the ApiError / InterruptError / RequestTimeoutError branches
@@ -1,11 +1,12 @@
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`,
6
- * `--profile`, `--endpoint-url`, `--request-timeout`, `--debug`.
7
+ * `--profile`, `--request-timeout`, `--debug`.
7
8
  */
8
- export const GLOBAL_OPTS_HINT = '\nGlobal options (--dry-run, --output, --profile, --endpoint-url, --request-timeout, --verbose, --debug):' +
9
+ export const GLOBAL_OPTS_HINT = '\nGlobal options (--dry-run, --output, --profile, --request-timeout, --verbose, --debug):' +
9
10
  '\n testsprite --help';
10
11
  export function isOutputMode(value) {
11
12
  return value === 'json' || value === 'text';
@@ -35,17 +36,8 @@ export class Output {
35
36
  mode;
36
37
  stdoutWrite;
37
38
  stderrWrite;
38
- rawStdoutWrite;
39
- deprecations;
40
- /**
41
- * `options.deprecations` is appended as the LAST key of a JSON object
42
- * payload from `print` (text mode, arrays and error envelopes are never
43
- * touched), so a deprecated command's output stays the same document plus
44
- * one trailing key.
45
- */
46
- constructor(mode = 'text', streams = {}, options = {}) {
39
+ constructor(mode = 'text', streams = {}) {
47
40
  this.mode = mode;
48
- this.deprecations = options.deprecations?.length ? options.deprecations : undefined;
49
41
  this.stdoutWrite =
50
42
  streams.stdout ??
51
43
  (line => {
@@ -56,12 +48,10 @@ export class Output {
56
48
  (line => {
57
49
  console.error(line);
58
50
  });
59
- this.rawStdoutWrite = streams.rawStdout ?? defaultRawStdout;
60
51
  }
61
52
  print(data, textRenderer) {
62
53
  // Success data is the caller's OWN content — generated test code, plans,
63
- // backend-test fixtures — and must round-trip byte-identical (`test code
64
- // get --output json` -> edit -> `test code put`), even when it
54
+ // backend-test fixtures — and JSON must round-trip it unchanged, even when it
65
55
  // legitimately contains a literal `Authorization: Bearer …` header or a
66
56
  // `password` fixture key. Never redacted here, in either mode. Secret
67
57
  // redaction (see `redact.ts`) applies only at error and request-trace
@@ -69,27 +59,12 @@ export class Output {
69
59
  // `index.ts`, and `--debug` tracing in `client-factory.ts` — never to a
70
60
  // success payload.
71
61
  if (this.mode === 'json' || !textRenderer) {
72
- const withDeprecations = this.mode === 'json' &&
73
- this.deprecations &&
74
- typeof data === 'object' &&
75
- data !== null &&
76
- !Array.isArray(data)
77
- ? { ...data, deprecations: this.deprecations }
78
- : data;
79
- this.stdoutWrite(JSON.stringify(withDeprecations, null, 2));
62
+ this.stdoutWrite(jsonForTerminal(data, 2));
80
63
  return;
81
64
  }
82
- this.stdoutWrite(textRenderer(data));
83
- }
84
- /**
85
- * Write a chunk of bytes to stdout verbatim. Awaits any
86
- * Promise the rawStdout writer returns so a slow downstream
87
- * consumer pauses the upstream reader instead of buffering chunks
88
- * in memory. See `OutputStreams.rawStdout` for the backpressure
89
- * contract.
90
- */
91
- async writeChunk(text) {
92
- 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)));
93
68
  }
94
69
  /**
95
70
  * Render a terminal error. JSON mode always emits the SAME 5-key envelope
@@ -116,25 +91,12 @@ export class Output {
116
91
  details: redactDeep(input.details ?? {}),
117
92
  },
118
93
  };
119
- this.stderrWrite(JSON.stringify(envelope, null, 2));
94
+ this.stderrWrite(jsonForTerminal(envelope, 2));
120
95
  return;
121
96
  }
122
- 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)}`);
123
100
  }
124
101
  }
125
- /**
126
- * Default rawStdout writer. Honors stdout backpressure: when
127
- * `process.stdout.write` returns `false` the OS buffer is full, so
128
- * resolve only when `'drain'` fires. Without this an upstream stream
129
- * reader keeps pulling chunks into memory — the documented streaming
130
- * guarantee for `test code get` would silently degrade into "buffered
131
- * download piped to a slow consumer."
132
- */
133
- function defaultRawStdout(text) {
134
- if (process.stdout.write(text))
135
- return;
136
- return new Promise(resolve => {
137
- process.stdout.once('drain', () => resolve());
138
- });
139
- }
140
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 an intercepted connection to the API — ' +
33
+ 'check HTTPS_PROXY and your network, then 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;