@testsprite/testsprite-cli 0.6.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.
Files changed (96) hide show
  1. package/README.md +52 -31
  2. package/dist/commands/agent.js +91 -45
  3. package/dist/commands/ci.d.ts +88 -0
  4. package/dist/commands/ci.js +429 -0
  5. package/dist/commands/doctor.d.ts +1 -1
  6. package/dist/commands/doctor.js +104 -8
  7. package/dist/commands/init.js +8 -0
  8. package/dist/commands/project.d.ts +78 -0
  9. package/dist/commands/project.js +429 -5
  10. package/dist/commands/schedule.d.ts +120 -0
  11. package/dist/commands/schedule.js +487 -0
  12. package/dist/commands/test.d.ts +176 -2
  13. package/dist/commands/test.js +2235 -609
  14. package/dist/commands/testlist.d.ts +88 -0
  15. package/dist/commands/testlist.js +753 -0
  16. package/dist/commands/tunnel.d.ts +72 -0
  17. package/dist/commands/tunnel.js +367 -0
  18. package/dist/index.js +113 -40
  19. package/dist/lib/agent-targets.d.ts +13 -4
  20. package/dist/lib/agent-targets.js +11 -2
  21. package/dist/lib/conflict-reason.d.ts +30 -0
  22. package/dist/lib/conflict-reason.js +45 -0
  23. package/dist/lib/credentials.js +42 -1
  24. package/dist/lib/cron.d.ts +40 -0
  25. package/dist/lib/cron.js +190 -0
  26. package/dist/lib/dry-run/samples.d.ts +9 -0
  27. package/dist/lib/dry-run/samples.js +293 -55
  28. package/dist/lib/errors.d.ts +9 -0
  29. package/dist/lib/errors.js +11 -0
  30. package/dist/lib/gh-output.d.ts +33 -1
  31. package/dist/lib/gh-output.js +97 -27
  32. package/dist/lib/http.d.ts +119 -0
  33. package/dist/lib/http.js +243 -2
  34. package/dist/lib/interrupt.d.ts +38 -13
  35. package/dist/lib/interrupt.js +130 -15
  36. package/dist/lib/junit-report.d.ts +20 -2
  37. package/dist/lib/junit-report.js +38 -5
  38. package/dist/lib/local-target.d.ts +95 -0
  39. package/dist/lib/local-target.js +184 -0
  40. package/dist/lib/plan-poll.d.ts +171 -0
  41. package/dist/lib/plan-poll.js +442 -0
  42. package/dist/lib/plans.types.d.ts +130 -0
  43. package/dist/lib/plans.types.js +31 -0
  44. package/dist/lib/poll-support.d.ts +26 -0
  45. package/dist/lib/poll-support.js +65 -0
  46. package/dist/lib/poll.d.ts +1 -0
  47. package/dist/lib/poll.js +2 -40
  48. package/dist/lib/proxy.d.ts +16 -0
  49. package/dist/lib/proxy.js +19 -1
  50. package/dist/lib/response-schemas.d.ts +20 -0
  51. package/dist/lib/response-schemas.js +55 -1
  52. package/dist/lib/run-progress.d.ts +41 -0
  53. package/dist/lib/run-progress.js +56 -0
  54. package/dist/lib/runs.types.d.ts +32 -3
  55. package/dist/lib/secret-file.d.ts +15 -0
  56. package/dist/lib/secret-file.js +82 -0
  57. package/dist/lib/target-url-preflight.d.ts +91 -0
  58. package/dist/lib/target-url-preflight.js +259 -0
  59. package/dist/lib/target-url.d.ts +63 -9
  60. package/dist/lib/target-url.js +283 -62
  61. package/dist/lib/telemetry.d.ts +11 -0
  62. package/dist/lib/telemetry.js +1 -0
  63. package/dist/lib/testlist.types.d.ts +77 -0
  64. package/dist/lib/testlist.types.js +9 -0
  65. package/dist/lib/ticker.d.ts +8 -0
  66. package/dist/lib/ticker.js +3 -0
  67. package/dist/lib/tunnel-session.d.ts +129 -0
  68. package/dist/lib/tunnel-session.js +232 -0
  69. package/dist/lib/tunnel.types.d.ts +54 -0
  70. package/dist/lib/tunnel.types.js +8 -0
  71. package/dist/lib/v3-advisory.d.ts +35 -22
  72. package/dist/lib/v3-advisory.js +44 -24
  73. package/dist/lib/wait-exit.d.ts +29 -0
  74. package/dist/lib/wait-exit.js +103 -0
  75. package/dist/vendor/tunnel-client/client.d.ts +83 -0
  76. package/dist/vendor/tunnel-client/client.js +871 -0
  77. package/dist/vendor/tunnel-client/config.d.ts +41 -0
  78. package/dist/vendor/tunnel-client/config.js +42 -0
  79. package/dist/vendor/tunnel-client/index.d.ts +9 -0
  80. package/dist/vendor/tunnel-client/index.js +9 -0
  81. package/dist/vendor/tunnel-client/lodash-lite.d.ts +14 -0
  82. package/dist/vendor/tunnel-client/lodash-lite.js +24 -0
  83. package/dist/vendor/tunnel-client/protocol.d.ts +60 -0
  84. package/dist/vendor/tunnel-client/protocol.js +143 -0
  85. package/dist/vendor/tunnel-client/types.d.ts +96 -0
  86. package/dist/vendor/tunnel-client/types.js +10 -0
  87. package/dist/vendor/tunnel-client/ws-compat.d.ts +206 -0
  88. package/dist/vendor/tunnel-client/ws-compat.js +316 -0
  89. package/dist/version-guard.d.ts +10 -7
  90. package/dist/version-guard.js +37 -9
  91. package/dist/version.d.ts +1 -1
  92. package/dist/version.js +1 -1
  93. package/package.json +2 -1
  94. package/skills/testsprite-onboard.skill.md +60 -4
  95. package/skills/testsprite-verify.codex.md +22 -16
  96. package/skills/testsprite-verify.skill.md +27 -18
@@ -2,25 +2,52 @@
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. This guard does **string/literal-only** checks to give a
6
- * fast, friendly error before sending the request. It cannot detect
7
- * DNS rebinding (a public hostname that resolves to a private IP) — the
8
- * backend catches that.
5
+ * resolution. `assertNotLocal` below does **literal-only** checks
6
+ * to give a fast, friendly error before sending the request — it cannot by
7
+ * itself detect DNS rebinding (a public hostname that resolves to a private
8
+ * IP). That gap is closed one layer up: `target-url-preflight.ts` reuses
9
+ * `disallowedIpReason` (exported below) against the actually-*resolved*
10
+ * address before probing, so the same range list guards both the literal
11
+ * string and the DNS answer — not two drifting copies of it.
9
12
  *
10
13
  * CLI-side target-url guard (exit 5 on any rejection):
11
14
  * - Reject non-http(s) schemes
12
- * - 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`, `::`)
13
16
  * - Reject `169.254.0.0/16` link-local and the `169.254.169.254` metadata address
14
17
  * - Reject RFC1918 literal IPv4 (10.x, 172.16-31.x, 192.168.x)
15
- * - Reject IPv4-mapped IPv6 (`::ffff:…`), IPv6 link-local (`fe80::/10`), unique-local (`fc00::/7`)
16
- * - Hostnames that resolve to private IPs are the backend's concern.
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`)
17
26
  */
27
+ import * as net from 'node:net';
18
28
  import { ApiError } from './errors.js';
19
- const LOCAL_DEV_HINT = 'Local-dev tests are out of scope for the CLI; use testsprite-mcp-plugin for the local tunnel.';
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.';
20
47
  /**
21
48
  * Throws a local `VALIDATION_ERROR` (exit 5) when `rawUrl` is a
22
- * disallowed target — localhost, RFC1918 literal IP, link-local, or
23
- * metadata-service address. Also rejects non-http(s) schemes.
49
+ * disallowed target — localhost or a private/reserved literal IP. Also rejects
50
+ * non-http(s) schemes.
24
51
  *
25
52
  * Silently returns on allowed URLs.
26
53
  */
@@ -44,79 +71,273 @@ export function assertNotLocal(rawUrl) {
44
71
  // IP literals are already dot-normalized by the WHATWG URL parser, so this
45
72
  // only affects named hosts.
46
73
  const host = parsed.hostname.toLowerCase().replace(/\.$/, '');
47
- // Loopback / unspecified.
48
- if (host === 'localhost' || host === '0.0.0.0') {
74
+ // 'localhost' is a name, not an IP literal, so it sits outside
75
+ // `disallowedIpReason` below (which classifies IPv4/IPv6 address forms).
76
+ // It is also always loopback — the same class `--local` can reach.
77
+ if (host === 'localhost') {
49
78
  throw localTargetError('target-url', 'localhost targets are not allowed', LOCAL_DEV_HINT);
50
79
  }
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;
102
+ }
103
+ }
104
+ /**
105
+ * Classify a bare IP-address literal — IPv4 dotted form, or IPv6 optionally
106
+ * wrapped in the `[...]` bracket notation `URL.hostname` uses — against the
107
+ * private/loopback/link-local/metadata blocklist. Returns the disallowed
108
+ * classification, or `undefined` when the address is allowed.
109
+ *
110
+ * This is the single source of truth for the range list: `assertNotLocal`
111
+ * calls it for the literal `--target-url` string above, and the reachability
112
+ * preflight (`target-url-preflight.ts`) calls it again for a DNS-*resolved*
113
+ * address — a public-looking hostname whose A/AAAA record actually points
114
+ * at a private or metadata IP (DNS rebinding) is a distinct bypass from a
115
+ * literal private IP typed on the command line, and both need the same
116
+ * range list, not two drifting copies of it.
117
+ */
118
+ export function disallowedIpReason(host) {
51
119
  // IPv6 literals. Node's URL parser wraps IPv6 hosts in brackets and
52
120
  // normalizes IPv4-mapped forms to hex (`http://[::ffff:127.0.0.1]` →
53
121
  // hostname `[::ffff:7f00:1]`). A dotted-form string check alone would miss
54
122
  // the normalized variant, so we strip the brackets and classify the
55
- // address family explicitly.
56
- if (host.startsWith('[') && host.endsWith(']')) {
57
- assertNotLocalIpv6(host.slice(1, -1));
123
+ // address family explicitly. A DNS-resolved IPv6 address arrives
124
+ // unbracketed already; stripping is a no-op for that shape.
125
+ const bare = host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host;
126
+ const addressFamily = net.isIP(bare);
127
+ if (addressFamily === 6) {
128
+ return disallowedIpv6Reason(bare.toLowerCase());
58
129
  }
59
- // 127.0.0.0/8 loopback range.
60
- if (/^127\.\d+\.\d+\.\d+$/.test(host)) {
61
- throw localTargetError('target-url', 'loopback addresses are not allowed', LOCAL_DEV_HINT);
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' };
62
136
  }
63
- // AWS instance-metadata service (168 and 169 prefixes used for IMDS).
64
- if (host === '169.254.169.254') {
65
- throw localTargetError('target-url', '169.254.169.254 (AWS metadata service) is not allowed', LOCAL_DEV_HINT);
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
+ };
66
143
  }
67
- // 169.254.x.x link-local (IPv4).
68
- if (/^169\.254\.\d+\.\d+$/.test(host)) {
69
- throw localTargetError('target-url', 'link-local addresses are not allowed', LOCAL_DEV_HINT);
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
+ };
70
151
  }
71
- // RFC1918 literal IP addresses only — hostnames that resolve to private
72
- // IPs are the backend's concern (DNS resolution is expensive CLI-side).
73
- if (isRfc1918Literal(host)) {
74
- throw localTargetError('target-url', 'private/RFC1918 addresses are not allowed', LOCAL_DEV_HINT);
152
+ if (ipv4ThisNetworkBlocklist.check(address, 'ipv4')) {
153
+ return { reason: 'reserved "this network" addresses are not allowed', hintKind: 'private' };
75
154
  }
76
- }
77
- function isRfc1918Literal(host) {
78
- // 10.0.0.0/8
79
- if (/^10\.\d+\.\d+\.\d+$/.test(host))
80
- return true;
81
- // 192.168.0.0/16
82
- if (/^192\.168\.\d+\.\d+$/.test(host))
83
- return true;
84
- // 172.16.0.0/12 (172.16.x.x – 172.31.x.x)
85
- const m = host.match(/^172\.(\d+)\.\d+\.\d+$/);
86
- if (m) {
87
- const second = parseInt(m[1], 10);
88
- if (second >= 16 && second <= 31)
89
- return true;
90
- }
91
- return false;
155
+ if (ipv4LinkLocalBlocklist.check(address, 'ipv4')) {
156
+ return { reason: 'link-local addresses are not allowed', hintKind: 'private' };
157
+ }
158
+ if (ipv4Rfc1918Blocklist.check(address, 'ipv4')) {
159
+ return { reason: 'private/RFC1918 addresses are not allowed', hintKind: 'private' };
160
+ }
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' };
169
+ }
170
+ return undefined;
92
171
  }
93
172
  /**
94
- * Reject disallowed IPv6 literals: loopback (`::1`), unspecified (`::`),
95
- * IPv4-mapped (`::ffff:…`), link-local (`fe80::/10`), and unique-local
96
- * (`fc00::/7`). `inner` is the bracket-stripped, lowercased host.
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.
97
193
  *
98
- * The IPv4-mapped class is rejected wholesale rather than decoding the
99
- * embedded v4 address: no legitimate target is expressed as a mapped
100
- * literal, and the hex-normalized form (`::ffff:7f00:1`) is error-prone to
101
- * decode. This closes the `http://[::ffff:127.0.0.1]` SSRF-guard bypass.
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.
102
235
  */
103
- function assertNotLocalIpv6(inner) {
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
+ };
295
+ }
296
+ /**
297
+ * Classify disallowed IPv6 literals: loopback (`::1`), unspecified (`::`),
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.
303
+ */
304
+ function disallowedIpv6Reason(inner) {
104
305
  // Loopback (::1) and unspecified (::).
105
306
  if (inner === '::1' || inner === '::') {
106
- throw localTargetError('target-url', 'localhost targets are not allowed', LOCAL_DEV_HINT);
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');
107
327
  }
108
- // IPv4-mapped IPv6 (`::ffff:a.b.c.d`, normalized to `::ffff:hhhh:hhhh`).
109
- if (inner.startsWith('::ffff:')) {
110
- throw localTargetError('target-url', 'IPv4-mapped IPv6 addresses are not allowed; use the IPv4 form or a hostname', LOCAL_DEV_HINT);
328
+ if (ipv6LinkLocalBlocklist.check(inner, 'ipv6')) {
329
+ return { reason: 'link-local addresses are not allowed', hintKind: 'private' };
111
330
  }
112
- // Link-local fe80::/10 (first hextet fe80–febf).
113
- if (/^fe[89ab][0-9a-f]:/.test(inner)) {
114
- throw localTargetError('target-url', 'link-local addresses are not allowed', LOCAL_DEV_HINT);
331
+ if (ipv6UniqueLocalBlocklist.check(inner, 'ipv6')) {
332
+ return { reason: 'unique-local (private) addresses are not allowed', hintKind: 'private' };
115
333
  }
116
- // Unique-local fc00::/7 (first hextet fc00–fdff).
117
- if (/^f[cd][0-9a-f]{2}:/.test(inner)) {
118
- throw localTargetError('target-url', 'unique-local (private) addresses are not allowed', LOCAL_DEV_HINT);
334
+ if (ipv6SiteLocalBlocklist.check(inner, 'ipv6')) {
335
+ return {
336
+ reason: 'site-local (deprecated private) addresses are not allowed',
337
+ hintKind: 'private',
338
+ };
119
339
  }
340
+ return undefined;
120
341
  }
121
342
  function localTargetError(field, reason, hint) {
122
343
  return ApiError.fromEnvelope({
@@ -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
@@ -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
  /**
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Wire shapes for the `/api/cli/v1/testlist/*` surface (CRUD).
3
+ *
4
+ * `testId` on a case IS the test's logical id (`test_case.key`) — the same id
5
+ * `test list` / `test get` return and `test run` accepts, so a case can be added
6
+ * to a list with no translation.
7
+ */
8
+ import type { RunConflict } from './conflict-reason.js';
9
+ export interface CliProjectEnvironment {
10
+ projectId: string;
11
+ environmentName: string;
12
+ }
13
+ /** A test-list row (no cases) — `testlist list`. */
14
+ export interface CliTestList {
15
+ id: string;
16
+ name: string;
17
+ orgId: string;
18
+ caseCount: number;
19
+ projectEnvironments: CliProjectEnvironment[];
20
+ lastExecutionId: string | null;
21
+ createdAt: string;
22
+ updatedAt: string;
23
+ }
24
+ /** One case inside a list — `testlist get`. */
25
+ export interface CliTestListCase {
26
+ /** The test's logical id (== `test_case.key`). */
27
+ testId: string;
28
+ type: 'frontend' | 'backend';
29
+ projectId: string;
30
+ projectName: string;
31
+ title: string | null;
32
+ category: string | null;
33
+ priority: string | null;
34
+ modified: string | null;
35
+ status: string | null;
36
+ }
37
+ /** Full detail incl. cases + stats — `testlist get` / after a mutation. */
38
+ export interface CliTestListDetail extends CliTestList {
39
+ cases: CliTestListCase[];
40
+ stats: {
41
+ total: number;
42
+ passed: number;
43
+ failed: number;
44
+ blocked: number;
45
+ running: number;
46
+ };
47
+ lastExecutionCreated: string | null;
48
+ }
49
+ export interface CliTestListListResponse {
50
+ items: CliTestList[];
51
+ }
52
+ export interface CliDeleteTestListResponse {
53
+ listId: string;
54
+ }
55
+ /** One dispatched run from `testlist run` — `runId` polls via `GET /runs/{runId}`. */
56
+ export interface CliTestListRunAccepted {
57
+ testId: string;
58
+ runId: string;
59
+ enqueuedAt: string;
60
+ }
61
+ /**
62
+ * `testlist run` result. Mirrors the batch-run-fresh envelope so `--wait` reuses
63
+ * the same poll/summary tail. `conflicts[]` carry the in-flight `currentRunId`
64
+ * (poll it instead of retrying). `deferred[]` carries the cases the per-key
65
+ * run-rate budget could not admit this call (retry after ~60s). `notFound[]` is
66
+ * present on a PARTIAL `--case` miss — ids not in this list, skipped (a FULL miss
67
+ * is a 404). `reason` is set only when nothing dispatched (empty list).
68
+ */
69
+ export interface CliTestListRunResponse {
70
+ accepted: CliTestListRunAccepted[];
71
+ conflicts: RunConflict[];
72
+ deferred: Array<{
73
+ testId: string;
74
+ }>;
75
+ notFound?: string[];
76
+ reason?: 'no_matching_cases' | 'empty_list';
77
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Wire shapes for the `/api/cli/v1/testlist/*` surface (CRUD).
3
+ *
4
+ * `testId` on a case IS the test's logical id (`test_case.key`) — the same id
5
+ * `test list` / `test get` return and `test run` accepts, so a case can be added
6
+ * to a list with no translation.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=testlist.types.js.map
@@ -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
@@ -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}`;