@testsprite/testsprite-cli 0.13.0 → 0.15.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.
Files changed (81) hide show
  1. package/README.md +54 -49
  2. package/dist/commands/ci.d.ts +66 -17
  3. package/dist/commands/ci.js +466 -104
  4. package/dist/commands/doctor.d.ts +3 -0
  5. package/dist/commands/doctor.js +62 -20
  6. package/dist/commands/init.js +17 -3
  7. package/dist/commands/project-env.d.ts +11 -1
  8. package/dist/commands/project-env.js +399 -61
  9. package/dist/commands/project-sign-in.d.ts +60 -0
  10. package/dist/commands/project-sign-in.js +289 -0
  11. package/dist/commands/project.d.ts +9 -0
  12. package/dist/commands/project.js +82 -28
  13. package/dist/commands/schedule.d.ts +12 -0
  14. package/dist/commands/schedule.js +175 -5
  15. package/dist/commands/test.d.ts +126 -30
  16. package/dist/commands/test.js +1928 -447
  17. package/dist/commands/testlist.d.ts +10 -5
  18. package/dist/commands/testlist.js +170 -30
  19. package/dist/commands/tunnel.js +11 -5
  20. package/dist/index.js +17 -38
  21. package/dist/lib/agent-targets.d.ts +8 -3
  22. package/dist/lib/agent-targets.js +15 -4
  23. package/dist/lib/ci-run.d.ts +11 -0
  24. package/dist/lib/ci-run.js +34 -0
  25. package/dist/lib/client-factory.d.ts +35 -1
  26. package/dist/lib/client-factory.js +21 -10
  27. package/dist/lib/config.d.ts +1 -0
  28. package/dist/lib/config.js +1 -1
  29. package/dist/lib/credentials.d.ts +0 -1
  30. package/dist/lib/credentials.js +51 -14
  31. package/dist/lib/dry-run/samples.js +95 -1
  32. package/dist/lib/environment-tunnel.d.ts +109 -0
  33. package/dist/lib/environment-tunnel.js +465 -0
  34. package/dist/lib/errors.js +12 -1
  35. package/dist/lib/first-suite-hint.d.ts +55 -0
  36. package/dist/lib/first-suite-hint.js +101 -0
  37. package/dist/lib/gh-output.d.ts +62 -4
  38. package/dist/lib/gh-output.js +152 -7
  39. package/dist/lib/github-context.d.ts +21 -0
  40. package/dist/lib/github-context.js +153 -0
  41. package/dist/lib/http.d.ts +12 -1
  42. package/dist/lib/http.js +9 -1
  43. package/dist/lib/junit-report.d.ts +11 -7
  44. package/dist/lib/junit-report.js +13 -7
  45. package/dist/lib/local-target.d.ts +13 -3
  46. package/dist/lib/local-target.js +47 -12
  47. package/dist/lib/output.js +15 -1
  48. package/dist/lib/plan-poll.js +3 -4
  49. package/dist/lib/plans.types.d.ts +1 -1
  50. package/dist/lib/redact.d.ts +38 -0
  51. package/dist/lib/redact.js +140 -0
  52. package/dist/lib/render-error.d.ts +19 -5
  53. package/dist/lib/render-error.js +31 -0
  54. package/dist/lib/response-schemas.d.ts +5 -1
  55. package/dist/lib/response-schemas.js +54 -0
  56. package/dist/lib/runs.types.d.ts +115 -1
  57. package/dist/lib/target-url.js +5 -5
  58. package/dist/lib/telemetry.d.ts +31 -8
  59. package/dist/lib/telemetry.js +55 -7
  60. package/dist/lib/testlist.types.d.ts +1 -0
  61. package/dist/lib/ticker.d.ts +9 -0
  62. package/dist/lib/ticker.js +18 -0
  63. package/dist/lib/tunnel-session.d.ts +3 -4
  64. package/dist/lib/tunnel-session.js +3 -4
  65. package/dist/lib/v3-advisory.js +0 -1
  66. package/dist/vendor/tunnel-client/client.d.ts +15 -8
  67. package/dist/vendor/tunnel-client/client.js +477 -407
  68. package/dist/vendor/tunnel-client/config.d.ts +5 -5
  69. package/dist/vendor/tunnel-client/config.js +5 -5
  70. package/dist/vendor/tunnel-client/index.d.ts +4 -4
  71. package/dist/vendor/tunnel-client/index.js +4 -4
  72. package/dist/vendor/tunnel-client/types.d.ts +19 -34
  73. package/dist/vendor/tunnel-client/types.js +1 -0
  74. package/dist/vendor/tunnel-client/ws-compat.d.ts +13 -3
  75. package/dist/vendor/tunnel-client/ws-compat.js +70 -12
  76. package/dist/version.d.ts +1 -1
  77. package/dist/version.js +1 -1
  78. package/package.json +1 -1
  79. package/schemas/plan.schema.json +2 -2
  80. package/skills/testsprite-ci.skill.md +154 -0
  81. package/skills/testsprite-onboard.skill.md +4 -4
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * VENDOR DELTA (not upstream). Upstream's `config.ts` reads `TSTUN_*`
3
- * environment variables and falls back to **hard-coded TestSprite dev
4
- * ALB/NLB hostnames**. Neither belongs in a package published to the public
3
+ * environment variables and falls back to **hard-coded TestSprite
4
+ * endpoints**. Neither belongs in a package published to the public
5
5
  * npm registry:
6
6
  *
7
7
  * - the endpoints are internal infrastructure names, and a default value is
@@ -23,9 +23,7 @@ export declare const DEFAULT_HEARTBEAT_MS = 10000;
23
23
  /**
24
24
  * Maximum time `start()` waits for the server's authentication Ack.
25
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.
26
+ * Upstream default: matches the heartbeat and target-connect windows.
29
27
  */
30
28
  export declare const DEFAULT_AUTH_TIMEOUT_MS = 10000;
31
29
  /** Maximum time allowed for each plaintext TCP connect. */
@@ -34,6 +32,8 @@ export declare const DEFAULT_CONNECT_TIMEOUT_MS = 10000;
34
32
  export declare const DEFAULT_TLS_HANDSHAKE_TIMEOUT_MS = 10000;
35
33
  /** Retry window after the first failed data-plane dial. Zero retries forever. */
36
34
  export declare const DEFAULT_DATA_PLANE_RETRY_DEADLINE_MS = 60000;
35
+ /** Upstream unknown-client retry window; dormant with the current capability-gated server. */
36
+ export declare const DEFAULT_CLIENT_UNKNOWN_RETRY_DEADLINE_MS = 120000;
37
37
  /** Post-hello interval after which an otherwise-idle data-plane session is established. */
38
38
  export declare const DEFAULT_DATA_PLANE_SETTLE_MS = 5000;
39
39
  /** Delay between control/tunnel reconnect attempts. Upstream default. */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * VENDOR DELTA (not upstream). Upstream's `config.ts` reads `TSTUN_*`
3
- * environment variables and falls back to **hard-coded TestSprite dev
4
- * ALB/NLB hostnames**. Neither belongs in a package published to the public
3
+ * environment variables and falls back to **hard-coded TestSprite
4
+ * endpoints**. Neither belongs in a package published to the public
5
5
  * npm registry:
6
6
  *
7
7
  * - the endpoints are internal infrastructure names, and a default value is
@@ -23,9 +23,7 @@ export const DEFAULT_HEARTBEAT_MS = 10_000;
23
23
  /**
24
24
  * Maximum time `start()` waits for the server's authentication Ack.
25
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.
26
+ * Upstream default: matches the heartbeat and target-connect windows.
29
27
  */
30
28
  export const DEFAULT_AUTH_TIMEOUT_MS = 10_000;
31
29
  /** Maximum time allowed for each plaintext TCP connect. */
@@ -34,6 +32,8 @@ export const DEFAULT_CONNECT_TIMEOUT_MS = 10_000;
34
32
  export const DEFAULT_TLS_HANDSHAKE_TIMEOUT_MS = 10_000;
35
33
  /** Retry window after the first failed data-plane dial. Zero retries forever. */
36
34
  export const DEFAULT_DATA_PLANE_RETRY_DEADLINE_MS = 60_000;
35
+ /** Upstream unknown-client retry window; dormant with the current capability-gated server. */
36
+ export const DEFAULT_CLIENT_UNKNOWN_RETRY_DEADLINE_MS = 120_000;
37
37
  /** Post-hello interval after which an otherwise-idle data-plane session is established. */
38
38
  export const DEFAULT_DATA_PLANE_SETTLE_MS = 5_000;
39
39
  /** Delay between control/tunnel reconnect attempts. Upstream default. */
@@ -1,8 +1,8 @@
1
1
  /**
2
- * VENDOR DELTA (not upstream). Upstream's `index.ts` re-exports only
3
- * `TunnelClient` / `BlockedTargetError`; this adds the two dial helpers,
4
- * which the CLI's port preflight reuses so the pre-charge probe dials the
5
- * SAME candidate set the client will dial at run time.
2
+ * VENDOR DELTA (not upstream). The CLI adds the two dial helpers, which its
3
+ * port preflight reuses so the pre-charge probe dials the SAME candidate set
4
+ * the client will dial at run time. Upstream endpoint defaults and dormant
5
+ * unknown-client recovery exports are intentionally omitted.
6
6
  */
7
7
  export { TunnelClient, BlockedTargetError, resolveDialCandidates, blockedTargetReason, } from './client.js';
8
8
  export type { TunnelClientOptions, StreamOpenRequestFrame, LogLevel } from './types.js';
@@ -1,8 +1,8 @@
1
1
  /**
2
- * VENDOR DELTA (not upstream). Upstream's `index.ts` re-exports only
3
- * `TunnelClient` / `BlockedTargetError`; this adds the two dial helpers,
4
- * which the CLI's port preflight reuses so the pre-charge probe dials the
5
- * SAME candidate set the client will dial at run time.
2
+ * VENDOR DELTA (not upstream). The CLI adds the two dial helpers, which its
3
+ * port preflight reuses so the pre-charge probe dials the SAME candidate set
4
+ * the client will dial at run time. Upstream endpoint defaults and dormant
5
+ * unknown-client recovery exports are intentionally omitted.
6
6
  */
7
7
  export { TunnelClient, BlockedTargetError, resolveDialCandidates, blockedTargetReason, } from './client.js';
8
8
  export { ErrCode } from './types.js';
@@ -1,4 +1,5 @@
1
1
  export type LogLevel = "debug" | "info" | "warn" | "error";
2
+ export type TunnelTransport = "tls" | "plaintext";
2
3
  export declare enum ErrCode {
3
4
  AuthFailed = "0001",
4
5
  ControlDisconnected = "0002",
@@ -6,7 +7,8 @@ export declare enum ErrCode {
6
7
  TargetConnectFailed = "0004",
7
8
  StreamFailed = "0005",
8
9
  BlockedTargetRejected = "0006",
9
- DataPlaneUnreachable = "0007"
10
+ DataPlaneUnreachable = "0007",
11
+ ClientUnknown = "0008"
10
12
  }
11
13
  export interface TunnelClientError {
12
14
  code: ErrCode;
@@ -15,42 +17,29 @@ export interface TunnelClientError {
15
17
  export interface TunnelClientOptions {
16
18
  clientId: string;
17
19
  secret: string;
18
- /**
19
- * VENDOR DELTA: required, not optional. The endpoint defaults upstream
20
- * carries are hard-coded TestSprite dev hostnames; they are gone here and
21
- * both values come from `POST /api/cli/v1/tunnel`. See ./config.ts.
22
- */
20
+ /** CLI endpoints must come from the tunnel mint response. */
23
21
  controlUrl: string;
24
- /** VENDOR DELTA: required. `host:port` of the tunnel DATA plane. */
22
+ /** Legacy unencrypted data-plane address (`host:port` or `[v6]:port`). */
25
23
  tunnelAddr: string;
26
- /**
27
- * TLS `host:port` (or `[v6]:port`) for the tunnel DATA plane. When set,
28
- * transport is fixed to TLS and `tunnelAddr` is never dialled as fallback.
29
- */
24
+ /** TLS data-plane address (`host:port` or `[v6]:port`). Takes precedence over `tunnelAddr`. */
30
25
  tunnelTlsAddr?: string;
31
- /** TLS SNI/verification name. Defaults to the hostname in `tunnelTlsAddr`. */
26
+ /** TLS SNI and certificate hostname. Defaults to the DNS host in `tunnelTlsAddr`. */
32
27
  tunnelTlsServername?: string;
33
- /** Extra PEM roots appended to Node's built-in root certificate set. */
28
+ /** Additional PEM roots appended to Node's default trust store. */
34
29
  tunnelTlsCa?: string | Buffer | Array<string | Buffer>;
35
- /** Maximum time to complete each plaintext TCP connect. Defaults to 10 seconds. */
36
- connectTimeoutMs?: number;
37
- /** Maximum time to complete each TLS connect + handshake. Defaults to 10 seconds. */
30
+ /** Maximum wait for the data-plane TLS handshake; defaults to 10 seconds. */
38
31
  tlsHandshakeTimeoutMs?: number;
39
- /**
40
- * Maximum retry window after the first failed data-plane attempt. The first
41
- * inbound yamux stream or the settle interval ends it. Defaults to 60
42
- * seconds; `0` retries forever.
43
- */
32
+ /** Maximum wait for a plaintext data-plane TCP connection; defaults to 10 seconds. */
33
+ connectTimeoutMs?: number;
34
+ /** Continuous data-plane failure episode; defaults to 60 seconds. Zero retries forever. */
44
35
  dataPlaneRetryDeadlineMs?: number;
45
- /**
46
- * Time a post-TunnelHello socket must remain open before the session counts
47
- * as established without an inbound yamux stream. Defaults to 5 seconds.
48
- */
36
+ /** Continuous unknown-client episode; defaults to 120 seconds. Zero retries forever. */
37
+ clientUnknownRetryDeadlineMs?: number;
38
+ /** Called before retrying an unknown client; can re-register the same ID and secret. */
39
+ onClientUnknown?: () => Promise<boolean | void>;
40
+ /** Open-session stability period that establishes the data plane; defaults to 5 seconds. */
49
41
  dataPlaneSettleMs?: number;
50
- /**
51
- * VENDOR DELTA: maximum time `start()` waits for the current control
52
- * connection's first Ack, which is the server's authentication acknowledgement.
53
- */
42
+ /** Maximum wait for the initial control connection's authentication Ack; defaults to 10 seconds. */
54
43
  authTimeoutMs?: number;
55
44
  heartbeatMs?: number;
56
45
  reconnectMs?: number;
@@ -70,11 +59,7 @@ export interface TunnelClientOptions {
70
59
  */
71
60
  allowPrivateNetworkTarget?: boolean;
72
61
  onError?(e: TunnelClientError): void;
73
- /**
74
- * VENDOR DELTA (not upstream): where log lines go. Upstream writes them to
75
- * `console.log`/`console.warn`, i.e. STDOUT, which would corrupt this CLI's
76
- * `--output json` contract. Absent -> stderr.
77
- */
62
+ /** CLI logs use the injected sink; the default writes only to stderr. */
78
63
  logSink?(level: LogLevel, line: string): void;
79
64
  }
80
65
  export type ClientToServerControlMessage = {
@@ -7,5 +7,6 @@ export var ErrCode;
7
7
  ErrCode["StreamFailed"] = "0005";
8
8
  ErrCode["BlockedTargetRejected"] = "0006";
9
9
  ErrCode["DataPlaneUnreachable"] = "0007";
10
+ ErrCode["ClientUnknown"] = "0008";
10
11
  })(ErrCode || (ErrCode = {}));
11
12
  //# sourceMappingURL=types.js.map
@@ -32,7 +32,7 @@
32
32
  * `WebSocket.close()` on an OPEN connection sends a Close frame and sets the
33
33
  * ready state to CLOSING — nothing more. It does not abort the underlying
34
34
  * connection and does not time out; that only happens for a CONNECTING
35
- * socket (`failWebsocketConnection`, upstream `client.ts` VENDOR DELTA #8's
35
+ * socket (`failWebsocketConnection`, upstream `client.ts` stop-on-CONNECTING
36
36
  * territory). If the peer never sends its own Close frame back — a redeploy
37
37
  * mid-handshake, a proxy that swallows the FIN, a server too busy to answer —
38
38
  * the ready state sits at CLOSING forever, the JS `'close'` event never
@@ -114,6 +114,14 @@ type PingListener = (data: Buffer) => void;
114
114
  * to hear about it.
115
115
  */
116
116
  export declare const CLOSE_GRACE_MS = 1200;
117
+ /** The fields undici publishes for a request about to write its headers. */
118
+ interface UpgradeRequest {
119
+ upgrade?: unknown;
120
+ path?: unknown;
121
+ origin?: unknown;
122
+ }
123
+ /** Does this `sendHeaders` request belong to the WebSocket upgrade for `target`? */
124
+ export declare function upgradeRequestMatchesTarget(request: UpgradeRequest | undefined, target: URL): boolean;
117
125
  /** The subset of `undici:client:connected`'s `connectParams` this filter reads. */
118
126
  export interface ConnectParams {
119
127
  hostname?: unknown;
@@ -161,7 +169,7 @@ export declare class WsCompatSocket {
161
169
  static readonly CONNECTING = 0;
162
170
  static readonly OPEN = 1;
163
171
  private readonly socket;
164
- /** Captured via `undici:client:connected`, if it fired — see the class docstring. */
172
+ /** Captured via connected or the upgrade's sendHeaders event, including reused sockets. */
165
173
  private rawSocket;
166
174
  private closeListener;
167
175
  private closeSettled;
@@ -173,7 +181,9 @@ export declare class WsCompatSocket {
173
181
  * `net.Socket` for THIS connection, filtered by target host/port so an
174
182
  * unrelated concurrent undici connection elsewhere in the process (e.g.
175
183
  * this CLI's own HTTP polling) is never mistaken for it. See the class
176
- * docstring for why `close()` needs this at all. Returns an idempotent
184
+ * docstring for why `close()` needs this at all. The sendHeaders fallback
185
+ * also checks the upgrade path and query, then ends both subscriptions.
186
+ * Returns an idempotent
177
187
  * unsubscribe closure. Never throws: a diagnostics hook failing must not
178
188
  * break the connection it exists only to make teardown more graceful for.
179
189
  */
@@ -32,7 +32,7 @@
32
32
  * `WebSocket.close()` on an OPEN connection sends a Close frame and sets the
33
33
  * ready state to CLOSING — nothing more. It does not abort the underlying
34
34
  * connection and does not time out; that only happens for a CONNECTING
35
- * socket (`failWebsocketConnection`, upstream `client.ts` VENDOR DELTA #8's
35
+ * socket (`failWebsocketConnection`, upstream `client.ts` stop-on-CONNECTING
36
36
  * territory). If the peer never sends its own Close frame back — a redeploy
37
37
  * mid-handshake, a proxy that swallows the FIN, a server too busy to answer —
38
38
  * the ready state sits at CLOSING forever, the JS `'close'` event never
@@ -118,6 +118,42 @@ export const CLOSE_GRACE_MS = 1200;
118
118
  * — payload is `{ socket, connectParams, connector }`.
119
119
  */
120
120
  const CONNECTED_CHANNEL = 'undici:client:connected';
121
+ /**
122
+ * Companion channel for the case `CONNECTED_CHANNEL` cannot see: the process-
123
+ * global dispatcher may hand the upgrade request an already-open pooled
124
+ * keep-alive connection (e.g. one an earlier API call left idle), in which
125
+ * case no dial happens and no `connected` event fires. `sendHeaders` is
126
+ * published for every request on whichever socket carries it, upgrade
127
+ * requests included — payload is `{ request, headers, socket }`.
128
+ */
129
+ const SEND_HEADERS_CHANNEL = 'undici:client:sendHeaders';
130
+ /** Does this `sendHeaders` request belong to the WebSocket upgrade for `target`? */
131
+ export function upgradeRequestMatchesTarget(request, target) {
132
+ if (typeof request?.upgrade !== 'string' ||
133
+ request.upgrade.toLowerCase() !== 'websocket' ||
134
+ typeof request.path !== 'string') {
135
+ return false;
136
+ }
137
+ try {
138
+ // undici converts ws/wss to http/https for the handshake. A forward
139
+ // proxy can put the target's absolute URL in path and its own origin in
140
+ // origin; in that case the absolute request target identifies the peer.
141
+ const absolutePath = /^https?:\/\//.test(request.path);
142
+ if (!absolutePath && typeof request.origin !== 'string')
143
+ return false;
144
+ const origin = new URL(absolutePath ? request.path : request.origin);
145
+ const protocol = target.protocol === 'wss:' ? 'https:' : 'http:';
146
+ const defaultPort = protocol === 'https:' ? '443' : '80';
147
+ const path = absolutePath ? `${origin.pathname}${origin.search}` : request.path;
148
+ return (origin.protocol === protocol &&
149
+ origin.hostname === target.hostname &&
150
+ (origin.port || defaultPort) === (target.port || defaultPort) &&
151
+ path === `${target.pathname}${target.search}`);
152
+ }
153
+ catch {
154
+ return false;
155
+ }
156
+ }
121
157
  /**
122
158
  * Does this `undici:client:connected` event belong to the WebSocket we are
123
159
  * trying to capture?
@@ -181,7 +217,7 @@ export class WsCompatSocket {
181
217
  static CONNECTING = 0;
182
218
  static OPEN = 1;
183
219
  socket;
184
- /** Captured via `undici:client:connected`, if it fired — see the class docstring. */
220
+ /** Captured via connected or the upgrade's sendHeaders event, including reused sockets. */
185
221
  rawSocket;
186
222
  closeListener;
187
223
  closeSettled = false;
@@ -189,22 +225,32 @@ export class WsCompatSocket {
189
225
  unsubscribeConnected;
190
226
  constructor(url) {
191
227
  this.unsubscribeConnected = this.captureRawSocket(url);
192
- this.socket = new UndiciWebSocket(url);
193
- // Whichever comes first, the capture window is over the moment this
194
- // connection attempt is decided — see captureRawSocket's docstring.
195
- this.socket.addEventListener('open', () => this.unsubscribeConnected(), { once: true });
196
- this.socket.addEventListener('error', () => this.unsubscribeConnected(), { once: true });
228
+ try {
229
+ this.socket = new UndiciWebSocket(url);
230
+ // Whichever comes first, the capture window is over the moment this
231
+ // connection attempt is decided — see captureRawSocket's docstring.
232
+ this.socket.addEventListener('open', () => this.unsubscribeConnected(), { once: true });
233
+ this.socket.addEventListener('error', () => this.unsubscribeConnected(), { once: true });
234
+ this.socket.addEventListener('close', (ev) => this.settleClose(ev.code, Buffer.from(ev.reason ?? '', 'utf8')), { once: true });
235
+ }
236
+ catch (error) {
237
+ this.unsubscribeConnected();
238
+ throw error;
239
+ }
197
240
  }
198
241
  /**
199
242
  * Subscribe to `undici:client:connected` just long enough to grab the raw
200
243
  * `net.Socket` for THIS connection, filtered by target host/port so an
201
244
  * unrelated concurrent undici connection elsewhere in the process (e.g.
202
245
  * this CLI's own HTTP polling) is never mistaken for it. See the class
203
- * docstring for why `close()` needs this at all. Returns an idempotent
246
+ * docstring for why `close()` needs this at all. The sendHeaders fallback
247
+ * also checks the upgrade path and query, then ends both subscriptions.
248
+ * Returns an idempotent
204
249
  * unsubscribe closure. Never throws: a diagnostics hook failing must not
205
250
  * break the connection it exists only to make teardown more graceful for.
206
251
  */
207
252
  captureRawSocket(url) {
253
+ let unsubscribe = () => { };
208
254
  try {
209
255
  const target = typeof url === 'string' ? new URL(url) : url;
210
256
  const channel = diagnosticsChannel.channel(CONNECTED_CHANNEL);
@@ -215,10 +261,24 @@ export class WsCompatSocket {
215
261
  channel.unsubscribe(onConnected);
216
262
  }
217
263
  };
264
+ const sendChannel = diagnosticsChannel.channel(SEND_HEADERS_CHANNEL);
265
+ const onSendHeaders = (message) => {
266
+ const { socket, request } = (message ?? {});
267
+ if (socket !== undefined && upgradeRequestMatchesTarget(request, target)) {
268
+ this.rawSocket = socket;
269
+ unsubscribe();
270
+ }
271
+ };
272
+ unsubscribe = () => {
273
+ channel.unsubscribe(onConnected);
274
+ sendChannel.unsubscribe(onSendHeaders);
275
+ };
218
276
  channel.subscribe(onConnected);
219
- return () => channel.unsubscribe(onConnected);
277
+ sendChannel.subscribe(onSendHeaders);
278
+ return unsubscribe;
220
279
  }
221
280
  catch {
281
+ unsubscribe();
222
282
  // Degrade to "no captured socket": close() still settles via the
223
283
  // synthetic-close path, just without the unref step.
224
284
  return () => { };
@@ -249,9 +309,6 @@ export class WsCompatSocket {
249
309
  // target of the synthetic close below, and either path must reach
250
310
  // this exact listener exactly once. See the class docstring.
251
311
  this.closeListener = listener;
252
- this.socket.addEventListener('close', (ev) => {
253
- this.settleClose(ev.code, Buffer.from(ev.reason ?? '', 'utf8'));
254
- });
255
312
  return this;
256
313
  case 'ping':
257
314
  // See the module docstring: undici answers PING internally, so there
@@ -265,6 +322,7 @@ export class WsCompatSocket {
265
322
  this.socket.send(data);
266
323
  }
267
324
  close(code, reason) {
325
+ this.unsubscribeConnected();
268
326
  this.socket.close(code, reason);
269
327
  this.armCloseGrace();
270
328
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.13.0";
1
+ export declare const VERSION = "0.15.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.13.0';
3
+ export const VERSION = '0.15.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.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Official TestSprite command-line interface",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "priority": {
34
34
  "type": "string",
35
- "enum": ["p0", "p1", "p2", "p3"],
36
- "description": "Optional. p0 = must-pass, p1 = important paths, p2 = edge cases, p3 = cosmetic."
35
+ "pattern": "^([pP][0-3]|[hH][iI][gG][hH]|[mM][eE][dD][iI][uU][mM]|[lL][oO][wW])$",
36
+ "description": "Optional. p0/high = must-pass, p1/medium = important paths, p2/low = edge cases; p3 is treated as low."
37
37
  },
38
38
  "planSteps": {
39
39
  "type": "array",
@@ -0,0 +1,154 @@
1
+ <!--
2
+ User-facing content for `testsprite agent install` (skill: testsprite-ci).
3
+ Body only — name + description frontmatter is emitted by the install wrapper.
4
+ The cursor (.mdc), cline (.clinerules), and antigravity (experimental)
5
+ wrappers reuse this body verbatim and swap only the frontmatter/header.
6
+ -->
7
+
8
+ # TestSprite: gate pull requests in CI
9
+
10
+ Put `testsprite ci run` into the repo's CI so every pull request's **preview
11
+ deployment** is tested before it merges.
12
+
13
+ This skill uses shipped CLI commands plus `git`, `gh` and the deploy platform's own
14
+ CLI. Do **not** call backend APIs directly.
15
+
16
+ ## When to use
17
+
18
+ - "Add TestSprite to CI / GitHub Actions", "run the tests on every PR", "block merges
19
+ on the tests", "PR gate".
20
+ - The project already has tests. If not, onboard it first with the `testsprite-onboard`
21
+ skill.
22
+
23
+ ## When NOT to use
24
+
25
+ - A nightly run of a fixed environment: `testsprite ci run --project <id> --env <name>`
26
+ on a `schedule:` trigger. No pull-request context is involved.
27
+
28
+ If this turns out to be more setup than the user wants, the TestSprite GitHub App
29
+ (Portal → project → Integrations) runs the same tests on every pull request with one
30
+ click.
31
+
32
+ ## 1. Find out how pull requests get deployed (the shape)
33
+
34
+ Decide from configuration. Read `.github/workflows/` and the repo root, in this order:
35
+
36
+ - A workflow step already runs `vercel deploy`, `netlify deploy` or a deploy script:
37
+ **B — the workflow deploys**. Trigger: `on: pull_request`.
38
+ - No workflow deploys, and `vercel.json` / `.vercel/` / `netlify.toml` or the platform's
39
+ git integration is present: **A — the platform deploys every PR**. Trigger:
40
+ `on: deployment_status`.
41
+ - Neither is clear: ask the user who deploys their pull-request previews.
42
+
43
+ Deployment history is a reference, not the decision:
44
+
45
+ ```bash
46
+ gh api repos/{owner}/{repo}/deployments --jq '.[] | "\(.environment) \(.ref[0:8]) \(.created_at)"'
47
+ ```
48
+
49
+ Recent **preview** records support A; production-only records mean preview deploys are
50
+ off on the platform. History is evidence, not configuration — the proof is a real pull
51
+ request (step 5).
52
+
53
+ Not linked but the user wants A: connect the repository to the platform's git
54
+ integration (Vercel: project → Settings → Git, or `npx vercel git connect` with the
55
+ user's approval — never `--yes`), or use shape B instead. Installing the platform's
56
+ GitHub App is a browser step only the user can do.
57
+
58
+ ## 2. Pick the environment the gate signs in with
59
+
60
+ ```bash
61
+ testsprite project env list <project-id>
62
+ ```
63
+
64
+ Choose the environment whose **account** the gate should sign in with. `ci run
65
+ --target-url` swaps only its address for the pull request's preview; the sign-in
66
+ stays. Without `--env` the project's default is written into the workflow **by name**.
67
+
68
+ ## 3. Generate the workflow, then finish it by hand
69
+
70
+ ```bash
71
+ testsprite ci init github --project <project-id> --env <name>
72
+ ```
73
+
74
+ This writes `.github/workflows/testsprite.yml` with one step marked `REPLACE ME`
75
+ (the job fails until it is replaced):
76
+
77
+ - **A:** change the trigger from `pull_request:` to `deployment_status:` and delete the
78
+ placeholder step; the run then reads the URL from `deployment_status.environment_url`.
79
+ A repo that deploys **several** Vercel projects gets one event per project for the
80
+ same commit — add `&& github.event.deployment.environment == 'Preview – <project>'`
81
+ to the `deployment_status` branch of the `if:`.
82
+ - **B:** replace the placeholder's `run:` with the deploy commands, ending in
83
+ `echo "url=<preview address>" >> "$GITHUB_OUTPUT"`. The platform token goes in its
84
+ own repo secret.
85
+
86
+ Keep what the template fixes: `testsprite ci run … --target-url "$PREVIEW_URL"
87
+ --fail-on-skipped --summary-file`, `npm i -g @testsprite/testsprite-cli@latest` (no
88
+ version pin — verdicts come from the backend), fork and draft PRs skipped, the upload
89
+ step on `if: always()`, and `concurrency` on the **job** (keyed by PR number in B, by
90
+ commit in A). Never re-judge pass/fail in YAML (`jq` + `exit 1`): `ci run`'s exit code
91
+ is the gate. Regenerate with `--force`; the previous file is kept as `.bak`.
92
+
93
+ ## 4. Secrets
94
+
95
+ ```bash
96
+ gh secret set TESTSPRITE_API_KEY # paste when prompted, or pipe on stdin
97
+ ```
98
+
99
+ (`ci init github --set-secret` does the same.) Never put the key in argv, YAML or
100
+ logs. A non-production endpoint goes in the workflow `env:` as `TESTSPRITE_API_URL`.
101
+ B also needs the platform's deploy token as a secret.
102
+
103
+ ## 5. Preflight, then prove it on one real pull request
104
+
105
+ Three checks before pushing; each of these otherwise shows up only as a red check
106
+ with the cause buried in the job log:
107
+
108
+ ```bash
109
+ gh auth status # gh can see this repo
110
+ gh secret list | grep TESTSPRITE_API_KEY # the secret landed (B: the deploy token too)
111
+ actionlint .github/workflows/testsprite.yml # the file parses — or `gh workflow view TestSprite` after the push
112
+ ```
113
+
114
+ Commit and push the workflow on a branch, open a PR that is **not a draft** and has
115
+ **no merge conflicts**, and watch the `TestSprite / testsprite-tests` check. The log shows
116
+ `Dispatched N tests.` then `CI run: x/y passed …`; the job summary is the execution
117
+ report (the same content as the App's PR comment); a `testsprite-results` artifact
118
+ holds `testsprite-summary.json`. Then suggest making the check **required** in branch
119
+ protection. In shape A the workflow file runs **at the deployed commit**, so the PR
120
+ branch itself is enough — nothing has to be merged first.
121
+
122
+ If nothing ran: a draft PR prints `Skipping draft pull request` and exits 0 with no
123
+ summary (mark it ready and re-run the job); a PR with merge conflicts never fires
124
+ `pull_request` workflows and GitHub shows no error; no run at all, not even the repo's
125
+ own workflows, means Actions is disabled on the repository (common on forks) — the
126
+ Actions tab shows an enable button; enable it and push an empty commit; in shape A
127
+ check that a
128
+ `deployment_status` with state `success` arrived for that commit (production
129
+ deployments are filtered out by the `if:`).
130
+
131
+ ## Reading the result
132
+
133
+ - The check is `ci run`'s exit code: 1 = a test failed, 7 = timeout or an unsupported
134
+ backend, 5 = configuration. A summary opening with a **CI gate** warning means the
135
+ CLI's own counts differ from the report (a run it could not read, a timeout) — the
136
+ check is right, the report is the server's view of the execution.
137
+ - `exit 7` with "did not confirm the single-execution admission mode" = the backend is
138
+ too old for `ci run`; the dispatched runs were cancelled and refunded.
139
+ - Screenshots in the report are capped at 12 per execution; later rows show `—`.
140
+ - Shape A is per commit: a new push starts its own run against its own preview, and
141
+ cancelling the job only stops the CLI — the execution keeps running and reports in
142
+ the Portal.
143
+ - Backend tests use the URL baked into their code, not `--target-url`.
144
+ - Testing `ci run` locally: a shell that exports `TESTSPRITE_API_URL` or
145
+ `TESTSPRITE_API_KEY` overrides `--profile` — a `fetch failed` against a healthy API is
146
+ usually that. Check `env | grep TESTSPRITE_` first.
147
+
148
+ ## Don'ts
149
+
150
+ - Don't add a CI gate next to the GitHub App on the same project without asking.
151
+ - Don't run `vercel link --yes`; don't pass secrets as arguments.
152
+ - Don't pin the CLI version in the workflow; don't parse the summary to decide the verdict.
153
+ - Don't commit a loopback or private `--target-url` (`ci run` refuses it).
154
+ - Don't skip step 5: a workflow that has not run on a real PR is not onboarded.
@@ -117,8 +117,8 @@ testsprite project docs upload ./prd.md --project <projectId> --role prd # opt
117
117
  testsprite test plan generate --project <projectId>
118
118
  ```
119
119
 
120
- Only missing stages run. Frontend exploration can take minutes; Ctrl-C detaches
121
- while generation continues. If inputs are still processing, wait and re-run.
120
+ Only missing stages run. Frontend exploration can take minutes. If cut off, the
121
+ running stage finishes; re-run to continue. If inputs are processing, wait and re-run.
122
122
 
123
123
  Review titles and steps against the source. Drop nonexistent flows, duplicates,
124
124
  and vague assertions before accepting.
@@ -181,8 +181,8 @@ runs keep working after the token expires. A hardcoded token expires within hour
181
181
  key can't be rotated centrally — `test create` emits a `[warn]` on an inlined credential; treat it
182
182
  as a must-fix.
183
183
 
184
- Each assertion must name an observable element, text, URL, count, or status.
185
- Avoid "verify it works" or "check the page loads": vague assertions create false passes.
184
+ Each assertion must name an observable element, text, URL, count, or status;
185
+ vague ones like "verify it works" create false passes.
186
186
 
187
187
  Aim for ~8–15 tests covering the core flows. Don't pad.
188
188