@testsprite/testsprite-cli 0.13.0 → 0.15.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 +54 -49
- package/dist/commands/ci.d.ts +66 -17
- package/dist/commands/ci.js +466 -104
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.js +62 -20
- package/dist/commands/init.js +17 -3
- package/dist/commands/project-env.d.ts +11 -1
- package/dist/commands/project-env.js +399 -61
- package/dist/commands/project-sign-in.d.ts +60 -0
- package/dist/commands/project-sign-in.js +289 -0
- package/dist/commands/project.d.ts +9 -0
- package/dist/commands/project.js +82 -28
- package/dist/commands/schedule.d.ts +12 -0
- package/dist/commands/schedule.js +175 -5
- package/dist/commands/test.d.ts +126 -30
- package/dist/commands/test.js +1928 -447
- package/dist/commands/testlist.d.ts +10 -5
- package/dist/commands/testlist.js +170 -30
- package/dist/commands/tunnel.js +11 -5
- package/dist/index.js +17 -38
- package/dist/lib/agent-targets.d.ts +8 -3
- package/dist/lib/agent-targets.js +15 -4
- package/dist/lib/ci-run.d.ts +11 -0
- package/dist/lib/ci-run.js +34 -0
- package/dist/lib/client-factory.d.ts +35 -1
- package/dist/lib/client-factory.js +21 -10
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.js +1 -1
- package/dist/lib/credentials.d.ts +0 -1
- package/dist/lib/credentials.js +51 -14
- package/dist/lib/dry-run/samples.js +95 -1
- package/dist/lib/environment-tunnel.d.ts +109 -0
- package/dist/lib/environment-tunnel.js +465 -0
- package/dist/lib/errors.js +12 -1
- package/dist/lib/first-suite-hint.d.ts +55 -0
- package/dist/lib/first-suite-hint.js +101 -0
- package/dist/lib/gh-output.d.ts +62 -4
- package/dist/lib/gh-output.js +152 -7
- package/dist/lib/github-context.d.ts +21 -0
- package/dist/lib/github-context.js +153 -0
- package/dist/lib/http.d.ts +12 -1
- package/dist/lib/http.js +9 -1
- package/dist/lib/junit-report.d.ts +11 -7
- package/dist/lib/junit-report.js +13 -7
- package/dist/lib/local-target.d.ts +13 -3
- package/dist/lib/local-target.js +47 -12
- package/dist/lib/output.js +15 -1
- package/dist/lib/plan-poll.js +3 -4
- package/dist/lib/plans.types.d.ts +1 -1
- package/dist/lib/redact.d.ts +38 -0
- package/dist/lib/redact.js +140 -0
- package/dist/lib/render-error.d.ts +19 -5
- package/dist/lib/render-error.js +31 -0
- package/dist/lib/response-schemas.d.ts +5 -1
- package/dist/lib/response-schemas.js +54 -0
- package/dist/lib/runs.types.d.ts +115 -1
- package/dist/lib/target-url.js +5 -5
- package/dist/lib/telemetry.d.ts +31 -8
- package/dist/lib/telemetry.js +55 -7
- package/dist/lib/testlist.types.d.ts +1 -0
- package/dist/lib/ticker.d.ts +9 -0
- package/dist/lib/ticker.js +18 -0
- package/dist/lib/tunnel-session.d.ts +3 -4
- package/dist/lib/tunnel-session.js +3 -4
- package/dist/lib/v3-advisory.js +0 -1
- package/dist/vendor/tunnel-client/client.d.ts +15 -8
- package/dist/vendor/tunnel-client/client.js +477 -407
- package/dist/vendor/tunnel-client/config.d.ts +5 -5
- package/dist/vendor/tunnel-client/config.js +5 -5
- package/dist/vendor/tunnel-client/index.d.ts +4 -4
- package/dist/vendor/tunnel-client/index.js +4 -4
- package/dist/vendor/tunnel-client/types.d.ts +19 -34
- package/dist/vendor/tunnel-client/types.js +1 -0
- package/dist/vendor/tunnel-client/ws-compat.d.ts +13 -3
- package/dist/vendor/tunnel-client/ws-compat.js +70 -12
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schemas/plan.schema.json +2 -2
- package/skills/testsprite-ci.skill.md +154 -0
- 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;
|
package/dist/commands/project.js
CHANGED
|
@@ -2,12 +2,13 @@ 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
|
+
import { firstSuiteNextSteps } from '../lib/first-suite-hint.js';
|
|
9
10
|
import { globalShutdown } from '../lib/interrupt.js';
|
|
10
|
-
import { assertStoredLocalTargetListening, buildLocalTargetUrl,
|
|
11
|
+
import { assertStoredLocalTargetListening, buildLocalTargetUrl, parseStoredLocalTarget, } from '../lib/local-target.js';
|
|
11
12
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
12
13
|
import { readSecretFileGuarded } from '../lib/secret-file.js';
|
|
13
14
|
import { assertNotLocal } from '../lib/target-url.js';
|
|
@@ -15,6 +16,7 @@ import { renderTextTable, resolveTextColumns } from '../lib/text-table.js';
|
|
|
15
16
|
import { assertIdempotencyKey } from '../lib/validate.js';
|
|
16
17
|
import { fetchSinglePage, paginate, validatePaginationFlags, } from '../lib/pagination.js';
|
|
17
18
|
import { createProjectEnvCommand } from './project-env.js';
|
|
19
|
+
import { createProjectSignInCommand } from './project-sign-in.js';
|
|
18
20
|
/** Attribute names are interpolated into CSS selectors by the engine — keep them plain. */
|
|
19
21
|
const TEST_ID_ATTRIBUTE_NAME = /^[A-Za-z_][\w.:-]*$/;
|
|
20
22
|
const TEST_ID_ATTRIBUTES_MAX = 10;
|
|
@@ -103,6 +105,9 @@ export async function runCreate(opts, deps = {}) {
|
|
|
103
105
|
if (opts.password !== undefined && opts.password.trim().length === 0) {
|
|
104
106
|
throw localValidationError('--password must not be empty or whitespace-only');
|
|
105
107
|
}
|
|
108
|
+
if (opts.password !== undefined && opts.passwordFile !== undefined) {
|
|
109
|
+
stderr('Warning: --password takes precedence; --password-file was ignored.');
|
|
110
|
+
}
|
|
106
111
|
if (opts.name.length > 200) {
|
|
107
112
|
throw localValidationError('--name must be at most 200 characters');
|
|
108
113
|
}
|
|
@@ -120,12 +125,15 @@ export async function runCreate(opts, deps = {}) {
|
|
|
120
125
|
localHost: opts.localHost,
|
|
121
126
|
url: opts.targetUrl,
|
|
122
127
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
// A loopback --url is the same stored target as --local, so it gets the same
|
|
129
|
+
// refusal before anything is sent.
|
|
130
|
+
if (localTarget && opts.type !== 'frontend') {
|
|
131
|
+
throw localValidationError('a --url on this machine (localhost, 127.0.0.1, [::1]) is frontend-only; give a backend project a public URL');
|
|
132
|
+
}
|
|
133
|
+
const targetUrl = opts.targetUrl ??
|
|
134
|
+
(localTarget ? buildLocalTargetUrl(localTarget.host, localTarget.port) : undefined);
|
|
135
|
+
// Keep the existing public-address guard for targets a loopback tunnel cannot reach.
|
|
136
|
+
if (opts.targetUrl !== undefined && !localTarget) {
|
|
129
137
|
assertNotLocal(opts.targetUrl, {
|
|
130
138
|
field: 'url',
|
|
131
139
|
helpCommand: 'testsprite project create',
|
|
@@ -245,6 +253,15 @@ export async function runCreate(opts, deps = {}) {
|
|
|
245
253
|
`no-target-resolvable until one is set. Fix: testsprite project update ` +
|
|
246
254
|
`${resolvedId ?? '<project-id>'} --url <url>`);
|
|
247
255
|
}
|
|
256
|
+
// A new project with no tests is where activation stalls. Point at
|
|
257
|
+
// the generate -> accept path (text mode only: a JSON caller already holds
|
|
258
|
+
// the id; --dry-run returned above, its id is the canned sample). Printed
|
|
259
|
+
// after the URL advisory so a fix-first warning is never buried below it.
|
|
260
|
+
// A --local project is skipped: its record above already ends with the
|
|
261
|
+
// hand-written-plan next steps.
|
|
262
|
+
if (opts.output !== 'json' && resolvedId !== undefined && !localTarget) {
|
|
263
|
+
stderr(firstSuiteNextSteps(resolvedId, opts.type));
|
|
264
|
+
}
|
|
248
265
|
return created;
|
|
249
266
|
}
|
|
250
267
|
/** Resolve the updated project's id regardless of which field name the backend used. */
|
|
@@ -265,23 +282,22 @@ export async function runUpdate(opts, deps = {}) {
|
|
|
265
282
|
if (opts.password !== undefined && opts.password.trim().length === 0) {
|
|
266
283
|
throw localValidationError('--password must not be empty or whitespace-only');
|
|
267
284
|
}
|
|
285
|
+
if (opts.password !== undefined && opts.passwordFile !== undefined) {
|
|
286
|
+
stderr('Warning: --password takes precedence; --password-file was ignored.');
|
|
287
|
+
}
|
|
268
288
|
if (opts.name !== undefined && opts.name.length > 200) {
|
|
269
289
|
throw localValidationError('--name must be at most 200 characters');
|
|
270
290
|
}
|
|
271
|
-
//
|
|
272
|
-
//
|
|
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.
|
|
291
|
+
// A loopback URL and --local shorthand use the same stored-target wire shape.
|
|
292
|
+
// The server owns project-type validation on update.
|
|
276
293
|
const localTarget = parseStoredLocalTarget({
|
|
277
294
|
local: opts.local,
|
|
278
295
|
localHost: opts.localHost,
|
|
279
296
|
url: opts.targetUrl,
|
|
280
297
|
});
|
|
281
|
-
const targetUrl =
|
|
282
|
-
? buildLocalTargetUrl(localTarget.host, localTarget.port)
|
|
283
|
-
|
|
284
|
-
if (opts.targetUrl !== undefined) {
|
|
298
|
+
const targetUrl = opts.targetUrl ??
|
|
299
|
+
(localTarget ? buildLocalTargetUrl(localTarget.host, localTarget.port) : undefined);
|
|
300
|
+
if (opts.targetUrl !== undefined && !localTarget) {
|
|
285
301
|
assertNotLocal(opts.targetUrl, {
|
|
286
302
|
field: 'url',
|
|
287
303
|
helpCommand: 'testsprite project update',
|
|
@@ -971,10 +987,10 @@ export function createProjectCommand(deps = {}) {
|
|
|
971
987
|
.description('Create a new project')
|
|
972
988
|
.option('--type <frontend|backend>', 'project type (required)')
|
|
973
989
|
.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 ' +
|
|
990
|
+
.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
991
|
'path — see `auth status` for your routing)')
|
|
976
|
-
.option('--local <port>', '
|
|
977
|
-
.
|
|
992
|
+
.option('--local <port>', 'shorthand for --url http://localhost:<port> (1-65535; excludes --url; runs open a tunnel automatically)')
|
|
993
|
+
.addOption(new Option('--local-host <host>', 'deprecated loopback host override; requires --local').hideHelp())
|
|
978
994
|
.option('--skip-preflight', 'skip the local TCP listener check before project creation')
|
|
979
995
|
.option('--description <text>', 'not supported — projects have no description (test-level descriptions are set on `test create`)')
|
|
980
996
|
.option('--username <user>', 'optional auth username')
|
|
@@ -1017,9 +1033,9 @@ export function createProjectCommand(deps = {}) {
|
|
|
1017
1033
|
.command('update <project-id>')
|
|
1018
1034
|
.description('Update project metadata')
|
|
1019
1035
|
.option('--name <name>', 'new project name')
|
|
1020
|
-
.option('--url <url>', 'new target URL (public
|
|
1021
|
-
.option('--local <port>', '
|
|
1022
|
-
.
|
|
1036
|
+
.option('--url <url>', 'new target URL (public http/https, or a loopback http origin with an explicit port)')
|
|
1037
|
+
.option('--local <port>', 'shorthand for --url http://localhost:<port> (1-65535; excludes --url; frontend only)')
|
|
1038
|
+
.addOption(new Option('--local-host <host>', 'deprecated loopback host override; requires --local').hideHelp())
|
|
1023
1039
|
.option('--skip-preflight', 'skip the local TCP listener check before the update')
|
|
1024
1040
|
.option('--username <user>', 'new auth username')
|
|
1025
1041
|
.option('--password <pw>', 'new auth password')
|
|
@@ -1178,6 +1194,7 @@ export function createProjectCommand(deps = {}) {
|
|
|
1178
1194
|
// `project env <verb>` — the per-project environment surface (credentials,
|
|
1179
1195
|
// URL, default). Own module; `deps` threaded so tests inject.
|
|
1180
1196
|
project.addCommand(createProjectEnvCommand(deps));
|
|
1197
|
+
project.addCommand(createProjectSignInCommand(deps));
|
|
1181
1198
|
return project;
|
|
1182
1199
|
}
|
|
1183
1200
|
function parseFlag(raw, flagName) {
|
|
@@ -1252,7 +1269,21 @@ const PROJECT_LIST_COLUMNS = [
|
|
|
1252
1269
|
width: rows => Math.max(3, ...rows.map(project => renderProjectUrl(project).length)),
|
|
1253
1270
|
render: renderProjectUrl,
|
|
1254
1271
|
},
|
|
1255
|
-
{
|
|
1272
|
+
{
|
|
1273
|
+
header: 'CREATED',
|
|
1274
|
+
width: rows => Math.max(7, ...rows.map(project => project.createdAt.length)),
|
|
1275
|
+
render: project => project.createdAt,
|
|
1276
|
+
},
|
|
1277
|
+
{
|
|
1278
|
+
header: 'DEFAULT ENV',
|
|
1279
|
+
width: rows => Math.max(11, ...rows.map(project => (project.defaultEnvironment ?? '-').length)),
|
|
1280
|
+
render: project => project.defaultEnvironment ?? '-',
|
|
1281
|
+
},
|
|
1282
|
+
{
|
|
1283
|
+
header: 'ENVS',
|
|
1284
|
+
width: 4,
|
|
1285
|
+
render: project => project.environmentCount?.toString() ?? '-',
|
|
1286
|
+
},
|
|
1256
1287
|
];
|
|
1257
1288
|
function renderProjectUrl(project) {
|
|
1258
1289
|
const url = project.targetUrl ?? '';
|
|
@@ -1300,6 +1331,13 @@ function renderProjectText(p) {
|
|
|
1300
1331
|
if (p.orgId !== undefined) {
|
|
1301
1332
|
lines.push(`org: ${p.orgName ?? '(name unknown)'} (${p.orgId})`);
|
|
1302
1333
|
}
|
|
1334
|
+
if ('defaultEnvironment' in p) {
|
|
1335
|
+
lines.push(`defaultEnv: ${p.defaultEnvironment ?? '-'}`);
|
|
1336
|
+
}
|
|
1337
|
+
if ('environmentCount' in p) {
|
|
1338
|
+
const count = p.environmentCount;
|
|
1339
|
+
lines.push(`envs: ${count}${count !== undefined && count > 0 ? ` (list with: testsprite project env list ${p.id})` : ''}`);
|
|
1340
|
+
}
|
|
1303
1341
|
// Presence, not truthiness — see the `targetUrl` docstring on `CliProject`.
|
|
1304
1342
|
// `'targetUrl' in p` distinguishes "the backend answered 'no URL'" (render the
|
|
1305
1343
|
// hint) from "this endpoint doesn't report it" (say nothing).
|
|
@@ -1338,8 +1376,11 @@ function renderCreateProjectText(p, localTarget) {
|
|
|
1338
1376
|
if (localTarget) {
|
|
1339
1377
|
const projectId = resolveCreatedProjectId(p) ?? '<project-id>';
|
|
1340
1378
|
const url = buildLocalTargetUrl(localTarget.host, localTarget.port);
|
|
1341
|
-
|
|
1342
|
-
|
|
1379
|
+
lines.push(`Local project: TestSprite will reach ${url} only through a tunnel from this machine.`, 'Next: write a plan and run it locally:',
|
|
1380
|
+
// The only next step a --local project gets (it has no first-suite hint),
|
|
1381
|
+
// so it names how to get a plan file. `--plan-from` takes the project from
|
|
1382
|
+
// the file and ignores `--project`, hence "set projectId" and no flag.
|
|
1383
|
+
' testsprite test create --plan-template > plan.json', ` In plan.json, set projectId to ${projectId} and edit the steps.`, ' testsprite test create --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
1384
|
}
|
|
1344
1385
|
return lines.join('\n');
|
|
1345
1386
|
}
|
|
@@ -1350,10 +1391,23 @@ function renderUpdateText(r, localTarget) {
|
|
|
1350
1391
|
];
|
|
1351
1392
|
if (r.updatedAt !== undefined)
|
|
1352
1393
|
lines.push(`updatedAt: ${r.updatedAt}`);
|
|
1394
|
+
if (r.environment !== undefined) {
|
|
1395
|
+
lines.push(`environment: ${r.environment.name} (default)`);
|
|
1396
|
+
const labels = {
|
|
1397
|
+
'environment.url': 'Environment URL updated',
|
|
1398
|
+
'environment.credentials': 'Environment credentials updated',
|
|
1399
|
+
'project.name': 'Project name updated',
|
|
1400
|
+
'project.instruction': 'Project instruction updated',
|
|
1401
|
+
'project.testIdAttributes': 'Project test ID attributes updated',
|
|
1402
|
+
};
|
|
1403
|
+
for (const effect of r.effects ?? []) {
|
|
1404
|
+
if (labels[effect])
|
|
1405
|
+
lines.push(`effect: ${labels[effect]}`);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1353
1408
|
if (localTarget) {
|
|
1354
1409
|
const url = buildLocalTargetUrl(localTarget.host, localTarget.port);
|
|
1355
|
-
|
|
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}`);
|
|
1410
|
+
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
1411
|
}
|
|
1358
1412
|
return lines.join('\n');
|
|
1359
1413
|
}
|
|
@@ -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;
|