@testsprite/testsprite-cli 0.12.0 → 0.14.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 +59 -49
- package/dist/commands/agent.js +16 -13
- package/dist/commands/auth.d.ts +19 -0
- package/dist/commands/auth.js +60 -24
- package/dist/commands/ci.d.ts +86 -1
- package/dist/commands/ci.js +436 -5
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +34 -20
- package/dist/commands/init.js +14 -11
- package/dist/commands/project-env.d.ts +11 -1
- package/dist/commands/project-env.js +408 -70
- package/dist/commands/project-sign-in.d.ts +60 -0
- package/dist/commands/project-sign-in.js +289 -0
- package/dist/commands/project.d.ts +14 -5
- package/dist/commands/project.js +110 -70
- package/dist/commands/schedule.d.ts +14 -0
- package/dist/commands/schedule.js +193 -15
- package/dist/commands/test.d.ts +123 -44
- package/dist/commands/test.js +2993 -636
- package/dist/commands/testlist.d.ts +10 -5
- package/dist/commands/testlist.js +217 -47
- package/dist/commands/tunnel.d.ts +26 -3
- package/dist/commands/tunnel.js +221 -18
- package/dist/commands/usage.d.ts +3 -0
- package/dist/commands/usage.js +12 -5
- package/dist/index.js +39 -50
- package/dist/lib/agent-targets.d.ts +3 -3
- package/dist/lib/agent-targets.js +2 -2
- package/dist/lib/billing-refusal.d.ts +43 -0
- package/dist/lib/billing-refusal.js +171 -0
- package/dist/lib/bundle.d.ts +5 -0
- package/dist/lib/bundle.js +43 -13
- package/dist/lib/ci-linkage.d.ts +90 -0
- package/dist/lib/ci-linkage.js +181 -0
- package/dist/lib/client-factory.d.ts +16 -2
- package/dist/lib/client-factory.js +37 -6
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.js +20 -1
- package/dist/lib/conflict-reason.d.ts +27 -3
- package/dist/lib/conflict-reason.js +53 -4
- package/dist/lib/credentials.js +56 -14
- package/dist/lib/dry-run/samples.d.ts +13 -1
- package/dist/lib/dry-run/samples.js +104 -7
- package/dist/lib/environment-tunnel.d.ts +109 -0
- package/dist/lib/environment-tunnel.js +465 -0
- package/dist/lib/errors.d.ts +18 -11
- package/dist/lib/errors.js +123 -14
- package/dist/lib/failing-fe-resolver.d.ts +1 -1
- package/dist/lib/failing-fe-resolver.js +3 -3
- package/dist/lib/gh-output.d.ts +1 -0
- package/dist/lib/gh-output.js +16 -4
- package/dist/lib/history-retention.d.ts +8 -0
- package/dist/lib/history-retention.js +24 -0
- package/dist/lib/http.d.ts +39 -19
- package/dist/lib/http.js +46 -24
- package/dist/lib/interrupt.d.ts +21 -13
- package/dist/lib/interrupt.js +32 -21
- package/dist/lib/junit-report.d.ts +18 -4
- package/dist/lib/junit-report.js +23 -5
- package/dist/lib/local-target.d.ts +14 -4
- package/dist/lib/local-target.js +48 -13
- package/dist/lib/output.js +15 -1
- package/dist/lib/plan-poll.d.ts +11 -11
- package/dist/lib/plan-poll.js +15 -16
- package/dist/lib/plans.types.d.ts +9 -9
- package/dist/lib/plans.types.js +3 -3
- package/dist/lib/poll.d.ts +2 -2
- package/dist/lib/poll.js +9 -3
- package/dist/lib/redact.d.ts +38 -0
- package/dist/lib/redact.js +140 -0
- package/dist/lib/render-error.d.ts +21 -5
- package/dist/lib/render-error.js +44 -0
- package/dist/lib/response-schemas.d.ts +54 -12
- package/dist/lib/response-schemas.js +88 -7
- package/dist/lib/runs.types.d.ts +68 -11
- package/dist/lib/secret-file.js +72 -14
- package/dist/lib/skill-nudge.d.ts +6 -1
- package/dist/lib/skill-nudge.js +32 -5
- package/dist/lib/target-url-preflight.d.ts +6 -4
- package/dist/lib/target-url-preflight.js +64 -51
- package/dist/lib/target-url.js +11 -11
- package/dist/lib/telemetry.d.ts +10 -8
- package/dist/lib/telemetry.js +24 -17
- package/dist/lib/testlist.types.d.ts +1 -0
- package/dist/lib/ticker.d.ts +9 -0
- package/dist/lib/ticker.js +111 -4
- package/dist/lib/tunnel-session.d.ts +16 -4
- package/dist/lib/tunnel-session.js +7 -5
- package/dist/lib/tunnel.types.d.ts +12 -2
- package/dist/lib/tunnel.types.js +2 -2
- package/dist/lib/v3-advisory.js +0 -1
- package/dist/lib/wait-exit.d.ts +8 -0
- package/dist/lib/wait-exit.js +76 -4
- package/dist/lib/workspace-status.d.ts +23 -0
- package/dist/lib/workspace-status.js +15 -0
- package/dist/vendor/tunnel-client/client.d.ts +15 -8
- package/dist/vendor/tunnel-client/client.js +477 -407
- package/dist/vendor/tunnel-client/config.d.ts +5 -5
- package/dist/vendor/tunnel-client/config.js +5 -5
- package/dist/vendor/tunnel-client/index.d.ts +4 -4
- package/dist/vendor/tunnel-client/index.js +4 -4
- package/dist/vendor/tunnel-client/types.d.ts +19 -34
- package/dist/vendor/tunnel-client/types.js +1 -0
- package/dist/vendor/tunnel-client/ws-compat.d.ts +13 -3
- package/dist/vendor/tunnel-client/ws-compat.js +70 -12
- package/dist/version-guard.d.ts +7 -1
- package/dist/version-guard.js +19 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/skills/testsprite-onboard.skill.md +8 -8
- package/skills/testsprite-verify.codex.md +59 -57
- package/skills/testsprite-verify.skill.md +53 -38
package/dist/lib/http.js
CHANGED
|
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
import { ApiError, InterruptError, RequestTimeoutError, TransportError } from './errors.js';
|
|
4
4
|
import { buildUserAgent } from './client-tag.js';
|
|
5
|
-
import { BATCH_RERUN_RESPONSE_SCHEMA, BATCH_RUN_FRESH_RESPONSE_SCHEMA, CANCEL_RUN_RESPONSE_SCHEMA, LIST_RUNS_RESPONSE_SCHEMA, RERUN_RESPONSE_SCHEMA, RUN_RESPONSE_SCHEMA, TESTLIST_RUN_RESPONSE_SCHEMA, TRIGGER_RUN_RESPONSE_SCHEMA, TUNNEL_MINT_RESPONSE_SCHEMA, TUNNEL_STATUS_RESPONSE_SCHEMA, } from './response-schemas.js';
|
|
5
|
+
import { BATCH_RERUN_RESPONSE_SCHEMA, BATCH_RUN_FRESH_RESPONSE_SCHEMA, CANCEL_RUN_RESPONSE_SCHEMA, LIST_RUNS_RESPONSE_SCHEMA, RERUN_RESPONSE_SCHEMA, RUN_RESPONSE_SCHEMA, TESTLIST_RUN_RESPONSE_SCHEMA, TRIGGER_RUN_RESPONSE_SCHEMA, TUNNEL_LIST_RESPONSE_SCHEMA, TUNNEL_MINT_RESPONSE_SCHEMA, TUNNEL_STATUS_RESPONSE_SCHEMA, } from './response-schemas.js';
|
|
6
6
|
/**
|
|
7
7
|
* Default per-request timeout (120s). Comfortably covers every metadata/read
|
|
8
8
|
* request and every <=25s long-poll request (`?waitSeconds` is capped at 25
|
|
@@ -41,11 +41,16 @@ const MAX_ATTEMPTS_INTERNAL = 2;
|
|
|
41
41
|
const MAX_RATE_LIMITED_DELAY_MS = 60_000;
|
|
42
42
|
/**
|
|
43
43
|
* 429 reasons that name a STANDING condition rather than a passing throttle —
|
|
44
|
-
* e.g. the per-user cap on live tunnel bindings
|
|
45
|
-
*
|
|
46
|
-
* server's nextAction (e.g.
|
|
44
|
+
* e.g. the per-user cap on live tunnel bindings, or already having the maximum
|
|
45
|
+
* number of runs in flight. Retrying cannot succeed until the caller frees the
|
|
46
|
+
* resource, so the retry budget is skipped and the server's nextAction (e.g.
|
|
47
|
+
* `testsprite tunnel stop`) surfaces immediately. `Retry-After` on these says
|
|
48
|
+
* when a retry COULD first succeed, not that the condition clears on its own.
|
|
47
49
|
*/
|
|
48
|
-
export const STANDING_RATE_LIMIT_REASONS = new Set([
|
|
50
|
+
export const STANDING_RATE_LIMIT_REASONS = new Set([
|
|
51
|
+
'tunnel_binding_limit',
|
|
52
|
+
'inflight_cap',
|
|
53
|
+
]);
|
|
49
54
|
/** True for a RATE_LIMITED error whose envelope names a standing condition. */
|
|
50
55
|
export function isStandingRateLimit(err) {
|
|
51
56
|
if (err.code !== 'RATE_LIMITED')
|
|
@@ -78,12 +83,14 @@ export class HttpClient {
|
|
|
78
83
|
onServerVersion;
|
|
79
84
|
requestTimeoutMs;
|
|
80
85
|
shutdownSignal;
|
|
86
|
+
shutdown;
|
|
81
87
|
maxResponseBytes;
|
|
82
88
|
userAgent;
|
|
83
89
|
constructor(options) {
|
|
84
90
|
this.baseUrl = trimTrailingSlash(options.baseUrl);
|
|
85
91
|
this.apiKey = options.apiKey;
|
|
86
92
|
this.shutdownSignal = options.shutdownSignal;
|
|
93
|
+
this.shutdown = options.shutdown;
|
|
87
94
|
// Resolved once: the tag is process-wide configuration, not per-request.
|
|
88
95
|
this.userAgent = buildUserAgent(options.env ?? process.env);
|
|
89
96
|
this.fetchImpl = options.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
@@ -97,8 +104,7 @@ export class HttpClient {
|
|
|
97
104
|
}
|
|
98
105
|
/** The resolved facade base URL (trailing slash trimmed). Read-only —
|
|
99
106
|
* callers that bypass the client for a side-channel request (e.g. the
|
|
100
|
-
* presigned S3 PUT) use it to reason about the facade's locality
|
|
101
|
-
* (DEV-384 review F3). */
|
|
107
|
+
* presigned S3 PUT) use it to reason about the facade's locality. */
|
|
102
108
|
get resolvedBaseUrl() {
|
|
103
109
|
return this.baseUrl;
|
|
104
110
|
}
|
|
@@ -140,7 +146,7 @@ export class HttpClient {
|
|
|
140
146
|
/**
|
|
141
147
|
* Like `get` / `post` / etc. but returns the full `RequestResult` including
|
|
142
148
|
* `requestId` and `status`, so callers can surface the requestId in
|
|
143
|
-
* happy-path output
|
|
149
|
+
* happy-path output.
|
|
144
150
|
*/
|
|
145
151
|
async getWithMeta(path, options = {}) {
|
|
146
152
|
return this.requestWithMeta('GET', path, options);
|
|
@@ -343,6 +349,16 @@ export class HttpClient {
|
|
|
343
349
|
retryOnConflict: false,
|
|
344
350
|
}).then(r => r.body);
|
|
345
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* GET /api/cli/v1/tunnel — list this account's live bindings.
|
|
354
|
+
* Secret-free, partition-scoped by the server; requires `run:tunnel`.
|
|
355
|
+
*/
|
|
356
|
+
async listTunnels(options = {}) {
|
|
357
|
+
return this.get('/tunnel', {
|
|
358
|
+
signal: options.signal,
|
|
359
|
+
schema: TUNNEL_LIST_RESPONSE_SCHEMA,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
346
362
|
/**
|
|
347
363
|
* GET /api/cli/v1/tunnel/{clientId} — is this binding's client connected?
|
|
348
364
|
*
|
|
@@ -350,7 +366,8 @@ export class HttpClient {
|
|
|
350
366
|
* deliberately not an existence oracle for client ids. Callers must not
|
|
351
367
|
* translate a transport failure or a non-200 into `offline` — "the tunnel is
|
|
352
368
|
* down" and "we could not reach TestSprite to ask" are different answers,
|
|
353
|
-
* and collapsing them
|
|
369
|
+
* and collapsing them would misreport a transient network failure as a
|
|
370
|
+
* dead tunnel.
|
|
354
371
|
*/
|
|
355
372
|
async getTunnelStatus(clientId, options = {}) {
|
|
356
373
|
return this.get(`/tunnel/${encodeURIComponent(clientId)}`, {
|
|
@@ -375,8 +392,8 @@ export class HttpClient {
|
|
|
375
392
|
}
|
|
376
393
|
/**
|
|
377
394
|
* POST /api/cli/v1/runs/{runId}/cancel
|
|
378
|
-
* User-initiated cancel of a queued/running run
|
|
379
|
-
* body, no `Idempotency-Key` — the endpoint is naturally idempotent
|
|
395
|
+
* User-initiated cancel of a queued/running run. No
|
|
396
|
+
* body, no `Idempotency-Key` — the endpoint is naturally idempotent:
|
|
380
397
|
* re-cancel → 200 `alreadyCancelled: true`; already-terminal (passed/
|
|
381
398
|
* failed/blocked) → 409 CONFLICT; unknown/cross-tenant runId → 404.
|
|
382
399
|
*
|
|
@@ -392,7 +409,7 @@ export class HttpClient {
|
|
|
392
409
|
});
|
|
393
410
|
}
|
|
394
411
|
/**
|
|
395
|
-
* POST /api/cli/v1/projects/{projectId}/plans/generate
|
|
412
|
+
* POST /api/cli/v1/projects/{projectId}/plans/generate
|
|
396
413
|
* Start whichever generation stage the project is missing next. The body
|
|
397
414
|
* is empty by contract — the server decides which rung fires. 202 both
|
|
398
415
|
* for `accepted` (a stage started) and `nothing_to_start` (proposals are
|
|
@@ -412,7 +429,7 @@ export class HttpClient {
|
|
|
412
429
|
});
|
|
413
430
|
}
|
|
414
431
|
/**
|
|
415
|
-
* GET /api/cli/v1/projects/{projectId}/plans
|
|
432
|
+
* GET /api/cli/v1/projects/{projectId}/plans
|
|
416
433
|
* Pure read: the facade-synthesized generation status, the staged
|
|
417
434
|
* proposal list (stable proposalIds — what `accept --only` consumes),
|
|
418
435
|
* and a best-effort credits block. When `waitSeconds` (1–25) is
|
|
@@ -426,7 +443,7 @@ export class HttpClient {
|
|
|
426
443
|
});
|
|
427
444
|
}
|
|
428
445
|
/**
|
|
429
|
-
* POST /api/cli/v1/projects/{projectId}/plans/accept
|
|
446
|
+
* POST /api/cli/v1/projects/{projectId}/plans/accept
|
|
430
447
|
* Convert staged proposals into real test cases. `only` is ALWAYS an
|
|
431
448
|
* explicit, non-empty id list — the caller enforces the two §3.3 safety
|
|
432
449
|
* rules (full list when the user didn't subset; an empty selection is a
|
|
@@ -450,7 +467,7 @@ export class HttpClient {
|
|
|
450
467
|
* continue its own error handling (transport retry / envelope parse).
|
|
451
468
|
*/
|
|
452
469
|
rethrowIfAbort(err, timeoutSignal, callerSignal, requestId, effectiveSignal = timeoutSignal) {
|
|
453
|
-
// A user interrupt
|
|
470
|
+
// A user interrupt outranks every other classification: once the
|
|
454
471
|
// shutdown signal fired, whatever error surfaced from the aborted fetch or
|
|
455
472
|
// body read is the interrupt. Throw its InterruptError reason so the wait
|
|
456
473
|
// paths can render the honest detach UX — never a RequestTimeoutError, and
|
|
@@ -472,6 +489,10 @@ export class HttpClient {
|
|
|
472
489
|
async requestWithMeta(method, path, options = {}) {
|
|
473
490
|
if (!this.apiKey)
|
|
474
491
|
throw ApiError.authRequired();
|
|
492
|
+
const operation = () => this.requestWithMetaUntracked(method, path, options);
|
|
493
|
+
return this.shutdown ? this.shutdown.runCriticalOperation(operation) : operation();
|
|
494
|
+
}
|
|
495
|
+
async requestWithMetaUntracked(method, path, options = {}) {
|
|
475
496
|
const url = buildUrl(this.baseUrl, path, options.query);
|
|
476
497
|
const requestId = options.requestId ?? newRequestId();
|
|
477
498
|
const allowRetry = options.retry !== false;
|
|
@@ -499,7 +520,7 @@ export class HttpClient {
|
|
|
499
520
|
const composedSignals = [timeoutSignal];
|
|
500
521
|
if (options.signal != null)
|
|
501
522
|
composedSignals.push(options.signal);
|
|
502
|
-
// Shutdown composition
|
|
523
|
+
// Shutdown composition: an armed SIGINT/SIGTERM aborts the
|
|
503
524
|
// in-flight fetch immediately (reason: InterruptError) instead of
|
|
504
525
|
// letting a long-poll drain its window before the interrupt surfaces.
|
|
505
526
|
if (this.shutdownSignal != null)
|
|
@@ -537,7 +558,7 @@ export class HttpClient {
|
|
|
537
558
|
// The instanceof check matters even without `this.shutdownSignal`:
|
|
538
559
|
// the polling path composes the shutdown signal into its per-
|
|
539
560
|
// iteration caller signal, so the fetch can reject with the
|
|
540
|
-
// InterruptError reason directly
|
|
561
|
+
// InterruptError reason directly.
|
|
541
562
|
if (err instanceof InterruptError)
|
|
542
563
|
throw err;
|
|
543
564
|
// A timeout/abort during the fetch itself: classify it (RequestTimeoutError
|
|
@@ -785,11 +806,10 @@ export class HttpClient {
|
|
|
785
806
|
return headers;
|
|
786
807
|
}
|
|
787
808
|
/**
|
|
788
|
-
* Retry-delay sleep that bails the moment the shutdown signal fires
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
* poll.ts::sleepUnlessInterrupted.
|
|
809
|
+
* Retry-delay sleep that bails the moment the shutdown signal fires: a
|
|
810
|
+
* RATE_LIMITED `Retry-After: 60` or a transport backoff must not delay the
|
|
811
|
+
* honest-detach exit by up to a minute — reject with the InterruptError
|
|
812
|
+
* reason immediately. Mirrors poll.ts::sleepUnlessInterrupted.
|
|
793
813
|
*/
|
|
794
814
|
sleepBeforeRetry(ms) {
|
|
795
815
|
const signal = this.shutdownSignal;
|
|
@@ -941,8 +961,10 @@ async function safeReadJson(response) {
|
|
|
941
961
|
return await response.json();
|
|
942
962
|
}
|
|
943
963
|
catch (err) {
|
|
944
|
-
// Don't swallow
|
|
945
|
-
//
|
|
964
|
+
// Don't swallow interrupts, aborts, or timeouts as a null body — the caller
|
|
965
|
+
// must preserve the interruption or classify a timeout correctly.
|
|
966
|
+
if (err instanceof InterruptError)
|
|
967
|
+
throw err;
|
|
946
968
|
if (isAbortError(err) || isTimeoutError(err))
|
|
947
969
|
throw err;
|
|
948
970
|
return null;
|
package/dist/lib/interrupt.d.ts
CHANGED
|
@@ -24,6 +24,11 @@ import { type TerminationSignal } from './errors.js';
|
|
|
24
24
|
export { TERMINATION_EXIT_CODES, type TerminationSignal } from './errors.js';
|
|
25
25
|
/** Back-compat alias: SIGINT's conventional exit code. */
|
|
26
26
|
export declare const SIGINT_EXIT_CODE: 130;
|
|
27
|
+
export declare const INTERRUPT_EXIT_BACKSTOP_MS = 3000;
|
|
28
|
+
export declare function armInterruptExitBackstop(code: number, deps?: {
|
|
29
|
+
setTimer?: (callback: () => void, delayMs: number) => Pick<NodeJS.Timeout, 'unref'>;
|
|
30
|
+
exit?: (code: number) => void;
|
|
31
|
+
}): void;
|
|
27
32
|
/**
|
|
28
33
|
* Structural view of {@link ShutdownController} threaded through the DI
|
|
29
34
|
* surfaces (`TestDeps`, `PollOptions`) — commands and the polling loop need
|
|
@@ -34,12 +39,12 @@ export interface ShutdownHandle {
|
|
|
34
39
|
readonly signal: AbortSignal;
|
|
35
40
|
/** Enter a graceful-detach scope. Returns the disposer that leaves it. */
|
|
36
41
|
arm(): () => void;
|
|
37
|
-
/** Run and track
|
|
42
|
+
/** Run and track work that a repeated signal may briefly wait for. */
|
|
38
43
|
runCriticalOperation<T>(operation: () => Promise<T>): Promise<T>;
|
|
39
44
|
}
|
|
40
45
|
/**
|
|
41
46
|
* Process-lifetime coordinator between the signal handler and the `--wait`
|
|
42
|
-
* polling paths
|
|
47
|
+
* polling paths.
|
|
43
48
|
*
|
|
44
49
|
* Two modes, chosen by whether a graceful-detach scope is armed when the
|
|
45
50
|
* signal arrives:
|
|
@@ -50,12 +55,12 @@ export interface ShutdownHandle {
|
|
|
50
55
|
* the cleanup (finalize the ticker, print the honest partial envelope +
|
|
51
56
|
* re-attach hint, rethrow to `index.ts` → exit 130/143/129).
|
|
52
57
|
* - **Disarmed** (no wait in progress — prompts, one-shot commands, local
|
|
53
|
-
* FS work): the handler prints the generic explanation
|
|
54
|
-
*
|
|
55
|
-
*
|
|
58
|
+
* FS work): the handler prints the generic explanation. An in-flight HTTP
|
|
59
|
+
* request can unwind through the top-level catch; idle work such as a
|
|
60
|
+
* readline prompt exits immediately because it cannot observe the abort.
|
|
56
61
|
*
|
|
57
62
|
* A repeated signal still provides a bounded escape hatch: the second waits
|
|
58
|
-
* briefly
|
|
63
|
+
* briefly when cleanup or an HTTP request is in flight, and the third exits at once.
|
|
59
64
|
*/
|
|
60
65
|
export declare class ShutdownController {
|
|
61
66
|
private readonly controller;
|
|
@@ -72,14 +77,14 @@ export declare class ShutdownController {
|
|
|
72
77
|
* Returns an idempotent disposer.
|
|
73
78
|
*/
|
|
74
79
|
arm(): () => void;
|
|
75
|
-
/** Whether
|
|
80
|
+
/** Whether cleanup or an HTTP request is in flight and needs time to settle. */
|
|
76
81
|
get hasCriticalOperations(): boolean;
|
|
77
82
|
/**
|
|
78
|
-
* Register
|
|
83
|
+
* Register an operation before it starts and remove it automatically when it
|
|
79
84
|
* settles. Rejections retain their original semantics for the caller.
|
|
80
85
|
*/
|
|
81
86
|
runCriticalOperation<T>(operation: () => Promise<T>): Promise<T>;
|
|
82
|
-
/** Wait until all current and directly chained
|
|
87
|
+
/** Wait until all current and directly chained tracked work settles. */
|
|
83
88
|
waitForCriticalOperations(): Promise<void>;
|
|
84
89
|
/** Record the signal and abort with an `InterruptError` carrying it. */
|
|
85
90
|
interrupt(signal: TerminationSignal): void;
|
|
@@ -106,6 +111,8 @@ export interface InterruptDeps {
|
|
|
106
111
|
stderr?: (line: string) => void;
|
|
107
112
|
/** Process exit. Defaults to `process.exit`. */
|
|
108
113
|
exit?: (code: number) => void;
|
|
114
|
+
/** Set the exit code while allowing in-flight work to drain. */
|
|
115
|
+
setExitCode?: (code: number) => void;
|
|
109
116
|
/** Shutdown coordinator. Defaults to {@link globalShutdown}. */
|
|
110
117
|
shutdown?: ShutdownController;
|
|
111
118
|
}
|
|
@@ -114,10 +121,11 @@ export interface InterruptDeps {
|
|
|
114
121
|
* single top-level call in `index.ts`; not designed to be installed twice.
|
|
115
122
|
*
|
|
116
123
|
* First signal, armed scope: abort-only — the `--wait` catch paths own the
|
|
117
|
-
* honest-detach UX and the exit (
|
|
118
|
-
* First signal, disarmed: print the generic explanation
|
|
119
|
-
*
|
|
120
|
-
*
|
|
124
|
+
* honest-detach UX and the exit (Ctrl-C detaches; it never cancels the run).
|
|
125
|
+
* First signal, disarmed: print the generic explanation, then drain an in-flight
|
|
126
|
+
* request or exit `128+signum` immediately when idle.
|
|
127
|
+
* Second signal: exit immediately unless cleanup or a request is registered;
|
|
128
|
+
* when it is, wait at most two seconds before exiting. Third signal: always exit
|
|
121
129
|
* immediately, including while that grace period is active.
|
|
122
130
|
*/
|
|
123
131
|
export declare function installSignalHandlers(deps?: InterruptDeps): void;
|
package/dist/lib/interrupt.js
CHANGED
|
@@ -26,9 +26,14 @@ import { InterruptError, TERMINATION_EXIT_CODES } from './errors.js';
|
|
|
26
26
|
export { TERMINATION_EXIT_CODES } from './errors.js';
|
|
27
27
|
/** Back-compat alias: SIGINT's conventional exit code. */
|
|
28
28
|
export const SIGINT_EXIT_CODE = TERMINATION_EXIT_CODES.SIGINT;
|
|
29
|
+
export const INTERRUPT_EXIT_BACKSTOP_MS = 3_000;
|
|
30
|
+
export function armInterruptExitBackstop(code, deps = {}) {
|
|
31
|
+
const timer = (deps.setTimer ?? setTimeout)(() => (deps.exit ?? process.exit)(code), INTERRUPT_EXIT_BACKSTOP_MS);
|
|
32
|
+
timer.unref();
|
|
33
|
+
}
|
|
29
34
|
/**
|
|
30
35
|
* Process-lifetime coordinator between the signal handler and the `--wait`
|
|
31
|
-
* polling paths
|
|
36
|
+
* polling paths.
|
|
32
37
|
*
|
|
33
38
|
* Two modes, chosen by whether a graceful-detach scope is armed when the
|
|
34
39
|
* signal arrives:
|
|
@@ -39,12 +44,12 @@ export const SIGINT_EXIT_CODE = TERMINATION_EXIT_CODES.SIGINT;
|
|
|
39
44
|
* the cleanup (finalize the ticker, print the honest partial envelope +
|
|
40
45
|
* re-attach hint, rethrow to `index.ts` → exit 130/143/129).
|
|
41
46
|
* - **Disarmed** (no wait in progress — prompts, one-shot commands, local
|
|
42
|
-
* FS work): the handler prints the generic explanation
|
|
43
|
-
*
|
|
44
|
-
*
|
|
47
|
+
* FS work): the handler prints the generic explanation. An in-flight HTTP
|
|
48
|
+
* request can unwind through the top-level catch; idle work such as a
|
|
49
|
+
* readline prompt exits immediately because it cannot observe the abort.
|
|
45
50
|
*
|
|
46
51
|
* A repeated signal still provides a bounded escape hatch: the second waits
|
|
47
|
-
* briefly
|
|
52
|
+
* briefly when cleanup or an HTTP request is in flight, and the third exits at once.
|
|
48
53
|
*/
|
|
49
54
|
export class ShutdownController {
|
|
50
55
|
controller = new AbortController();
|
|
@@ -81,12 +86,12 @@ export class ShutdownController {
|
|
|
81
86
|
this.armedCount -= 1;
|
|
82
87
|
};
|
|
83
88
|
}
|
|
84
|
-
/** Whether
|
|
89
|
+
/** Whether cleanup or an HTTP request is in flight and needs time to settle. */
|
|
85
90
|
get hasCriticalOperations() {
|
|
86
91
|
return this.criticalOperations.size > 0;
|
|
87
92
|
}
|
|
88
93
|
/**
|
|
89
|
-
* Register
|
|
94
|
+
* Register an operation before it starts and remove it automatically when it
|
|
90
95
|
* settles. Rejections retain their original semantics for the caller.
|
|
91
96
|
*/
|
|
92
97
|
runCriticalOperation(operation) {
|
|
@@ -97,7 +102,7 @@ export class ShutdownController {
|
|
|
97
102
|
this.criticalOperations.add(tracked);
|
|
98
103
|
return tracked;
|
|
99
104
|
}
|
|
100
|
-
/** Wait until all current and directly chained
|
|
105
|
+
/** Wait until all current and directly chained tracked work settles. */
|
|
101
106
|
async waitForCriticalOperations() {
|
|
102
107
|
while (this.criticalOperations.size > 0) {
|
|
103
108
|
await Promise.allSettled([...this.criticalOperations]);
|
|
@@ -144,7 +149,7 @@ export function formatInterruptMessage(signal = 'SIGINT') {
|
|
|
144
149
|
'check it with `testsprite test list` or `testsprite test wait <runId>`.');
|
|
145
150
|
}
|
|
146
151
|
const CRITICAL_OPERATION_GRACE_MS = 2_000;
|
|
147
|
-
/** How often the grace period re-checks whether
|
|
152
|
+
/** How often the grace period re-checks whether tracked work is still running. */
|
|
148
153
|
const CRITICAL_OPERATION_POLL_MS = 10;
|
|
149
154
|
function afterDelay(ms) {
|
|
150
155
|
return new Promise(resolve => {
|
|
@@ -180,10 +185,11 @@ async function waitForCriticalOperationsWithGrace(shutdown) {
|
|
|
180
185
|
* single top-level call in `index.ts`; not designed to be installed twice.
|
|
181
186
|
*
|
|
182
187
|
* First signal, armed scope: abort-only — the `--wait` catch paths own the
|
|
183
|
-
* honest-detach UX and the exit (
|
|
184
|
-
* First signal, disarmed: print the generic explanation
|
|
185
|
-
*
|
|
186
|
-
*
|
|
188
|
+
* honest-detach UX and the exit (Ctrl-C detaches; it never cancels the run).
|
|
189
|
+
* First signal, disarmed: print the generic explanation, then drain an in-flight
|
|
190
|
+
* request or exit `128+signum` immediately when idle.
|
|
191
|
+
* Second signal: exit immediately unless cleanup or a request is registered;
|
|
192
|
+
* when it is, wait at most two seconds before exiting. Third signal: always exit
|
|
187
193
|
* immediately, including while that grace period is active.
|
|
188
194
|
*/
|
|
189
195
|
export function installSignalHandlers(deps = {}) {
|
|
@@ -193,9 +199,8 @@ export function installSignalHandlers(deps = {}) {
|
|
|
193
199
|
});
|
|
194
200
|
const stderr = deps.stderr ??
|
|
195
201
|
((line) => {
|
|
196
|
-
//
|
|
197
|
-
//
|
|
198
|
-
// synchronously so the interrupt hint is flushed before the process exits.
|
|
202
|
+
// An idle or repeated signal can call process.exit() right after writing,
|
|
203
|
+
// truncating an async stderr write when stderr is a pipe.
|
|
199
204
|
try {
|
|
200
205
|
writeSync(process.stderr.fd, `${line}\n`);
|
|
201
206
|
}
|
|
@@ -204,6 +209,10 @@ export function installSignalHandlers(deps = {}) {
|
|
|
204
209
|
}
|
|
205
210
|
});
|
|
206
211
|
const exit = deps.exit ?? ((code) => process.exit(code));
|
|
212
|
+
const setExitCode = deps.setExitCode ??
|
|
213
|
+
((code) => {
|
|
214
|
+
process.exitCode = code;
|
|
215
|
+
});
|
|
207
216
|
const shutdown = deps.shutdown ?? globalShutdown;
|
|
208
217
|
let signalCount = 0;
|
|
209
218
|
let graceGeneration = 0;
|
|
@@ -222,8 +231,8 @@ export function installSignalHandlers(deps = {}) {
|
|
|
222
231
|
// credential delete is registered only after the poll loop unwinds. A
|
|
223
232
|
// second signal that arrives in between — which is what a reflexive
|
|
224
233
|
// double Ctrl-C actually does — would otherwise hard-exit and strand a
|
|
225
|
-
// live inbound credential until its TTL
|
|
226
|
-
//
|
|
234
|
+
// live inbound credential until its TTL. An ordinary in-flight request
|
|
235
|
+
// is registered too, so it gets the same bounded grace period.
|
|
227
236
|
if (!shutdown.hasCriticalOperations && !shutdown.isArmed) {
|
|
228
237
|
exit(TERMINATION_EXIT_CODES[signal]);
|
|
229
238
|
return;
|
|
@@ -245,14 +254,16 @@ export function installSignalHandlers(deps = {}) {
|
|
|
245
254
|
shutdown.interrupt(signal);
|
|
246
255
|
return;
|
|
247
256
|
}
|
|
248
|
-
//
|
|
249
|
-
// signal first so a second one takes the hard-exit branch even when
|
|
250
|
-
// `exit` is injected and does not terminate (unit tests).
|
|
257
|
+
// Record the signal first so a second one takes the escalation path.
|
|
251
258
|
shutdown.interrupt(signal);
|
|
252
259
|
// Blank line first so the message starts on its own row rather than
|
|
253
260
|
// trailing the progress ticker's in-place line.
|
|
254
261
|
stderr('');
|
|
255
262
|
stderr(formatInterruptMessage(signal));
|
|
263
|
+
if (shutdown.hasCriticalOperations) {
|
|
264
|
+
setExitCode(TERMINATION_EXIT_CODES[signal]);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
256
267
|
exit(TERMINATION_EXIT_CODES[signal]);
|
|
257
268
|
});
|
|
258
269
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CiSummary } from './gh-output.js';
|
|
1
2
|
export type JUnitReportFormat = 'junit';
|
|
2
3
|
/** Minimal testcase input shared by batch run and batch rerun poll results. */
|
|
3
4
|
export interface JUnitTestResult {
|
|
@@ -11,6 +12,8 @@ export interface JUnitTestResult {
|
|
|
11
12
|
message: string;
|
|
12
13
|
exitCode?: number;
|
|
13
14
|
};
|
|
15
|
+
/** Why a member was skipped before dispatch. */
|
|
16
|
+
skipReason?: string;
|
|
14
17
|
/**
|
|
15
18
|
* Human-readable test name for the `testcase name` attribute. Falls back to
|
|
16
19
|
* `testId` when absent (older data / a run whose name could not be resolved).
|
|
@@ -19,16 +22,17 @@ export interface JUnitTestResult {
|
|
|
19
22
|
name?: string;
|
|
20
23
|
/**
|
|
21
24
|
* Wall-clock duration of the run in seconds, for `testcase time`. Derived from
|
|
22
|
-
* the poll result's `startedAt
|
|
25
|
+
* the poll result's `startedAt` (or `createdAt`) and `finishedAt`; omitted when timing is absent
|
|
23
26
|
* (rendered as `0`, the pre-fix behaviour).
|
|
24
27
|
*/
|
|
25
28
|
durationSeconds?: number;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Duration in seconds between two ISO timestamps, or `undefined` when either is
|
|
29
|
-
* missing / unparseable / negative (clock skew).
|
|
32
|
+
* missing / unparseable / negative (clock skew). Prefer startedAt, falling back
|
|
33
|
+
* to createdAt on servers that do not record a start. Kept ≥ 0.
|
|
30
34
|
*/
|
|
31
|
-
export declare function durationSecondsBetween(startedAt: string | null | undefined, finishedAt: string | null | undefined): number | undefined;
|
|
35
|
+
export declare function durationSecondsBetween(startedAt: string | null | undefined, finishedAt: string | null | undefined, createdAt?: string | null): number | undefined;
|
|
32
36
|
export interface JUnitReportBuildOptions {
|
|
33
37
|
suiteName: string;
|
|
34
38
|
classname: string;
|
|
@@ -65,11 +69,21 @@ export declare function resolveBatchReportProjectId(opts: {
|
|
|
65
69
|
*/
|
|
66
70
|
export declare function escapeXml(text: string): string;
|
|
67
71
|
/**
|
|
68
|
-
* Build a JUnit XML document from batch
|
|
72
|
+
* Build a JUnit XML document from batch results, including skipped members. Per-`testcase` `time` is
|
|
69
73
|
* the run's wall-clock duration (from `startedAt`/`finishedAt`); the `testsuite`
|
|
70
74
|
* `time` is their sum. `time` falls back to `0` for a run with no timing.
|
|
71
75
|
*/
|
|
72
76
|
export declare function buildJUnitReport(opts: JUnitReportBuildOptions): string;
|
|
77
|
+
/**
|
|
78
|
+
* The summary's non-dispatched rows (deferred / conflict / not-found) as
|
|
79
|
+
* skipped JUnit results. Accepted rows carry run statuses and today never
|
|
80
|
+
* match `isNonDispatchedStatus`, but the two vocabularies are only disjoint
|
|
81
|
+
* by convention: `skipped` is a word both could use. So a member already in
|
|
82
|
+
* `dispatched` (the polled results the caller is writing) is left out here
|
|
83
|
+
* rather than trusted to stay apart, which keeps `tests` from counting one
|
|
84
|
+
* member twice if the server ever reports such a status for an admitted run.
|
|
85
|
+
*/
|
|
86
|
+
export declare function skippedJUnitResultsFromSummary(summary: CiSummary, dispatched?: ReadonlyArray<Pick<JUnitTestResult, 'testId'>>): JUnitTestResult[];
|
|
73
87
|
/**
|
|
74
88
|
* Atomically write JUnit XML to `--report-file` (temp sibling + rename).
|
|
75
89
|
*/
|
package/dist/lib/junit-report.js
CHANGED
|
@@ -3,11 +3,14 @@ import { rename, stat, unlink } from 'node:fs/promises';
|
|
|
3
3
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
5
5
|
import { localValidationError, TransportError } from './errors.js';
|
|
6
|
+
import { isNonDispatchedStatus } from './gh-output.js';
|
|
6
7
|
/**
|
|
7
8
|
* Duration in seconds between two ISO timestamps, or `undefined` when either is
|
|
8
|
-
* missing / unparseable / negative (clock skew).
|
|
9
|
+
* missing / unparseable / negative (clock skew). Prefer startedAt, falling back
|
|
10
|
+
* to createdAt on servers that do not record a start. Kept ≥ 0.
|
|
9
11
|
*/
|
|
10
|
-
export function durationSecondsBetween(startedAt, finishedAt) {
|
|
12
|
+
export function durationSecondsBetween(startedAt, finishedAt, createdAt) {
|
|
13
|
+
startedAt = startedAt ?? createdAt;
|
|
11
14
|
if (!startedAt || !finishedAt)
|
|
12
15
|
return undefined;
|
|
13
16
|
const start = Date.parse(startedAt);
|
|
@@ -84,7 +87,7 @@ export function escapeXml(text) {
|
|
|
84
87
|
function classifyJUnitOutcome(status, error) {
|
|
85
88
|
if (status === 'passed')
|
|
86
89
|
return 'passed';
|
|
87
|
-
if (status
|
|
90
|
+
if (isNonDispatchedStatus(status))
|
|
88
91
|
return 'skipped';
|
|
89
92
|
if (status === 'error' || error?.exitCode === 3)
|
|
90
93
|
return 'error';
|
|
@@ -136,13 +139,13 @@ function renderTestcase(result, classname) {
|
|
|
136
139
|
lines.push(` <error message="${message}" type="${type}">${body}</error>`);
|
|
137
140
|
}
|
|
138
141
|
else if (outcome === 'skipped') {
|
|
139
|
-
lines.push(` <skipped/>`);
|
|
142
|
+
lines.push(` <skipped message="${escapeXml(result.skipReason ?? failureMessage(result))}"/>`);
|
|
140
143
|
}
|
|
141
144
|
lines.push(' </testcase>');
|
|
142
145
|
return lines.join('\n');
|
|
143
146
|
}
|
|
144
147
|
/**
|
|
145
|
-
* Build a JUnit XML document from batch
|
|
148
|
+
* Build a JUnit XML document from batch results, including skipped members. Per-`testcase` `time` is
|
|
146
149
|
* the run's wall-clock duration (from `startedAt`/`finishedAt`); the `testsuite`
|
|
147
150
|
* `time` is their sum. `time` falls back to `0` for a run with no timing.
|
|
148
151
|
*/
|
|
@@ -176,6 +179,21 @@ export function buildJUnitReport(opts) {
|
|
|
176
179
|
'',
|
|
177
180
|
].join('\n');
|
|
178
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* The summary's non-dispatched rows (deferred / conflict / not-found) as
|
|
184
|
+
* skipped JUnit results. Accepted rows carry run statuses and today never
|
|
185
|
+
* match `isNonDispatchedStatus`, but the two vocabularies are only disjoint
|
|
186
|
+
* by convention: `skipped` is a word both could use. So a member already in
|
|
187
|
+
* `dispatched` (the polled results the caller is writing) is left out here
|
|
188
|
+
* rather than trusted to stay apart, which keeps `tests` from counting one
|
|
189
|
+
* member twice if the server ever reports such a status for an admitted run.
|
|
190
|
+
*/
|
|
191
|
+
export function skippedJUnitResultsFromSummary(summary, dispatched = []) {
|
|
192
|
+
const alreadyIncluded = new Set(dispatched.map(row => row.testId));
|
|
193
|
+
return summary.runs
|
|
194
|
+
.filter(row => isNonDispatchedStatus(row.status) && !alreadyIncluded.has(row.testId))
|
|
195
|
+
.map(row => ({ testId: row.testId, status: 'skipped', skipReason: row.error ?? row.status }));
|
|
196
|
+
}
|
|
179
197
|
async function assertReportFileParent(rawPath) {
|
|
180
198
|
if (typeof rawPath !== 'string' || rawPath.length === 0) {
|
|
181
199
|
throw localValidationError('report-file', 'must be a non-empty file path');
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
export declare const LOOPBACK_HOSTS: readonly ["localhost", "127.0.0.1", "::1"];
|
|
34
34
|
export type LoopbackHost = (typeof LOOPBACK_HOSTS)[number];
|
|
35
|
-
/** Default
|
|
35
|
+
/** Default host for a new `--local <port>` shorthand target. */
|
|
36
36
|
export declare const DEFAULT_LOCAL_HOST: LoopbackHost;
|
|
37
37
|
/**
|
|
38
38
|
* Per-candidate dial budget. Deliberately short: this is a loopback connect on
|
|
@@ -68,6 +68,13 @@ export declare function parseLocalPort(raw: string): number;
|
|
|
68
68
|
* caller's own machine and nothing else, so a non-loopback value here is a
|
|
69
69
|
* misunderstanding to correct immediately, not a request to forward.
|
|
70
70
|
*/
|
|
71
|
+
/**
|
|
72
|
+
* The loopback spelling a host string names, or `undefined` when it names
|
|
73
|
+
* anything else. Accepts bracketed IPv6 (`[::1]`, as `URL.hostname` renders
|
|
74
|
+
* it) and any letter case. This is the membership question; callers that
|
|
75
|
+
* need a refusal on a miss use {@link normalizeLocalHost}.
|
|
76
|
+
*/
|
|
77
|
+
export declare function loopbackHost(raw: string): LoopbackHost | undefined;
|
|
71
78
|
export declare function normalizeLocalHost(raw: string | undefined): LoopbackHost;
|
|
72
79
|
/**
|
|
73
80
|
* `normalizeLocalHost` for a command whose alternative to `--local` is `--url`
|
|
@@ -80,13 +87,15 @@ export interface StoredLocalTarget {
|
|
|
80
87
|
host: LoopbackHost;
|
|
81
88
|
port: number;
|
|
82
89
|
}
|
|
90
|
+
/** Parse a loopback origin that the stored-target API and tunnel can reach. */
|
|
91
|
+
export declare function parseLoopbackTargetUrl(raw: string, field?: string): StoredLocalTarget | undefined;
|
|
83
92
|
/**
|
|
84
93
|
* Parse the `--local` / `--local-host` / `--url` trio a stored-target write
|
|
85
94
|
* takes. `--local` and `--url` are two spellings of one field, so both is a
|
|
86
95
|
* contradiction; `--local-host` only means something next to `--local`; the
|
|
87
96
|
* port is validated strictly because it becomes part of a URL runs are billed
|
|
88
|
-
* against. Returns the local target
|
|
89
|
-
*
|
|
97
|
+
* against. Returns the local target for either shorthand or loopback URL input,
|
|
98
|
+
* or `undefined` for a public URL (or no target).
|
|
90
99
|
*/
|
|
91
100
|
export declare function parseStoredLocalTarget(opts: {
|
|
92
101
|
local?: string;
|
|
@@ -113,7 +122,7 @@ export declare function probeLocalPort(host: string, port: number, deps?: LocalP
|
|
|
113
122
|
/**
|
|
114
123
|
* Run {@link probeLocalPort} and either throw (refuse) or no-op (ok / skipped).
|
|
115
124
|
*
|
|
116
|
-
* Call this BEFORE minting a tunnel. That ordering is the feature:
|
|
125
|
+
* Call this BEFORE minting a tunnel. That ordering is the feature: telemetry
|
|
117
126
|
* measured 1,003 blocked-with-URL CLI runs, 55.5% of the third-party-tunnel
|
|
118
127
|
* ones blocked, every one of them charged, because the run row and its credit
|
|
119
128
|
* spend happen before the Lambda ever discovers the target is dead. A dev
|
|
@@ -124,4 +133,5 @@ export declare function probeLocalPort(host: string, port: number, deps?: LocalP
|
|
|
124
133
|
*/
|
|
125
134
|
export declare function assertLocalPortListening(host: LoopbackHost | string, port: number, opts: {
|
|
126
135
|
skipPreflight?: boolean;
|
|
136
|
+
environmentName?: string;
|
|
127
137
|
}, _stderrFn: (line: string) => void, deps?: LocalPortProbeDeps): Promise<void>;
|