@testsprite/testsprite-cli 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +51 -147
  2. package/dist/commands/agent.d.ts +12 -4
  3. package/dist/commands/agent.js +48 -63
  4. package/dist/commands/auth.d.ts +6 -10
  5. package/dist/commands/auth.js +38 -54
  6. package/dist/commands/ci.d.ts +23 -100
  7. package/dist/commands/ci.js +293 -487
  8. package/dist/commands/conversation.d.ts +27 -0
  9. package/dist/commands/conversation.js +702 -0
  10. package/dist/commands/doctor.d.ts +5 -1
  11. package/dist/commands/doctor.js +129 -34
  12. package/dist/commands/init.d.ts +4 -45
  13. package/dist/commands/init.js +108 -66
  14. package/dist/commands/project-env.d.ts +62 -2
  15. package/dist/commands/project-env.js +388 -37
  16. package/dist/commands/project-sign-in.d.ts +0 -48
  17. package/dist/commands/project-sign-in.js +1 -229
  18. package/dist/commands/project.d.ts +15 -186
  19. package/dist/commands/project.js +89 -924
  20. package/dist/commands/result.d.ts +10 -0
  21. package/dist/commands/result.js +215 -0
  22. package/dist/commands/schedule.d.ts +0 -29
  23. package/dist/commands/schedule.js +28 -87
  24. package/dist/commands/test.d.ts +301 -1816
  25. package/dist/commands/test.js +1951 -13902
  26. package/dist/commands/testlist.d.ts +128 -5
  27. package/dist/commands/testlist.js +269 -339
  28. package/dist/commands/tunnel.d.ts +2 -2
  29. package/dist/commands/tunnel.js +23 -19
  30. package/dist/commands/usage.d.ts +12 -45
  31. package/dist/commands/usage.js +50 -131
  32. package/dist/index.js +182 -104
  33. package/dist/lib/agent-detect.js +9 -5
  34. package/dist/lib/agent-targets.d.ts +21 -2
  35. package/dist/lib/agent-targets.js +88 -11
  36. package/dist/lib/args.d.ts +13 -0
  37. package/dist/lib/args.js +49 -0
  38. package/dist/lib/basic-auth.d.ts +3 -0
  39. package/dist/lib/basic-auth.js +15 -0
  40. package/dist/lib/billing-refusal.js +4 -3
  41. package/dist/lib/ci-linkage.d.ts +4 -82
  42. package/dist/lib/ci-linkage.js +4 -157
  43. package/dist/lib/ci-run.js +1 -1
  44. package/dist/lib/client-factory.d.ts +10 -2
  45. package/dist/lib/client-factory.js +38 -26
  46. package/dist/lib/commit-signal.d.ts +65 -0
  47. package/dist/lib/commit-signal.js +305 -0
  48. package/dist/lib/concurrency-limiter.d.ts +6 -0
  49. package/dist/lib/concurrency-limiter.js +29 -0
  50. package/dist/lib/config.js +10 -5
  51. package/dist/lib/conflict-reason.d.ts +9 -3
  52. package/dist/lib/conflict-reason.js +6 -3
  53. package/dist/lib/conversation/answers.d.ts +9 -0
  54. package/dist/lib/conversation/answers.js +49 -0
  55. package/dist/lib/conversation/api.d.ts +71 -0
  56. package/dist/lib/conversation/api.js +150 -0
  57. package/dist/lib/conversation/change.d.ts +31 -0
  58. package/dist/lib/conversation/change.js +124 -0
  59. package/dist/lib/conversation/context.d.ts +19 -0
  60. package/dist/lib/conversation/context.js +70 -0
  61. package/dist/lib/conversation/environment.d.ts +15 -0
  62. package/dist/lib/conversation/environment.js +33 -0
  63. package/dist/lib/conversation/follow.d.ts +24 -0
  64. package/dist/lib/conversation/follow.js +42 -0
  65. package/dist/lib/conversation/render.d.ts +33 -0
  66. package/dist/lib/conversation/render.js +315 -0
  67. package/dist/lib/conversation/title.d.ts +2 -0
  68. package/dist/lib/conversation/title.js +18 -0
  69. package/dist/lib/conversation/types.d.ts +156 -0
  70. package/dist/lib/conversation/types.js +6 -0
  71. package/dist/lib/credentials.js +67 -11
  72. package/dist/lib/cron.d.ts +1 -1
  73. package/dist/lib/cron.js +2 -2
  74. package/dist/lib/dispatch-stop.d.ts +20 -0
  75. package/dist/lib/dispatch-stop.js +30 -0
  76. package/dist/lib/download.d.ts +71 -0
  77. package/dist/lib/download.js +274 -0
  78. package/dist/lib/dry-run/fetch.d.ts +10 -0
  79. package/dist/lib/dry-run/fetch.js +20 -0
  80. package/dist/lib/dry-run/samples.d.ts +6 -34
  81. package/dist/lib/dry-run/samples.js +375 -747
  82. package/dist/lib/environment-tunnel.d.ts +16 -27
  83. package/dist/lib/environment-tunnel.js +161 -154
  84. package/dist/lib/errors.d.ts +20 -4
  85. package/dist/lib/errors.js +36 -16
  86. package/dist/lib/facade.d.ts +7 -29
  87. package/dist/lib/facade.js +7 -36
  88. package/dist/lib/failing-fe-resolver.d.ts +13 -58
  89. package/dist/lib/failing-fe-resolver.js +47 -132
  90. package/dist/lib/first-suite-hint.d.ts +16 -22
  91. package/dist/lib/first-suite-hint.js +38 -47
  92. package/dist/lib/gh-output.d.ts +76 -21
  93. package/dist/lib/gh-output.js +171 -90
  94. package/dist/lib/git-utils.d.ts +56 -0
  95. package/dist/lib/git-utils.js +212 -0
  96. package/dist/lib/github-context.d.ts +2 -0
  97. package/dist/lib/github-context.js +40 -8
  98. package/dist/lib/history-retention.d.ts +6 -2
  99. package/dist/lib/history-retention.js +10 -7
  100. package/dist/lib/http.d.ts +58 -134
  101. package/dist/lib/http.js +352 -289
  102. package/dist/lib/interrupt.d.ts +14 -8
  103. package/dist/lib/interrupt.js +28 -10
  104. package/dist/lib/junit-report.d.ts +57 -4
  105. package/dist/lib/junit-report.js +202 -32
  106. package/dist/lib/local-target.d.ts +3 -3
  107. package/dist/lib/local-target.js +3 -3
  108. package/dist/lib/output.d.ts +1 -40
  109. package/dist/lib/output.js +11 -49
  110. package/dist/lib/pagination.d.ts +2 -5
  111. package/dist/lib/pagination.js +2 -5
  112. package/dist/lib/presigned-url.d.ts +22 -0
  113. package/dist/lib/presigned-url.js +90 -0
  114. package/dist/lib/prompt.js +36 -2
  115. package/dist/lib/proxy.js +2 -1
  116. package/dist/lib/redact.d.ts +2 -2
  117. package/dist/lib/redact.js +3 -4
  118. package/dist/lib/removed-commands.d.ts +18 -0
  119. package/dist/lib/removed-commands.js +154 -0
  120. package/dist/lib/render-error.d.ts +31 -6
  121. package/dist/lib/render-error.js +88 -25
  122. package/dist/lib/response-schemas.d.ts +38 -30
  123. package/dist/lib/response-schemas.js +207 -207
  124. package/dist/lib/result/api.d.ts +24 -0
  125. package/dist/lib/result/api.js +28 -0
  126. package/dist/lib/result/evidence.d.ts +71 -0
  127. package/dist/lib/result/evidence.js +420 -0
  128. package/dist/lib/result/render.d.ts +20 -0
  129. package/dist/lib/result/render.js +194 -0
  130. package/dist/lib/result/types.d.ts +122 -0
  131. package/dist/lib/result/types.js +19 -0
  132. package/dist/lib/run-output.d.ts +275 -0
  133. package/dist/lib/run-output.js +227 -0
  134. package/dist/lib/run-render.d.ts +101 -0
  135. package/dist/lib/run-render.js +183 -0
  136. package/dist/lib/run-wait.d.ts +192 -0
  137. package/dist/lib/run-wait.js +452 -0
  138. package/dist/lib/runs.types.d.ts +118 -367
  139. package/dist/lib/runs.types.js +0 -14
  140. package/dist/lib/secret-file.d.ts +1 -1
  141. package/dist/lib/secret-file.js +11 -2
  142. package/dist/lib/skill-nudge.d.ts +7 -27
  143. package/dist/lib/skill-nudge.js +9 -37
  144. package/dist/lib/target-path.d.ts +15 -0
  145. package/dist/lib/target-path.js +35 -0
  146. package/dist/lib/target-url-advisory.d.ts +19 -0
  147. package/dist/lib/target-url-advisory.js +31 -0
  148. package/dist/lib/target-url-preflight.d.ts +9 -0
  149. package/dist/lib/target-url-preflight.js +214 -106
  150. package/dist/lib/target-url.d.ts +1 -1
  151. package/dist/lib/target-url.js +6 -16
  152. package/dist/lib/telemetry.d.ts +31 -11
  153. package/dist/lib/telemetry.js +37 -8
  154. package/dist/lib/terminal-text.d.ts +41 -0
  155. package/dist/lib/terminal-text.js +127 -0
  156. package/dist/lib/testlist.types.d.ts +16 -8
  157. package/dist/lib/testlist.types.js +1 -1
  158. package/dist/lib/text-equality.d.ts +2 -0
  159. package/dist/lib/text-equality.js +5 -0
  160. package/dist/lib/text-file.d.ts +16 -0
  161. package/dist/lib/text-file.js +41 -0
  162. package/dist/lib/text-table.d.ts +46 -0
  163. package/dist/lib/text-table.js +72 -4
  164. package/dist/lib/ticker.d.ts +9 -2
  165. package/dist/lib/ticker.js +16 -3
  166. package/dist/lib/transport-failure.d.ts +22 -0
  167. package/dist/lib/transport-failure.js +126 -0
  168. package/dist/lib/tunnel-session.d.ts +7 -1
  169. package/dist/lib/tunnel-session.js +22 -9
  170. package/dist/lib/update-check.js +3 -2
  171. package/dist/lib/url-template.d.ts +43 -0
  172. package/dist/lib/url-template.js +151 -0
  173. package/dist/lib/validate.d.ts +0 -64
  174. package/dist/lib/validate.js +2 -131
  175. package/dist/lib/version-notice.js +4 -3
  176. package/dist/lib/wait-exit.d.ts +37 -2
  177. package/dist/lib/wait-exit.js +88 -30
  178. package/dist/lib/workspace-status.js +10 -2
  179. package/dist/version.d.ts +1 -1
  180. package/dist/version.js +1 -1
  181. package/package.json +2 -3
  182. package/skills/testsprite-ci.skill.md +48 -18
  183. package/skills/testsprite-onboard.skill.md +66 -151
  184. package/skills/testsprite-verify.codex.md +50 -52
  185. package/skills/testsprite-verify.skill.md +184 -351
  186. package/dist/lib/browser.d.ts +0 -6
  187. package/dist/lib/browser.js +0 -54
  188. package/dist/lib/bundle.d.ts +0 -234
  189. package/dist/lib/bundle.js +0 -781
  190. package/dist/lib/deprecate.d.ts +0 -32
  191. package/dist/lib/deprecate.js +0 -39
  192. package/dist/lib/flaky.d.ts +0 -91
  193. package/dist/lib/flaky.js +0 -71
  194. package/dist/lib/plan-poll.d.ts +0 -171
  195. package/dist/lib/plan-poll.js +0 -441
  196. package/dist/lib/plans.types.d.ts +0 -130
  197. package/dist/lib/plans.types.js +0 -31
  198. package/dist/lib/poll.d.ts +0 -100
  199. package/dist/lib/poll.js +0 -290
  200. package/dist/lib/rate-throttle.d.ts +0 -49
  201. package/dist/lib/rate-throttle.js +0 -75
  202. package/dist/lib/run-progress.d.ts +0 -41
  203. package/dist/lib/run-progress.js +0 -56
  204. package/dist/lib/v3-advisory.d.ts +0 -55
  205. package/dist/lib/v3-advisory.js +0 -74
  206. package/schemas/plan.schema.json +0 -61
@@ -1,4 +1,3 @@
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
@@ -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,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,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 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