@testsprite/testsprite-cli 0.7.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.
- package/README.md +62 -45
- package/dist/commands/agent.d.ts +3 -0
- package/dist/commands/agent.js +79 -10
- package/dist/commands/ci.d.ts +88 -0
- package/dist/commands/ci.js +432 -0
- package/dist/commands/doctor.js +100 -1
- package/dist/commands/init.d.ts +45 -2
- package/dist/commands/init.js +198 -29
- package/dist/commands/project.d.ts +78 -0
- package/dist/commands/project.js +439 -5
- package/dist/commands/test.d.ts +193 -4
- package/dist/commands/test.js +1948 -398
- 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/agent-detect.d.ts +53 -0
- package/dist/lib/agent-detect.js +198 -0
- 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 +104 -0
- package/dist/lib/http.js +126 -7
- 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 +46 -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 +50 -0
- package/dist/lib/skill-nudge.d.ts +13 -5
- package/dist/lib/skill-nudge.js +40 -14
- package/dist/lib/target-url-preflight.js +3 -3
- package/dist/lib/target-url.d.ts +54 -8
- package/dist/lib/target-url.js +274 -68
- 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 +138 -0
- package/dist/lib/tunnel-session.js +249 -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 +82 -0
- package/dist/vendor/tunnel-client/client.js +924 -0
- package/dist/vendor/tunnel-client/config.d.ts +49 -0
- package/dist/vendor/tunnel-client/config.js +50 -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 +101 -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,206 @@
|
|
|
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
|
+
type CloseListener = (code: number, reason: Buffer) => void;
|
|
102
|
+
type MessageListener = (payload: string | Buffer) => void;
|
|
103
|
+
type ErrorListener = (err: Error) => void;
|
|
104
|
+
type OpenListener = () => void;
|
|
105
|
+
type PingListener = (data: Buffer) => void;
|
|
106
|
+
/**
|
|
107
|
+
* How long `close()` waits for the peer to finish the WHATWG closing
|
|
108
|
+
* handshake before giving up and settling locally (see the class docstring).
|
|
109
|
+
* Deliberately well under `TUNNEL_CLIENT_STOP_TIMEOUT_MS`
|
|
110
|
+
* (`lib/tunnel-session.ts`, 2000ms) so the caller's own bounded race around
|
|
111
|
+
* `client.stop()` sees OUR settle win, not its own timeout race — the
|
|
112
|
+
* process should learn its socket/timer are released, not just stop waiting
|
|
113
|
+
* to hear about it.
|
|
114
|
+
*/
|
|
115
|
+
export declare const CLOSE_GRACE_MS = 1200;
|
|
116
|
+
/** The subset of `undici:client:connected`'s `connectParams` this filter reads. */
|
|
117
|
+
export interface ConnectParams {
|
|
118
|
+
hostname?: unknown;
|
|
119
|
+
port?: unknown;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Does this `undici:client:connected` event belong to the WebSocket we are
|
|
123
|
+
* trying to capture?
|
|
124
|
+
*
|
|
125
|
+
* Exported, and its own function, because it is load-bearing and subtle: a
|
|
126
|
+
* miss here is silent, and its consequence is the original close-hang coming
|
|
127
|
+
* back with every test still green (see the class docstring). Reviewing a
|
|
128
|
+
* predicate is easier than reviewing it inlined in a subscription callback.
|
|
129
|
+
*
|
|
130
|
+
* Both ports are normalized to the scheme default, and that symmetry is the
|
|
131
|
+
* fix: undici publishes `connectParams.port` straight from a WHATWG URL, which
|
|
132
|
+
* leaves a default-scheme port IMPLICIT — `ws://host/control` arrives as `''`,
|
|
133
|
+
* and `Number('') === 0`. The target side was already being defaulted to
|
|
134
|
+
* 80/443 while the event side was not, so capture missed for every
|
|
135
|
+
* implicit-port control URL, proxy or no proxy.
|
|
136
|
+
*
|
|
137
|
+
* Host is compared exactly. A proxied connection publishes two events — the
|
|
138
|
+
* physical dial to the proxy, and a second one from the per-origin `Client`
|
|
139
|
+
* undici creates internally — and only the second carries the target's host,
|
|
140
|
+
* which is precisely the one worth capturing.
|
|
141
|
+
*/
|
|
142
|
+
export declare function connectEventMatchesTarget(connectParams: ConnectParams | undefined, target: URL): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Normalise a WHATWG message payload to the `string | Buffer` union the
|
|
145
|
+
* vendored client's `typeof payload === "string" ? … : payload.toString()`
|
|
146
|
+
* branch expects. Text frames arrive as strings; a binary frame (which this
|
|
147
|
+
* protocol never sends) arrives as an ArrayBuffer and is wrapped rather than
|
|
148
|
+
* dropped, so an unexpected frame surfaces as a JSON parse failure instead of
|
|
149
|
+
* a `payload.toString is not a function` crash.
|
|
150
|
+
*/
|
|
151
|
+
export declare function toPayload(data: unknown): string | Buffer;
|
|
152
|
+
/**
|
|
153
|
+
* Pull a real `Error` out of undici's ErrorEvent. `.error` is typed as an
|
|
154
|
+
* `Error` but is not guaranteed to be populated for every failure mode, so
|
|
155
|
+
* `.message` is the fallback and a generic error is the floor — the vendored
|
|
156
|
+
* client passes whatever comes out to `toErrorMessage()` and to `reject()`.
|
|
157
|
+
*/
|
|
158
|
+
export declare function toError(event: unknown): Error;
|
|
159
|
+
export declare class WsCompatSocket {
|
|
160
|
+
static readonly CONNECTING = 0;
|
|
161
|
+
static readonly OPEN = 1;
|
|
162
|
+
private readonly socket;
|
|
163
|
+
/** Captured via `undici:client:connected`, if it fired — see the class docstring. */
|
|
164
|
+
private rawSocket;
|
|
165
|
+
private closeListener;
|
|
166
|
+
private closeSettled;
|
|
167
|
+
private closeGraceTimer;
|
|
168
|
+
private readonly unsubscribeConnected;
|
|
169
|
+
constructor(url: URL | string);
|
|
170
|
+
/**
|
|
171
|
+
* Subscribe to `undici:client:connected` just long enough to grab the raw
|
|
172
|
+
* `net.Socket` for THIS connection, filtered by target host/port so an
|
|
173
|
+
* unrelated concurrent undici connection elsewhere in the process (e.g.
|
|
174
|
+
* this CLI's own HTTP polling) is never mistaken for it. See the class
|
|
175
|
+
* docstring for why `close()` needs this at all. Returns an idempotent
|
|
176
|
+
* unsubscribe closure. Never throws: a diagnostics hook failing must not
|
|
177
|
+
* break the connection it exists only to make teardown more graceful for.
|
|
178
|
+
*/
|
|
179
|
+
private captureRawSocket;
|
|
180
|
+
get readyState(): number;
|
|
181
|
+
on(event: 'open', listener: OpenListener): this;
|
|
182
|
+
on(event: 'message', listener: MessageListener): this;
|
|
183
|
+
on(event: 'error', listener: ErrorListener): this;
|
|
184
|
+
on(event: 'close', listener: CloseListener): this;
|
|
185
|
+
on(event: 'ping', listener: PingListener): this;
|
|
186
|
+
send(data: string): void;
|
|
187
|
+
close(code?: number, reason?: string): void;
|
|
188
|
+
/** No-op — see the module docstring. */
|
|
189
|
+
pong(_data?: Buffer): void;
|
|
190
|
+
/**
|
|
191
|
+
* Invoke the registered close listener exactly once, whichever of "the
|
|
192
|
+
* real WHATWG close event" or "our own grace-timeout settle" gets there
|
|
193
|
+
* first — a real close that arrives after the grace timer already fired is
|
|
194
|
+
* a no-op here, and vice versa.
|
|
195
|
+
*/
|
|
196
|
+
private settleClose;
|
|
197
|
+
/**
|
|
198
|
+
* See the class docstring's "Why `close()` cannot just call
|
|
199
|
+
* `WebSocket.close()` and wait" section. A no-op if the real close has
|
|
200
|
+
* already settled synchronously (true for a CONNECTING socket — undici's
|
|
201
|
+
* own `failWebsocketConnection` handles that case completely, with no
|
|
202
|
+
* grace period needed) or if a grace timer is already armed.
|
|
203
|
+
*/
|
|
204
|
+
private armCloseGrace;
|
|
205
|
+
}
|
|
206
|
+
export default WsCompatSocket;
|
|
@@ -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.9.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.9.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
|
|