@testsprite/testsprite-cli 0.16.0 → 0.18.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 (206) hide show
  1. package/README.md +52 -147
  2. package/dist/commands/agent.d.ts +12 -4
  3. package/dist/commands/agent.js +48 -63
  4. package/dist/commands/auth.d.ts +6 -10
  5. package/dist/commands/auth.js +40 -56
  6. package/dist/commands/ci.d.ts +23 -100
  7. package/dist/commands/ci.js +293 -487
  8. package/dist/commands/conversation.d.ts +27 -0
  9. package/dist/commands/conversation.js +741 -0
  10. package/dist/commands/doctor.d.ts +5 -1
  11. package/dist/commands/doctor.js +129 -34
  12. package/dist/commands/init.d.ts +4 -45
  13. package/dist/commands/init.js +108 -66
  14. package/dist/commands/project-env.d.ts +62 -2
  15. package/dist/commands/project-env.js +434 -43
  16. package/dist/commands/project-sign-in.d.ts +0 -48
  17. package/dist/commands/project-sign-in.js +1 -229
  18. package/dist/commands/project.d.ts +19 -186
  19. package/dist/commands/project.js +108 -926
  20. package/dist/commands/result.d.ts +10 -0
  21. package/dist/commands/result.js +216 -0
  22. package/dist/commands/schedule.d.ts +0 -29
  23. package/dist/commands/schedule.js +28 -87
  24. package/dist/commands/test.d.ts +301 -1838
  25. package/dist/commands/test.js +1880 -13917
  26. package/dist/commands/testlist.d.ts +130 -5
  27. package/dist/commands/testlist.js +300 -342
  28. package/dist/commands/tunnel.d.ts +3 -3
  29. package/dist/commands/tunnel.js +23 -20
  30. package/dist/commands/usage.d.ts +12 -45
  31. package/dist/commands/usage.js +50 -131
  32. package/dist/index.js +191 -110
  33. package/dist/lib/agent-detect.js +9 -5
  34. package/dist/lib/agent-targets.d.ts +21 -2
  35. package/dist/lib/agent-targets.js +88 -11
  36. package/dist/lib/args.d.ts +13 -0
  37. package/dist/lib/args.js +49 -0
  38. package/dist/lib/basic-auth.d.ts +3 -0
  39. package/dist/lib/basic-auth.js +15 -0
  40. package/dist/lib/billing-refusal.js +4 -3
  41. package/dist/lib/ci-linkage.d.ts +4 -82
  42. package/dist/lib/ci-linkage.js +4 -157
  43. package/dist/lib/ci-run.js +1 -1
  44. package/dist/lib/client-factory.d.ts +12 -4
  45. package/dist/lib/client-factory.js +41 -30
  46. package/dist/lib/commit-signal.d.ts +65 -0
  47. package/dist/lib/commit-signal.js +305 -0
  48. package/dist/lib/concurrency-limiter.d.ts +6 -0
  49. package/dist/lib/concurrency-limiter.js +29 -0
  50. package/dist/lib/config.js +10 -5
  51. package/dist/lib/conflict-reason.d.ts +9 -3
  52. package/dist/lib/conflict-reason.js +6 -3
  53. package/dist/lib/conversation/answers.d.ts +9 -0
  54. package/dist/lib/conversation/answers.js +49 -0
  55. package/dist/lib/conversation/api.d.ts +75 -0
  56. package/dist/lib/conversation/api.js +151 -0
  57. package/dist/lib/conversation/change.d.ts +31 -0
  58. package/dist/lib/conversation/change.js +124 -0
  59. package/dist/lib/conversation/context.d.ts +29 -0
  60. package/dist/lib/conversation/context.js +82 -0
  61. package/dist/lib/conversation/environment.d.ts +16 -0
  62. package/dist/lib/conversation/environment.js +21 -0
  63. package/dist/lib/conversation/follow.d.ts +24 -0
  64. package/dist/lib/conversation/follow.js +42 -0
  65. package/dist/lib/conversation/render.d.ts +33 -0
  66. package/dist/lib/conversation/render.js +318 -0
  67. package/dist/lib/conversation/title.d.ts +2 -0
  68. package/dist/lib/conversation/title.js +18 -0
  69. package/dist/lib/conversation/types.d.ts +158 -0
  70. package/dist/lib/conversation/types.js +6 -0
  71. package/dist/lib/credentials.js +67 -11
  72. package/dist/lib/cron.d.ts +1 -1
  73. package/dist/lib/cron.js +2 -2
  74. package/dist/lib/dispatch-stop.d.ts +20 -0
  75. package/dist/lib/dispatch-stop.js +30 -0
  76. package/dist/lib/download.d.ts +100 -0
  77. package/dist/lib/download.js +408 -0
  78. package/dist/lib/dry-run/fetch.d.ts +10 -0
  79. package/dist/lib/dry-run/fetch.js +20 -0
  80. package/dist/lib/dry-run/samples.d.ts +6 -34
  81. package/dist/lib/dry-run/samples.js +375 -747
  82. package/dist/lib/environment-tunnel.d.ts +19 -30
  83. package/dist/lib/environment-tunnel.js +168 -202
  84. package/dist/lib/errors.d.ts +20 -4
  85. package/dist/lib/errors.js +36 -16
  86. package/dist/lib/facade.d.ts +7 -29
  87. package/dist/lib/facade.js +7 -36
  88. package/dist/lib/failing-fe-resolver.d.ts +13 -58
  89. package/dist/lib/failing-fe-resolver.js +47 -132
  90. package/dist/lib/first-suite-hint.d.ts +20 -30
  91. package/dist/lib/first-suite-hint.js +57 -72
  92. package/dist/lib/gh-output.d.ts +76 -21
  93. package/dist/lib/gh-output.js +171 -90
  94. package/dist/lib/git-utils.d.ts +56 -0
  95. package/dist/lib/git-utils.js +212 -0
  96. package/dist/lib/github-context.d.ts +2 -0
  97. package/dist/lib/github-context.js +40 -8
  98. package/dist/lib/history-retention.d.ts +6 -2
  99. package/dist/lib/history-retention.js +10 -7
  100. package/dist/lib/http.d.ts +58 -134
  101. package/dist/lib/http.js +354 -291
  102. package/dist/lib/interrupt.d.ts +14 -8
  103. package/dist/lib/interrupt.js +28 -10
  104. package/dist/lib/junit-report.d.ts +57 -4
  105. package/dist/lib/junit-report.js +202 -32
  106. package/dist/lib/local-target.d.ts +8 -7
  107. package/dist/lib/local-target.js +14 -13
  108. package/dist/lib/output.d.ts +2 -41
  109. package/dist/lib/output.js +13 -51
  110. package/dist/lib/pagination.d.ts +2 -5
  111. package/dist/lib/pagination.js +2 -5
  112. package/dist/lib/presigned-url.d.ts +22 -0
  113. package/dist/lib/presigned-url.js +90 -0
  114. package/dist/lib/prompt.js +36 -2
  115. package/dist/lib/proxy.js +2 -1
  116. package/dist/lib/redact.d.ts +2 -2
  117. package/dist/lib/redact.js +3 -4
  118. package/dist/lib/removed-commands.d.ts +18 -0
  119. package/dist/lib/removed-commands.js +170 -0
  120. package/dist/lib/render-error.d.ts +31 -6
  121. package/dist/lib/render-error.js +88 -25
  122. package/dist/lib/response-schemas.d.ts +38 -30
  123. package/dist/lib/response-schemas.js +207 -207
  124. package/dist/lib/result/api.d.ts +24 -0
  125. package/dist/lib/result/api.js +28 -0
  126. package/dist/lib/result/evidence.d.ts +73 -0
  127. package/dist/lib/result/evidence.js +422 -0
  128. package/dist/lib/result/render.d.ts +20 -0
  129. package/dist/lib/result/render.js +194 -0
  130. package/dist/lib/result/types.d.ts +122 -0
  131. package/dist/lib/result/types.js +19 -0
  132. package/dist/lib/run-output.d.ts +275 -0
  133. package/dist/lib/run-output.js +227 -0
  134. package/dist/lib/run-render.d.ts +101 -0
  135. package/dist/lib/run-render.js +183 -0
  136. package/dist/lib/run-wait.d.ts +192 -0
  137. package/dist/lib/run-wait.js +452 -0
  138. package/dist/lib/runs.types.d.ts +118 -367
  139. package/dist/lib/runs.types.js +0 -14
  140. package/dist/lib/secret-file.d.ts +1 -1
  141. package/dist/lib/secret-file.js +11 -2
  142. package/dist/lib/skill-nudge.d.ts +7 -27
  143. package/dist/lib/skill-nudge.js +9 -37
  144. package/dist/lib/target-path.d.ts +15 -0
  145. package/dist/lib/target-path.js +35 -0
  146. package/dist/lib/target-url-advisory.d.ts +19 -0
  147. package/dist/lib/target-url-advisory.js +31 -0
  148. package/dist/lib/target-url-preflight.d.ts +9 -0
  149. package/dist/lib/target-url-preflight.js +214 -106
  150. package/dist/lib/target-url.d.ts +8 -8
  151. package/dist/lib/target-url.js +14 -24
  152. package/dist/lib/telemetry.d.ts +35 -15
  153. package/dist/lib/telemetry.js +38 -9
  154. package/dist/lib/terminal-text.d.ts +41 -0
  155. package/dist/lib/terminal-text.js +127 -0
  156. package/dist/lib/testlist.types.d.ts +16 -8
  157. package/dist/lib/testlist.types.js +1 -1
  158. package/dist/lib/text-equality.d.ts +2 -0
  159. package/dist/lib/text-equality.js +5 -0
  160. package/dist/lib/text-file.d.ts +16 -0
  161. package/dist/lib/text-file.js +41 -0
  162. package/dist/lib/text-table.d.ts +46 -0
  163. package/dist/lib/text-table.js +72 -4
  164. package/dist/lib/ticker.d.ts +9 -2
  165. package/dist/lib/ticker.js +16 -3
  166. package/dist/lib/transport-failure.d.ts +22 -0
  167. package/dist/lib/transport-failure.js +126 -0
  168. package/dist/lib/tunnel-session.d.ts +8 -2
  169. package/dist/lib/tunnel-session.js +24 -11
  170. package/dist/lib/update-check.js +3 -2
  171. package/dist/lib/url-template.d.ts +43 -0
  172. package/dist/lib/url-template.js +151 -0
  173. package/dist/lib/validate.d.ts +0 -64
  174. package/dist/lib/validate.js +2 -131
  175. package/dist/lib/version-notice.js +4 -3
  176. package/dist/lib/wait-exit.d.ts +37 -2
  177. package/dist/lib/wait-exit.js +88 -30
  178. package/dist/lib/workspace-status.js +10 -2
  179. package/dist/version.d.ts +1 -1
  180. package/dist/version.js +1 -1
  181. package/package.json +2 -3
  182. package/skills/testsprite-ci.skill.md +52 -23
  183. package/skills/testsprite-onboard.skill.md +70 -153
  184. package/skills/testsprite-verify.codex.md +54 -58
  185. package/skills/testsprite-verify.skill.md +189 -358
  186. package/dist/lib/browser.d.ts +0 -6
  187. package/dist/lib/browser.js +0 -54
  188. package/dist/lib/bundle.d.ts +0 -234
  189. package/dist/lib/bundle.js +0 -781
  190. package/dist/lib/deprecate.d.ts +0 -32
  191. package/dist/lib/deprecate.js +0 -39
  192. package/dist/lib/flaky.d.ts +0 -91
  193. package/dist/lib/flaky.js +0 -71
  194. package/dist/lib/plan-poll.d.ts +0 -171
  195. package/dist/lib/plan-poll.js +0 -441
  196. package/dist/lib/plans.types.d.ts +0 -130
  197. package/dist/lib/plans.types.js +0 -31
  198. package/dist/lib/poll.d.ts +0 -100
  199. package/dist/lib/poll.js +0 -290
  200. package/dist/lib/rate-throttle.d.ts +0 -49
  201. package/dist/lib/rate-throttle.js +0 -75
  202. package/dist/lib/run-progress.d.ts +0 -41
  203. package/dist/lib/run-progress.js +0 -56
  204. package/dist/lib/v3-advisory.d.ts +0 -55
  205. package/dist/lib/v3-advisory.js +0 -74
  206. 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,216 @@
1
+ import { Command } from 'commander';
2
+ import { makeHttpClient, resolveCommonOptions, resolveRequestTimeoutMs, } 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
+ stallTimeoutMs: resolveRequestTimeoutMs(opts, deps.env ?? process.env),
124
+ });
125
+ output.print(evidence, data => renderEvidence(data));
126
+ // With no step at all there is nothing to say "every step" of.
127
+ const steps = detail.steps.length + (detail.signIn?.steps.length ?? 0);
128
+ if (flags.failedOnly && opts.output === 'text' && steps > 0 && !hasFailedStep(detail)) {
129
+ stderrOf(deps)('No failed step; downloaded every step.');
130
+ }
131
+ if (evidence.failed.length > 0)
132
+ throw notDownloaded(resultId, evidence);
133
+ return detail;
134
+ }
135
+ /** A download that left files out: UNAVAILABLE, as an incomplete download has always been. */
136
+ function notDownloaded(resultId, evidence) {
137
+ // The evidence files planned: every one written but result.json, and every one that failed.
138
+ const planned = evidence.written.length - 1 + evidence.failed.length;
139
+ return ApiError.fromEnvelope({
140
+ error: {
141
+ code: 'UNAVAILABLE',
142
+ message: `${evidence.failed.length} of ${planned} evidence files could not be downloaded.`,
143
+ // A failure is not always an expired link (a dead network, a full disk):
144
+ // each file's reason says which.
145
+ nextAction: `Run testsprite result get ${resultId} --out <dir> again: each read signs new links. ` +
146
+ "See each file's reason above.",
147
+ requestId: 'local',
148
+ details: { failed: evidence.failed },
149
+ },
150
+ });
151
+ }
152
+ /** The flags of `result list` as one query, refused (exit 5) before anything is sent. */
153
+ function listQuery(flags) {
154
+ if (flags.run !== undefined && flags.test !== undefined) {
155
+ throw localValidationError('test', '--test and --run are mutually exclusive: pass --test <test-id> or --run <run-id>, not both');
156
+ }
157
+ if (flags.run === undefined && flags.test === undefined) {
158
+ throw localValidationError('test', "pass --test <test-id> (one test's results) or --run <run-id> (one run's results)");
159
+ }
160
+ const statuses = flags.status === undefined ? undefined : parseStatuses(flags.status);
161
+ if (flags.run !== undefined) {
162
+ const testOnly = flags.env !== undefined ? 'env' : flags.limit !== undefined ? 'limit' : undefined;
163
+ if (testOnly !== undefined) {
164
+ throw localValidationError(testOnly, `--${testOnly} only applies with --test (it narrows one test's history). Remove --${testOnly}, or list with --test <test-id>`);
165
+ }
166
+ return { run: nonEmpty(flags.run, 'run'), statuses };
167
+ }
168
+ return {
169
+ test: nonEmpty(flags.test, 'test'),
170
+ statuses,
171
+ env: flags.env === undefined ? undefined : nonEmpty(flags.env, 'env'),
172
+ limit: flags.limit === undefined ? undefined : parseLimit(flags.limit),
173
+ };
174
+ }
175
+ function nonEmpty(value, flag) {
176
+ if (value.trim() === '')
177
+ throw localValidationError(flag, 'must not be empty');
178
+ return value;
179
+ }
180
+ /** `--status` values, comma-separated or repeated and in any case, as the server spells them. */
181
+ function parseStatuses(values) {
182
+ const accepted = ALL_RESULT_STATUSES;
183
+ const named = values
184
+ .flatMap(value => value.split(','))
185
+ .map(status => status.trim().toLowerCase())
186
+ .filter(Boolean);
187
+ const unknown = named.filter(status => !accepted.includes(status));
188
+ if (named.length === 0 || unknown.length > 0) {
189
+ throw localValidationError('status', `${unknown.length > 0 ? `unknown status ${unknown.join(', ')}; ` : ''}` +
190
+ `use one or more of: ${accepted.join(', ')}`, [...accepted]);
191
+ }
192
+ return [...new Set(named)];
193
+ }
194
+ function parseLimit(raw) {
195
+ const limit = /^\d+$/.test(raw.trim()) ? Number(raw) : NaN;
196
+ if (!(limit >= 1 && limit <= MAX_LIMIT)) {
197
+ throw localValidationError('limit', `must be an integer from 1 to ${MAX_LIMIT}`);
198
+ }
199
+ return limit;
200
+ }
201
+ function makeClient(opts, deps) {
202
+ return makeHttpClient(opts, {
203
+ env: deps.env,
204
+ credentialsPath: deps.credentialsPath,
205
+ // A dry run answers from the canned samples, never from an injected fetch.
206
+ fetchImpl: opts.dryRun ? undefined : deps.fetchImpl,
207
+ stderr: deps.stderr,
208
+ });
209
+ }
210
+ function makeOutput(opts, deps) {
211
+ return new Output(opts.output, { stdout: deps.stdout, stderr: deps.stderr });
212
+ }
213
+ function stderrOf(deps) {
214
+ return terminalSafeWriter(deps.stderr);
215
+ }
216
+ //# 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,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 ?? ((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({
@@ -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 (V3 workspace)')
476
- .description('Manage TestSprite schedules. Needs a V3 workspace and an API key with the read:schedules / write:schedules scopes.');
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
  // ---------------------------------------------------------------------------