@testsprite/testsprite-cli 0.10.0 → 0.11.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 +25 -2
- package/dist/commands/auth.d.ts +5 -1
- package/dist/commands/auth.js +17 -5
- package/dist/commands/init.d.ts +6 -1
- package/dist/commands/init.js +13 -5
- package/dist/commands/project.d.ts +9 -0
- package/dist/commands/project.js +89 -18
- package/dist/commands/test.d.ts +14 -2
- package/dist/commands/test.js +141 -33
- package/dist/commands/tunnel.d.ts +2 -2
- package/dist/commands/tunnel.js +139 -31
- package/dist/index.js +29 -11
- package/dist/lib/client-factory.d.ts +4 -1
- package/dist/lib/client-factory.js +12 -4
- package/dist/lib/credentials.d.ts +4 -0
- package/dist/lib/credentials.js +43 -4
- package/dist/lib/http.d.ts +14 -2
- package/dist/lib/http.js +38 -6
- package/dist/lib/response-schemas.d.ts +5 -2
- package/dist/lib/response-schemas.js +21 -1
- package/dist/lib/runs.types.d.ts +11 -0
- package/dist/lib/target-url.d.ts +1 -1
- package/dist/lib/target-url.js +4 -0
- package/dist/lib/telemetry.d.ts +6 -2
- package/dist/lib/telemetry.js +12 -0
- package/dist/lib/tunnel-session.d.ts +13 -2
- package/dist/lib/tunnel-session.js +92 -23
- package/dist/lib/tunnel.types.d.ts +3 -1
- package/dist/vendor/tunnel-client/client.d.ts +11 -0
- package/dist/vendor/tunnel-client/client.js +383 -56
- package/dist/vendor/tunnel-client/config.d.ts +11 -3
- package/dist/vendor/tunnel-client/config.js +11 -3
- package/dist/vendor/tunnel-client/types.d.ts +26 -1
- package/dist/vendor/tunnel-client/types.js +1 -0
- package/dist/vendor/tunnel-client/ws-compat.d.ts +3 -2
- package/dist/vendor/tunnel-client/ws-compat.js +3 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
- package/skills/testsprite-onboard.skill.md +74 -59
- package/skills/testsprite-verify.codex.md +82 -97
- package/skills/testsprite-verify.skill.md +62 -15
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 { VERSION } from '../version.js';
|
|
5
|
-
import { BATCH_RERUN_RESPONSE_SCHEMA, BATCH_RUN_FRESH_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_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
|
|
@@ -39,6 +39,20 @@ const MAX_ATTEMPTS_INTERNAL = 2;
|
|
|
39
39
|
// Cap server-directed RATE_LIMITED waits so a hostile or misconfigured
|
|
40
40
|
// `Retry-After` (e.g. 86400) can't hang the CLI inside the retry sleep.
|
|
41
41
|
const MAX_RATE_LIMITED_DELAY_MS = 60_000;
|
|
42
|
+
/**
|
|
43
|
+
* 429 reasons that name a STANDING condition rather than a passing throttle —
|
|
44
|
+
* e.g. the per-user cap on live tunnel bindings. Retrying cannot succeed until
|
|
45
|
+
* the caller frees the resource, so the retry budget is skipped and the
|
|
46
|
+
* server's nextAction (e.g. `testsprite tunnel stop`) surfaces immediately.
|
|
47
|
+
*/
|
|
48
|
+
export const STANDING_RATE_LIMIT_REASONS = new Set(['tunnel_binding_limit']);
|
|
49
|
+
/** True for a RATE_LIMITED error whose envelope names a standing condition. */
|
|
50
|
+
export function isStandingRateLimit(err) {
|
|
51
|
+
if (err.code !== 'RATE_LIMITED')
|
|
52
|
+
return false;
|
|
53
|
+
const reason = err.getDetail('reason', (v) => typeof v === 'string');
|
|
54
|
+
return reason !== undefined && STANDING_RATE_LIMIT_REASONS.has(reason);
|
|
55
|
+
}
|
|
42
56
|
const CONFLICT_DELAY_MS = 1000;
|
|
43
57
|
const INTERNAL_DELAY_MS = 500;
|
|
44
58
|
// Upper bound on the size of a successful JSON response body the client will
|
|
@@ -259,7 +273,7 @@ export class HttpClient {
|
|
|
259
273
|
* than `pageSize` rows while still yielding a non-null `nextCursor`.
|
|
260
274
|
* That means "none in THIS window", not end-of-history.
|
|
261
275
|
*/
|
|
262
|
-
async listTestRuns(testId, query) {
|
|
276
|
+
async listTestRuns(testId, query, options = {}) {
|
|
263
277
|
const q = {};
|
|
264
278
|
if (query.cursor !== undefined)
|
|
265
279
|
q.cursor = query.cursor;
|
|
@@ -271,6 +285,8 @@ export class HttpClient {
|
|
|
271
285
|
q.since = query.since;
|
|
272
286
|
return this.get(`/tests/${encodeURIComponent(testId)}/runs`, {
|
|
273
287
|
query: q,
|
|
288
|
+
signal: options.signal,
|
|
289
|
+
retry: options.retry,
|
|
274
290
|
schema: LIST_RUNS_RESPONSE_SCHEMA,
|
|
275
291
|
});
|
|
276
292
|
}
|
|
@@ -366,6 +382,7 @@ export class HttpClient {
|
|
|
366
382
|
async cancelRun(runId, options) {
|
|
367
383
|
return this.post(`/runs/${encodeURIComponent(runId)}/cancel`, {
|
|
368
384
|
signal: options?.signal,
|
|
385
|
+
schema: CANCEL_RUN_RESPONSE_SCHEMA,
|
|
369
386
|
retryOnConflict: false,
|
|
370
387
|
});
|
|
371
388
|
}
|
|
@@ -699,7 +716,10 @@ export class HttpClient {
|
|
|
699
716
|
durationMs,
|
|
700
717
|
});
|
|
701
718
|
const retryOnConflict = options.retryOnConflict !== false;
|
|
702
|
-
|
|
719
|
+
// A standing-condition 429 skips the retry budget outright: its
|
|
720
|
+
// Retry-After says when a retry COULD first succeed if the caller
|
|
721
|
+
// frees the resource, not that the condition clears on its own.
|
|
722
|
+
const retryOnRateLimit = options.retryOnRateLimit !== false && !isStandingRateLimit(apiError);
|
|
703
723
|
const decision = allowRetry
|
|
704
724
|
? apiRetryDecision(apiError.code, attempt, retryAfterSec, this.random, retryOnConflict, retryOnRateLimit)
|
|
705
725
|
: { retry: false, delayMs: 0 };
|
|
@@ -775,7 +795,7 @@ export class HttpClient {
|
|
|
775
795
|
return new Promise((resolve, reject) => {
|
|
776
796
|
const onAbort = () => reject(signal.reason);
|
|
777
797
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
778
|
-
this.sleep(ms).then(() => {
|
|
798
|
+
this.sleep(ms, signal).then(() => {
|
|
779
799
|
signal.removeEventListener('abort', onAbort);
|
|
780
800
|
resolve();
|
|
781
801
|
}, err => {
|
|
@@ -1153,8 +1173,20 @@ function backoffDelay(attempt, random) {
|
|
|
1153
1173
|
const jitter = Math.floor(random() * RETRY_JITTER_MS);
|
|
1154
1174
|
return Math.min(base + jitter, RETRY_MAX_DELAY_MS);
|
|
1155
1175
|
}
|
|
1156
|
-
function defaultSleep(ms) {
|
|
1157
|
-
|
|
1176
|
+
function defaultSleep(ms, signal) {
|
|
1177
|
+
if (signal?.aborted)
|
|
1178
|
+
return Promise.reject(signal.reason);
|
|
1179
|
+
return new Promise((resolve, reject) => {
|
|
1180
|
+
const onAbort = () => {
|
|
1181
|
+
clearTimeout(timer);
|
|
1182
|
+
reject(signal?.reason);
|
|
1183
|
+
};
|
|
1184
|
+
const timer = setTimeout(() => {
|
|
1185
|
+
signal?.removeEventListener('abort', onAbort);
|
|
1186
|
+
resolve();
|
|
1187
|
+
}, ms);
|
|
1188
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
1189
|
+
});
|
|
1158
1190
|
}
|
|
1159
1191
|
function isAbortError(err) {
|
|
1160
1192
|
if (err instanceof Error && err.name === 'AbortError')
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* `undefined` output or an opaque TypeError deep inside a command. These
|
|
7
7
|
* schemas are wired (opt-in, via `RequestOptions.schema`) into the typed
|
|
8
8
|
* HttpClient helpers only: `triggerRun`, `triggerRunWithMeta`, `triggerRerun`,
|
|
9
|
-
* `triggerBatchRerun`, `triggerBatchRunFresh`, `getRun`, `listTestRuns
|
|
9
|
+
* `triggerBatchRerun`, `triggerBatchRunFresh`, `getRun`, `listTestRuns`,
|
|
10
|
+
* `cancelRun`.
|
|
10
11
|
* The generic `get`/`post`/`put`/`patch`/`delete` paths stay schema-free.
|
|
11
12
|
*
|
|
12
13
|
* Resilience rules (additive server changes must never hard-fail the CLI):
|
|
@@ -32,11 +33,13 @@
|
|
|
32
33
|
* interface it mirrors, so schema/interface drift fails `tsc` in this file.
|
|
33
34
|
*/
|
|
34
35
|
import * as v from 'valibot';
|
|
35
|
-
import type { BatchRerunResponse, BatchRunFreshResponse, ListRunsResponse, RerunResponse, RunResponse, TriggerRunResponse } from './runs.types.js';
|
|
36
|
+
import type { BatchRerunResponse, BatchRunFreshResponse, CancelRunResponse, ListRunsResponse, RerunResponse, RunResponse, TriggerRunResponse } from './runs.types.js';
|
|
36
37
|
import type { CliTestListRunResponse } from './testlist.types.js';
|
|
37
38
|
import type { TunnelMintResponse, TunnelStatusResponse } from './tunnel.types.js';
|
|
38
39
|
/** Mirrors `RunResponse` (runs.types.ts): `GET /api/cli/v1/runs/{runId}`. */
|
|
39
40
|
export declare const RUN_RESPONSE_SCHEMA: v.GenericSchema<unknown, RunResponse>;
|
|
41
|
+
/** Mirrors `CancelRunResponse` (runs.types.ts): the run envelope plus cancel metadata. */
|
|
42
|
+
export declare const CANCEL_RUN_RESPONSE_SCHEMA: v.GenericSchema<unknown, CancelRunResponse>;
|
|
40
43
|
/** Mirrors `TriggerRunResponse` (runs.types.ts): `POST /tests/{testId}/runs`. */
|
|
41
44
|
export declare const TRIGGER_RUN_RESPONSE_SCHEMA: v.GenericSchema<unknown, TriggerRunResponse>;
|
|
42
45
|
/** Mirrors `RerunResponse` (runs.types.ts): `POST /tests/{testId}/runs/rerun`. */
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* `undefined` output or an opaque TypeError deep inside a command. These
|
|
7
7
|
* schemas are wired (opt-in, via `RequestOptions.schema`) into the typed
|
|
8
8
|
* HttpClient helpers only: `triggerRun`, `triggerRunWithMeta`, `triggerRerun`,
|
|
9
|
-
* `triggerBatchRerun`, `triggerBatchRunFresh`, `getRun`, `listTestRuns
|
|
9
|
+
* `triggerBatchRerun`, `triggerBatchRunFresh`, `getRun`, `listTestRuns`,
|
|
10
|
+
* `cancelRun`.
|
|
10
11
|
* The generic `get`/`post`/`put`/`patch`/`delete` paths stay schema-free.
|
|
11
12
|
*
|
|
12
13
|
* Resilience rules (additive server changes must never hard-fail the CLI):
|
|
@@ -133,6 +134,24 @@ export const RUN_RESPONSE_SCHEMA = v.looseObject({
|
|
|
133
134
|
steps: v.optional(v.nullable(v.array(RUN_STEP_DTO_SCHEMA))),
|
|
134
135
|
});
|
|
135
136
|
// ---------------------------------------------------------------------------
|
|
137
|
+
// POST /runs/{runId}/cancel
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
/** Mirrors `CancelRunRefund` (runs.types.ts): optional V3 frontend refund result. */
|
|
140
|
+
const CANCEL_RUN_REFUND_SCHEMA = v.looseObject({
|
|
141
|
+
status: openWireLiteral(),
|
|
142
|
+
amount: v.optional(v.number()),
|
|
143
|
+
});
|
|
144
|
+
/** Mirrors `CancelRunResponse` (runs.types.ts): the run envelope plus cancel metadata. */
|
|
145
|
+
export const CANCEL_RUN_RESPONSE_SCHEMA = v.intersect([
|
|
146
|
+
RUN_RESPONSE_SCHEMA,
|
|
147
|
+
v.looseObject({
|
|
148
|
+
alreadyCancelled: v.boolean(),
|
|
149
|
+
// Older backends, V2 runs, and backend-test runs omit this field. No
|
|
150
|
+
// default: absence must stay absent so JSON output passes through unchanged.
|
|
151
|
+
refund: v.optional(CANCEL_RUN_REFUND_SCHEMA),
|
|
152
|
+
}),
|
|
153
|
+
]);
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
136
155
|
// POST /tests/{testId}/runs
|
|
137
156
|
// ---------------------------------------------------------------------------
|
|
138
157
|
/** Mirrors `TriggerRunResponse` (runs.types.ts): `POST /tests/{testId}/runs`. */
|
|
@@ -339,6 +358,7 @@ export const TUNNEL_MINT_RESPONSE_SCHEMA = v.looseObject({
|
|
|
339
358
|
secret: v.pipe(v.string(), v.minLength(1)),
|
|
340
359
|
controlUrl: v.pipe(v.string(), v.minLength(1)),
|
|
341
360
|
tunnelAddr: v.pipe(v.string(), v.minLength(1)),
|
|
361
|
+
tunnelTlsAddr: v.optional(v.pipe(v.string(), v.minLength(1))),
|
|
342
362
|
expiresAt: v.string(),
|
|
343
363
|
});
|
|
344
364
|
/** Mirrors `TunnelStatusResponse` (tunnel.types.ts): `GET /tunnel/{clientId}`. */
|
package/dist/lib/runs.types.d.ts
CHANGED
|
@@ -288,6 +288,12 @@ export interface RunResponse {
|
|
|
288
288
|
*/
|
|
289
289
|
steps?: RunStepDto[] | null;
|
|
290
290
|
}
|
|
291
|
+
/** Credit outcome returned when cancellation applies V3 frontend billing rules. */
|
|
292
|
+
export interface CancelRunRefund {
|
|
293
|
+
status: 'refunded' | 'not_charged' | 'failed';
|
|
294
|
+
/** Original charged amount returned to the workspace. Present when refunded. */
|
|
295
|
+
amount?: number;
|
|
296
|
+
}
|
|
291
297
|
/**
|
|
292
298
|
* Response from `POST /api/cli/v1/runs/{runId}/cancel`.
|
|
293
299
|
* Same shape as `GET /runs/{runId}` (`status: "cancelled"`, verdict
|
|
@@ -296,6 +302,11 @@ export interface RunResponse {
|
|
|
296
302
|
*/
|
|
297
303
|
export interface CancelRunResponse extends RunResponse {
|
|
298
304
|
alreadyCancelled: boolean;
|
|
305
|
+
/**
|
|
306
|
+
* Present only when the server evaluated a V3 frontend run refund. Older
|
|
307
|
+
* backends, V2 runs, and backend-test runs omit it.
|
|
308
|
+
*/
|
|
309
|
+
refund?: CancelRunRefund;
|
|
299
310
|
}
|
|
300
311
|
/** Terminal states from the RunStatus union. */
|
|
301
312
|
export declare const TERMINAL_RUN_STATUSES: ReadonlySet<RunStatus>;
|
package/dist/lib/target-url.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* - Reject IPv6 link-local (`fe80::/10`), unique-local (`fc00::/7`), and
|
|
25
25
|
* deprecated site-local (`fec0::/10`)
|
|
26
26
|
*/
|
|
27
|
-
type TargetUrlHintContext = 'runtime' | 'bootstrap';
|
|
27
|
+
type TargetUrlHintContext = 'runtime' | 'bootstrap' | 'local-project-create';
|
|
28
28
|
export interface TargetUrlCaller {
|
|
29
29
|
/** CLI flag name without the leading `--`, used in the error envelope. */
|
|
30
30
|
field: string;
|
package/dist/lib/target-url.js
CHANGED
|
@@ -42,6 +42,8 @@ const LOCAL_DEV_BOOTSTRAP_HINT = "TestSprite executes tests from the cloud, so a
|
|
|
42
42
|
'Set the project to its deployed or staging URL. ' +
|
|
43
43
|
'After a test exists, target an app on this machine for an individual run with ' +
|
|
44
44
|
"`testsprite test run <test-id> --local <port>`; that tunnel is per-run and does not make localhost the project's URL.";
|
|
45
|
+
const LOCAL_PROJECT_CREATE_HINT = 'Use --local <port> instead of --url for an app on this machine. ' +
|
|
46
|
+
'Local projects are frontend-only and require the V3 project platform.';
|
|
45
47
|
const DEFAULT_TARGET_URL_CALLER = {
|
|
46
48
|
field: 'target-url',
|
|
47
49
|
helpCommand: 'testsprite test run',
|
|
@@ -97,6 +99,8 @@ export function assertNotLocal(rawUrl, caller = DEFAULT_TARGET_URL_CALLER) {
|
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
function localDevHintFor(hintContext) {
|
|
102
|
+
if (hintContext === 'local-project-create')
|
|
103
|
+
return LOCAL_PROJECT_CREATE_HINT;
|
|
100
104
|
return hintContext === 'bootstrap' ? LOCAL_DEV_BOOTSTRAP_HINT : LOCAL_DEV_RUNTIME_HINT;
|
|
101
105
|
}
|
|
102
106
|
/**
|
package/dist/lib/telemetry.d.ts
CHANGED
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const TELEMETRY_TIMEOUT_MS = 1000;
|
|
8
8
|
export type TelemetryOutcome = 'success' | 'error' | 'abort';
|
|
9
|
-
export interface
|
|
9
|
+
export interface WaitTimeoutTelemetry {
|
|
10
|
+
reason: 'wait_timeout';
|
|
11
|
+
cancelOutcome?: 'cancelled' | 'already_terminal' | 'failed' | 'skipped';
|
|
12
|
+
}
|
|
13
|
+
export interface TelemetryOutcomeInput extends Partial<WaitTimeoutTelemetry> {
|
|
10
14
|
/** Leaf command path that ran, e.g. `test run`. Empty → skip (no command). */
|
|
11
15
|
command: string;
|
|
12
16
|
outcome: TelemetryOutcome;
|
|
@@ -49,7 +53,7 @@ export interface ResolvedTelemetryAuth {
|
|
|
49
53
|
apiUrl: string;
|
|
50
54
|
}
|
|
51
55
|
/** The exact wire body — a flat allowlist mirroring the backend DTO. */
|
|
52
|
-
export interface TelemetryEvent {
|
|
56
|
+
export interface TelemetryEvent extends Partial<WaitTimeoutTelemetry> {
|
|
53
57
|
command: string;
|
|
54
58
|
outcome: TelemetryOutcome;
|
|
55
59
|
exitCode?: number;
|
package/dist/lib/telemetry.js
CHANGED
|
@@ -89,6 +89,18 @@ export function buildTelemetryEvent(input, env, isTTY) {
|
|
|
89
89
|
...(input.output === 'json' || input.output === 'text' ? { output: input.output } : {}),
|
|
90
90
|
ci: isTruthyEnv(env.CI) || !isTTY,
|
|
91
91
|
...(input.local ? { local: true } : {}),
|
|
92
|
+
...(input.outcome === 'error' && input.reason === 'wait_timeout'
|
|
93
|
+
? {
|
|
94
|
+
reason: 'wait_timeout',
|
|
95
|
+
...(input.local &&
|
|
96
|
+
(input.cancelOutcome === 'cancelled' ||
|
|
97
|
+
input.cancelOutcome === 'already_terminal' ||
|
|
98
|
+
input.cancelOutcome === 'failed' ||
|
|
99
|
+
input.cancelOutcome === 'skipped')
|
|
100
|
+
? { cancelOutcome: input.cancelOutcome }
|
|
101
|
+
: {}),
|
|
102
|
+
}
|
|
103
|
+
: {}),
|
|
92
104
|
};
|
|
93
105
|
}
|
|
94
106
|
/**
|
|
@@ -57,6 +57,10 @@ export declare const TUNNEL_CLIENT_STOP_TIMEOUT_MS = 2000;
|
|
|
57
57
|
export type TunnelFatalReason =
|
|
58
58
|
/** The server refused or dropped a client WE minted and connected. */
|
|
59
59
|
'auth-failed'
|
|
60
|
+
/** The server revoked our credential or another connection took over. */
|
|
61
|
+
| 'credential-revoked'
|
|
62
|
+
/** The selected data-plane transport could not connect inside its retry window. */
|
|
63
|
+
| 'data-plane-unreachable'
|
|
60
64
|
/**
|
|
61
65
|
* A BORROWED client (`--tunnel-client`) is no longer registered. Different
|
|
62
66
|
* cause and different remedy from `auth-failed`: nobody disconnected us,
|
|
@@ -66,10 +70,14 @@ export type TunnelFatalReason =
|
|
|
66
70
|
export interface TunnelSession {
|
|
67
71
|
readonly clientId: string;
|
|
68
72
|
readonly expiresAt: string;
|
|
73
|
+
/** Unknown only for an adopted client whose owning process chose the transport. */
|
|
74
|
+
readonly transport: 'tls' | 'plaintext' | undefined;
|
|
69
75
|
/** True when this session attached to a client someone else minted. */
|
|
70
76
|
readonly adopted: boolean;
|
|
71
77
|
/** The fatal reason, once one has occurred. `undefined` while healthy. */
|
|
72
78
|
fatalReason(): TunnelFatalReason | undefined;
|
|
79
|
+
/** Safe client detail for the fatal reason, when one carries user-facing context. */
|
|
80
|
+
fatalMessage(): string | undefined;
|
|
73
81
|
/** Give the client a bounded stop window, then delete our binding. Idempotent. */
|
|
74
82
|
close(): Promise<void>;
|
|
75
83
|
}
|
|
@@ -92,7 +100,7 @@ export interface OpenTunnelSessionOptions {
|
|
|
92
100
|
/** See {@link DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS}. */
|
|
93
101
|
connectTimeoutMs?: number;
|
|
94
102
|
/** Called once, the first time the tunnel becomes unusable for this run. */
|
|
95
|
-
onFatal?: (reason: TunnelFatalReason) => void;
|
|
103
|
+
onFatal?: (reason: TunnelFatalReason, message?: string) => void;
|
|
96
104
|
/**
|
|
97
105
|
* Attach to a client someone else minted (`testsprite tunnel start` in
|
|
98
106
|
* another terminal) instead of minting one. No secret is available, so
|
|
@@ -123,8 +131,11 @@ export interface TunnelSessionDeps {
|
|
|
123
131
|
* the already-started server-side run before deciding whether to retry.
|
|
124
132
|
*/
|
|
125
133
|
export declare class TunnelLostError extends ApiError {
|
|
126
|
-
constructor(reason: TunnelFatalReason, runId: string);
|
|
134
|
+
constructor(reason: TunnelFatalReason, runId: string, fatalMessage?: string);
|
|
127
135
|
}
|
|
136
|
+
export declare function formatDataPlaneUnreachableMessage(clientMessage?: string): string;
|
|
137
|
+
export declare function formatDataPlaneUnreachableNextAction(clientMessage: string | undefined, retryAction: string): string;
|
|
138
|
+
export declare const TUNNEL_DATA_PLANE_PROXY_BYPASS_DESCRIPTION: string;
|
|
128
139
|
/**
|
|
129
140
|
* Mint (or adopt) a tunnel client and connect it.
|
|
130
141
|
*
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
*/
|
|
41
41
|
import { ApiError } from './errors.js';
|
|
42
42
|
import { ErrCode, TunnelClient } from '../vendor/tunnel-client/index.js';
|
|
43
|
+
import { DEFAULT_DATA_PLANE_RETRY_DEADLINE_MS } from '../vendor/tunnel-client/config.js';
|
|
43
44
|
/**
|
|
44
45
|
* How long to wait for the control plane's first successful connection.
|
|
45
46
|
*
|
|
@@ -53,6 +54,10 @@ export const DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS = 20_000;
|
|
|
53
54
|
/** Maximum time teardown lets a wedged client delay credential deletion. */
|
|
54
55
|
export const TUNNEL_CLIENT_STOP_TIMEOUT_MS = 2_000;
|
|
55
56
|
const TUNNEL_SECRET_REDACTION = '[REDACTED]';
|
|
57
|
+
function isCredentialRevokedMessage(message) {
|
|
58
|
+
return (message === 'tunnel credential revoked' ||
|
|
59
|
+
message === 'tunnel connection superseded or credential revoked');
|
|
60
|
+
}
|
|
56
61
|
/**
|
|
57
62
|
* Thrown when the tunnel a run depends on dies mid-run. `UNAVAILABLE` (exit
|
|
58
63
|
* 10 rather than a run failure: the test did not fail, the transport under it
|
|
@@ -60,35 +65,75 @@ const TUNNEL_SECRET_REDACTION = '[REDACTED]';
|
|
|
60
65
|
* the already-started server-side run before deciding whether to retry.
|
|
61
66
|
*/
|
|
62
67
|
export class TunnelLostError extends ApiError {
|
|
63
|
-
constructor(reason, runId) {
|
|
68
|
+
constructor(reason, runId, fatalMessage) {
|
|
64
69
|
// Two different things go wrong here and they do NOT share a remedy.
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
// failure mode this whole area keeps repeating, so each reason carries its
|
|
69
|
-
// own copy.
|
|
70
|
+
// `--tunnel-client <id>` re-attaches to the same dead id and mints nothing,
|
|
71
|
+
// so a borrower must inspect this run before deciding what to do next.
|
|
72
|
+
// The wait path reports the observed cancellation outcome separately.
|
|
70
73
|
const ownerGone = reason === 'owner-gone';
|
|
74
|
+
const dataPlaneUnreachable = reason === 'data-plane-unreachable';
|
|
71
75
|
super({
|
|
72
76
|
code: 'UNAVAILABLE',
|
|
73
77
|
message: ownerGone
|
|
74
78
|
? `The borrowed tunnel for run ${runId} is no longer registered. It was minted by ` +
|
|
75
79
|
`another process (\`testsprite tunnel start\`), and that process has stopped or its ` +
|
|
76
|
-
`credential expired.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
`
|
|
80
|
+
`credential expired. The run cannot reach your app through that tunnel.`
|
|
81
|
+
: dataPlaneUnreachable
|
|
82
|
+
? formatDataPlaneUnreachableMessage(fatalMessage)
|
|
83
|
+
: `The tunnel carrying run ${runId} was disconnected by the server and cannot be ` +
|
|
84
|
+
`restored for this run (${reason}).`,
|
|
80
85
|
nextAction: ownerGone
|
|
81
|
-
? `
|
|
82
|
-
|
|
83
|
-
`testsprite test wait ${runId}
|
|
84
|
-
|
|
85
|
-
'the
|
|
86
|
+
? `Check the run before re-running: testsprite test wait ${runId}.`
|
|
87
|
+
: dataPlaneUnreachable
|
|
88
|
+
? `Check the cancelled run with testsprite test wait ${runId}. ` +
|
|
89
|
+
formatDataPlaneUnreachableNextAction(fatalMessage, 'start a new run')
|
|
90
|
+
: 'This usually means the tunnel service was redeployed mid-run. Start the run again: ' +
|
|
91
|
+
'the retry mints a fresh tunnel.',
|
|
86
92
|
requestId: 'local',
|
|
87
93
|
details: { reason, runId },
|
|
88
94
|
});
|
|
89
95
|
this.name = 'TunnelLostError';
|
|
90
96
|
}
|
|
91
97
|
}
|
|
98
|
+
function parseDataPlaneUnreachableMessage(clientMessage) {
|
|
99
|
+
const parsed = /^Data plane (tls|plaintext) at (.+) is unreachable after (\d+)ms: ([\s\S]+)$/u.exec(clientMessage ?? '');
|
|
100
|
+
if (!parsed)
|
|
101
|
+
return undefined;
|
|
102
|
+
return {
|
|
103
|
+
transport: parsed[1],
|
|
104
|
+
address: parsed[2],
|
|
105
|
+
deadlineMs: Number(parsed[3]),
|
|
106
|
+
error: parsed[4],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function formatDataPlaneUnreachableMessage(clientMessage) {
|
|
110
|
+
const parsed = parseDataPlaneUnreachableMessage(clientMessage);
|
|
111
|
+
const base = parsed
|
|
112
|
+
? `The tunnel's ${parsed.transport === 'tls' ? 'encrypted' : 'plaintext'} data connection to ${parsed.address} ` +
|
|
113
|
+
`could not be established for ${parsed.deadlineMs / 1_000}s (last error: ${parsed.error}).`
|
|
114
|
+
: (clientMessage ?? "The tunnel's encrypted data connection could not be established.");
|
|
115
|
+
if (parsed?.transport === 'plaintext') {
|
|
116
|
+
return (`${base} Check that the self-hosted tunnel service at ${parsed.address} is running and ` +
|
|
117
|
+
'that the egress firewall allows a direct connection to that address and port.');
|
|
118
|
+
}
|
|
119
|
+
if (base.includes('NODE_EXTRA_CA_CERTS'))
|
|
120
|
+
return base;
|
|
121
|
+
return (`${base} Corporate TLS interception, a wrong system clock, or a firewall blocking port 443 ` +
|
|
122
|
+
"are the usual causes; set NODE_EXTRA_CA_CERTS to your organisation's CA bundle if your " +
|
|
123
|
+
'network re-signs TLS.');
|
|
124
|
+
}
|
|
125
|
+
export function formatDataPlaneUnreachableNextAction(clientMessage, retryAction) {
|
|
126
|
+
const parsed = parseDataPlaneUnreachableMessage(clientMessage);
|
|
127
|
+
if (parsed?.transport === 'plaintext') {
|
|
128
|
+
return (`Check that the self-hosted tunnel service at ${parsed.address} is running and that the ` +
|
|
129
|
+
`egress firewall allows a direct connection to that address and port. Then ${retryAction}.`);
|
|
130
|
+
}
|
|
131
|
+
return ('Fix the network or TLS trust configuration: check for TLS interception, correct the system ' +
|
|
132
|
+
"clock, allow outbound port 443, and set NODE_EXTRA_CA_CERTS to your organisation's CA " +
|
|
133
|
+
`bundle when the network re-signs TLS. Then ${retryAction}.`);
|
|
134
|
+
}
|
|
135
|
+
export const TUNNEL_DATA_PLANE_PROXY_BYPASS_DESCRIPTION = 'the tunnel data plane uses a direct socket connection (TLS when the server advertises it; ' +
|
|
136
|
+
'raw TCP only for the legacy transport) that bypasses HTTP proxies';
|
|
92
137
|
function defaultCreateClient(options) {
|
|
93
138
|
return new TunnelClient(options);
|
|
94
139
|
}
|
|
@@ -125,14 +170,17 @@ function redactTunnelSecret(line, secret) {
|
|
|
125
170
|
export async function openTunnelSession(options, deps) {
|
|
126
171
|
const { log } = options;
|
|
127
172
|
let fatal;
|
|
173
|
+
let fatalMessage;
|
|
128
174
|
let closed = false;
|
|
129
175
|
if (options.adopt) {
|
|
130
176
|
// Adopted: no secret here, so no connection and no teardown obligation.
|
|
131
177
|
return {
|
|
132
178
|
clientId: options.adopt.clientId,
|
|
133
179
|
expiresAt: options.adopt.expiresAt,
|
|
180
|
+
transport: undefined,
|
|
134
181
|
adopted: true,
|
|
135
182
|
fatalReason: () => fatal,
|
|
183
|
+
fatalMessage: () => fatalMessage,
|
|
136
184
|
close: async () => { },
|
|
137
185
|
};
|
|
138
186
|
}
|
|
@@ -141,6 +189,10 @@ export async function openTunnelSession(options, deps) {
|
|
|
141
189
|
// scrubbed before the caller-owned sink can observe it. This remains safe if
|
|
142
190
|
// a future client log message accidentally interpolates its options.
|
|
143
191
|
const sessionLog = (line) => log(redactTunnelSecret(line, minted.secret));
|
|
192
|
+
const transport = minted.tunnelTlsAddr === undefined ? 'plaintext' : 'tls';
|
|
193
|
+
if (transport === 'plaintext') {
|
|
194
|
+
sessionLog('Warning: this TestSprite server did not advertise an encrypted tunnel data plane; the tunnel secret will be sent over plaintext TCP.');
|
|
195
|
+
}
|
|
144
196
|
const createClient = deps.createClient ?? defaultCreateClient;
|
|
145
197
|
let client;
|
|
146
198
|
const stopAndDestroy = async () => {
|
|
@@ -171,6 +223,8 @@ export async function openTunnelSession(options, deps) {
|
|
|
171
223
|
secret: minted.secret,
|
|
172
224
|
controlUrl: minted.controlUrl,
|
|
173
225
|
tunnelAddr: minted.tunnelAddr,
|
|
226
|
+
...(minted.tunnelTlsAddr !== undefined ? { tunnelTlsAddr: minted.tunnelTlsAddr } : {}),
|
|
227
|
+
dataPlaneRetryDeadlineMs: DEFAULT_DATA_PLANE_RETRY_DEADLINE_MS,
|
|
174
228
|
logLevel: options.logLevel ?? 'error',
|
|
175
229
|
// Never opened up. The point of `--local` is the caller's own loopback;
|
|
176
230
|
// a run that pivots into the rest of their network is the failure this
|
|
@@ -178,14 +232,24 @@ export async function openTunnelSession(options, deps) {
|
|
|
178
232
|
allowPrivateNetworkTarget: false,
|
|
179
233
|
logSink: (_level, line) => sessionLog(line),
|
|
180
234
|
onError: e => {
|
|
181
|
-
|
|
235
|
+
const terminal = e.code === ErrCode.AuthFailed || e.code === ErrCode.DataPlaneUnreachable;
|
|
236
|
+
if (terminal && fatal === undefined) {
|
|
182
237
|
// Terminal: the vendored client has stopped reconnecting, and a
|
|
183
238
|
// remint cannot rescue this run (see the module docstring).
|
|
184
|
-
fatal =
|
|
185
|
-
|
|
239
|
+
fatal =
|
|
240
|
+
e.code === ErrCode.DataPlaneUnreachable
|
|
241
|
+
? 'data-plane-unreachable'
|
|
242
|
+
: isCredentialRevokedMessage(e.message)
|
|
243
|
+
? 'credential-revoked'
|
|
244
|
+
: 'auth-failed';
|
|
245
|
+
fatalMessage =
|
|
246
|
+
e.code === ErrCode.DataPlaneUnreachable
|
|
247
|
+
? redactTunnelSecret(e.message, minted.secret)
|
|
248
|
+
: undefined;
|
|
249
|
+
options.onFatal?.(fatal, fatalMessage);
|
|
186
250
|
return;
|
|
187
251
|
}
|
|
188
|
-
if (
|
|
252
|
+
if (terminal)
|
|
189
253
|
return;
|
|
190
254
|
sessionLog(`[tunnel] ${e.message}`);
|
|
191
255
|
},
|
|
@@ -205,8 +269,7 @@ export async function openTunnelSession(options, deps) {
|
|
|
205
269
|
code: 'UNAVAILABLE',
|
|
206
270
|
message: `The tunnel did not connect within ${Math.round(timeoutMs / 1000)}s.`,
|
|
207
271
|
nextAction: 'Check that outbound WebSocket traffic is allowed from this machine, then retry. ' +
|
|
208
|
-
|
|
209
|
-
'and does not go through one.',
|
|
272
|
+
`An HTTP proxy does not help here: ${TUNNEL_DATA_PLANE_PROXY_BYPASS_DESCRIPTION}.`,
|
|
210
273
|
requestId: 'local',
|
|
211
274
|
details: { reason: 'tunnel-connect-timeout', timeoutMs },
|
|
212
275
|
},
|
|
@@ -222,10 +285,14 @@ export async function openTunnelSession(options, deps) {
|
|
|
222
285
|
throw ApiError.fromEnvelope({
|
|
223
286
|
error: {
|
|
224
287
|
code: 'UNAVAILABLE',
|
|
225
|
-
message:
|
|
288
|
+
message: fatal === 'credential-revoked'
|
|
289
|
+
? `Tunnel credential ${minted.clientId} was revoked, expired, or taken over by another process.`
|
|
290
|
+
: `Could not connect the tunnel: ${err instanceof Error ? err.message : String(err)}`,
|
|
226
291
|
nextAction: 'Retry. If this persists, report it to support@testsprite.com.',
|
|
227
292
|
requestId: 'local',
|
|
228
|
-
details: {
|
|
293
|
+
details: {
|
|
294
|
+
reason: fatal === 'credential-revoked' ? 'credential-revoked' : 'tunnel-connect-failed',
|
|
295
|
+
},
|
|
229
296
|
},
|
|
230
297
|
});
|
|
231
298
|
}
|
|
@@ -236,8 +303,10 @@ export async function openTunnelSession(options, deps) {
|
|
|
236
303
|
return {
|
|
237
304
|
clientId: minted.clientId,
|
|
238
305
|
expiresAt: minted.expiresAt,
|
|
306
|
+
transport,
|
|
239
307
|
adopted: false,
|
|
240
308
|
fatalReason: () => fatal,
|
|
309
|
+
fatalMessage: () => fatalMessage,
|
|
241
310
|
close: async () => {
|
|
242
311
|
if (closed)
|
|
243
312
|
return;
|
|
@@ -35,8 +35,10 @@ export interface TunnelMintResponse {
|
|
|
35
35
|
* the facade returns these two explicitly instead of a host/port pair.
|
|
36
36
|
*/
|
|
37
37
|
controlUrl: string;
|
|
38
|
-
/** `host:port`
|
|
38
|
+
/** Plaintext `host:port` retained for compatibility with older clients. */
|
|
39
39
|
tunnelAddr: string;
|
|
40
|
+
/** TLS `host:port` for the encrypted data plane; absent on older backends. */
|
|
41
|
+
tunnelTlsAddr?: string;
|
|
40
42
|
/** ISO8601. After this the binding is gone and the run can no longer attach. */
|
|
41
43
|
expiresAt: string;
|
|
42
44
|
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
import { TunnelClientOptions } from "./types.js";
|
|
3
3
|
export declare class TunnelClient extends EventEmitter {
|
|
4
|
+
#private;
|
|
4
5
|
private readonly options;
|
|
6
|
+
private readonly tunnelAddress;
|
|
5
7
|
private running;
|
|
6
8
|
private controlConnected;
|
|
7
9
|
private controlWs?;
|
|
8
10
|
private controlLoopTask?;
|
|
9
11
|
private controlConnectionGeneration;
|
|
10
12
|
private allowTunnelReconnect;
|
|
13
|
+
private dataPlaneTerminalErrorReported;
|
|
11
14
|
private readonly tunnelRuntimes;
|
|
12
15
|
private reconnectDelayController;
|
|
13
16
|
private readonly activeTargetSockets;
|
|
14
17
|
constructor(options: TunnelClientOptions);
|
|
18
|
+
get transport(): "tls" | "plaintext";
|
|
15
19
|
start(): Promise<void>;
|
|
16
20
|
stop(): Promise<void>;
|
|
17
21
|
private runControlLoop;
|
|
@@ -21,7 +25,14 @@ export declare class TunnelClient extends EventEmitter {
|
|
|
21
25
|
private parseControlMessage;
|
|
22
26
|
private ensureTunnelRuntime;
|
|
23
27
|
private connectTunnel;
|
|
28
|
+
private recordDataPlaneFailure;
|
|
29
|
+
private armDataPlaneFailureDeadline;
|
|
30
|
+
private expireDataPlaneFailureEpisode;
|
|
31
|
+
private markDataPlaneEstablished;
|
|
32
|
+
private clearDataPlaneAttemptTimers;
|
|
33
|
+
private clearDataPlaneFailureEpisode;
|
|
24
34
|
private stopAllTunnelRuntimes;
|
|
35
|
+
private beginStop;
|
|
25
36
|
private handleIncomingStream;
|
|
26
37
|
private proxyStreams;
|
|
27
38
|
private copyOneWay;
|