@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
@@ -0,0 +1,486 @@
1
+ /**
2
+ * `testsprite project env <verb>` — the per-project environment surface.
3
+ *
4
+ * An environment is a named bundle of "how to reach and log in to the app": a
5
+ * URL and a login method. `test run --env <name>`
6
+ * picks one by NAME, which is unique per project server-side; the default
7
+ * environment is what every run without `--env` has always used.
8
+ *
9
+ * An app that only runs on your own machine is named with `--local <port>`
10
+ * instead of `--url` — the same spelling as `project create`. The CLI builds
11
+ * the loopback URL and sends the `originMode: 'local'` marker that lets the
12
+ * server store it:
13
+ *
14
+ * project env create <pid> --name local-dev --local 5173 \
15
+ * --username … --password-file …
16
+ * test run <test-id> --env local-dev --local 5173
17
+ *
18
+ * `--local` on the run is what makes that address reachable from the cloud
19
+ * runner; a run against a loopback environment without it is refused before
20
+ * dispatch. A loopback `--url` is redirected to `--local`; everything the
21
+ * runner can never reach (RFC1918, link-local, the metadata address,
22
+ * non-http(s)) stays rejected.
23
+ *
24
+ * Thin facade over `/api/cli/v1/projects/{id}/env`; the server owns every
25
+ * rule (name uniqueness, default recompute, credential storage). Passwords go
26
+ * up in the request body and are never echoed — not by the server, not by any
27
+ * renderer here.
28
+ */
29
+ import { randomUUID } from 'node:crypto';
30
+ import { Command } from 'commander';
31
+ import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
32
+ import { resolveProfileName } from '../lib/config.js';
33
+ import { ApiError } from '../lib/errors.js';
34
+ import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
35
+ import { readSecretFileGuarded } from '../lib/secret-file.js';
36
+ import { assertStoredLocalTargetListening, buildLocalTargetUrl, parseStoredLocalTarget, } from '../lib/local-target.js';
37
+ import { assertNotLocal } from '../lib/target-url.js';
38
+ import { renderTextTable } from '../lib/text-table.js';
39
+ import { assertIdempotencyKey } from '../lib/validate.js';
40
+ // ---------------------------------------------------------------------------
41
+ // Shared plumbing (same shape as `project.ts`; kept local so this module does
42
+ // not import `project.ts` at runtime — that file imports this one).
43
+ // ---------------------------------------------------------------------------
44
+ function resolveCommonOptions(command, env) {
45
+ const globals = command.optsWithGlobals();
46
+ return {
47
+ profile: resolveProfileName(globals.profile, env),
48
+ output: resolveOutputMode(globals.output),
49
+ endpointUrl: globals.endpointUrl,
50
+ debug: globals.debug ?? false,
51
+ verbose: globals.verbose ?? false,
52
+ dryRun: globals.dryRun ?? false,
53
+ requestTimeoutMs: parseRequestTimeoutFlag(globals.requestTimeout),
54
+ };
55
+ }
56
+ function makeClient(opts, deps) {
57
+ return makeHttpClient(opts, {
58
+ env: deps.env,
59
+ credentialsPath: deps.credentialsPath,
60
+ fetchImpl: deps.fetchImpl,
61
+ stderr: deps.stderr,
62
+ });
63
+ }
64
+ function makeOutput(mode, deps) {
65
+ return new Output(mode, { stdout: deps.stdout, stderr: deps.stderr });
66
+ }
67
+ function stderrOf(deps) {
68
+ return deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
69
+ }
70
+ function localValidationError(message) {
71
+ return ApiError.fromEnvelope({
72
+ error: {
73
+ code: 'VALIDATION_ERROR',
74
+ message: 'Invalid request.',
75
+ nextAction: message,
76
+ requestId: 'local',
77
+ details: { reason: 'missing_required_flag' },
78
+ },
79
+ });
80
+ }
81
+ function envPath(projectId, name) {
82
+ const base = `/projects/${encodeURIComponent(projectId)}/env`;
83
+ return name === undefined ? base : `${base}/${encodeURIComponent(name)}`;
84
+ }
85
+ /** Trim + reject an empty environment name; the server owns every other rule. */
86
+ function requireEnvName(raw, flag) {
87
+ const name = raw?.trim() ?? '';
88
+ if (name.length === 0) {
89
+ throw localValidationError(`${flag} is required and must not be empty or whitespace-only`);
90
+ }
91
+ if (name.length > 100)
92
+ throw localValidationError(`${flag} must be at most 100 characters`);
93
+ return name;
94
+ }
95
+ /** Resolve `--password` / `--password-file` (mutually exclusive; never both). */
96
+ function resolvePassword(opts) {
97
+ if (opts.password !== undefined && opts.passwordFile !== undefined) {
98
+ throw localValidationError('--password and --password-file are mutually exclusive.');
99
+ }
100
+ if (opts.password !== undefined) {
101
+ if (opts.password.trim().length === 0) {
102
+ throw localValidationError('--password must not be empty or whitespace-only');
103
+ }
104
+ return opts.password;
105
+ }
106
+ if (opts.passwordFile !== undefined) {
107
+ return readSecretFileGuarded('password-file', opts.passwordFile);
108
+ }
109
+ return undefined;
110
+ }
111
+ function mintIdempotencyKey(verb, opts, stderr) {
112
+ const key = opts.idempotencyKey ?? `cli-proj-env-${verb}-${randomUUID()}`;
113
+ if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
114
+ stderr(`idempotency-key: ${key}`);
115
+ }
116
+ return key;
117
+ }
118
+ function describeAuth(env) {
119
+ // `otp` already says the mode; repeating it as a suffix read as two settings.
120
+ const parts = [env.authMode];
121
+ if (env.hasCredentials)
122
+ parts.push('(credentials set)');
123
+ if (env.enableOtp && env.authMode !== 'otp')
124
+ parts.push('+otp');
125
+ return parts.join(' ');
126
+ }
127
+ const ENV_LIST_COLUMNS = [
128
+ {
129
+ header: 'NAME',
130
+ width: rows => Math.max(4, ...rows.map(env => env.name.length)),
131
+ render: env => env.name,
132
+ },
133
+ { header: 'DEFAULT', width: 7, render: env => (env.isDefault ? 'yes' : '—') },
134
+ {
135
+ header: 'URL',
136
+ width: rows => Math.max(3, ...rows.map(env => env.url.length)),
137
+ render: env => env.url,
138
+ },
139
+ {
140
+ header: 'AUTH',
141
+ width: rows => Math.max(4, ...rows.map(env => describeAuth(env).length)),
142
+ render: describeAuth,
143
+ },
144
+ { header: 'ACCOUNT', width: 0, render: env => env.username ?? '—' },
145
+ ];
146
+ function renderEnvListText(r) {
147
+ if (r.environments.length === 0) {
148
+ return 'No environments. Create one with: testsprite project env create <project-id> --name <name> --url <url>';
149
+ }
150
+ return renderTextTable(r.environments, ENV_LIST_COLUMNS);
151
+ }
152
+ function renderEnvText(env) {
153
+ return [
154
+ `name: ${env.name}`,
155
+ `id: ${env.id}`,
156
+ `default: ${env.isDefault ? 'yes' : 'no'}`,
157
+ `url: ${env.url}`,
158
+ `auth: ${describeAuth(env)}`,
159
+ `account: ${env.username ?? '(none stored)'}`,
160
+ `updatedAt: ${env.updatedAt}`,
161
+ ].join('\n');
162
+ }
163
+ function sampleEnv(overrides) {
164
+ return {
165
+ id: '00000000-0000-4000-8000-000000000000',
166
+ name: 'sample',
167
+ url: 'https://staging.example.com',
168
+ isDefault: false,
169
+ authMode: 'account',
170
+ hasCredentials: false,
171
+ username: null,
172
+ enableOtp: false,
173
+ updatedAt: '2026-09-09T00:00:00.000Z',
174
+ ...overrides,
175
+ };
176
+ }
177
+ export async function runEnvList(opts, deps = {}) {
178
+ const out = makeOutput(opts.output, deps);
179
+ if (opts.dryRun) {
180
+ emitDryRunBanner(stderrOf(deps));
181
+ const sample = {
182
+ environments: [
183
+ sampleEnv({ name: 'production', isDefault: true, hasCredentials: true }),
184
+ sampleEnv({ name: 'local-dev', url: 'http://127.0.0.1:5173', hasCredentials: true }),
185
+ ],
186
+ };
187
+ out.print(sample, data => renderEnvListText(data));
188
+ return sample;
189
+ }
190
+ const client = makeClient(opts, deps);
191
+ const res = await client.get(envPath(opts.projectId));
192
+ out.print(res, data => renderEnvListText(data));
193
+ return res;
194
+ }
195
+ export async function runEnvCreate(opts, deps = {}) {
196
+ const out = makeOutput(opts.output, deps);
197
+ const stderr = stderrOf(deps);
198
+ assertIdempotencyKey(opts.idempotencyKey);
199
+ const name = requireEnvName(opts.name, '--name');
200
+ const localTarget = parseStoredLocalTarget(opts);
201
+ if (localTarget === undefined && (opts.url === undefined || opts.url.trim().length === 0)) {
202
+ throw localValidationError('--url is required: it names the address runs against this environment open. ' +
203
+ 'For an app that only runs on this machine, pass --local <port> instead, then run it ' +
204
+ 'with `test run <id> --env <name> --local <port>`.');
205
+ }
206
+ if (opts.url !== undefined) {
207
+ assertNotLocal(opts.url, {
208
+ field: 'url',
209
+ helpCommand: 'testsprite project env create',
210
+ hintContext: 'local-project-create',
211
+ });
212
+ }
213
+ const url = localTarget ? buildLocalTargetUrl(localTarget.host, localTarget.port) : opts.url;
214
+ if (opts.username !== undefined && opts.username.trim().length === 0) {
215
+ throw localValidationError('--username must not be empty or whitespace-only');
216
+ }
217
+ if (opts.dryRun) {
218
+ emitDryRunBanner(stderr);
219
+ mintIdempotencyKey('create', opts, stderr);
220
+ const sample = {
221
+ environment: sampleEnv({
222
+ name,
223
+ url,
224
+ isDefault: opts.setDefault === true,
225
+ hasCredentials: opts.password !== undefined || opts.passwordFile !== undefined,
226
+ }),
227
+ created: true,
228
+ };
229
+ out.print(sample, data => renderEnvText(data.environment));
230
+ return sample;
231
+ }
232
+ if (localTarget) {
233
+ await assertStoredLocalTargetListening(localTarget, opts, deps.localPortProbeDeps);
234
+ }
235
+ // Secrets are read only on the real path — never for a dry run.
236
+ const password = resolvePassword(opts);
237
+ const body = { name, url };
238
+ // The marker rides with the URL: it is what authorizes storing a loopback
239
+ // address, and it lives on the environment the server creates.
240
+ if (localTarget)
241
+ body.originMode = 'local';
242
+ if (opts.username !== undefined)
243
+ body.username = opts.username;
244
+ if (password !== undefined)
245
+ body.password = password;
246
+ if (opts.setDefault)
247
+ body.setDefault = true;
248
+ const idempotencyKey = mintIdempotencyKey('create', opts, stderr);
249
+ const client = makeClient(opts, deps);
250
+ const res = await client.post(envPath(opts.projectId), {
251
+ body,
252
+ headers: { 'idempotency-key': idempotencyKey },
253
+ });
254
+ out.print(res, data => renderEnvText(data.environment));
255
+ return res;
256
+ }
257
+ export async function runEnvUpdate(opts, deps = {}) {
258
+ const out = makeOutput(opts.output, deps);
259
+ const stderr = stderrOf(deps);
260
+ assertIdempotencyKey(opts.idempotencyKey);
261
+ const name = requireEnvName(opts.name, '<name>');
262
+ const localTarget = parseStoredLocalTarget(opts);
263
+ if (opts.url !== undefined) {
264
+ if (opts.url.trim().length === 0) {
265
+ throw localValidationError('--url must not be empty. An environment always has an address; delete the environment ' +
266
+ 'if it is no longer used (testsprite project env delete <project-id> <name> --confirm).');
267
+ }
268
+ assertNotLocal(opts.url, {
269
+ field: 'url',
270
+ helpCommand: 'testsprite project env update',
271
+ hintContext: 'local-project-create',
272
+ });
273
+ }
274
+ const url = localTarget ? buildLocalTargetUrl(localTarget.host, localTarget.port) : opts.url;
275
+ if (opts.username !== undefined && opts.username.trim().length === 0) {
276
+ throw localValidationError('--username must not be empty or whitespace-only');
277
+ }
278
+ const rename = opts.rename !== undefined ? requireEnvName(opts.rename, '--rename') : undefined;
279
+ const passwordSupplied = opts.password !== undefined || opts.passwordFile !== undefined;
280
+ const mutable = {
281
+ url: url !== undefined,
282
+ username: opts.username !== undefined,
283
+ password: passwordSupplied,
284
+ rename: rename !== undefined,
285
+ };
286
+ const present = Object.entries(mutable)
287
+ .filter(([, on]) => on)
288
+ .map(([field]) => field);
289
+ if (present.length === 0) {
290
+ throw localValidationError('At least one mutable flag is required: --url, --username, ' +
291
+ '--password / --password-file, or --rename.');
292
+ }
293
+ if (opts.dryRun) {
294
+ emitDryRunBanner(stderr);
295
+ mintIdempotencyKey('update', opts, stderr);
296
+ const sample = {
297
+ environment: sampleEnv({
298
+ name: rename ?? name,
299
+ url: url ?? 'https://staging.example.com',
300
+ hasCredentials: passwordSupplied,
301
+ }),
302
+ };
303
+ out.print(sample, data => renderEnvText(data.environment));
304
+ return sample;
305
+ }
306
+ if (localTarget) {
307
+ await assertStoredLocalTargetListening(localTarget, opts, deps.localPortProbeDeps);
308
+ }
309
+ const password = resolvePassword(opts);
310
+ const body = {};
311
+ if (url !== undefined)
312
+ body.url = url;
313
+ if (localTarget)
314
+ body.originMode = 'local';
315
+ if (opts.username !== undefined)
316
+ body.username = opts.username;
317
+ if (password !== undefined)
318
+ body.password = password;
319
+ if (rename !== undefined)
320
+ body.rename = rename;
321
+ const idempotencyKey = mintIdempotencyKey('update', opts, stderr);
322
+ const client = makeClient(opts, deps);
323
+ const res = await client.patch(envPath(opts.projectId, name), {
324
+ body,
325
+ headers: { 'idempotency-key': idempotencyKey },
326
+ });
327
+ out.print(res, data => renderEnvText(data.environment));
328
+ return res;
329
+ }
330
+ export async function runEnvDelete(opts, deps = {}) {
331
+ const out = makeOutput(opts.output, deps);
332
+ const stderr = stderrOf(deps);
333
+ assertIdempotencyKey(opts.idempotencyKey);
334
+ const name = requireEnvName(opts.name, '<name>');
335
+ if (!opts.confirm) {
336
+ throw localValidationError('--confirm is required: deleting an environment removes its stored credentials and ' +
337
+ 'login settings. Runs that referenced it by name will fail until you recreate it.');
338
+ }
339
+ if (opts.dryRun) {
340
+ emitDryRunBanner(stderr);
341
+ mintIdempotencyKey('delete', opts, stderr);
342
+ const sample = { deleted: true, name };
343
+ out.print(sample, () => `deleted: ${name}`);
344
+ return sample;
345
+ }
346
+ const idempotencyKey = mintIdempotencyKey('delete', opts, stderr);
347
+ const client = makeClient(opts, deps);
348
+ const res = await client.delete(envPath(opts.projectId, name), {
349
+ headers: { 'idempotency-key': idempotencyKey },
350
+ });
351
+ out.print(res, data => `deleted: ${data.name}`);
352
+ return res;
353
+ }
354
+ export async function runEnvSetDefault(opts, deps = {}) {
355
+ const out = makeOutput(opts.output, deps);
356
+ const stderr = stderrOf(deps);
357
+ assertIdempotencyKey(opts.idempotencyKey);
358
+ const name = requireEnvName(opts.name, '<name>');
359
+ if (opts.dryRun) {
360
+ emitDryRunBanner(stderr);
361
+ mintIdempotencyKey('set-default', opts, stderr);
362
+ const sample = {
363
+ environment: sampleEnv({ name, isDefault: true }),
364
+ };
365
+ out.print(sample, data => renderEnvText(data.environment));
366
+ return sample;
367
+ }
368
+ const idempotencyKey = mintIdempotencyKey('set-default', opts, stderr);
369
+ const client = makeClient(opts, deps);
370
+ const res = await client.post(`${envPath(opts.projectId, name)}/default`, { body: {}, headers: { 'idempotency-key': idempotencyKey } });
371
+ out.print(res, data => renderEnvText(data.environment));
372
+ return res;
373
+ }
374
+ const IDEMPOTENCY_HELP = 'opaque idempotency token. Defaults to a UUIDv4 minted per invocation.';
375
+ const EXIT_CODE_NOTE = '\nExit codes:\n' +
376
+ ' 0 success\n' +
377
+ ' 3 auth error\n' +
378
+ ' 4 project (or environment) not found\n' +
379
+ ' 5 validation error\n' +
380
+ ' 6 conflict (name already exists / deleting the default)';
381
+ export function createProjectEnvCommand(deps = {}) {
382
+ const env = new Command('env')
383
+ .description("Manage a project's environments — named URL + test-account bundles that `test run --env <name>` selects")
384
+ .addHelpText('after', '\nFor an app that only runs on this machine, create or update the environment with\n' +
385
+ '`--local <port>` instead of `--url`; reach it per run with `test run <id> --env <name> --local <port>`.');
386
+ env
387
+ .command('list <project-id>')
388
+ .description("List a project's environments (name, default, URL, auth)." + EXIT_CODE_NOTE)
389
+ .addHelpText('after', GLOBAL_OPTS_HINT)
390
+ .action(async (projectId, _cmdOpts, command) => {
391
+ await runEnvList({ ...resolveCommonOptions(command, deps.env), projectId }, deps);
392
+ });
393
+ env
394
+ .command('create <project-id>')
395
+ .description('Create an environment (--name and one of --url / --local are required).' + EXIT_CODE_NOTE)
396
+ .option('--name <name>', 'environment name, unique within the project (required)')
397
+ .option('--url <url>', 'address runs open (public http/https; for an app on this machine use --local)')
398
+ .option('--local <port>', 'an app on this machine: stores http://<host>:<port> (1-65535; excludes --url; frontend only)')
399
+ .option('--local-host <host>', 'loopback host: localhost, 127.0.0.1 (default), or ::1; requires --local')
400
+ .option('--skip-preflight', 'skip the local TCP listener check before creating')
401
+ .option('--username <user>', 'test-account username the browser logs in with')
402
+ .option('--password <pw>', 'test-account password (prefer --password-file)')
403
+ .option('--password-file <path>', 'read the password from a file instead of the command line')
404
+ .option('--set-default', "make this the project's default environment", false)
405
+ .option('--idempotency-key <token>', IDEMPOTENCY_HELP)
406
+ .addHelpText('after', GLOBAL_OPTS_HINT)
407
+ .action(async (projectId, cmdOpts, command) => {
408
+ await runEnvCreate({
409
+ ...resolveCommonOptions(command, deps.env),
410
+ projectId,
411
+ name: cmdOpts.name,
412
+ url: cmdOpts.url,
413
+ local: cmdOpts.local,
414
+ localHost: cmdOpts.localHost,
415
+ skipPreflight: cmdOpts.skipPreflight,
416
+ username: cmdOpts.username,
417
+ password: cmdOpts.password,
418
+ passwordFile: cmdOpts.passwordFile,
419
+ setDefault: cmdOpts.setDefault === true,
420
+ idempotencyKey: cmdOpts.idempotencyKey,
421
+ }, deps);
422
+ });
423
+ env
424
+ .command('update <project-id> <name>')
425
+ .description("Change an environment's URL, credentials or name." + EXIT_CODE_NOTE)
426
+ .option('--url <url>', 'new address runs open (public http/https; for an app on this machine use --local)')
427
+ .option('--local <port>', 'repoint at an app on this machine: stores http://<host>:<port> (1-65535; excludes --url)')
428
+ .option('--local-host <host>', 'loopback host: localhost, 127.0.0.1 (default), or ::1; requires --local')
429
+ .option('--skip-preflight', 'skip the local TCP listener check before the update')
430
+ .option('--username <user>', 'new test-account username')
431
+ .option('--password <pw>', 'new test-account password (prefer --password-file)')
432
+ .option('--password-file <path>', 'read the new password from a file')
433
+ .option('--rename <new-name>', 'rename the environment (runs keep referring to it by the new name)')
434
+ .option('--idempotency-key <token>', IDEMPOTENCY_HELP)
435
+ .addHelpText('after', GLOBAL_OPTS_HINT)
436
+ .action(async (projectId, name, cmdOpts, command) => {
437
+ await runEnvUpdate({
438
+ ...resolveCommonOptions(command, deps.env),
439
+ projectId,
440
+ name,
441
+ url: cmdOpts.url,
442
+ local: cmdOpts.local,
443
+ localHost: cmdOpts.localHost,
444
+ skipPreflight: cmdOpts.skipPreflight,
445
+ username: cmdOpts.username,
446
+ password: cmdOpts.password,
447
+ passwordFile: cmdOpts.passwordFile,
448
+ rename: cmdOpts.rename,
449
+ idempotencyKey: cmdOpts.idempotencyKey,
450
+ }, deps);
451
+ });
452
+ env
453
+ .command('delete <project-id> <name>')
454
+ .description('Delete an environment and its stored credentials. Requires --confirm; the default\n' +
455
+ 'environment cannot be deleted (set another default first).' +
456
+ EXIT_CODE_NOTE)
457
+ .option('--confirm', 'required: explicit confirmation for the destructive operation', false)
458
+ .option('--idempotency-key <token>', IDEMPOTENCY_HELP)
459
+ .addHelpText('after', GLOBAL_OPTS_HINT)
460
+ .action(async (projectId, name, cmdOpts, command) => {
461
+ await runEnvDelete({
462
+ ...resolveCommonOptions(command, deps.env),
463
+ projectId,
464
+ name,
465
+ confirm: cmdOpts.confirm === true,
466
+ idempotencyKey: cmdOpts.idempotencyKey,
467
+ }, deps);
468
+ });
469
+ env
470
+ .command('set-default <project-id> <name>')
471
+ .description('Make an environment the project default — what every run without --env uses.\n' +
472
+ 'The environment needs a URL.' +
473
+ EXIT_CODE_NOTE)
474
+ .option('--idempotency-key <token>', IDEMPOTENCY_HELP)
475
+ .addHelpText('after', GLOBAL_OPTS_HINT)
476
+ .action(async (projectId, name, cmdOpts, command) => {
477
+ await runEnvSetDefault({
478
+ ...resolveCommonOptions(command, deps.env),
479
+ projectId,
480
+ name,
481
+ idempotencyKey: cmdOpts.idempotencyKey,
482
+ }, deps);
483
+ });
484
+ return env;
485
+ }
486
+ //# sourceMappingURL=project-env.js.map
@@ -68,7 +68,7 @@ export interface ProjectDeps {
68
68
  stdout?: (line: string) => void;
69
69
  stderr?: (line: string) => void;
70
70
  localPortProbeDeps?: LocalPortProbeDeps;
71
- /** Graceful-detach coordinator (DEV-331); tests inject their own. */
71
+ /** Graceful-detach coordinator; tests inject their own. */
72
72
  shutdown?: ShutdownHandle;
73
73
  }
74
74
  type CommonOptions = FactoryCommonOptions;
@@ -125,6 +125,8 @@ export interface CliCreateProjectResponse {
125
125
  /** Resolve the created project's id regardless of which field name the backend used. */
126
126
  export declare function resolveCreatedProjectId(r: CliCreateProjectResponse): string | undefined;
127
127
  interface CreateOptions extends CommonOptions {
128
+ /** `'local'` marks the target as an app on the caller's own machine. */
129
+ originMode?: 'local';
128
130
  type: 'frontend' | 'backend';
129
131
  name: string;
130
132
  targetUrl?: string;
@@ -163,6 +165,14 @@ interface UpdateOptions extends CommonOptions {
163
165
  projectId: string;
164
166
  name?: string;
165
167
  targetUrl?: string;
168
+ /**
169
+ * `--local <port>`: point the project at an app on this machine. The same
170
+ * spelling as `project create`; builds the loopback URL and sends the
171
+ * `originMode: 'local'` marker that lets the server store it.
172
+ */
173
+ local?: string;
174
+ localHost?: string;
175
+ skipPreflight?: boolean;
166
176
  username?: string;
167
177
  password?: string;
168
178
  passwordFile?: string;
@@ -258,20 +268,20 @@ declare const DOC_ROLES: {
258
268
  };
259
269
  type DocRoleFlag = keyof typeof DOC_ROLES;
260
270
  type DocRoleWire = (typeof DOC_ROLES)[DocRoleFlag];
261
- /** `POST /projects/{id}/docs/upload-url` response (V3-A facade). */
271
+ /** `POST /projects/{id}/docs/upload-url` response (docs facade). */
262
272
  export interface CliDocsUploadUrlResponse {
263
273
  uploadUrl: string;
264
274
  s3Key: string;
265
275
  expiresInSeconds: number;
266
276
  }
267
- /** `POST /projects/{id}/docs` (register) response (V3-A facade). */
277
+ /** `POST /projects/{id}/docs` (register) response (docs facade). */
268
278
  export interface CliDocsRegisterResponse {
269
279
  resourceId: string;
270
280
  displayName: string;
271
281
  docRole: DocRoleWire | null;
272
282
  processStatus: string;
273
283
  }
274
- /** Success result — the JSON-mode stdout shape (piece V3-D scope item 3). */
284
+ /** Success result — the JSON-mode stdout shape. */
275
285
  export interface CliDocsUploadResult {
276
286
  resourceId: string;
277
287
  displayName: string;
@@ -303,7 +313,7 @@ interface DocsUploadOptions extends CommonOptions {
303
313
  * source so plan generation has inputs to feed on (closes the API-project
304
314
  * cold start at `no_processed_inputs`).
305
315
  *
306
- * Three-step flow against the V3-A facade routes:
316
+ * Three-step flow against the docs facade routes:
307
317
  *
308
318
  * 1. `POST /projects/{id}/docs/upload-url` — mints a one-hour presigned
309
319
  * S3 PUT URL plus the S3 key to register afterwards.