@testsprite/testsprite-cli 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +51 -48
  2. package/dist/commands/doctor.js +12 -11
  3. package/dist/commands/project-env.d.ts +11 -1
  4. package/dist/commands/project-env.js +399 -61
  5. package/dist/commands/project-sign-in.d.ts +60 -0
  6. package/dist/commands/project-sign-in.js +289 -0
  7. package/dist/commands/project.d.ts +9 -0
  8. package/dist/commands/project.js +68 -28
  9. package/dist/commands/schedule.d.ts +12 -0
  10. package/dist/commands/schedule.js +175 -5
  11. package/dist/commands/test.d.ts +53 -20
  12. package/dist/commands/test.js +1356 -342
  13. package/dist/commands/testlist.d.ts +10 -5
  14. package/dist/commands/testlist.js +170 -30
  15. package/dist/commands/tunnel.js +11 -5
  16. package/dist/index.js +12 -37
  17. package/dist/lib/client-factory.d.ts +12 -1
  18. package/dist/lib/client-factory.js +14 -4
  19. package/dist/lib/dry-run/samples.js +53 -0
  20. package/dist/lib/environment-tunnel.d.ts +109 -0
  21. package/dist/lib/environment-tunnel.js +465 -0
  22. package/dist/lib/errors.js +12 -1
  23. package/dist/lib/gh-output.js +3 -0
  24. package/dist/lib/http.d.ts +2 -0
  25. package/dist/lib/junit-report.d.ts +11 -7
  26. package/dist/lib/junit-report.js +13 -7
  27. package/dist/lib/local-target.d.ts +13 -3
  28. package/dist/lib/local-target.js +47 -12
  29. package/dist/lib/output.js +15 -1
  30. package/dist/lib/plan-poll.js +3 -4
  31. package/dist/lib/redact.d.ts +38 -0
  32. package/dist/lib/redact.js +140 -0
  33. package/dist/lib/render-error.d.ts +19 -5
  34. package/dist/lib/render-error.js +31 -0
  35. package/dist/lib/runs.types.d.ts +9 -1
  36. package/dist/lib/target-url.js +5 -5
  37. package/dist/lib/telemetry.d.ts +6 -7
  38. package/dist/lib/telemetry.js +11 -4
  39. package/dist/lib/testlist.types.d.ts +1 -0
  40. package/dist/lib/ticker.d.ts +9 -0
  41. package/dist/lib/ticker.js +18 -0
  42. package/dist/lib/tunnel-session.d.ts +3 -4
  43. package/dist/lib/tunnel-session.js +3 -4
  44. package/dist/lib/v3-advisory.js +0 -1
  45. package/dist/vendor/tunnel-client/client.d.ts +15 -8
  46. package/dist/vendor/tunnel-client/client.js +477 -407
  47. package/dist/vendor/tunnel-client/config.d.ts +5 -5
  48. package/dist/vendor/tunnel-client/config.js +5 -5
  49. package/dist/vendor/tunnel-client/index.d.ts +4 -4
  50. package/dist/vendor/tunnel-client/index.js +4 -4
  51. package/dist/vendor/tunnel-client/types.d.ts +19 -34
  52. package/dist/vendor/tunnel-client/types.js +1 -0
  53. package/dist/vendor/tunnel-client/ws-compat.d.ts +13 -3
  54. package/dist/vendor/tunnel-client/ws-compat.js +70 -12
  55. package/dist/version.d.ts +1 -1
  56. package/dist/version.js +1 -1
  57. package/package.json +1 -1
  58. package/skills/testsprite-onboard.skill.md +4 -4
@@ -0,0 +1,60 @@
1
+ import { Command } from 'commander';
2
+ import { type CommonOptions } from '../lib/client-factory.js';
3
+ import { ApiError } from '../lib/errors.js';
4
+ import type { CliProjectEnvironment } from './project-env.js';
5
+ import type { ProjectDeps } from './project.js';
6
+ export interface CliProjectSignInResponse {
7
+ projectId: string;
8
+ environment: CliProjectEnvironment;
9
+ signIn: {
10
+ mode: string;
11
+ account: {
12
+ username: string | null;
13
+ passwordSet: boolean;
14
+ } | null;
15
+ otp: {
16
+ channels: Array<'email' | 'sms'>;
17
+ email: string | null;
18
+ phone: string | null;
19
+ } | null;
20
+ manual: {
21
+ sessionReuseTtlSeconds: number;
22
+ hasValidSession: boolean;
23
+ needsReauth: boolean;
24
+ reason: 'never' | 'expired' | null;
25
+ capturedAt: string | null;
26
+ expiresAt: string | null;
27
+ } | null;
28
+ };
29
+ nextAction: string | null;
30
+ }
31
+ export interface CliProjectSignInSetResponse extends CliProjectSignInResponse {
32
+ changed: boolean;
33
+ }
34
+ export type SignInMode = 'public' | 'account' | 'otp' | 'manual';
35
+ type GetOptions = CommonOptions & {
36
+ projectId: string;
37
+ env?: string;
38
+ };
39
+ type SetOptions = GetOptions & {
40
+ mode?: string;
41
+ username?: string;
42
+ password?: string;
43
+ passwordFile?: string;
44
+ sessionTtl?: string;
45
+ idempotencyKey?: string;
46
+ };
47
+ export declare function signInValidationError(message: string, reason?: string): ApiError;
48
+ export declare function parseSignInMode(raw: string | undefined, flag: string): SignInMode;
49
+ export declare function parseSessionTtl(raw: string): number;
50
+ export declare function validateSignInFlags(mode: SignInMode | undefined, opts: {
51
+ username?: string;
52
+ password?: string;
53
+ passwordFile?: string;
54
+ sessionTtl?: string;
55
+ otpChannel?: string[];
56
+ }, requireAccountPair: boolean): void;
57
+ export declare function runSignInGet(opts: GetOptions, deps?: ProjectDeps): Promise<CliProjectSignInResponse>;
58
+ export declare function runSignInSet(opts: SetOptions, deps?: ProjectDeps): Promise<CliProjectSignInSetResponse>;
59
+ export declare function createProjectSignInCommand(deps?: ProjectDeps): Command;
60
+ export {};
@@ -0,0 +1,289 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { Command } from 'commander';
3
+ import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
4
+ import { resolveProfileName } from '../lib/config.js';
5
+ import { ApiError, InterruptError } from '../lib/errors.js';
6
+ import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
7
+ import { readSecretFileGuarded } from '../lib/secret-file.js';
8
+ import { assertIdempotencyKey } from '../lib/validate.js';
9
+ export function signInValidationError(message, reason = 'invalid_sign_in_flags') {
10
+ return ApiError.fromEnvelope({
11
+ error: {
12
+ code: 'VALIDATION_ERROR',
13
+ message: 'Invalid request.',
14
+ nextAction: message,
15
+ requestId: 'local',
16
+ details: { reason },
17
+ },
18
+ });
19
+ }
20
+ export function parseSignInMode(raw, flag) {
21
+ const aliases = {
22
+ public: 'public',
23
+ account: 'account',
24
+ otp: 'otp',
25
+ manual: 'manual',
26
+ none: 'public',
27
+ credentials: 'account',
28
+ sso: 'manual',
29
+ };
30
+ if (raw === undefined && flag === '--mode')
31
+ throw signInValidationError('--mode is required: public, account or manual (otp can only be chosen with `project env create --sign-in otp`)');
32
+ const key = raw?.toLowerCase();
33
+ const mode = key !== undefined && Object.hasOwn(aliases, key) ? aliases[key] : undefined;
34
+ if (!mode)
35
+ throw signInValidationError(`${flag} must be one of: public, account, otp, manual, none, credentials, sso.`);
36
+ return mode;
37
+ }
38
+ export function parseSessionTtl(raw) {
39
+ if (raw === 'never')
40
+ return -1;
41
+ if (!/^[1-9]\d*$/.test(raw) || Number(raw) > 2_592_000)
42
+ throw signInValidationError('--session-ttl must be an integer from 1 to 2592000 seconds, or never.');
43
+ return Number(raw);
44
+ }
45
+ export function validateSignInFlags(mode, opts, requireAccountPair) {
46
+ if (opts.password !== undefined && opts.passwordFile !== undefined)
47
+ throw signInValidationError('--password and --password-file are mutually exclusive.');
48
+ if (opts.username !== undefined && !opts.username.trim())
49
+ throw signInValidationError('--username must not be empty or whitespace-only.');
50
+ if (opts.password !== undefined && !opts.password.trim())
51
+ throw signInValidationError('--password must not be empty or whitespace-only.');
52
+ if (mode !== undefined && mode !== 'account') {
53
+ if (opts.username !== undefined)
54
+ throw signInValidationError('--username is only valid with account sign-in.');
55
+ if (opts.password !== undefined)
56
+ throw signInValidationError('--password is only valid with account sign-in.');
57
+ if (opts.passwordFile !== undefined)
58
+ throw signInValidationError('--password-file is only valid with account sign-in.');
59
+ }
60
+ if (requireAccountPair && mode === 'account') {
61
+ if (opts.username === undefined)
62
+ throw signInValidationError('--username is required with --sign-in account.');
63
+ if (opts.password === undefined && opts.passwordFile === undefined)
64
+ throw signInValidationError('--password or --password-file is required with --sign-in account.');
65
+ }
66
+ if (opts.sessionTtl !== undefined && mode !== 'manual')
67
+ throw signInValidationError('--session-ttl is only valid with manual sign-in.');
68
+ if (opts.otpChannel !== undefined && mode !== 'otp')
69
+ throw signInValidationError('--otp-channel is only valid with --sign-in otp.');
70
+ if (opts.sessionTtl !== undefined)
71
+ parseSessionTtl(opts.sessionTtl);
72
+ }
73
+ function commonOptions(command, env) {
74
+ const globals = command.optsWithGlobals();
75
+ return {
76
+ profile: resolveProfileName(globals.profile, env),
77
+ output: resolveOutputMode(globals.output),
78
+ endpointUrl: globals.endpointUrl,
79
+ debug: globals.debug ?? false,
80
+ verbose: globals.verbose ?? false,
81
+ dryRun: globals.dryRun ?? false,
82
+ requestTimeoutMs: parseRequestTimeoutFlag(globals.requestTimeout),
83
+ };
84
+ }
85
+ function stderrOf(deps) {
86
+ return deps.stderr ?? (line => process.stderr.write(`${line}\n`));
87
+ }
88
+ function pathFor(projectId) {
89
+ return `/projects/${encodeURIComponent(projectId)}/sign-in`;
90
+ }
91
+ function clientFor(opts, deps) {
92
+ return makeHttpClient(opts, {
93
+ env: deps.env,
94
+ credentialsPath: deps.credentialsPath,
95
+ fetchImpl: deps.fetchImpl,
96
+ stderr: deps.stderr,
97
+ });
98
+ }
99
+ function ttlText(seconds) {
100
+ if (seconds === -1)
101
+ return 'never expires';
102
+ if (seconds % 86400 === 0)
103
+ return `${seconds / 86400}d`;
104
+ if (seconds % 3600 === 0)
105
+ return `${seconds / 3600}h`;
106
+ if (seconds % 60 === 0)
107
+ return `${seconds / 60}m`;
108
+ return `${seconds}s`;
109
+ }
110
+ function renderText(result) {
111
+ const { environment, signIn } = result;
112
+ const labels = {
113
+ public: 'No sign-in',
114
+ account: 'Test account credentials',
115
+ otp: 'OTP (one-time password) login',
116
+ manual: 'SSO: log in once in a live browser, runs reuse the session',
117
+ };
118
+ const lines = [
119
+ `Environment ${environment.name}${environment.isDefault ? ' (default)' : ''} — ${environment.url}`,
120
+ `Sign-in ${signIn.mode}${labels[signIn.mode] ? ` — ${labels[signIn.mode]}` : ''}`,
121
+ ];
122
+ if (signIn.mode === 'account' && signIn.account)
123
+ lines.push(`Username ${signIn.account.username}`, `Password ${signIn.account.passwordSet ? 'set' : 'not set'}`);
124
+ if (signIn.mode === 'otp' && signIn.otp) {
125
+ lines.push(`Channels ${signIn.otp.channels.join(', ')}`);
126
+ if (signIn.otp.email)
127
+ lines.push(`Inbox ${signIn.otp.email}`);
128
+ if (signIn.otp.phone)
129
+ lines.push(`Phone ${signIn.otp.phone}`);
130
+ }
131
+ if (signIn.mode === 'manual') {
132
+ const manual = signIn.manual;
133
+ let session = 'none captured yet — runs will NOT be signed in until someone logs in once';
134
+ if (manual?.hasValidSession) {
135
+ session =
136
+ manual.expiresAt && manual.sessionReuseTtlSeconds !== -1
137
+ ? `valid until ${manual.expiresAt}`
138
+ : 'valid (never expires)';
139
+ if (manual.capturedAt)
140
+ session += ` — captured ${manual.capturedAt}`;
141
+ }
142
+ else if (manual?.reason === 'expired') {
143
+ session = `expired ${manual.expiresAt ?? '(expiration unknown)'} — runs will NOT be signed in until someone logs in again`;
144
+ }
145
+ lines.push(`Session ${session}`);
146
+ if (manual)
147
+ lines.push(`Session TTL ${ttlText(manual.sessionReuseTtlSeconds)}`);
148
+ }
149
+ if (result.nextAction)
150
+ lines.push(`Next ${result.nextAction}`);
151
+ return lines.join('\n');
152
+ }
153
+ function dryRunResponse(projectId, mode = 'public') {
154
+ return {
155
+ projectId,
156
+ environment: {
157
+ id: 'env_dryrun',
158
+ name: 'default',
159
+ url: 'https://app.example.com',
160
+ isDefault: true,
161
+ authMode: mode,
162
+ hasCredentials: mode === 'account',
163
+ username: mode === 'account' ? 'qa@example.com' : null,
164
+ enableOtp: mode === 'otp',
165
+ updatedAt: '2026-09-25T00:00:00.000Z',
166
+ },
167
+ signIn: {
168
+ mode,
169
+ account: mode === 'account' ? { username: 'qa@example.com', passwordSet: true } : null,
170
+ otp: mode === 'otp' ? { channels: ['email'], email: 'dryrun@inbox.example', phone: null } : null,
171
+ manual: mode === 'manual'
172
+ ? {
173
+ sessionReuseTtlSeconds: 3600,
174
+ hasValidSession: false,
175
+ needsReauth: true,
176
+ reason: 'never',
177
+ capturedAt: null,
178
+ expiresAt: null,
179
+ }
180
+ : null,
181
+ },
182
+ nextAction: mode === 'manual' ? 'Log in once in the Portal.' : null,
183
+ };
184
+ }
185
+ function redactSecret(value, secret) {
186
+ if (typeof value === 'string')
187
+ return value.split(secret).join('[REDACTED]');
188
+ if (Array.isArray(value))
189
+ return value.map(item => redactSecret(item, secret));
190
+ if (value !== null && typeof value === 'object') {
191
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [
192
+ key.split(secret).join('[REDACTED]'),
193
+ redactSecret(item, secret),
194
+ ]));
195
+ }
196
+ return value;
197
+ }
198
+ export async function runSignInGet(opts, deps = {}) {
199
+ if (opts.env !== undefined && !opts.env.trim())
200
+ throw signInValidationError('--env must not be empty or whitespace-only.');
201
+ const out = new Output(opts.output, { stdout: deps.stdout, stderr: deps.stderr });
202
+ if (opts.dryRun) {
203
+ emitDryRunBanner(stderrOf(deps));
204
+ const sample = dryRunResponse(opts.projectId);
205
+ out.print(sample, data => renderText(data));
206
+ return sample;
207
+ }
208
+ const result = await clientFor(opts, deps).get(pathFor(opts.projectId), opts.env === undefined ? {} : { query: { environment: opts.env } });
209
+ out.print(result, data => renderText(data));
210
+ return result;
211
+ }
212
+ export async function runSignInSet(opts, deps = {}) {
213
+ if (opts.env !== undefined && !opts.env.trim())
214
+ throw signInValidationError('--env must not be empty or whitespace-only.');
215
+ const mode = parseSignInMode(opts.mode, '--mode');
216
+ validateSignInFlags(mode, opts, false);
217
+ assertIdempotencyKey(opts.idempotencyKey);
218
+ const out = new Output(opts.output, { stdout: deps.stdout, stderr: deps.stderr });
219
+ const stderr = stderrOf(deps);
220
+ const key = opts.idempotencyKey ?? `cli-proj-signin-set-${randomUUID()}`;
221
+ if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug))
222
+ stderr(`idempotency-key: ${key}`);
223
+ if (opts.dryRun) {
224
+ emitDryRunBanner(stderr);
225
+ const sample = { ...dryRunResponse(opts.projectId, mode), changed: mode !== 'otp' };
226
+ out.print(sample, data => renderText(data));
227
+ return sample;
228
+ }
229
+ const password = opts.passwordFile === undefined
230
+ ? opts.password
231
+ : readSecretFileGuarded('password-file', opts.passwordFile);
232
+ const body = { mode };
233
+ if (opts.env !== undefined)
234
+ body.environment = opts.env;
235
+ if (opts.username !== undefined)
236
+ body.username = opts.username;
237
+ if (password !== undefined)
238
+ body.password = password;
239
+ if (opts.sessionTtl !== undefined)
240
+ body.sessionReuseTtlSeconds = parseSessionTtl(opts.sessionTtl);
241
+ try {
242
+ const result = await clientFor(opts, deps).put(pathFor(opts.projectId), { body, headers: { 'idempotency-key': key } });
243
+ out.print(result, data => renderText(data));
244
+ return result;
245
+ }
246
+ catch (err) {
247
+ if (err instanceof InterruptError)
248
+ throw err;
249
+ if (err instanceof ApiError && password) {
250
+ throw new ApiError({
251
+ code: err.code,
252
+ message: redactSecret(err.message, password),
253
+ nextAction: redactSecret(err.nextAction, password),
254
+ requestId: err.requestId,
255
+ details: redactSecret(err.details, password),
256
+ }, err.httpStatus, err.retryAfterMs);
257
+ }
258
+ if (err instanceof Error && password)
259
+ err.message = redactSecret(err.message, password);
260
+ throw err;
261
+ }
262
+ }
263
+ export function createProjectSignInCommand(deps = {}) {
264
+ const group = new Command('sign-in').description('Inspect or change how an environment signs in to the app under test.');
265
+ group
266
+ .command('get <project-id>')
267
+ .description('Show the environment sign-in mode, credentials status, OTP channels, or SSO session.')
268
+ .option('--env <name>', 'environment name (defaults to the project default)')
269
+ .addHelpText('after', GLOBAL_OPTS_HINT)
270
+ .action(async (projectId, flags, command) => {
271
+ await runSignInGet({ ...commonOptions(command, deps.env), projectId, env: flags.env }, deps);
272
+ });
273
+ group
274
+ .command('set <project-id>')
275
+ .description('Set the sign-in mode; choose OTP when creating a new environment.')
276
+ .option('--mode <mode>', 'required: public, account, otp, or manual (aliases: none, credentials, sso)')
277
+ .option('--env <name>', 'environment name (defaults to the project default)')
278
+ .option('--username <user>', 'test-account username (account only)')
279
+ .option('--password <pw>', 'test-account password (prefer --password-file; account only)')
280
+ .option('--password-file <path>', 'read the test-account password from a file (account only)')
281
+ .option('--session-ttl <seconds|never>', 'SSO session reuse lifetime: 1–2592000 seconds or never (manual only)')
282
+ .option('--idempotency-key <token>', 'opaque idempotency token. Defaults to a UUIDv4 minted per invocation.')
283
+ .addHelpText('after', GLOBAL_OPTS_HINT)
284
+ .action(async (projectId, flags, command) => {
285
+ await runSignInSet({ ...commonOptions(command, deps.env), projectId, ...flags }, deps);
286
+ });
287
+ return group;
288
+ }
289
+ //# sourceMappingURL=project-sign-in.js.map
@@ -43,6 +43,9 @@ export interface CliProject {
43
43
  * (see the `project create --type backend` note in CLAUDE.md).
44
44
  */
45
45
  targetUrl?: string | null;
46
+ /** Absent on older servers, V2 projects, or when the environment read failed. */
47
+ defaultEnvironment?: string | null;
48
+ environmentCount?: number;
46
49
  /** Present only when the stored project target is local to the developer machine. */
47
50
  originMode?: 'local';
48
51
  /**
@@ -158,6 +161,12 @@ export interface CliUpdateProjectResponse {
158
161
  updatedFields?: string[];
159
162
  /** Absent-safe: not guaranteed on every backend response. */
160
163
  updatedAt?: string;
164
+ /** Present on servers that report which default environment was edited. */
165
+ environment?: {
166
+ name: string;
167
+ isDefault: true;
168
+ };
169
+ effects?: string[];
161
170
  }
162
171
  /** Resolve the updated project's id regardless of which field name the backend used. */
163
172
  export declare function resolveUpdatedProjectId(r: CliUpdateProjectResponse): string | undefined;
@@ -2,12 +2,12 @@ import { randomUUID } from 'node:crypto';
2
2
  import { createReadStream, readFileSync, statSync } from 'node:fs';
3
3
  import { basename, extname } from 'node:path';
4
4
  import { Readable } from 'node:stream';
5
- import { Command } from 'commander';
5
+ import { Command, Option } from 'commander';
6
6
  import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, resolveRequestTimeoutMs, } from '../lib/client-factory.js';
7
7
  import { resolveProfileName } from '../lib/config.js';
8
8
  import { ApiError, InterruptError, RequestTimeoutError } from '../lib/errors.js';
9
9
  import { globalShutdown } from '../lib/interrupt.js';
10
- import { assertStoredLocalTargetListening, buildLocalTargetUrl, DEFAULT_LOCAL_HOST, parseStoredLocalTarget, } from '../lib/local-target.js';
10
+ import { assertStoredLocalTargetListening, buildLocalTargetUrl, parseStoredLocalTarget, } from '../lib/local-target.js';
11
11
  import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
12
12
  import { readSecretFileGuarded } from '../lib/secret-file.js';
13
13
  import { assertNotLocal } from '../lib/target-url.js';
@@ -15,6 +15,7 @@ import { renderTextTable, resolveTextColumns } from '../lib/text-table.js';
15
15
  import { assertIdempotencyKey } from '../lib/validate.js';
16
16
  import { fetchSinglePage, paginate, validatePaginationFlags, } from '../lib/pagination.js';
17
17
  import { createProjectEnvCommand } from './project-env.js';
18
+ import { createProjectSignInCommand } from './project-sign-in.js';
18
19
  /** Attribute names are interpolated into CSS selectors by the engine — keep them plain. */
19
20
  const TEST_ID_ATTRIBUTE_NAME = /^[A-Za-z_][\w.:-]*$/;
20
21
  const TEST_ID_ATTRIBUTES_MAX = 10;
@@ -103,6 +104,9 @@ export async function runCreate(opts, deps = {}) {
103
104
  if (opts.password !== undefined && opts.password.trim().length === 0) {
104
105
  throw localValidationError('--password must not be empty or whitespace-only');
105
106
  }
107
+ if (opts.password !== undefined && opts.passwordFile !== undefined) {
108
+ stderr('Warning: --password takes precedence; --password-file was ignored.');
109
+ }
106
110
  if (opts.name.length > 200) {
107
111
  throw localValidationError('--name must be at most 200 characters');
108
112
  }
@@ -120,12 +124,15 @@ export async function runCreate(opts, deps = {}) {
120
124
  localHost: opts.localHost,
121
125
  url: opts.targetUrl,
122
126
  });
123
- const targetUrl = localTarget
124
- ? buildLocalTargetUrl(localTarget.host, localTarget.port)
125
- : opts.targetUrl;
126
- // P2-7: guard --url against localhost/RFC1918/non-http(s) (same rules as
127
- // `test create --target-url`). Applies to both FE (required) and BE (optional).
128
- if (opts.targetUrl !== undefined) {
127
+ // A loopback --url is the same stored target as --local, so it gets the same
128
+ // refusal before anything is sent.
129
+ if (localTarget && opts.type !== 'frontend') {
130
+ throw localValidationError('a --url on this machine (localhost, 127.0.0.1, [::1]) is frontend-only; give a backend project a public URL');
131
+ }
132
+ const targetUrl = opts.targetUrl ??
133
+ (localTarget ? buildLocalTargetUrl(localTarget.host, localTarget.port) : undefined);
134
+ // Keep the existing public-address guard for targets a loopback tunnel cannot reach.
135
+ if (opts.targetUrl !== undefined && !localTarget) {
129
136
  assertNotLocal(opts.targetUrl, {
130
137
  field: 'url',
131
138
  helpCommand: 'testsprite project create',
@@ -265,23 +272,22 @@ export async function runUpdate(opts, deps = {}) {
265
272
  if (opts.password !== undefined && opts.password.trim().length === 0) {
266
273
  throw localValidationError('--password must not be empty or whitespace-only');
267
274
  }
275
+ if (opts.password !== undefined && opts.passwordFile !== undefined) {
276
+ stderr('Warning: --password takes precedence; --password-file was ignored.');
277
+ }
268
278
  if (opts.name !== undefined && opts.name.length > 200) {
269
279
  throw localValidationError('--name must be at most 200 characters');
270
280
  }
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.
281
+ // A loopback URL and --local shorthand use the same stored-target wire shape.
282
+ // The server owns project-type validation on update.
276
283
  const localTarget = parseStoredLocalTarget({
277
284
  local: opts.local,
278
285
  localHost: opts.localHost,
279
286
  url: opts.targetUrl,
280
287
  });
281
- const targetUrl = localTarget
282
- ? buildLocalTargetUrl(localTarget.host, localTarget.port)
283
- : opts.targetUrl;
284
- if (opts.targetUrl !== undefined) {
288
+ const targetUrl = opts.targetUrl ??
289
+ (localTarget ? buildLocalTargetUrl(localTarget.host, localTarget.port) : undefined);
290
+ if (opts.targetUrl !== undefined && !localTarget) {
285
291
  assertNotLocal(opts.targetUrl, {
286
292
  field: 'url',
287
293
  helpCommand: 'testsprite project update',
@@ -971,10 +977,10 @@ export function createProjectCommand(deps = {}) {
971
977
  .description('Create a new project')
972
978
  .option('--type <frontend|backend>', 'project type (required)')
973
979
  .option('--name <name>', 'project name (required)')
974
- .option('--url <url>', 'target URL (required for frontend unless --local is used; also required for backend on the V3 execution ' +
980
+ .option('--url <url>', 'target URL (public http/https or a loopback http origin with an explicit port; required for frontend unless --local is used; also required for backend on the V3 execution ' +
975
981
  'path — see `auth status` for your routing)')
976
- .option('--local <port>', 'create a frontend project for an app on this machine (1-65535; excludes --url)')
977
- .option('--local-host <host>', 'loopback host: localhost, 127.0.0.1 (default), or ::1; requires --local')
982
+ .option('--local <port>', 'shorthand for --url http://localhost:<port> (1-65535; excludes --url; runs open a tunnel automatically)')
983
+ .addOption(new Option('--local-host <host>', 'deprecated loopback host override; requires --local').hideHelp())
978
984
  .option('--skip-preflight', 'skip the local TCP listener check before project creation')
979
985
  .option('--description <text>', 'not supported — projects have no description (test-level descriptions are set on `test create`)')
980
986
  .option('--username <user>', 'optional auth username')
@@ -1017,9 +1023,9 @@ export function createProjectCommand(deps = {}) {
1017
1023
  .command('update <project-id>')
1018
1024
  .description('Update project metadata')
1019
1025
  .option('--name <name>', 'new project name')
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')
1026
+ .option('--url <url>', 'new target URL (public http/https, or a loopback http origin with an explicit port)')
1027
+ .option('--local <port>', 'shorthand for --url http://localhost:<port> (1-65535; excludes --url; frontend only)')
1028
+ .addOption(new Option('--local-host <host>', 'deprecated loopback host override; requires --local').hideHelp())
1023
1029
  .option('--skip-preflight', 'skip the local TCP listener check before the update')
1024
1030
  .option('--username <user>', 'new auth username')
1025
1031
  .option('--password <pw>', 'new auth password')
@@ -1178,6 +1184,7 @@ export function createProjectCommand(deps = {}) {
1178
1184
  // `project env <verb>` — the per-project environment surface (credentials,
1179
1185
  // URL, default). Own module; `deps` threaded so tests inject.
1180
1186
  project.addCommand(createProjectEnvCommand(deps));
1187
+ project.addCommand(createProjectSignInCommand(deps));
1181
1188
  return project;
1182
1189
  }
1183
1190
  function parseFlag(raw, flagName) {
@@ -1252,7 +1259,21 @@ const PROJECT_LIST_COLUMNS = [
1252
1259
  width: rows => Math.max(3, ...rows.map(project => renderProjectUrl(project).length)),
1253
1260
  render: renderProjectUrl,
1254
1261
  },
1255
- { header: 'CREATED', width: 0, render: project => project.createdAt },
1262
+ {
1263
+ header: 'CREATED',
1264
+ width: rows => Math.max(7, ...rows.map(project => project.createdAt.length)),
1265
+ render: project => project.createdAt,
1266
+ },
1267
+ {
1268
+ header: 'DEFAULT ENV',
1269
+ width: rows => Math.max(11, ...rows.map(project => (project.defaultEnvironment ?? '-').length)),
1270
+ render: project => project.defaultEnvironment ?? '-',
1271
+ },
1272
+ {
1273
+ header: 'ENVS',
1274
+ width: 4,
1275
+ render: project => project.environmentCount?.toString() ?? '-',
1276
+ },
1256
1277
  ];
1257
1278
  function renderProjectUrl(project) {
1258
1279
  const url = project.targetUrl ?? '';
@@ -1300,6 +1321,13 @@ function renderProjectText(p) {
1300
1321
  if (p.orgId !== undefined) {
1301
1322
  lines.push(`org: ${p.orgName ?? '(name unknown)'} (${p.orgId})`);
1302
1323
  }
1324
+ if ('defaultEnvironment' in p) {
1325
+ lines.push(`defaultEnv: ${p.defaultEnvironment ?? '-'}`);
1326
+ }
1327
+ if ('environmentCount' in p) {
1328
+ const count = p.environmentCount;
1329
+ lines.push(`envs: ${count}${count !== undefined && count > 0 ? ` (list with: testsprite project env list ${p.id})` : ''}`);
1330
+ }
1303
1331
  // Presence, not truthiness — see the `targetUrl` docstring on `CliProject`.
1304
1332
  // `'targetUrl' in p` distinguishes "the backend answered 'no URL'" (render the
1305
1333
  // hint) from "this endpoint doesn't report it" (say nothing).
@@ -1338,8 +1366,7 @@ function renderCreateProjectText(p, localTarget) {
1338
1366
  if (localTarget) {
1339
1367
  const projectId = resolveCreatedProjectId(p) ?? '<project-id>';
1340
1368
  const url = buildLocalTargetUrl(localTarget.host, localTarget.port);
1341
- const hostFlag = localTarget.host === DEFAULT_LOCAL_HOST ? '' : ` --local-host ${localTarget.host}`;
1342
- lines.push(`Local project: TestSprite will reach ${url} only through a tunnel from this machine.`, 'Next: write a plan and run it locally:', ` In plan.json, set projectId to ${projectId}.`, ` testsprite test create --project ${projectId} --plan-from plan.json`, ` testsprite test run <test-id> --local ${localTarget.port}${hostFlag}`, `Portal runs of this project stay blocked (free) until you set a public URL with: testsprite project update ${projectId} --url https://...`);
1369
+ lines.push(`Local project: TestSprite will reach ${url} only through a tunnel from this machine.`, 'Next: write a plan and run it locally:', ` In plan.json, set projectId to ${projectId}.`, ` testsprite test create --project ${projectId} --plan-from plan.json`, ' testsprite test run <test-id>', `Portal runs of this project stay blocked (free) until you set a public URL with: testsprite project update ${projectId} --url https://...`);
1343
1370
  }
1344
1371
  return lines.join('\n');
1345
1372
  }
@@ -1350,10 +1377,23 @@ function renderUpdateText(r, localTarget) {
1350
1377
  ];
1351
1378
  if (r.updatedAt !== undefined)
1352
1379
  lines.push(`updatedAt: ${r.updatedAt}`);
1380
+ if (r.environment !== undefined) {
1381
+ lines.push(`environment: ${r.environment.name} (default)`);
1382
+ const labels = {
1383
+ 'environment.url': 'Environment URL updated',
1384
+ 'environment.credentials': 'Environment credentials updated',
1385
+ 'project.name': 'Project name updated',
1386
+ 'project.instruction': 'Project instruction updated',
1387
+ 'project.testIdAttributes': 'Project test ID attributes updated',
1388
+ };
1389
+ for (const effect of r.effects ?? []) {
1390
+ if (labels[effect])
1391
+ lines.push(`effect: ${labels[effect]}`);
1392
+ }
1393
+ }
1353
1394
  if (localTarget) {
1354
1395
  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}`);
1396
+ lines.push(`Local project: TestSprite will reach ${url} only through a tunnel from this machine.`, 'Run its tests with: testsprite test run <test-id> (the CLI opens a tunnel automatically).');
1357
1397
  }
1358
1398
  return lines.join('\n');
1359
1399
  }
@@ -10,6 +10,8 @@ export interface CliSchedule {
10
10
  targetType: 'project' | 'testList';
11
11
  /** Project id when `targetType` is `project`, else the test-list id. */
12
12
  targetId: string | null;
13
+ environment?: string | null;
14
+ environmentMode?: 'inherit' | 'pinned' | null;
13
15
  cron: string | null;
14
16
  timezone: string | null;
15
17
  startAt: string | null;
@@ -46,6 +48,7 @@ export interface CreateOptions extends CommonOptions {
46
48
  name?: string;
47
49
  targetType?: string;
48
50
  targetId?: string;
51
+ env?: string;
49
52
  cron?: string;
50
53
  timezone?: string;
51
54
  start?: string;
@@ -64,10 +67,19 @@ export interface CliCreateScheduleResponse {
64
67
  * this side knows how often the cron fires; neither knows both.
65
68
  */
66
69
  estimatedCreditsPerRun?: number | null;
70
+ /**
71
+ * Echoed back by a server that understands schedule environments — absent
72
+ * entirely on one that doesn't. That absence (not a falsy value) is what
73
+ * `runCreate` uses to detect an old server and refuse instead of confirming
74
+ * a pin that was never applied.
75
+ */
76
+ environment?: string | null;
77
+ environmentMode?: 'inherit' | 'pinned' | null;
67
78
  }
68
79
  export interface UpdateOptions extends CommonOptions {
69
80
  scheduleId: string;
70
81
  name?: string;
82
+ env?: string;
71
83
  cron?: string;
72
84
  timezone?: string;
73
85
  start?: string;