@testsprite/testsprite-cli 0.8.0 → 0.9.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.
@@ -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 and the client has not opted in via `allowPrivateNetworkTarget` /
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.once("control-connected", resolve);
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 and the client has not opted in via `allowPrivateNetworkTarget` /
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
- + "Set TS_TUNNEL_ALLOW_PRIVATE_NETWORK_TARGET=true (or allowPrivateNetworkTarget: true) to override.");
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.8.0";
1
+ export declare const VERSION = "0.9.0";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // AUTO-GENERATED by scripts/generate-version.mjs — do not edit by hand.
2
2
  // Run `npm run build` (or `npm run generate:version`) to regenerate.
3
- export const VERSION = '0.8.0';
3
+ export const VERSION = '0.9.0';
4
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testsprite/testsprite-cli",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Official TestSprite command-line interface",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",