@testsprite/testsprite-cli 0.11.0 → 0.12.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.
- package/README.md +41 -40
- package/dist/commands/ci.js +34 -4
- package/dist/commands/project-env.d.ts +90 -0
- package/dist/commands/project-env.js +486 -0
- package/dist/commands/project.d.ts +10 -0
- package/dist/commands/project.js +48 -52
- package/dist/commands/test.d.ts +30 -4
- package/dist/commands/test.js +203 -16
- package/dist/commands/testlist.js +29 -3
- package/dist/index.js +13 -3
- package/dist/lib/client-factory.js +2 -0
- package/dist/lib/client-tag.d.ts +13 -0
- package/dist/lib/client-tag.js +44 -0
- package/dist/lib/conflict-reason.d.ts +43 -2
- package/dist/lib/conflict-reason.js +100 -14
- package/dist/lib/cron.js +8 -1
- package/dist/lib/errors.d.ts +44 -1
- package/dist/lib/errors.js +69 -12
- package/dist/lib/gh-output.d.ts +25 -11
- package/dist/lib/gh-output.js +36 -13
- package/dist/lib/http.d.ts +7 -0
- package/dist/lib/http.js +7 -2
- package/dist/lib/local-target.d.ts +32 -0
- package/dist/lib/local-target.js +77 -0
- package/dist/lib/output.d.ts +27 -1
- package/dist/lib/output.js +22 -3
- package/dist/lib/response-schemas.js +18 -0
- package/dist/lib/runs.types.d.ts +39 -2
- package/dist/lib/target-url.js +31 -12
- package/dist/lib/telemetry.d.ts +169 -3
- package/dist/lib/telemetry.js +274 -13
- package/dist/lib/version-notice.d.ts +20 -1
- package/dist/lib/version-notice.js +59 -12
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/skills/testsprite-verify.skill.md +3 -1
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `testsprite project env <verb>` — the per-project environment surface
|
|
3
|
+
* (DEV-1305, Phase 1 of DEV-793).
|
|
4
|
+
*
|
|
5
|
+
* An environment is a named bundle of "how to reach and log in to the app": a
|
|
6
|
+
* URL and a login method. `test run --env <name>`
|
|
7
|
+
* picks one by NAME, which is unique per project server-side; the default
|
|
8
|
+
* environment is what every run without `--env` has always used.
|
|
9
|
+
*
|
|
10
|
+
* An app that only runs on your own machine is named with `--local <port>`
|
|
11
|
+
* instead of `--url` — the same spelling as `project create`. The CLI builds
|
|
12
|
+
* the loopback URL and sends the `originMode: 'local'` marker that lets the
|
|
13
|
+
* server store it:
|
|
14
|
+
*
|
|
15
|
+
* project env create <pid> --name local-dev --local 5173 \
|
|
16
|
+
* --username … --password-file …
|
|
17
|
+
* test run <test-id> --env local-dev --local 5173
|
|
18
|
+
*
|
|
19
|
+
* `--local` on the run is what makes that address reachable from the cloud
|
|
20
|
+
* runner; a run against a loopback environment without it is refused before
|
|
21
|
+
* dispatch. A loopback `--url` is redirected to `--local`; everything the
|
|
22
|
+
* runner can never reach (RFC1918, link-local, the metadata address,
|
|
23
|
+
* non-http(s)) stays rejected.
|
|
24
|
+
*
|
|
25
|
+
* Thin facade over `/api/cli/v1/projects/{id}/env`; the server owns every
|
|
26
|
+
* rule (name uniqueness, default recompute, credential storage). Passwords go
|
|
27
|
+
* up in the request body and are never echoed — not by the server, not by any
|
|
28
|
+
* renderer here.
|
|
29
|
+
*/
|
|
30
|
+
import { randomUUID } from 'node:crypto';
|
|
31
|
+
import { Command } from 'commander';
|
|
32
|
+
import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.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) {
|
|
45
|
+
const globals = command.optsWithGlobals();
|
|
46
|
+
return {
|
|
47
|
+
profile: globals.profile ?? 'default',
|
|
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), 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),
|
|
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),
|
|
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),
|
|
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),
|
|
479
|
+
projectId,
|
|
480
|
+
name,
|
|
481
|
+
idempotencyKey: cmdOpts.idempotencyKey,
|
|
482
|
+
}, deps);
|
|
483
|
+
});
|
|
484
|
+
return env;
|
|
485
|
+
}
|
|
486
|
+
//# sourceMappingURL=project-env.js.map
|
|
@@ -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;
|