@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.
- package/README.md +53 -141
- package/dist/commands/agent.d.ts +12 -4
- package/dist/commands/agent.js +55 -65
- package/dist/commands/auth.d.ts +6 -10
- package/dist/commands/auth.js +44 -56
- package/dist/commands/ci.d.ts +23 -100
- package/dist/commands/ci.js +297 -489
- package/dist/commands/completion.js +2 -1
- package/dist/commands/conversation.d.ts +27 -0
- package/dist/commands/conversation.js +702 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +130 -34
- package/dist/commands/init.d.ts +4 -45
- package/dist/commands/init.js +116 -68
- package/dist/commands/project-env.d.ts +62 -2
- package/dist/commands/project-env.js +426 -53
- package/dist/commands/project-sign-in.d.ts +0 -48
- package/dist/commands/project-sign-in.js +1 -224
- package/dist/commands/project.d.ts +15 -186
- package/dist/commands/project.js +93 -921
- package/dist/commands/result.d.ts +10 -0
- package/dist/commands/result.js +215 -0
- package/dist/commands/schedule.d.ts +0 -29
- package/dist/commands/schedule.js +47 -97
- package/dist/commands/test.d.ts +315 -1824
- package/dist/commands/test.js +1962 -13733
- package/dist/commands/testlist.d.ts +128 -5
- package/dist/commands/testlist.js +269 -329
- package/dist/commands/tunnel.d.ts +2 -2
- package/dist/commands/tunnel.js +43 -41
- package/dist/commands/usage.d.ts +12 -45
- package/dist/commands/usage.js +51 -131
- package/dist/index.js +189 -108
- package/dist/lib/agent-detect.js +9 -5
- package/dist/lib/agent-targets.d.ts +21 -2
- package/dist/lib/agent-targets.js +88 -11
- package/dist/lib/args.d.ts +13 -0
- package/dist/lib/args.js +49 -0
- package/dist/lib/basic-auth.d.ts +3 -0
- package/dist/lib/basic-auth.js +15 -0
- package/dist/lib/billing-refusal.js +4 -3
- package/dist/lib/ci-linkage.d.ts +4 -82
- package/dist/lib/ci-linkage.js +4 -157
- package/dist/lib/ci-run.js +1 -1
- package/dist/lib/client-factory.d.ts +10 -2
- package/dist/lib/client-factory.js +38 -26
- package/dist/lib/commit-signal.d.ts +65 -0
- package/dist/lib/commit-signal.js +305 -0
- package/dist/lib/concurrency-limiter.d.ts +6 -0
- package/dist/lib/concurrency-limiter.js +29 -0
- package/dist/lib/config.js +10 -5
- package/dist/lib/conflict-reason.d.ts +31 -4
- package/dist/lib/conflict-reason.js +38 -4
- package/dist/lib/conversation/answers.d.ts +9 -0
- package/dist/lib/conversation/answers.js +49 -0
- package/dist/lib/conversation/api.d.ts +71 -0
- package/dist/lib/conversation/api.js +150 -0
- package/dist/lib/conversation/change.d.ts +31 -0
- package/dist/lib/conversation/change.js +124 -0
- package/dist/lib/conversation/context.d.ts +19 -0
- package/dist/lib/conversation/context.js +70 -0
- package/dist/lib/conversation/environment.d.ts +15 -0
- package/dist/lib/conversation/environment.js +33 -0
- package/dist/lib/conversation/follow.d.ts +24 -0
- package/dist/lib/conversation/follow.js +42 -0
- package/dist/lib/conversation/render.d.ts +33 -0
- package/dist/lib/conversation/render.js +315 -0
- package/dist/lib/conversation/title.d.ts +2 -0
- package/dist/lib/conversation/title.js +18 -0
- package/dist/lib/conversation/types.d.ts +156 -0
- package/dist/lib/conversation/types.js +6 -0
- package/dist/lib/credentials.js +67 -11
- package/dist/lib/cron.d.ts +1 -1
- package/dist/lib/cron.js +2 -2
- package/dist/lib/dispatch-stop.d.ts +20 -0
- package/dist/lib/dispatch-stop.js +30 -0
- package/dist/lib/download.d.ts +71 -0
- package/dist/lib/download.js +274 -0
- package/dist/lib/dry-run/fetch.d.ts +10 -0
- package/dist/lib/dry-run/fetch.js +20 -0
- package/dist/lib/dry-run/samples.d.ts +6 -34
- package/dist/lib/dry-run/samples.js +389 -751
- package/dist/lib/environment-tunnel.d.ts +16 -26
- package/dist/lib/environment-tunnel.js +161 -157
- package/dist/lib/errors.d.ts +20 -4
- package/dist/lib/errors.js +36 -16
- package/dist/lib/facade.d.ts +7 -29
- package/dist/lib/facade.js +7 -36
- package/dist/lib/failing-fe-resolver.d.ts +13 -58
- package/dist/lib/failing-fe-resolver.js +47 -132
- package/dist/lib/first-suite-hint.d.ts +16 -22
- package/dist/lib/first-suite-hint.js +38 -47
- package/dist/lib/gh-output.d.ts +76 -21
- package/dist/lib/gh-output.js +171 -90
- package/dist/lib/git-utils.d.ts +56 -0
- package/dist/lib/git-utils.js +212 -0
- package/dist/lib/github-context.d.ts +2 -0
- package/dist/lib/github-context.js +40 -8
- package/dist/lib/history-retention.d.ts +6 -2
- package/dist/lib/history-retention.js +10 -7
- package/dist/lib/http.d.ts +58 -134
- package/dist/lib/http.js +352 -271
- package/dist/lib/interrupt.d.ts +14 -8
- package/dist/lib/interrupt.js +28 -10
- package/dist/lib/junit-report.d.ts +60 -4
- package/dist/lib/junit-report.js +209 -32
- package/dist/lib/local-target.d.ts +3 -3
- package/dist/lib/local-target.js +3 -3
- package/dist/lib/output.d.ts +0 -29
- package/dist/lib/output.js +10 -33
- package/dist/lib/pagination.d.ts +2 -5
- package/dist/lib/pagination.js +2 -5
- package/dist/lib/presigned-url.d.ts +22 -0
- package/dist/lib/presigned-url.js +90 -0
- package/dist/lib/prompt.js +36 -2
- package/dist/lib/proxy.js +2 -1
- package/dist/lib/redact.d.ts +2 -2
- package/dist/lib/redact.js +3 -4
- package/dist/lib/removed-commands.d.ts +18 -0
- package/dist/lib/removed-commands.js +154 -0
- package/dist/lib/render-error.d.ts +31 -6
- package/dist/lib/render-error.js +88 -25
- package/dist/lib/response-schemas.d.ts +38 -30
- package/dist/lib/response-schemas.js +210 -207
- package/dist/lib/result/api.d.ts +24 -0
- package/dist/lib/result/api.js +28 -0
- package/dist/lib/result/evidence.d.ts +71 -0
- package/dist/lib/result/evidence.js +420 -0
- package/dist/lib/result/render.d.ts +20 -0
- package/dist/lib/result/render.js +194 -0
- package/dist/lib/result/types.d.ts +122 -0
- package/dist/lib/result/types.js +19 -0
- package/dist/lib/run-output.d.ts +275 -0
- package/dist/lib/run-output.js +227 -0
- package/dist/lib/run-render.d.ts +101 -0
- package/dist/lib/run-render.js +183 -0
- package/dist/lib/run-wait.d.ts +192 -0
- package/dist/lib/run-wait.js +452 -0
- package/dist/lib/runs.types.d.ts +134 -367
- package/dist/lib/runs.types.js +0 -14
- package/dist/lib/secret-file.d.ts +1 -1
- package/dist/lib/secret-file.js +11 -2
- package/dist/lib/skill-nudge.d.ts +7 -27
- package/dist/lib/skill-nudge.js +9 -37
- package/dist/lib/target-path.d.ts +15 -0
- package/dist/lib/target-path.js +35 -0
- package/dist/lib/target-url-advisory.d.ts +19 -0
- package/dist/lib/target-url-advisory.js +31 -0
- package/dist/lib/target-url-preflight.d.ts +9 -0
- package/dist/lib/target-url-preflight.js +214 -106
- package/dist/lib/target-url.d.ts +1 -1
- package/dist/lib/target-url.js +6 -16
- package/dist/lib/telemetry.d.ts +32 -12
- package/dist/lib/telemetry.js +39 -8
- package/dist/lib/terminal-text.d.ts +41 -0
- package/dist/lib/terminal-text.js +127 -0
- package/dist/lib/testlist.types.d.ts +16 -8
- package/dist/lib/testlist.types.js +1 -1
- package/dist/lib/text-equality.d.ts +2 -0
- package/dist/lib/text-equality.js +5 -0
- package/dist/lib/text-file.d.ts +16 -0
- package/dist/lib/text-file.js +41 -0
- package/dist/lib/text-table.d.ts +46 -0
- package/dist/lib/text-table.js +72 -4
- package/dist/lib/ticker.d.ts +9 -2
- package/dist/lib/ticker.js +16 -3
- package/dist/lib/transport-failure.d.ts +22 -0
- package/dist/lib/transport-failure.js +126 -0
- package/dist/lib/tunnel-session.d.ts +7 -1
- package/dist/lib/tunnel-session.js +22 -9
- package/dist/lib/update-check.js +3 -2
- package/dist/lib/url-template.d.ts +43 -0
- package/dist/lib/url-template.js +151 -0
- package/dist/lib/validate.d.ts +0 -64
- package/dist/lib/validate.js +2 -131
- package/dist/lib/version-notice.js +4 -3
- package/dist/lib/wait-exit.d.ts +37 -2
- package/dist/lib/wait-exit.js +88 -30
- package/dist/lib/workspace-status.js +10 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -4
- package/skills/testsprite-ci.skill.md +48 -18
- package/skills/testsprite-onboard.skill.md +66 -151
- package/skills/testsprite-verify.codex.md +54 -56
- package/skills/testsprite-verify.skill.md +194 -358
- package/dist/lib/browser.d.ts +0 -6
- package/dist/lib/browser.js +0 -54
- package/dist/lib/bundle.d.ts +0 -234
- package/dist/lib/bundle.js +0 -781
- package/dist/lib/deprecate.d.ts +0 -10
- package/dist/lib/deprecate.js +0 -13
- package/dist/lib/flaky.d.ts +0 -91
- package/dist/lib/flaky.js +0 -71
- package/dist/lib/plan-poll.d.ts +0 -171
- package/dist/lib/plan-poll.js +0 -441
- package/dist/lib/plans.types.d.ts +0 -130
- package/dist/lib/plans.types.js +0 -31
- package/dist/lib/poll.d.ts +0 -100
- package/dist/lib/poll.js +0 -290
- package/dist/lib/rate-throttle.d.ts +0 -49
- package/dist/lib/rate-throttle.js +0 -75
- package/dist/lib/run-progress.d.ts +0 -41
- package/dist/lib/run-progress.js +0 -56
- package/dist/lib/v3-advisory.d.ts +0 -55
- package/dist/lib/v3-advisory.js +0 -74
- package/schemas/plan.schema.json +0 -61
package/dist/lib/telemetry.js
CHANGED
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
* Flag-derived values are limited to bounded numeric controls:
|
|
28
28
|
* `timeoutSeconds` is the operator's timeout (not a URL or free text) and
|
|
29
29
|
* distinguishes a wait deadline from a slow backend; `localConcurrencyLimit`
|
|
30
|
-
* is
|
|
31
|
-
*
|
|
30
|
+
* is the requested integer 1–15 cap for each local execution and lets local
|
|
31
|
+
* outcomes be grouped by the requested server limit. The CLI
|
|
32
|
+
* does not estimate a server-side peak from client dispatches.
|
|
32
33
|
*
|
|
33
34
|
* `errorOrigin` ('client' | 'server') and `timeoutSeconds` are sent by this
|
|
34
35
|
* revision of the CLI. The telemetry endpoint validates against an allowlist
|
|
@@ -142,7 +143,6 @@ const COUNT_KEYS = [
|
|
|
142
143
|
'blocked',
|
|
143
144
|
'timedOut',
|
|
144
145
|
'localConcurrencyLimit',
|
|
145
|
-
'localPeakInFlight',
|
|
146
146
|
];
|
|
147
147
|
const BOOLEAN_KEYS = ['force', 'workflowExisted', 'local', 'reportReady'];
|
|
148
148
|
/** Opaque server ids the beacon accepts — a UUID, nothing free-form. */
|
|
@@ -157,6 +157,8 @@ const ENUM_KEYS = {
|
|
|
157
157
|
'mcp_view_only',
|
|
158
158
|
'local_address',
|
|
159
159
|
'tunnel-required',
|
|
160
|
+
'no_producer',
|
|
161
|
+
'producer_in_flight',
|
|
160
162
|
'error',
|
|
161
163
|
]),
|
|
162
164
|
platform: new Set(['github']),
|
|
@@ -165,6 +167,9 @@ const ENUM_KEYS = {
|
|
|
165
167
|
'gated',
|
|
166
168
|
'skipped_draft',
|
|
167
169
|
'skipped_no_pr',
|
|
170
|
+
'skipped_no_preview',
|
|
171
|
+
'timeout_preview',
|
|
172
|
+
'refused_url_template',
|
|
168
173
|
'refused_admission',
|
|
169
174
|
'refused_env',
|
|
170
175
|
'refused_preview_name',
|
|
@@ -229,13 +234,14 @@ export function takeTelemetryExtras() {
|
|
|
229
234
|
return taken;
|
|
230
235
|
}
|
|
231
236
|
/**
|
|
232
|
-
* Disjoint verdict counts over
|
|
233
|
-
*
|
|
237
|
+
* Disjoint verdict counts over finished polls. A test still running when the
|
|
238
|
+
* wait ends has no verdict. Unlike the CI summary's `failed` (which folds
|
|
234
239
|
* blocked in), `blocked` is split out here because it is the signal that
|
|
235
240
|
* separates a broken target from a failing assertion.
|
|
236
241
|
*/
|
|
237
242
|
export function batchOutcomeCounts(results) {
|
|
238
243
|
let passed = 0;
|
|
244
|
+
let failed = 0;
|
|
239
245
|
let blocked = 0;
|
|
240
246
|
let timedOut = 0;
|
|
241
247
|
for (const r of results) {
|
|
@@ -245,12 +251,14 @@ export function batchOutcomeCounts(results) {
|
|
|
245
251
|
blocked++;
|
|
246
252
|
else if (r.status === 'timeout')
|
|
247
253
|
timedOut++;
|
|
254
|
+
else if (r.status !== 'running')
|
|
255
|
+
failed++;
|
|
248
256
|
}
|
|
249
|
-
return { passed, failed
|
|
257
|
+
return { passed, failed, blocked, timedOut };
|
|
250
258
|
}
|
|
251
259
|
/**
|
|
252
260
|
* Record a batch command's dispatch accounting (and, under `--wait`, its
|
|
253
|
-
* verdict counts) in one call, so `
|
|
261
|
+
* verdict counts) in one call, so `run --project` and `run --testlist` cannot
|
|
254
262
|
* drift in how they count. `conflictReason` is the dominant reason of the
|
|
255
263
|
* batch; `results` are the polled runs (omit for a non-wait dispatch).
|
|
256
264
|
*/
|
|
@@ -271,7 +279,7 @@ export function recordBatchOutcome(batch) {
|
|
|
271
279
|
*
|
|
272
280
|
* Every branch below now fills `errorCode` — the two fallback branches
|
|
273
281
|
* (`CLIError`, and the final catch-all for a non-CLIError throw) previously
|
|
274
|
-
* left it `undefined`, which is why a meaningful share of `
|
|
282
|
+
* left it `undefined`, which is why a meaningful share of `run`
|
|
275
283
|
* invocations and `setup` failures landed in telemetry with `errorCode=None`.
|
|
276
284
|
*
|
|
277
285
|
* `errorOrigin` ('client' | 'server') resolves a real UNSUPPORTED
|
|
@@ -426,6 +434,29 @@ export function resolveTelemetryAuth(opts, deps = {}) {
|
|
|
426
434
|
});
|
|
427
435
|
return { apiKey: config.apiKey, apiUrl: config.apiUrl };
|
|
428
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* {@link resolveTelemetryAuth} for the pre-action hook, which runs before every
|
|
439
|
+
* command: never throws. An unreadable credentials file (EPERM/EACCES — the
|
|
440
|
+
* Windows ACL lock-out `doctor` diagnoses — or any other read/parse failure)
|
|
441
|
+
* returns `undefined` so the caller can skip the beacon and let the command run
|
|
442
|
+
* and report the problem its own way, as the module contract requires
|
|
443
|
+
* (telemetry never changes a command's behavior, output, or exit code).
|
|
444
|
+
* `onError` receives the swallowed error, for `--debug`.
|
|
445
|
+
*/
|
|
446
|
+
export function tryResolveTelemetryAuth(opts, deps = {}) {
|
|
447
|
+
try {
|
|
448
|
+
return resolveTelemetryAuth(opts, deps);
|
|
449
|
+
}
|
|
450
|
+
catch (error) {
|
|
451
|
+
try {
|
|
452
|
+
deps.onError?.(error);
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
// A broken diagnostic sink must not turn a skipped beacon into a failure.
|
|
456
|
+
}
|
|
457
|
+
return undefined;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
429
460
|
/**
|
|
430
461
|
* Fire one command-outcome event to the beacon. Awaited by `index.ts` before
|
|
431
462
|
* `process.exit` (the flush) — bounded and fully best-effort, so it can neither
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text from the server, made safe to print on a terminal.
|
|
3
|
+
*
|
|
4
|
+
* Titles, step descriptions, errors and URLs come from the server, and
|
|
5
|
+
* through it from the pages a test visited and from model output, so they can
|
|
6
|
+
* carry escape sequences that set the window title, open a hyperlink, clear
|
|
7
|
+
* the screen or colour what follows, and bidi controls that reorder a line.
|
|
8
|
+
* This removes every escape sequence and every other control character, and
|
|
9
|
+
* keeps line breaks and tabs. A carriage return becomes a line break, so it
|
|
10
|
+
* cannot return over a printed line.
|
|
11
|
+
*
|
|
12
|
+
* For text output only; JSON keeps the server's text and escapes these
|
|
13
|
+
* characters instead (see {@link jsonForTerminal}).
|
|
14
|
+
*/
|
|
15
|
+
export declare function terminalSafe(text: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* {@link terminalSafe} on one line: every run of whitespace, line breaks
|
|
18
|
+
* included, becomes one space. For a value printed inside a line (a cell, an
|
|
19
|
+
* id in a message), where a line break would start a line the server wrote.
|
|
20
|
+
*/
|
|
21
|
+
export declare function terminalSafeLine(text: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* A line writer whose every line goes through {@link terminalSafe} first: the
|
|
24
|
+
* stderr a command writes its own lines to (progress, hints, advisories), each
|
|
25
|
+
* of which may carry a server value. With no writer, lines go to the process's
|
|
26
|
+
* stderr. Never for JSON: a JSON line goes out through {@link jsonForTerminal}.
|
|
27
|
+
*/
|
|
28
|
+
export declare function terminalSafeWriter(write?: (line: string) => void): (line: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* The `--verbose` writer: each transition the HTTP client or a poll reports
|
|
31
|
+
* (which may name a server id) as one `[verbose]` line on `stderr`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function verboseWriter(stderr: (line: string) => void): (msg: string) => void;
|
|
34
|
+
/**
|
|
35
|
+
* `JSON.stringify` for output a terminal may show. It escapes C0 controls
|
|
36
|
+
* itself but leaves DEL, the C1 controls and the bidi controls raw: U+009B and
|
|
37
|
+
* U+009D are the 8-bit CSI and OSC, and U+202E reorders the rest of a line.
|
|
38
|
+
* This writes those as `\uXXXX` too: the same JSON value, with nothing a
|
|
39
|
+
* terminal acts on.
|
|
40
|
+
*/
|
|
41
|
+
export declare function jsonForTerminal(value: unknown, space?: number): string;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The patterns below match control characters on purpose: finding them is
|
|
3
|
+
* their whole job.
|
|
4
|
+
*/
|
|
5
|
+
/* eslint-disable no-control-regex */
|
|
6
|
+
/**
|
|
7
|
+
* Escape sequences that carry a string, through their terminator: OSC (window
|
|
8
|
+
* titles, hyperlinks), DCS, SOS, PM and APC, started by ESC and ended by ST
|
|
9
|
+
* (7-bit or 8-bit), BEL, or the CAN or SUB that aborts them, on the same line.
|
|
10
|
+
* An introducer that nothing on its line ends is not one: the later passes
|
|
11
|
+
* remove it alone and keep the text after it. So a sequence opened in one
|
|
12
|
+
* server value and ended in another can never take the lines the CLI wrote
|
|
13
|
+
* between them.
|
|
14
|
+
*
|
|
15
|
+
* The 8-bit introducers (U+0090, U+0098, U+009D–U+009F) do not start one
|
|
16
|
+
* here: in badly decoded text they are ordinary characters' second bytes (a
|
|
17
|
+
* curly quote read as Latin-1 ends in U+009D), and taking the text up to the
|
|
18
|
+
* next U+009C would drop words. The CONTROL pass removes each of them alone,
|
|
19
|
+
* so a terminal never receives one, and what followed it is printed as text.
|
|
20
|
+
*/
|
|
21
|
+
const STRING_SEQUENCE = /\u001b[\]PX^_][^\n]*?(?:\u0007|\u0018|\u001a|\u001b\\|\u009c)/g;
|
|
22
|
+
/**
|
|
23
|
+
* An ESC that starts nothing, with its intermediate bytes (0x20–0x2F) if it
|
|
24
|
+
* has any: one whose intermediates no final byte (0x30–0x7E) follows, so what
|
|
25
|
+
* comes next is not printable ASCII (another ESC, a C1 control, a line break,
|
|
26
|
+
* the end). Removed first, so that removing a sequence after it can never join
|
|
27
|
+
* it to the next visible character: `ESC (` before an OSC would otherwise take
|
|
28
|
+
* the character after the OSC as its final byte. A complete escape such as
|
|
29
|
+
* `ESC ( B` never matches: at every split of its intermediates the next
|
|
30
|
+
* character is printable. Intermediates are never a line break or an ESC, so
|
|
31
|
+
* each ESC's backtracking is bounded by its own run of them and the pass stays
|
|
32
|
+
* linear.
|
|
33
|
+
*/
|
|
34
|
+
const LONE_ESCAPE = /\u001b[ -/]*(?![ -~])/g;
|
|
35
|
+
/**
|
|
36
|
+
* Control sequences (colours, cursor moves, clearing the screen), 7-bit and
|
|
37
|
+
* 8-bit, or else any other escape: ESC, any intermediate bytes, and its final
|
|
38
|
+
* byte if there is one. One pass, so one removal cannot make the next match.
|
|
39
|
+
*/
|
|
40
|
+
const CSI_OR_ESCAPE = /(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]|\u001b[ -/]*[0-~]?/g;
|
|
41
|
+
/**
|
|
42
|
+
* C0 and C1 control characters, tab and line feed excepted, and the bidi
|
|
43
|
+
* controls (embeddings, overrides, isolates and marks) that reorder how the
|
|
44
|
+
* rest of a line reads.
|
|
45
|
+
*/
|
|
46
|
+
const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
|
|
47
|
+
/* eslint-enable no-control-regex */
|
|
48
|
+
/**
|
|
49
|
+
* Text from the server, made safe to print on a terminal.
|
|
50
|
+
*
|
|
51
|
+
* Titles, step descriptions, errors and URLs come from the server, and
|
|
52
|
+
* through it from the pages a test visited and from model output, so they can
|
|
53
|
+
* carry escape sequences that set the window title, open a hyperlink, clear
|
|
54
|
+
* the screen or colour what follows, and bidi controls that reorder a line.
|
|
55
|
+
* This removes every escape sequence and every other control character, and
|
|
56
|
+
* keeps line breaks and tabs. A carriage return becomes a line break, so it
|
|
57
|
+
* cannot return over a printed line.
|
|
58
|
+
*
|
|
59
|
+
* For text output only; JSON keeps the server's text and escapes these
|
|
60
|
+
* characters instead (see {@link jsonForTerminal}).
|
|
61
|
+
*/
|
|
62
|
+
export function terminalSafe(text) {
|
|
63
|
+
return text
|
|
64
|
+
.replace(/\r\n?/g, '\n')
|
|
65
|
+
.replace(LONE_ESCAPE, '')
|
|
66
|
+
.split('\n')
|
|
67
|
+
.map(withoutStringSequences)
|
|
68
|
+
.join('\n')
|
|
69
|
+
.replace(CSI_OR_ESCAPE, '')
|
|
70
|
+
.replace(CONTROL, '');
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* One line without its string sequences. A sequence ends at a terminator on
|
|
74
|
+
* its line, so none can match after the line's last one. Matching only up to
|
|
75
|
+
* it keeps the pass linear: from an introducer that nothing ends, the lazy
|
|
76
|
+
* match would scan to the end of the line, once per introducer.
|
|
77
|
+
*/
|
|
78
|
+
function withoutStringSequences(line) {
|
|
79
|
+
const end = endOfLastTerminator(line);
|
|
80
|
+
return line.slice(0, end).replace(STRING_SEQUENCE, '') + line.slice(end);
|
|
81
|
+
}
|
|
82
|
+
/** The index just past the last string-sequence terminator in `text`, or 0. */
|
|
83
|
+
function endOfLastTerminator(text) {
|
|
84
|
+
const st = text.lastIndexOf('\u001b\\');
|
|
85
|
+
return Math.max(text.lastIndexOf('\u0007') + 1, text.lastIndexOf('\u0018') + 1, text.lastIndexOf('\u001a') + 1, text.lastIndexOf('\u009c') + 1, st === -1 ? 0 : st + 2);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* {@link terminalSafe} on one line: every run of whitespace, line breaks
|
|
89
|
+
* included, becomes one space. For a value printed inside a line (a cell, an
|
|
90
|
+
* id in a message), where a line break would start a line the server wrote.
|
|
91
|
+
*/
|
|
92
|
+
export function terminalSafeLine(text) {
|
|
93
|
+
return terminalSafe(text).replace(/\s+/g, ' ').trim();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A line writer whose every line goes through {@link terminalSafe} first: the
|
|
97
|
+
* stderr a command writes its own lines to (progress, hints, advisories), each
|
|
98
|
+
* of which may carry a server value. With no writer, lines go to the process's
|
|
99
|
+
* stderr. Never for JSON: a JSON line goes out through {@link jsonForTerminal}.
|
|
100
|
+
*/
|
|
101
|
+
export function terminalSafeWriter(write) {
|
|
102
|
+
const target = write ?? ((line) => process.stderr.write(`${line}\n`));
|
|
103
|
+
return line => target(terminalSafe(line));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The `--verbose` writer: each transition the HTTP client or a poll reports
|
|
107
|
+
* (which may name a server id) as one `[verbose]` line on `stderr`.
|
|
108
|
+
*/
|
|
109
|
+
export function verboseWriter(stderr) {
|
|
110
|
+
return msg => stderr(`[verbose] ${terminalSafeLine(msg)}`);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* DEL, the C1 controls and the bidi controls (embeddings, overrides, isolates
|
|
114
|
+
* and marks), which `JSON.stringify` leaves as they are.
|
|
115
|
+
*/
|
|
116
|
+
const JSON_RAW_CONTROL = /[\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
|
|
117
|
+
/**
|
|
118
|
+
* `JSON.stringify` for output a terminal may show. It escapes C0 controls
|
|
119
|
+
* itself but leaves DEL, the C1 controls and the bidi controls raw: U+009B and
|
|
120
|
+
* U+009D are the 8-bit CSI and OSC, and U+202E reorders the rest of a line.
|
|
121
|
+
* This writes those as `\uXXXX` too: the same JSON value, with nothing a
|
|
122
|
+
* terminal acts on.
|
|
123
|
+
*/
|
|
124
|
+
export function jsonForTerminal(value, space) {
|
|
125
|
+
return String(JSON.stringify(value, null, space)).replace(JSON_RAW_CONTROL, char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=terminal-text.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Wire shapes for the `/api/cli/v1/testlist/*` surface (CRUD).
|
|
3
3
|
*
|
|
4
4
|
* `testId` on a case IS the test's logical id (`test_case.key`) — the same id
|
|
5
|
-
* `test list` / `test get` return and `
|
|
5
|
+
* `test list` / `test get` return and `run` accepts, so a case can be added
|
|
6
6
|
* to a list with no translation.
|
|
7
7
|
*/
|
|
8
8
|
import type { RunConflict } from './conflict-reason.js';
|
|
@@ -17,7 +17,7 @@ export interface CliTestList {
|
|
|
17
17
|
orgId: string;
|
|
18
18
|
caseCount: number;
|
|
19
19
|
projectEnvironments: CliProjectEnvironment[];
|
|
20
|
-
|
|
20
|
+
lastRunId: string | null;
|
|
21
21
|
createdAt: string;
|
|
22
22
|
updatedAt: string;
|
|
23
23
|
}
|
|
@@ -44,7 +44,7 @@ export interface CliTestListDetail extends CliTestList {
|
|
|
44
44
|
blocked: number;
|
|
45
45
|
running: number;
|
|
46
46
|
};
|
|
47
|
-
|
|
47
|
+
lastRunCreated: string | null;
|
|
48
48
|
}
|
|
49
49
|
export interface CliTestListListResponse {
|
|
50
50
|
items: CliTestList[];
|
|
@@ -52,22 +52,30 @@ export interface CliTestListListResponse {
|
|
|
52
52
|
export interface CliDeleteTestListResponse {
|
|
53
53
|
listId: string;
|
|
54
54
|
}
|
|
55
|
-
/** One dispatched
|
|
55
|
+
/** One dispatched result from `run --testlist`; wait by runId through GET /results?run=. */
|
|
56
56
|
export interface CliTestListRunAccepted {
|
|
57
57
|
testId: string;
|
|
58
|
-
|
|
58
|
+
/** The result id (wire name). Printed as `resultId`. */
|
|
59
|
+
resultId: string;
|
|
60
|
+
/** The launch this result belongs to (wire name); required for whole-run waiting. */
|
|
61
|
+
runId?: string;
|
|
59
62
|
enqueuedAt: string;
|
|
63
|
+
testTitle?: string | null;
|
|
64
|
+
dashboardUrl?: string | null;
|
|
65
|
+
executionUrl?: string | null;
|
|
60
66
|
}
|
|
61
67
|
/**
|
|
62
|
-
* `testlist
|
|
63
|
-
* the
|
|
64
|
-
* (
|
|
68
|
+
* `run --testlist` result. Mirrors the batch-run-fresh envelope so `--wait` reuses
|
|
69
|
+
* the execution wait and summary tail. `conflicts[]` carry the in-flight `currentResultId`
|
|
70
|
+
* (inspect it instead of retrying). `deferred[]` carries the cases the per-key
|
|
65
71
|
* run-rate budget could not admit this call (retry after ~60s). `notFound[]` is
|
|
66
72
|
* present on a PARTIAL `--case` miss — ids not in this list, skipped (a FULL miss
|
|
67
73
|
* is a 404). `reason` is set only when nothing dispatched (empty list).
|
|
68
74
|
*/
|
|
69
75
|
export interface CliTestListRunResponse {
|
|
70
76
|
tunnelClientId?: string;
|
|
77
|
+
/** Maximum effective server concurrency across frontend project executions. */
|
|
78
|
+
maxConcurrency?: number;
|
|
71
79
|
accepted: CliTestListRunAccepted[];
|
|
72
80
|
conflicts: RunConflict[];
|
|
73
81
|
deferred: Array<{
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Wire shapes for the `/api/cli/v1/testlist/*` surface (CRUD).
|
|
3
3
|
*
|
|
4
4
|
* `testId` on a case IS the test's logical id (`test_case.key`) — the same id
|
|
5
|
-
* `test list` / `test get` return and `
|
|
5
|
+
* `test list` / `test get` return and `run` accepts, so a case can be added
|
|
6
6
|
* to a list with no translation.
|
|
7
7
|
*/
|
|
8
8
|
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode a buffer that may start with a Unicode BOM: UTF-8 (EF BB BF),
|
|
3
|
+
* UTF-16LE (FF FE) or UTF-16BE (FE FF). BOM-less input decodes as UTF-8.
|
|
4
|
+
*
|
|
5
|
+
* Why: Windows PowerShell 5.1's `>` redirection (the default shell on
|
|
6
|
+
* Windows 10/11) writes UTF-16LE with a BOM, and this CLI's own documentation
|
|
7
|
+
* suggests exactly that redirection for creating plan files. Readers that
|
|
8
|
+
* decode UTF-8 unconditionally turn the CLI's own template into garbage.
|
|
9
|
+
*/
|
|
10
|
+
export declare function decodeWithBom(bytes: Buffer): string;
|
|
11
|
+
/**
|
|
12
|
+
* Read a small text file, sniffing and stripping UTF-8 / UTF-16LE / UTF-16BE
|
|
13
|
+
* BOMs. BOM-less files decode as UTF-8, byte-for-byte unchanged from
|
|
14
|
+
* `readFileSync(path, 'utf8')`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function readTextFileBomAware(path: string): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* Decode a buffer that may start with a Unicode BOM: UTF-8 (EF BB BF),
|
|
4
|
+
* UTF-16LE (FF FE) or UTF-16BE (FE FF). BOM-less input decodes as UTF-8.
|
|
5
|
+
*
|
|
6
|
+
* Why: Windows PowerShell 5.1's `>` redirection (the default shell on
|
|
7
|
+
* Windows 10/11) writes UTF-16LE with a BOM, and this CLI's own documentation
|
|
8
|
+
* suggests exactly that redirection for creating plan files. Readers that
|
|
9
|
+
* decode UTF-8 unconditionally turn the CLI's own template into garbage.
|
|
10
|
+
*/
|
|
11
|
+
export function decodeWithBom(bytes) {
|
|
12
|
+
if (bytes.length >= 3 && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf) {
|
|
13
|
+
return bytes.subarray(3).toString('utf8');
|
|
14
|
+
}
|
|
15
|
+
if (bytes.length >= 2 && bytes[0] === 0xff && bytes[1] === 0xfe) {
|
|
16
|
+
return bytes.subarray(2).toString('utf16le');
|
|
17
|
+
}
|
|
18
|
+
if (bytes.length >= 2 && bytes[0] === 0xfe && bytes[1] === 0xff) {
|
|
19
|
+
// Buffers have no 'utf16be' decoder: swap the byte pairs, then decode LE.
|
|
20
|
+
// An odd trailing byte is an incomplete code unit — reject it here instead
|
|
21
|
+
// of letting swap16() throw an untyped ERR_INVALID_BUFFER_SIZE.
|
|
22
|
+
const body = bytes.subarray(2);
|
|
23
|
+
if (body.length % 2 !== 0) {
|
|
24
|
+
throw new Error('UTF-16BE input ends with an incomplete code unit');
|
|
25
|
+
}
|
|
26
|
+
const be = Buffer.from(body);
|
|
27
|
+
be.swap16();
|
|
28
|
+
return be.toString('utf16le');
|
|
29
|
+
}
|
|
30
|
+
return bytes.toString('utf8');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Read a small text file, sniffing and stripping UTF-8 / UTF-16LE / UTF-16BE
|
|
34
|
+
* BOMs. BOM-less files decode as UTF-8, byte-for-byte unchanged from
|
|
35
|
+
* `readFileSync(path, 'utf8')`.
|
|
36
|
+
*/
|
|
37
|
+
export function readTextFileBomAware(path) {
|
|
38
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- `path` is a caller-supplied text file path; this helper only changes how the bytes are decoded, so callers keep their own path checks, exactly as with the readFileSync(path, 'utf8') call it replaces.
|
|
39
|
+
return decodeWithBom(readFileSync(path));
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=text-file.js.map
|
package/dist/lib/text-table.d.ts
CHANGED
|
@@ -8,7 +8,53 @@ export interface TextTableOptions {
|
|
|
8
8
|
noHeader?: boolean;
|
|
9
9
|
separator?: boolean;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Render `rows` as an aligned plain-text table over the selected columns.
|
|
13
|
+
*
|
|
14
|
+
* Column widths come from {@link measureTextColumns}, so cells are padded by
|
|
15
|
+
* terminal display width (CJK/full-width aware) and a column always fits its
|
|
16
|
+
* header and every rendered cell.
|
|
17
|
+
*
|
|
18
|
+
* @param rows - Data rows to render.
|
|
19
|
+
* @param columns - Column definitions (all of them; `options.columns` selects).
|
|
20
|
+
* @param options - `columns` selection string, `noHeader`, `separator`.
|
|
21
|
+
* @returns The rendered table, newline-joined, with no trailing newline.
|
|
22
|
+
*/
|
|
11
23
|
export declare function renderTextTable<T>(rows: readonly T[], columns: readonly TextTableColumn<T>[], options?: TextTableOptions): string;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the user's `--columns` selection string against the full column set.
|
|
26
|
+
*
|
|
27
|
+
* Matching is case-insensitive and ignores non-alphanumerics
|
|
28
|
+
* (see {@link textColumnKey}), so `"default-env"` selects `DEFAULT ENV`.
|
|
29
|
+
*
|
|
30
|
+
* @returns The selected columns in the requested order.
|
|
31
|
+
* @throws {localValidationError} On an empty selection token or an unknown
|
|
32
|
+
* column key; the error's payload lists the valid keys.
|
|
33
|
+
*/
|
|
12
34
|
export declare function resolveTextColumns<T>(raw: string | undefined, columns: readonly TextTableColumn<T>[]): readonly TextTableColumn<T>[];
|
|
35
|
+
/**
|
|
36
|
+
* Measure the final display width of each column.
|
|
37
|
+
*
|
|
38
|
+
* The declared width is a floor, measured however the caller likes (usually
|
|
39
|
+
* `.length`). It is raised to the widest RENDERED cell and to the header,
|
|
40
|
+
* both measured in terminal display columns: `.length` counts UTF-16 code
|
|
41
|
+
* units, so an East-Asian full-width character (2 terminal cells, 1 code
|
|
42
|
+
* unit) made a row containing it push every column to its right out of
|
|
43
|
+
* alignment. Measuring rendered cells here fixes every table that goes
|
|
44
|
+
* through this module, and an overlong cell widens its column instead of
|
|
45
|
+
* overflowing it (a long ASCII value had the same misaligning effect
|
|
46
|
+
* before). The header joins the floor too: `--columns` reordering can put a
|
|
47
|
+
* narrow declared width in front of wider columns, and a header wider than
|
|
48
|
+
* its own column overflowed it the same way.
|
|
49
|
+
*
|
|
50
|
+
* @param rows - The rows about to be rendered; their cells are measured.
|
|
51
|
+
* @param columns - The selected column definitions.
|
|
52
|
+
* @returns One display-column width per column, in column order.
|
|
53
|
+
*/
|
|
13
54
|
export declare function measureTextColumns<T>(rows: readonly T[], columns: readonly TextTableColumn<T>[]): number[];
|
|
55
|
+
/**
|
|
56
|
+
* Format one table row: pad every value to its column's display width except
|
|
57
|
+
* the last, joined by two spaces (the last column is left unpadded so the
|
|
58
|
+
* line never carries trailing whitespace).
|
|
59
|
+
*/
|
|
14
60
|
export declare function formatTextTableRow(values: readonly string[], widths: readonly number[]): string;
|
package/dist/lib/text-table.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { localValidationError } from './errors.js';
|
|
2
|
+
import { terminalSafeLine } from './terminal-text.js';
|
|
3
|
+
import { terminalWidth } from './ticker.js';
|
|
4
|
+
/**
|
|
5
|
+
* Render `rows` as an aligned plain-text table over the selected columns.
|
|
6
|
+
*
|
|
7
|
+
* Column widths come from {@link measureTextColumns}, so cells are padded by
|
|
8
|
+
* terminal display width (CJK/full-width aware) and a column always fits its
|
|
9
|
+
* header and every rendered cell.
|
|
10
|
+
*
|
|
11
|
+
* @param rows - Data rows to render.
|
|
12
|
+
* @param columns - Column definitions (all of them; `options.columns` selects).
|
|
13
|
+
* @param options - `columns` selection string, `noHeader`, `separator`.
|
|
14
|
+
* @returns The rendered table, newline-joined, with no trailing newline.
|
|
15
|
+
*/
|
|
2
16
|
export function renderTextTable(rows, columns, options = {}) {
|
|
3
|
-
|
|
17
|
+
// A cell is one line of server text: no escape sequence, and no line break
|
|
18
|
+
// that would start a row the server wrote. Made safe before it is measured.
|
|
19
|
+
const selected = resolveTextColumns(options.columns, columns).map(column => ({
|
|
20
|
+
...column,
|
|
21
|
+
render: (row) => terminalSafeLine(column.render(row)),
|
|
22
|
+
}));
|
|
4
23
|
const widths = measureTextColumns(rows, selected);
|
|
5
24
|
const body = rows.map(row => formatTextTableRow(selected.map(column => column.render(row)), widths));
|
|
6
25
|
if (options.noHeader === true)
|
|
@@ -8,6 +27,16 @@ export function renderTextTable(rows, columns, options = {}) {
|
|
|
8
27
|
const header = formatTextTableRow(selected.map(column => column.header), widths);
|
|
9
28
|
return [header, ...(options.separator === true ? ['-'.repeat(header.length)] : []), ...body].join('\n');
|
|
10
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolve the user's `--columns` selection string against the full column set.
|
|
32
|
+
*
|
|
33
|
+
* Matching is case-insensitive and ignores non-alphanumerics
|
|
34
|
+
* (see {@link textColumnKey}), so `"default-env"` selects `DEFAULT ENV`.
|
|
35
|
+
*
|
|
36
|
+
* @returns The selected columns in the requested order.
|
|
37
|
+
* @throws {localValidationError} On an empty selection token or an unknown
|
|
38
|
+
* column key; the error's payload lists the valid keys.
|
|
39
|
+
*/
|
|
11
40
|
export function resolveTextColumns(raw, columns) {
|
|
12
41
|
if (raw === undefined || raw.trim() === '')
|
|
13
42
|
return columns;
|
|
@@ -26,20 +55,59 @@ export function resolveTextColumns(raw, columns) {
|
|
|
26
55
|
return column;
|
|
27
56
|
});
|
|
28
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Measure the final display width of each column.
|
|
60
|
+
*
|
|
61
|
+
* The declared width is a floor, measured however the caller likes (usually
|
|
62
|
+
* `.length`). It is raised to the widest RENDERED cell and to the header,
|
|
63
|
+
* both measured in terminal display columns: `.length` counts UTF-16 code
|
|
64
|
+
* units, so an East-Asian full-width character (2 terminal cells, 1 code
|
|
65
|
+
* unit) made a row containing it push every column to its right out of
|
|
66
|
+
* alignment. Measuring rendered cells here fixes every table that goes
|
|
67
|
+
* through this module, and an overlong cell widens its column instead of
|
|
68
|
+
* overflowing it (a long ASCII value had the same misaligning effect
|
|
69
|
+
* before). The header joins the floor too: `--columns` reordering can put a
|
|
70
|
+
* narrow declared width in front of wider columns, and a header wider than
|
|
71
|
+
* its own column overflowed it the same way.
|
|
72
|
+
*
|
|
73
|
+
* @param rows - The rows about to be rendered; their cells are measured.
|
|
74
|
+
* @param columns - The selected column definitions.
|
|
75
|
+
* @returns One display-column width per column, in column order.
|
|
76
|
+
*/
|
|
29
77
|
export function measureTextColumns(rows, columns) {
|
|
30
|
-
return columns.map(column =>
|
|
78
|
+
return columns.map(column => {
|
|
79
|
+
let width = Math.max(terminalWidth(column.header), typeof column.width === 'function' ? column.width(rows) : column.width);
|
|
80
|
+
for (const row of rows) {
|
|
81
|
+
const cellWidth = terminalWidth(column.render(row));
|
|
82
|
+
if (cellWidth > width)
|
|
83
|
+
width = cellWidth;
|
|
84
|
+
}
|
|
85
|
+
return width;
|
|
86
|
+
});
|
|
31
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Format one table row: pad every value to its column's display width except
|
|
90
|
+
* the last, joined by two spaces (the last column is left unpadded so the
|
|
91
|
+
* line never carries trailing whitespace).
|
|
92
|
+
*/
|
|
32
93
|
export function formatTextTableRow(values, widths) {
|
|
33
94
|
return values
|
|
34
95
|
.map((value, index) => (index === values.length - 1 ? value : pad(value, widths[index] ?? 0)))
|
|
35
96
|
.join(' ');
|
|
36
97
|
}
|
|
98
|
+
/** Lowercase and strip non-alphanumerics so `DEFAULT ENV` matches `default-env`. */
|
|
37
99
|
function textColumnKey(value) {
|
|
38
100
|
return value.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
39
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Right-pad `value` with spaces up to `width` terminal display columns.
|
|
104
|
+
* Measures display width (CJK/full-width = 2 cells), not UTF-16 length; a
|
|
105
|
+
* value already at or beyond `width` is returned unchanged.
|
|
106
|
+
*/
|
|
40
107
|
function pad(value, width) {
|
|
41
|
-
|
|
108
|
+
const display = terminalWidth(value);
|
|
109
|
+
if (display >= width)
|
|
42
110
|
return value;
|
|
43
|
-
return value + ' '.repeat(width -
|
|
111
|
+
return value + ' '.repeat(width - display);
|
|
44
112
|
}
|
|
45
113
|
//# sourceMappingURL=text-table.js.map
|
package/dist/lib/ticker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TTY-gated single-line stderr progress ticker for `
|
|
3
|
-
* and `
|
|
2
|
+
* TTY-gated single-line stderr progress ticker for `run --wait`
|
|
3
|
+
* and `run wait`. On non-TTY (CI) the ticker is completely silent —
|
|
4
4
|
* logs stay clean for shell-script consumers.
|
|
5
5
|
*
|
|
6
6
|
* Behavior:
|
|
@@ -48,6 +48,13 @@ export interface Ticker {
|
|
|
48
48
|
* an empty string, per https://no-color.org/.
|
|
49
49
|
*/
|
|
50
50
|
export declare function isNoColor(env?: NodeJS.ProcessEnv): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Measure a complete string in terminal display columns.
|
|
53
|
+
*
|
|
54
|
+
* @param text - Text to measure.
|
|
55
|
+
* @returns The number of terminal columns occupied by the text.
|
|
56
|
+
*/
|
|
57
|
+
export declare function terminalWidth(text: string): number;
|
|
51
58
|
/**
|
|
52
59
|
* Create a ticker bound to the given stderr writer. Respects
|
|
53
60
|
* `isTTY` to silently no-op in CI environments.
|
package/dist/lib/ticker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TTY-gated single-line stderr progress ticker for `
|
|
3
|
-
* and `
|
|
2
|
+
* TTY-gated single-line stderr progress ticker for `run --wait`
|
|
3
|
+
* and `run wait`. On non-TTY (CI) the ticker is completely silent —
|
|
4
4
|
* logs stay clean for shell-script consumers.
|
|
5
5
|
*
|
|
6
6
|
* Behavior:
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* Timestamps: each tick prefixes an ISO 8601 timestamp so engineers
|
|
18
18
|
* can correlate spinner output with --debug logs (dogfood item 2).
|
|
19
19
|
*/
|
|
20
|
+
import { terminalSafe, terminalSafeLine } from './terminal-text.js';
|
|
20
21
|
/**
|
|
21
22
|
* Returns true when NO_COLOR is present in the environment and is not
|
|
22
23
|
* an empty string, per https://no-color.org/.
|
|
@@ -81,7 +82,7 @@ function graphemeWidth(grapheme) {
|
|
|
81
82
|
* @param text - Text to measure.
|
|
82
83
|
* @returns The number of terminal columns occupied by the text.
|
|
83
84
|
*/
|
|
84
|
-
function terminalWidth(text) {
|
|
85
|
+
export function terminalWidth(text) {
|
|
85
86
|
let width = 0;
|
|
86
87
|
for (const { segment } of graphemeSegmenter.segment(text)) {
|
|
87
88
|
width += graphemeWidth(segment);
|
|
@@ -128,6 +129,18 @@ function fitToTerminal(line) {
|
|
|
128
129
|
* Defaults to checking `NO_COLOR` env var per https://no-color.org/.
|
|
129
130
|
*/
|
|
130
131
|
export function createTicker(stderrWrite, isTTY, stderrRaw, noColor) {
|
|
132
|
+
// A line names server values (a title, a status, an id). The ticker writes
|
|
133
|
+
// its own escape sequences around them, so they reach it already safe: the
|
|
134
|
+
// live line on one line, a note with its line breaks kept.
|
|
135
|
+
const ticker = createTickerWriter(stderrWrite, isTTY, stderrRaw, noColor);
|
|
136
|
+
return {
|
|
137
|
+
redrawsInPlace: ticker.redrawsInPlace,
|
|
138
|
+
update: line => ticker.update(terminalSafeLine(line)),
|
|
139
|
+
finalize: line => ticker.finalize(line === undefined ? undefined : terminalSafeLine(line)),
|
|
140
|
+
note: line => ticker.note(terminalSafe(line)),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function createTickerWriter(stderrWrite, isTTY, stderrRaw, noColor) {
|
|
131
144
|
const tty = isTTY ?? (typeof process !== 'undefined' ? process.stderr.isTTY === true : false);
|
|
132
145
|
const rawWrite = stderrRaw ??
|
|
133
146
|
(typeof process !== 'undefined'
|