@testsprite/testsprite-cli 0.7.0 → 0.8.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 -38
- package/dist/commands/agent.js +47 -3
- package/dist/commands/ci.d.ts +88 -0
- package/dist/commands/ci.js +429 -0
- package/dist/commands/doctor.js +100 -1
- package/dist/commands/init.js +8 -0
- package/dist/commands/project.d.ts +78 -0
- package/dist/commands/project.js +426 -3
- package/dist/commands/test.d.ts +162 -2
- package/dist/commands/test.js +1814 -392
- package/dist/commands/testlist.js +15 -9
- package/dist/commands/tunnel.d.ts +72 -0
- package/dist/commands/tunnel.js +367 -0
- package/dist/index.js +107 -38
- package/dist/lib/dry-run/samples.d.ts +9 -0
- package/dist/lib/dry-run/samples.js +116 -0
- package/dist/lib/gh-output.d.ts +7 -0
- package/dist/lib/gh-output.js +50 -7
- package/dist/lib/http.d.ts +94 -0
- package/dist/lib/http.js +120 -5
- package/dist/lib/interrupt.d.ts +38 -13
- package/dist/lib/interrupt.js +130 -15
- package/dist/lib/local-target.d.ts +95 -0
- package/dist/lib/local-target.js +184 -0
- package/dist/lib/plan-poll.d.ts +171 -0
- package/dist/lib/plan-poll.js +442 -0
- package/dist/lib/plans.types.d.ts +130 -0
- package/dist/lib/plans.types.js +31 -0
- package/dist/lib/poll-support.d.ts +26 -0
- package/dist/lib/poll-support.js +65 -0
- package/dist/lib/poll.d.ts +1 -0
- package/dist/lib/poll.js +2 -40
- package/dist/lib/response-schemas.d.ts +13 -0
- package/dist/lib/response-schemas.js +32 -0
- package/dist/lib/run-progress.d.ts +41 -0
- package/dist/lib/run-progress.js +56 -0
- package/dist/lib/runs.types.d.ts +24 -0
- package/dist/lib/target-url-preflight.js +3 -3
- package/dist/lib/target-url.d.ts +44 -7
- package/dist/lib/target-url.js +250 -61
- package/dist/lib/telemetry.d.ts +11 -0
- package/dist/lib/telemetry.js +1 -0
- package/dist/lib/ticker.d.ts +8 -0
- package/dist/lib/ticker.js +3 -0
- package/dist/lib/tunnel-session.d.ts +129 -0
- package/dist/lib/tunnel-session.js +232 -0
- package/dist/lib/tunnel.types.d.ts +54 -0
- package/dist/lib/tunnel.types.js +8 -0
- package/dist/vendor/tunnel-client/client.d.ts +83 -0
- package/dist/vendor/tunnel-client/client.js +871 -0
- package/dist/vendor/tunnel-client/config.d.ts +41 -0
- package/dist/vendor/tunnel-client/config.js +42 -0
- package/dist/vendor/tunnel-client/index.d.ts +9 -0
- package/dist/vendor/tunnel-client/index.js +9 -0
- package/dist/vendor/tunnel-client/lodash-lite.d.ts +14 -0
- package/dist/vendor/tunnel-client/lodash-lite.js +24 -0
- package/dist/vendor/tunnel-client/protocol.d.ts +60 -0
- package/dist/vendor/tunnel-client/protocol.js +143 -0
- package/dist/vendor/tunnel-client/types.d.ts +96 -0
- package/dist/vendor/tunnel-client/types.js +10 -0
- package/dist/vendor/tunnel-client/ws-compat.d.ts +206 -0
- package/dist/vendor/tunnel-client/ws-compat.js +316 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
- package/skills/testsprite-onboard.skill.md +60 -4
- package/skills/testsprite-verify.codex.md +22 -16
- package/skills/testsprite-verify.skill.md +27 -18
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VENDOR DELTA (not upstream). A minimal `ws`-shaped facade over undici's
|
|
3
|
+
* WHATWG `WebSocket`, so the vendored tunnel client keeps its upstream body
|
|
4
|
+
* while this CLI adds no `ws` dependency: `undici` is already a runtime
|
|
5
|
+
* dependency here (`lib/proxy.ts` uses its `EnvHttpProxyAgent`), and its
|
|
6
|
+
* `WebSocket` is the same RFC 6455 implementation Node ships as the global.
|
|
7
|
+
*
|
|
8
|
+
* Only the surface `client.ts` actually touches is implemented — `on`,
|
|
9
|
+
* `send`, `close`, `pong`, `readyState`, and the statics `CONNECTING`/`OPEN`. Anything else
|
|
10
|
+
* is deliberately absent, and an unknown event name throws rather than being
|
|
11
|
+
* silently accepted, so a future upstream sync that reaches for a new `ws` API
|
|
12
|
+
* fails loudly instead of quietly never firing.
|
|
13
|
+
*
|
|
14
|
+
* Two behavioural notes, both a consequence of WHATWG's narrower surface:
|
|
15
|
+
*
|
|
16
|
+
* - **`ping` never fires and `pong()` is a no-op.** The WHATWG API does not
|
|
17
|
+
* expose control frames; undici answers a server PING with a PONG inside
|
|
18
|
+
* its own receiver, which is exactly what upstream's handler did by hand.
|
|
19
|
+
* Registering the listener is still accepted so the upstream line stays
|
|
20
|
+
* compilable and diffable.
|
|
21
|
+
* - **The control socket uses the process-global undici dispatcher**, so an
|
|
22
|
+
* `HTTP(S)_PROXY` this CLI honours (`lib/proxy.ts`) also carries the
|
|
23
|
+
* control WebSocket. Deliberate — but note it does NOT help the tunnel
|
|
24
|
+
* DATA plane, which is a raw `net.connect` and bypasses proxies entirely.
|
|
25
|
+
* `lib/tunnel-session.ts` warns about that asymmetry rather than
|
|
26
|
+
* pretending a proxied environment is supported.
|
|
27
|
+
*
|
|
28
|
+
* ## Why `close()` cannot just call `WebSocket.close()` and wait
|
|
29
|
+
*
|
|
30
|
+
* Read straight from undici's own source (`lib/web/websocket/connection.js`):
|
|
31
|
+
* `WebSocket.close()` on an OPEN connection sends a Close frame and sets the
|
|
32
|
+
* ready state to CLOSING — nothing more. It does not abort the underlying
|
|
33
|
+
* connection and does not time out; that only happens for a CONNECTING
|
|
34
|
+
* socket (`failWebsocketConnection`, upstream `client.ts` VENDOR DELTA #8's
|
|
35
|
+
* territory). If the peer never sends its own Close frame back — a redeploy
|
|
36
|
+
* mid-handshake, a proxy that swallows the FIN, a server too busy to answer —
|
|
37
|
+
* the ready state sits at CLOSING forever, the JS `'close'` event never
|
|
38
|
+
* fires, and the socket stays an active libuv handle. Confirmed empirically:
|
|
39
|
+
* against a stub that completes the WS upgrade and then never answers a
|
|
40
|
+
* Close frame, `TunnelClient.stop()` (which awaits exactly this event) never
|
|
41
|
+
* resolves, and `process.getActiveResourcesInfo()` shows the same
|
|
42
|
+
* `TCPSocketWrap` present indefinitely. There is no public undici API to
|
|
43
|
+
* force it — `#handler.socket` is a true private class field, and even a
|
|
44
|
+
* dedicated per-connection `Dispatcher.destroy()` does nothing once the
|
|
45
|
+
* connection has been upgraded (verified: undici hands the socket off to the
|
|
46
|
+
* `WebSocket` instance at that point, detaching it from the dispatcher's own
|
|
47
|
+
* bookkeeping).
|
|
48
|
+
*
|
|
49
|
+
* So `close()` here arms a short local grace timer alongside the real
|
|
50
|
+
* WHATWG close. If the peer answers within it, the real `'close'` event
|
|
51
|
+
* settles everything and the timer is a no-op. If it doesn't, we settle
|
|
52
|
+
* locally instead of waiting forever:
|
|
53
|
+
*
|
|
54
|
+
* - `.unref()` (never `.destroy()`) the raw socket, captured at connect
|
|
55
|
+
* time via undici's documented `undici:client:connected` diagnostics
|
|
56
|
+
* channel — a public, if "Experimental"-labeled, hook that hands us the
|
|
57
|
+
* `net.Socket` undici itself dialed, filtered to this connection's own
|
|
58
|
+
* host/port so an unrelated concurrent undici connection is never
|
|
59
|
+
* mistaken for it. `unref()` is the right tool and `.destroy()` is not:
|
|
60
|
+
* by the time the grace period expires we have already sent our own
|
|
61
|
+
* Close frame and have no further use for the socket — there is no
|
|
62
|
+
* work left that it is the last thing holding open, which is exactly
|
|
63
|
+
* the bar this codebase's timer-`unref` doctrine sets (contrast the
|
|
64
|
+
* rejected fix elsewhere in this repo, where `unref`ing a POLLING
|
|
65
|
+
* timer let a process exit before its work was done — this is the
|
|
66
|
+
* opposite situation, a corpse the peer refuses to bury after the work
|
|
67
|
+
* is already finished). `.destroy()` would instead reset the still-open
|
|
68
|
+
* TCP connection out from under a peer that might complete its side a
|
|
69
|
+
* moment later, for no benefit we need.
|
|
70
|
+
* - Synthesize the `'close'` event ourselves (code 1006, "abnormal
|
|
71
|
+
* closure" — the conventional code for "the connection just went away",
|
|
72
|
+
* and never confused with an auth failure: `client.ts`'s
|
|
73
|
+
* `isAuthFailureClose` only matches code 1008) so `client.ts`'s own
|
|
74
|
+
* unmodified `ws.on("close", ...)` handler runs exactly as it would for
|
|
75
|
+
* a real close: it clears the heartbeat interval, resolves the
|
|
76
|
+
* `connectControl()` promise `runControlLoop` is stuck awaiting, and
|
|
77
|
+
* unwinds `stop()`'s own `Promise.allSettled`. No vendored file needs to
|
|
78
|
+
* change for this — the synthetic close travels through the exact same,
|
|
79
|
+
* already-correct listener.
|
|
80
|
+
*
|
|
81
|
+
* A proxied connection is NOT a miss, which is worth stating because it looks
|
|
82
|
+
* like one: with `EnvHttpProxyAgent` installed as the global dispatcher,
|
|
83
|
+
* undici publishes TWO `undici:client:connected` events — the physical dial to
|
|
84
|
+
* the proxy, whose `connectParams` carry the PROXY's host/port, and a second
|
|
85
|
+
* one from the per-origin `Client` it creates internally, whose `connectParams`
|
|
86
|
+
* carry the TARGET's. The filter below matches the second and captures the
|
|
87
|
+
* same live socket (physically connected to the proxy, tunneled to the
|
|
88
|
+
* target). Verified against undici 7.29.0 with a real CONNECT proxy: a `--local`
|
|
89
|
+
* teardown under `HTTP_PROXY` exits in the same ~1.4s as without one. The `wss:`
|
|
90
|
+
* variant TLS-wraps that tunneled socket and was not exercised — it is
|
|
91
|
+
* analogous by code reading only.
|
|
92
|
+
*
|
|
93
|
+
* If capture DOES miss — the channel never fires, or a future undici publishes
|
|
94
|
+
* a different payload shape — the synthetic close still clears the heartbeat,
|
|
95
|
+
* but the control socket stays ref'd and **the original hang comes back**. That
|
|
96
|
+
* is the honest statement: this is not a socket "left for process exit to
|
|
97
|
+
* reap", because nothing forces this process to exit — a ref'd socket IS the
|
|
98
|
+
* bug. Treat any change to the filter as load-bearing. Never throws either way:
|
|
99
|
+
* a diagnostics hook failing must not break teardown.
|
|
100
|
+
*/
|
|
101
|
+
import diagnosticsChannel from 'node:diagnostics_channel';
|
|
102
|
+
import { WebSocket as UndiciWebSocket } from 'undici';
|
|
103
|
+
/**
|
|
104
|
+
* How long `close()` waits for the peer to finish the WHATWG closing
|
|
105
|
+
* handshake before giving up and settling locally (see the class docstring).
|
|
106
|
+
* Deliberately well under `TUNNEL_CLIENT_STOP_TIMEOUT_MS`
|
|
107
|
+
* (`lib/tunnel-session.ts`, 2000ms) so the caller's own bounded race around
|
|
108
|
+
* `client.stop()` sees OUR settle win, not its own timeout race — the
|
|
109
|
+
* process should learn its socket/timer are released, not just stop waiting
|
|
110
|
+
* to hear about it.
|
|
111
|
+
*/
|
|
112
|
+
export const CLOSE_GRACE_MS = 1200;
|
|
113
|
+
/**
|
|
114
|
+
* The diagnostics_channel this module listens to in order to capture the raw
|
|
115
|
+
* socket a WebSocket connection is running over. Documented at
|
|
116
|
+
* https://github.com/nodejs/undici/blob/main/docs/docs/api/DiagnosticsChannel.md#undiciclientconnected
|
|
117
|
+
* — payload is `{ socket, connectParams, connector }`.
|
|
118
|
+
*/
|
|
119
|
+
const CONNECTED_CHANNEL = 'undici:client:connected';
|
|
120
|
+
/**
|
|
121
|
+
* Does this `undici:client:connected` event belong to the WebSocket we are
|
|
122
|
+
* trying to capture?
|
|
123
|
+
*
|
|
124
|
+
* Exported, and its own function, because it is load-bearing and subtle: a
|
|
125
|
+
* miss here is silent, and its consequence is the original close-hang coming
|
|
126
|
+
* back with every test still green (see the class docstring). Reviewing a
|
|
127
|
+
* predicate is easier than reviewing it inlined in a subscription callback.
|
|
128
|
+
*
|
|
129
|
+
* Both ports are normalized to the scheme default, and that symmetry is the
|
|
130
|
+
* fix: undici publishes `connectParams.port` straight from a WHATWG URL, which
|
|
131
|
+
* leaves a default-scheme port IMPLICIT — `ws://host/control` arrives as `''`,
|
|
132
|
+
* and `Number('') === 0`. The target side was already being defaulted to
|
|
133
|
+
* 80/443 while the event side was not, so capture missed for every
|
|
134
|
+
* implicit-port control URL, proxy or no proxy.
|
|
135
|
+
*
|
|
136
|
+
* Host is compared exactly. A proxied connection publishes two events — the
|
|
137
|
+
* physical dial to the proxy, and a second one from the per-origin `Client`
|
|
138
|
+
* undici creates internally — and only the second carries the target's host,
|
|
139
|
+
* which is precisely the one worth capturing.
|
|
140
|
+
*/
|
|
141
|
+
export function connectEventMatchesTarget(connectParams, target) {
|
|
142
|
+
if (connectParams?.hostname !== target.hostname)
|
|
143
|
+
return false;
|
|
144
|
+
const defaultPort = target.protocol === 'wss:' ? 443 : 80;
|
|
145
|
+
const normalize = (raw) => raw === '' || raw === undefined || raw === null ? defaultPort : Number(raw);
|
|
146
|
+
return normalize(connectParams.port) === normalize(target.port);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Normalise a WHATWG message payload to the `string | Buffer` union the
|
|
150
|
+
* vendored client's `typeof payload === "string" ? … : payload.toString()`
|
|
151
|
+
* branch expects. Text frames arrive as strings; a binary frame (which this
|
|
152
|
+
* protocol never sends) arrives as an ArrayBuffer and is wrapped rather than
|
|
153
|
+
* dropped, so an unexpected frame surfaces as a JSON parse failure instead of
|
|
154
|
+
* a `payload.toString is not a function` crash.
|
|
155
|
+
*/
|
|
156
|
+
export function toPayload(data) {
|
|
157
|
+
if (typeof data === 'string')
|
|
158
|
+
return data;
|
|
159
|
+
if (data instanceof ArrayBuffer)
|
|
160
|
+
return Buffer.from(data);
|
|
161
|
+
if (ArrayBuffer.isView(data)) {
|
|
162
|
+
return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
163
|
+
}
|
|
164
|
+
return String(data);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Pull a real `Error` out of undici's ErrorEvent. `.error` is typed as an
|
|
168
|
+
* `Error` but is not guaranteed to be populated for every failure mode, so
|
|
169
|
+
* `.message` is the fallback and a generic error is the floor — the vendored
|
|
170
|
+
* client passes whatever comes out to `toErrorMessage()` and to `reject()`.
|
|
171
|
+
*/
|
|
172
|
+
export function toError(event) {
|
|
173
|
+
const candidate = event?.error;
|
|
174
|
+
if (candidate instanceof Error)
|
|
175
|
+
return candidate;
|
|
176
|
+
const message = event?.message;
|
|
177
|
+
return new Error(typeof message === 'string' && message.length > 0 ? message : 'websocket error');
|
|
178
|
+
}
|
|
179
|
+
export class WsCompatSocket {
|
|
180
|
+
static CONNECTING = 0;
|
|
181
|
+
static OPEN = 1;
|
|
182
|
+
socket;
|
|
183
|
+
/** Captured via `undici:client:connected`, if it fired — see the class docstring. */
|
|
184
|
+
rawSocket;
|
|
185
|
+
closeListener;
|
|
186
|
+
closeSettled = false;
|
|
187
|
+
closeGraceTimer;
|
|
188
|
+
unsubscribeConnected;
|
|
189
|
+
constructor(url) {
|
|
190
|
+
this.unsubscribeConnected = this.captureRawSocket(url);
|
|
191
|
+
this.socket = new UndiciWebSocket(url);
|
|
192
|
+
// Whichever comes first, the capture window is over the moment this
|
|
193
|
+
// connection attempt is decided — see captureRawSocket's docstring.
|
|
194
|
+
this.socket.addEventListener('open', () => this.unsubscribeConnected(), { once: true });
|
|
195
|
+
this.socket.addEventListener('error', () => this.unsubscribeConnected(), { once: true });
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Subscribe to `undici:client:connected` just long enough to grab the raw
|
|
199
|
+
* `net.Socket` for THIS connection, filtered by target host/port so an
|
|
200
|
+
* unrelated concurrent undici connection elsewhere in the process (e.g.
|
|
201
|
+
* this CLI's own HTTP polling) is never mistaken for it. See the class
|
|
202
|
+
* docstring for why `close()` needs this at all. Returns an idempotent
|
|
203
|
+
* unsubscribe closure. Never throws: a diagnostics hook failing must not
|
|
204
|
+
* break the connection it exists only to make teardown more graceful for.
|
|
205
|
+
*/
|
|
206
|
+
captureRawSocket(url) {
|
|
207
|
+
try {
|
|
208
|
+
const target = typeof url === 'string' ? new URL(url) : url;
|
|
209
|
+
const channel = diagnosticsChannel.channel(CONNECTED_CHANNEL);
|
|
210
|
+
const onConnected = (message) => {
|
|
211
|
+
const { socket, connectParams } = (message ?? {});
|
|
212
|
+
if (socket !== undefined && connectEventMatchesTarget(connectParams, target)) {
|
|
213
|
+
this.rawSocket = socket;
|
|
214
|
+
channel.unsubscribe(onConnected);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
channel.subscribe(onConnected);
|
|
218
|
+
return () => channel.unsubscribe(onConnected);
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
// Degrade to "no captured socket": close() still settles via the
|
|
222
|
+
// synthetic-close path, just without the unref step.
|
|
223
|
+
return () => { };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
get readyState() {
|
|
227
|
+
return this.socket.readyState;
|
|
228
|
+
}
|
|
229
|
+
on(event, listener) {
|
|
230
|
+
switch (event) {
|
|
231
|
+
case 'open':
|
|
232
|
+
this.socket.addEventListener('open', () => {
|
|
233
|
+
listener();
|
|
234
|
+
});
|
|
235
|
+
return this;
|
|
236
|
+
case 'message':
|
|
237
|
+
this.socket.addEventListener('message', (ev) => {
|
|
238
|
+
listener(toPayload(ev.data));
|
|
239
|
+
});
|
|
240
|
+
return this;
|
|
241
|
+
case 'error':
|
|
242
|
+
this.socket.addEventListener('error', (ev) => {
|
|
243
|
+
listener(toError(ev));
|
|
244
|
+
});
|
|
245
|
+
return this;
|
|
246
|
+
case 'close':
|
|
247
|
+
// Stored rather than forwarded directly: settleClose() is also the
|
|
248
|
+
// target of the synthetic close below, and either path must reach
|
|
249
|
+
// this exact listener exactly once. See the class docstring.
|
|
250
|
+
this.closeListener = listener;
|
|
251
|
+
this.socket.addEventListener('close', (ev) => {
|
|
252
|
+
this.settleClose(ev.code, Buffer.from(ev.reason ?? '', 'utf8'));
|
|
253
|
+
});
|
|
254
|
+
return this;
|
|
255
|
+
case 'ping':
|
|
256
|
+
// See the module docstring: undici answers PING internally, so there
|
|
257
|
+
// is nothing to forward. Accepted, never invoked.
|
|
258
|
+
return this;
|
|
259
|
+
default:
|
|
260
|
+
throw new Error(`WsCompatSocket: unsupported event "${String(event)}"`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
send(data) {
|
|
264
|
+
this.socket.send(data);
|
|
265
|
+
}
|
|
266
|
+
close(code, reason) {
|
|
267
|
+
this.socket.close(code, reason);
|
|
268
|
+
this.armCloseGrace();
|
|
269
|
+
}
|
|
270
|
+
/** No-op — see the module docstring. */
|
|
271
|
+
pong(_data) {
|
|
272
|
+
void _data;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Invoke the registered close listener exactly once, whichever of "the
|
|
276
|
+
* real WHATWG close event" or "our own grace-timeout settle" gets there
|
|
277
|
+
* first — a real close that arrives after the grace timer already fired is
|
|
278
|
+
* a no-op here, and vice versa.
|
|
279
|
+
*/
|
|
280
|
+
settleClose(code, reason) {
|
|
281
|
+
if (this.closeSettled)
|
|
282
|
+
return;
|
|
283
|
+
this.closeSettled = true;
|
|
284
|
+
if (this.closeGraceTimer !== undefined) {
|
|
285
|
+
clearTimeout(this.closeGraceTimer);
|
|
286
|
+
this.closeGraceTimer = undefined;
|
|
287
|
+
}
|
|
288
|
+
this.unsubscribeConnected();
|
|
289
|
+
this.closeListener?.(code, reason);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* See the class docstring's "Why `close()` cannot just call
|
|
293
|
+
* `WebSocket.close()` and wait" section. A no-op if the real close has
|
|
294
|
+
* already settled synchronously (true for a CONNECTING socket — undici's
|
|
295
|
+
* own `failWebsocketConnection` handles that case completely, with no
|
|
296
|
+
* grace period needed) or if a grace timer is already armed.
|
|
297
|
+
*/
|
|
298
|
+
armCloseGrace() {
|
|
299
|
+
if (this.closeSettled || this.closeGraceTimer !== undefined)
|
|
300
|
+
return;
|
|
301
|
+
this.closeGraceTimer = setTimeout(() => {
|
|
302
|
+
this.closeGraceTimer = undefined;
|
|
303
|
+
// The peer never finished the closing handshake within the grace
|
|
304
|
+
// window. We already sent our own Close frame and have no further use
|
|
305
|
+
// for this socket, so unref (never destroy — see the class docstring)
|
|
306
|
+
// it, then settle locally so client.ts's own unmodified close handler
|
|
307
|
+
// still runs (clears the heartbeat interval, unwinds the control
|
|
308
|
+
// loop). 1006 ("abnormal closure") is never mistaken for an auth
|
|
309
|
+
// failure — client.ts's isAuthFailureClose only matches code 1008.
|
|
310
|
+
this.rawSocket?.unref();
|
|
311
|
+
this.settleClose(1006, Buffer.from('local close timeout: peer did not complete the WS closing handshake', 'utf8'));
|
|
312
|
+
}, CLOSE_GRACE_MS);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
export default WsCompatSocket;
|
|
316
|
+
//# sourceMappingURL=ws-compat.js.map
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.8.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testsprite/testsprite-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Official TestSprite command-line interface",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"author": "TestSprite team",
|
|
60
60
|
"license": "Apache-2.0",
|
|
61
61
|
"dependencies": {
|
|
62
|
+
"@llmcode/yamux-ts": "0.0.2",
|
|
62
63
|
"commander": "^12.1.0",
|
|
63
64
|
"undici": "^7.16.0",
|
|
64
65
|
"valibot": "^1.4.1"
|
|
@@ -12,8 +12,11 @@ Your job is to take a repo that has **no TestSprite tests yet** and leave it wit
|
|
|
12
12
|
A new user who can immediately run a real, passing test is an activated user; an empty
|
|
13
13
|
project is the #1 drop-off.
|
|
14
14
|
|
|
15
|
-
This skill only uses shipped CLI commands.
|
|
16
|
-
|
|
15
|
+
This skill only uses shipped CLI commands. Do **not** call backend APIs directly.
|
|
16
|
+
|
|
17
|
+
Step 3 offers two paths to a suite, tried in order: let TestSprite **generate** the tests
|
|
18
|
+
(fastest; needs a V3-platform account and a recent CLI), or **author** them by hand
|
|
19
|
+
(always works). Everything else here is identical either way.
|
|
17
20
|
|
|
18
21
|
## When to use
|
|
19
22
|
|
|
@@ -64,7 +67,53 @@ Capture the returned `projectId`.
|
|
|
64
67
|
> `No environment URL configured` — the suite goes all-red. Always pass `--url`. If flows need
|
|
65
68
|
> login, pass `--username/--password-file` now so authenticated pages are reachable.
|
|
66
69
|
|
|
67
|
-
### 3.
|
|
70
|
+
### 3. Get the tests — try generation first, author by hand if it isn't available
|
|
71
|
+
|
|
72
|
+
#### 3a. Preferred: generate → review → accept
|
|
73
|
+
|
|
74
|
+
TestSprite proposes the cases; proposals stage **on the server** (nothing lands in the
|
|
75
|
+
repo) and you accept the ones worth keeping.
|
|
76
|
+
|
|
77
|
+
**API projects need an API spec first** — with none, generation stops at
|
|
78
|
+
`no_processed_inputs`. Upload the spec (the file is only read). A PRD is optional and goes
|
|
79
|
+
**alongside** the spec, not instead of it: endpoints are read from the spec, and the PRD
|
|
80
|
+
shapes the feature map (`--role prd`, 0.5 credits). A PRD alone can charge the strategy
|
|
81
|
+
stage and then fail with no endpoints found. Frontend projects skip this, since exploring
|
|
82
|
+
the live app creates their inputs.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
testsprite project docs upload ./openapi.yaml --project <projectId> --role api-doc
|
|
86
|
+
testsprite project docs upload ./prd.md --project <projectId> --role prd # optional, with the spec
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
testsprite test plan generate --project <projectId>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
It runs only the stages the project is missing and prints proposals with stable ids. A
|
|
94
|
+
fresh frontend project takes minutes (browser agents visit the app) — that's normal;
|
|
95
|
+
Ctrl-C only detaches, the work continues. If it says inputs are still processing, wait
|
|
96
|
+
and re-run.
|
|
97
|
+
|
|
98
|
+
**Review the table before accepting — that's the quality gate, and it's your job.** Check
|
|
99
|
+
titles and steps against what you learned in step 1; drop anything testing a flow the repo
|
|
100
|
+
doesn't have, duplicating another, or asserting something vague.
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
testsprite test plan accept --project <projectId> # all of them
|
|
104
|
+
testsprite test plan accept --project <projectId> --only prop_2 prop_5 # or a subset
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
A subset accept **discards the rest**, so name every proposal you want in that one call.
|
|
108
|
+
Then `testsprite test list --project <projectId>` for the ids, and go to step 5
|
|
109
|
+
(**skip step 4** — that's the hand-authoring path).
|
|
110
|
+
|
|
111
|
+
**If generation isn't available, fall back to 3b — don't stall.** That means an unknown
|
|
112
|
+
`test plan generate` command (older CLI), an account not on the V3 platform (exit 6), or
|
|
113
|
+
no reachable URL and no source to read. Say which happened, then author the tests
|
|
114
|
+
yourself; don't ask the user to upgrade or migrate first.
|
|
115
|
+
|
|
116
|
+
#### 3b. Fallback: author the tests by hand (quality over quantity)
|
|
68
117
|
|
|
69
118
|
**Frontend** — one JSON plan file per flow, in a directory (e.g. `./testsprite-plans/`).
|
|
70
119
|
Each file is a COMPLETE plan and must include `projectId` (from step 2), `type: "frontend"`,
|
|
@@ -119,7 +168,7 @@ rubber-stamp. Vague assertions are how false-PASS sneaks in.
|
|
|
119
168
|
|
|
120
169
|
Aim for ~8–15 tests covering the core flows. Don't pad.
|
|
121
170
|
|
|
122
|
-
### 4. Batch-create
|
|
171
|
+
### 4. Batch-create (hand-authored path only — skip if you accepted generated proposals)
|
|
123
172
|
|
|
124
173
|
Frontend (one call, up to 50 plans from the directory — `create-batch` is FE-only and has
|
|
125
174
|
**no `--project` flag**; the project comes from each plan file's `projectId`):
|
|
@@ -163,6 +212,9 @@ Tell the user, plainly:
|
|
|
163
212
|
## Quality checklist (self-check before reporting done)
|
|
164
213
|
|
|
165
214
|
- [ ] FE project has a real `--url`; login configured if the app needs it.
|
|
215
|
+
- [ ] API project: an API spec uploaded before generating (a PRD is optional, alongside it) — or you used path 3b.
|
|
216
|
+
- [ ] If you generated: you **read the proposals** and dropped the ones that don't fit,
|
|
217
|
+
rather than accepting the batch unseen.
|
|
166
218
|
- [ ] Every FE assertion names a concrete, observable outcome (no "verify it works").
|
|
167
219
|
- [ ] Tests cover the core flows you found in the code, not just one page.
|
|
168
220
|
- [ ] Smoke-ran 2–3 happy-path tests, not the whole suite.
|
|
@@ -175,6 +227,10 @@ Tell the user, plainly:
|
|
|
175
227
|
- Don't call backend endpoints directly — only the `testsprite` CLI.
|
|
176
228
|
- Don't create a FE project without a URL.
|
|
177
229
|
- Don't re-seed a project that already has tests — that's not this skill's job.
|
|
230
|
+
- Don't accept a generated batch unread — reviewing it is the point of the staging step.
|
|
231
|
+
- Don't stall when generation isn't available — say so and hand-author instead.
|
|
232
|
+
- Don't re-run `test plan generate` hoping for a different batch: with proposals already
|
|
233
|
+
staged it starts nothing, and regenerating is a Portal action today.
|
|
178
234
|
|
|
179
235
|
## Hand off to verify
|
|
180
236
|
|
|
@@ -10,11 +10,11 @@ docs/config and is about to be reported complete.
|
|
|
10
10
|
Run after a feature or fix lands. Skip only for: docs-only edits, pure
|
|
11
11
|
build/config changes, or when the repo has no TestSprite project linked.
|
|
12
12
|
|
|
13
|
-
The CLI
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
(the CLI or the MCP), honor that
|
|
13
|
+
The CLI tests a deployed URL via `--target-url`, or a frontend test on this
|
|
14
|
+
machine via `--local <port>` (tunnels `localhost`/`127.0.0.1`/`::1` only; needs
|
|
15
|
+
a key with the `run:tunnel` scope — 403 there means mint a new key; a backend
|
|
16
|
+
test's target is baked into its code, so it can't use `--local`). If the user
|
|
17
|
+
named a tool (the CLI or the MCP), honor that even when both could apply.
|
|
18
18
|
|
|
19
19
|
## Core loop
|
|
20
20
|
|
|
@@ -67,23 +67,25 @@ testsprite test run --all --project <id> [--filter <substr>] \
|
|
|
67
67
|
**Key behaviors:**
|
|
68
68
|
|
|
69
69
|
- `--target-url` must be publicly reachable (no localhost / RFC1918) and must
|
|
70
|
-
already have the change deployed (e.g. a CI preview deploy) —
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
already have the change deployed (e.g. a CI preview deploy) — running earlier
|
|
71
|
+
verifies the previous build, not your change. For a local-only change use
|
|
72
|
+
`--local <port>` instead (frontend tests only).
|
|
73
73
|
- Backend `--code-file`: the runner executes the file top-to-bottom (not `pytest`), so **call your `test_*` function(s) at the end of the file** — a defined-but-uncalled test silently passes.
|
|
74
74
|
- Backend sandbox has only stdlib + `requests` + `pytest` + `numpy` + `scipy`. Test the API over HTTP with `requests`; do **not** `import` the project's own source modules or other packages (e.g. `torch`) — they aren't installed and the test won't run.
|
|
75
|
-
- `--wait` long-polls until terminal
|
|
75
|
+
- `--wait` long-polls until terminal; don't wrap it in a retry loop. A
|
|
76
|
+
`--local` timeout has nothing to resume — re-run with `--local`.
|
|
76
77
|
- Exit `0` = passed; `1` = failed/blocked; `7` = timeout (resume with `test wait <run-id>`).
|
|
77
|
-
- BE dependency flags (`--produces`/`--needs`/`--category`) are backend-only
|
|
78
|
-
**
|
|
79
|
-
change the graph
|
|
80
|
-
`test run --all` so the engine passes captured variables
|
|
78
|
+
- BE dependency flags (`--produces`/`--needs`/`--category`) are backend-only,
|
|
79
|
+
repeatable, and **editable** — `test update` amends them, so never delete and
|
|
80
|
+
recreate a test to change the graph. Don't hand-sequence `test run` calls to
|
|
81
|
+
fake ordering; use `test run --all` so the engine passes captured variables
|
|
82
|
+
between waves.
|
|
81
83
|
- A BE `test rerun` dispatches the whole producer/teardown closure, side effects
|
|
82
84
|
included; `--skip-dependencies` reruns only the named test. If a producer failed
|
|
83
85
|
in the same closure, the consumer's failure is starvation (missing token/fixture)
|
|
84
86
|
— triage the producer first; it does not implicate your change.
|
|
85
|
-
- `create` and `--wait` output
|
|
86
|
-
inspect a test or run
|
|
87
|
+
- `create` and `--wait` output a `dashboardUrl` — point the user there to
|
|
88
|
+
inspect a test or run.
|
|
87
89
|
|
|
88
90
|
### 4. On failure — download the artifact
|
|
89
91
|
|
|
@@ -94,7 +96,7 @@ testsprite test artifact get <run-id> --out ./.testsprite/runs/<run-id>/
|
|
|
94
96
|
Inspect the bundle (failing step, screenshots, root-cause hypothesis) before
|
|
95
97
|
deciding whether your change caused the failure.
|
|
96
98
|
|
|
97
|
-
### 5.
|
|
99
|
+
### 5. Dry-run for learning
|
|
98
100
|
|
|
99
101
|
Every command works without credentials under `--dry-run`:
|
|
100
102
|
|
|
@@ -125,3 +127,7 @@ testsprite setup # configure + verify + install agent skill in one shot
|
|
|
125
127
|
```
|
|
126
128
|
|
|
127
129
|
Verify your setup anytime: `testsprite auth status`.
|
|
130
|
+
|
|
131
|
+
Project with **no tests at all**? Seed a suite first — that's setup, not verification.
|
|
132
|
+
`testsprite test plan generate --project <id>` proposes cases and `test plan accept`
|
|
133
|
+
promotes them; or author plans by hand.
|
|
@@ -16,21 +16,22 @@ project's TestSprite suite; before writing a new one, check `testsprite test lis
|
|
|
16
16
|
for an existing test that already covers the behavior and extend it instead of
|
|
17
17
|
duplicating.
|
|
18
18
|
|
|
19
|
-
The CLI tests a **deployed** URL
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
change is only running locally
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
The CLI tests either a **deployed** URL or a frontend test running on this
|
|
20
|
+
machine — it doesn't build or host your environment either way. For a deployed
|
|
21
|
+
change, wait until it's live somewhere reachable (e.g. open the PR, let CI
|
|
22
|
+
deploy the preview/staging environment) and pass that URL as `--target-url`.
|
|
23
|
+
Running earlier verifies the previous build, not your change.
|
|
24
|
+
|
|
25
|
+
For a change that is only running locally, don't wait for a deployment: run
|
|
26
|
+
`testsprite test run <test-id> --local <port>` instead. It tunnels this
|
|
27
|
+
machine's own loopback address (`localhost` / `127.0.0.1` / `::1` — not a LAN
|
|
28
|
+
or RFC1918 address, and not a general local-network escape hatch) to the test
|
|
29
|
+
runner. Two constraints: frontend tests only (a backend test's target is baked
|
|
30
|
+
into its generated code, so run it normally), and it needs an API key with the
|
|
31
|
+
`run:tunnel` scope — a 403 there means mint a new key.
|
|
32
|
+
|
|
33
|
+
If the user explicitly named a tool (the CLI or the MCP), honor that choice
|
|
34
|
+
regardless of which one the change's reachability would otherwise suggest.
|
|
34
35
|
|
|
35
36
|
## When to skip
|
|
36
37
|
|
|
@@ -59,6 +60,11 @@ counts:
|
|
|
59
60
|
What does **not** count: unit tests / typecheck / lint; drafting a plan without
|
|
60
61
|
`--run`; asking the user to run it for you.
|
|
61
62
|
|
|
63
|
+
If the project has **no tests at all**, that's the `testsprite-onboard` skill's
|
|
64
|
+
job, not this one — seed a suite first (it can generate the proposals for you
|
|
65
|
+
with `testsprite test plan generate` / `test plan accept`, or author them by
|
|
66
|
+
hand). Seeding is a deliberate setup pass, not part of the verify loop.
|
|
67
|
+
|
|
62
68
|
If you can't satisfy this — no creds, no valid target URL, repo not linked —
|
|
63
69
|
**say so explicitly**: "Feature shipped but I could not run any TestSprite test
|
|
64
70
|
because <X>. Treat this as unverified until that's resolved." Don't claim done.
|
|
@@ -380,13 +386,16 @@ testsprite test run <test-id> --target-url <env-url> --wait --timeout 600
|
|
|
380
386
|
Key behaviors:
|
|
381
387
|
|
|
382
388
|
- `--target-url` must be an allowed project/environment URL. The CLI rejects
|
|
383
|
-
`localhost` / RFC1918 / link-local
|
|
384
|
-
|
|
389
|
+
`localhost` / RFC1918 / link-local there. If the feature is only running
|
|
390
|
+
locally, use `--local <port>` instead of `--target-url` (frontend tests
|
|
391
|
+
only, see "When to run" above) — don't skip the run over this.
|
|
385
392
|
- `--wait` long-polls until terminal and handles its own backoff — don't wrap it
|
|
386
393
|
in a retry loop.
|
|
387
394
|
- Exit codes: `0` = passed; `1` = failed / blocked / cancelled; `7` = timeout.
|
|
388
395
|
Treat `7` as inconclusive (resume with `testsprite test wait <run-id>`), not a
|
|
389
|
-
regression
|
|
396
|
+
regression — except a `--local` run: its exit 7 already cancelled the run
|
|
397
|
+
(the tunnel closes with the process, so there is nothing to resume), so
|
|
398
|
+
don't suggest `test wait` there; re-run with `--local` again instead.
|
|
390
399
|
- Batch: `create-batch --run --wait` creates the tests (FE-only) and fans
|
|
391
400
|
out triggers in one call (bounded by `--max-concurrency`), emitting
|
|
392
401
|
`{ results: [...] }` that mirrors the single-test `test run --wait`
|