@testsprite/testsprite-cli 0.11.0 → 0.13.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 (99) hide show
  1. package/README.md +52 -44
  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 +470 -9
  7. package/dist/commands/doctor.d.ts +2 -0
  8. package/dist/commands/doctor.js +22 -9
  9. package/dist/commands/init.js +14 -11
  10. package/dist/commands/project-env.d.ts +90 -0
  11. package/dist/commands/project-env.js +486 -0
  12. package/dist/commands/project.d.ts +15 -5
  13. package/dist/commands/project.js +88 -92
  14. package/dist/commands/schedule.d.ts +2 -0
  15. package/dist/commands/schedule.js +18 -10
  16. package/dist/commands/test.d.ts +102 -30
  17. package/dist/commands/test.js +1949 -419
  18. package/dist/commands/testlist.js +77 -21
  19. package/dist/commands/tunnel.d.ts +26 -3
  20. package/dist/commands/tunnel.js +211 -14
  21. package/dist/commands/usage.d.ts +3 -0
  22. package/dist/commands/usage.js +12 -5
  23. package/dist/index.js +47 -23
  24. package/dist/lib/agent-targets.d.ts +3 -3
  25. package/dist/lib/agent-targets.js +2 -2
  26. package/dist/lib/billing-refusal.d.ts +43 -0
  27. package/dist/lib/billing-refusal.js +171 -0
  28. package/dist/lib/bundle.d.ts +5 -0
  29. package/dist/lib/bundle.js +43 -13
  30. package/dist/lib/ci-linkage.d.ts +90 -0
  31. package/dist/lib/ci-linkage.js +181 -0
  32. package/dist/lib/client-factory.d.ts +4 -1
  33. package/dist/lib/client-factory.js +25 -2
  34. package/dist/lib/client-tag.d.ts +13 -0
  35. package/dist/lib/client-tag.js +44 -0
  36. package/dist/lib/config.d.ts +17 -0
  37. package/dist/lib/config.js +20 -1
  38. package/dist/lib/conflict-reason.d.ts +67 -2
  39. package/dist/lib/conflict-reason.js +148 -13
  40. package/dist/lib/credentials.js +56 -14
  41. package/dist/lib/cron.js +8 -1
  42. package/dist/lib/dry-run/samples.d.ts +13 -1
  43. package/dist/lib/dry-run/samples.js +51 -7
  44. package/dist/lib/errors.d.ts +62 -12
  45. package/dist/lib/errors.js +180 -25
  46. package/dist/lib/failing-fe-resolver.d.ts +1 -1
  47. package/dist/lib/failing-fe-resolver.js +3 -3
  48. package/dist/lib/gh-output.d.ts +26 -11
  49. package/dist/lib/gh-output.js +47 -15
  50. package/dist/lib/history-retention.d.ts +8 -0
  51. package/dist/lib/history-retention.js +24 -0
  52. package/dist/lib/http.d.ts +44 -19
  53. package/dist/lib/http.js +53 -26
  54. package/dist/lib/interrupt.d.ts +21 -13
  55. package/dist/lib/interrupt.js +32 -21
  56. package/dist/lib/junit-report.d.ts +11 -1
  57. package/dist/lib/junit-report.js +15 -3
  58. package/dist/lib/local-target.d.ts +33 -1
  59. package/dist/lib/local-target.js +78 -1
  60. package/dist/lib/output.d.ts +27 -1
  61. package/dist/lib/output.js +22 -3
  62. package/dist/lib/plan-poll.d.ts +11 -11
  63. package/dist/lib/plan-poll.js +12 -12
  64. package/dist/lib/plans.types.d.ts +9 -9
  65. package/dist/lib/plans.types.js +3 -3
  66. package/dist/lib/poll.d.ts +2 -2
  67. package/dist/lib/poll.js +9 -3
  68. package/dist/lib/render-error.d.ts +2 -0
  69. package/dist/lib/render-error.js +13 -0
  70. package/dist/lib/response-schemas.d.ts +54 -12
  71. package/dist/lib/response-schemas.js +106 -7
  72. package/dist/lib/runs.types.d.ts +92 -6
  73. package/dist/lib/secret-file.js +72 -14
  74. package/dist/lib/skill-nudge.d.ts +6 -1
  75. package/dist/lib/skill-nudge.js +32 -5
  76. package/dist/lib/target-url-preflight.d.ts +6 -4
  77. package/dist/lib/target-url-preflight.js +64 -51
  78. package/dist/lib/target-url.js +31 -12
  79. package/dist/lib/telemetry.d.ts +172 -3
  80. package/dist/lib/telemetry.js +276 -15
  81. package/dist/lib/ticker.js +93 -4
  82. package/dist/lib/tunnel-session.d.ts +13 -0
  83. package/dist/lib/tunnel-session.js +4 -1
  84. package/dist/lib/tunnel.types.d.ts +12 -2
  85. package/dist/lib/tunnel.types.js +2 -2
  86. package/dist/lib/version-notice.d.ts +20 -1
  87. package/dist/lib/version-notice.js +59 -12
  88. package/dist/lib/wait-exit.d.ts +8 -0
  89. package/dist/lib/wait-exit.js +76 -4
  90. package/dist/lib/workspace-status.d.ts +23 -0
  91. package/dist/lib/workspace-status.js +15 -0
  92. package/dist/version-guard.d.ts +7 -1
  93. package/dist/version-guard.js +19 -1
  94. package/dist/version.d.ts +1 -1
  95. package/dist/version.js +1 -1
  96. package/package.json +4 -4
  97. package/skills/testsprite-onboard.skill.md +4 -4
  98. package/skills/testsprite-verify.codex.md +59 -57
  99. package/skills/testsprite-verify.skill.md +53 -36
@@ -4,15 +4,17 @@ import { basename, extname } from 'node:path';
4
4
  import { Readable } from 'node:stream';
5
5
  import { Command } from 'commander';
6
6
  import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, resolveRequestTimeoutMs, } from '../lib/client-factory.js';
7
- import { ApiError, InterruptError, RequestTimeoutError, localValidationError as flagValidationError, } from '../lib/errors.js';
7
+ import { resolveProfileName } from '../lib/config.js';
8
+ import { ApiError, InterruptError, RequestTimeoutError } from '../lib/errors.js';
8
9
  import { globalShutdown } from '../lib/interrupt.js';
9
- import { buildLocalTargetUrl, DEFAULT_LOCAL_HOST, normalizeLocalHost, parseLocalPort, probeLocalPort, } from '../lib/local-target.js';
10
+ import { assertStoredLocalTargetListening, buildLocalTargetUrl, DEFAULT_LOCAL_HOST, parseStoredLocalTarget, } from '../lib/local-target.js';
10
11
  import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
11
12
  import { readSecretFileGuarded } from '../lib/secret-file.js';
12
13
  import { assertNotLocal } from '../lib/target-url.js';
13
14
  import { renderTextTable, resolveTextColumns } from '../lib/text-table.js';
14
15
  import { assertIdempotencyKey } from '../lib/validate.js';
15
16
  import { fetchSinglePage, paginate, validatePaginationFlags, } from '../lib/pagination.js';
17
+ import { createProjectEnvCommand } from './project-env.js';
16
18
  /** Attribute names are interpolated into CSS selectors by the engine — keep them plain. */
17
19
  const TEST_ID_ATTRIBUTE_NAME = /^[A-Za-z_][\w.:-]*$/;
18
20
  const TEST_ID_ATTRIBUTES_MAX = 10;
@@ -85,17 +87,6 @@ export async function runGet(opts, deps = {}) {
85
87
  export function resolveCreatedProjectId(r) {
86
88
  return r.projectId ?? r.id;
87
89
  }
88
- function normalizeProjectLocalHost(raw) {
89
- try {
90
- return normalizeLocalHost(raw);
91
- }
92
- catch (err) {
93
- if (err instanceof ApiError && typeof err.details?.reason === 'string') {
94
- throw flagValidationError('local-host', err.details.reason.replace('--target-url', '--url'), err.details.accepted);
95
- }
96
- throw err;
97
- }
98
- }
99
90
  export async function runCreate(opts, deps = {}) {
100
91
  const out = makeOutput(opts.output, deps);
101
92
  const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
@@ -121,21 +112,14 @@ export async function runCreate(opts, deps = {}) {
121
112
  if (opts.description !== undefined) {
122
113
  throw localValidationError('--description is not supported for projects; omit it (test-level descriptions are set on `test create`)');
123
114
  }
124
- if (opts.local !== undefined && opts.targetUrl !== undefined) {
125
- throw localValidationError('--local and --url are mutually exclusive');
126
- }
127
115
  if (opts.local !== undefined && opts.type !== 'frontend') {
128
116
  throw localValidationError('--local projects are frontend-only');
129
117
  }
130
- if (opts.localHost !== undefined && opts.local === undefined) {
131
- throw localValidationError('--local-host requires --local');
132
- }
133
- if (opts.local !== undefined && !/^\d+$/.test(opts.local)) {
134
- throw localValidationError('--local must be a port number between 1 and 65535');
135
- }
136
- const localTarget = opts.local !== undefined
137
- ? { host: normalizeProjectLocalHost(opts.localHost), port: parseLocalPort(opts.local) }
138
- : undefined;
118
+ const localTarget = parseStoredLocalTarget({
119
+ local: opts.local,
120
+ localHost: opts.localHost,
121
+ url: opts.targetUrl,
122
+ });
139
123
  const targetUrl = localTarget
140
124
  ? buildLocalTargetUrl(localTarget.host, localTarget.port)
141
125
  : opts.targetUrl;
@@ -152,8 +136,8 @@ export async function runCreate(opts, deps = {}) {
152
136
  throw localValidationError('--url is required for --type frontend');
153
137
  }
154
138
  if (opts.dryRun) {
155
- // DEV-247: this path returns before makeClient() fires the banner, so emit it
156
- // here — otherwise the canned sample can be mistaken for a live response.
139
+ // This path returns before makeClient() fires the banner, so emit it here
140
+ // — otherwise the canned sample can be mistaken for a live response.
157
141
  emitDryRunBanner(stderr);
158
142
  const idempotencyKey = opts.idempotencyKey ?? `cli-proj-create-${randomUUID()}`;
159
143
  // P2-6: gate idempotency-key output behind --verbose/--debug/json (matches
@@ -180,25 +164,8 @@ export async function runCreate(opts, deps = {}) {
180
164
  out.print(sample, data => renderCreateProjectText(data));
181
165
  return sample;
182
166
  }
183
- if (localTarget && !opts.skipPreflight) {
184
- const outcome = await probeLocalPort(localTarget.host, localTarget.port, deps.localPortProbeDeps);
185
- if (outcome.verdict === 'refuse') {
186
- throw ApiError.fromEnvelope({
187
- error: {
188
- code: 'VALIDATION_ERROR',
189
- message: `Nothing is listening on ${targetUrl}. Start your app first, or pass --skip-preflight.`,
190
- nextAction: 'Verify --local and --local-host match the app you want to test.',
191
- requestId: 'local',
192
- details: {
193
- field: 'local',
194
- reason: 'local-port-not-listening',
195
- host: localTarget.host,
196
- port: localTarget.port,
197
- probeReason: outcome.reason,
198
- },
199
- },
200
- });
201
- }
167
+ if (localTarget) {
168
+ await assertStoredLocalTargetListening(localTarget, opts, deps.localPortProbeDeps);
202
169
  }
203
170
  // Resolve password: flag > file > none
204
171
  let password = opts.password;
@@ -301,12 +268,24 @@ export async function runUpdate(opts, deps = {}) {
301
268
  if (opts.name !== undefined && opts.name.length > 200) {
302
269
  throw localValidationError('--name must be at most 200 characters');
303
270
  }
304
- // P2-7: guard --url against localhost/RFC1918/non-http(s).
271
+ // `--local <port>` is the one way to point a project at an app on this
272
+ // machine, on update exactly as on create. A loopback `--url` has no
273
+ // accepted form here and is redirected to `--local`. The project's type is
274
+ // not known client-side on update; the server refuses `--local` on a
275
+ // backend project.
276
+ const localTarget = parseStoredLocalTarget({
277
+ local: opts.local,
278
+ localHost: opts.localHost,
279
+ url: opts.targetUrl,
280
+ });
281
+ const targetUrl = localTarget
282
+ ? buildLocalTargetUrl(localTarget.host, localTarget.port)
283
+ : opts.targetUrl;
305
284
  if (opts.targetUrl !== undefined) {
306
285
  assertNotLocal(opts.targetUrl, {
307
286
  field: 'url',
308
287
  helpCommand: 'testsprite project update',
309
- hintContext: 'bootstrap',
288
+ hintContext: 'local-project-create',
310
289
  });
311
290
  }
312
291
  if (opts.testIdAttributes !== undefined && opts.clearTestIdAttributes) {
@@ -315,7 +294,7 @@ export async function runUpdate(opts, deps = {}) {
315
294
  const passwordSupplied = opts.password !== undefined || opts.passwordFile !== undefined;
316
295
  const mutableFields = {
317
296
  name: opts.name !== undefined,
318
- targetUrl: opts.targetUrl !== undefined,
297
+ targetUrl: targetUrl !== undefined,
319
298
  username: opts.username !== undefined,
320
299
  password: passwordSupplied,
321
300
  instruction: opts.instruction !== undefined,
@@ -329,7 +308,7 @@ export async function runUpdate(opts, deps = {}) {
329
308
  '--instruction, --test-id-attributes, or --clear-test-id-attributes.');
330
309
  }
331
310
  if (opts.dryRun) {
332
- // DEV-247: emit the banner here (this path returns before makeClient() does).
311
+ // Emit the banner here (this path returns before makeClient() does).
333
312
  emitDryRunBanner(stderr);
334
313
  const idempotencyKey = opts.idempotencyKey ?? `cli-proj-update-${randomUUID()}`;
335
314
  if (opts.idempotencyKey === undefined &&
@@ -345,9 +324,12 @@ export async function runUpdate(opts, deps = {}) {
345
324
  updatedFields: presentFieldNames,
346
325
  updatedAt: '2026-05-16T00:00:00.000Z',
347
326
  };
348
- out.print(sample, data => renderUpdateText(data));
327
+ out.print(sample, data => renderUpdateText(data, localTarget));
349
328
  return sample;
350
329
  }
330
+ if (localTarget) {
331
+ await assertStoredLocalTargetListening(localTarget, opts, deps.localPortProbeDeps);
332
+ }
351
333
  // Resolve password only on the real path. Dry-run must not touch the
352
334
  // filesystem, even when --password-file is present.
353
335
  let password = opts.password;
@@ -360,7 +342,8 @@ export async function runUpdate(opts, deps = {}) {
360
342
  }
361
343
  const bodyFields = {
362
344
  name: opts.name,
363
- targetUrl: opts.targetUrl,
345
+ targetUrl,
346
+ originMode: localTarget ? 'local' : undefined,
364
347
  username: opts.username,
365
348
  password,
366
349
  instruction: opts.instruction,
@@ -389,7 +372,7 @@ export async function runUpdate(opts, deps = {}) {
389
372
  ? { projectId: resolvedUpdatedId, id: resolvedUpdatedId }
390
373
  : {}),
391
374
  };
392
- out.print(updated, data => renderUpdateText(data));
375
+ out.print(updated, data => renderUpdateText(data, localTarget));
393
376
  return updated;
394
377
  }
395
378
  /**
@@ -568,7 +551,7 @@ function renderAutoAuthText(r) {
568
551
  return lines.join('\n');
569
552
  }
570
553
  // ---------------------------------------------------------------------------
571
- // project docs upload — DEV-384 piece V3-D
554
+ // project docs upload
572
555
  // ---------------------------------------------------------------------------
573
556
  /**
574
557
  * CLI-facing role flags → wire enum. Default is `api-doc` (stated in help);
@@ -596,7 +579,7 @@ const DEFAULT_DOC_CONTENT_TYPE = 'application/octet-stream';
596
579
  * source so plan generation has inputs to feed on (closes the API-project
597
580
  * cold start at `no_processed_inputs`).
598
581
  *
599
- * Three-step flow against the V3-A facade routes:
582
+ * Three-step flow against the docs facade routes:
600
583
  *
601
584
  * 1. `POST /projects/{id}/docs/upload-url` — mints a one-hour presigned
602
585
  * S3 PUT URL plus the S3 key to register afterwards.
@@ -701,17 +684,17 @@ export async function runDocsUpload(opts, deps = {}) {
701
684
  // transfer-encoding on presigned PUTs, and Node's fetch uses the explicit
702
685
  // header to keep identity framing with a streamed body.
703
686
  const fetchImpl = deps.fetchImpl ?? globalThis.fetch.bind(globalThis);
704
- // DEV-384 review F3: a remote facade must mint a non-local https URL.
687
+ // A remote facade must mint a non-local https URL.
705
688
  assertSafePresignedUploadUrl(minted.uploadUrl, client.resolvedBaseUrl);
706
689
  // Same flag > TESTSPRITE_REQUEST_TIMEOUT_MS > default resolution (and 1-600s
707
690
  // clamp) as makeHttpClient — this leg bypasses HttpClient, so resolve here.
708
691
  const requestTimeoutMs = resolveRequestTimeoutMs(opts, deps.env ?? process.env);
709
692
  const controller = new AbortController();
710
693
  const timer = setTimeout(() => controller.abort(), requestTimeoutMs);
711
- // DEV-384 review F14b: compose the shutdown signal into the PUT abort
712
- // (manual listeners, house style — no AbortSignal.any) and arm the
713
- // graceful scope for the upload's duration, so Ctrl-C during a long PUT
714
- // takes the honest DEV-331 detach path instead of being unabortable.
694
+ // Compose the shutdown signal into the PUT abort (manual listeners, house
695
+ // style — no AbortSignal.any) and arm the graceful scope for the upload's
696
+ // duration, so Ctrl-C during a long PUT takes the honest detach path
697
+ // instead of being unabortable.
715
698
  const shutdown = deps.shutdown ?? globalShutdown;
716
699
  const shutdownSignal = shutdown.signal;
717
700
  const onShutdownAbort = () => controller.abort(shutdownSignal.reason);
@@ -727,7 +710,7 @@ export async function runDocsUpload(opts, deps = {}) {
727
710
  headers: { 'content-type': contentType, 'content-length': String(stat.size) },
728
711
  body: Readable.toWeb(createReadStream(opts.file)),
729
712
  duplex: 'half',
730
- // #342 review: assertSafePresignedUploadUrl vets the MINTED url, but a
713
+ // assertSafePresignedUploadUrl vets the MINTED url, but a
731
714
  // default `redirect: 'follow'` would let a 3xx from that host resend
732
715
  // the request to an unvetted Location (e.g. a 303 → 169.254.169.254) —
733
716
  // an SSRF-shaped hop the guard never sees. A real S3 presigned PUT never
@@ -771,10 +754,10 @@ export async function runDocsUpload(opts, deps = {}) {
771
754
  catch (cause) {
772
755
  if (cause instanceof ApiError)
773
756
  throw registerStepError(cause);
774
- // DEV-384 review F4: a register timeout needs the same step-3 context —
775
- // it is precisely the case where the caller can't tell whether the
776
- // register landed. Class and exit 7 are preserved; only the text gains
777
- // the upload-succeeded / safe-to-re-run explanation.
757
+ // A register timeout needs the same step-3 context — it is precisely the
758
+ // case where the caller can't tell whether the register landed. Class and
759
+ // exit 7 are preserved; only the text gains the upload-succeeded /
760
+ // safe-to-re-run explanation.
778
761
  if (cause instanceof RequestTimeoutError) {
779
762
  cause.message =
780
763
  `Document register timed out (step 3 of 3) — the S3 upload succeeded, and the ` +
@@ -807,7 +790,7 @@ function describeCause(cause) {
807
790
  return `${cause.message}${nestedMsg}`;
808
791
  }
809
792
  /**
810
- * DEV-384 review F3 — defense-in-depth on the server-minted presigned URL.
793
+ * Defense-in-depth on the server-minted presigned URL.
811
794
  *
812
795
  * A REMOTE facade must mint a non-local `https:` URL; a localhost/private or
813
796
  * plain-http mint from a remote facade is exactly the anomaly to reject
@@ -815,18 +798,17 @@ function describeCause(cause) {
815
798
  * otherwise send the user's file wherever that URL points, before any bytes
816
799
  * leave the machine. A facade that is ITSELF loopback (dev rig, localhost
817
800
  * e2e) is a deliberate operator configuration and is trusted to mint local
818
- * URLs — and ONLY loopback qualifies (#342 review): the gate is a positive,
819
- * fail-closed check, because gating on "anything `assertNotLocal` dislikes"
820
- * would silently disable the guard for an unparsable base URL or a
821
- * user-settable private-range endpoint (`--endpoint-url https://10.1.2.3`).
822
- * Literal checks only (same scope as `assertNotLocal`); no host
823
- * allow-listing by design.
801
+ * URLs — and ONLY loopback qualifies: the gate is a positive, fail-closed
802
+ * check, because gating on "anything `assertNotLocal` dislikes" would
803
+ * silently disable the guard for an unparsable base URL or a user-settable
804
+ * private-range endpoint (`--endpoint-url https://10.1.2.3`). Literal checks
805
+ * only (same scope as `assertNotLocal`); no host allow-listing by design.
824
806
  *
825
- * Known residual (#342 review): a loopback facade that is really a TUNNEL to a
826
- * remote backend (`ssh -L`, a localhost corporate proxy) is trusted here even
827
- * though the real conversation is remote and MITM-able upstream. This is
828
- * inherent to "loopback facade = trusted dev rig" and accepted — the CLI
829
- * cannot tell a dev rig from a tunnel by the base URL alone.
807
+ * Known residual: a loopback facade that is really a TUNNEL to a remote
808
+ * backend (`ssh -L`, a localhost corporate proxy) is trusted here even though
809
+ * the real conversation is remote and MITM-able upstream. This is inherent to
810
+ * "loopback facade = trusted dev rig" and accepted — the CLI cannot tell a
811
+ * dev rig from a tunnel by the base URL alone.
830
812
  */
831
813
  function assertSafePresignedUploadUrl(uploadUrl, facadeBaseUrl) {
832
814
  if (isLoopbackFacade(facadeBaseUrl))
@@ -872,7 +854,7 @@ function isLocalUrl(url) {
872
854
  }
873
855
  }
874
856
  /**
875
- * #342 review: the facade-trust gate for `assertSafePresignedUploadUrl`.
857
+ * The facade-trust gate for `assertSafePresignedUploadUrl`.
876
858
  * Positive and narrow — only an explicitly-loopback facade (`localhost`,
877
859
  * a `127.0.0.0/8` literal, or `[::1]`) is trusted to mint local upload URLs.
878
860
  * Anything else — including an unparsable base URL or a private-range
@@ -969,7 +951,7 @@ export function createProjectCommand(deps = {}) {
969
951
  // raises a typed `ApiError(VALIDATION_ERROR)` and surfaces with
970
952
  // the contract-mandated exit code 5.
971
953
  await runList({
972
- ...resolveCommonOptions(command),
954
+ ...resolveCommonOptions(command, deps.env),
973
955
  pageSize: parseFlag(cmdOpts.pageSize, 'page-size'),
974
956
  startingToken: cmdOpts.startingToken,
975
957
  maxItems: parseFlag(cmdOpts.maxItems, 'max-items'),
@@ -982,7 +964,7 @@ export function createProjectCommand(deps = {}) {
982
964
  .description('Get a project by id')
983
965
  .addHelpText('after', GLOBAL_OPTS_HINT)
984
966
  .action(async (projectId, _cmdOpts, command) => {
985
- await runGet({ ...resolveCommonOptions(command), projectId }, deps);
967
+ await runGet({ ...resolveCommonOptions(command, deps.env), projectId }, deps);
986
968
  });
987
969
  project
988
970
  .command('create')
@@ -1013,7 +995,7 @@ export function createProjectCommand(deps = {}) {
1013
995
  throw localValidationError('--type must be frontend or backend');
1014
996
  }
1015
997
  await runCreate({
1016
- ...resolveCommonOptions(command),
998
+ ...resolveCommonOptions(command, deps.env),
1017
999
  type,
1018
1000
  name: cmdOpts.name,
1019
1001
  targetUrl: cmdOpts.url,
@@ -1035,7 +1017,10 @@ export function createProjectCommand(deps = {}) {
1035
1017
  .command('update <project-id>')
1036
1018
  .description('Update project metadata')
1037
1019
  .option('--name <name>', 'new project name')
1038
- .option('--url <url>', 'new target URL')
1020
+ .option('--url <url>', 'new target URL (public; for an app on this machine use --local)')
1021
+ .option('--local <port>', 'point the project at an app on this machine (1-65535; excludes --url; frontend only)')
1022
+ .option('--local-host <host>', 'loopback host: localhost, 127.0.0.1 (default), or ::1; requires --local')
1023
+ .option('--skip-preflight', 'skip the local TCP listener check before the update')
1039
1024
  .option('--username <user>', 'new auth username')
1040
1025
  .option('--password <pw>', 'new auth password')
1041
1026
  .option('--password-file <path>', 'read new password from file')
@@ -1047,10 +1032,13 @@ export function createProjectCommand(deps = {}) {
1047
1032
  .addHelpText('after', GLOBAL_OPTS_HINT)
1048
1033
  .action(async (projectId, cmdOpts, command) => {
1049
1034
  await runUpdate({
1050
- ...resolveCommonOptions(command),
1035
+ ...resolveCommonOptions(command, deps.env),
1051
1036
  projectId,
1052
1037
  name: cmdOpts.name,
1053
1038
  targetUrl: cmdOpts.url,
1039
+ local: cmdOpts.local,
1040
+ localHost: cmdOpts.localHost,
1041
+ skipPreflight: cmdOpts.skipPreflight,
1054
1042
  username: cmdOpts.username,
1055
1043
  password: cmdOpts.password,
1056
1044
  passwordFile: cmdOpts.passwordFile,
@@ -1076,7 +1064,7 @@ export function createProjectCommand(deps = {}) {
1076
1064
  .addHelpText('after', GLOBAL_OPTS_HINT)
1077
1065
  .action(async (projectId, cmdOpts, command) => {
1078
1066
  await runDelete({
1079
- ...resolveCommonOptions(command),
1067
+ ...resolveCommonOptions(command, deps.env),
1080
1068
  projectId,
1081
1069
  confirm: cmdOpts.confirm === true,
1082
1070
  idempotencyKey: cmdOpts.idempotencyKey,
@@ -1093,7 +1081,7 @@ export function createProjectCommand(deps = {}) {
1093
1081
  .addHelpText('after', GLOBAL_OPTS_HINT)
1094
1082
  .action(async (projectId, cmdOpts, command) => {
1095
1083
  await runCredential({
1096
- ...resolveCommonOptions(command),
1084
+ ...resolveCommonOptions(command, deps.env),
1097
1085
  projectId,
1098
1086
  authType: cmdOpts.type,
1099
1087
  credential: cmdOpts.credential,
@@ -1132,7 +1120,7 @@ export function createProjectCommand(deps = {}) {
1132
1120
  .addHelpText('after', GLOBAL_OPTS_HINT)
1133
1121
  .action(async (projectId, cmdOpts, command) => {
1134
1122
  await runAutoAuth({
1135
- ...resolveCommonOptions(command),
1123
+ ...resolveCommonOptions(command, deps.env),
1136
1124
  projectId,
1137
1125
  disable: cmdOpts.disable,
1138
1126
  method: cmdOpts.method,
@@ -1160,7 +1148,7 @@ export function createProjectCommand(deps = {}) {
1160
1148
  const docs = new Command('docs').description('Manage project documents — the sources plan generation feeds on');
1161
1149
  docs
1162
1150
  .command('upload <file>')
1163
- .description('Upload an API spec or PRD as a project source (DEV-384). Three steps:\n' +
1151
+ .description('Upload an API spec or PRD as a project source. Three steps:\n' +
1164
1152
  'mint a presigned S3 URL, stream the file bytes to it, register the\n' +
1165
1153
  'document — which starts processing + embedding. The local file is\n' +
1166
1154
  'only read; nothing is written back to disk.\n' +
@@ -1178,7 +1166,7 @@ export function createProjectCommand(deps = {}) {
1178
1166
  .addHelpText('after', GLOBAL_OPTS_HINT)
1179
1167
  .action(async (file, cmdOpts, command) => {
1180
1168
  await runDocsUpload({
1181
- ...resolveCommonOptions(command),
1169
+ ...resolveCommonOptions(command, deps.env),
1182
1170
  file,
1183
1171
  projectId: cmdOpts.project,
1184
1172
  role: cmdOpts.role,
@@ -1187,6 +1175,9 @@ export function createProjectCommand(deps = {}) {
1187
1175
  }, deps);
1188
1176
  });
1189
1177
  project.addCommand(docs);
1178
+ // `project env <verb>` — the per-project environment surface (credentials,
1179
+ // URL, default). Own module; `deps` threaded so tests inject.
1180
+ project.addCommand(createProjectEnvCommand(deps));
1190
1181
  return project;
1191
1182
  }
1192
1183
  function parseFlag(raw, flagName) {
@@ -1206,11 +1197,11 @@ function parseFlag(raw, flagName) {
1206
1197
  }
1207
1198
  return n;
1208
1199
  }
1209
- function resolveCommonOptions(command) {
1200
+ function resolveCommonOptions(command, env) {
1210
1201
  const globals = command.optsWithGlobals();
1211
1202
  // P2-8: validate --output before allowing silent fallback to 'text'.
1212
1203
  return {
1213
- profile: globals.profile ?? 'default',
1204
+ profile: resolveProfileName(globals.profile, env),
1214
1205
  output: resolveOutputMode(globals.output),
1215
1206
  endpointUrl: globals.endpointUrl,
1216
1207
  debug: globals.debug ?? false,
@@ -1352,13 +1343,18 @@ function renderCreateProjectText(p, localTarget) {
1352
1343
  }
1353
1344
  return lines.join('\n');
1354
1345
  }
1355
- function renderUpdateText(r) {
1346
+ function renderUpdateText(r, localTarget) {
1356
1347
  const lines = [
1357
1348
  `id: ${resolveUpdatedProjectId(r) ?? '(unknown)'}`,
1358
1349
  `updatedFields: ${r.updatedFields?.join(', ') ?? '(none)'}`,
1359
1350
  ];
1360
1351
  if (r.updatedAt !== undefined)
1361
1352
  lines.push(`updatedAt: ${r.updatedAt}`);
1353
+ if (localTarget) {
1354
+ const url = buildLocalTargetUrl(localTarget.host, localTarget.port);
1355
+ const hostFlag = localTarget.host === DEFAULT_LOCAL_HOST ? '' : ` --local-host ${localTarget.host}`;
1356
+ lines.push(`Local project: TestSprite will reach ${url} only through a tunnel from this machine.`, `Run its tests with: testsprite test run <test-id> --local ${localTarget.port}${hostFlag}`);
1357
+ }
1362
1358
  return lines.join('\n');
1363
1359
  }
1364
1360
  function renderDeleteText(r) {
@@ -1367,7 +1363,7 @@ function renderDeleteText(r) {
1367
1363
  /**
1368
1364
  * `--project` resolution for `project docs upload` — mirrors test.ts's
1369
1365
  * resolveProjectId/requireProjectId so `TESTSPRITE_PROJECT_ID` works here the
1370
- * same as on every other command (DEV-384 review F5). Flag wins over env.
1366
+ * same as on every other command. Flag wins over env.
1371
1367
  */
1372
1368
  function requireDocsProjectId(projectId, deps) {
1373
1369
  const explicit = projectId?.trim();
@@ -1,6 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
  import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factory.js';
3
3
  import type { FetchImpl } from '../lib/http.js';
4
+ import { type HistoryRetentionMeta } from '../lib/history-retention.js';
4
5
  /** A schedule as returned by the API. */
5
6
  export interface CliSchedule {
6
7
  scheduleId: string;
@@ -109,6 +110,7 @@ export interface CliScheduleRun {
109
110
  /** `GET /schedules/{id}/runs` response. Not paginated. */
110
111
  interface ScheduleRunListResponse {
111
112
  runs: CliScheduleRun[];
113
+ meta?: HistoryRetentionMeta;
112
114
  }
113
115
  export declare function runList(opts: ListOptions, deps?: ScheduleDeps): Promise<ScheduleListResponse>;
114
116
  export declare function runGet(opts: GetOptions, deps?: ScheduleDeps): Promise<CliSchedule>;
@@ -1,11 +1,13 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { Command } from 'commander';
3
3
  import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
4
+ import { resolveProfileName } from '../lib/config.js';
4
5
  import { ApiError } from '../lib/errors.js';
5
6
  import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
6
7
  import { formatScheduleFrequencyAdvisory, runsPerMonth } from '../lib/cron.js';
7
8
  import { renderTextTable } from '../lib/text-table.js';
8
9
  import { assertIdempotencyKey } from '../lib/validate.js';
10
+ import { historyRetentionNote } from '../lib/history-retention.js';
9
11
  // ---------------------------------------------------------------------------
10
12
  // schedule list
11
13
  // ---------------------------------------------------------------------------
@@ -191,8 +193,14 @@ export async function runRunList(opts, deps = {}) {
191
193
  const client = makeClient(opts, deps);
192
194
  const response = await client.get(`/schedules/${encodeURIComponent(opts.scheduleId)}/runs`);
193
195
  const runs = response.runs ?? [];
194
- out.print({ runs }, () => renderRunListText(runs, { columns: opts.columns, noHeader: opts.noHeader }));
195
- return { runs };
196
+ const outputResponse = { ...response, runs };
197
+ out.print(outputResponse, () => renderRunListText(runs, { columns: opts.columns, noHeader: opts.noHeader }));
198
+ if (opts.output === 'text') {
199
+ const note = historyRetentionNote(response.meta, client.resolvedBaseUrl);
200
+ if (note)
201
+ (deps.stderr ?? ((line) => process.stderr.write(`${line}\n`)))(note);
202
+ }
203
+ return outputResponse;
196
204
  }
197
205
  // ---------------------------------------------------------------------------
198
206
  // Rendering
@@ -315,7 +323,7 @@ export function createScheduleCommand(deps = {}) {
315
323
  .addHelpText('after', GLOBAL_OPTS_HINT)
316
324
  .action(async (cmdOpts, command) => {
317
325
  await runList({
318
- ...resolveCommonOptions(command),
326
+ ...resolveCommonOptions(command, deps.env),
319
327
  columns: cmdOpts.columns,
320
328
  noHeader: cmdOpts.header === false,
321
329
  }, deps);
@@ -332,7 +340,7 @@ export function createScheduleCommand(deps = {}) {
332
340
  ' 13 not available on your plan')
333
341
  .addHelpText('after', GLOBAL_OPTS_HINT)
334
342
  .action(async (scheduleId, _cmdOpts, command) => {
335
- await runGet({ ...resolveCommonOptions(command), scheduleId }, deps);
343
+ await runGet({ ...resolveCommonOptions(command, deps.env), scheduleId }, deps);
336
344
  });
337
345
  schedule
338
346
  .command('create')
@@ -361,7 +369,7 @@ export function createScheduleCommand(deps = {}) {
361
369
  .addHelpText('after', GLOBAL_OPTS_HINT)
362
370
  .action(async (cmdOpts, command) => {
363
371
  await runCreate({
364
- ...resolveCommonOptions(command),
372
+ ...resolveCommonOptions(command, deps.env),
365
373
  name: cmdOpts.name,
366
374
  targetType: cmdOpts.targetType,
367
375
  targetId: cmdOpts.targetId,
@@ -398,7 +406,7 @@ export function createScheduleCommand(deps = {}) {
398
406
  .addHelpText('after', GLOBAL_OPTS_HINT)
399
407
  .action(async (scheduleId, cmdOpts, command) => {
400
408
  await runUpdate({
401
- ...resolveCommonOptions(command),
409
+ ...resolveCommonOptions(command, deps.env),
402
410
  scheduleId,
403
411
  name: cmdOpts.name,
404
412
  cron: cmdOpts.cron,
@@ -428,7 +436,7 @@ export function createScheduleCommand(deps = {}) {
428
436
  .addHelpText('after', GLOBAL_OPTS_HINT)
429
437
  .action(async (scheduleId, cmdOpts, command) => {
430
438
  await runDelete({
431
- ...resolveCommonOptions(command),
439
+ ...resolveCommonOptions(command, deps.env),
432
440
  scheduleId,
433
441
  confirm: cmdOpts.confirm === true,
434
442
  idempotencyKey: cmdOpts.idempotencyKey,
@@ -450,7 +458,7 @@ export function createScheduleCommand(deps = {}) {
450
458
  .addHelpText('after', GLOBAL_OPTS_HINT)
451
459
  .action(async (scheduleId, cmdOpts, command) => {
452
460
  await runRunList({
453
- ...resolveCommonOptions(command),
461
+ ...resolveCommonOptions(command, deps.env),
454
462
  scheduleId,
455
463
  columns: cmdOpts.columns,
456
464
  noHeader: cmdOpts.header === false,
@@ -461,10 +469,10 @@ export function createScheduleCommand(deps = {}) {
461
469
  // ---------------------------------------------------------------------------
462
470
  // Helpers
463
471
  // ---------------------------------------------------------------------------
464
- function resolveCommonOptions(command) {
472
+ function resolveCommonOptions(command, env) {
465
473
  const globals = command.optsWithGlobals();
466
474
  return {
467
- profile: globals.profile ?? 'default',
475
+ profile: resolveProfileName(globals.profile, env),
468
476
  output: resolveOutputMode(globals.output),
469
477
  endpointUrl: globals.endpointUrl,
470
478
  debug: globals.debug ?? false,