@testsprite/testsprite-cli 0.16.0 → 0.17.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 +51 -147
- package/dist/commands/agent.d.ts +12 -4
- package/dist/commands/agent.js +48 -63
- package/dist/commands/auth.d.ts +6 -10
- package/dist/commands/auth.js +38 -54
- package/dist/commands/ci.d.ts +23 -100
- package/dist/commands/ci.js +293 -487
- package/dist/commands/conversation.d.ts +27 -0
- package/dist/commands/conversation.js +702 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +129 -34
- package/dist/commands/init.d.ts +4 -45
- package/dist/commands/init.js +108 -66
- package/dist/commands/project-env.d.ts +62 -2
- package/dist/commands/project-env.js +388 -37
- package/dist/commands/project-sign-in.d.ts +0 -48
- package/dist/commands/project-sign-in.js +1 -229
- package/dist/commands/project.d.ts +15 -186
- package/dist/commands/project.js +89 -924
- package/dist/commands/result.d.ts +10 -0
- package/dist/commands/result.js +215 -0
- package/dist/commands/schedule.d.ts +0 -29
- package/dist/commands/schedule.js +28 -87
- package/dist/commands/test.d.ts +301 -1816
- package/dist/commands/test.js +1951 -13902
- package/dist/commands/testlist.d.ts +128 -5
- package/dist/commands/testlist.js +269 -339
- package/dist/commands/tunnel.d.ts +2 -2
- package/dist/commands/tunnel.js +23 -19
- package/dist/commands/usage.d.ts +12 -45
- package/dist/commands/usage.js +50 -131
- package/dist/index.js +182 -104
- package/dist/lib/agent-detect.js +9 -5
- package/dist/lib/agent-targets.d.ts +21 -2
- package/dist/lib/agent-targets.js +88 -11
- package/dist/lib/args.d.ts +13 -0
- package/dist/lib/args.js +49 -0
- package/dist/lib/basic-auth.d.ts +3 -0
- package/dist/lib/basic-auth.js +15 -0
- package/dist/lib/billing-refusal.js +4 -3
- package/dist/lib/ci-linkage.d.ts +4 -82
- package/dist/lib/ci-linkage.js +4 -157
- package/dist/lib/ci-run.js +1 -1
- package/dist/lib/client-factory.d.ts +10 -2
- package/dist/lib/client-factory.js +38 -26
- package/dist/lib/commit-signal.d.ts +65 -0
- package/dist/lib/commit-signal.js +305 -0
- package/dist/lib/concurrency-limiter.d.ts +6 -0
- package/dist/lib/concurrency-limiter.js +29 -0
- package/dist/lib/config.js +10 -5
- package/dist/lib/conflict-reason.d.ts +9 -3
- package/dist/lib/conflict-reason.js +6 -3
- package/dist/lib/conversation/answers.d.ts +9 -0
- package/dist/lib/conversation/answers.js +49 -0
- package/dist/lib/conversation/api.d.ts +71 -0
- package/dist/lib/conversation/api.js +150 -0
- package/dist/lib/conversation/change.d.ts +31 -0
- package/dist/lib/conversation/change.js +124 -0
- package/dist/lib/conversation/context.d.ts +19 -0
- package/dist/lib/conversation/context.js +70 -0
- package/dist/lib/conversation/environment.d.ts +15 -0
- package/dist/lib/conversation/environment.js +33 -0
- package/dist/lib/conversation/follow.d.ts +24 -0
- package/dist/lib/conversation/follow.js +42 -0
- package/dist/lib/conversation/render.d.ts +33 -0
- package/dist/lib/conversation/render.js +315 -0
- package/dist/lib/conversation/title.d.ts +2 -0
- package/dist/lib/conversation/title.js +18 -0
- package/dist/lib/conversation/types.d.ts +156 -0
- package/dist/lib/conversation/types.js +6 -0
- package/dist/lib/credentials.js +67 -11
- package/dist/lib/cron.d.ts +1 -1
- package/dist/lib/cron.js +2 -2
- package/dist/lib/dispatch-stop.d.ts +20 -0
- package/dist/lib/dispatch-stop.js +30 -0
- package/dist/lib/download.d.ts +71 -0
- package/dist/lib/download.js +274 -0
- package/dist/lib/dry-run/fetch.d.ts +10 -0
- package/dist/lib/dry-run/fetch.js +20 -0
- package/dist/lib/dry-run/samples.d.ts +6 -34
- package/dist/lib/dry-run/samples.js +375 -747
- package/dist/lib/environment-tunnel.d.ts +16 -27
- package/dist/lib/environment-tunnel.js +161 -154
- package/dist/lib/errors.d.ts +20 -4
- package/dist/lib/errors.js +36 -16
- package/dist/lib/facade.d.ts +7 -29
- package/dist/lib/facade.js +7 -36
- package/dist/lib/failing-fe-resolver.d.ts +13 -58
- package/dist/lib/failing-fe-resolver.js +47 -132
- package/dist/lib/first-suite-hint.d.ts +16 -22
- package/dist/lib/first-suite-hint.js +38 -47
- package/dist/lib/gh-output.d.ts +76 -21
- package/dist/lib/gh-output.js +171 -90
- package/dist/lib/git-utils.d.ts +56 -0
- package/dist/lib/git-utils.js +212 -0
- package/dist/lib/github-context.d.ts +2 -0
- package/dist/lib/github-context.js +40 -8
- package/dist/lib/history-retention.d.ts +6 -2
- package/dist/lib/history-retention.js +10 -7
- package/dist/lib/http.d.ts +58 -134
- package/dist/lib/http.js +352 -289
- package/dist/lib/interrupt.d.ts +14 -8
- package/dist/lib/interrupt.js +28 -10
- package/dist/lib/junit-report.d.ts +57 -4
- package/dist/lib/junit-report.js +202 -32
- package/dist/lib/local-target.d.ts +3 -3
- package/dist/lib/local-target.js +3 -3
- package/dist/lib/output.d.ts +1 -40
- package/dist/lib/output.js +11 -49
- package/dist/lib/pagination.d.ts +2 -5
- package/dist/lib/pagination.js +2 -5
- package/dist/lib/presigned-url.d.ts +22 -0
- package/dist/lib/presigned-url.js +90 -0
- package/dist/lib/prompt.js +36 -2
- package/dist/lib/proxy.js +2 -1
- package/dist/lib/redact.d.ts +2 -2
- package/dist/lib/redact.js +3 -4
- package/dist/lib/removed-commands.d.ts +18 -0
- package/dist/lib/removed-commands.js +154 -0
- package/dist/lib/render-error.d.ts +31 -6
- package/dist/lib/render-error.js +88 -25
- package/dist/lib/response-schemas.d.ts +38 -30
- package/dist/lib/response-schemas.js +207 -207
- package/dist/lib/result/api.d.ts +24 -0
- package/dist/lib/result/api.js +28 -0
- package/dist/lib/result/evidence.d.ts +71 -0
- package/dist/lib/result/evidence.js +420 -0
- package/dist/lib/result/render.d.ts +20 -0
- package/dist/lib/result/render.js +194 -0
- package/dist/lib/result/types.d.ts +122 -0
- package/dist/lib/result/types.js +19 -0
- package/dist/lib/run-output.d.ts +275 -0
- package/dist/lib/run-output.js +227 -0
- package/dist/lib/run-render.d.ts +101 -0
- package/dist/lib/run-render.js +183 -0
- package/dist/lib/run-wait.d.ts +192 -0
- package/dist/lib/run-wait.js +452 -0
- package/dist/lib/runs.types.d.ts +118 -367
- package/dist/lib/runs.types.js +0 -14
- package/dist/lib/secret-file.d.ts +1 -1
- package/dist/lib/secret-file.js +11 -2
- package/dist/lib/skill-nudge.d.ts +7 -27
- package/dist/lib/skill-nudge.js +9 -37
- package/dist/lib/target-path.d.ts +15 -0
- package/dist/lib/target-path.js +35 -0
- package/dist/lib/target-url-advisory.d.ts +19 -0
- package/dist/lib/target-url-advisory.js +31 -0
- package/dist/lib/target-url-preflight.d.ts +9 -0
- package/dist/lib/target-url-preflight.js +214 -106
- package/dist/lib/target-url.d.ts +1 -1
- package/dist/lib/target-url.js +6 -16
- package/dist/lib/telemetry.d.ts +31 -11
- package/dist/lib/telemetry.js +37 -8
- package/dist/lib/terminal-text.d.ts +41 -0
- package/dist/lib/terminal-text.js +127 -0
- package/dist/lib/testlist.types.d.ts +16 -8
- package/dist/lib/testlist.types.js +1 -1
- package/dist/lib/text-equality.d.ts +2 -0
- package/dist/lib/text-equality.js +5 -0
- package/dist/lib/text-file.d.ts +16 -0
- package/dist/lib/text-file.js +41 -0
- package/dist/lib/text-table.d.ts +46 -0
- package/dist/lib/text-table.js +72 -4
- package/dist/lib/ticker.d.ts +9 -2
- package/dist/lib/ticker.js +16 -3
- package/dist/lib/transport-failure.d.ts +22 -0
- package/dist/lib/transport-failure.js +126 -0
- package/dist/lib/tunnel-session.d.ts +7 -1
- package/dist/lib/tunnel-session.js +22 -9
- package/dist/lib/update-check.js +3 -2
- package/dist/lib/url-template.d.ts +43 -0
- package/dist/lib/url-template.js +151 -0
- package/dist/lib/validate.d.ts +0 -64
- package/dist/lib/validate.js +2 -131
- package/dist/lib/version-notice.js +4 -3
- package/dist/lib/wait-exit.d.ts +37 -2
- package/dist/lib/wait-exit.js +88 -30
- package/dist/lib/workspace-status.js +10 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -3
- package/skills/testsprite-ci.skill.md +48 -18
- package/skills/testsprite-onboard.skill.md +66 -151
- package/skills/testsprite-verify.codex.md +50 -52
- package/skills/testsprite-verify.skill.md +184 -351
- package/dist/lib/browser.d.ts +0 -6
- package/dist/lib/browser.js +0 -54
- package/dist/lib/bundle.d.ts +0 -234
- package/dist/lib/bundle.js +0 -781
- package/dist/lib/deprecate.d.ts +0 -32
- package/dist/lib/deprecate.js +0 -39
- package/dist/lib/flaky.d.ts +0 -91
- package/dist/lib/flaky.js +0 -71
- package/dist/lib/plan-poll.d.ts +0 -171
- package/dist/lib/plan-poll.js +0 -441
- package/dist/lib/plans.types.d.ts +0 -130
- package/dist/lib/plans.types.js +0 -31
- package/dist/lib/poll.d.ts +0 -100
- package/dist/lib/poll.js +0 -290
- package/dist/lib/rate-throttle.d.ts +0 -49
- package/dist/lib/rate-throttle.js +0 -75
- package/dist/lib/run-progress.d.ts +0 -41
- package/dist/lib/run-progress.js +0 -56
- package/dist/lib/v3-advisory.d.ts +0 -55
- package/dist/lib/v3-advisory.js +0 -74
- package/schemas/plan.schema.json +0 -61
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import type { FetchImpl } from '../lib/http.js';
|
|
3
|
+
export interface ResultDeps {
|
|
4
|
+
env?: NodeJS.ProcessEnv;
|
|
5
|
+
credentialsPath?: string;
|
|
6
|
+
fetchImpl?: FetchImpl;
|
|
7
|
+
stdout?: (line: string) => void;
|
|
8
|
+
stderr?: (line: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function createResultCommand(deps?: ResultDeps): Command;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { makeHttpClient, resolveCommonOptions } from '../lib/client-factory.js';
|
|
3
|
+
import { assertOutDirParentExists, resolveOutDir } from '../lib/download.js';
|
|
4
|
+
import { ApiError, localValidationError } from '../lib/errors.js';
|
|
5
|
+
import { historyRetentionNote } from '../lib/history-retention.js';
|
|
6
|
+
import { GLOBAL_OPTS_HINT, Output } from '../lib/output.js';
|
|
7
|
+
import { resultApi } from '../lib/result/api.js';
|
|
8
|
+
import { hasFailedStep, planEvidence, RESULT_FILE, writeEvidence, } from '../lib/result/evidence.js';
|
|
9
|
+
import { renderEvidence, renderResultDetail, renderResultList } from '../lib/result/render.js';
|
|
10
|
+
import { ALL_RESULT_STATUSES } from '../lib/result/types.js';
|
|
11
|
+
import { terminalSafeWriter } from '../lib/terminal-text.js';
|
|
12
|
+
const MAX_LIMIT = 100;
|
|
13
|
+
export function createResultCommand(deps = {}) {
|
|
14
|
+
const result = new Command('result').description('List and read test results');
|
|
15
|
+
result
|
|
16
|
+
.command('list')
|
|
17
|
+
.summary('List the results of a run or of a test')
|
|
18
|
+
.description("List the results of one run (--run <run-id>), or one test's results across runs,\n" +
|
|
19
|
+
'newest first (--test <test-id>). A run id is the runId testsprite run prints;\n' +
|
|
20
|
+
"a result is one test's part of a run, printed as resultId.\n" +
|
|
21
|
+
'\nRead one result with: testsprite result get <result-id>\n' +
|
|
22
|
+
'\nExit codes:\n' +
|
|
23
|
+
' 0 listed, whatever the verdicts\n' +
|
|
24
|
+
' 3 auth error\n' +
|
|
25
|
+
' 4 run or test not found\n' +
|
|
26
|
+
' 5 validation error')
|
|
27
|
+
.option('--run <run-id>', 'list the results of this run')
|
|
28
|
+
.option('--test <test-id>', "list this test's results, newest first")
|
|
29
|
+
.option('--status <list>', `keep only these statuses: ${ALL_RESULT_STATUSES.join(', ')} (comma-separated or ` +
|
|
30
|
+
'repeated, any case). Running includes queued results. Cancelled results are listed only when named', (value, previous = []) => [...previous, value])
|
|
31
|
+
.option('--env <name>', 'with --test: only results from this project environment')
|
|
32
|
+
.option('--limit <n>', `with --test: how many results (1-${MAX_LIMIT}, default 20)`)
|
|
33
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
34
|
+
.action(async (flags, command) => {
|
|
35
|
+
await runResultList(resolveCommonOptions(command, deps.env), flags, deps);
|
|
36
|
+
});
|
|
37
|
+
result
|
|
38
|
+
.command('get <result-id>')
|
|
39
|
+
.summary('Read one result: verdict, cause, failed step')
|
|
40
|
+
.description("Read one result: its verdict, error, cause and fix, the failed step's screenshot and\n" +
|
|
41
|
+
"the video. A result is one test's part of a run, printed as resultId. Every step is\n" +
|
|
42
|
+
'in --output json.\n' +
|
|
43
|
+
'\nWith --out <dir>, download it instead: result.json (the result, each link replaced\n' +
|
|
44
|
+
"by the file it was written to), the video, and each step's screenshot and page as\n" +
|
|
45
|
+
'steps/001.png, steps/001.html, ...; a result blocked at sign-in adds the sign-in\n' +
|
|
46
|
+
"run's video and steps under sign-in/. <dir> is created if missing. In an existing\n" +
|
|
47
|
+
'<dir>, result.json, video.<mp4|webm|mov|mkv|avi>, steps/ and sign-in/ are replaced\n' +
|
|
48
|
+
'once the download ends, and every other file is left alone; a file that fails keeps\n' +
|
|
49
|
+
'the copy an earlier download of the same result left.\n' +
|
|
50
|
+
'\nExit codes:\n' +
|
|
51
|
+
' 0 read, whatever the verdict (with --out: every file written)\n' +
|
|
52
|
+
' 3 auth error\n' +
|
|
53
|
+
' 4 result not found\n' +
|
|
54
|
+
' 5 validation error\n' +
|
|
55
|
+
' 10 with --out: a file could not be downloaded; the others and result.json are written')
|
|
56
|
+
.option('--out <dir>', "write the result and its evidence (video, each step's files) into <dir>")
|
|
57
|
+
.option('--failed-only', 'with --out: only the failed steps and one step on each side (every step when none failed)')
|
|
58
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
59
|
+
.action(async (resultId, flags, command) => {
|
|
60
|
+
await runResultGet(resolveCommonOptions(command, deps.env), resultId, flags, deps);
|
|
61
|
+
});
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
async function runResultList(opts, flags, deps) {
|
|
65
|
+
const query = listQuery(flags);
|
|
66
|
+
const client = makeClient(opts, deps);
|
|
67
|
+
const api = resultApi(client);
|
|
68
|
+
const list = await ('run' in query
|
|
69
|
+
? api.listByRun(query.run, query.statuses)
|
|
70
|
+
: api.listByTest(query.test, {
|
|
71
|
+
statuses: query.statuses,
|
|
72
|
+
env: query.env,
|
|
73
|
+
limit: query.limit,
|
|
74
|
+
}));
|
|
75
|
+
makeOutput(opts, deps).print(list, data => renderResultList(data));
|
|
76
|
+
if (opts.output !== 'text')
|
|
77
|
+
return list;
|
|
78
|
+
const stderr = stderrOf(deps);
|
|
79
|
+
// Only a test's history is cut by the plan's window; a run is listed whole.
|
|
80
|
+
const note = 'test' in query
|
|
81
|
+
? historyRetentionNote({ hiddenCount: list.hiddenRunCount, retentionDays: list.retentionDays }, client.resolvedBaseUrl, 'result')
|
|
82
|
+
: undefined;
|
|
83
|
+
// The server leaves cancelled results out unless `status` names them, so an
|
|
84
|
+
// empty list may be one whose only results were cancelled. When the plan's
|
|
85
|
+
// window hides results, that is the explanation given instead.
|
|
86
|
+
if (list.results.length === 0 && query.statuses === undefined && !note) {
|
|
87
|
+
stderr('If its results were cancelled, list them with --status cancelled.');
|
|
88
|
+
}
|
|
89
|
+
if (note)
|
|
90
|
+
stderr(note);
|
|
91
|
+
return list;
|
|
92
|
+
}
|
|
93
|
+
async function runResultGet(opts, resultId, flags, deps) {
|
|
94
|
+
if (flags.failedOnly && flags.out === undefined) {
|
|
95
|
+
throw localValidationError('failed-only', '--failed-only only applies with --out (it narrows what is downloaded). Add --out <dir>, or remove --failed-only');
|
|
96
|
+
}
|
|
97
|
+
if (resultId.trim() === '') {
|
|
98
|
+
throw localValidationError('result-id', 'cannot be empty or whitespace-only', undefined, 'argument');
|
|
99
|
+
}
|
|
100
|
+
const dir = flags.out === undefined ? undefined : resolveOutDir(flags.out);
|
|
101
|
+
if (dir !== undefined)
|
|
102
|
+
await assertOutDirParentExists(dir);
|
|
103
|
+
const client = makeClient(opts, deps);
|
|
104
|
+
const detail = await resultApi(client).get(resultId);
|
|
105
|
+
const output = makeOutput(opts, deps);
|
|
106
|
+
if (dir === undefined) {
|
|
107
|
+
output.print(detail, data => renderResultDetail(data));
|
|
108
|
+
return detail;
|
|
109
|
+
}
|
|
110
|
+
if (opts.dryRun) {
|
|
111
|
+
const planned = planEvidence(detail, flags.failedOnly).map(({ file }) => file);
|
|
112
|
+
const preview = { dir, written: [...planned, RESULT_FILE], failed: [] };
|
|
113
|
+
output.print(preview, data => renderEvidence(data, true));
|
|
114
|
+
return detail;
|
|
115
|
+
}
|
|
116
|
+
// Downloads go straight to storage with the bare fetch: the signed link is
|
|
117
|
+
// the credential, and the API key stays with the API.
|
|
118
|
+
const evidence = await writeEvidence(detail, {
|
|
119
|
+
dir,
|
|
120
|
+
warn: stderrOf(deps),
|
|
121
|
+
failedOnly: flags.failedOnly,
|
|
122
|
+
fetchImpl: deps.fetchImpl,
|
|
123
|
+
});
|
|
124
|
+
output.print(evidence, data => renderEvidence(data));
|
|
125
|
+
// With no step at all there is nothing to say "every step" of.
|
|
126
|
+
const steps = detail.steps.length + (detail.signIn?.steps.length ?? 0);
|
|
127
|
+
if (flags.failedOnly && opts.output === 'text' && steps > 0 && !hasFailedStep(detail)) {
|
|
128
|
+
stderrOf(deps)('No failed step; downloaded every step.');
|
|
129
|
+
}
|
|
130
|
+
if (evidence.failed.length > 0)
|
|
131
|
+
throw notDownloaded(resultId, evidence);
|
|
132
|
+
return detail;
|
|
133
|
+
}
|
|
134
|
+
/** A download that left files out: UNAVAILABLE, as an incomplete download has always been. */
|
|
135
|
+
function notDownloaded(resultId, evidence) {
|
|
136
|
+
// The evidence files planned: every one written but result.json, and every one that failed.
|
|
137
|
+
const planned = evidence.written.length - 1 + evidence.failed.length;
|
|
138
|
+
return ApiError.fromEnvelope({
|
|
139
|
+
error: {
|
|
140
|
+
code: 'UNAVAILABLE',
|
|
141
|
+
message: `${evidence.failed.length} of ${planned} evidence files could not be downloaded.`,
|
|
142
|
+
// A failure is not always an expired link (a dead network, a full disk):
|
|
143
|
+
// each file's reason says which.
|
|
144
|
+
nextAction: `Run testsprite result get ${resultId} --out <dir> again: each read signs new links. ` +
|
|
145
|
+
"See each file's reason above.",
|
|
146
|
+
requestId: 'local',
|
|
147
|
+
details: { failed: evidence.failed },
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/** The flags of `result list` as one query, refused (exit 5) before anything is sent. */
|
|
152
|
+
function listQuery(flags) {
|
|
153
|
+
if (flags.run !== undefined && flags.test !== undefined) {
|
|
154
|
+
throw localValidationError('test', '--test and --run are mutually exclusive: pass --test <test-id> or --run <run-id>, not both');
|
|
155
|
+
}
|
|
156
|
+
if (flags.run === undefined && flags.test === undefined) {
|
|
157
|
+
throw localValidationError('test', "pass --test <test-id> (one test's results) or --run <run-id> (one run's results)");
|
|
158
|
+
}
|
|
159
|
+
const statuses = flags.status === undefined ? undefined : parseStatuses(flags.status);
|
|
160
|
+
if (flags.run !== undefined) {
|
|
161
|
+
const testOnly = flags.env !== undefined ? 'env' : flags.limit !== undefined ? 'limit' : undefined;
|
|
162
|
+
if (testOnly !== undefined) {
|
|
163
|
+
throw localValidationError(testOnly, `--${testOnly} only applies with --test (it narrows one test's history). Remove --${testOnly}, or list with --test <test-id>`);
|
|
164
|
+
}
|
|
165
|
+
return { run: nonEmpty(flags.run, 'run'), statuses };
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
test: nonEmpty(flags.test, 'test'),
|
|
169
|
+
statuses,
|
|
170
|
+
env: flags.env === undefined ? undefined : nonEmpty(flags.env, 'env'),
|
|
171
|
+
limit: flags.limit === undefined ? undefined : parseLimit(flags.limit),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function nonEmpty(value, flag) {
|
|
175
|
+
if (value.trim() === '')
|
|
176
|
+
throw localValidationError(flag, 'must not be empty');
|
|
177
|
+
return value;
|
|
178
|
+
}
|
|
179
|
+
/** `--status` values, comma-separated or repeated and in any case, as the server spells them. */
|
|
180
|
+
function parseStatuses(values) {
|
|
181
|
+
const accepted = ALL_RESULT_STATUSES;
|
|
182
|
+
const named = values
|
|
183
|
+
.flatMap(value => value.split(','))
|
|
184
|
+
.map(status => status.trim().toLowerCase())
|
|
185
|
+
.filter(Boolean);
|
|
186
|
+
const unknown = named.filter(status => !accepted.includes(status));
|
|
187
|
+
if (named.length === 0 || unknown.length > 0) {
|
|
188
|
+
throw localValidationError('status', `${unknown.length > 0 ? `unknown status ${unknown.join(', ')}; ` : ''}` +
|
|
189
|
+
`use one or more of: ${accepted.join(', ')}`, [...accepted]);
|
|
190
|
+
}
|
|
191
|
+
return [...new Set(named)];
|
|
192
|
+
}
|
|
193
|
+
function parseLimit(raw) {
|
|
194
|
+
const limit = /^\d+$/.test(raw.trim()) ? Number(raw) : NaN;
|
|
195
|
+
if (!(limit >= 1 && limit <= MAX_LIMIT)) {
|
|
196
|
+
throw localValidationError('limit', `must be an integer from 1 to ${MAX_LIMIT}`);
|
|
197
|
+
}
|
|
198
|
+
return limit;
|
|
199
|
+
}
|
|
200
|
+
function makeClient(opts, deps) {
|
|
201
|
+
return makeHttpClient(opts, {
|
|
202
|
+
env: deps.env,
|
|
203
|
+
credentialsPath: deps.credentialsPath,
|
|
204
|
+
// A dry run answers from the canned samples, never from an injected fetch.
|
|
205
|
+
fetchImpl: opts.dryRun ? undefined : deps.fetchImpl,
|
|
206
|
+
stderr: deps.stderr,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function makeOutput(opts, deps) {
|
|
210
|
+
return new Output(opts.output, { stdout: deps.stdout, stderr: deps.stderr });
|
|
211
|
+
}
|
|
212
|
+
function stderrOf(deps) {
|
|
213
|
+
return terminalSafeWriter(deps.stderr);
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factory.js';
|
|
3
3
|
import type { FetchImpl } from '../lib/http.js';
|
|
4
|
-
import { type HistoryRetentionMeta } from '../lib/history-retention.js';
|
|
5
4
|
/** A schedule as returned by the API. */
|
|
6
5
|
export interface CliSchedule {
|
|
7
6
|
scheduleId: string;
|
|
@@ -97,38 +96,10 @@ export interface DeleteOptions extends CommonOptions {
|
|
|
97
96
|
export interface CliDeleteScheduleResponse {
|
|
98
97
|
scheduleId: string;
|
|
99
98
|
}
|
|
100
|
-
export interface RunListOptions extends CommonOptions {
|
|
101
|
-
scheduleId: string;
|
|
102
|
-
columns?: string;
|
|
103
|
-
noHeader?: boolean;
|
|
104
|
-
}
|
|
105
|
-
export interface CliScheduleRun {
|
|
106
|
-
runId: string;
|
|
107
|
-
scheduleId: string | null;
|
|
108
|
-
status: 'queued' | 'running' | 'passed' | 'failed' | 'blocked' | 'cancelled';
|
|
109
|
-
projectId: string | null;
|
|
110
|
-
testListId: string | null;
|
|
111
|
-
stats: {
|
|
112
|
-
total: number;
|
|
113
|
-
passed: number;
|
|
114
|
-
failed: number;
|
|
115
|
-
blocked: number;
|
|
116
|
-
running: number;
|
|
117
|
-
cancelled: number;
|
|
118
|
-
};
|
|
119
|
-
createdAt: string;
|
|
120
|
-
updatedAt: string;
|
|
121
|
-
}
|
|
122
|
-
/** `GET /schedules/{id}/runs` response. Not paginated. */
|
|
123
|
-
interface ScheduleRunListResponse {
|
|
124
|
-
runs: CliScheduleRun[];
|
|
125
|
-
meta?: HistoryRetentionMeta;
|
|
126
|
-
}
|
|
127
99
|
export declare function runList(opts: ListOptions, deps?: ScheduleDeps): Promise<ScheduleListResponse>;
|
|
128
100
|
export declare function runGet(opts: GetOptions, deps?: ScheduleDeps): Promise<CliSchedule>;
|
|
129
101
|
export declare function runCreate(opts: CreateOptions, deps?: ScheduleDeps): Promise<CliCreateScheduleResponse>;
|
|
130
102
|
export declare function runUpdate(opts: UpdateOptions, deps?: ScheduleDeps): Promise<CliSchedule>;
|
|
131
103
|
export declare function runDelete(opts: DeleteOptions, deps?: ScheduleDeps): Promise<CliDeleteScheduleResponse>;
|
|
132
|
-
export declare function runRunList(opts: RunListOptions, deps?: ScheduleDeps): Promise<ScheduleRunListResponse>;
|
|
133
104
|
export declare function createScheduleCommand(deps?: ScheduleDeps): Command;
|
|
134
105
|
export {};
|
|
@@ -5,14 +5,17 @@ import { resolveProfileName } from '../lib/config.js';
|
|
|
5
5
|
import { ApiError, InterruptError } from '../lib/errors.js';
|
|
6
6
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
7
7
|
import { formatScheduleFrequencyAdvisory, runsPerMonth } from '../lib/cron.js';
|
|
8
|
-
import { renderTextTable } from '../lib/text-table.js';
|
|
8
|
+
import { renderTextTable, resolveTextColumns } from '../lib/text-table.js';
|
|
9
9
|
import { assertIdempotencyKey } from '../lib/validate.js';
|
|
10
|
-
import {
|
|
10
|
+
import { terminalSafeLine, terminalSafeWriter } from '../lib/terminal-text.js';
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// schedule list
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
14
|
export async function runList(opts, deps = {}) {
|
|
15
15
|
const out = makeOutput(opts.output, deps);
|
|
16
|
+
if (opts.output === 'text') {
|
|
17
|
+
resolveTextColumns(opts.columns, SCHEDULE_LIST_COLUMNS);
|
|
18
|
+
}
|
|
16
19
|
const client = makeClient(opts, deps);
|
|
17
20
|
const response = await client.get('/schedules');
|
|
18
21
|
const schedules = response.schedules ?? [];
|
|
@@ -35,7 +38,7 @@ export async function runGet(opts, deps = {}) {
|
|
|
35
38
|
const TARGET_TYPES = ['project', 'testList'];
|
|
36
39
|
export async function runCreate(opts, deps = {}) {
|
|
37
40
|
const out = makeOutput(opts.output, deps);
|
|
38
|
-
const stderr = deps.stderr
|
|
41
|
+
const stderr = terminalSafeWriter(deps.stderr);
|
|
39
42
|
assertIdempotencyKey(opts.idempotencyKey);
|
|
40
43
|
if (opts.name === undefined || opts.name.trim().length === 0) {
|
|
41
44
|
throw localValidationError('--name is required and must not be empty');
|
|
@@ -168,7 +171,7 @@ function formatMonthly(value) {
|
|
|
168
171
|
// ---------------------------------------------------------------------------
|
|
169
172
|
export async function runUpdate(opts, deps = {}) {
|
|
170
173
|
const out = makeOutput(opts.output, deps);
|
|
171
|
-
const stderr = deps.stderr
|
|
174
|
+
const stderr = terminalSafeWriter(deps.stderr);
|
|
172
175
|
assertIdempotencyKey(opts.idempotencyKey);
|
|
173
176
|
if (opts.pause && opts.resume) {
|
|
174
177
|
throw localValidationError('--pause and --resume cannot be combined');
|
|
@@ -226,7 +229,7 @@ export async function runUpdate(opts, deps = {}) {
|
|
|
226
229
|
// ---------------------------------------------------------------------------
|
|
227
230
|
export async function runDelete(opts, deps = {}) {
|
|
228
231
|
const out = makeOutput(opts.output, deps);
|
|
229
|
-
const stderr = deps.stderr
|
|
232
|
+
const stderr = terminalSafeWriter(deps.stderr);
|
|
230
233
|
assertIdempotencyKey(opts.idempotencyKey);
|
|
231
234
|
if (!opts.confirm && !opts.dryRun) {
|
|
232
235
|
throw ApiError.fromEnvelope({
|
|
@@ -247,27 +250,10 @@ export async function runDelete(opts, deps = {}) {
|
|
|
247
250
|
}
|
|
248
251
|
const client = makeClient(opts, deps);
|
|
249
252
|
const deleted = await client.delete(`/schedules/${encodeURIComponent(opts.scheduleId)}`, { headers: { 'idempotency-key': idempotencyKey } });
|
|
250
|
-
out.print(deleted, data => `deleted: ${data.scheduleId}`);
|
|
253
|
+
out.print(deleted, data => `deleted: ${terminalSafeLine(data.scheduleId)}`);
|
|
251
254
|
return deleted;
|
|
252
255
|
}
|
|
253
256
|
// ---------------------------------------------------------------------------
|
|
254
|
-
// schedule run list
|
|
255
|
-
// ---------------------------------------------------------------------------
|
|
256
|
-
export async function runRunList(opts, deps = {}) {
|
|
257
|
-
const out = makeOutput(opts.output, deps);
|
|
258
|
-
const client = makeClient(opts, deps);
|
|
259
|
-
const response = await client.get(`/schedules/${encodeURIComponent(opts.scheduleId)}/runs`);
|
|
260
|
-
const runs = response.runs ?? [];
|
|
261
|
-
const outputResponse = { ...response, runs };
|
|
262
|
-
out.print(outputResponse, () => renderRunListText(runs, { columns: opts.columns, noHeader: opts.noHeader }));
|
|
263
|
-
if (opts.output === 'text') {
|
|
264
|
-
const note = historyRetentionNote(response.meta, client.resolvedBaseUrl);
|
|
265
|
-
if (note)
|
|
266
|
-
(deps.stderr ?? ((line) => process.stderr.write(`${line}\n`)))(note);
|
|
267
|
-
}
|
|
268
|
-
return outputResponse;
|
|
269
|
-
}
|
|
270
|
-
// ---------------------------------------------------------------------------
|
|
271
257
|
// Rendering
|
|
272
258
|
// ---------------------------------------------------------------------------
|
|
273
259
|
/**
|
|
@@ -324,22 +310,22 @@ function renderScheduleListText(schedules, options = {}) {
|
|
|
324
310
|
}
|
|
325
311
|
function renderScheduleText(s) {
|
|
326
312
|
const lines = [
|
|
327
|
-
`id: ${s.scheduleId}`,
|
|
328
|
-
`name: ${s.name}`,
|
|
313
|
+
`id: ${terminalSafeLine(s.scheduleId)}`,
|
|
314
|
+
`name: ${terminalSafeLine(s.name)}`,
|
|
329
315
|
`status: ${statusOf(s)}`,
|
|
330
|
-
`targetType: ${s.targetType}`,
|
|
331
|
-
`targetId: ${s.targetId ?? '(none)'}`,
|
|
332
|
-
`cron: ${s.cron ?? '(none)'}`,
|
|
333
|
-
`timezone: ${s.timezone ?? '(none)'}`,
|
|
334
|
-
`startAt: ${s.startAt ?? '(none)'}`,
|
|
335
|
-
`endAt: ${s.endAt ?? '(open-ended)'}`,
|
|
336
|
-
`sendTo: ${s.sendTo ?? '(none)'}`,
|
|
337
|
-
`lastRunId: ${s.lastRunId ?? '(never run)'}`,
|
|
338
|
-
`createdAt: ${s.createdAt}`,
|
|
339
|
-
`updatedAt: ${s.updatedAt}`,
|
|
316
|
+
`targetType: ${terminalSafeLine(s.targetType)}`,
|
|
317
|
+
`targetId: ${terminalSafeLine(s.targetId ?? '(none)')}`,
|
|
318
|
+
`cron: ${terminalSafeLine(s.cron ?? '(none)')}`,
|
|
319
|
+
`timezone: ${terminalSafeLine(s.timezone ?? '(none)')}`,
|
|
320
|
+
`startAt: ${terminalSafeLine(s.startAt ?? '(none)')}`,
|
|
321
|
+
`endAt: ${terminalSafeLine(s.endAt ?? '(open-ended)')}`,
|
|
322
|
+
`sendTo: ${terminalSafeLine(s.sendTo ?? '(none)')}`,
|
|
323
|
+
`lastRunId: ${terminalSafeLine(s.lastRunId ?? '(never run)')}`,
|
|
324
|
+
`createdAt: ${terminalSafeLine(s.createdAt)}`,
|
|
325
|
+
`updatedAt: ${terminalSafeLine(s.updatedAt)}`,
|
|
340
326
|
];
|
|
341
327
|
if (s.autoPausedAt)
|
|
342
|
-
lines.push(`autoPaused: ${s.autoPausedAt}`);
|
|
328
|
+
lines.push(`autoPaused: ${terminalSafeLine(s.autoPausedAt)}`);
|
|
343
329
|
if (s.environmentMode !== undefined) {
|
|
344
330
|
lines.push(`environment: ${scheduleEnvironmentText(s)}`);
|
|
345
331
|
}
|
|
@@ -356,14 +342,14 @@ function renderScheduleText(s) {
|
|
|
356
342
|
*/
|
|
357
343
|
function renderCreateScheduleText(r) {
|
|
358
344
|
if (r.environmentMode === undefined)
|
|
359
|
-
return `id: ${r.scheduleId}`;
|
|
360
|
-
return `id: ${r.scheduleId}\nenvironment: ${scheduleEnvironmentText(r)}`;
|
|
345
|
+
return `id: ${terminalSafeLine(r.scheduleId)}`;
|
|
346
|
+
return `id: ${terminalSafeLine(r.scheduleId)}\nenvironment: ${scheduleEnvironmentText(r)}`;
|
|
361
347
|
}
|
|
362
348
|
function scheduleEnvironmentText(schedule) {
|
|
363
349
|
if (schedule.environmentMode === 'inherit')
|
|
364
350
|
return 'project default (inherits)';
|
|
365
351
|
if (schedule.environmentMode === 'pinned' && schedule.environment) {
|
|
366
|
-
return `${schedule.environment} (pinned)`;
|
|
352
|
+
return `${terminalSafeLine(schedule.environment)} (pinned)`;
|
|
367
353
|
}
|
|
368
354
|
return '-';
|
|
369
355
|
}
|
|
@@ -434,28 +420,6 @@ function unsupportedEnvironmentError(nextAction, details) {
|
|
|
434
420
|
},
|
|
435
421
|
});
|
|
436
422
|
}
|
|
437
|
-
const RUN_LIST_COLUMNS = [
|
|
438
|
-
{
|
|
439
|
-
header: 'RUN ID',
|
|
440
|
-
width: rows => Math.max(6, ...rows.map(r => r.runId.length)),
|
|
441
|
-
render: r => r.runId,
|
|
442
|
-
},
|
|
443
|
-
{ header: 'STATUS', width: 9, render: r => r.status },
|
|
444
|
-
{ header: 'TOTAL', width: 5, render: r => String(r.stats.total) },
|
|
445
|
-
{ header: 'PASS', width: 4, render: r => String(r.stats.passed) },
|
|
446
|
-
{ header: 'FAIL', width: 4, render: r => String(r.stats.failed) },
|
|
447
|
-
{ header: 'BLOCK', width: 5, render: r => String(r.stats.blocked) },
|
|
448
|
-
{ header: 'STARTED', width: 0, render: r => r.createdAt },
|
|
449
|
-
];
|
|
450
|
-
function renderRunListText(runs, options = {}) {
|
|
451
|
-
// Distinct from a missing schedule, which is reported as not found.
|
|
452
|
-
if (runs.length === 0)
|
|
453
|
-
return 'No runs yet.';
|
|
454
|
-
return renderTextTable(runs, RUN_LIST_COLUMNS, {
|
|
455
|
-
columns: options.columns,
|
|
456
|
-
noHeader: options.noHeader,
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
423
|
function localValidationError(message) {
|
|
460
424
|
return ApiError.fromEnvelope({
|
|
461
425
|
error: {
|
|
@@ -472,8 +436,8 @@ function localValidationError(message) {
|
|
|
472
436
|
// ---------------------------------------------------------------------------
|
|
473
437
|
export function createScheduleCommand(deps = {}) {
|
|
474
438
|
const schedule = new Command('schedule')
|
|
475
|
-
.summary('Manage schedules
|
|
476
|
-
.description('Manage TestSprite schedules. Needs
|
|
439
|
+
.summary('Manage schedules')
|
|
440
|
+
.description('Manage TestSprite schedules. Needs an API key with the read:schedules / write:schedules scopes.');
|
|
477
441
|
schedule
|
|
478
442
|
.command('list')
|
|
479
443
|
.summary('List schedules visible to the API key')
|
|
@@ -481,6 +445,7 @@ export function createScheduleCommand(deps = {}) {
|
|
|
481
445
|
'\nExit codes:\n' +
|
|
482
446
|
' 0 success\n' +
|
|
483
447
|
' 3 auth error\n' +
|
|
448
|
+
' 5 validation error (e.g., bad --columns)\n' +
|
|
484
449
|
' 7 schedules are not available on this account\n' +
|
|
485
450
|
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
486
451
|
' 13 not available on your plan')
|
|
@@ -619,30 +584,6 @@ export function createScheduleCommand(deps = {}) {
|
|
|
619
584
|
idempotencyKey: cmdOpts.idempotencyKey,
|
|
620
585
|
}, deps);
|
|
621
586
|
});
|
|
622
|
-
const run = schedule.command('run').description("Inspect a schedule's runs");
|
|
623
|
-
run
|
|
624
|
-
.command('list <schedule-id>')
|
|
625
|
-
.summary("List a schedule's most recent runs")
|
|
626
|
-
.description("List a schedule's most recent runs (up to 100, within your plan's history window;\n" +
|
|
627
|
-
'JSON `meta.hiddenCount` shows how many are hidden)\n' +
|
|
628
|
-
'\nExit codes:\n' +
|
|
629
|
-
' 0 success\n' +
|
|
630
|
-
' 3 auth error\n' +
|
|
631
|
-
' 4 not found\n' +
|
|
632
|
-
' 7 schedules are not available on this account\n' +
|
|
633
|
-
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
634
|
-
' 13 not available on your plan')
|
|
635
|
-
.option('--columns <list>', 'select/reorder text table columns (comma-separated keys)')
|
|
636
|
-
.option('--no-header', 'suppress the text table header row')
|
|
637
|
-
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
638
|
-
.action(async (scheduleId, cmdOpts, command) => {
|
|
639
|
-
await runRunList({
|
|
640
|
-
...resolveCommonOptions(command, deps.env),
|
|
641
|
-
scheduleId,
|
|
642
|
-
columns: cmdOpts.columns,
|
|
643
|
-
noHeader: cmdOpts.header === false,
|
|
644
|
-
}, deps);
|
|
645
|
-
});
|
|
646
587
|
return schedule;
|
|
647
588
|
}
|
|
648
589
|
// ---------------------------------------------------------------------------
|