@testsprite/testsprite-cli 0.5.0 → 0.7.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 +39 -30
- package/dist/commands/agent.js +44 -42
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.js +4 -7
- package/dist/commands/project.js +3 -2
- package/dist/commands/schedule.d.ts +120 -0
- package/dist/commands/schedule.js +487 -0
- package/dist/commands/test.d.ts +55 -1
- package/dist/commands/test.js +714 -183
- package/dist/commands/testlist.d.ts +88 -0
- package/dist/commands/testlist.js +747 -0
- package/dist/index.js +6 -2
- package/dist/lib/agent-targets.d.ts +13 -4
- package/dist/lib/agent-targets.js +11 -2
- package/dist/lib/conflict-reason.d.ts +30 -0
- package/dist/lib/conflict-reason.js +45 -0
- package/dist/lib/credentials.js +42 -1
- package/dist/lib/cron.d.ts +40 -0
- package/dist/lib/cron.js +190 -0
- package/dist/lib/dry-run/samples.js +177 -55
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.js +11 -0
- package/dist/lib/gh-output.d.ts +51 -4
- package/dist/lib/gh-output.js +149 -19
- package/dist/lib/http.d.ts +25 -0
- package/dist/lib/http.js +201 -3
- package/dist/lib/junit-report.d.ts +20 -2
- package/dist/lib/junit-report.js +38 -5
- package/dist/lib/poll.js +72 -36
- package/dist/lib/proxy.d.ts +16 -0
- package/dist/lib/proxy.js +19 -1
- package/dist/lib/response-schemas.d.ts +7 -0
- package/dist/lib/response-schemas.js +46 -14
- package/dist/lib/runs.types.d.ts +8 -3
- package/dist/lib/secret-file.d.ts +15 -0
- package/dist/lib/secret-file.js +82 -0
- package/dist/lib/target-url-preflight.d.ts +91 -0
- package/dist/lib/target-url-preflight.js +259 -0
- package/dist/lib/target-url.d.ts +22 -5
- package/dist/lib/target-url.js +60 -28
- package/dist/lib/testlist.types.d.ts +77 -0
- package/dist/lib/testlist.types.js +9 -0
- package/dist/lib/v3-advisory.d.ts +37 -4
- package/dist/lib/v3-advisory.js +47 -4
- package/dist/lib/wait-exit.d.ts +29 -0
- package/dist/lib/wait-exit.js +103 -0
- package/dist/version-guard.d.ts +10 -7
- package/dist/version-guard.js +37 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
|
|
4
|
+
import { ApiError } from '../lib/errors.js';
|
|
5
|
+
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
6
|
+
import { formatScheduleFrequencyAdvisory, runsPerMonth } from '../lib/cron.js';
|
|
7
|
+
import { renderTextTable } from '../lib/text-table.js';
|
|
8
|
+
import { assertIdempotencyKey } from '../lib/validate.js';
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// schedule list
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
export async function runList(opts, deps = {}) {
|
|
13
|
+
const out = makeOutput(opts.output, deps);
|
|
14
|
+
const client = makeClient(opts, deps);
|
|
15
|
+
const response = await client.get('/schedules');
|
|
16
|
+
const schedules = response.schedules ?? [];
|
|
17
|
+
out.print({ schedules }, () => renderScheduleListText(schedules, { columns: opts.columns, noHeader: opts.noHeader }));
|
|
18
|
+
return { schedules };
|
|
19
|
+
}
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// schedule get
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
export async function runGet(opts, deps = {}) {
|
|
24
|
+
const out = makeOutput(opts.output, deps);
|
|
25
|
+
const client = makeClient(opts, deps);
|
|
26
|
+
const schedule = await client.get(`/schedules/${encodeURIComponent(opts.scheduleId)}`);
|
|
27
|
+
out.print(schedule, data => renderScheduleText(data));
|
|
28
|
+
return schedule;
|
|
29
|
+
}
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// schedule create
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
const TARGET_TYPES = ['project', 'testList'];
|
|
34
|
+
export async function runCreate(opts, deps = {}) {
|
|
35
|
+
const out = makeOutput(opts.output, deps);
|
|
36
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
37
|
+
assertIdempotencyKey(opts.idempotencyKey);
|
|
38
|
+
if (opts.name === undefined || opts.name.trim().length === 0) {
|
|
39
|
+
throw localValidationError('--name is required and must not be empty');
|
|
40
|
+
}
|
|
41
|
+
if (opts.targetType === undefined) {
|
|
42
|
+
throw localValidationError('--target-type is required (project or testList)');
|
|
43
|
+
}
|
|
44
|
+
if (!TARGET_TYPES.includes(opts.targetType)) {
|
|
45
|
+
throw localValidationError('--target-type must be one of: project, testList');
|
|
46
|
+
}
|
|
47
|
+
if (opts.targetId === undefined || opts.targetId.trim().length === 0) {
|
|
48
|
+
throw localValidationError('--target-id is required and must not be empty');
|
|
49
|
+
}
|
|
50
|
+
if (opts.cron === undefined || opts.cron.trim().length === 0) {
|
|
51
|
+
throw localValidationError('--cron is required and must not be empty');
|
|
52
|
+
}
|
|
53
|
+
const targetType = opts.targetType;
|
|
54
|
+
const cron = opts.cron.trim();
|
|
55
|
+
const body = {
|
|
56
|
+
name: opts.name,
|
|
57
|
+
targetType,
|
|
58
|
+
targetId: opts.targetId,
|
|
59
|
+
cron,
|
|
60
|
+
...(opts.timezone !== undefined ? { timezone: opts.timezone } : {}),
|
|
61
|
+
...(opts.start !== undefined ? { startAt: opts.start } : {}),
|
|
62
|
+
...(opts.end !== undefined ? { endAt: opts.end } : {}),
|
|
63
|
+
...(opts.sendTo !== undefined ? { sendTo: opts.sendTo } : {}),
|
|
64
|
+
};
|
|
65
|
+
const idempotencyKey = opts.idempotencyKey ?? `cli-sched-create-${randomUUID()}`;
|
|
66
|
+
if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
|
|
67
|
+
stderr(`idempotency-key: ${idempotencyKey}`);
|
|
68
|
+
}
|
|
69
|
+
// Printed before the request so it is visible even if the create then fails.
|
|
70
|
+
stderr(formatScheduleFrequencyAdvisory(cron));
|
|
71
|
+
if (opts.dryRun) {
|
|
72
|
+
emitDryRunBanner(stderr);
|
|
73
|
+
// Carries a cost figure so the advisory below is exercised offline too.
|
|
74
|
+
const sample = {
|
|
75
|
+
scheduleId: 'sch_dryrun_2026',
|
|
76
|
+
estimatedCreditsPerRun: 5,
|
|
77
|
+
};
|
|
78
|
+
emitCostAdvisory(sample, cron, stderr);
|
|
79
|
+
out.print(sample, data => renderCreateScheduleText(data));
|
|
80
|
+
return sample;
|
|
81
|
+
}
|
|
82
|
+
const client = makeClient(opts, deps);
|
|
83
|
+
const created = await client.post('/schedules', {
|
|
84
|
+
body,
|
|
85
|
+
headers: { 'idempotency-key': idempotencyKey },
|
|
86
|
+
});
|
|
87
|
+
emitCostAdvisory(created, cron, stderr);
|
|
88
|
+
out.print(created, data => renderCreateScheduleText(data));
|
|
89
|
+
return created;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Cost advisory for a schedule that was just created.
|
|
93
|
+
*
|
|
94
|
+
* Silent unless the API priced the run — the rates are not exposed, so no figure
|
|
95
|
+
* is invented here. The monthly total is the per-run price times the cron's
|
|
96
|
+
* frequency, and is omitted for an expression this side cannot read.
|
|
97
|
+
*/
|
|
98
|
+
function emitCostAdvisory(response, cron, stderr) {
|
|
99
|
+
const perRun = response.estimatedCreditsPerRun;
|
|
100
|
+
if (typeof perRun !== 'number')
|
|
101
|
+
return;
|
|
102
|
+
const runs = runsPerMonth(cron);
|
|
103
|
+
const monthly = runs === null ? '' : `, ~${formatMonthly(perRun * runs)} credits/month`;
|
|
104
|
+
stderr(`Estimated cost: ~${formatPerRun(perRun)} credits/run${monthly}, ` +
|
|
105
|
+
"based on the target's current case count.");
|
|
106
|
+
}
|
|
107
|
+
/** Kept to 2 decimals: rounding a per-run price to whole credits stops the monthly total beside it from multiplying out. */
|
|
108
|
+
function formatPerRun(value) {
|
|
109
|
+
return String(Number(value.toFixed(2)));
|
|
110
|
+
}
|
|
111
|
+
/** Whole credits read better for a total; keep decimals only where rounding would say zero. */
|
|
112
|
+
function formatMonthly(value) {
|
|
113
|
+
if (value >= 1)
|
|
114
|
+
return String(Math.round(value));
|
|
115
|
+
return String(Number(value.toFixed(2)));
|
|
116
|
+
}
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
// schedule update
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
export async function runUpdate(opts, deps = {}) {
|
|
121
|
+
const out = makeOutput(opts.output, deps);
|
|
122
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
123
|
+
assertIdempotencyKey(opts.idempotencyKey);
|
|
124
|
+
if (opts.pause && opts.resume) {
|
|
125
|
+
throw localValidationError('--pause and --resume cannot be combined');
|
|
126
|
+
}
|
|
127
|
+
const body = {
|
|
128
|
+
...(opts.name !== undefined ? { name: opts.name } : {}),
|
|
129
|
+
...(opts.cron !== undefined ? { cron: opts.cron } : {}),
|
|
130
|
+
...(opts.timezone !== undefined ? { timezone: opts.timezone } : {}),
|
|
131
|
+
...(opts.start !== undefined ? { startAt: opts.start } : {}),
|
|
132
|
+
...(opts.end !== undefined ? { endAt: opts.end } : {}),
|
|
133
|
+
...(opts.sendTo !== undefined ? { sendTo: opts.sendTo } : {}),
|
|
134
|
+
...(opts.pause ? { enabled: false } : {}),
|
|
135
|
+
...(opts.resume ? { enabled: true } : {}),
|
|
136
|
+
};
|
|
137
|
+
if (Object.keys(body).length === 0) {
|
|
138
|
+
throw localValidationError('nothing to update — pass at least one field, --pause or --resume');
|
|
139
|
+
}
|
|
140
|
+
const idempotencyKey = opts.idempotencyKey ?? `cli-sched-update-${randomUUID()}`;
|
|
141
|
+
if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
|
|
142
|
+
stderr(`idempotency-key: ${idempotencyKey}`);
|
|
143
|
+
}
|
|
144
|
+
// Same advisory create prints, for the same reason: retiming a daily schedule
|
|
145
|
+
// to `* * * * *` is the same order-of-magnitude mistake as creating one that
|
|
146
|
+
// way, on an existing schedule and for the same bill. Printed before the
|
|
147
|
+
// request so it is visible even if the update then fails.
|
|
148
|
+
if (opts.cron !== undefined) {
|
|
149
|
+
stderr(formatScheduleFrequencyAdvisory(opts.cron));
|
|
150
|
+
}
|
|
151
|
+
const client = makeClient(opts, deps);
|
|
152
|
+
const updated = await client.patch(`/schedules/${encodeURIComponent(opts.scheduleId)}`, { body, headers: { 'idempotency-key': idempotencyKey } });
|
|
153
|
+
out.print(updated, data => renderScheduleText(data));
|
|
154
|
+
return updated;
|
|
155
|
+
}
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
// schedule delete
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
export async function runDelete(opts, deps = {}) {
|
|
160
|
+
const out = makeOutput(opts.output, deps);
|
|
161
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
162
|
+
assertIdempotencyKey(opts.idempotencyKey);
|
|
163
|
+
if (!opts.confirm && !opts.dryRun) {
|
|
164
|
+
throw ApiError.fromEnvelope({
|
|
165
|
+
error: {
|
|
166
|
+
code: 'VALIDATION_ERROR',
|
|
167
|
+
message: 'Refusing to delete without --confirm.',
|
|
168
|
+
nextAction: 'This removes the schedule and its run history, and stops it firing (no ' +
|
|
169
|
+
'restore window — recreating it starts a fresh schedule). The CLI convention ' +
|
|
170
|
+
'is explicit confirmation for destructive operations. Re-run with --confirm. ' +
|
|
171
|
+
'(--dry-run also works without --confirm.)',
|
|
172
|
+
requestId: 'local',
|
|
173
|
+
details: { field: 'confirm', reason: 'required for destructive operation' },
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const idempotencyKey = opts.idempotencyKey ?? `cli-sched-delete-${randomUUID()}`;
|
|
178
|
+
if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
|
|
179
|
+
stderr(`idempotency-key: ${idempotencyKey}`);
|
|
180
|
+
}
|
|
181
|
+
const client = makeClient(opts, deps);
|
|
182
|
+
const deleted = await client.delete(`/schedules/${encodeURIComponent(opts.scheduleId)}`, { headers: { 'idempotency-key': idempotencyKey } });
|
|
183
|
+
out.print(deleted, data => `deleted: ${data.scheduleId}`);
|
|
184
|
+
return deleted;
|
|
185
|
+
}
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
// schedule run list
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
export async function runRunList(opts, deps = {}) {
|
|
190
|
+
const out = makeOutput(opts.output, deps);
|
|
191
|
+
const client = makeClient(opts, deps);
|
|
192
|
+
const response = await client.get(`/schedules/${encodeURIComponent(opts.scheduleId)}/runs`);
|
|
193
|
+
const runs = response.runs ?? [];
|
|
194
|
+
out.print({ runs }, () => renderRunListText(runs, { columns: opts.columns, noHeader: opts.noHeader }));
|
|
195
|
+
return { runs };
|
|
196
|
+
}
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
// Rendering
|
|
199
|
+
// ---------------------------------------------------------------------------
|
|
200
|
+
/**
|
|
201
|
+
* `AUTO_PAUSED` is reported separately from `PAUSED` so a schedule the platform
|
|
202
|
+
* turned off after repeated failures is distinguishable from one someone paused
|
|
203
|
+
* with `update --pause`.
|
|
204
|
+
*/
|
|
205
|
+
function statusOf(s) {
|
|
206
|
+
if (s.enabled)
|
|
207
|
+
return 'ENABLED';
|
|
208
|
+
return s.autoPausedAt ? 'AUTO_PAUSED' : 'PAUSED';
|
|
209
|
+
}
|
|
210
|
+
const SCHEDULE_LIST_COLUMNS = [
|
|
211
|
+
{
|
|
212
|
+
header: 'ID',
|
|
213
|
+
width: rows => Math.max(2, ...rows.map(s => s.scheduleId.length)),
|
|
214
|
+
render: s => s.scheduleId,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
header: 'NAME',
|
|
218
|
+
width: rows => Math.max(4, ...rows.map(s => s.name.length)),
|
|
219
|
+
render: s => s.name,
|
|
220
|
+
},
|
|
221
|
+
{ header: 'STATUS', width: 11, render: statusOf },
|
|
222
|
+
{ header: 'TARGET', width: 8, render: s => s.targetType },
|
|
223
|
+
{
|
|
224
|
+
header: 'CRON',
|
|
225
|
+
width: rows => Math.max(4, ...rows.map(s => (s.cron ?? '').length)),
|
|
226
|
+
render: s => s.cron ?? '',
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
header: 'TZ',
|
|
230
|
+
width: rows => Math.max(2, ...rows.map(s => (s.timezone ?? '').length)),
|
|
231
|
+
render: s => s.timezone ?? '',
|
|
232
|
+
},
|
|
233
|
+
{ header: 'LAST RUN', width: 0, render: s => s.lastRunId ?? '' },
|
|
234
|
+
];
|
|
235
|
+
function renderScheduleListText(schedules, options = {}) {
|
|
236
|
+
if (schedules.length === 0)
|
|
237
|
+
return 'No schedules.';
|
|
238
|
+
return renderTextTable(schedules, SCHEDULE_LIST_COLUMNS, {
|
|
239
|
+
columns: options.columns,
|
|
240
|
+
noHeader: options.noHeader,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
function renderScheduleText(s) {
|
|
244
|
+
const lines = [
|
|
245
|
+
`id: ${s.scheduleId}`,
|
|
246
|
+
`name: ${s.name}`,
|
|
247
|
+
`status: ${statusOf(s)}`,
|
|
248
|
+
`targetType: ${s.targetType}`,
|
|
249
|
+
`targetId: ${s.targetId ?? '(none)'}`,
|
|
250
|
+
`cron: ${s.cron ?? '(none)'}`,
|
|
251
|
+
`timezone: ${s.timezone ?? '(none)'}`,
|
|
252
|
+
`startAt: ${s.startAt ?? '(none)'}`,
|
|
253
|
+
`endAt: ${s.endAt ?? '(open-ended)'}`,
|
|
254
|
+
`sendTo: ${s.sendTo ?? '(none)'}`,
|
|
255
|
+
`lastRunId: ${s.lastRunId ?? '(never run)'}`,
|
|
256
|
+
`createdAt: ${s.createdAt}`,
|
|
257
|
+
`updatedAt: ${s.updatedAt}`,
|
|
258
|
+
];
|
|
259
|
+
if (s.autoPausedAt)
|
|
260
|
+
lines.push(`autoPaused: ${s.autoPausedAt}`);
|
|
261
|
+
return lines.join('\n');
|
|
262
|
+
}
|
|
263
|
+
function renderCreateScheduleText(r) {
|
|
264
|
+
return `id: ${r.scheduleId}`;
|
|
265
|
+
}
|
|
266
|
+
const RUN_LIST_COLUMNS = [
|
|
267
|
+
{
|
|
268
|
+
header: 'RUN ID',
|
|
269
|
+
width: rows => Math.max(6, ...rows.map(r => r.runId.length)),
|
|
270
|
+
render: r => r.runId,
|
|
271
|
+
},
|
|
272
|
+
{ header: 'STATUS', width: 9, render: r => r.status },
|
|
273
|
+
{ header: 'TOTAL', width: 5, render: r => String(r.stats.total) },
|
|
274
|
+
{ header: 'PASS', width: 4, render: r => String(r.stats.passed) },
|
|
275
|
+
{ header: 'FAIL', width: 4, render: r => String(r.stats.failed) },
|
|
276
|
+
{ header: 'BLOCK', width: 5, render: r => String(r.stats.blocked) },
|
|
277
|
+
{ header: 'STARTED', width: 0, render: r => r.createdAt },
|
|
278
|
+
];
|
|
279
|
+
function renderRunListText(runs, options = {}) {
|
|
280
|
+
// Distinct from a missing schedule, which is reported as not found.
|
|
281
|
+
if (runs.length === 0)
|
|
282
|
+
return 'No runs yet.';
|
|
283
|
+
return renderTextTable(runs, RUN_LIST_COLUMNS, {
|
|
284
|
+
columns: options.columns,
|
|
285
|
+
noHeader: options.noHeader,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
function localValidationError(message) {
|
|
289
|
+
return ApiError.fromEnvelope({
|
|
290
|
+
error: {
|
|
291
|
+
code: 'VALIDATION_ERROR',
|
|
292
|
+
message: 'Invalid request.',
|
|
293
|
+
nextAction: message,
|
|
294
|
+
requestId: 'local',
|
|
295
|
+
details: { reason: 'missing_required_flag' },
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
// ---------------------------------------------------------------------------
|
|
300
|
+
// Wiring
|
|
301
|
+
// ---------------------------------------------------------------------------
|
|
302
|
+
export function createScheduleCommand(deps = {}) {
|
|
303
|
+
const schedule = new Command('schedule').description('Manage TestSprite schedules');
|
|
304
|
+
schedule
|
|
305
|
+
.command('list')
|
|
306
|
+
.description('List schedules visible to the API key\n' +
|
|
307
|
+
'\nExit codes:\n' +
|
|
308
|
+
' 0 success\n' +
|
|
309
|
+
' 3 auth error\n' +
|
|
310
|
+
' 7 schedules are not available on this account\n' +
|
|
311
|
+
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
312
|
+
' 13 not available on your plan')
|
|
313
|
+
.option('--columns <list>', 'select/reorder text table columns (comma-separated keys)')
|
|
314
|
+
.option('--no-header', 'suppress the text table header row')
|
|
315
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
316
|
+
.action(async (cmdOpts, command) => {
|
|
317
|
+
await runList({
|
|
318
|
+
...resolveCommonOptions(command),
|
|
319
|
+
columns: cmdOpts.columns,
|
|
320
|
+
noHeader: cmdOpts.header === false,
|
|
321
|
+
}, deps);
|
|
322
|
+
});
|
|
323
|
+
schedule
|
|
324
|
+
.command('get <schedule-id>')
|
|
325
|
+
.description('Get a schedule by id\n' +
|
|
326
|
+
'\nExit codes:\n' +
|
|
327
|
+
' 0 success\n' +
|
|
328
|
+
' 3 auth error\n' +
|
|
329
|
+
' 4 not found\n' +
|
|
330
|
+
' 7 schedules are not available on this account\n' +
|
|
331
|
+
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
332
|
+
' 13 not available on your plan')
|
|
333
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
334
|
+
.action(async (scheduleId, _cmdOpts, command) => {
|
|
335
|
+
await runGet({ ...resolveCommonOptions(command), scheduleId }, deps);
|
|
336
|
+
});
|
|
337
|
+
schedule
|
|
338
|
+
.command('create')
|
|
339
|
+
.description('Create a schedule\n' +
|
|
340
|
+
'\nExit codes:\n' +
|
|
341
|
+
' 0 success\n' +
|
|
342
|
+
' 3 auth error\n' +
|
|
343
|
+
' 4 target not found\n' +
|
|
344
|
+
' 5 validation error (e.g., missing --cron)\n' +
|
|
345
|
+
' 6 idempotency conflict\n' +
|
|
346
|
+
' 7 schedules are not available on this account\n' +
|
|
347
|
+
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
348
|
+
' 13 not available on your plan, or the plan limit is reached')
|
|
349
|
+
.option('--name <name>', 'schedule name (required)')
|
|
350
|
+
.option('--target-type <project|testList>', 'what to run (required)')
|
|
351
|
+
.option('--target-id <id>', 'project id or test-list id (required)')
|
|
352
|
+
.option('--cron <expr>', 'standard 5-field cron (minute hour day-of-month month day-of-week), ' +
|
|
353
|
+
'e.g. "0 3 * * *". Day-of-week is 0-7, with both 0 and 7 = Sunday. ' +
|
|
354
|
+
'Constrain ' +
|
|
355
|
+
'day-of-month or day-of-week, not both. (required)')
|
|
356
|
+
.option('--timezone <tz>', 'IANA timezone (default UTC)')
|
|
357
|
+
.option('--start <iso>', 'ISO 8601 start instant (default: a few minutes from now)')
|
|
358
|
+
.option('--end <iso>', 'ISO 8601 end instant (default: open-ended)')
|
|
359
|
+
.option('--send-to <emails>', 'comma-separated notification recipients')
|
|
360
|
+
.option('--idempotency-key <key>', 'reuse to retry a create safely')
|
|
361
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
362
|
+
.action(async (cmdOpts, command) => {
|
|
363
|
+
await runCreate({
|
|
364
|
+
...resolveCommonOptions(command),
|
|
365
|
+
name: cmdOpts.name,
|
|
366
|
+
targetType: cmdOpts.targetType,
|
|
367
|
+
targetId: cmdOpts.targetId,
|
|
368
|
+
cron: cmdOpts.cron,
|
|
369
|
+
timezone: cmdOpts.timezone,
|
|
370
|
+
start: cmdOpts.start,
|
|
371
|
+
end: cmdOpts.end,
|
|
372
|
+
sendTo: cmdOpts.sendTo,
|
|
373
|
+
idempotencyKey: cmdOpts.idempotencyKey,
|
|
374
|
+
}, deps);
|
|
375
|
+
});
|
|
376
|
+
schedule
|
|
377
|
+
.command('update <schedule-id>')
|
|
378
|
+
.description('Update a schedule, or pause/resume it\n' +
|
|
379
|
+
'\nExit codes:\n' +
|
|
380
|
+
' 0 success\n' +
|
|
381
|
+
' 3 auth error\n' +
|
|
382
|
+
' 4 not found\n' +
|
|
383
|
+
' 5 validation error (e.g., no fields given)\n' +
|
|
384
|
+
' 6 idempotency conflict\n' +
|
|
385
|
+
' 7 schedules are not available on this account\n' +
|
|
386
|
+
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
387
|
+
' 13 not available on your plan')
|
|
388
|
+
.option('--name <name>', 'new schedule name')
|
|
389
|
+
.option('--cron <expr>', 'new standard 5-field cron, as printed by `schedule get`. Day-of-week is ' +
|
|
390
|
+
'0-7, with both 0 and 7 = Sunday. Constrain day-of-month or day-of-week, not both.')
|
|
391
|
+
.option('--timezone <tz>', 'new IANA timezone')
|
|
392
|
+
.option('--start <iso>', 'new ISO 8601 start instant')
|
|
393
|
+
.option('--end <iso>', 'new ISO 8601 end instant')
|
|
394
|
+
.option('--send-to <emails>', 'comma-separated notification recipients')
|
|
395
|
+
.option('--pause', 'stop the schedule from running')
|
|
396
|
+
.option('--resume', 'let the schedule run again')
|
|
397
|
+
.option('--idempotency-key <key>', 'reuse to retry an update safely')
|
|
398
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
399
|
+
.action(async (scheduleId, cmdOpts, command) => {
|
|
400
|
+
await runUpdate({
|
|
401
|
+
...resolveCommonOptions(command),
|
|
402
|
+
scheduleId,
|
|
403
|
+
name: cmdOpts.name,
|
|
404
|
+
cron: cmdOpts.cron,
|
|
405
|
+
timezone: cmdOpts.timezone,
|
|
406
|
+
start: cmdOpts.start,
|
|
407
|
+
end: cmdOpts.end,
|
|
408
|
+
sendTo: cmdOpts.sendTo,
|
|
409
|
+
pause: cmdOpts.pause === true,
|
|
410
|
+
resume: cmdOpts.resume === true,
|
|
411
|
+
idempotencyKey: cmdOpts.idempotencyKey,
|
|
412
|
+
}, deps);
|
|
413
|
+
});
|
|
414
|
+
schedule
|
|
415
|
+
.command('delete <schedule-id>')
|
|
416
|
+
.description('Delete a schedule and its run history. Requires --confirm.\n' +
|
|
417
|
+
'\nExit codes:\n' +
|
|
418
|
+
' 0 success\n' +
|
|
419
|
+
' 3 auth error\n' +
|
|
420
|
+
' 4 not found\n' +
|
|
421
|
+
' 5 validation error (e.g., missing --confirm)\n' +
|
|
422
|
+
' 6 idempotency conflict\n' +
|
|
423
|
+
' 7 schedules are not available on this account\n' +
|
|
424
|
+
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
425
|
+
' 13 not available on your plan')
|
|
426
|
+
.option('--confirm', 'required: explicit confirmation for the destructive operation', false)
|
|
427
|
+
.option('--idempotency-key <key>', 'reuse to retry a delete safely')
|
|
428
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
429
|
+
.action(async (scheduleId, cmdOpts, command) => {
|
|
430
|
+
await runDelete({
|
|
431
|
+
...resolveCommonOptions(command),
|
|
432
|
+
scheduleId,
|
|
433
|
+
confirm: cmdOpts.confirm === true,
|
|
434
|
+
idempotencyKey: cmdOpts.idempotencyKey,
|
|
435
|
+
}, deps);
|
|
436
|
+
});
|
|
437
|
+
const run = schedule.command('run').description("Inspect a schedule's runs");
|
|
438
|
+
run
|
|
439
|
+
.command('list <schedule-id>')
|
|
440
|
+
.description("List a schedule's past runs\n" +
|
|
441
|
+
'\nExit codes:\n' +
|
|
442
|
+
' 0 success\n' +
|
|
443
|
+
' 3 auth error\n' +
|
|
444
|
+
' 4 not found\n' +
|
|
445
|
+
' 7 schedules are not available on this account\n' +
|
|
446
|
+
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
447
|
+
' 13 not available on your plan')
|
|
448
|
+
.option('--columns <list>', 'select/reorder text table columns (comma-separated keys)')
|
|
449
|
+
.option('--no-header', 'suppress the text table header row')
|
|
450
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
451
|
+
.action(async (scheduleId, cmdOpts, command) => {
|
|
452
|
+
await runRunList({
|
|
453
|
+
...resolveCommonOptions(command),
|
|
454
|
+
scheduleId,
|
|
455
|
+
columns: cmdOpts.columns,
|
|
456
|
+
noHeader: cmdOpts.header === false,
|
|
457
|
+
}, deps);
|
|
458
|
+
});
|
|
459
|
+
return schedule;
|
|
460
|
+
}
|
|
461
|
+
// ---------------------------------------------------------------------------
|
|
462
|
+
// Helpers
|
|
463
|
+
// ---------------------------------------------------------------------------
|
|
464
|
+
function resolveCommonOptions(command) {
|
|
465
|
+
const globals = command.optsWithGlobals();
|
|
466
|
+
return {
|
|
467
|
+
profile: globals.profile ?? 'default',
|
|
468
|
+
output: resolveOutputMode(globals.output),
|
|
469
|
+
endpointUrl: globals.endpointUrl,
|
|
470
|
+
debug: globals.debug ?? false,
|
|
471
|
+
verbose: globals.verbose ?? false,
|
|
472
|
+
dryRun: globals.dryRun ?? false,
|
|
473
|
+
requestTimeoutMs: parseRequestTimeoutFlag(globals.requestTimeout),
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function makeClient(opts, deps) {
|
|
477
|
+
return makeHttpClient(opts, {
|
|
478
|
+
env: deps.env,
|
|
479
|
+
credentialsPath: deps.credentialsPath,
|
|
480
|
+
fetchImpl: deps.fetchImpl,
|
|
481
|
+
stderr: deps.stderr,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
function makeOutput(mode, deps) {
|
|
485
|
+
return new Output(mode, { stdout: deps.stdout, stderr: deps.stderr });
|
|
486
|
+
}
|
|
487
|
+
//# sourceMappingURL=schedule.js.map
|
package/dist/commands/test.d.ts
CHANGED
|
@@ -359,6 +359,18 @@ export interface CliCreateTestResponse {
|
|
|
359
359
|
* still succeeded.
|
|
360
360
|
*/
|
|
361
361
|
warnings?: string[];
|
|
362
|
+
/**
|
|
363
|
+
* Server-built Portal deep link for the created test (DEV-737). Same
|
|
364
|
+
* presence/absence contract as `RunResponse.dashboardUrl`
|
|
365
|
+
* (`withRunDashboardUrl` below): PRESENT (string or falsy) on a backend
|
|
366
|
+
* that resolved the question at all — a falsy value means "there is no
|
|
367
|
+
* correct link for this test" (e.g. a V3-native create with no DynamoDB
|
|
368
|
+
* mirror row for the client's V2-shaped guess to land on) and must never
|
|
369
|
+
* be replaced by the client fallback; ABSENT on an older backend that
|
|
370
|
+
* predates this field, which safely reopens the client fallback via
|
|
371
|
+
* `resolveDashboardUrl` below. See that function's doc for the reasoning.
|
|
372
|
+
*/
|
|
373
|
+
dashboardUrl?: string | null;
|
|
362
374
|
}
|
|
363
375
|
export declare const CLI_CREATE_PRIORITIES: readonly ["p0", "p1", "p2", "p3"];
|
|
364
376
|
export type CliCreatePriority = (typeof CLI_CREATE_PRIORITIES)[number];
|
|
@@ -402,6 +414,8 @@ interface CreateOptions extends CommonOptions {
|
|
|
402
414
|
timeoutIsDefault?: boolean;
|
|
403
415
|
/** M3.3 chain: per-run target URL override. */
|
|
404
416
|
targetUrl?: string;
|
|
417
|
+
/** Skip the pre-charge --target-url reachability preflight (zero network calls). */
|
|
418
|
+
skipPreflight?: boolean;
|
|
405
419
|
}
|
|
406
420
|
/**
|
|
407
421
|
* `test create --code-file <path>` — M3.2 piece-2 first mutation.
|
|
@@ -671,7 +685,7 @@ export interface CliCreateFromPlanResponse extends CliCreateTestResponse {
|
|
|
671
685
|
* Caveat: the pinned tag only resolves once that version is actually
|
|
672
686
|
* released — a locally-built/pre-release checkout may see a 404 until then.
|
|
673
687
|
*/
|
|
674
|
-
export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.
|
|
688
|
+
export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.7.0/schemas/plan.schema.json";
|
|
675
689
|
/**
|
|
676
690
|
* The SINGLE canonical example plan. This
|
|
677
691
|
* exact value (via `PLAN_TEMPLATE_TEXT` below) is:
|
|
@@ -718,6 +732,12 @@ export interface CliBatchSpecResult {
|
|
|
718
732
|
message: string;
|
|
719
733
|
field?: string;
|
|
720
734
|
};
|
|
735
|
+
/**
|
|
736
|
+
* Server-built Portal deep link for this created item (DEV-737). Same
|
|
737
|
+
* presence/absence contract as `CliCreateTestResponse.dashboardUrl` —
|
|
738
|
+
* see that field's doc.
|
|
739
|
+
*/
|
|
740
|
+
dashboardUrl?: string | null;
|
|
721
741
|
}
|
|
722
742
|
export interface CliCreateBatchResponse {
|
|
723
743
|
results: CliBatchSpecResult[];
|
|
@@ -751,6 +771,13 @@ export interface CliBatchRunResult {
|
|
|
751
771
|
message: string;
|
|
752
772
|
exitCode: number;
|
|
753
773
|
};
|
|
774
|
+
/**
|
|
775
|
+
* Portal deep link (R3b), threaded through from the SAME per-item
|
|
776
|
+
* create-time decision `test create-batch`'s own output carries — never
|
|
777
|
+
* recomputed at run time. Absent when unresolvable OR explicitly
|
|
778
|
+
* suppressed by the server (see `resolveDashboardUrl`'s doc).
|
|
779
|
+
*/
|
|
780
|
+
dashboardUrl?: string;
|
|
754
781
|
}
|
|
755
782
|
/** Envelope emitted by `test create-batch --run` in JSON mode. */
|
|
756
783
|
export interface CliCreateBatchRunResponse {
|
|
@@ -875,6 +902,8 @@ interface CreateFromPlanOptions extends CommonOptions {
|
|
|
875
902
|
timeoutIsDefault?: boolean;
|
|
876
903
|
/** Reserved for the M3.3 chain. Per-run target URL override. */
|
|
877
904
|
targetUrl?: string;
|
|
905
|
+
/** Skip the pre-charge --target-url reachability preflight (zero network calls). */
|
|
906
|
+
skipPreflight?: boolean;
|
|
878
907
|
/**
|
|
879
908
|
* Names of `test create` flags the caller supplied that `--plan-from`
|
|
880
909
|
* ignores (identity lives in the JSON). Surfaced as a stderr advisory
|
|
@@ -926,6 +955,8 @@ interface CreateBatchOptions extends CommonOptions {
|
|
|
926
955
|
timeoutSeconds?: number;
|
|
927
956
|
/** With `--run`, override the project default env URL for each triggered run. */
|
|
928
957
|
targetUrl?: string;
|
|
958
|
+
/** Skip the pre-charge --target-url reachability preflight (zero network calls). */
|
|
959
|
+
skipPreflight?: boolean;
|
|
929
960
|
}
|
|
930
961
|
/**
|
|
931
962
|
* `test create-batch --plans <plans.jsonl>` — M3.2 piece-5.
|
|
@@ -1358,6 +1389,14 @@ export declare function runFailureGet(opts: FailureGetOptions, deps?: TestDeps):
|
|
|
1358
1389
|
interface RunTestRunOptions extends CommonOptions {
|
|
1359
1390
|
testId: string;
|
|
1360
1391
|
targetUrl?: string;
|
|
1392
|
+
/**
|
|
1393
|
+
* Skip the pre-charge --target-url reachability preflight (zero
|
|
1394
|
+
* network calls). Also set by a delegating caller (`runCreate`/
|
|
1395
|
+
* `runCreateFromPlan` chaining `--run`) that already ran the same probe
|
|
1396
|
+
* against the same URL before its own create POST, so this run doesn't
|
|
1397
|
+
* probe twice.
|
|
1398
|
+
*/
|
|
1399
|
+
skipPreflight?: boolean;
|
|
1361
1400
|
wait: boolean;
|
|
1362
1401
|
timeoutSeconds: number;
|
|
1363
1402
|
/**
|
|
@@ -1368,6 +1407,14 @@ interface RunTestRunOptions extends CommonOptions {
|
|
|
1368
1407
|
*/
|
|
1369
1408
|
timeoutIsDefault?: boolean;
|
|
1370
1409
|
idempotencyKey?: string;
|
|
1410
|
+
/**
|
|
1411
|
+
* --gh-output: force the GitHub-native output layer (::error:: annotations +
|
|
1412
|
+
* job-summary table) even off-Actions. On the single-test `--wait` path the
|
|
1413
|
+
* result is reduced to a one-row CI summary (`summarizeSingleRun`).
|
|
1414
|
+
*/
|
|
1415
|
+
ghOutput?: boolean;
|
|
1416
|
+
/** --summary-file: also write the reduced machine summary JSON to this path. */
|
|
1417
|
+
summaryFile?: string;
|
|
1371
1418
|
/**
|
|
1372
1419
|
* Per codex round-1 P1: when chained from `test create --run`, the caller
|
|
1373
1420
|
* passes the create response here so `runTestRun` can emit a single merged
|
|
@@ -1449,6 +1496,13 @@ interface RunTestRerunOptions extends CommonOptions {
|
|
|
1449
1496
|
reportFile?: string;
|
|
1450
1497
|
/** --report-suite-name: optional override for the JUnit <testsuite name=...>. */
|
|
1451
1498
|
reportSuiteName?: string;
|
|
1499
|
+
/**
|
|
1500
|
+
* --gh-output: force the GitHub-native output layer (::error:: annotations +
|
|
1501
|
+
* job-summary table) on the batch-rerun `--wait` result, even off-Actions.
|
|
1502
|
+
*/
|
|
1503
|
+
ghOutput?: boolean;
|
|
1504
|
+
/** --summary-file: also write the reduced machine summary JSON to this path. */
|
|
1505
|
+
summaryFile?: string;
|
|
1452
1506
|
}
|
|
1453
1507
|
/**
|
|
1454
1508
|
* Decide whether a testId-scoped result belongs to THIS run (vs a stale
|