@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
package/dist/commands/project.js
CHANGED
|
@@ -4,15 +4,16 @@ import { basename, extname } from 'node:path';
|
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
5
5
|
import { Command } from 'commander';
|
|
6
6
|
import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, resolveRequestTimeoutMs, } from '../lib/client-factory.js';
|
|
7
|
-
import { ApiError, InterruptError, RequestTimeoutError
|
|
7
|
+
import { ApiError, InterruptError, RequestTimeoutError } from '../lib/errors.js';
|
|
8
8
|
import { globalShutdown } from '../lib/interrupt.js';
|
|
9
|
-
import { buildLocalTargetUrl, DEFAULT_LOCAL_HOST,
|
|
9
|
+
import { assertStoredLocalTargetListening, buildLocalTargetUrl, DEFAULT_LOCAL_HOST, parseStoredLocalTarget, } from '../lib/local-target.js';
|
|
10
10
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
11
11
|
import { readSecretFileGuarded } from '../lib/secret-file.js';
|
|
12
12
|
import { assertNotLocal } from '../lib/target-url.js';
|
|
13
13
|
import { renderTextTable, resolveTextColumns } from '../lib/text-table.js';
|
|
14
14
|
import { assertIdempotencyKey } from '../lib/validate.js';
|
|
15
15
|
import { fetchSinglePage, paginate, validatePaginationFlags, } from '../lib/pagination.js';
|
|
16
|
+
import { createProjectEnvCommand } from './project-env.js';
|
|
16
17
|
/** Attribute names are interpolated into CSS selectors by the engine — keep them plain. */
|
|
17
18
|
const TEST_ID_ATTRIBUTE_NAME = /^[A-Za-z_][\w.:-]*$/;
|
|
18
19
|
const TEST_ID_ATTRIBUTES_MAX = 10;
|
|
@@ -85,17 +86,6 @@ export async function runGet(opts, deps = {}) {
|
|
|
85
86
|
export function resolveCreatedProjectId(r) {
|
|
86
87
|
return r.projectId ?? r.id;
|
|
87
88
|
}
|
|
88
|
-
function normalizeProjectLocalHost(raw) {
|
|
89
|
-
try {
|
|
90
|
-
return normalizeLocalHost(raw);
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
if (err instanceof ApiError && typeof err.details?.reason === 'string') {
|
|
94
|
-
throw flagValidationError('local-host', err.details.reason.replace('--target-url', '--url'), err.details.accepted);
|
|
95
|
-
}
|
|
96
|
-
throw err;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
89
|
export async function runCreate(opts, deps = {}) {
|
|
100
90
|
const out = makeOutput(opts.output, deps);
|
|
101
91
|
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
@@ -121,21 +111,14 @@ export async function runCreate(opts, deps = {}) {
|
|
|
121
111
|
if (opts.description !== undefined) {
|
|
122
112
|
throw localValidationError('--description is not supported for projects; omit it (test-level descriptions are set on `test create`)');
|
|
123
113
|
}
|
|
124
|
-
if (opts.local !== undefined && opts.targetUrl !== undefined) {
|
|
125
|
-
throw localValidationError('--local and --url are mutually exclusive');
|
|
126
|
-
}
|
|
127
114
|
if (opts.local !== undefined && opts.type !== 'frontend') {
|
|
128
115
|
throw localValidationError('--local projects are frontend-only');
|
|
129
116
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
const localTarget = opts.local !== undefined
|
|
137
|
-
? { host: normalizeProjectLocalHost(opts.localHost), port: parseLocalPort(opts.local) }
|
|
138
|
-
: undefined;
|
|
117
|
+
const localTarget = parseStoredLocalTarget({
|
|
118
|
+
local: opts.local,
|
|
119
|
+
localHost: opts.localHost,
|
|
120
|
+
url: opts.targetUrl,
|
|
121
|
+
});
|
|
139
122
|
const targetUrl = localTarget
|
|
140
123
|
? buildLocalTargetUrl(localTarget.host, localTarget.port)
|
|
141
124
|
: opts.targetUrl;
|
|
@@ -180,25 +163,8 @@ export async function runCreate(opts, deps = {}) {
|
|
|
180
163
|
out.print(sample, data => renderCreateProjectText(data));
|
|
181
164
|
return sample;
|
|
182
165
|
}
|
|
183
|
-
if (localTarget
|
|
184
|
-
|
|
185
|
-
if (outcome.verdict === 'refuse') {
|
|
186
|
-
throw ApiError.fromEnvelope({
|
|
187
|
-
error: {
|
|
188
|
-
code: 'VALIDATION_ERROR',
|
|
189
|
-
message: `Nothing is listening on ${targetUrl}. Start your app first, or pass --skip-preflight.`,
|
|
190
|
-
nextAction: 'Verify --local and --local-host match the app you want to test.',
|
|
191
|
-
requestId: 'local',
|
|
192
|
-
details: {
|
|
193
|
-
field: 'local',
|
|
194
|
-
reason: 'local-port-not-listening',
|
|
195
|
-
host: localTarget.host,
|
|
196
|
-
port: localTarget.port,
|
|
197
|
-
probeReason: outcome.reason,
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
}
|
|
166
|
+
if (localTarget) {
|
|
167
|
+
await assertStoredLocalTargetListening(localTarget, opts, deps.localPortProbeDeps);
|
|
202
168
|
}
|
|
203
169
|
// Resolve password: flag > file > none
|
|
204
170
|
let password = opts.password;
|
|
@@ -301,12 +267,24 @@ export async function runUpdate(opts, deps = {}) {
|
|
|
301
267
|
if (opts.name !== undefined && opts.name.length > 200) {
|
|
302
268
|
throw localValidationError('--name must be at most 200 characters');
|
|
303
269
|
}
|
|
304
|
-
//
|
|
270
|
+
// `--local <port>` is the one way to point a project at an app on this
|
|
271
|
+
// machine, on update exactly as on create. A loopback `--url` has no
|
|
272
|
+
// accepted form here and is redirected to `--local`. The project's type is
|
|
273
|
+
// not known client-side on update; the server refuses `--local` on a
|
|
274
|
+
// backend project.
|
|
275
|
+
const localTarget = parseStoredLocalTarget({
|
|
276
|
+
local: opts.local,
|
|
277
|
+
localHost: opts.localHost,
|
|
278
|
+
url: opts.targetUrl,
|
|
279
|
+
});
|
|
280
|
+
const targetUrl = localTarget
|
|
281
|
+
? buildLocalTargetUrl(localTarget.host, localTarget.port)
|
|
282
|
+
: opts.targetUrl;
|
|
305
283
|
if (opts.targetUrl !== undefined) {
|
|
306
284
|
assertNotLocal(opts.targetUrl, {
|
|
307
285
|
field: 'url',
|
|
308
286
|
helpCommand: 'testsprite project update',
|
|
309
|
-
hintContext: '
|
|
287
|
+
hintContext: 'local-project-create',
|
|
310
288
|
});
|
|
311
289
|
}
|
|
312
290
|
if (opts.testIdAttributes !== undefined && opts.clearTestIdAttributes) {
|
|
@@ -315,7 +293,7 @@ export async function runUpdate(opts, deps = {}) {
|
|
|
315
293
|
const passwordSupplied = opts.password !== undefined || opts.passwordFile !== undefined;
|
|
316
294
|
const mutableFields = {
|
|
317
295
|
name: opts.name !== undefined,
|
|
318
|
-
targetUrl:
|
|
296
|
+
targetUrl: targetUrl !== undefined,
|
|
319
297
|
username: opts.username !== undefined,
|
|
320
298
|
password: passwordSupplied,
|
|
321
299
|
instruction: opts.instruction !== undefined,
|
|
@@ -345,9 +323,12 @@ export async function runUpdate(opts, deps = {}) {
|
|
|
345
323
|
updatedFields: presentFieldNames,
|
|
346
324
|
updatedAt: '2026-05-16T00:00:00.000Z',
|
|
347
325
|
};
|
|
348
|
-
out.print(sample, data => renderUpdateText(data));
|
|
326
|
+
out.print(sample, data => renderUpdateText(data, localTarget));
|
|
349
327
|
return sample;
|
|
350
328
|
}
|
|
329
|
+
if (localTarget) {
|
|
330
|
+
await assertStoredLocalTargetListening(localTarget, opts, deps.localPortProbeDeps);
|
|
331
|
+
}
|
|
351
332
|
// Resolve password only on the real path. Dry-run must not touch the
|
|
352
333
|
// filesystem, even when --password-file is present.
|
|
353
334
|
let password = opts.password;
|
|
@@ -360,7 +341,8 @@ export async function runUpdate(opts, deps = {}) {
|
|
|
360
341
|
}
|
|
361
342
|
const bodyFields = {
|
|
362
343
|
name: opts.name,
|
|
363
|
-
targetUrl
|
|
344
|
+
targetUrl,
|
|
345
|
+
originMode: localTarget ? 'local' : undefined,
|
|
364
346
|
username: opts.username,
|
|
365
347
|
password,
|
|
366
348
|
instruction: opts.instruction,
|
|
@@ -389,7 +371,7 @@ export async function runUpdate(opts, deps = {}) {
|
|
|
389
371
|
? { projectId: resolvedUpdatedId, id: resolvedUpdatedId }
|
|
390
372
|
: {}),
|
|
391
373
|
};
|
|
392
|
-
out.print(updated, data => renderUpdateText(data));
|
|
374
|
+
out.print(updated, data => renderUpdateText(data, localTarget));
|
|
393
375
|
return updated;
|
|
394
376
|
}
|
|
395
377
|
/**
|
|
@@ -1035,7 +1017,10 @@ export function createProjectCommand(deps = {}) {
|
|
|
1035
1017
|
.command('update <project-id>')
|
|
1036
1018
|
.description('Update project metadata')
|
|
1037
1019
|
.option('--name <name>', 'new project name')
|
|
1038
|
-
.option('--url <url>', 'new target URL')
|
|
1020
|
+
.option('--url <url>', 'new target URL (public; for an app on this machine use --local)')
|
|
1021
|
+
.option('--local <port>', 'point the project at an app on this machine (1-65535; excludes --url; frontend only)')
|
|
1022
|
+
.option('--local-host <host>', 'loopback host: localhost, 127.0.0.1 (default), or ::1; requires --local')
|
|
1023
|
+
.option('--skip-preflight', 'skip the local TCP listener check before the update')
|
|
1039
1024
|
.option('--username <user>', 'new auth username')
|
|
1040
1025
|
.option('--password <pw>', 'new auth password')
|
|
1041
1026
|
.option('--password-file <path>', 'read new password from file')
|
|
@@ -1051,6 +1036,9 @@ export function createProjectCommand(deps = {}) {
|
|
|
1051
1036
|
projectId,
|
|
1052
1037
|
name: cmdOpts.name,
|
|
1053
1038
|
targetUrl: cmdOpts.url,
|
|
1039
|
+
local: cmdOpts.local,
|
|
1040
|
+
localHost: cmdOpts.localHost,
|
|
1041
|
+
skipPreflight: cmdOpts.skipPreflight,
|
|
1054
1042
|
username: cmdOpts.username,
|
|
1055
1043
|
password: cmdOpts.password,
|
|
1056
1044
|
passwordFile: cmdOpts.passwordFile,
|
|
@@ -1187,6 +1175,9 @@ export function createProjectCommand(deps = {}) {
|
|
|
1187
1175
|
}, deps);
|
|
1188
1176
|
});
|
|
1189
1177
|
project.addCommand(docs);
|
|
1178
|
+
// DEV-1305: `project env <verb>` — the per-project environment surface
|
|
1179
|
+
// (credentials, URL, default). Own module; `deps` threaded so tests inject.
|
|
1180
|
+
project.addCommand(createProjectEnvCommand(deps));
|
|
1190
1181
|
return project;
|
|
1191
1182
|
}
|
|
1192
1183
|
function parseFlag(raw, flagName) {
|
|
@@ -1352,13 +1343,18 @@ function renderCreateProjectText(p, localTarget) {
|
|
|
1352
1343
|
}
|
|
1353
1344
|
return lines.join('\n');
|
|
1354
1345
|
}
|
|
1355
|
-
function renderUpdateText(r) {
|
|
1346
|
+
function renderUpdateText(r, localTarget) {
|
|
1356
1347
|
const lines = [
|
|
1357
1348
|
`id: ${resolveUpdatedProjectId(r) ?? '(unknown)'}`,
|
|
1358
1349
|
`updatedFields: ${r.updatedFields?.join(', ') ?? '(none)'}`,
|
|
1359
1350
|
];
|
|
1360
1351
|
if (r.updatedAt !== undefined)
|
|
1361
1352
|
lines.push(`updatedAt: ${r.updatedAt}`);
|
|
1353
|
+
if (localTarget) {
|
|
1354
|
+
const url = buildLocalTargetUrl(localTarget.host, localTarget.port);
|
|
1355
|
+
const hostFlag = localTarget.host === DEFAULT_LOCAL_HOST ? '' : ` --local-host ${localTarget.host}`;
|
|
1356
|
+
lines.push(`Local project: TestSprite will reach ${url} only through a tunnel from this machine.`, `Run its tests with: testsprite test run <test-id> --local ${localTarget.port}${hostFlag}`);
|
|
1357
|
+
}
|
|
1362
1358
|
return lines.join('\n');
|
|
1363
1359
|
}
|
|
1364
1360
|
function renderDeleteText(r) {
|
package/dist/commands/test.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { ApiError, InterruptError } from '../lib/errors.js';
|
|
|
6
6
|
import { type ShutdownHandle } from '../lib/interrupt.js';
|
|
7
7
|
import type { FetchImpl } from '../lib/http.js';
|
|
8
8
|
import { type Page } from '../lib/pagination.js';
|
|
9
|
-
import type
|
|
9
|
+
import { type WaitTimeoutTelemetry } from '../lib/telemetry.js';
|
|
10
10
|
import type { CliGetPlansResponse } from '../lib/plans.types.js';
|
|
11
|
-
import type { RunResponse, RunStatus, TriggerRunResponse, RerunResponse, BatchRerunResponse, ListRunsResponse, RunSource, BatchRunFreshResponse, CancelRunResponse } from '../lib/runs.types.js';
|
|
11
|
+
import type { RunResponse, RunStatus, TriggerRunResponse, RerunResponse, BatchRerunResponse, ListRunsResponse, RunSource, BatchRunFreshResponse, CancelRunResponse, RunEnvironmentRef } from '../lib/runs.types.js';
|
|
12
12
|
import { type LoopbackHost } from '../lib/local-target.js';
|
|
13
13
|
import { type TunnelClientHandle } from '../lib/tunnel-session.js';
|
|
14
14
|
import { type TunnelClientOptions } from '../vendor/tunnel-client/index.js';
|
|
@@ -184,6 +184,11 @@ export interface CliLatestResult {
|
|
|
184
184
|
* (semantically equivalent to `'unresolved'`).
|
|
185
185
|
*/
|
|
186
186
|
targetUrlSource?: 'run' | 'project-default' | 'unresolved' | null;
|
|
187
|
+
/**
|
|
188
|
+
* The environment the latest run resolved to. Absent on an older backend;
|
|
189
|
+
* `null` when the row names no environment.
|
|
190
|
+
*/
|
|
191
|
+
environment?: RunEnvironmentRef | null;
|
|
187
192
|
failedStepIndex: number | null;
|
|
188
193
|
failureKind: CliFailureKind;
|
|
189
194
|
/**
|
|
@@ -751,7 +756,7 @@ export interface CliCreateFromPlanResponse extends CliCreateTestResponse {
|
|
|
751
756
|
* Caveat: the pinned tag only resolves once that version is actually
|
|
752
757
|
* released — a locally-built/pre-release checkout may see a 404 until then.
|
|
753
758
|
*/
|
|
754
|
-
export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.
|
|
759
|
+
export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.12.0/schemas/plan.schema.json";
|
|
755
760
|
/**
|
|
756
761
|
* The SINGLE canonical example plan. This
|
|
757
762
|
* exact value (via `PLAN_TEMPLATE_TEXT` below) is:
|
|
@@ -1383,6 +1388,8 @@ interface ResultHistoryOptions extends CommonOptions {
|
|
|
1383
1388
|
* fresh runs, `undefined` → no filter. Applied to each page after the fetch.
|
|
1384
1389
|
*/
|
|
1385
1390
|
rerun?: boolean;
|
|
1391
|
+
/** `--env <name>`: only runs whose credentials came from this environment (server-side filter). */
|
|
1392
|
+
environment?: string;
|
|
1386
1393
|
columns?: string;
|
|
1387
1394
|
noHeader?: boolean;
|
|
1388
1395
|
}
|
|
@@ -1532,6 +1539,14 @@ interface RunTestRunOptions extends CommonOptions {
|
|
|
1532
1539
|
* ordinary runs, where detaching leaves a run that can still pass.
|
|
1533
1540
|
*/
|
|
1534
1541
|
cancelOnInterrupt?: boolean;
|
|
1542
|
+
/**
|
|
1543
|
+
* `--env <name>` — the project environment whose credentials, auto-auth and
|
|
1544
|
+
* OTP settings this run uses. Composes with `--local` / `--target-url` (those
|
|
1545
|
+
* choose WHERE the browser goes; this chooses WHOSE login it uses). Absent →
|
|
1546
|
+
* the project's default environment, byte-identical to today. Feature-gated
|
|
1547
|
+
* per workspace: checked client-side before anything is minted or billed.
|
|
1548
|
+
*/
|
|
1549
|
+
environment?: string;
|
|
1535
1550
|
}
|
|
1536
1551
|
interface RunTestWaitOptions extends CommonOptions {
|
|
1537
1552
|
runId: string;
|
|
@@ -1567,6 +1582,8 @@ interface RunTestRerunOptions extends CommonOptions {
|
|
|
1567
1582
|
autoHealExplicit: boolean;
|
|
1568
1583
|
/** --skip-dependencies: BE only. Don't expand the producer/teardown closure. */
|
|
1569
1584
|
skipDependencies: boolean;
|
|
1585
|
+
/** `--env <name>`: see `RunTestRunOptions.environment` — the environment to replay against. */
|
|
1586
|
+
environment?: string;
|
|
1570
1587
|
/** --max-concurrency: bounds the --wait poll fan-out (batch / BE closure). */
|
|
1571
1588
|
maxConcurrency: number;
|
|
1572
1589
|
/** --idempotency-key: caller-supplied; auto-minted UUID when absent. */
|
|
@@ -1602,6 +1619,13 @@ interface RunTestRerunOptions extends CommonOptions {
|
|
|
1602
1619
|
ghOutput?: boolean;
|
|
1603
1620
|
/** --summary-file: also write the reduced machine summary JSON to this path. */
|
|
1604
1621
|
summaryFile?: string;
|
|
1622
|
+
/**
|
|
1623
|
+
* --allow-empty: with --all, exit 0 (instead of failing with exit 5) when the
|
|
1624
|
+
* resolved test set is EMPTY — no tests match --filter/--status/--skip-terminal,
|
|
1625
|
+
* or the project has none. Mirrors `test run --all --allow-empty`;
|
|
1626
|
+
* it does NOT cover ids the server rejected (notFound still gates, exit 4).
|
|
1627
|
+
*/
|
|
1628
|
+
allowEmpty?: boolean;
|
|
1605
1629
|
}
|
|
1606
1630
|
/** Minimal client surface the backend-test wait fallback needs. */
|
|
1607
1631
|
interface ResultReadClient {
|
|
@@ -1771,9 +1795,11 @@ interface RunTestRunAllOptions extends CommonOptions {
|
|
|
1771
1795
|
* --allow-empty: exit 0 (instead of failing) when the batch dispatches ZERO
|
|
1772
1796
|
* tests (all skipped / empty project / --filter matched nothing). Default off:
|
|
1773
1797
|
* a zero-dispatch `--all` is a CI false-green, so it fails with exit 5 by
|
|
1774
|
-
* default and still emits the summary / annotation / JUnit report
|
|
1798
|
+
* default and still emits the summary / annotation / JUnit report.
|
|
1775
1799
|
*/
|
|
1776
1800
|
allowEmpty?: boolean;
|
|
1801
|
+
/** `--env <name>`: see `RunTestRunOptions.environment` — applied to every test in the batch. */
|
|
1802
|
+
environment?: string;
|
|
1777
1803
|
}
|
|
1778
1804
|
export declare function writeBatchJUnitReportIfRequested(opts: {
|
|
1779
1805
|
report?: JUnitReportFormat;
|