@testsprite/testsprite-cli 0.6.0 → 0.8.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 +52 -31
- package/dist/commands/agent.js +91 -45
- package/dist/commands/ci.d.ts +88 -0
- package/dist/commands/ci.js +429 -0
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.js +104 -8
- package/dist/commands/init.js +8 -0
- package/dist/commands/project.d.ts +78 -0
- package/dist/commands/project.js +429 -5
- package/dist/commands/schedule.d.ts +120 -0
- package/dist/commands/schedule.js +487 -0
- package/dist/commands/test.d.ts +176 -2
- package/dist/commands/test.js +2235 -609
- package/dist/commands/testlist.d.ts +88 -0
- package/dist/commands/testlist.js +753 -0
- package/dist/commands/tunnel.d.ts +72 -0
- package/dist/commands/tunnel.js +367 -0
- package/dist/index.js +113 -40
- 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.d.ts +9 -0
- package/dist/lib/dry-run/samples.js +293 -55
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.js +11 -0
- package/dist/lib/gh-output.d.ts +33 -1
- package/dist/lib/gh-output.js +97 -27
- package/dist/lib/http.d.ts +119 -0
- package/dist/lib/http.js +243 -2
- package/dist/lib/interrupt.d.ts +38 -13
- package/dist/lib/interrupt.js +130 -15
- package/dist/lib/junit-report.d.ts +20 -2
- package/dist/lib/junit-report.js +38 -5
- package/dist/lib/local-target.d.ts +95 -0
- package/dist/lib/local-target.js +184 -0
- package/dist/lib/plan-poll.d.ts +171 -0
- package/dist/lib/plan-poll.js +442 -0
- package/dist/lib/plans.types.d.ts +130 -0
- package/dist/lib/plans.types.js +31 -0
- package/dist/lib/poll-support.d.ts +26 -0
- package/dist/lib/poll-support.js +65 -0
- package/dist/lib/poll.d.ts +1 -0
- package/dist/lib/poll.js +2 -40
- package/dist/lib/proxy.d.ts +16 -0
- package/dist/lib/proxy.js +19 -1
- package/dist/lib/response-schemas.d.ts +20 -0
- package/dist/lib/response-schemas.js +55 -1
- package/dist/lib/run-progress.d.ts +41 -0
- package/dist/lib/run-progress.js +56 -0
- package/dist/lib/runs.types.d.ts +32 -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 +63 -9
- package/dist/lib/target-url.js +283 -62
- package/dist/lib/telemetry.d.ts +11 -0
- package/dist/lib/telemetry.js +1 -0
- package/dist/lib/testlist.types.d.ts +77 -0
- package/dist/lib/testlist.types.js +9 -0
- package/dist/lib/ticker.d.ts +8 -0
- package/dist/lib/ticker.js +3 -0
- package/dist/lib/tunnel-session.d.ts +129 -0
- package/dist/lib/tunnel-session.js +232 -0
- package/dist/lib/tunnel.types.d.ts +54 -0
- package/dist/lib/tunnel.types.js +8 -0
- package/dist/lib/v3-advisory.d.ts +35 -22
- package/dist/lib/v3-advisory.js +44 -24
- package/dist/lib/wait-exit.d.ts +29 -0
- package/dist/lib/wait-exit.js +103 -0
- package/dist/vendor/tunnel-client/client.d.ts +83 -0
- package/dist/vendor/tunnel-client/client.js +871 -0
- package/dist/vendor/tunnel-client/config.d.ts +41 -0
- package/dist/vendor/tunnel-client/config.js +42 -0
- package/dist/vendor/tunnel-client/index.d.ts +9 -0
- package/dist/vendor/tunnel-client/index.js +9 -0
- package/dist/vendor/tunnel-client/lodash-lite.d.ts +14 -0
- package/dist/vendor/tunnel-client/lodash-lite.js +24 -0
- package/dist/vendor/tunnel-client/protocol.d.ts +60 -0
- package/dist/vendor/tunnel-client/protocol.js +143 -0
- package/dist/vendor/tunnel-client/types.d.ts +96 -0
- package/dist/vendor/tunnel-client/types.js +10 -0
- package/dist/vendor/tunnel-client/ws-compat.d.ts +206 -0
- package/dist/vendor/tunnel-client/ws-compat.js +316 -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
- package/skills/testsprite-onboard.skill.md +60 -4
- package/skills/testsprite-verify.codex.md +22 -16
- package/skills/testsprite-verify.skill.md +27 -18
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factory.js';
|
|
3
|
+
import type { FetchImpl } from '../lib/http.js';
|
|
4
|
+
/** A schedule as returned by the API. */
|
|
5
|
+
export interface CliSchedule {
|
|
6
|
+
scheduleId: string;
|
|
7
|
+
name: string;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
targetType: 'project' | 'testList';
|
|
10
|
+
/** Project id when `targetType` is `project`, else the test-list id. */
|
|
11
|
+
targetId: string | null;
|
|
12
|
+
cron: string | null;
|
|
13
|
+
timezone: string | null;
|
|
14
|
+
startAt: string | null;
|
|
15
|
+
endAt: string | null;
|
|
16
|
+
/** Comma-separated notification recipients. */
|
|
17
|
+
sendTo: string | null;
|
|
18
|
+
/** Set when the schedule was disabled automatically after repeated failures. */
|
|
19
|
+
autoPausedAt: string | null;
|
|
20
|
+
/** Most recent run, or null if it has never run. */
|
|
21
|
+
lastRunId: string | null;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
updatedAt: string;
|
|
24
|
+
}
|
|
25
|
+
/** `GET /schedules` response. Not paginated. */
|
|
26
|
+
interface ScheduleListResponse {
|
|
27
|
+
schedules: CliSchedule[];
|
|
28
|
+
}
|
|
29
|
+
export interface ScheduleDeps {
|
|
30
|
+
env?: NodeJS.ProcessEnv;
|
|
31
|
+
credentialsPath?: string;
|
|
32
|
+
fetchImpl?: FetchImpl;
|
|
33
|
+
stdout?: (line: string) => void;
|
|
34
|
+
stderr?: (line: string) => void;
|
|
35
|
+
}
|
|
36
|
+
type CommonOptions = FactoryCommonOptions;
|
|
37
|
+
interface ListOptions extends CommonOptions {
|
|
38
|
+
columns?: string;
|
|
39
|
+
noHeader?: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface GetOptions extends CommonOptions {
|
|
42
|
+
scheduleId: string;
|
|
43
|
+
}
|
|
44
|
+
export interface CreateOptions extends CommonOptions {
|
|
45
|
+
name?: string;
|
|
46
|
+
targetType?: string;
|
|
47
|
+
targetId?: string;
|
|
48
|
+
cron?: string;
|
|
49
|
+
timezone?: string;
|
|
50
|
+
start?: string;
|
|
51
|
+
end?: string;
|
|
52
|
+
sendTo?: string;
|
|
53
|
+
idempotencyKey?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface CliCreateScheduleResponse {
|
|
56
|
+
scheduleId: string;
|
|
57
|
+
/**
|
|
58
|
+
* Approximate credits ONE run of this schedule will consume, as calculated by
|
|
59
|
+
* the API from the target's live case count. `null` when it could not be
|
|
60
|
+
* determined, absent on an API that does not supply it.
|
|
61
|
+
*
|
|
62
|
+
* Per run rather than per month because the API knows the price of a run and
|
|
63
|
+
* this side knows how often the cron fires; neither knows both.
|
|
64
|
+
*/
|
|
65
|
+
estimatedCreditsPerRun?: number | null;
|
|
66
|
+
}
|
|
67
|
+
export interface UpdateOptions extends CommonOptions {
|
|
68
|
+
scheduleId: string;
|
|
69
|
+
name?: string;
|
|
70
|
+
cron?: string;
|
|
71
|
+
timezone?: string;
|
|
72
|
+
start?: string;
|
|
73
|
+
end?: string;
|
|
74
|
+
sendTo?: string;
|
|
75
|
+
pause?: boolean;
|
|
76
|
+
resume?: boolean;
|
|
77
|
+
idempotencyKey?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface DeleteOptions extends CommonOptions {
|
|
80
|
+
scheduleId: string;
|
|
81
|
+
confirm?: boolean;
|
|
82
|
+
idempotencyKey?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface CliDeleteScheduleResponse {
|
|
85
|
+
scheduleId: string;
|
|
86
|
+
}
|
|
87
|
+
export interface RunListOptions extends CommonOptions {
|
|
88
|
+
scheduleId: string;
|
|
89
|
+
columns?: string;
|
|
90
|
+
noHeader?: boolean;
|
|
91
|
+
}
|
|
92
|
+
export interface CliScheduleRun {
|
|
93
|
+
runId: string;
|
|
94
|
+
scheduleId: string | null;
|
|
95
|
+
status: 'queued' | 'running' | 'passed' | 'failed' | 'blocked' | 'cancelled';
|
|
96
|
+
projectId: string | null;
|
|
97
|
+
testListId: string | null;
|
|
98
|
+
stats: {
|
|
99
|
+
total: number;
|
|
100
|
+
passed: number;
|
|
101
|
+
failed: number;
|
|
102
|
+
blocked: number;
|
|
103
|
+
running: number;
|
|
104
|
+
cancelled: number;
|
|
105
|
+
};
|
|
106
|
+
createdAt: string;
|
|
107
|
+
updatedAt: string;
|
|
108
|
+
}
|
|
109
|
+
/** `GET /schedules/{id}/runs` response. Not paginated. */
|
|
110
|
+
interface ScheduleRunListResponse {
|
|
111
|
+
runs: CliScheduleRun[];
|
|
112
|
+
}
|
|
113
|
+
export declare function runList(opts: ListOptions, deps?: ScheduleDeps): Promise<ScheduleListResponse>;
|
|
114
|
+
export declare function runGet(opts: GetOptions, deps?: ScheduleDeps): Promise<CliSchedule>;
|
|
115
|
+
export declare function runCreate(opts: CreateOptions, deps?: ScheduleDeps): Promise<CliCreateScheduleResponse>;
|
|
116
|
+
export declare function runUpdate(opts: UpdateOptions, deps?: ScheduleDeps): Promise<CliSchedule>;
|
|
117
|
+
export declare function runDelete(opts: DeleteOptions, deps?: ScheduleDeps): Promise<CliDeleteScheduleResponse>;
|
|
118
|
+
export declare function runRunList(opts: RunListOptions, deps?: ScheduleDeps): Promise<ScheduleRunListResponse>;
|
|
119
|
+
export declare function createScheduleCommand(deps?: ScheduleDeps): Command;
|
|
120
|
+
export {};
|
|
@@ -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
|