@testsprite/testsprite-cli 0.2.0 → 0.4.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 (68) hide show
  1. package/README.md +35 -26
  2. package/dist/commands/agent.d.ts +43 -0
  3. package/dist/commands/agent.js +200 -18
  4. package/dist/commands/auth.d.ts +5 -0
  5. package/dist/commands/auth.js +38 -27
  6. package/dist/commands/doctor.d.ts +49 -0
  7. package/dist/commands/doctor.js +233 -0
  8. package/dist/commands/init.d.ts +1 -1
  9. package/dist/commands/init.js +24 -14
  10. package/dist/commands/project.d.ts +75 -2
  11. package/dist/commands/project.js +326 -47
  12. package/dist/commands/test.d.ts +281 -2
  13. package/dist/commands/test.js +1658 -177
  14. package/dist/commands/usage.js +13 -12
  15. package/dist/index.js +71 -3
  16. package/dist/lib/agent-targets.d.ts +72 -6
  17. package/dist/lib/agent-targets.js +188 -6
  18. package/dist/lib/bundle.d.ts +34 -0
  19. package/dist/lib/bundle.js +63 -11
  20. package/dist/lib/client-factory.d.ts +31 -0
  21. package/dist/lib/client-factory.js +63 -0
  22. package/dist/lib/config.d.ts +2 -0
  23. package/dist/lib/config.js +11 -2
  24. package/dist/lib/credentials.js +10 -1
  25. package/dist/lib/dry-run/samples.d.ts +5 -0
  26. package/dist/lib/dry-run/samples.js +64 -0
  27. package/dist/lib/errors.d.ts +28 -1
  28. package/dist/lib/errors.js +40 -0
  29. package/dist/lib/failing-fe-resolver.d.ts +15 -0
  30. package/dist/lib/failing-fe-resolver.js +49 -1
  31. package/dist/lib/flaky.d.ts +80 -0
  32. package/dist/lib/flaky.js +76 -0
  33. package/dist/lib/http.d.ts +73 -1
  34. package/dist/lib/http.js +327 -135
  35. package/dist/lib/interrupt.d.ts +116 -0
  36. package/dist/lib/interrupt.js +182 -0
  37. package/dist/lib/junit-report.d.ts +58 -0
  38. package/dist/lib/junit-report.js +210 -0
  39. package/dist/lib/output.d.ts +16 -1
  40. package/dist/lib/output.js +24 -2
  41. package/dist/lib/pagination.d.ts +4 -3
  42. package/dist/lib/pagination.js +34 -6
  43. package/dist/lib/poll.d.ts +11 -0
  44. package/dist/lib/poll.js +70 -5
  45. package/dist/lib/prompt.js +52 -8
  46. package/dist/lib/proxy.d.ts +29 -0
  47. package/dist/lib/proxy.js +30 -0
  48. package/dist/lib/render-error.js +3 -1
  49. package/dist/lib/runs.types.d.ts +9 -0
  50. package/dist/lib/skill-nudge.d.ts +2 -2
  51. package/dist/lib/skill-nudge.js +13 -4
  52. package/dist/lib/target-url.js +8 -1
  53. package/dist/lib/ticker.d.ts +11 -1
  54. package/dist/lib/ticker.js +33 -1
  55. package/dist/lib/update-check.d.ts +67 -0
  56. package/dist/lib/update-check.js +246 -0
  57. package/dist/lib/v3-advisory.d.ts +13 -0
  58. package/dist/lib/v3-advisory.js +24 -0
  59. package/dist/lib/version-notice.d.ts +37 -0
  60. package/dist/lib/version-notice.js +87 -0
  61. package/dist/version-guard.d.ts +33 -0
  62. package/dist/version-guard.js +39 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +3 -2
  66. package/skills/testsprite-onboard.skill.md +21 -0
  67. package/skills/testsprite-verify.codex.md +6 -0
  68. package/skills/testsprite-verify.skill.md +48 -4
@@ -1,20 +1,20 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { readFileSync } from 'node:fs';
3
3
  import { Command } from 'commander';
4
- import { emitDryRunBanner, makeHttpClient, } from '../lib/client-factory.js';
4
+ import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
5
5
  import { ApiError } from '../lib/errors.js';
6
- import { GLOBAL_OPTS_HINT, Output } from '../lib/output.js';
6
+ import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
7
7
  import { assertNotLocal } from '../lib/target-url.js';
8
8
  import { assertIdempotencyKey } from '../lib/validate.js';
9
9
  import { fetchSinglePage, paginate, validatePaginationFlags, } from '../lib/pagination.js';
10
10
  export async function runList(opts, deps = {}) {
11
11
  const out = makeOutput(opts.output, deps);
12
- const client = makeClient(opts, deps);
13
12
  const paginationFlags = validatePaginationFlags({
14
13
  pageSize: opts.pageSize,
15
14
  startingToken: opts.startingToken,
16
15
  maxItems: opts.maxItems,
17
16
  });
17
+ const client = makeClient(opts, deps);
18
18
  // When the user explicitly passed a page-size flag and did NOT ask
19
19
  // for --max-items, treat that as a "give me one page and the cursor"
20
20
  // request — same shape AWS CLI ships. Otherwise auto-page.
@@ -49,11 +49,22 @@ export async function runCreate(opts, deps = {}) {
49
49
  // (exit 10 UNAVAILABLE) — fail fast with a clear exit 5 instead.
50
50
  assertIdempotencyKey(opts.idempotencyKey);
51
51
  // P1-3: client-side length checks matching server limits.
52
- if (opts.name !== undefined && opts.name.length > 200) {
52
+ // Whitespace-only / empty rejection (parity with `test create`'s requireString;
53
+ // a truthy `--name " "` otherwise creates a blank-named project on the backend).
54
+ if (opts.name === undefined || opts.name.trim().length === 0) {
55
+ throw localValidationError('--name is required and must not be empty or whitespace-only');
56
+ }
57
+ if (opts.password !== undefined && opts.password.trim().length === 0) {
58
+ throw localValidationError('--password must not be empty or whitespace-only');
59
+ }
60
+ if (opts.name.length > 200) {
53
61
  throw localValidationError('--name must be at most 200 characters');
54
62
  }
55
- if (opts.description !== undefined && opts.description.length > 2000) {
56
- throw localValidationError('--description must be at most 2000 characters');
63
+ // `--description` is not supported on projects — no project entity stores a
64
+ // description, and the backend rejects it with a 422. Fail fast client-side
65
+ // with an actionable message instead of a wasted round trip.
66
+ if (opts.description !== undefined) {
67
+ throw localValidationError('--description is not supported for projects; omit it (test-level descriptions are set on `test create`)');
57
68
  }
58
69
  // P2-7: guard --url against localhost/RFC1918/non-http(s) (same rules as
59
70
  // `test create --target-url`). Applies to both FE (required) and BE (optional).
@@ -100,7 +111,6 @@ export async function runCreate(opts, deps = {}) {
100
111
  type: opts.type,
101
112
  name: opts.name,
102
113
  ...(opts.targetUrl !== undefined ? { targetUrl: opts.targetUrl } : {}),
103
- ...(opts.description !== undefined ? { description: opts.description } : {}),
104
114
  ...(opts.username !== undefined ? { username: opts.username } : {}),
105
115
  ...(password !== undefined ? { password } : {}),
106
116
  ...(opts.instruction !== undefined ? { instruction: opts.instruction } : {}),
@@ -119,32 +129,34 @@ export async function runUpdate(opts, deps = {}) {
119
129
  // P1-2: validate idempotency key before sending as an HTTP header.
120
130
  assertIdempotencyKey(opts.idempotencyKey);
121
131
  // P1-3: client-side length checks matching server limits.
122
- if (opts.name !== undefined && opts.name.length > 200) {
123
- throw localValidationError('--name must be at most 200 characters');
132
+ // Reject a whitespace-only `--name` on update too (parity with create); name
133
+ // stays optional here, so only validate when the flag is supplied.
134
+ if (opts.name !== undefined && opts.name.trim().length === 0) {
135
+ throw localValidationError('--name must not be empty or whitespace-only');
124
136
  }
125
- if (opts.description !== undefined && opts.description.length > 2000) {
126
- throw localValidationError('--description must be at most 2000 characters');
137
+ if (opts.password !== undefined && opts.password.trim().length === 0) {
138
+ throw localValidationError('--password must not be empty or whitespace-only');
127
139
  }
128
- // Resolve password
129
- let password = opts.password;
130
- if (password === undefined && opts.passwordFile !== undefined) {
131
- password = readFileSync(opts.passwordFile, 'utf8').trim();
140
+ if (opts.name !== undefined && opts.name.length > 200) {
141
+ throw localValidationError('--name must be at most 200 characters');
132
142
  }
133
143
  // P2-7: guard --url against localhost/RFC1918/non-http(s).
134
144
  if (opts.targetUrl !== undefined) {
135
145
  assertNotLocal(opts.targetUrl);
136
146
  }
147
+ const passwordSupplied = opts.password !== undefined || opts.passwordFile !== undefined;
137
148
  const mutableFields = {
138
- name: opts.name,
139
- targetUrl: opts.targetUrl,
140
- username: opts.username,
141
- password,
142
- description: opts.description,
143
- instruction: opts.instruction,
149
+ name: opts.name !== undefined,
150
+ targetUrl: opts.targetUrl !== undefined,
151
+ username: opts.username !== undefined,
152
+ password: passwordSupplied,
153
+ instruction: opts.instruction !== undefined,
144
154
  };
145
- const presentFields = Object.entries(mutableFields).filter(([, v]) => v !== undefined);
146
- if (presentFields.length === 0) {
147
- throw localValidationError('At least one mutable flag is required: --name, --url, --username, --password/--password-file, --description, or --instruction.');
155
+ const presentFieldNames = Object.entries(mutableFields)
156
+ .filter(([, present]) => present)
157
+ .map(([field]) => field);
158
+ if (presentFieldNames.length === 0) {
159
+ throw localValidationError('At least one mutable flag is required: --name, --url, --username, --password/--password-file, or --instruction.');
148
160
  }
149
161
  if (opts.dryRun) {
150
162
  // DEV-247: emit the banner here (this path returns before makeClient() does).
@@ -156,17 +168,30 @@ export async function runUpdate(opts, deps = {}) {
156
168
  }
157
169
  const sample = {
158
170
  id: opts.projectId,
159
- updatedFields: presentFields.map(([k]) => k),
171
+ updatedFields: presentFieldNames,
160
172
  updatedAt: '2026-05-16T00:00:00.000Z',
161
173
  };
162
174
  out.print(sample, data => renderUpdateText(data));
163
175
  return sample;
164
176
  }
177
+ // Resolve password only on the real path. Dry-run must not touch the
178
+ // filesystem, even when --password-file is present.
179
+ let password = opts.password;
180
+ if (password === undefined && opts.passwordFile !== undefined) {
181
+ password = readFileSync(opts.passwordFile, 'utf8').trim();
182
+ }
165
183
  const idempotencyKey = opts.idempotencyKey ?? `cli-proj-update-${randomUUID()}`;
166
184
  if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
167
185
  stderr(`idempotency-key: ${idempotencyKey}`);
168
186
  }
169
- const body = Object.fromEntries(presentFields);
187
+ const bodyFields = {
188
+ name: opts.name,
189
+ targetUrl: opts.targetUrl,
190
+ username: opts.username,
191
+ password,
192
+ instruction: opts.instruction,
193
+ };
194
+ const body = Object.fromEntries(Object.entries(bodyFields).filter(([, v]) => v !== undefined));
170
195
  const client = makeClient(opts, deps);
171
196
  const updated = await client.patch(`/projects/${encodeURIComponent(opts.projectId)}`, {
172
197
  body,
@@ -175,6 +200,181 @@ export async function runUpdate(opts, deps = {}) {
175
200
  out.print(updated, data => renderUpdateText(data));
176
201
  return updated;
177
202
  }
203
+ /**
204
+ * `project delete <project-id> --confirm` — permanent cascade delete via
205
+ * DELETE /projects/{id}.
206
+ *
207
+ * The server deletes the project together with everything under it — its
208
+ * frontend/backend sub-projects, all their tests, and backend fixtures —
209
+ * matching the Portal's own delete behavior. There is no restore window.
210
+ *
211
+ * **`--confirm` is required** (unless `--dry-run`). Without either, the CLI
212
+ * exits 5 `VALIDATION_ERROR` with a typed envelope explaining the convention.
213
+ * The CLI never prompts interactively (CI-friendly contract). Re-delete on an already-deleted (or missing) project returns 404 from
214
+ * the server; the CLI surfaces the envelope as-is (exit 4), no client branching.
215
+ */
216
+ export async function runDelete(opts, deps = {}) {
217
+ assertIdempotencyKey(opts.idempotencyKey);
218
+ if (opts.projectId === undefined || opts.projectId.trim().length === 0) {
219
+ throw localValidationError('<project-id> is required');
220
+ }
221
+ if (!opts.confirm && !opts.dryRun) {
222
+ throw ApiError.fromEnvelope({
223
+ error: {
224
+ code: 'VALIDATION_ERROR',
225
+ message: 'Refusing to delete without --confirm.',
226
+ nextAction: 'This permanently deletes the project and everything under it — its ' +
227
+ 'sub-projects, all their tests, and backend fixtures (no restore window). ' +
228
+ 'The CLI convention is explicit confirmation for destructive operations. ' +
229
+ 'Re-run with --confirm. (--dry-run also works without --confirm.)',
230
+ requestId: 'local',
231
+ details: { field: 'confirm', reason: 'required for destructive operation' },
232
+ },
233
+ });
234
+ }
235
+ const idempotencyKey = opts.idempotencyKey ?? `cli-delete-${randomUUID()}`;
236
+ if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
237
+ const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
238
+ stderr(`idempotency-key: ${idempotencyKey}`);
239
+ }
240
+ const client = makeClient(opts, deps);
241
+ const out = makeOutput(opts.output, deps);
242
+ const response = await client.delete(`/projects/${encodeURIComponent(opts.projectId)}`, {
243
+ headers: { 'idempotency-key': idempotencyKey },
244
+ });
245
+ out.print(response, data => renderDeleteText(data));
246
+ return response;
247
+ }
248
+ // ---------------------------------------------------------------------------
249
+ // project credential — set the static backend credential
250
+ // ---------------------------------------------------------------------------
251
+ const CLI_AUTH_TYPES = ['public', 'Bearer token', 'API key', 'basic token'];
252
+ export async function runCredential(opts, deps = {}) {
253
+ const out = makeOutput(opts.output, deps);
254
+ const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
255
+ assertIdempotencyKey(opts.idempotencyKey);
256
+ if (!CLI_AUTH_TYPES.includes(opts.authType)) {
257
+ throw localValidationError(`--type must be one of: ${CLI_AUTH_TYPES.join(', ')}`);
258
+ }
259
+ // Resolve the credential value (flag or file). Required for every type
260
+ // except `public` (which clears it).
261
+ let credential = opts.credential;
262
+ if (credential === undefined && opts.credentialFile !== undefined) {
263
+ credential = readFileSync(opts.credentialFile, 'utf8').trim();
264
+ }
265
+ if (opts.authType !== 'public' && (credential === undefined || credential === '')) {
266
+ throw localValidationError('--credential (or --credential-file) is required unless --type is "public"');
267
+ }
268
+ const body = { authType: opts.authType };
269
+ if (opts.authType !== 'public' && credential !== undefined)
270
+ body.credential = credential;
271
+ const idempotencyKey = opts.idempotencyKey ?? `cli-proj-cred-${randomUUID()}`;
272
+ if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
273
+ stderr(`idempotency-key: ${idempotencyKey}`);
274
+ }
275
+ if (opts.dryRun) {
276
+ const sample = {
277
+ projectId: opts.projectId,
278
+ authType: opts.authType,
279
+ rewroteCount: 0,
280
+ };
281
+ out.print(sample, data => renderCredentialText(data));
282
+ return sample;
283
+ }
284
+ const client = makeClient(opts, deps);
285
+ const res = await client.put(`/projects/${encodeURIComponent(opts.projectId)}/credential`, { body, headers: { 'idempotency-key': idempotencyKey } });
286
+ out.print(res, data => renderCredentialText(data));
287
+ return res;
288
+ }
289
+ function renderCredentialText(r) {
290
+ return [
291
+ `projectId ${r.projectId}`,
292
+ `authType ${r.authType}`,
293
+ `rewroteCount ${r.rewroteCount}`,
294
+ ].join('\n');
295
+ }
296
+ // ---------------------------------------------------------------------------
297
+ // project auto-auth — configure the recurring-token (auto-refresh) login
298
+ // ---------------------------------------------------------------------------
299
+ const AUTO_AUTH_METHODS = ['password', 'refresh_token', 'aws_cognito_refresh'];
300
+ const AUTO_AUTH_INJECTS = ['bearer', 'header', 'cookie'];
301
+ export async function runAutoAuth(opts, deps = {}) {
302
+ const out = makeOutput(opts.output, deps);
303
+ const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
304
+ assertIdempotencyKey(opts.idempotencyKey);
305
+ if (!AUTO_AUTH_METHODS.includes(opts.method)) {
306
+ throw localValidationError(`--method must be one of: ${AUTO_AUTH_METHODS.join(', ')}`);
307
+ }
308
+ if (!AUTO_AUTH_INJECTS.includes(opts.inject)) {
309
+ throw localValidationError(`--inject must be one of: ${AUTO_AUTH_INJECTS.join(', ')}`);
310
+ }
311
+ // Resolve secrets from --*-file variants so they stay out of shell history.
312
+ const password = opts.password ??
313
+ (opts.passwordFile !== undefined ? readFileSync(opts.passwordFile, 'utf8').trim() : undefined);
314
+ const clientSecret = opts.clientSecret ??
315
+ (opts.clientSecretFile !== undefined
316
+ ? readFileSync(opts.clientSecretFile, 'utf8').trim()
317
+ : undefined);
318
+ const refreshToken = opts.refreshToken ??
319
+ (opts.refreshTokenFile !== undefined
320
+ ? readFileSync(opts.refreshTokenFile, 'utf8').trim()
321
+ : undefined);
322
+ const enabled = opts.disable !== true;
323
+ const body = { enabled, method: opts.method, inject: opts.inject };
324
+ const maybe = (k, v) => {
325
+ if (v !== undefined)
326
+ body[k] = v;
327
+ };
328
+ maybe('injectKey', opts.injectKey);
329
+ maybe('loginUrl', opts.loginUrl);
330
+ maybe('loginMethod', opts.loginMethod);
331
+ maybe('loginContentType', opts.loginContentType);
332
+ maybe('loginBodyTemplate', opts.loginBodyTemplate);
333
+ maybe('username', opts.username);
334
+ maybe('password', password);
335
+ maybe('tokenPath', opts.tokenPath);
336
+ maybe('tokenEndpoint', opts.tokenEndpoint);
337
+ maybe('clientId', opts.clientId);
338
+ maybe('clientSecret', clientSecret);
339
+ maybe('refreshToken', refreshToken);
340
+ maybe('scope', opts.scope);
341
+ maybe('region', opts.region);
342
+ const idempotencyKey = opts.idempotencyKey ?? `cli-proj-autoauth-${randomUUID()}`;
343
+ if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
344
+ stderr(`idempotency-key: ${idempotencyKey}`);
345
+ }
346
+ if (opts.dryRun) {
347
+ const sample = {
348
+ projectId: opts.projectId,
349
+ enabled,
350
+ method: opts.method,
351
+ inject: opts.inject,
352
+ };
353
+ out.print(sample, data => renderAutoAuthText(data));
354
+ return sample;
355
+ }
356
+ const client = makeClient(opts, deps);
357
+ const res = await client.put(`/projects/${encodeURIComponent(opts.projectId)}/auto-auth`, { body, headers: { 'idempotency-key': idempotencyKey } });
358
+ out.print(res, data => renderAutoAuthText(data));
359
+ return res;
360
+ }
361
+ function renderAutoAuthText(r) {
362
+ const lines = [
363
+ `projectId ${r.projectId}`,
364
+ `enabled ${r.enabled}`,
365
+ `method ${r.method}`,
366
+ `inject ${r.inject}`,
367
+ ];
368
+ if (r.lastRefreshError) {
369
+ lines.push(`lastRefreshError ${r.lastRefreshError}`);
370
+ }
371
+ // A disabled result after a write means the trial login failed — call it out
372
+ // so the user doesn't assume auto-auth is live.
373
+ if (!r.enabled) {
374
+ lines.push('note auto-auth was stored but is DISABLED — the trial login failed. Fix the credentials (e.g. a valid refresh token) and re-run.');
375
+ }
376
+ return lines.join('\n');
377
+ }
178
378
  export function createProjectCommand(deps = {}) {
179
379
  const project = new Command('project').description('Manage TestSprite projects');
180
380
  project
@@ -215,7 +415,7 @@ export function createProjectCommand(deps = {}) {
215
415
  .option('--type <frontend|backend>', 'project type (required)')
216
416
  .option('--name <name>', 'project name (required)')
217
417
  .option('--url <url>', 'target URL (required for frontend)')
218
- .option('--description <text>', 'optional human description')
418
+ .option('--description <text>', 'not supported — projects have no description (test-level descriptions are set on `test create`)')
219
419
  .option('--username <user>', 'optional auth username')
220
420
  .option('--password <pw>', 'optional auth password (use --password-file for non-interactive)')
221
421
  .option('--password-file <path>', 'read password from file instead of inline flag')
@@ -255,7 +455,6 @@ export function createProjectCommand(deps = {}) {
255
455
  .option('--username <user>', 'new auth username')
256
456
  .option('--password <pw>', 'new auth password')
257
457
  .option('--password-file <path>', 'read new password from file')
258
- .option('--description <text>', 'new description')
259
458
  .option('--instruction <text>', 'new FE plan-gen instruction hint')
260
459
  .option('--idempotency-key <token>', 'opaque idempotency token. Defaults to a UUIDv4 minted per invocation.')
261
460
  .addHelpText('after', GLOBAL_OPTS_HINT)
@@ -268,11 +467,105 @@ export function createProjectCommand(deps = {}) {
268
467
  username: cmdOpts.username,
269
468
  password: cmdOpts.password,
270
469
  passwordFile: cmdOpts.passwordFile,
271
- description: cmdOpts.description,
272
470
  instruction: cmdOpts.instruction,
273
471
  idempotencyKey: cmdOpts.idempotencyKey,
274
472
  }, deps);
275
473
  });
474
+ project
475
+ .command('delete <project-id>')
476
+ .description('Permanently delete a project and everything under it (sub-projects,\n' +
477
+ 'their tests, and backend fixtures). Requires --confirm.\n' +
478
+ '\nExit codes:\n' +
479
+ ' 0 success\n' +
480
+ ' 3 auth error\n' +
481
+ ' 4 project not found (or already deleted)\n' +
482
+ ' 5 validation error (e.g., missing --confirm)')
483
+ .option('--confirm', 'required: explicit confirmation for the destructive operation', false)
484
+ .option('--idempotency-key <token>', 'opaque idempotency token. Defaults to a UUIDv4 minted per invocation.')
485
+ .addHelpText('after', GLOBAL_OPTS_HINT)
486
+ .action(async (projectId, cmdOpts, command) => {
487
+ await runDelete({
488
+ ...resolveCommonOptions(command),
489
+ projectId,
490
+ confirm: cmdOpts.confirm === true,
491
+ idempotencyKey: cmdOpts.idempotencyKey,
492
+ }, deps);
493
+ });
494
+ project
495
+ .command('credential <project-id>')
496
+ .description('Set the static backend credential injected into every backend test\n' +
497
+ '(Bearer token / API key / Basic token / public). Free tier.')
498
+ .requiredOption('--type <type>', 'public | "Bearer token" | "API key" | "basic token"')
499
+ .option('--credential <value>', 'credential value (required unless --type public)')
500
+ .option('--credential-file <path>', 'read the credential value from a file')
501
+ .option('--idempotency-key <token>', 'opaque idempotency token. Defaults to a UUIDv4 minted per invocation.')
502
+ .addHelpText('after', GLOBAL_OPTS_HINT)
503
+ .action(async (projectId, cmdOpts, command) => {
504
+ await runCredential({
505
+ ...resolveCommonOptions(command),
506
+ projectId,
507
+ authType: cmdOpts.type,
508
+ credential: cmdOpts.credential,
509
+ credentialFile: cmdOpts.credentialFile,
510
+ idempotencyKey: cmdOpts.idempotencyKey,
511
+ }, deps);
512
+ });
513
+ project
514
+ .command('auto-auth <project-id>')
515
+ .description('Configure the recurring-token (auto-refresh login) for backend tests (Pro).\n' +
516
+ 'A fresh token is fetched on each run and injected into every backend test.')
517
+ .requiredOption('--method <method>', 'password | refresh_token | aws_cognito_refresh')
518
+ .requiredOption('--inject <where>', 'bearer | header | cookie')
519
+ .option('--disable', 'turn auto-auth off (keeps stored config)')
520
+ .option('--inject-key <name>', 'header/cookie name when --inject is header/cookie')
521
+ // password method
522
+ .option('--login-url <url>', 'login endpoint (method=password)')
523
+ .option('--login-method <verb>', 'POST | PUT (method=password)')
524
+ .option('--login-content-type <ct>', 'application/json | application/x-www-form-urlencoded')
525
+ .option('--login-body-template <tpl>', 'login body template with {{username}}/{{password}}')
526
+ .option('--username <user>', 'login username (method=password)')
527
+ .option('--password <pw>', 'login password (method=password)')
528
+ .option('--password-file <path>', 'read login password from a file')
529
+ .option('--token-path <jsonpath>', 'JSONPath to the token in the login response')
530
+ // refresh_token method
531
+ .option('--token-endpoint <url>', 'OAuth token endpoint (method=refresh_token)')
532
+ .option('--client-id <id>', 'OAuth client id')
533
+ .option('--client-secret <secret>', 'OAuth client secret')
534
+ .option('--client-secret-file <path>', 'read OAuth client secret from a file')
535
+ .option('--refresh-token <token>', 'OAuth/Cognito refresh token')
536
+ .option('--refresh-token-file <path>', 'read the refresh token from a file')
537
+ .option('--scope <scope>', 'OAuth scope')
538
+ // aws_cognito_refresh method
539
+ .option('--region <region>', "AWS region (method=aws_cognito_refresh, e.g. 'us-east-1')")
540
+ .option('--idempotency-key <token>', 'opaque idempotency token. Defaults to a UUIDv4 minted per invocation.')
541
+ .addHelpText('after', GLOBAL_OPTS_HINT)
542
+ .action(async (projectId, cmdOpts, command) => {
543
+ await runAutoAuth({
544
+ ...resolveCommonOptions(command),
545
+ projectId,
546
+ disable: cmdOpts.disable,
547
+ method: cmdOpts.method,
548
+ inject: cmdOpts.inject,
549
+ injectKey: cmdOpts.injectKey,
550
+ loginUrl: cmdOpts.loginUrl,
551
+ loginMethod: cmdOpts.loginMethod,
552
+ loginContentType: cmdOpts.loginContentType,
553
+ loginBodyTemplate: cmdOpts.loginBodyTemplate,
554
+ username: cmdOpts.username,
555
+ password: cmdOpts.password,
556
+ passwordFile: cmdOpts.passwordFile,
557
+ tokenPath: cmdOpts.tokenPath,
558
+ tokenEndpoint: cmdOpts.tokenEndpoint,
559
+ clientId: cmdOpts.clientId,
560
+ clientSecret: cmdOpts.clientSecret,
561
+ clientSecretFile: cmdOpts.clientSecretFile,
562
+ refreshToken: cmdOpts.refreshToken,
563
+ refreshTokenFile: cmdOpts.refreshTokenFile,
564
+ scope: cmdOpts.scope,
565
+ region: cmdOpts.region,
566
+ idempotencyKey: cmdOpts.idempotencyKey,
567
+ }, deps);
568
+ });
276
569
  return project;
277
570
  }
278
571
  function parseFlag(raw, flagName) {
@@ -295,13 +588,9 @@ function parseFlag(raw, flagName) {
295
588
  function resolveCommonOptions(command) {
296
589
  const globals = command.optsWithGlobals();
297
590
  // P2-8: validate --output before allowing silent fallback to 'text'.
298
- const rawOutput = globals.output;
299
- if (rawOutput !== undefined && rawOutput !== 'json' && rawOutput !== 'text') {
300
- throw localValidationError('--output must be one of: json, text');
301
- }
302
591
  return {
303
592
  profile: globals.profile ?? 'default',
304
- output: globals.output ?? 'text',
593
+ output: resolveOutputMode(globals.output),
305
594
  endpointUrl: globals.endpointUrl,
306
595
  debug: globals.debug ?? false,
307
596
  verbose: globals.verbose ?? false,
@@ -309,19 +598,6 @@ function resolveCommonOptions(command) {
309
598
  requestTimeoutMs: parseRequestTimeoutFlag(globals.requestTimeout),
310
599
  };
311
600
  }
312
- /**
313
- * Parse the `--request-timeout <seconds>` flag value into milliseconds.
314
- * Returns `undefined` when the flag was not supplied (factory falls back to
315
- * the env var / default). Silently clamps out-of-range values.
316
- */
317
- function parseRequestTimeoutFlag(raw) {
318
- if (raw === undefined)
319
- return undefined;
320
- const n = Number(raw);
321
- if (!Number.isFinite(n) || n <= 0)
322
- return undefined;
323
- return Math.round(n * 1000); // seconds → milliseconds
324
- }
325
601
  function makeClient(opts, deps) {
326
602
  return makeHttpClient(opts, {
327
603
  env: deps.env,
@@ -391,6 +667,9 @@ function renderUpdateText(r) {
391
667
  `updatedAt: ${r.updatedAt}`,
392
668
  ].join('\n');
393
669
  }
670
+ function renderDeleteText(r) {
671
+ return [`projectId ${r.projectId}`, `deletedAt ${r.deletedAt}`].join('\n');
672
+ }
394
673
  function localValidationError(message) {
395
674
  return ApiError.fromEnvelope({
396
675
  error: {