@testsprite/testsprite-cli 0.12.0 → 0.14.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 (113) hide show
  1. package/README.md +59 -49
  2. package/dist/commands/agent.js +16 -13
  3. package/dist/commands/auth.d.ts +19 -0
  4. package/dist/commands/auth.js +60 -24
  5. package/dist/commands/ci.d.ts +86 -1
  6. package/dist/commands/ci.js +436 -5
  7. package/dist/commands/doctor.d.ts +2 -0
  8. package/dist/commands/doctor.js +34 -20
  9. package/dist/commands/init.js +14 -11
  10. package/dist/commands/project-env.d.ts +11 -1
  11. package/dist/commands/project-env.js +408 -70
  12. package/dist/commands/project-sign-in.d.ts +60 -0
  13. package/dist/commands/project-sign-in.js +289 -0
  14. package/dist/commands/project.d.ts +14 -5
  15. package/dist/commands/project.js +110 -70
  16. package/dist/commands/schedule.d.ts +14 -0
  17. package/dist/commands/schedule.js +193 -15
  18. package/dist/commands/test.d.ts +123 -44
  19. package/dist/commands/test.js +2993 -636
  20. package/dist/commands/testlist.d.ts +10 -5
  21. package/dist/commands/testlist.js +217 -47
  22. package/dist/commands/tunnel.d.ts +26 -3
  23. package/dist/commands/tunnel.js +221 -18
  24. package/dist/commands/usage.d.ts +3 -0
  25. package/dist/commands/usage.js +12 -5
  26. package/dist/index.js +39 -50
  27. package/dist/lib/agent-targets.d.ts +3 -3
  28. package/dist/lib/agent-targets.js +2 -2
  29. package/dist/lib/billing-refusal.d.ts +43 -0
  30. package/dist/lib/billing-refusal.js +171 -0
  31. package/dist/lib/bundle.d.ts +5 -0
  32. package/dist/lib/bundle.js +43 -13
  33. package/dist/lib/ci-linkage.d.ts +90 -0
  34. package/dist/lib/ci-linkage.js +181 -0
  35. package/dist/lib/client-factory.d.ts +16 -2
  36. package/dist/lib/client-factory.js +37 -6
  37. package/dist/lib/config.d.ts +17 -0
  38. package/dist/lib/config.js +20 -1
  39. package/dist/lib/conflict-reason.d.ts +27 -3
  40. package/dist/lib/conflict-reason.js +53 -4
  41. package/dist/lib/credentials.js +56 -14
  42. package/dist/lib/dry-run/samples.d.ts +13 -1
  43. package/dist/lib/dry-run/samples.js +104 -7
  44. package/dist/lib/environment-tunnel.d.ts +109 -0
  45. package/dist/lib/environment-tunnel.js +465 -0
  46. package/dist/lib/errors.d.ts +18 -11
  47. package/dist/lib/errors.js +123 -14
  48. package/dist/lib/failing-fe-resolver.d.ts +1 -1
  49. package/dist/lib/failing-fe-resolver.js +3 -3
  50. package/dist/lib/gh-output.d.ts +1 -0
  51. package/dist/lib/gh-output.js +16 -4
  52. package/dist/lib/history-retention.d.ts +8 -0
  53. package/dist/lib/history-retention.js +24 -0
  54. package/dist/lib/http.d.ts +39 -19
  55. package/dist/lib/http.js +46 -24
  56. package/dist/lib/interrupt.d.ts +21 -13
  57. package/dist/lib/interrupt.js +32 -21
  58. package/dist/lib/junit-report.d.ts +18 -4
  59. package/dist/lib/junit-report.js +23 -5
  60. package/dist/lib/local-target.d.ts +14 -4
  61. package/dist/lib/local-target.js +48 -13
  62. package/dist/lib/output.js +15 -1
  63. package/dist/lib/plan-poll.d.ts +11 -11
  64. package/dist/lib/plan-poll.js +15 -16
  65. package/dist/lib/plans.types.d.ts +9 -9
  66. package/dist/lib/plans.types.js +3 -3
  67. package/dist/lib/poll.d.ts +2 -2
  68. package/dist/lib/poll.js +9 -3
  69. package/dist/lib/redact.d.ts +38 -0
  70. package/dist/lib/redact.js +140 -0
  71. package/dist/lib/render-error.d.ts +21 -5
  72. package/dist/lib/render-error.js +44 -0
  73. package/dist/lib/response-schemas.d.ts +54 -12
  74. package/dist/lib/response-schemas.js +88 -7
  75. package/dist/lib/runs.types.d.ts +68 -11
  76. package/dist/lib/secret-file.js +72 -14
  77. package/dist/lib/skill-nudge.d.ts +6 -1
  78. package/dist/lib/skill-nudge.js +32 -5
  79. package/dist/lib/target-url-preflight.d.ts +6 -4
  80. package/dist/lib/target-url-preflight.js +64 -51
  81. package/dist/lib/target-url.js +11 -11
  82. package/dist/lib/telemetry.d.ts +10 -8
  83. package/dist/lib/telemetry.js +24 -17
  84. package/dist/lib/testlist.types.d.ts +1 -0
  85. package/dist/lib/ticker.d.ts +9 -0
  86. package/dist/lib/ticker.js +111 -4
  87. package/dist/lib/tunnel-session.d.ts +16 -4
  88. package/dist/lib/tunnel-session.js +7 -5
  89. package/dist/lib/tunnel.types.d.ts +12 -2
  90. package/dist/lib/tunnel.types.js +2 -2
  91. package/dist/lib/v3-advisory.js +0 -1
  92. package/dist/lib/wait-exit.d.ts +8 -0
  93. package/dist/lib/wait-exit.js +76 -4
  94. package/dist/lib/workspace-status.d.ts +23 -0
  95. package/dist/lib/workspace-status.js +15 -0
  96. package/dist/vendor/tunnel-client/client.d.ts +15 -8
  97. package/dist/vendor/tunnel-client/client.js +477 -407
  98. package/dist/vendor/tunnel-client/config.d.ts +5 -5
  99. package/dist/vendor/tunnel-client/config.js +5 -5
  100. package/dist/vendor/tunnel-client/index.d.ts +4 -4
  101. package/dist/vendor/tunnel-client/index.js +4 -4
  102. package/dist/vendor/tunnel-client/types.d.ts +19 -34
  103. package/dist/vendor/tunnel-client/types.js +1 -0
  104. package/dist/vendor/tunnel-client/ws-compat.d.ts +13 -3
  105. package/dist/vendor/tunnel-client/ws-compat.js +70 -12
  106. package/dist/version-guard.d.ts +7 -1
  107. package/dist/version-guard.js +19 -1
  108. package/dist/version.d.ts +1 -1
  109. package/dist/version.js +1 -1
  110. package/package.json +4 -4
  111. package/skills/testsprite-onboard.skill.md +8 -8
  112. package/skills/testsprite-verify.codex.md +59 -57
  113. package/skills/testsprite-verify.skill.md +53 -38
@@ -16,10 +16,12 @@
16
16
  */
17
17
  import { Command } from 'commander';
18
18
  import { assertValidEndpointUrl, makeHttpClient, } from '../lib/client-factory.js';
19
- import { loadConfig } from '../lib/config.js';
20
- import { ApiError, CLIError, RequestTimeoutError, localValidationError } from '../lib/errors.js';
19
+ import { loadConfig, resolveProfileName } from '../lib/config.js';
20
+ import { ApiError, CLIError, InterruptError, RequestTimeoutError, localValidationError, } from '../lib/errors.js';
21
+ import { globalShutdown } from '../lib/interrupt.js';
21
22
  import { formatOrgBinding, formatOrgsSummary, formatPersonalScopeHint } from '../lib/org-render.js';
22
23
  import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
24
+ import { ME_IDENTITY_SCHEMA } from '../lib/response-schemas.js';
23
25
  import { isVerifySkillInstalled } from '../lib/skill-nudge.js';
24
26
  import { emitV3RoutingAdvisory, routingLabel } from '../lib/v3-advisory.js';
25
27
  import { VERSION } from '../version.js';
@@ -165,8 +167,9 @@ async function checkConnectivity(opts, deps, ctx) {
165
167
  credentialsPath: deps.credentialsPath,
166
168
  fetchImpl: deps.fetchImpl,
167
169
  stderr: deps.stderr,
170
+ shutdownSignal: deps.shutdownSignal,
168
171
  });
169
- const me = await client.get('/me');
172
+ const me = await client.get('/me', { schema: ME_IDENTITY_SCHEMA });
170
173
  const who = me.userId ? ` (userId ${me.userId})` : '';
171
174
  return {
172
175
  check: { name, status: 'ok', detail: `reached GET /me, API key accepted${who}` },
@@ -176,6 +179,8 @@ async function checkConnectivity(opts, deps, ctx) {
176
179
  };
177
180
  }
178
181
  catch (error) {
182
+ if (error instanceof InterruptError)
183
+ throw error;
179
184
  if (error instanceof ApiError) {
180
185
  if (error.code === 'AUTH_REQUIRED' ||
181
186
  error.code === 'AUTH_INVALID' ||
@@ -194,7 +199,7 @@ async function checkConnectivity(opts, deps, ctx) {
194
199
  }
195
200
  }
196
201
  /**
197
- * Can this key open a tunnel to this machine (`test run --local`)?
202
+ * Can this key open a tunnel for an environment on this machine?
198
203
  *
199
204
  * A READ, not a mint. `GET /tunnel/<random-uuid>` runs the same scope guard
200
205
  * and the same environment-configured check as the mint, and answers 404 for
@@ -202,13 +207,10 @@ async function checkConnectivity(opts, deps, ctx) {
202
207
  * one of the caller's few concurrent live bindings or any rate-limit budget on
203
208
  * a diagnostic.
204
209
  *
205
- * The case this exists for: `run:tunnel` is the first scope deliberately kept
206
- * OUT of the grandfather grant, so a key minted before it — most keys in the
207
- * wild — gets a 403 the first time someone tries `--local`, and the remedy is
208
- * to mint a NEW key rather than to re-authenticate. Nothing else in the CLI
209
- * says that until a run has already been refused.
210
+ * Keys deliberately narrowed without `run:tunnel` receive a 403. Older
211
+ * servers may also exclude the scope from their legacy-key grant.
210
212
  *
211
- * Never `fail`: a caller who does not use `--local` should not see `doctor`
213
+ * Never `fail`: a caller who does not use a tunnel should not see `doctor`
212
214
  * exit 1 over a surface that is not even configured in their environment.
213
215
  */
214
216
  async function checkLocalTunnel(opts, deps, ctx) {
@@ -220,6 +222,12 @@ async function checkLocalTunnel(opts, deps, ctx) {
220
222
  if (!ctx.endpointOk)
221
223
  return { name, status: 'warn', detail: 'skipped; endpoint URL is invalid' };
222
224
  const controller = new AbortController();
225
+ const shutdownSignal = deps.shutdownSignal ?? globalShutdown.signal;
226
+ const onShutdown = () => controller.abort(shutdownSignal.reason);
227
+ if (shutdownSignal.aborted)
228
+ onShutdown();
229
+ else
230
+ shutdownSignal.addEventListener('abort', onShutdown, { once: true });
223
231
  const probeTimer = setTimeout(() => {
224
232
  controller.abort(new RequestTimeoutError(DOCTOR_TUNNEL_PROBE_TIMEOUT_MS));
225
233
  }, DOCTOR_TUNNEL_PROBE_TIMEOUT_MS);
@@ -230,9 +238,8 @@ async function checkLocalTunnel(opts, deps, ctx) {
230
238
  credentialsPath: deps.credentialsPath,
231
239
  fetchImpl: deps.fetchImpl,
232
240
  stderr: deps.stderr,
233
- // The retry sleeper listens to the client shutdown signal, so using
234
- // the probe deadline here bounds attempts and Retry-After sleeps as
235
- // one operation rather than timing each fetch independently.
241
+ // The retry sleeper listens to the client shutdown signal. Compose
242
+ // the probe deadline with process shutdown so either aborts the fetch.
236
243
  shutdownSignal: controller.signal,
237
244
  });
238
245
  // A well-formed id that cannot name anyone's binding. A 200 here would
@@ -246,6 +253,8 @@ async function checkLocalTunnel(opts, deps, ctx) {
246
253
  };
247
254
  }
248
255
  catch (error) {
256
+ if (error instanceof InterruptError)
257
+ throw error;
249
258
  if (!(error instanceof ApiError)) {
250
259
  return {
251
260
  name,
@@ -254,27 +263,32 @@ async function checkLocalTunnel(opts, deps, ctx) {
254
263
  };
255
264
  }
256
265
  if (error.code === 'NOT_FOUND') {
257
- return { name, status: 'ok', detail: 'available; this key can open a tunnel (--local)' };
266
+ return {
267
+ name,
268
+ status: 'ok',
269
+ detail: 'available; this key can open a tunnel for an environment on this machine',
270
+ };
258
271
  }
259
272
  if (error.code === 'AUTH_FORBIDDEN') {
260
273
  return {
261
274
  name,
262
275
  status: 'warn',
263
- detail: 'this API key cannot open a tunnel — it predates the `run:tunnel` scope. ' +
264
- 'Mint a new API key in the dashboard to use `test run --local`.',
276
+ detail: 'this API key does not have the `run:tunnel` scope. ' +
277
+ 'Mint a new API key with that scope in the dashboard to run an environment on this machine.',
265
278
  };
266
279
  }
267
280
  if (error.code === 'UNAVAILABLE') {
268
281
  return {
269
282
  name,
270
283
  status: 'warn',
271
- detail: '`test run --local` is not available on this endpoint',
284
+ detail: 'tunnels for environments on this machine are not available on this endpoint',
272
285
  };
273
286
  }
274
287
  return { name, status: 'warn', detail: `could not check (${error.code})` };
275
288
  }
276
289
  finally {
277
290
  clearTimeout(probeTimer);
291
+ shutdownSignal.removeEventListener('abort', onShutdown);
278
292
  }
279
293
  }
280
294
  /**
@@ -314,14 +328,14 @@ export function createDoctorCommand(deps = {}) {
314
328
  ' testsprite doctor --output json # machine-readable report\n' +
315
329
  ' testsprite doctor && testsprite test run <id> # gate a command on a healthy setup')
316
330
  .action(async (_cmdOpts, command) => {
317
- await runDoctor(resolveCommonOptions(command), deps);
331
+ await runDoctor(resolveCommonOptions(command, deps.env), deps);
318
332
  });
319
333
  return cmd;
320
334
  }
321
- function resolveCommonOptions(command) {
335
+ function resolveCommonOptions(command, env) {
322
336
  const globals = command.optsWithGlobals();
323
337
  return {
324
- profile: globals.profile ?? 'default',
338
+ profile: resolveProfileName(globals.profile, env),
325
339
  output: resolveOutputMode(globals.output),
326
340
  endpointUrl: globals.endpointUrl,
327
341
  debug: globals.debug ?? false,
@@ -13,11 +13,11 @@
13
13
  */
14
14
  import { Command } from 'commander';
15
15
  import { parseRequestTimeoutFlag, } from '../lib/client-factory.js';
16
- import { normalizeEnvVar } from '../lib/config.js';
16
+ import { normalizeEnvVar, resolveProfileName } from '../lib/config.js';
17
17
  import { emitDeprecationNotice } from '../lib/deprecate.js';
18
- import { CLIError, localValidationError } from '../lib/errors.js';
18
+ import { CLIError, InterruptError, localValidationError } from '../lib/errors.js';
19
19
  import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
20
- import { runConfigure, runWhoami } from './auth.js';
20
+ import { missingApiKeyError, runConfigure, runWhoami } from './auth.js';
21
21
  import { runInstall } from './agent.js';
22
22
  import { TARGETS, DEFAULT_SKILLS } from '../lib/agent-targets.js';
23
23
  import { FALLBACK_TARGET, resolveAgentTargets, } from '../lib/agent-detect.js';
@@ -98,6 +98,7 @@ function toAuthDeps(deps, apiKey, commandTag) {
98
98
  // If an explicit API key was provided, override the prompt so configure
99
99
  // never actually prompts the user.
100
100
  prompt: apiKey ? { secret: async (_q) => apiKey } : deps.prompt,
101
+ suppliedApiKey: Boolean(apiKey),
101
102
  // Telemetry attribution for the configure-validate GET /me. Passed only for
102
103
  // the configure step (see runInit) — never whoami — so each init run emits
103
104
  // exactly one cli.initialized event on the backend.
@@ -253,8 +254,8 @@ export async function runInit(opts, deps = {}) {
253
254
  // Non-interactive guard: no TTY + no key source → exit 5. Skipped under
254
255
  // --dry-run, which is documented to work without credentials or network.
255
256
  if (!isTTY && !hasKeySource && !skipWillApply && !opts.dryRun) {
256
- throw new CLIError('No API key available in non-interactive mode. ' +
257
- 'Pass --api-key <key>, --from-env (reads TESTSPRITE_API_KEY), or run interactively.', 5);
257
+ throw missingApiKeyError('No API key available in non-interactive mode. ' +
258
+ 'Pass --api-key <key>, --from-env (reads TESTSPRITE_API_KEY), or run interactively.', resolveReportedEndpoint(opts, deps));
258
259
  }
259
260
  // JSON-output guard: an interactive secret prompt writes to stdout and would
260
261
  // corrupt init's single-JSON-object output contract. In --output json mode
@@ -363,6 +364,8 @@ export async function runInit(opts, deps = {}) {
363
364
  me = await runWhoami(opts, whoamiDeps);
364
365
  }
365
366
  catch (err) {
367
+ if (err instanceof InterruptError)
368
+ throw err;
366
369
  // Whoami is display-only. If it fails after a successful configure,
367
370
  // continue with a minimal placeholder so the summary still prints.
368
371
  if (opts.debug) {
@@ -484,7 +487,7 @@ function renderInitText(data) {
484
487
  : ' agent: skipped (--no-agent)');
485
488
  }
486
489
  lines.push('');
487
- // DEV-279: an agent session already open when the skills landed won't re-read
490
+ // An agent session already open when the skills landed won't re-read
488
491
  // them. `agent install` emits the same line on stderr; setup owns its summary,
489
492
  // so it goes here. Only when bytes actually changed — `aggregateInstallAction`
490
493
  // reports 'installed'/'updated' for that, 'dry-run'/'skipped' otherwise.
@@ -519,10 +522,10 @@ function renderInitText(data) {
519
522
  // ---------------------------------------------------------------------------
520
523
  // Command factory
521
524
  // ---------------------------------------------------------------------------
522
- function resolveCommonOptions(command) {
525
+ function resolveCommonOptions(command, env) {
523
526
  const globals = command.optsWithGlobals();
524
527
  return {
525
- profile: globals.profile ?? 'default',
528
+ profile: resolveProfileName(globals.profile, env),
526
529
  output: resolveOutputMode(globals.output),
527
530
  endpointUrl: globals.endpointUrl,
528
531
  debug: globals.debug ?? false,
@@ -551,8 +554,8 @@ export function addSetupOptions(cmd, validTargets, defaultAgent) {
551
554
  .option('--skip-if-configured', 'Skip the API key prompt when credentials already exist for this profile (CI-safe idempotent re-run)');
552
555
  }
553
556
  /** Build {@link InitOptions} from raw Commander opts + globals. */
554
- function buildSetupOptions(cmdOpts, command) {
555
- const common = resolveCommonOptions(command);
557
+ function buildSetupOptions(cmdOpts, command, env) {
558
+ const common = resolveCommonOptions(command, env);
556
559
  // Commander sets `agent: false` (boolean) when `--no-agent` is passed,
557
560
  // because `--no-agent` is the negation of `--agent <target>`.
558
561
  const isNoAgent = cmdOpts.noAgent === true || cmdOpts.agent === false;
@@ -586,7 +589,7 @@ function buildSetupOptions(cmdOpts, command) {
586
589
  }
587
590
  /** Shared action for `setup` and the deprecated `init` alias. */
588
591
  async function runSetupAction(cmdOpts, command, deps) {
589
- const opts = buildSetupOptions(cmdOpts, command);
592
+ const opts = buildSetupOptions(cmdOpts, command, deps.env);
590
593
  // When --yes is supplied without a key source, force isTTY=false so runInit
591
594
  // emits exit 5 with a clear message rather than hanging on a prompt in a
592
595
  // headless CI environment where a TTY fd happens to be open.
@@ -7,7 +7,7 @@ export interface CliProjectEnvironment {
7
7
  name: string;
8
8
  /**
9
9
  * The address runs against this environment open. May be a loopback URL for
10
- * an app that only runs on your own machine — pair it with `--local`.
10
+ * an app that only runs on your own machine — frontend runs open a tunnel.
11
11
  */
12
12
  url: string;
13
13
  isDefault: boolean;
@@ -24,6 +24,7 @@ export interface CliProjectEnvironment {
24
24
  username: string | null;
25
25
  enableOtp: boolean;
26
26
  updatedAt: string;
27
+ variables?: Record<string, string>;
27
28
  }
28
29
  export interface CliProjectEnvListResponse {
29
30
  environments: CliProjectEnvironment[];
@@ -43,6 +44,9 @@ interface EnvListOptions extends CommonOptions {
43
44
  projectId: string;
44
45
  }
45
46
  export declare function runEnvList(opts: EnvListOptions, deps?: ProjectDeps): Promise<CliProjectEnvListResponse>;
47
+ export declare function runEnvGet(opts: EnvListOptions & {
48
+ name: string;
49
+ }, deps?: ProjectDeps): Promise<CliProjectEnvUpdateResponse>;
46
50
  interface EnvCreateOptions extends CommonOptions {
47
51
  projectId: string;
48
52
  name?: string;
@@ -54,8 +58,12 @@ interface EnvCreateOptions extends CommonOptions {
54
58
  username?: string;
55
59
  password?: string;
56
60
  passwordFile?: string;
61
+ vars?: string[];
57
62
  setDefault?: boolean;
58
63
  idempotencyKey?: string;
64
+ signIn?: string;
65
+ otpChannel?: string[];
66
+ sessionTtl?: string;
59
67
  }
60
68
  export declare function runEnvCreate(opts: EnvCreateOptions, deps?: ProjectDeps): Promise<CliProjectEnvCreateResponse>;
61
69
  interface EnvUpdateOptions extends CommonOptions {
@@ -69,6 +77,8 @@ interface EnvUpdateOptions extends CommonOptions {
69
77
  username?: string;
70
78
  password?: string;
71
79
  passwordFile?: string;
80
+ clearCredentials?: boolean;
81
+ vars?: string[];
72
82
  rename?: string;
73
83
  idempotencyKey?: string;
74
84
  }