@testsprite/testsprite-cli 0.15.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.
Files changed (207) hide show
  1. package/README.md +53 -141
  2. package/dist/commands/agent.d.ts +12 -4
  3. package/dist/commands/agent.js +55 -65
  4. package/dist/commands/auth.d.ts +6 -10
  5. package/dist/commands/auth.js +44 -56
  6. package/dist/commands/ci.d.ts +23 -100
  7. package/dist/commands/ci.js +297 -489
  8. package/dist/commands/completion.js +2 -1
  9. package/dist/commands/conversation.d.ts +27 -0
  10. package/dist/commands/conversation.js +702 -0
  11. package/dist/commands/doctor.d.ts +5 -1
  12. package/dist/commands/doctor.js +130 -34
  13. package/dist/commands/init.d.ts +4 -45
  14. package/dist/commands/init.js +116 -68
  15. package/dist/commands/project-env.d.ts +62 -2
  16. package/dist/commands/project-env.js +426 -53
  17. package/dist/commands/project-sign-in.d.ts +0 -48
  18. package/dist/commands/project-sign-in.js +1 -224
  19. package/dist/commands/project.d.ts +15 -186
  20. package/dist/commands/project.js +93 -921
  21. package/dist/commands/result.d.ts +10 -0
  22. package/dist/commands/result.js +215 -0
  23. package/dist/commands/schedule.d.ts +0 -29
  24. package/dist/commands/schedule.js +47 -97
  25. package/dist/commands/test.d.ts +315 -1824
  26. package/dist/commands/test.js +1962 -13733
  27. package/dist/commands/testlist.d.ts +128 -5
  28. package/dist/commands/testlist.js +269 -329
  29. package/dist/commands/tunnel.d.ts +2 -2
  30. package/dist/commands/tunnel.js +43 -41
  31. package/dist/commands/usage.d.ts +12 -45
  32. package/dist/commands/usage.js +51 -131
  33. package/dist/index.js +189 -108
  34. package/dist/lib/agent-detect.js +9 -5
  35. package/dist/lib/agent-targets.d.ts +21 -2
  36. package/dist/lib/agent-targets.js +88 -11
  37. package/dist/lib/args.d.ts +13 -0
  38. package/dist/lib/args.js +49 -0
  39. package/dist/lib/basic-auth.d.ts +3 -0
  40. package/dist/lib/basic-auth.js +15 -0
  41. package/dist/lib/billing-refusal.js +4 -3
  42. package/dist/lib/ci-linkage.d.ts +4 -82
  43. package/dist/lib/ci-linkage.js +4 -157
  44. package/dist/lib/ci-run.js +1 -1
  45. package/dist/lib/client-factory.d.ts +10 -2
  46. package/dist/lib/client-factory.js +38 -26
  47. package/dist/lib/commit-signal.d.ts +65 -0
  48. package/dist/lib/commit-signal.js +305 -0
  49. package/dist/lib/concurrency-limiter.d.ts +6 -0
  50. package/dist/lib/concurrency-limiter.js +29 -0
  51. package/dist/lib/config.js +10 -5
  52. package/dist/lib/conflict-reason.d.ts +31 -4
  53. package/dist/lib/conflict-reason.js +38 -4
  54. package/dist/lib/conversation/answers.d.ts +9 -0
  55. package/dist/lib/conversation/answers.js +49 -0
  56. package/dist/lib/conversation/api.d.ts +71 -0
  57. package/dist/lib/conversation/api.js +150 -0
  58. package/dist/lib/conversation/change.d.ts +31 -0
  59. package/dist/lib/conversation/change.js +124 -0
  60. package/dist/lib/conversation/context.d.ts +19 -0
  61. package/dist/lib/conversation/context.js +70 -0
  62. package/dist/lib/conversation/environment.d.ts +15 -0
  63. package/dist/lib/conversation/environment.js +33 -0
  64. package/dist/lib/conversation/follow.d.ts +24 -0
  65. package/dist/lib/conversation/follow.js +42 -0
  66. package/dist/lib/conversation/render.d.ts +33 -0
  67. package/dist/lib/conversation/render.js +315 -0
  68. package/dist/lib/conversation/title.d.ts +2 -0
  69. package/dist/lib/conversation/title.js +18 -0
  70. package/dist/lib/conversation/types.d.ts +156 -0
  71. package/dist/lib/conversation/types.js +6 -0
  72. package/dist/lib/credentials.js +67 -11
  73. package/dist/lib/cron.d.ts +1 -1
  74. package/dist/lib/cron.js +2 -2
  75. package/dist/lib/dispatch-stop.d.ts +20 -0
  76. package/dist/lib/dispatch-stop.js +30 -0
  77. package/dist/lib/download.d.ts +71 -0
  78. package/dist/lib/download.js +274 -0
  79. package/dist/lib/dry-run/fetch.d.ts +10 -0
  80. package/dist/lib/dry-run/fetch.js +20 -0
  81. package/dist/lib/dry-run/samples.d.ts +6 -34
  82. package/dist/lib/dry-run/samples.js +389 -751
  83. package/dist/lib/environment-tunnel.d.ts +16 -26
  84. package/dist/lib/environment-tunnel.js +161 -157
  85. package/dist/lib/errors.d.ts +20 -4
  86. package/dist/lib/errors.js +36 -16
  87. package/dist/lib/facade.d.ts +7 -29
  88. package/dist/lib/facade.js +7 -36
  89. package/dist/lib/failing-fe-resolver.d.ts +13 -58
  90. package/dist/lib/failing-fe-resolver.js +47 -132
  91. package/dist/lib/first-suite-hint.d.ts +16 -22
  92. package/dist/lib/first-suite-hint.js +38 -47
  93. package/dist/lib/gh-output.d.ts +76 -21
  94. package/dist/lib/gh-output.js +171 -90
  95. package/dist/lib/git-utils.d.ts +56 -0
  96. package/dist/lib/git-utils.js +212 -0
  97. package/dist/lib/github-context.d.ts +2 -0
  98. package/dist/lib/github-context.js +40 -8
  99. package/dist/lib/history-retention.d.ts +6 -2
  100. package/dist/lib/history-retention.js +10 -7
  101. package/dist/lib/http.d.ts +58 -134
  102. package/dist/lib/http.js +352 -271
  103. package/dist/lib/interrupt.d.ts +14 -8
  104. package/dist/lib/interrupt.js +28 -10
  105. package/dist/lib/junit-report.d.ts +60 -4
  106. package/dist/lib/junit-report.js +209 -32
  107. package/dist/lib/local-target.d.ts +3 -3
  108. package/dist/lib/local-target.js +3 -3
  109. package/dist/lib/output.d.ts +0 -29
  110. package/dist/lib/output.js +10 -33
  111. package/dist/lib/pagination.d.ts +2 -5
  112. package/dist/lib/pagination.js +2 -5
  113. package/dist/lib/presigned-url.d.ts +22 -0
  114. package/dist/lib/presigned-url.js +90 -0
  115. package/dist/lib/prompt.js +36 -2
  116. package/dist/lib/proxy.js +2 -1
  117. package/dist/lib/redact.d.ts +2 -2
  118. package/dist/lib/redact.js +3 -4
  119. package/dist/lib/removed-commands.d.ts +18 -0
  120. package/dist/lib/removed-commands.js +154 -0
  121. package/dist/lib/render-error.d.ts +31 -6
  122. package/dist/lib/render-error.js +88 -25
  123. package/dist/lib/response-schemas.d.ts +38 -30
  124. package/dist/lib/response-schemas.js +210 -207
  125. package/dist/lib/result/api.d.ts +24 -0
  126. package/dist/lib/result/api.js +28 -0
  127. package/dist/lib/result/evidence.d.ts +71 -0
  128. package/dist/lib/result/evidence.js +420 -0
  129. package/dist/lib/result/render.d.ts +20 -0
  130. package/dist/lib/result/render.js +194 -0
  131. package/dist/lib/result/types.d.ts +122 -0
  132. package/dist/lib/result/types.js +19 -0
  133. package/dist/lib/run-output.d.ts +275 -0
  134. package/dist/lib/run-output.js +227 -0
  135. package/dist/lib/run-render.d.ts +101 -0
  136. package/dist/lib/run-render.js +183 -0
  137. package/dist/lib/run-wait.d.ts +192 -0
  138. package/dist/lib/run-wait.js +452 -0
  139. package/dist/lib/runs.types.d.ts +134 -367
  140. package/dist/lib/runs.types.js +0 -14
  141. package/dist/lib/secret-file.d.ts +1 -1
  142. package/dist/lib/secret-file.js +11 -2
  143. package/dist/lib/skill-nudge.d.ts +7 -27
  144. package/dist/lib/skill-nudge.js +9 -37
  145. package/dist/lib/target-path.d.ts +15 -0
  146. package/dist/lib/target-path.js +35 -0
  147. package/dist/lib/target-url-advisory.d.ts +19 -0
  148. package/dist/lib/target-url-advisory.js +31 -0
  149. package/dist/lib/target-url-preflight.d.ts +9 -0
  150. package/dist/lib/target-url-preflight.js +214 -106
  151. package/dist/lib/target-url.d.ts +1 -1
  152. package/dist/lib/target-url.js +6 -16
  153. package/dist/lib/telemetry.d.ts +32 -12
  154. package/dist/lib/telemetry.js +39 -8
  155. package/dist/lib/terminal-text.d.ts +41 -0
  156. package/dist/lib/terminal-text.js +127 -0
  157. package/dist/lib/testlist.types.d.ts +16 -8
  158. package/dist/lib/testlist.types.js +1 -1
  159. package/dist/lib/text-equality.d.ts +2 -0
  160. package/dist/lib/text-equality.js +5 -0
  161. package/dist/lib/text-file.d.ts +16 -0
  162. package/dist/lib/text-file.js +41 -0
  163. package/dist/lib/text-table.d.ts +46 -0
  164. package/dist/lib/text-table.js +72 -4
  165. package/dist/lib/ticker.d.ts +9 -2
  166. package/dist/lib/ticker.js +16 -3
  167. package/dist/lib/transport-failure.d.ts +22 -0
  168. package/dist/lib/transport-failure.js +126 -0
  169. package/dist/lib/tunnel-session.d.ts +7 -1
  170. package/dist/lib/tunnel-session.js +22 -9
  171. package/dist/lib/update-check.js +3 -2
  172. package/dist/lib/url-template.d.ts +43 -0
  173. package/dist/lib/url-template.js +151 -0
  174. package/dist/lib/validate.d.ts +0 -64
  175. package/dist/lib/validate.js +2 -131
  176. package/dist/lib/version-notice.js +4 -3
  177. package/dist/lib/wait-exit.d.ts +37 -2
  178. package/dist/lib/wait-exit.js +88 -30
  179. package/dist/lib/workspace-status.js +10 -2
  180. package/dist/version.d.ts +1 -1
  181. package/dist/version.js +1 -1
  182. package/package.json +3 -4
  183. package/skills/testsprite-ci.skill.md +48 -18
  184. package/skills/testsprite-onboard.skill.md +66 -151
  185. package/skills/testsprite-verify.codex.md +54 -56
  186. package/skills/testsprite-verify.skill.md +194 -358
  187. package/dist/lib/browser.d.ts +0 -6
  188. package/dist/lib/browser.js +0 -54
  189. package/dist/lib/bundle.d.ts +0 -234
  190. package/dist/lib/bundle.js +0 -781
  191. package/dist/lib/deprecate.d.ts +0 -10
  192. package/dist/lib/deprecate.js +0 -13
  193. package/dist/lib/flaky.d.ts +0 -91
  194. package/dist/lib/flaky.js +0 -71
  195. package/dist/lib/plan-poll.d.ts +0 -171
  196. package/dist/lib/plan-poll.js +0 -441
  197. package/dist/lib/plans.types.d.ts +0 -130
  198. package/dist/lib/plans.types.js +0 -31
  199. package/dist/lib/poll.d.ts +0 -100
  200. package/dist/lib/poll.js +0 -290
  201. package/dist/lib/rate-throttle.d.ts +0 -49
  202. package/dist/lib/rate-throttle.js +0 -75
  203. package/dist/lib/run-progress.d.ts +0 -41
  204. package/dist/lib/run-progress.js +0 -56
  205. package/dist/lib/v3-advisory.d.ts +0 -55
  206. package/dist/lib/v3-advisory.js +0 -74
  207. 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 { historyRetentionNote } from '../lib/history-retention.js';
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 ?? ((line) => process.stderr.write(`${line}\n`));
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 ?? ((line) => process.stderr.write(`${line}\n`));
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,17 +229,16 @@ 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 ?? ((line) => process.stderr.write(`${line}\n`));
232
+ const stderr = terminalSafeWriter(deps.stderr);
230
233
  assertIdempotencyKey(opts.idempotencyKey);
231
234
  if (!opts.confirm && !opts.dryRun) {
232
235
  throw ApiError.fromEnvelope({
233
236
  error: {
234
237
  code: 'VALIDATION_ERROR',
235
238
  message: 'Refusing to delete without --confirm.',
236
- nextAction: 'This removes the schedule and its run history, and stops it firing (no ' +
237
- 'restore window — recreating it starts a fresh schedule). The CLI convention ' +
238
- 'is explicit confirmation for destructive operations. Re-run with --confirm. ' +
239
- '(--dry-run also works without --confirm.)',
239
+ nextAction: 'This removes the schedule and stops it firing; past runs are kept but no longer ' +
240
+ 'listed under it (no restore window). Re-run with --confirm ' +
241
+ '(--dry-run also works without it).',
240
242
  requestId: 'local',
241
243
  details: { field: 'confirm', reason: 'required for destructive operation' },
242
244
  },
@@ -248,27 +250,10 @@ export async function runDelete(opts, deps = {}) {
248
250
  }
249
251
  const client = makeClient(opts, deps);
250
252
  const deleted = await client.delete(`/schedules/${encodeURIComponent(opts.scheduleId)}`, { headers: { 'idempotency-key': idempotencyKey } });
251
- out.print(deleted, data => `deleted: ${data.scheduleId}`);
253
+ out.print(deleted, data => `deleted: ${terminalSafeLine(data.scheduleId)}`);
252
254
  return deleted;
253
255
  }
254
256
  // ---------------------------------------------------------------------------
255
- // schedule run list
256
- // ---------------------------------------------------------------------------
257
- export async function runRunList(opts, deps = {}) {
258
- const out = makeOutput(opts.output, deps);
259
- const client = makeClient(opts, deps);
260
- const response = await client.get(`/schedules/${encodeURIComponent(opts.scheduleId)}/runs`);
261
- const runs = response.runs ?? [];
262
- const outputResponse = { ...response, runs };
263
- out.print(outputResponse, () => renderRunListText(runs, { columns: opts.columns, noHeader: opts.noHeader }));
264
- if (opts.output === 'text') {
265
- const note = historyRetentionNote(response.meta, client.resolvedBaseUrl);
266
- if (note)
267
- (deps.stderr ?? ((line) => process.stderr.write(`${line}\n`)))(note);
268
- }
269
- return outputResponse;
270
- }
271
- // ---------------------------------------------------------------------------
272
257
  // Rendering
273
258
  // ---------------------------------------------------------------------------
274
259
  /**
@@ -325,22 +310,22 @@ function renderScheduleListText(schedules, options = {}) {
325
310
  }
326
311
  function renderScheduleText(s) {
327
312
  const lines = [
328
- `id: ${s.scheduleId}`,
329
- `name: ${s.name}`,
313
+ `id: ${terminalSafeLine(s.scheduleId)}`,
314
+ `name: ${terminalSafeLine(s.name)}`,
330
315
  `status: ${statusOf(s)}`,
331
- `targetType: ${s.targetType}`,
332
- `targetId: ${s.targetId ?? '(none)'}`,
333
- `cron: ${s.cron ?? '(none)'}`,
334
- `timezone: ${s.timezone ?? '(none)'}`,
335
- `startAt: ${s.startAt ?? '(none)'}`,
336
- `endAt: ${s.endAt ?? '(open-ended)'}`,
337
- `sendTo: ${s.sendTo ?? '(none)'}`,
338
- `lastRunId: ${s.lastRunId ?? '(never run)'}`,
339
- `createdAt: ${s.createdAt}`,
340
- `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)}`,
341
326
  ];
342
327
  if (s.autoPausedAt)
343
- lines.push(`autoPaused: ${s.autoPausedAt}`);
328
+ lines.push(`autoPaused: ${terminalSafeLine(s.autoPausedAt)}`);
344
329
  if (s.environmentMode !== undefined) {
345
330
  lines.push(`environment: ${scheduleEnvironmentText(s)}`);
346
331
  }
@@ -357,14 +342,14 @@ function renderScheduleText(s) {
357
342
  */
358
343
  function renderCreateScheduleText(r) {
359
344
  if (r.environmentMode === undefined)
360
- return `id: ${r.scheduleId}`;
361
- return `id: ${r.scheduleId}\nenvironment: ${scheduleEnvironmentText(r)}`;
345
+ return `id: ${terminalSafeLine(r.scheduleId)}`;
346
+ return `id: ${terminalSafeLine(r.scheduleId)}\nenvironment: ${scheduleEnvironmentText(r)}`;
362
347
  }
363
348
  function scheduleEnvironmentText(schedule) {
364
349
  if (schedule.environmentMode === 'inherit')
365
350
  return 'project default (inherits)';
366
351
  if (schedule.environmentMode === 'pinned' && schedule.environment) {
367
- return `${schedule.environment} (pinned)`;
352
+ return `${terminalSafeLine(schedule.environment)} (pinned)`;
368
353
  }
369
354
  return '-';
370
355
  }
@@ -435,28 +420,6 @@ function unsupportedEnvironmentError(nextAction, details) {
435
420
  },
436
421
  });
437
422
  }
438
- const RUN_LIST_COLUMNS = [
439
- {
440
- header: 'RUN ID',
441
- width: rows => Math.max(6, ...rows.map(r => r.runId.length)),
442
- render: r => r.runId,
443
- },
444
- { header: 'STATUS', width: 9, render: r => r.status },
445
- { header: 'TOTAL', width: 5, render: r => String(r.stats.total) },
446
- { header: 'PASS', width: 4, render: r => String(r.stats.passed) },
447
- { header: 'FAIL', width: 4, render: r => String(r.stats.failed) },
448
- { header: 'BLOCK', width: 5, render: r => String(r.stats.blocked) },
449
- { header: 'STARTED', width: 0, render: r => r.createdAt },
450
- ];
451
- function renderRunListText(runs, options = {}) {
452
- // Distinct from a missing schedule, which is reported as not found.
453
- if (runs.length === 0)
454
- return 'No runs yet.';
455
- return renderTextTable(runs, RUN_LIST_COLUMNS, {
456
- columns: options.columns,
457
- noHeader: options.noHeader,
458
- });
459
- }
460
423
  function localValidationError(message) {
461
424
  return ApiError.fromEnvelope({
462
425
  error: {
@@ -472,13 +435,17 @@ function localValidationError(message) {
472
435
  // Wiring
473
436
  // ---------------------------------------------------------------------------
474
437
  export function createScheduleCommand(deps = {}) {
475
- const schedule = new Command('schedule').description('Manage TestSprite schedules');
438
+ const schedule = new Command('schedule')
439
+ .summary('Manage schedules')
440
+ .description('Manage TestSprite schedules. Needs an API key with the read:schedules / write:schedules scopes.');
476
441
  schedule
477
442
  .command('list')
443
+ .summary('List schedules visible to the API key')
478
444
  .description('List schedules visible to the API key\n' +
479
445
  '\nExit codes:\n' +
480
446
  ' 0 success\n' +
481
447
  ' 3 auth error\n' +
448
+ ' 5 validation error (e.g., bad --columns)\n' +
482
449
  ' 7 schedules are not available on this account\n' +
483
450
  ' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
484
451
  ' 13 not available on your plan')
@@ -494,6 +461,7 @@ export function createScheduleCommand(deps = {}) {
494
461
  });
495
462
  schedule
496
463
  .command('get <schedule-id>')
464
+ .summary('Get a schedule by id')
497
465
  .description('Get a schedule by id\n' +
498
466
  '\nExit codes:\n' +
499
467
  ' 0 success\n' +
@@ -508,7 +476,9 @@ export function createScheduleCommand(deps = {}) {
508
476
  });
509
477
  schedule
510
478
  .command('create')
511
- .description('Create a schedule\n' +
479
+ .summary('Create a schedule (starts enabled; runs spend credits)')
480
+ .description('Create a schedule. It starts enabled and each run spends credits (an estimate is printed);\n' +
481
+ 'pause it with `schedule update <id> --pause`.\n' +
512
482
  '\nExit codes:\n' +
513
483
  ' 0 success\n' +
514
484
  ' 3 auth error\n' +
@@ -523,10 +493,9 @@ export function createScheduleCommand(deps = {}) {
523
493
  .option('--target-type <project|testList>', 'what to run (required)')
524
494
  .option('--target-id <id>', 'project id or test-list id (required)')
525
495
  .option('--env <name>', "Pin this project schedule to an environment; omit to always use the project's default environment")
526
- .option('--cron <expr>', 'standard 5-field cron (minute hour day-of-month month day-of-week), ' +
527
- 'e.g. "0 3 * * *". Day-of-week is 0-7, with both 0 and 7 = Sunday. ' +
528
- 'Constrain ' +
529
- 'day-of-month or day-of-week, not both. (required)')
496
+ .option('--cron <expr>', 'standard 5-field cron (minute hour day-of-month month day-of-week), e.g. "0 3 * * *". ' +
497
+ 'Day-of-week 0-7 (0 and 7 = Sunday). Constrain day-of-month or day-of-week, not both. ' +
498
+ 'Numeric fields only (* n a-b */n, lists); no names, ?, L, W or #. (required)')
530
499
  .option('--timezone <tz>', 'IANA timezone (default UTC)')
531
500
  .option('--start <iso>', 'ISO 8601 start instant (default: a few minutes from now)')
532
501
  .option('--end <iso>', 'ISO 8601 end instant (default: open-ended)')
@@ -550,6 +519,7 @@ export function createScheduleCommand(deps = {}) {
550
519
  });
551
520
  schedule
552
521
  .command('update <schedule-id>')
522
+ .summary('Update a schedule, or pause/resume it')
553
523
  .description('Update a schedule, or pause/resume it\n' +
554
524
  '\nExit codes:\n' +
555
525
  ' 0 success\n' +
@@ -562,9 +532,9 @@ export function createScheduleCommand(deps = {}) {
562
532
  ' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
563
533
  ' 13 not available on your plan')
564
534
  .option('--name <name>', 'new schedule name')
565
- .option('--env <name>', "Pin this project schedule to an environment; omit to always use the project's default environment")
566
- .option('--cron <expr>', 'new standard 5-field cron, as printed by `schedule get`. Day-of-week is ' +
567
- '0-7, with both 0 and 7 = Sunday. Constrain day-of-month or day-of-week, not both.')
535
+ .option('--env <name>', 'Pin this project schedule to an environment; omit to leave the current pin unchanged')
536
+ .option('--cron <expr>', 'new standard 5-field cron, as printed by `schedule get`. Day-of-week 0-7 (0 and 7 = Sunday). ' +
537
+ 'Constrain day-of-month or day-of-week, not both. Numeric fields only (no names, ?, L, W or #).')
568
538
  .option('--timezone <tz>', 'new IANA timezone')
569
539
  .option('--start <iso>', 'new ISO 8601 start instant')
570
540
  .option('--end <iso>', 'new ISO 8601 end instant')
@@ -591,7 +561,9 @@ export function createScheduleCommand(deps = {}) {
591
561
  });
592
562
  schedule
593
563
  .command('delete <schedule-id>')
594
- .description('Delete a schedule and its run history. Requires --confirm.\n' +
564
+ .summary('Delete a schedule (requires --confirm)')
565
+ .description('Delete a schedule and stop it firing. Past runs are kept but no longer listed under it.\n' +
566
+ 'Requires --confirm.\n' +
595
567
  '\nExit codes:\n' +
596
568
  ' 0 success\n' +
597
569
  ' 3 auth error\n' +
@@ -612,28 +584,6 @@ export function createScheduleCommand(deps = {}) {
612
584
  idempotencyKey: cmdOpts.idempotencyKey,
613
585
  }, deps);
614
586
  });
615
- const run = schedule.command('run').description("Inspect a schedule's runs");
616
- run
617
- .command('list <schedule-id>')
618
- .description("List a schedule's past runs\n" +
619
- '\nExit codes:\n' +
620
- ' 0 success\n' +
621
- ' 3 auth error\n' +
622
- ' 4 not found\n' +
623
- ' 7 schedules are not available on this account\n' +
624
- ' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
625
- ' 13 not available on your plan')
626
- .option('--columns <list>', 'select/reorder text table columns (comma-separated keys)')
627
- .option('--no-header', 'suppress the text table header row')
628
- .addHelpText('after', GLOBAL_OPTS_HINT)
629
- .action(async (scheduleId, cmdOpts, command) => {
630
- await runRunList({
631
- ...resolveCommonOptions(command, deps.env),
632
- scheduleId,
633
- columns: cmdOpts.columns,
634
- noHeader: cmdOpts.header === false,
635
- }, deps);
636
- });
637
587
  return schedule;
638
588
  }
639
589
  // ---------------------------------------------------------------------------