@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.
Files changed (206) hide show
  1. package/README.md +51 -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 +38 -54
  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 +702 -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 +388 -37
  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 +15 -186
  19. package/dist/commands/project.js +89 -924
  20. package/dist/commands/result.d.ts +10 -0
  21. package/dist/commands/result.js +215 -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 -1816
  25. package/dist/commands/test.js +1951 -13902
  26. package/dist/commands/testlist.d.ts +128 -5
  27. package/dist/commands/testlist.js +269 -339
  28. package/dist/commands/tunnel.d.ts +2 -2
  29. package/dist/commands/tunnel.js +23 -19
  30. package/dist/commands/usage.d.ts +12 -45
  31. package/dist/commands/usage.js +50 -131
  32. package/dist/index.js +182 -104
  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 +10 -2
  45. package/dist/lib/client-factory.js +38 -26
  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 +71 -0
  56. package/dist/lib/conversation/api.js +150 -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 +19 -0
  60. package/dist/lib/conversation/context.js +70 -0
  61. package/dist/lib/conversation/environment.d.ts +15 -0
  62. package/dist/lib/conversation/environment.js +33 -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 +315 -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 +156 -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 +71 -0
  77. package/dist/lib/download.js +274 -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 +16 -27
  83. package/dist/lib/environment-tunnel.js +161 -154
  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 +16 -22
  91. package/dist/lib/first-suite-hint.js +38 -47
  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 +352 -289
  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 +3 -3
  107. package/dist/lib/local-target.js +3 -3
  108. package/dist/lib/output.d.ts +1 -40
  109. package/dist/lib/output.js +11 -49
  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 +154 -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 +71 -0
  127. package/dist/lib/result/evidence.js +420 -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 +1 -1
  151. package/dist/lib/target-url.js +6 -16
  152. package/dist/lib/telemetry.d.ts +31 -11
  153. package/dist/lib/telemetry.js +37 -8
  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 +7 -1
  169. package/dist/lib/tunnel-session.js +22 -9
  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 +48 -18
  183. package/skills/testsprite-onboard.skill.md +66 -151
  184. package/skills/testsprite-verify.codex.md +50 -52
  185. package/skills/testsprite-verify.skill.md +184 -351
  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,227 @@
1
+ import { InterruptError, RequestTimeoutError } from './errors.js';
2
+ import { formatFailureCounts, summarizeRunRows } from './gh-output.js';
3
+ import { ALL_RESULT_STATUSES, isResultRunning } from './result/types.js';
4
+ import { toWaitMembers } from './run-wait.js';
5
+ import { waitCommand } from './run-render.js';
6
+ import { terminalSafeLine } from './terminal-text.js';
7
+ import { waitMemberError } from './wait-exit.js';
8
+ /** Normalize the saved-list wire receipt before combining it with listed results. */
9
+ export function listResultReceipt(row) {
10
+ return {
11
+ testId: row.testId,
12
+ resultId: row.resultId,
13
+ runId: row.runId,
14
+ enqueuedAt: row.enqueuedAt,
15
+ status: 'dispatched',
16
+ ...(typeof row.testTitle === 'string' ? { title: row.testTitle } : {}),
17
+ ...(typeof row.dashboardUrl === 'string' ? { dashboardUrl: row.dashboardUrl } : {}),
18
+ ...(typeof row.executionUrl === 'string' ? { executionUrl: row.executionUrl } : {}),
19
+ };
20
+ }
21
+ function runDiagnostic(outcome, statuses) {
22
+ const { runId } = outcome;
23
+ if (outcome.run?.cancelled && !outcome.joined)
24
+ return {
25
+ runId,
26
+ status: 'cancelled',
27
+ error: { code: 'RUN_CANCELLED', message: `Run ${runId} was cancelled.`, exitCode: 1 },
28
+ };
29
+ if (outcome.error && !statuses?.has('error'))
30
+ return { runId, status: 'error', error: waitMemberError(outcome.error) };
31
+ if (outcome.timedOut && !outcome.error && !statuses?.has('timeout'))
32
+ return {
33
+ runId,
34
+ status: 'timeout',
35
+ error: {
36
+ code: 'TIMEOUT',
37
+ message: `Run ${runId} did not finish before the deadline.`,
38
+ exitCode: 7,
39
+ },
40
+ };
41
+ return undefined;
42
+ }
43
+ function resultErrorCode(status) {
44
+ switch (status) {
45
+ case 'failed':
46
+ return 'TEST_FAILED';
47
+ case 'blocked':
48
+ return 'TEST_BLOCKED';
49
+ case 'cancelled':
50
+ return 'TEST_CANCELLED';
51
+ default:
52
+ return 'RESULT_ERROR';
53
+ }
54
+ }
55
+ /** Project launches, saved lists and reattached waits share one native output contract. */
56
+ export function buildRunOutput(opts) {
57
+ const outcomes = opts.outcomes ?? new Map();
58
+ const runs = opts.receipts.map(receipt => {
59
+ const outcome = outcomes.get(receipt.runId);
60
+ const cancel = opts.cancellation?.(receipt.runId);
61
+ return {
62
+ ...outcome?.run,
63
+ ...receipt,
64
+ ...(outcome?.run ? { status: outcome.run.status, cancelled: outcome.run.cancelled } : {}),
65
+ ...(opts.wait && !outcome?.run ? { listed: false } : {}),
66
+ ...(outcome?.timedOut ? { timedOut: true } : {}),
67
+ ...(outcome?.error ? { error: waitMemberError(outcome.error) } : {}),
68
+ ...(cancel ? { cancel } : {}),
69
+ };
70
+ });
71
+ const receipts = new Map(opts.dispatched?.map(row => [row.resultId, row]));
72
+ const observed = [];
73
+ for (const outcome of outcomes.values()) {
74
+ const lines = new Map(outcome.results.map(line => [line.resultId, line]));
75
+ const cancel = opts.cancellation?.(outcome.runId);
76
+ for (const member of toWaitMembers(outcome)) {
77
+ const line = lines.get(member.resultId);
78
+ const receipt = receipts.get(member.resultId);
79
+ const receiptError = receipt?.status === member.status ? receipt.error : undefined;
80
+ const detail = line?.error || (member.status === 'blocked' ? line?.blockedReason : null);
81
+ const error = member.error ??
82
+ (detail
83
+ ? {
84
+ code: receiptError?.code ?? resultErrorCode(member.status),
85
+ message: detail,
86
+ exitCode: 1,
87
+ }
88
+ : receiptError);
89
+ observed.push({
90
+ ...receipt,
91
+ ...member,
92
+ ...(line ? { title: line.title, createdAt: line.created } : {}),
93
+ error,
94
+ ...(cancel ? { cancel } : {}),
95
+ });
96
+ receipts.delete(member.resultId);
97
+ }
98
+ }
99
+ for (const row of receipts.values()) {
100
+ const outcome = row.runId ? outcomes.get(row.runId) : undefined;
101
+ const cancel = row.runId ? opts.cancellation?.(row.runId) : undefined;
102
+ observed.push({
103
+ ...row,
104
+ ...(opts.wait && row.status === 'dispatched'
105
+ ? { status: outcome?.timedOut ? 'timeout' : 'running' }
106
+ : {}),
107
+ ...(cancel ? { cancel } : {}),
108
+ });
109
+ }
110
+ const results = observed.map(({ error, ...row }) => ({
111
+ ...row,
112
+ ...(error ? { error: error.message, errorCode: error.code } : {}),
113
+ }));
114
+ const statusesByRun = new Map();
115
+ for (const row of results) {
116
+ if (!row.runId)
117
+ continue;
118
+ const statuses = statusesByRun.get(row.runId) ?? new Set();
119
+ statuses.add(row.status);
120
+ statusesByRun.set(row.runId, statuses);
121
+ }
122
+ const diagnosticRows = [...outcomes.values()].flatMap(outcome => {
123
+ const row = runDiagnostic(outcome, statusesByRun.get(outcome.runId));
124
+ return row ? [{ ...row, testId: `(run ${row.runId})`, name: row.error.message }] : [];
125
+ });
126
+ const members = observed.map(row => ({
127
+ ...row,
128
+ testId: row.testId ?? '(integration)',
129
+ name: row.title,
130
+ }));
131
+ const summary = summarizeRunRows(results, opts.buckets, {
132
+ notFoundNote: opts.notFoundNote,
133
+ foldSkippedBuckets: opts.foldSkippedBuckets,
134
+ });
135
+ if (diagnosticRows.length)
136
+ summary.runFailures = diagnosticRows.map(({ runId, status, error }) => ({
137
+ runId,
138
+ status,
139
+ message: error.message,
140
+ }));
141
+ const stopped = opts.failure instanceof InterruptError ||
142
+ opts.failure instanceof RequestTimeoutError ||
143
+ opts.requestTimedOut;
144
+ const incompleteWait = (run) => {
145
+ if (run.status === 'finished' || outcomes.get(run.runId)?.error?.code === 'NOT_FOUND')
146
+ return false;
147
+ const joinedIds = opts.joinedScopes?.get(run.runId);
148
+ if (!joinedIds)
149
+ return true;
150
+ const settled = new Set(outcomes
151
+ .get(run.runId)
152
+ ?.results.filter(line => !isResultRunning(line.testStatus))
153
+ .map(line => line.resultId));
154
+ return joinedIds.some(id => !settled.has(id));
155
+ };
156
+ const unfinishedRuns = runs.filter(incompleteWait);
157
+ const partial = [...outcomes.values()].some(outcome => outcome.timedOut) ||
158
+ (stopped && (opts.incompleteDispatch || (opts.wait && unfinishedRuns.length > 0)));
159
+ return {
160
+ output: {
161
+ runs,
162
+ results,
163
+ ...(opts.wait ? { summary: runCounts(summary) } : {}),
164
+ ...(summary.runFailures ? { runFailures: summary.runFailures } : {}),
165
+ ...(partial ? { partial: true } : {}),
166
+ },
167
+ summary,
168
+ members,
169
+ // JUnit needs a synthetic testcase only when no result already reports this failure.
170
+ diagnosticRows: diagnosticRows.filter(row => !statusesByRun.get(row.runId)?.has(row.status)),
171
+ unfinishedRuns,
172
+ };
173
+ }
174
+ export function runCounts({ results: _results, runFailures: _runFailures, executionReport: _executionReport, ...counts }) {
175
+ return counts;
176
+ }
177
+ /** The poll descriptor used by all run previews. Only supplied ids need escaping. */
178
+ export function runListingPath(runId) {
179
+ return `/api/cli/v1/results?run=${runId === undefined ? '<run-id>' : encodeURIComponent(runId)}&status=${ALL_RESULT_STATUSES.join(',')}`;
180
+ }
181
+ export function previewRun(requests, wait, thenPoll = false) {
182
+ const { output } = buildRunOutput({ receipts: [], wait });
183
+ return { ...output, dryRun: true, requests, ...(thenPoll ? { thenPoll: runListingPath() } : {}) };
184
+ }
185
+ function renderRunCounts(summary) {
186
+ return [
187
+ `${summary.passed}/${summary.total} passed`,
188
+ formatFailureCounts(summary),
189
+ `${summary.timedOut} timed out`,
190
+ ...(summary.running ? [`${summary.running} still running`] : []),
191
+ ...(summary.skipped ? [`${summary.skipped} not dispatched`] : []),
192
+ ].join(', ');
193
+ }
194
+ export function renderRunResults(runs, results, summary, notes = []) {
195
+ const rows = new Map();
196
+ for (const result of results) {
197
+ const group = rows.get(result.runId) ?? [];
198
+ group.push(` ${terminalSafeLine(result.resultId)} ${terminalSafeLine(result.title?.trim() || result.testId || '-')} ${terminalSafeLine(result.status)}`);
199
+ rows.set(result.runId, group);
200
+ }
201
+ const wait = summary ? undefined : waitCommand(runs.filter(run => !run.joined));
202
+ const lines = runs.flatMap(run => {
203
+ const members = rows.get(run.runId) ?? [];
204
+ const count = run.total ?? members.length;
205
+ const header = [
206
+ `Run ${terminalSafeLine(run.runId)}${run.cancelled ? ' — cancelled' : ''}`,
207
+ ...(run.targetUrl ? [terminalSafeLine(run.targetUrl)] : []),
208
+ ...(!summary ? [`(${count} test${count === 1 ? '' : 's'})`] : []),
209
+ ].join(' ');
210
+ return [
211
+ header,
212
+ ...members,
213
+ // The run's page in the Portal, on a launch receipt and a waited card alike.
214
+ ...(run.dashboardUrl ? [` Dashboard: ${terminalSafeLine(run.dashboardUrl)}`] : []),
215
+ ];
216
+ });
217
+ lines.push(...(rows.get(undefined) ?? []));
218
+ for (const failure of summary?.runFailures ?? [])
219
+ lines.push(terminalSafeLine(failure.message));
220
+ lines.push(...notes);
221
+ if (summary)
222
+ lines.push(renderRunCounts(summary));
223
+ if (wait)
224
+ lines.push(wait);
225
+ return lines.length ? lines.join('\n') : 'No runs dispatched.';
226
+ }
227
+ //# sourceMappingURL=run-output.js.map
@@ -0,0 +1,101 @@
1
+ export interface RunRef {
2
+ runId?: string | null;
3
+ resultId?: string | null;
4
+ joined?: boolean;
5
+ }
6
+ export declare function resultCount(n: number): string;
7
+ /** A count of runs in prose: "1 run", "2 runs". */
8
+ export declare function runCount(n: number): string;
9
+ /** The launches these results belong to, each once, in first-seen order. */
10
+ export declare function launchIds(refs: ReadonlyArray<RunRef>): string[];
11
+ /**
12
+ * The one launch all of these results belong to. `undefined` when they span
13
+ * several launches, or when the backend named no launch for one of them: a
14
+ * launch id is never stated for results it may not cover. An entry that never
15
+ * got a result id (a test that was not dispatched) does not count.
16
+ */
17
+ export declare function sharedLaunchId(refs: ReadonlyArray<RunRef>): string | undefined;
18
+ /**
19
+ * The command that waits for these results' launches, or `undefined` when no
20
+ * launch is known: `run wait` takes a launch id, so a result id is never
21
+ * offered in its place.
22
+ */
23
+ export declare function waitCommand(refs: ReadonlyArray<RunRef>): string | undefined;
24
+ /**
25
+ * The read that shows what was cancelled in these results' launches, one
26
+ * `result list --run <run-id> --status cancelled` per launch: after a closing
27
+ * tunnel has cancelled them, `run cancel` would stop everything else still
28
+ * running in the launch.
29
+ */
30
+ export declare function cancelledResultsCommand(refs: ReadonlyArray<RunRef>): string | undefined;
31
+ /**
32
+ * What `run cancel` does to a launch: it takes the launch id, so it stops
33
+ * every test in that run, not one of them.
34
+ */
35
+ export declare const CANCEL_STOPS_WHOLE_RUN = "stops every test in that run";
36
+ /**
37
+ * The command that cancels these results' launches; see {@link waitCommand}.
38
+ * A launch this invocation started is its own to cancel, so the command stands
39
+ * alone. For a launch it only joined, the command is followed by what
40
+ * cancelling it stops.
41
+ */
42
+ export declare function cancelCommand(refs: ReadonlyArray<RunRef>): string | undefined;
43
+ /**
44
+ * What is true of work a wait let go of: it keeps executing, and billing, on
45
+ * the server. One result is named by its launch (`Run <id>`), or as
46
+ * `Result <id>` when the backend named no launch. Several are counted as
47
+ * tests, since they may all belong to one run, and refs that name only a
48
+ * launch (a run whose results were never listed) as runs.
49
+ */
50
+ export declare function stillRunningAndBillingSubject(refs: ReadonlyArray<RunRef>): string;
51
+ /**
52
+ * The two indented lines under a detach message: how to re-attach and how to
53
+ * cancel. Both commands take the launch, so they name each launch once; when
54
+ * the backend named no launch there is nothing to offer and no line is added.
55
+ */
56
+ export declare function reattachLines(refs: ReadonlyArray<RunRef>): string;
57
+ /** The same two commands as one trailing sentence, or nothing when no launch is known. */
58
+ export declare function reattachSentence(refs: ReadonlyArray<RunRef>): string;
59
+ /**
60
+ * What a wait says when Ctrl-C ends it: only the local wait stopped, the work
61
+ * keeps executing and billing, and these are the commands to re-attach to it
62
+ * or to really stop it.
63
+ */
64
+ export declare function interruptDetachMessage(interrupt: {
65
+ signal: string;
66
+ }, refs: ReadonlyArray<RunRef>): string;
67
+ /** One piece of work to look up later, by whatever ids are known (wire names). */
68
+ export interface LaterLookup {
69
+ testId?: string | null;
70
+ /** The result id. */
71
+ resultId?: string | null;
72
+ /**
73
+ * Look the result itself up rather than the test's results. Set for a
74
+ * result the CLI cancelled: result lists leave cancelled results out, so
75
+ * the test's list would show an older verdict as if it were this one.
76
+ */
77
+ byResult?: boolean;
78
+ }
79
+ /** How many lookups a hint lists before it counts the rest. */
80
+ export declare const CHECK_LATER_LIMIT = 10;
81
+ /**
82
+ * What a wait that gave up can still point at when no launch is known (so
83
+ * neither `run wait` nor `run cancel` can be offered): one line per piece of
84
+ * work, the first ten, then a count of the rest. A test is looked up by its
85
+ * results; with no test id, or for a result named with `byResult`, the result
86
+ * is looked up itself. No line carries a placeholder. Empty when nothing can
87
+ * be looked up.
88
+ */
89
+ export declare function checkLaterHint(lookups: ReadonlyArray<LaterLookup>): string;
90
+ /**
91
+ * How prose names one result's work: `Run <launch id>` when the launch is
92
+ * known, otherwise `Result <result id>`. A result id is never called a run.
93
+ * With neither id it is just `The run`.
94
+ */
95
+ export declare function runLabel(ref: RunRef, letterCase?: 'upper' | 'lower'): string;
96
+ /**
97
+ * The id of one result's work as a `name: value` note: `resultId: <launch id>`
98
+ * when the launch is known, otherwise `resultId: <result id>`.
99
+ */
100
+ export declare function runIdNote(ref: RunRef): string;
101
+ export declare const OLDER_CLI_RESULT_ID_HINT = "a result id printed by an older CLI is not one. Look a result up with: testsprite result get <result-id>";
@@ -0,0 +1,183 @@
1
+ /** Native run/result references and human-readable command hints. */
2
+ import { terminalSafeLine } from './terminal-text.js';
3
+ const idOf = (value) => typeof value === 'string' && value.length > 0 ? value : undefined;
4
+ const inLine = terminalSafeLine;
5
+ export function resultCount(n) {
6
+ return `${n} result${n === 1 ? '' : 's'}`;
7
+ }
8
+ /** A count of runs in prose: "1 run", "2 runs". */
9
+ export function runCount(n) {
10
+ return `${n} run${n === 1 ? '' : 's'}`;
11
+ }
12
+ /** The launches these results belong to, each once, in first-seen order. */
13
+ export function launchIds(refs) {
14
+ const ids = [];
15
+ for (const ref of refs) {
16
+ const launchId = idOf(ref.runId);
17
+ if (launchId !== undefined && !ids.includes(launchId))
18
+ ids.push(launchId);
19
+ }
20
+ return ids;
21
+ }
22
+ /**
23
+ * The one launch all of these results belong to. `undefined` when they span
24
+ * several launches, or when the backend named no launch for one of them: a
25
+ * launch id is never stated for results it may not cover. An entry that never
26
+ * got a result id (a test that was not dispatched) does not count.
27
+ */
28
+ export function sharedLaunchId(refs) {
29
+ const dispatched = refs.filter(ref => idOf(ref.resultId) !== undefined);
30
+ const ids = launchIds(dispatched);
31
+ return ids.length === 1 && dispatched.every(ref => idOf(ref.runId) !== undefined)
32
+ ? ids[0]
33
+ : undefined;
34
+ }
35
+ /**
36
+ * The command that waits for these results' launches, or `undefined` when no
37
+ * launch is known: `run wait` takes a launch id, so a result id is never
38
+ * offered in its place.
39
+ */
40
+ export function waitCommand(refs) {
41
+ const ids = launchIds(refs).map(inLine);
42
+ return ids.length > 0 ? `testsprite run wait ${ids.join(' ')}` : undefined;
43
+ }
44
+ /**
45
+ * The read that shows what was cancelled in these results' launches, one
46
+ * `result list --run <run-id> --status cancelled` per launch: after a closing
47
+ * tunnel has cancelled them, `run cancel` would stop everything else still
48
+ * running in the launch.
49
+ */
50
+ export function cancelledResultsCommand(refs) {
51
+ const ids = launchIds(refs).map(inLine);
52
+ return ids.length > 0
53
+ ? ids.map(id => `testsprite result list --run ${id} --status cancelled`).join('; ')
54
+ : undefined;
55
+ }
56
+ /**
57
+ * What `run cancel` does to a launch: it takes the launch id, so it stops
58
+ * every test in that run, not one of them.
59
+ */
60
+ export const CANCEL_STOPS_WHOLE_RUN = 'stops every test in that run';
61
+ /** The same, said of several launches at once. */
62
+ const CANCEL_STOPS_WHOLE_RUNS = 'stops every test in those runs';
63
+ /**
64
+ * The command that cancels these results' launches; see {@link waitCommand}.
65
+ * A launch this invocation started is its own to cancel, so the command stands
66
+ * alone. For a launch it only joined, the command is followed by what
67
+ * cancelling it stops.
68
+ */
69
+ export function cancelCommand(refs) {
70
+ const ids = launchIds(refs).map(inLine);
71
+ if (ids.length === 0)
72
+ return undefined;
73
+ const joined = launchIds(refs.filter(ref => ref.joined === true)).map(inLine);
74
+ const command = `testsprite run cancel ${ids.join(' ')}`;
75
+ if (joined.length === 0)
76
+ return command;
77
+ const scope = joined.length === 1 ? CANCEL_STOPS_WHOLE_RUN : CANCEL_STOPS_WHOLE_RUNS;
78
+ return (`${command} (cancelling ${joined.join(' or ')} ${scope}, ` +
79
+ 'which this command joined and did not start)');
80
+ }
81
+ /**
82
+ * What is true of work a wait let go of: it keeps executing, and billing, on
83
+ * the server. One result is named by its launch (`Run <id>`), or as
84
+ * `Result <id>` when the backend named no launch. Several are counted as
85
+ * tests, since they may all belong to one run, and refs that name only a
86
+ * launch (a run whose results were never listed) as runs.
87
+ */
88
+ export function stillRunningAndBillingSubject(refs) {
89
+ if (refs.length === 1) {
90
+ return `${runLabel(refs[0])} is still executing on the server and will keep running (and billing) until it finishes.`;
91
+ }
92
+ const tests = refs.filter(ref => idOf(ref.resultId) !== undefined).length;
93
+ const runs = refs.length - tests;
94
+ const counted = [
95
+ ...(tests > 0 ? [`${tests} test${tests === 1 ? '' : 's'}`] : []),
96
+ ...(runs > 0 ? [runCount(runs)] : []),
97
+ ].join(' and ');
98
+ return `${counted} are still executing on the server and will keep running (and billing) until they finish.`;
99
+ }
100
+ /**
101
+ * The two indented lines under a detach message: how to re-attach and how to
102
+ * cancel. Both commands take the launch, so they name each launch once; when
103
+ * the backend named no launch there is nothing to offer and no line is added.
104
+ */
105
+ export function reattachLines(refs) {
106
+ const wait = waitCommand(refs);
107
+ const cancel = cancelCommand(refs);
108
+ return ((wait ? `\n Re-attach with: ${wait}` : '') + (cancel ? `\n Cancel with: ${cancel}` : ''));
109
+ }
110
+ /** The same two commands as one trailing sentence, or nothing when no launch is known. */
111
+ export function reattachSentence(refs) {
112
+ const wait = waitCommand(refs);
113
+ const cancel = cancelCommand(refs);
114
+ return wait && cancel ? ` Re-attach with: ${wait}, or cancel with: ${cancel}` : '';
115
+ }
116
+ /**
117
+ * What a wait says when Ctrl-C ends it: only the local wait stopped, the work
118
+ * keeps executing and billing, and these are the commands to re-attach to it
119
+ * or to really stop it.
120
+ */
121
+ export function interruptDetachMessage(interrupt, refs) {
122
+ return (`Interrupted (${interrupt.signal}). ${stillRunningAndBillingSubject(refs)}` +
123
+ reattachLines(refs));
124
+ }
125
+ /** How many lookups a hint lists before it counts the rest. */
126
+ export const CHECK_LATER_LIMIT = 10;
127
+ /**
128
+ * What a wait that gave up can still point at when no launch is known (so
129
+ * neither `run wait` nor `run cancel` can be offered): one line per piece of
130
+ * work, the first ten, then a count of the rest. A test is looked up by its
131
+ * results; with no test id, or for a result named with `byResult`, the result
132
+ * is looked up itself. No line carries a placeholder. Empty when nothing can
133
+ * be looked up.
134
+ */
135
+ export function checkLaterHint(lookups) {
136
+ const commands = [];
137
+ for (const lookup of lookups) {
138
+ const testId = idOf(lookup.testId);
139
+ const resultId = idOf(lookup.resultId);
140
+ const command = testId !== undefined && lookup.byResult !== true
141
+ ? `testsprite result list --test ${inLine(testId)}`
142
+ : resultId !== undefined
143
+ ? `testsprite result get ${inLine(resultId)}`
144
+ : undefined;
145
+ if (command !== undefined && !commands.includes(command))
146
+ commands.push(command);
147
+ }
148
+ const lines = commands
149
+ .slice(0, CHECK_LATER_LIMIT)
150
+ .map(command => `Check the verdict later with: ${command}`);
151
+ if (commands.length > CHECK_LATER_LIMIT) {
152
+ lines.push(`… ${commands.length - CHECK_LATER_LIMIT} more`);
153
+ }
154
+ return lines.join('\n');
155
+ }
156
+ /**
157
+ * How prose names one result's work: `Run <launch id>` when the launch is
158
+ * known, otherwise `Result <result id>`. A result id is never called a run.
159
+ * With neither id it is just `The run`.
160
+ */
161
+ export function runLabel(ref, letterCase = 'upper') {
162
+ const launchId = idOf(ref.runId);
163
+ const resultId = idOf(ref.resultId);
164
+ const label = launchId !== undefined
165
+ ? `Run ${inLine(launchId)}`
166
+ : resultId !== undefined
167
+ ? `Result ${inLine(resultId)}`
168
+ : 'The run';
169
+ return letterCase === 'lower' ? label.charAt(0).toLowerCase() + label.slice(1) : label;
170
+ }
171
+ /**
172
+ * The id of one result's work as a `name: value` note: `resultId: <launch id>`
173
+ * when the launch is known, otherwise `resultId: <result id>`.
174
+ */
175
+ export function runIdNote(ref) {
176
+ const launchId = idOf(ref.runId);
177
+ const resultId = idOf(ref.resultId);
178
+ return launchId !== undefined
179
+ ? `runId: ${inLine(launchId)}`
180
+ : `resultId: ${resultId !== undefined ? inLine(resultId) : '(unknown)'}`;
181
+ }
182
+ export const OLDER_CLI_RESULT_ID_HINT = 'a result id printed by an older CLI is not one. Look a result up with: testsprite result get <result-id>';
183
+ //# sourceMappingURL=run-render.js.map