@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
package/dist/lib/target-url.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* CLI-side pre-flight guard for `--target-url`.
|
|
3
3
|
*
|
|
4
4
|
* Defense-in-depth: the backend is the trust boundary and performs DNS
|
|
5
|
-
* resolution. `assertNotLocal` below does **
|
|
5
|
+
* resolution. `assertNotLocal` below does **literal-only** checks
|
|
6
6
|
* to give a fast, friendly error before sending the request — it cannot by
|
|
7
7
|
* itself detect DNS rebinding (a public hostname that resolves to a private
|
|
8
8
|
* IP). That gap is closed one layer up: `target-url-preflight.ts` reuses
|
|
@@ -12,17 +12,42 @@
|
|
|
12
12
|
*
|
|
13
13
|
* CLI-side target-url guard (exit 5 on any rejection):
|
|
14
14
|
* - Reject non-http(s) schemes
|
|
15
|
-
* - Reject `localhost`, `127.0.0.0/8`, `0.0.0.0`, and IPv6 loopback/unspecified (`::1`, `::`)
|
|
15
|
+
* - Reject `localhost`, `127.0.0.0/8`, `0.0.0.0/8`, and IPv6 loopback/unspecified (`::1`, `::`)
|
|
16
16
|
* - Reject `169.254.0.0/16` link-local and the `169.254.169.254` metadata address
|
|
17
17
|
* - Reject RFC1918 literal IPv4 (10.x, 172.16-31.x, 192.168.x)
|
|
18
|
-
* - Reject
|
|
18
|
+
* - Reject carrier-grade NAT (`100.64.0.0/10`), multicast (`224.0.0.0/4`),
|
|
19
|
+
* and class E / limited broadcast (`240.0.0.0/4`)
|
|
20
|
+
* - Decode and re-classify the low 32 bits of standard embedded-IPv4 forms:
|
|
21
|
+
* IPv4-mapped/translated, RFC 6052 NAT64 (`64:ff9b::/96`), and deprecated
|
|
22
|
+
* IPv4-compatible (`::/96`); public embedded IPv4 addresses stay allowed
|
|
23
|
+
* - Reject RFC 8215's NAT64 local-use range (`64:ff9b:1::/48`) wholesale
|
|
24
|
+
* - Reject IPv6 link-local (`fe80::/10`), unique-local (`fc00::/7`), and
|
|
25
|
+
* deprecated site-local (`fec0::/10`)
|
|
19
26
|
*/
|
|
27
|
+
import * as net from 'node:net';
|
|
20
28
|
import { ApiError } from './errors.js';
|
|
21
|
-
|
|
29
|
+
// `--local-host` accepts EXACTLY `localhost`, `127.0.0.1`, `::1` (mirroring
|
|
30
|
+
// the server's `isLoopbackString`) — not "anything loopback-shaped". This
|
|
31
|
+
// hint is only honest for those three literal hosts (`0.0.0.0` and `::`
|
|
32
|
+
// join them below because binding to the unspecified address also answers
|
|
33
|
+
// on `127.0.0.1`/`::1`, so `--local`'s default dial reaches it) — NOT for
|
|
34
|
+
// the rest of `127.0.0.0/8`, which `--local` cannot dial by name at all. See
|
|
35
|
+
// `'loopback-other'` below for that distinction.
|
|
36
|
+
const LOCAL_DEV_HINT = "This looks like a local-dev target. Run it with `testsprite test run <test-id> --local <port>` instead — it tunnels this machine's loopback address to the test runner (frontend tests only; requires an API key with the `run:tunnel` scope).";
|
|
37
|
+
// Private, reserved, link-local, and metadata addresses are network-reachable from
|
|
38
|
+
// the caller's own machine in general (a LAN or VPN address usually answers)
|
|
39
|
+
// — what is actually true, and all this hint claims, is that TestSprite's
|
|
40
|
+
// execution modes cannot target them: `--target-url` refuses them outright,
|
|
41
|
+
// and `--local`'s tunnel only ever dials `localhost` / `127.0.0.1` / `::1`
|
|
42
|
+
// on THIS machine, never a LAN/VPC address. Embedded IPv4 addresses inherit
|
|
43
|
+
// this hint only after their decoded IPv4 address lands in this class.
|
|
44
|
+
const PRIVATE_NETWORK_HINT = 'This is a private/reserved network address (private, link-local, multicast, or metadata). ' +
|
|
45
|
+
'TestSprite cannot use it as --target-url, and --local cannot tunnel it either — --local only ' +
|
|
46
|
+
'reaches localhost, 127.0.0.1, or ::1 on this machine.';
|
|
22
47
|
/**
|
|
23
48
|
* Throws a local `VALIDATION_ERROR` (exit 5) when `rawUrl` is a
|
|
24
|
-
* disallowed target — localhost
|
|
25
|
-
*
|
|
49
|
+
* disallowed target — localhost or a private/reserved literal IP. Also rejects
|
|
50
|
+
* non-http(s) schemes.
|
|
26
51
|
*
|
|
27
52
|
* Silently returns on allowed URLs.
|
|
28
53
|
*/
|
|
@@ -48,19 +73,39 @@ export function assertNotLocal(rawUrl) {
|
|
|
48
73
|
const host = parsed.hostname.toLowerCase().replace(/\.$/, '');
|
|
49
74
|
// 'localhost' is a name, not an IP literal, so it sits outside
|
|
50
75
|
// `disallowedIpReason` below (which classifies IPv4/IPv6 address forms).
|
|
76
|
+
// It is also always loopback — the same class `--local` can reach.
|
|
51
77
|
if (host === 'localhost') {
|
|
52
78
|
throw localTargetError('target-url', 'localhost targets are not allowed', LOCAL_DEV_HINT);
|
|
53
79
|
}
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
throw localTargetError('target-url', reason,
|
|
80
|
+
const disallowed = disallowedIpReason(host);
|
|
81
|
+
if (disallowed !== undefined) {
|
|
82
|
+
throw localTargetError('target-url', disallowed.reason, hintFor(disallowed.hintKind));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Map a classification's `hintKind` to the hint text `assertNotLocal` attaches
|
|
87
|
+
* to the rejection — or no hint at all for `'loopback-other'`/`'undecided'`.
|
|
88
|
+
* Kept as its own function so the four-way mapping is a single, testable
|
|
89
|
+
* spot rather than a nested ternary repeated wherever a classification is
|
|
90
|
+
* consumed.
|
|
91
|
+
*/
|
|
92
|
+
function hintFor(hintKind) {
|
|
93
|
+
switch (hintKind) {
|
|
94
|
+
case 'loopback':
|
|
95
|
+
return LOCAL_DEV_HINT;
|
|
96
|
+
case 'loopback-other':
|
|
97
|
+
return undefined;
|
|
98
|
+
case 'private':
|
|
99
|
+
return PRIVATE_NETWORK_HINT;
|
|
100
|
+
case 'undecided':
|
|
101
|
+
return undefined;
|
|
57
102
|
}
|
|
58
103
|
}
|
|
59
104
|
/**
|
|
60
105
|
* Classify a bare IP-address literal — IPv4 dotted form, or IPv6 optionally
|
|
61
106
|
* wrapped in the `[...]` bracket notation `URL.hostname` uses — against the
|
|
62
107
|
* private/loopback/link-local/metadata blocklist. Returns the disallowed
|
|
63
|
-
*
|
|
108
|
+
* classification, or `undefined` when the address is allowed.
|
|
64
109
|
*
|
|
65
110
|
* This is the single source of truth for the range list: `assertNotLocal`
|
|
66
111
|
* calls it for the literal `--target-url` string above, and the reachability
|
|
@@ -78,75 +123,219 @@ export function disallowedIpReason(host) {
|
|
|
78
123
|
// address family explicitly. A DNS-resolved IPv6 address arrives
|
|
79
124
|
// unbracketed already; stripping is a no-op for that shape.
|
|
80
125
|
const bare = host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host;
|
|
81
|
-
|
|
82
|
-
|
|
126
|
+
const addressFamily = net.isIP(bare);
|
|
127
|
+
if (addressFamily === 6) {
|
|
128
|
+
return disallowedIpv6Reason(bare.toLowerCase());
|
|
129
|
+
}
|
|
130
|
+
return addressFamily === 4 ? disallowedIpv4Reason(bare) : undefined;
|
|
131
|
+
}
|
|
132
|
+
function disallowedIpv4Reason(address) {
|
|
133
|
+
// Unspecified — binds every interface, including loopback.
|
|
134
|
+
if (address === '0.0.0.0') {
|
|
135
|
+
return { reason: 'localhost targets are not allowed', hintKind: 'loopback' };
|
|
136
|
+
}
|
|
137
|
+
// Only the literal 127.0.0.1 is in `--local-host`'s exact accepted set.
|
|
138
|
+
if (ipv4LoopbackBlocklist.check(address, 'ipv4')) {
|
|
139
|
+
return {
|
|
140
|
+
reason: 'loopback addresses are not allowed',
|
|
141
|
+
hintKind: address === '127.0.0.1' ? 'loopback' : 'loopback-other',
|
|
142
|
+
};
|
|
83
143
|
}
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
144
|
+
// AWS instance-metadata service. Keep the specific diagnostic ahead of the
|
|
145
|
+
// enclosing link-local subnet rule.
|
|
146
|
+
if (address === '169.254.169.254') {
|
|
147
|
+
return {
|
|
148
|
+
reason: '169.254.169.254 (AWS metadata service) is not allowed',
|
|
149
|
+
hintKind: 'private',
|
|
150
|
+
};
|
|
87
151
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return 'loopback addresses are not allowed';
|
|
152
|
+
if (ipv4ThisNetworkBlocklist.check(address, 'ipv4')) {
|
|
153
|
+
return { reason: 'reserved "this network" addresses are not allowed', hintKind: 'private' };
|
|
91
154
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return '169.254.169.254 (AWS metadata service) is not allowed';
|
|
155
|
+
if (ipv4LinkLocalBlocklist.check(address, 'ipv4')) {
|
|
156
|
+
return { reason: 'link-local addresses are not allowed', hintKind: 'private' };
|
|
95
157
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return 'link-local addresses are not allowed';
|
|
158
|
+
if (ipv4Rfc1918Blocklist.check(address, 'ipv4')) {
|
|
159
|
+
return { reason: 'private/RFC1918 addresses are not allowed', hintKind: 'private' };
|
|
99
160
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
161
|
+
if (ipv4CgnatBlocklist.check(address, 'ipv4')) {
|
|
162
|
+
return { reason: 'carrier-grade NAT addresses are not allowed', hintKind: 'private' };
|
|
163
|
+
}
|
|
164
|
+
if (ipv4MulticastBlocklist.check(address, 'ipv4')) {
|
|
165
|
+
return { reason: 'multicast addresses are not allowed', hintKind: 'private' };
|
|
166
|
+
}
|
|
167
|
+
if (ipv4ClassEBlocklist.check(address, 'ipv4')) {
|
|
168
|
+
return { reason: 'reserved/class E addresses are not allowed', hintKind: 'private' };
|
|
103
169
|
}
|
|
104
170
|
return undefined;
|
|
105
171
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
172
|
+
/**
|
|
173
|
+
* Standard IPv6 forms that encode a literal IPv4 address in their low 32 bits —
|
|
174
|
+
* IPv4-mapped (`::ffff:a.b.c.d`), IPv4-translated (`::ffff:0:a.b.c.d`),
|
|
175
|
+
* RFC 6052's well-known NAT64 prefix (`64:ff9b::/96`), and IPv4-compatible
|
|
176
|
+
* (deprecated, `::a.b.c.d`). RFC 8215's local-use `64:ff9b:1::/48` is a
|
|
177
|
+
* separate blanket refusal because its embedded address is not in the low
|
|
178
|
+
* 32 bits.
|
|
179
|
+
*
|
|
180
|
+
* `net.BlockList` — binary subnet matching, not a per-spelling regex or
|
|
181
|
+
* `startsWith` — is what makes the spelling question go away entirely: the
|
|
182
|
+
* WHATWG URL parser COMPRESSES some of these forms
|
|
183
|
+
* (`0:0:0:0:0:ffff:a9fe:a9fe` → `::ffff:a9fe:a9fe`) while it PRESERVES others
|
|
184
|
+
* verbatim (`::ffff:0:a9fe:a9fe` stays exactly as typed), so a check tuned to
|
|
185
|
+
* one textual shape reliably misses the other — which is exactly how
|
|
186
|
+
* `64:ff9b::a9fe:a9fe` (NAT64-encoded AWS metadata) once reached the network
|
|
187
|
+
* unrejected. Binary matching also holds for NON-canonical input, which a
|
|
188
|
+
* `startsWith` check on a canonical-form assumption does not.
|
|
189
|
+
*
|
|
190
|
+
* Each class keeps its own list so it can be decoded only where its prefix
|
|
191
|
+
* defines the low 32 bits as IPv4. The three are checked mapped → NAT64 →
|
|
192
|
+
* compatible, preserving the established class precedence.
|
|
193
|
+
*
|
|
194
|
+
* This is the SAME primitive `src/vendor/tunnel-client/client.ts`'s
|
|
195
|
+
* `blockedTargetReason` already uses for the identical problem (see its
|
|
196
|
+
* VENDOR.md deltas #7/#10) — the two host classifiers in this repo now
|
|
197
|
+
* share one mechanism instead of two independently maintained spelling
|
|
198
|
+
* lists, so a future NAT64-shaped bypass can't reopen only one of them.
|
|
199
|
+
*
|
|
200
|
+
* The matched `/96` forms are decoded from their final two 16-bit groups and
|
|
201
|
+
* re-classified through the IPv4 blocklists. This makes an embedded public
|
|
202
|
+
* address public while preserving the decoded address's exact hint class.
|
|
203
|
+
*/
|
|
204
|
+
const IPV4_MAPPED_SUBNETS = [
|
|
205
|
+
// Exact `/96` prefixes whose canonical `::` head contains only zero/ffff
|
|
206
|
+
// groups. Keeping them exact avoids the old `/80` rule's false positives on
|
|
207
|
+
// a non-embedded group while covering mapped, translated, and repeated-ffff
|
|
208
|
+
// spellings on the same binary value seen by URL and DNS paths.
|
|
209
|
+
['0:0:0:0:0:ffff:0:0', 96],
|
|
210
|
+
['0:0:0:0:ffff:0:0:0', 96],
|
|
211
|
+
['0:0:0:0:ffff:ffff:0:0', 96],
|
|
212
|
+
['0:0:0:ffff:0:0:0:0', 96],
|
|
213
|
+
['0:0:0:ffff:0:ffff:0:0', 96],
|
|
214
|
+
['0:0:0:ffff:ffff:0:0:0', 96],
|
|
215
|
+
['0:0:0:ffff:ffff:ffff:0:0', 96],
|
|
216
|
+
['0:0:ffff:0:0:ffff:0:0', 96],
|
|
217
|
+
['0:0:ffff:0:ffff:0:0:0', 96],
|
|
218
|
+
['0:0:ffff:0:ffff:ffff:0:0', 96],
|
|
219
|
+
['0:0:ffff:ffff:0:0:0:0', 96],
|
|
220
|
+
['0:0:ffff:ffff:0:ffff:0:0', 96],
|
|
221
|
+
['0:0:ffff:ffff:ffff:0:0:0', 96],
|
|
222
|
+
['0:0:ffff:ffff:ffff:ffff:0:0', 96],
|
|
223
|
+
];
|
|
224
|
+
/**
|
|
225
|
+
* The RFC 6052 well-known prefix stores IPv4 in the final 32 bits, so it can
|
|
226
|
+
* be decoded. RFC 8215 local-use has a different bit layout and stays a
|
|
227
|
+
* separate, undecoded `/48` blanket refusal.
|
|
228
|
+
*/
|
|
229
|
+
const NAT64_SUBNETS = [['64:ff9b::', 96]];
|
|
230
|
+
const NAT64_LOCAL_USE_SUBNETS = [['64:ff9b:1::', 48]];
|
|
231
|
+
/**
|
|
232
|
+
* Deprecated IPv4-compatible addresses use `::/96`; a broader `::/32` would
|
|
233
|
+
* read genuine IPv6 interface bits as IPv4 and reject targets the backend
|
|
234
|
+
* accepts. `::` and `::1` are exact-matched before this list is consulted.
|
|
235
|
+
*/
|
|
236
|
+
const IPV4_COMPATIBLE_SUBNETS = [['::', 96]];
|
|
237
|
+
function blocklistOf(subnets, family) {
|
|
238
|
+
const list = new net.BlockList();
|
|
239
|
+
for (const [network, prefix] of subnets) {
|
|
240
|
+
list.addSubnet(network, prefix, family);
|
|
241
|
+
}
|
|
242
|
+
return list;
|
|
243
|
+
}
|
|
244
|
+
const ipv4ThisNetworkBlocklist = blocklistOf([['0.0.0.0', 8]], 'ipv4');
|
|
245
|
+
const ipv4LoopbackBlocklist = blocklistOf([['127.0.0.0', 8]], 'ipv4');
|
|
246
|
+
const ipv4Rfc1918Blocklist = blocklistOf([
|
|
247
|
+
['10.0.0.0', 8],
|
|
248
|
+
['172.16.0.0', 12],
|
|
249
|
+
['192.168.0.0', 16],
|
|
250
|
+
], 'ipv4');
|
|
251
|
+
const ipv4CgnatBlocklist = blocklistOf([['100.64.0.0', 10]], 'ipv4');
|
|
252
|
+
const ipv4LinkLocalBlocklist = blocklistOf([['169.254.0.0', 16]], 'ipv4');
|
|
253
|
+
const ipv4MulticastBlocklist = blocklistOf([['224.0.0.0', 4]], 'ipv4');
|
|
254
|
+
const ipv4ClassEBlocklist = blocklistOf([['240.0.0.0', 4]], 'ipv4');
|
|
255
|
+
const ipv4MappedBlocklist = blocklistOf(IPV4_MAPPED_SUBNETS, 'ipv6');
|
|
256
|
+
const nat64Blocklist = blocklistOf(NAT64_SUBNETS, 'ipv6');
|
|
257
|
+
const nat64LocalUseBlocklist = blocklistOf(NAT64_LOCAL_USE_SUBNETS, 'ipv6');
|
|
258
|
+
const ipv4CompatibleBlocklist = blocklistOf(IPV4_COMPATIBLE_SUBNETS, 'ipv6');
|
|
259
|
+
const ipv6LinkLocalBlocklist = blocklistOf([['fe80::', 10]], 'ipv6');
|
|
260
|
+
const ipv6UniqueLocalBlocklist = blocklistOf([['fc00::', 7]], 'ipv6');
|
|
261
|
+
const ipv6SiteLocalBlocklist = blocklistOf([['fec0::', 10]], 'ipv6');
|
|
262
|
+
function decodeLow32BitsAsIpv4(address) {
|
|
263
|
+
const groups = address.split(':');
|
|
264
|
+
const last = groups.at(-1);
|
|
265
|
+
if (last === undefined)
|
|
266
|
+
return undefined;
|
|
267
|
+
// A DNS result can preserve the human-written dotted tail even though the
|
|
268
|
+
// WHATWG URL path canonicalises it to two hex groups.
|
|
269
|
+
if (net.isIP(last) === 4)
|
|
270
|
+
return last;
|
|
271
|
+
const secondLast = groups.at(-2);
|
|
272
|
+
if (secondLast === undefined)
|
|
273
|
+
return undefined;
|
|
274
|
+
const high = Number.parseInt(secondLast, 16);
|
|
275
|
+
const low = Number.parseInt(last, 16);
|
|
276
|
+
if (!Number.isInteger(high) || !Number.isInteger(low))
|
|
277
|
+
return undefined;
|
|
278
|
+
return `${(high >> 8) & 0xff}.${high & 0xff}.${(low >> 8) & 0xff}.${low & 0xff}`;
|
|
279
|
+
}
|
|
280
|
+
function reclassifyEmbeddedIpv4(address, label) {
|
|
281
|
+
const decoded = decodeLow32BitsAsIpv4(address);
|
|
282
|
+
if (decoded === undefined) {
|
|
283
|
+
return {
|
|
284
|
+
reason: `${label} address could not be decoded safely`,
|
|
285
|
+
hintKind: 'undecided',
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const decodedClassification = disallowedIpv4Reason(decoded);
|
|
289
|
+
if (decodedClassification === undefined)
|
|
290
|
+
return undefined;
|
|
291
|
+
return {
|
|
292
|
+
reason: `${label} address embeds disallowed IPv4 address ${decoded}: ${decodedClassification.reason}`,
|
|
293
|
+
hintKind: decodedClassification.hintKind,
|
|
294
|
+
};
|
|
121
295
|
}
|
|
122
296
|
/**
|
|
123
297
|
* Classify disallowed IPv6 literals: loopback (`::1`), unspecified (`::`),
|
|
124
|
-
* IPv4
|
|
125
|
-
* (`
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* The IPv4-mapped class is rejected wholesale rather than decoding the
|
|
130
|
-
* embedded v4 address: no legitimate target is expressed as a mapped
|
|
131
|
-
* literal, and the hex-normalized form (`::ffff:7f00:1`) is error-prone to
|
|
132
|
-
* decode. This closes the `http://[::ffff:127.0.0.1]` SSRF-guard bypass.
|
|
298
|
+
* the embedded-IPv4 family (see {@link IPV4_MAPPED_SUBNETS}'s doc comment),
|
|
299
|
+
* link-local (`fe80::/10`), unique-local (`fc00::/7`), and deprecated
|
|
300
|
+
* site-local (`fec0::/10`). `inner` is the
|
|
301
|
+
* bracket-stripped, already-lowercased host — `disallowedIpReason` lowercases
|
|
302
|
+
* it on the way in rather than trusting every caller to.
|
|
133
303
|
*/
|
|
134
304
|
function disallowedIpv6Reason(inner) {
|
|
135
305
|
// Loopback (::1) and unspecified (::).
|
|
136
306
|
if (inner === '::1' || inner === '::') {
|
|
137
|
-
return 'localhost targets are not allowed';
|
|
307
|
+
return { reason: 'localhost targets are not allowed', hintKind: 'loopback' };
|
|
308
|
+
}
|
|
309
|
+
// Embedded-IPv4 family, checked mapped → NAT64 → compatible. Standard /96
|
|
310
|
+
// forms inherit the decoded IPv4 classification; RFC 8215 local-use stays
|
|
311
|
+
// wholesale and undecided because its embedded address has a different bit
|
|
312
|
+
// position.
|
|
313
|
+
if (ipv4MappedBlocklist.check(inner, 'ipv6')) {
|
|
314
|
+
return reclassifyEmbeddedIpv4(inner, 'IPv4-mapped/translated IPv6');
|
|
315
|
+
}
|
|
316
|
+
if (nat64Blocklist.check(inner, 'ipv6')) {
|
|
317
|
+
return reclassifyEmbeddedIpv4(inner, 'NAT64-translated IPv6');
|
|
318
|
+
}
|
|
319
|
+
if (nat64LocalUseBlocklist.check(inner, 'ipv6')) {
|
|
320
|
+
return {
|
|
321
|
+
reason: 'NAT64 local-use addresses are not allowed',
|
|
322
|
+
hintKind: 'undecided',
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (ipv4CompatibleBlocklist.check(inner, 'ipv6')) {
|
|
326
|
+
return reclassifyEmbeddedIpv4(inner, 'IPv4-compatible/deprecated IPv6');
|
|
138
327
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return 'IPv4-mapped IPv6 addresses are not allowed; use the IPv4 form or a hostname';
|
|
328
|
+
if (ipv6LinkLocalBlocklist.check(inner, 'ipv6')) {
|
|
329
|
+
return { reason: 'link-local addresses are not allowed', hintKind: 'private' };
|
|
142
330
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return 'link-local addresses are not allowed';
|
|
331
|
+
if (ipv6UniqueLocalBlocklist.check(inner, 'ipv6')) {
|
|
332
|
+
return { reason: 'unique-local (private) addresses are not allowed', hintKind: 'private' };
|
|
146
333
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
334
|
+
if (ipv6SiteLocalBlocklist.check(inner, 'ipv6')) {
|
|
335
|
+
return {
|
|
336
|
+
reason: 'site-local (deprecated private) addresses are not allowed',
|
|
337
|
+
hintKind: 'private',
|
|
338
|
+
};
|
|
150
339
|
}
|
|
151
340
|
return undefined;
|
|
152
341
|
}
|
package/dist/lib/telemetry.d.ts
CHANGED
|
@@ -19,6 +19,15 @@ export interface TelemetryOutcomeInput {
|
|
|
19
19
|
endpointUrl?: string;
|
|
20
20
|
output?: string;
|
|
21
21
|
dryRun?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* True when the invocation requested a local tunnel target (`test run
|
|
24
|
+
* --local <port>`) — the flag's mere presence, never its port number or
|
|
25
|
+
* host. Reported regardless of outcome, including a zero-network refusal
|
|
26
|
+
* (dead port, `--local` combined with an incompatible flag): those are
|
|
27
|
+
* exactly the attempts nothing server-side ever sees, which is why this
|
|
28
|
+
* field is not redundant with a backend-side mint/attach analytics event.
|
|
29
|
+
*/
|
|
30
|
+
local?: boolean;
|
|
22
31
|
}
|
|
23
32
|
export interface TelemetryDeps {
|
|
24
33
|
env?: NodeJS.ProcessEnv;
|
|
@@ -51,6 +60,8 @@ export interface TelemetryEvent {
|
|
|
51
60
|
nodeVersion?: string;
|
|
52
61
|
output?: string;
|
|
53
62
|
ci?: boolean;
|
|
63
|
+
/** Present (always `true`) only for a `test run --local` invocation; absent otherwise. */
|
|
64
|
+
local?: boolean;
|
|
54
65
|
}
|
|
55
66
|
/**
|
|
56
67
|
* Map a thrown CLI error to its telemetry disposition — mirrors the exit-code
|
package/dist/lib/telemetry.js
CHANGED
|
@@ -88,6 +88,7 @@ export function buildTelemetryEvent(input, env, isTTY) {
|
|
|
88
88
|
nodeVersion: process.versions.node,
|
|
89
89
|
...(input.output === 'json' || input.output === 'text' ? { output: input.output } : {}),
|
|
90
90
|
ci: isTruthyEnv(env.CI) || !isTTY,
|
|
91
|
+
...(input.local ? { local: true } : {}),
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
/**
|
package/dist/lib/ticker.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export interface Ticker {
|
|
|
25
25
|
* doesn't run into the result block). No-op on non-TTY.
|
|
26
26
|
*/
|
|
27
27
|
finalize(line?: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* True only when `update()` redraws the SAME terminal line (TTY, ANSI
|
|
30
|
+
* allowed). False on a non-TTY (updates are no-ops) and under NO_COLOR
|
|
31
|
+
* (every update prints a new line). The one signal a between-polls
|
|
32
|
+
* refresher may key on — re-deriving it from process globals elsewhere
|
|
33
|
+
* is how the two decisions drift apart.
|
|
34
|
+
*/
|
|
35
|
+
readonly redrawsInPlace: boolean;
|
|
28
36
|
}
|
|
29
37
|
/**
|
|
30
38
|
* Returns true when NO_COLOR is present in the environment and is not
|
package/dist/lib/ticker.js
CHANGED
|
@@ -49,6 +49,7 @@ export function createTicker(stderrWrite, isTTY, stderrRaw, noColor) {
|
|
|
49
49
|
if (!tty) {
|
|
50
50
|
// Non-TTY: completely silent.
|
|
51
51
|
return {
|
|
52
|
+
redrawsInPlace: false,
|
|
52
53
|
update: () => undefined,
|
|
53
54
|
finalize: () => undefined,
|
|
54
55
|
};
|
|
@@ -56,6 +57,7 @@ export function createTicker(stderrWrite, isTTY, stderrRaw, noColor) {
|
|
|
56
57
|
if (suppressAnsi) {
|
|
57
58
|
// TTY but NO_COLOR: emit plain-text lines without ANSI escape sequences.
|
|
58
59
|
return {
|
|
60
|
+
redrawsInPlace: false,
|
|
59
61
|
update(line) {
|
|
60
62
|
const stamped = `${new Date().toISOString()} ${line}`;
|
|
61
63
|
stderrWrite(stamped);
|
|
@@ -72,6 +74,7 @@ export function createTicker(stderrWrite, isTTY, stderrRaw, noColor) {
|
|
|
72
74
|
};
|
|
73
75
|
}
|
|
74
76
|
return {
|
|
77
|
+
redrawsInPlace: true,
|
|
75
78
|
update(line) {
|
|
76
79
|
// ANSI ESC[2K clears the entire line; \r moves to column 0.
|
|
77
80
|
const stamped = `${new Date().toISOString()} ${line}`;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle of one `--local` tunnel: mint → connect → (run) → tear down.
|
|
3
|
+
*
|
|
4
|
+
* The credential handling is the point of this module, so it is stated once
|
|
5
|
+
* here rather than repeated at every line that touches it. The secret returned
|
|
6
|
+
* by `POST /api/cli/v1/tunnel` lives in exactly one place — a local in this
|
|
7
|
+
* function — for the lifetime of the process. It is never written to disk,
|
|
8
|
+
* never placed in `argv`, never exported into a child's environment, never
|
|
9
|
+
* logged (the log sink is a closure this module owns), and never sent on the
|
|
10
|
+
* run trigger: the trigger body carries only `tunnelClientId`, and the backend
|
|
11
|
+
* builds the proxy string from its own configuration. `config.json`
|
|
12
|
+
* credentials are a settled no in this codebase, and a tunnel secret is worse
|
|
13
|
+
* than an API key — it authorises an inbound network path into the holder's
|
|
14
|
+
* machine.
|
|
15
|
+
*
|
|
16
|
+
* ## Why there is no remint-and-reconnect
|
|
17
|
+
*
|
|
18
|
+
* The design ledger's D3 said a terminal `1008/AUTH_FAILED` mid-run should
|
|
19
|
+
* mint a fresh client, reconnect, and keep polling — "the in-flight step still
|
|
20
|
+
* fails" being the only accepted cost. That is not achievable, and the reason
|
|
21
|
+
* is structural rather than a matter of effort:
|
|
22
|
+
*
|
|
23
|
+
* - The proxy string the execution Lambda uses is
|
|
24
|
+
* `http://<clientId>:<secret>@<proxy-host>:<port>`, built ONCE at trigger
|
|
25
|
+
* time and baked into the Lambda payload (the invoke is async — there is
|
|
26
|
+
* no channel to hand it a new one).
|
|
27
|
+
* - The tunnel's proxy plane authenticates every request against that
|
|
28
|
+
* `(clientId, secret)` pair and looks the client session up **by that
|
|
29
|
+
* clientId** (`src/proxy/runtime.rs`: `extract_proxy_credentials` →
|
|
30
|
+
* `registry.authenticate(client_id, &secret)` → `registry.get(client_id)`).
|
|
31
|
+
* - The facade is mint-only by design — there is no route that re-registers
|
|
32
|
+
* an existing id, and adding one would be the credential-confirmation
|
|
33
|
+
* oracle the MCP surface already has.
|
|
34
|
+
*
|
|
35
|
+
* So a reminted client necessarily has a NEW id that the in-flight run's proxy
|
|
36
|
+
* string can never name. It would connect a tunnel nothing routes to, while
|
|
37
|
+
* the run kept burning credits failing every remaining step. What this module
|
|
38
|
+
* does instead is honest failure: record the loss, let the caller stop the run
|
|
39
|
+
* and say why. See `openTunnelSession`'s `onFatal`.
|
|
40
|
+
*/
|
|
41
|
+
import { ApiError } from './errors.js';
|
|
42
|
+
import type { LogLevel, TunnelClientOptions } from '../vendor/tunnel-client/index.js';
|
|
43
|
+
import type { TunnelMintResponse } from './tunnel.types.js';
|
|
44
|
+
/**
|
|
45
|
+
* How long to wait for the control plane's first successful connection.
|
|
46
|
+
*
|
|
47
|
+
* The vendored client resolves `start()` only on the first
|
|
48
|
+
* `control-connected` event, and its control loop retries every non-auth
|
|
49
|
+
* failure forever. Without a deadline, `--local` against an unreachable
|
|
50
|
+
* control plane hangs with no output at all — the worst possible shape for a
|
|
51
|
+
* command an agent might be driving unattended.
|
|
52
|
+
*/
|
|
53
|
+
export declare const DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS = 20000;
|
|
54
|
+
/** Maximum time teardown lets a wedged client delay credential deletion. */
|
|
55
|
+
export declare const TUNNEL_CLIENT_STOP_TIMEOUT_MS = 2000;
|
|
56
|
+
/** Why a tunnel stopped being usable for the run that was attached to it. */
|
|
57
|
+
export type TunnelFatalReason = 'auth-failed';
|
|
58
|
+
export interface TunnelSession {
|
|
59
|
+
readonly clientId: string;
|
|
60
|
+
readonly expiresAt: string;
|
|
61
|
+
/** True when this session attached to a client someone else minted. */
|
|
62
|
+
readonly adopted: boolean;
|
|
63
|
+
/** The fatal reason, once one has occurred. `undefined` while healthy. */
|
|
64
|
+
fatalReason(): TunnelFatalReason | undefined;
|
|
65
|
+
/** Give the client a bounded stop window, then delete our binding. Idempotent. */
|
|
66
|
+
close(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/** The slice of the vendored client this module drives. */
|
|
69
|
+
export interface TunnelClientHandle {
|
|
70
|
+
start(): Promise<void>;
|
|
71
|
+
stop(): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
export interface OpenTunnelSessionOptions {
|
|
74
|
+
/** stderr sink. Every line this module emits goes here, never to stdout. */
|
|
75
|
+
log: (line: string) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Verbosity floor forwarded to the vendored client. Default `'error'` —
|
|
78
|
+
* at `'info'` the client narrates every stream open and close, which on a
|
|
79
|
+
* page pulling dozens of subresources buries the run's own output.
|
|
80
|
+
*/
|
|
81
|
+
logLevel?: LogLevel;
|
|
82
|
+
/** Requested binding lifetime. Server clamps and defaults. */
|
|
83
|
+
ttlSeconds?: number;
|
|
84
|
+
/** See {@link DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS}. */
|
|
85
|
+
connectTimeoutMs?: number;
|
|
86
|
+
/** Called once, the first time the tunnel becomes unusable for this run. */
|
|
87
|
+
onFatal?: (reason: TunnelFatalReason) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Attach to a client someone else minted (`testsprite tunnel start` in
|
|
90
|
+
* another terminal) instead of minting one. No secret is available, so
|
|
91
|
+
* nothing is connected here and nothing is deleted at teardown — the
|
|
92
|
+
* process that minted it owns both.
|
|
93
|
+
*/
|
|
94
|
+
adopt?: {
|
|
95
|
+
clientId: string;
|
|
96
|
+
expiresAt: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export interface TunnelSessionDeps {
|
|
100
|
+
mint: (ttlSeconds?: number) => Promise<TunnelMintResponse>;
|
|
101
|
+
/**
|
|
102
|
+
* Delete the binding. MUST be issued through a client whose shutdown signal
|
|
103
|
+
* is not the interrupted one — teardown runs from a `finally` that is often
|
|
104
|
+
* reached *because* of a signal, and a request composed with an
|
|
105
|
+
* already-aborted signal never leaves the process.
|
|
106
|
+
*/
|
|
107
|
+
destroy: (clientId: string) => Promise<void>;
|
|
108
|
+
/** Injectable for tests. Defaults to the vendored `TunnelClient`. */
|
|
109
|
+
createClient?: (options: TunnelClientOptions) => TunnelClientHandle;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Thrown when the tunnel a run depends on dies mid-run. `UNAVAILABLE` (exit
|
|
113
|
+
* 10, "retry the command") rather than a run failure: the test did not fail,
|
|
114
|
+
* the transport under it did, and re-running is the right next action.
|
|
115
|
+
*/
|
|
116
|
+
export declare class TunnelLostError extends ApiError {
|
|
117
|
+
constructor(reason: TunnelFatalReason, runId: string);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Mint (or adopt) a tunnel client and connect it.
|
|
121
|
+
*
|
|
122
|
+
* On any failure after the mint, the client gets a bounded chance to stop and
|
|
123
|
+
* the binding is always deleted before the error propagates. A
|
|
124
|
+
* minted-but-unconnected binding is a live credential with nothing watching
|
|
125
|
+
* it, while an un-stopped client can leave ref'd heartbeat/reconnect timers
|
|
126
|
+
* that keep the process alive long after the command has printed its last
|
|
127
|
+
* line. Credential deletion cannot wait indefinitely for those timers.
|
|
128
|
+
*/
|
|
129
|
+
export declare function openTunnelSession(options: OpenTunnelSessionOptions, deps: TunnelSessionDeps): Promise<TunnelSession>;
|