@testsprite/testsprite-cli 0.8.0 → 0.10.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 +51 -47
- package/dist/commands/agent.d.ts +3 -0
- package/dist/commands/agent.js +32 -7
- package/dist/commands/ci.js +4 -1
- package/dist/commands/init.d.ts +45 -2
- package/dist/commands/init.js +190 -29
- package/dist/commands/project.d.ts +21 -0
- package/dist/commands/project.js +118 -12
- package/dist/commands/test.d.ts +32 -3
- package/dist/commands/test.js +157 -29
- package/dist/lib/agent-detect.d.ts +53 -0
- package/dist/lib/agent-detect.js +198 -0
- package/dist/lib/dry-run/samples.js +16 -9
- package/dist/lib/http.d.ts +10 -0
- package/dist/lib/http.js +6 -2
- package/dist/lib/response-schemas.js +14 -0
- package/dist/lib/runs.types.d.ts +26 -0
- package/dist/lib/skill-nudge.d.ts +13 -5
- package/dist/lib/skill-nudge.js +40 -14
- package/dist/lib/target-url.d.ts +10 -1
- package/dist/lib/target-url.js +28 -11
- package/dist/lib/tunnel-session.d.ts +12 -3
- package/dist/lib/tunnel-session.js +23 -6
- package/dist/vendor/tunnel-client/client.d.ts +2 -3
- package/dist/vendor/tunnel-client/client.js +60 -7
- package/dist/vendor/tunnel-client/config.d.ts +8 -0
- package/dist/vendor/tunnel-client/config.js +8 -0
- package/dist/vendor/tunnel-client/types.d.ts +5 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/skills/testsprite-onboard.skill.md +6 -0
- package/skills/testsprite-verify.skill.md +5 -1
|
@@ -54,7 +54,15 @@ export declare const DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS = 20000;
|
|
|
54
54
|
/** Maximum time teardown lets a wedged client delay credential deletion. */
|
|
55
55
|
export declare const TUNNEL_CLIENT_STOP_TIMEOUT_MS = 2000;
|
|
56
56
|
/** Why a tunnel stopped being usable for the run that was attached to it. */
|
|
57
|
-
export type TunnelFatalReason =
|
|
57
|
+
export type TunnelFatalReason =
|
|
58
|
+
/** The server refused or dropped a client WE minted and connected. */
|
|
59
|
+
'auth-failed'
|
|
60
|
+
/**
|
|
61
|
+
* A BORROWED client (`--tunnel-client`) is no longer registered. Different
|
|
62
|
+
* cause and different remedy from `auth-failed`: nobody disconnected us,
|
|
63
|
+
* the process that minted the tunnel stopped owning it.
|
|
64
|
+
*/
|
|
65
|
+
| 'owner-gone';
|
|
58
66
|
export interface TunnelSession {
|
|
59
67
|
readonly clientId: string;
|
|
60
68
|
readonly expiresAt: string;
|
|
@@ -110,8 +118,9 @@ export interface TunnelSessionDeps {
|
|
|
110
118
|
}
|
|
111
119
|
/**
|
|
112
120
|
* Thrown when the tunnel a run depends on dies mid-run. `UNAVAILABLE` (exit
|
|
113
|
-
* 10
|
|
114
|
-
*
|
|
121
|
+
* 10 rather than a run failure: the test did not fail, the transport under it
|
|
122
|
+
* did. An owned run can retry with a fresh tunnel; a borrowed run must inspect
|
|
123
|
+
* the already-started server-side run before deciding whether to retry.
|
|
115
124
|
*/
|
|
116
125
|
export declare class TunnelLostError extends ApiError {
|
|
117
126
|
constructor(reason: TunnelFatalReason, runId: string);
|
|
@@ -55,17 +55,34 @@ export const TUNNEL_CLIENT_STOP_TIMEOUT_MS = 2_000;
|
|
|
55
55
|
const TUNNEL_SECRET_REDACTION = '[REDACTED]';
|
|
56
56
|
/**
|
|
57
57
|
* Thrown when the tunnel a run depends on dies mid-run. `UNAVAILABLE` (exit
|
|
58
|
-
* 10
|
|
59
|
-
*
|
|
58
|
+
* 10 rather than a run failure: the test did not fail, the transport under it
|
|
59
|
+
* did. An owned run can retry with a fresh tunnel; a borrowed run must inspect
|
|
60
|
+
* the already-started server-side run before deciding whether to retry.
|
|
60
61
|
*/
|
|
61
62
|
export class TunnelLostError extends ApiError {
|
|
62
63
|
constructor(reason, runId) {
|
|
64
|
+
// Two different things go wrong here and they do NOT share a remedy.
|
|
65
|
+
// Telling a borrower to "run again" both hides the already-started billed
|
|
66
|
+
// run and is false about the tunnel — `--tunnel-client <id>` re-attaches
|
|
67
|
+
// to the same dead id and mints nothing. Naming the wrong cause is the
|
|
68
|
+
// failure mode this whole area keeps repeating, so each reason carries its
|
|
69
|
+
// own copy.
|
|
70
|
+
const ownerGone = reason === 'owner-gone';
|
|
63
71
|
super({
|
|
64
72
|
code: 'UNAVAILABLE',
|
|
65
|
-
message:
|
|
66
|
-
`
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
message: ownerGone
|
|
74
|
+
? `The borrowed tunnel for run ${runId} is no longer registered. It was minted by ` +
|
|
75
|
+
`another process (\`testsprite tunnel start\`), and that process has stopped or its ` +
|
|
76
|
+
`credential expired. Run ${runId} was left executing server-side and may still ` +
|
|
77
|
+
`finish; if it is cancelled, its verdict is discarded.`
|
|
78
|
+
: `The tunnel carrying run ${runId} was disconnected by the server and cannot be ` +
|
|
79
|
+
`restored for this run (${reason}).`,
|
|
80
|
+
nextAction: ownerGone
|
|
81
|
+
? `Run ${runId} has lost its tunnel and cannot reach your app any more. Stop it now ` +
|
|
82
|
+
`with: testsprite test cancel ${runId} (idempotent). To watch it instead: ` +
|
|
83
|
+
`testsprite test wait ${runId} --timeout <s>.`
|
|
84
|
+
: 'This usually means the tunnel service was redeployed mid-run. Start the run again: ' +
|
|
85
|
+
'the retry mints a fresh tunnel.',
|
|
69
86
|
requestId: 'local',
|
|
70
87
|
details: { reason, runId },
|
|
71
88
|
});
|
|
@@ -6,6 +6,7 @@ export declare class TunnelClient extends EventEmitter {
|
|
|
6
6
|
private controlConnected;
|
|
7
7
|
private controlWs?;
|
|
8
8
|
private controlLoopTask?;
|
|
9
|
+
private controlConnectionGeneration;
|
|
9
10
|
private allowTunnelReconnect;
|
|
10
11
|
private readonly tunnelRuntimes;
|
|
11
12
|
private reconnectDelayController;
|
|
@@ -74,9 +75,7 @@ export declare function ensureTargetAllowed(host: string, port: number, candidat
|
|
|
74
75
|
}>, allowPrivateNetwork: boolean): void;
|
|
75
76
|
/**
|
|
76
77
|
* Thrown by {@link ensureTargetAllowed} when a proxied target resolves into a blocked
|
|
77
|
-
* (private/internal) range
|
|
78
|
-
* `TS_TUNNEL_ALLOW_PRIVATE_NETWORK_TARGET`. Mirrors the Rust client's
|
|
79
|
-
* `ensure_candidates_allowed` error.
|
|
78
|
+
* (private/internal) range. Mirrors the Rust client's `ensure_candidates_allowed` error.
|
|
80
79
|
*/
|
|
81
80
|
export declare class BlockedTargetError extends Error {
|
|
82
81
|
constructor(host: string, port: number, address?: string, reason?: string);
|
|
@@ -9,7 +9,7 @@ import { encodeFrame, readTypedFrame } from "./protocol.js";
|
|
|
9
9
|
// VENDOR DELTA: no CLIENT_VERSION (no package.json import) and no endpoint
|
|
10
10
|
// defaults — `controlUrl`/`tunnelAddr` are required and come from the mint
|
|
11
11
|
// response. See ./config.ts.
|
|
12
|
-
import { DEFAULT_ALLOW_PRIVATE_NETWORK_TARGET, DEFAULT_HEARTBEAT_MS, DEFAULT_LOG_LEVEL, DEFAULT_RECONNECT_MS, DEFAULT_TARGET_CONNECT_TIMEOUT_MS, } from "./config.js";
|
|
12
|
+
import { DEFAULT_ALLOW_PRIVATE_NETWORK_TARGET, DEFAULT_AUTH_TIMEOUT_MS, DEFAULT_HEARTBEAT_MS, DEFAULT_LOG_LEVEL, DEFAULT_RECONNECT_MS, DEFAULT_TARGET_CONNECT_TIMEOUT_MS, } from "./config.js";
|
|
13
13
|
import { ErrCode, } from "./types.js";
|
|
14
14
|
import { Client as createYamuxClientSession, YamuxStreamResetError, } from "@llmcode/yamux-ts";
|
|
15
15
|
// VENDOR DELTA: `Record<string, number>` -> `Record<LogLevel, number>`, and
|
|
@@ -24,12 +24,17 @@ const LEVEL_ORDER = {
|
|
|
24
24
|
error: 40,
|
|
25
25
|
};
|
|
26
26
|
const STREAM_CLOSE_TIMEOUT_MS = 1_500;
|
|
27
|
+
const CONTROL_AUTHENTICATION_FAILED = Symbol("control-authentication-failed");
|
|
27
28
|
export class TunnelClient extends EventEmitter {
|
|
28
29
|
options;
|
|
29
30
|
running = false;
|
|
30
31
|
controlConnected = false;
|
|
31
32
|
controlWs;
|
|
32
33
|
controlLoopTask;
|
|
34
|
+
// VENDOR DELTA: monotonically scopes authentication readiness to one
|
|
35
|
+
// control socket. A reconnect gets a new generation, so an Ack emitted by
|
|
36
|
+
// an older socket cannot satisfy a later start() wait. See VENDOR.md #14.
|
|
37
|
+
controlConnectionGeneration = 0;
|
|
33
38
|
allowTunnelReconnect = true;
|
|
34
39
|
tunnelRuntimes = new Map();
|
|
35
40
|
// VENDOR DELTA: reconnect backoffs are tied to this lifecycle controller so stop() cancels
|
|
@@ -55,6 +60,7 @@ export class TunnelClient extends EventEmitter {
|
|
|
55
60
|
secret: options.secret,
|
|
56
61
|
controlUrl: options.controlUrl,
|
|
57
62
|
tunnelAddr: options.tunnelAddr,
|
|
63
|
+
authTimeoutMs: options.authTimeoutMs ?? DEFAULT_AUTH_TIMEOUT_MS,
|
|
58
64
|
heartbeatMs: options.heartbeatMs ?? DEFAULT_HEARTBEAT_MS,
|
|
59
65
|
reconnectMs: options.reconnectMs ?? DEFAULT_RECONNECT_MS,
|
|
60
66
|
logLevel: options.logLevel ?? DEFAULT_LOG_LEVEL,
|
|
@@ -78,13 +84,42 @@ export class TunnelClient extends EventEmitter {
|
|
|
78
84
|
this.reconnectDelayController = new AbortController();
|
|
79
85
|
}
|
|
80
86
|
this.running = true;
|
|
87
|
+
const expectedConnectionGeneration = this.controlConnectionGeneration + 1;
|
|
81
88
|
this.controlLoopTask = this.runControlLoop();
|
|
82
89
|
await new Promise((resolve, reject) => {
|
|
90
|
+
let settled = false;
|
|
91
|
+
const cleanup = () => {
|
|
92
|
+
clearTimeout(timeout);
|
|
93
|
+
this.off("control-authenticated", onAuthenticated);
|
|
94
|
+
this.off(CONTROL_AUTHENTICATION_FAILED, onAuthenticationFailed);
|
|
95
|
+
};
|
|
96
|
+
const settle = (callback) => {
|
|
97
|
+
if (settled) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
settled = true;
|
|
101
|
+
cleanup();
|
|
102
|
+
callback();
|
|
103
|
+
};
|
|
104
|
+
const onAuthenticated = (connectionGeneration) => {
|
|
105
|
+
if (connectionGeneration === expectedConnectionGeneration) {
|
|
106
|
+
settle(resolve);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const onAuthenticationFailed = (connectionGeneration, error) => {
|
|
110
|
+
if (connectionGeneration === expectedConnectionGeneration) {
|
|
111
|
+
settle(() => reject(error));
|
|
112
|
+
}
|
|
113
|
+
};
|
|
83
114
|
const onLoopEnd = () => {
|
|
84
|
-
reject(new Error("Control loop ended before connecting"));
|
|
115
|
+
settle(() => reject(new Error("Control loop ended before connecting")));
|
|
85
116
|
};
|
|
86
|
-
this.
|
|
117
|
+
this.on("control-authenticated", onAuthenticated);
|
|
118
|
+
this.on(CONTROL_AUTHENTICATION_FAILED, onAuthenticationFailed);
|
|
87
119
|
this.controlLoopTask?.then(onLoopEnd);
|
|
120
|
+
const timeout = setTimeout(() => {
|
|
121
|
+
settle(() => reject(new Error(`The tunnel server accepted the connection but never acknowledged authentication within ${this.options.authTimeoutMs}ms`)));
|
|
122
|
+
}, this.options.authTimeoutMs);
|
|
88
123
|
});
|
|
89
124
|
this.log("info", "Tunnel client started");
|
|
90
125
|
}
|
|
@@ -159,12 +194,21 @@ export class TunnelClient extends EventEmitter {
|
|
|
159
194
|
}
|
|
160
195
|
connectControl() {
|
|
161
196
|
return new Promise((resolve, reject) => {
|
|
197
|
+
const connectionGeneration = ++this.controlConnectionGeneration;
|
|
162
198
|
const controlUrl = new URL(this.options.controlUrl);
|
|
163
199
|
controlUrl.searchParams.set("client_id", this.options.clientId);
|
|
164
200
|
const ws = new WebSocket(controlUrl);
|
|
165
201
|
this.controlWs = ws;
|
|
166
202
|
let heartbeatTimer;
|
|
167
203
|
let opened = false;
|
|
204
|
+
let authenticationSettled = false;
|
|
205
|
+
const failAuthentication = (error) => {
|
|
206
|
+
if (authenticationSettled) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
authenticationSettled = true;
|
|
210
|
+
this.emit(CONTROL_AUTHENTICATION_FAILED, connectionGeneration, error);
|
|
211
|
+
};
|
|
168
212
|
const cleanup = () => {
|
|
169
213
|
if (heartbeatTimer) {
|
|
170
214
|
clearInterval(heartbeatTimer);
|
|
@@ -207,6 +251,13 @@ export class TunnelClient extends EventEmitter {
|
|
|
207
251
|
if (!message) {
|
|
208
252
|
return;
|
|
209
253
|
}
|
|
254
|
+
if (message.type === "Ack") {
|
|
255
|
+
if (!authenticationSettled) {
|
|
256
|
+
authenticationSettled = true;
|
|
257
|
+
this.emit("control-authenticated", connectionGeneration);
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
210
261
|
if (message.type === "RequestTunnel") {
|
|
211
262
|
this.log("debug", `RequestTunnel received: ${message.payload.tunnel_connection_id}`);
|
|
212
263
|
this.allowTunnelReconnect = true;
|
|
@@ -221,6 +272,7 @@ export class TunnelClient extends EventEmitter {
|
|
|
221
272
|
});
|
|
222
273
|
ws.on("error", (err) => {
|
|
223
274
|
cleanup();
|
|
275
|
+
failAuthentication(new Error(`Control websocket errored before authentication was acknowledged: ${toErrorMessage(err)}`));
|
|
224
276
|
if (!opened) {
|
|
225
277
|
this.controlConnected = false;
|
|
226
278
|
this.stopAllTunnelRuntimes();
|
|
@@ -235,6 +287,7 @@ export class TunnelClient extends EventEmitter {
|
|
|
235
287
|
this.stopAllTunnelRuntimes();
|
|
236
288
|
this.emit("control-disconnected");
|
|
237
289
|
const reason = reasonBuffer.toString("utf8");
|
|
290
|
+
failAuthentication(new Error(`Control websocket closed before authentication was acknowledged (code=${code}, reason=${reason || "<empty>"})`));
|
|
238
291
|
this.log("warn", `Control websocket closed (code=${code}, reason=${reason || "<empty>"})`);
|
|
239
292
|
if (isAuthFailureClose(code, reason)) {
|
|
240
293
|
reject(new ControlAuthFailureError(code, reason));
|
|
@@ -849,16 +902,16 @@ class TargetConnectError extends Error {
|
|
|
849
902
|
}
|
|
850
903
|
/**
|
|
851
904
|
* Thrown by {@link ensureTargetAllowed} when a proxied target resolves into a blocked
|
|
852
|
-
* (private/internal) range
|
|
853
|
-
* `TS_TUNNEL_ALLOW_PRIVATE_NETWORK_TARGET`. Mirrors the Rust client's
|
|
854
|
-
* `ensure_candidates_allowed` error.
|
|
905
|
+
* (private/internal) range. Mirrors the Rust client's `ensure_candidates_allowed` error.
|
|
855
906
|
*/
|
|
856
907
|
export class BlockedTargetError extends Error {
|
|
857
908
|
constructor(host, port, address, reason) {
|
|
858
909
|
super(address === undefined
|
|
859
910
|
? `target ${host}:${port} did not resolve to any address`
|
|
860
911
|
: `target ${host}:${port} resolves to ${address} (${reason}); refusing to dial. `
|
|
861
|
-
+ "
|
|
912
|
+
+ "This run can reach localhost, 127.0.0.1, or ::1 on this machine and the public internet; "
|
|
913
|
+
+ "private/LAN/VPN addresses are deliberately blocked. Make the dependency reachable through "
|
|
914
|
+
+ "loopback or a public address, then retry.");
|
|
862
915
|
this.name = "BlockedTargetError";
|
|
863
916
|
}
|
|
864
917
|
}
|
|
@@ -20,6 +20,14 @@
|
|
|
20
20
|
*/
|
|
21
21
|
/** Heartbeat cadence on the control WebSocket. Upstream default. */
|
|
22
22
|
export declare const DEFAULT_HEARTBEAT_MS = 10000;
|
|
23
|
+
/**
|
|
24
|
+
* Maximum time `start()` waits for the server's authentication Ack.
|
|
25
|
+
*
|
|
26
|
+
* VENDOR DELTA: matches the existing 10-second heartbeat and target-connect
|
|
27
|
+
* windows, so a control socket cannot look ready indefinitely when the server
|
|
28
|
+
* accepted the transport but never authenticated it.
|
|
29
|
+
*/
|
|
30
|
+
export declare const DEFAULT_AUTH_TIMEOUT_MS = 10000;
|
|
23
31
|
/** Delay between control/tunnel reconnect attempts. Upstream default. */
|
|
24
32
|
export declare const DEFAULT_RECONNECT_MS = 3000;
|
|
25
33
|
/** Log verbosity floor. Upstream default. */
|
|
@@ -20,6 +20,14 @@
|
|
|
20
20
|
*/
|
|
21
21
|
/** Heartbeat cadence on the control WebSocket. Upstream default. */
|
|
22
22
|
export const DEFAULT_HEARTBEAT_MS = 10_000;
|
|
23
|
+
/**
|
|
24
|
+
* Maximum time `start()` waits for the server's authentication Ack.
|
|
25
|
+
*
|
|
26
|
+
* VENDOR DELTA: matches the existing 10-second heartbeat and target-connect
|
|
27
|
+
* windows, so a control socket cannot look ready indefinitely when the server
|
|
28
|
+
* accepted the transport but never authenticated it.
|
|
29
|
+
*/
|
|
30
|
+
export const DEFAULT_AUTH_TIMEOUT_MS = 10_000;
|
|
23
31
|
/** Delay between control/tunnel reconnect attempts. Upstream default. */
|
|
24
32
|
export const DEFAULT_RECONNECT_MS = 3_000;
|
|
25
33
|
/** Log verbosity floor. Upstream default. */
|
|
@@ -22,6 +22,11 @@ export interface TunnelClientOptions {
|
|
|
22
22
|
controlUrl: string;
|
|
23
23
|
/** VENDOR DELTA: required. `host:port` of the tunnel DATA plane. */
|
|
24
24
|
tunnelAddr: string;
|
|
25
|
+
/**
|
|
26
|
+
* VENDOR DELTA: maximum time `start()` waits for the current control
|
|
27
|
+
* connection's first Ack, which is the server's authentication acknowledgement.
|
|
28
|
+
*/
|
|
29
|
+
authTimeoutMs?: number;
|
|
25
30
|
heartbeatMs?: number;
|
|
26
31
|
reconnectMs?: number;
|
|
27
32
|
logLevel?: LogLevel;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.10.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -67,6 +67,12 @@ Capture the returned `projectId`.
|
|
|
67
67
|
> `No environment URL configured` — the suite goes all-red. Always pass `--url`. If flows need
|
|
68
68
|
> login, pass `--username/--password-file` now so authenticated pages are reachable.
|
|
69
69
|
|
|
70
|
+
#### 2b. FE: register the app's test-hook attribute
|
|
71
|
+
|
|
72
|
+
If the source tags elements with something other than `data-testid` (e.g. `data-element`),
|
|
73
|
+
run `testsprite project update <projectId> --test-id-attributes data-element,data-testid`
|
|
74
|
+
once; exported locators then use the tag (check: `project get` → `testIdAttrs:`).
|
|
75
|
+
|
|
70
76
|
### 3. Get the tests — try generation first, author by hand if it isn't available
|
|
71
77
|
|
|
72
78
|
#### 3a. Preferred: generate → review → accept
|
|
@@ -261,7 +261,11 @@ confidently-wrong `passed` (bare visibility assertions) or a thrashing
|
|
|
261
261
|
- **Describe outcomes, not selectors.** The testing agent locates targets
|
|
262
262
|
semantically — describe the intent and the match stays robust across copy
|
|
263
263
|
changes; a guessed literal label defeats that. E.g. write `"Submit the form"`,
|
|
264
|
-
not `"Click the blue 'Submit' button"`.
|
|
264
|
+
not `"Click the blue 'Submit' button"`. If the app tags elements with its own
|
|
265
|
+
attribute (`data-element`, `data-cy`, …), make sure the project knows —
|
|
266
|
+
`testsprite project get <projectId>` shows `testIdAttrs:`; set it once with
|
|
267
|
+
`project update <projectId> --test-id-attributes <attr>,data-testid` — and the
|
|
268
|
+
exported code will locate tagged elements by that attribute instead of text.
|
|
265
269
|
- **`Navigate to` only on step 1** (or a login page). Use clicks for every later
|
|
266
270
|
transition — direct URLs break SPA routing.
|
|
267
271
|
- **FE plans narrate a user journey through their actions.** Each action is
|