@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.
Files changed (68) hide show
  1. package/README.md +51 -38
  2. package/dist/commands/agent.js +47 -3
  3. package/dist/commands/ci.d.ts +88 -0
  4. package/dist/commands/ci.js +429 -0
  5. package/dist/commands/doctor.js +100 -1
  6. package/dist/commands/init.js +8 -0
  7. package/dist/commands/project.d.ts +78 -0
  8. package/dist/commands/project.js +426 -3
  9. package/dist/commands/test.d.ts +162 -2
  10. package/dist/commands/test.js +1814 -392
  11. package/dist/commands/testlist.js +15 -9
  12. package/dist/commands/tunnel.d.ts +72 -0
  13. package/dist/commands/tunnel.js +367 -0
  14. package/dist/index.js +107 -38
  15. package/dist/lib/dry-run/samples.d.ts +9 -0
  16. package/dist/lib/dry-run/samples.js +116 -0
  17. package/dist/lib/gh-output.d.ts +7 -0
  18. package/dist/lib/gh-output.js +50 -7
  19. package/dist/lib/http.d.ts +94 -0
  20. package/dist/lib/http.js +120 -5
  21. package/dist/lib/interrupt.d.ts +38 -13
  22. package/dist/lib/interrupt.js +130 -15
  23. package/dist/lib/local-target.d.ts +95 -0
  24. package/dist/lib/local-target.js +184 -0
  25. package/dist/lib/plan-poll.d.ts +171 -0
  26. package/dist/lib/plan-poll.js +442 -0
  27. package/dist/lib/plans.types.d.ts +130 -0
  28. package/dist/lib/plans.types.js +31 -0
  29. package/dist/lib/poll-support.d.ts +26 -0
  30. package/dist/lib/poll-support.js +65 -0
  31. package/dist/lib/poll.d.ts +1 -0
  32. package/dist/lib/poll.js +2 -40
  33. package/dist/lib/response-schemas.d.ts +13 -0
  34. package/dist/lib/response-schemas.js +32 -0
  35. package/dist/lib/run-progress.d.ts +41 -0
  36. package/dist/lib/run-progress.js +56 -0
  37. package/dist/lib/runs.types.d.ts +24 -0
  38. package/dist/lib/target-url-preflight.js +3 -3
  39. package/dist/lib/target-url.d.ts +44 -7
  40. package/dist/lib/target-url.js +250 -61
  41. package/dist/lib/telemetry.d.ts +11 -0
  42. package/dist/lib/telemetry.js +1 -0
  43. package/dist/lib/ticker.d.ts +8 -0
  44. package/dist/lib/ticker.js +3 -0
  45. package/dist/lib/tunnel-session.d.ts +129 -0
  46. package/dist/lib/tunnel-session.js +232 -0
  47. package/dist/lib/tunnel.types.d.ts +54 -0
  48. package/dist/lib/tunnel.types.js +8 -0
  49. package/dist/vendor/tunnel-client/client.d.ts +83 -0
  50. package/dist/vendor/tunnel-client/client.js +871 -0
  51. package/dist/vendor/tunnel-client/config.d.ts +41 -0
  52. package/dist/vendor/tunnel-client/config.js +42 -0
  53. package/dist/vendor/tunnel-client/index.d.ts +9 -0
  54. package/dist/vendor/tunnel-client/index.js +9 -0
  55. package/dist/vendor/tunnel-client/lodash-lite.d.ts +14 -0
  56. package/dist/vendor/tunnel-client/lodash-lite.js +24 -0
  57. package/dist/vendor/tunnel-client/protocol.d.ts +60 -0
  58. package/dist/vendor/tunnel-client/protocol.js +143 -0
  59. package/dist/vendor/tunnel-client/types.d.ts +96 -0
  60. package/dist/vendor/tunnel-client/types.js +10 -0
  61. package/dist/vendor/tunnel-client/ws-compat.d.ts +206 -0
  62. package/dist/vendor/tunnel-client/ws-compat.js +316 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +2 -1
  66. package/skills/testsprite-onboard.skill.md +60 -4
  67. package/skills/testsprite-verify.codex.md +22 -16
  68. package/skills/testsprite-verify.skill.md +27 -18
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Shared low-level helpers for the two polling loops (`poll.ts` for run
3
+ * polling, `plan-poll.ts` for the plan-generation ladder). These three were
4
+ * byte-identical copies in both files (#341 review); extracted here so a fix
5
+ * to the interrupt/abort contract lands in one place. Signal COMPOSITION is
6
+ * deliberately NOT here — each loop composes its own session signal with a
7
+ * shape specific to its lifetime (`poll.ts` inline, `plan-poll.ts` via
8
+ * `composeSessionSignal`), and folding those together would couple two
9
+ * unrelated lifetimes.
10
+ */
11
+ /** Resolve after `ms`. The default injectable sleep; tests substitute a fake. */
12
+ export function defaultSleep(ms, signal) {
13
+ if (signal?.aborted)
14
+ return Promise.reject(signal.reason);
15
+ return new Promise((resolve, reject) => {
16
+ const timer = setTimeout(() => {
17
+ signal?.removeEventListener('abort', onAbort);
18
+ resolve();
19
+ }, ms);
20
+ const onAbort = () => {
21
+ clearTimeout(timer);
22
+ signal?.removeEventListener('abort', onAbort);
23
+ reject(signal?.reason);
24
+ };
25
+ signal?.addEventListener('abort', onAbort, { once: true });
26
+ });
27
+ }
28
+ /**
29
+ * Race a sleep against the shutdown signal: rejects with the signal's
30
+ * `InterruptError` reason the moment it fires, so no backoff/retry/pacing wait
31
+ * can delay the honest-detach UX. The default sleep receives the signal and
32
+ * clears its pending timer when interrupted; the outer race remains necessary
33
+ * for injected sleeps that do not implement cancellation themselves.
34
+ */
35
+ export function sleepUnlessInterrupted(sleep, ms, signal) {
36
+ if (signal == null)
37
+ return sleep(ms);
38
+ if (signal.aborted)
39
+ return Promise.reject(signal.reason);
40
+ return new Promise((resolve, reject) => {
41
+ const onAbort = () => reject(signal.reason);
42
+ signal.addEventListener('abort', onAbort, { once: true });
43
+ sleep(ms, signal).then(() => {
44
+ signal.removeEventListener('abort', onAbort);
45
+ resolve();
46
+ }, err => {
47
+ signal.removeEventListener('abort', onAbort);
48
+ reject(err instanceof Error ? err : new Error(String(err)));
49
+ });
50
+ });
51
+ }
52
+ /**
53
+ * Detects an AbortError thrown when an AbortSignal fires. Works for native
54
+ * fetch AbortErrors as well as `AbortController.abort()` from Node 18+ stdlib
55
+ * (both set `name === 'AbortError'`).
56
+ */
57
+ export function isAbortError(err) {
58
+ if (err instanceof Error && err.name === 'AbortError')
59
+ return true;
60
+ if (typeof err === 'object' && err !== null && 'name' in err) {
61
+ return err.name === 'AbortError';
62
+ }
63
+ return false;
64
+ }
65
+ //# sourceMappingURL=poll-support.js.map
@@ -22,6 +22,7 @@
22
22
  */
23
23
  import type { ShutdownHandle } from './interrupt.js';
24
24
  import type { RunResponse } from './runs.types.js';
25
+ export { isTerminalStatus } from './runs.types.js';
25
26
  /**
26
27
  * Minimal interface that `pollRunUntilTerminal` requires from the HTTP client.
27
28
  * Using a structural interface (rather than the concrete `HttpClient`) makes
package/dist/lib/poll.js CHANGED
@@ -21,7 +21,9 @@
21
21
  * Deadline exceeded → throw `TimeoutError`.
22
22
  */
23
23
  import { ApiError, InterruptError } from './errors.js';
24
+ import { defaultSleep, isAbortError, sleepUnlessInterrupted } from './poll-support.js';
24
25
  import { isTerminalStatus } from './runs.types.js';
26
+ export { isTerminalStatus } from './runs.types.js';
25
27
  /** Thrown when the polling deadline is hit. */
26
28
  export class TimeoutError extends Error {
27
29
  runId;
@@ -279,44 +281,4 @@ function backoffScheduleDelay(index) {
279
281
  const jitter = base * 0.2 * (Math.random() * 2 - 1); // ±20%
280
282
  return Math.max(0, Math.round(base + jitter));
281
283
  }
282
- function defaultSleep(ms) {
283
- return new Promise(resolve => setTimeout(resolve, ms));
284
- }
285
- /**
286
- * Race a sleep against the shutdown signal: rejects with the signal's
287
- * `InterruptError` reason the moment it fires, so no backoff/retry wait can
288
- * delay the honest-detach UX. Wraps the injected `sleep` (tests keep their
289
- * deterministic fakes); the underlying timer is left to fire harmlessly —
290
- * the interrupt path exits the process long before it matters.
291
- */
292
- function sleepUnlessInterrupted(sleep, ms, signal) {
293
- if (signal == null)
294
- return sleep(ms);
295
- if (signal.aborted)
296
- return Promise.reject(signal.reason);
297
- return new Promise((resolve, reject) => {
298
- const onAbort = () => reject(signal.reason);
299
- signal.addEventListener('abort', onAbort, { once: true });
300
- sleep(ms).then(() => {
301
- signal.removeEventListener('abort', onAbort);
302
- resolve();
303
- }, err => {
304
- signal.removeEventListener('abort', onAbort);
305
- reject(err instanceof Error ? err : new Error(String(err)));
306
- });
307
- });
308
- }
309
- /**
310
- * Detects an AbortError thrown when an AbortSignal fires.
311
- * Works for native fetch AbortErrors as well as `AbortController.abort()`
312
- * from Node 18+ stdlib (both set `name === 'AbortError'`).
313
- */
314
- function isAbortError(err) {
315
- if (err instanceof Error && err.name === 'AbortError')
316
- return true;
317
- if (typeof err === 'object' && err !== null && 'name' in err) {
318
- return err.name === 'AbortError';
319
- }
320
- return false;
321
- }
322
284
  //# sourceMappingURL=poll.js.map
@@ -34,6 +34,7 @@
34
34
  import * as v from 'valibot';
35
35
  import type { BatchRerunResponse, BatchRunFreshResponse, ListRunsResponse, RerunResponse, RunResponse, TriggerRunResponse } from './runs.types.js';
36
36
  import type { CliTestListRunResponse } from './testlist.types.js';
37
+ import type { TunnelMintResponse, TunnelStatusResponse } from './tunnel.types.js';
37
38
  /** Mirrors `RunResponse` (runs.types.ts): `GET /api/cli/v1/runs/{runId}`. */
38
39
  export declare const RUN_RESPONSE_SCHEMA: v.GenericSchema<unknown, RunResponse>;
39
40
  /** Mirrors `TriggerRunResponse` (runs.types.ts): `POST /tests/{testId}/runs`. */
@@ -88,3 +89,15 @@ export interface MeIdentityWire {
88
89
  }
89
90
  /** Mirrors `MeIdentity` (commands/doctor.ts): `GET /api/cli/v1/me` core. */
90
91
  export declare const ME_IDENTITY_SCHEMA: v.GenericSchema<unknown, MeIdentityWire>;
92
+ /**
93
+ * Mirrors `TunnelMintResponse` (tunnel.types.ts): `POST /tunnel`.
94
+ *
95
+ * Every field is required rather than nullish-defaulted, and that is
96
+ * deliberate on this one surface: a mint response missing `controlUrl` or
97
+ * `tunnelAddr` cannot be used for anything, and the client's failure mode
98
+ * for a bad endpoint (a control socket that closes) is indistinguishable
99
+ * from an auth failure. Refusing the response here names the real problem.
100
+ */
101
+ export declare const TUNNEL_MINT_RESPONSE_SCHEMA: v.GenericSchema<unknown, TunnelMintResponse>;
102
+ /** Mirrors `TunnelStatusResponse` (tunnel.types.ts): `GET /tunnel/{clientId}`. */
103
+ export declare const TUNNEL_STATUS_RESPONSE_SCHEMA: v.GenericSchema<unknown, TunnelStatusResponse>;
@@ -69,6 +69,9 @@ const RUN_STEP_DTO_SCHEMA = v.looseObject({
69
69
  export const RUN_RESPONSE_SCHEMA = v.looseObject({
70
70
  runId: v.string(),
71
71
  testId: v.string(),
72
+ // The test's human title (for CI output). Absent on older servers; the type
73
+ // keeps it optional and renderers fall back to `testId`.
74
+ testTitle: v.nullish(v.string(), null),
72
75
  projectId: v.string(),
73
76
  userId: v.string(),
74
77
  status: openWireLiteral(),
@@ -121,6 +124,10 @@ export const RUN_RESPONSE_SCHEMA = v.looseObject({
121
124
  // through untouched) and normalized at the consumer, not in the schema.
122
125
  // Locked by tests in response-schemas.test.ts.
123
126
  dashboardUrl: v.nullish(v.string(), undefined),
127
+ // Same absent-key-preserving contract as `dashboardUrl` (see the note above):
128
+ // the run-scoped execution-result link is present only for a V3-served run
129
+ // with the server flag on, absent otherwise, and never materialized as null.
130
+ executionUrl: v.nullish(v.string(), undefined),
124
131
  // Absence means "steps not requested" and drives command branching, so no
125
132
  // default is applied (rule 3, optional branch).
126
133
  steps: v.optional(v.nullable(v.array(RUN_STEP_DTO_SCHEMA))),
@@ -301,4 +308,29 @@ export const ME_IDENTITY_SCHEMA = v.looseObject({
301
308
  organizations: v.optional(v.array(ORG_SUMMARY_SCHEMA)),
302
309
  org: v.optional(ORG_BINDING_SCHEMA),
303
310
  });
311
+ // ---------------------------------------------------------------------------
312
+ // /tunnel — DEV-747 piece 1 facade
313
+ // ---------------------------------------------------------------------------
314
+ /**
315
+ * Mirrors `TunnelMintResponse` (tunnel.types.ts): `POST /tunnel`.
316
+ *
317
+ * Every field is required rather than nullish-defaulted, and that is
318
+ * deliberate on this one surface: a mint response missing `controlUrl` or
319
+ * `tunnelAddr` cannot be used for anything, and the client's failure mode
320
+ * for a bad endpoint (a control socket that closes) is indistinguishable
321
+ * from an auth failure. Refusing the response here names the real problem.
322
+ */
323
+ export const TUNNEL_MINT_RESPONSE_SCHEMA = v.looseObject({
324
+ clientId: v.pipe(v.string(), v.minLength(1)),
325
+ secret: v.pipe(v.string(), v.minLength(1)),
326
+ controlUrl: v.pipe(v.string(), v.minLength(1)),
327
+ tunnelAddr: v.pipe(v.string(), v.minLength(1)),
328
+ expiresAt: v.string(),
329
+ });
330
+ /** Mirrors `TunnelStatusResponse` (tunnel.types.ts): `GET /tunnel/{clientId}`. */
331
+ export const TUNNEL_STATUS_RESPONSE_SCHEMA = v.looseObject({
332
+ clientId: v.string(),
333
+ status: openWireLiteral(),
334
+ expiresAt: v.string(),
335
+ });
304
336
  //# sourceMappingURL=response-schemas.js.map
@@ -0,0 +1,41 @@
1
+ import type { RunResponse } from './runs.types.js';
2
+ import type { Ticker } from './ticker.js';
3
+ /**
4
+ * The in-place progress line for a polled run.
5
+ *
6
+ * Deliberately NO `completed/total` counter: on both the V2 and V3 read paths
7
+ * `stepSummary.total` and `.completed` are computed from the same array of
8
+ * already-finished step rows (a row is inserted only once its step has a
9
+ * verdict), so the two can never differ — `0/0 steps` at the start and `N/N`
10
+ * thereafter carried no information. Show the recorded count, or nothing.
11
+ *
12
+ * `tag` is inserted verbatim after the run id — the caller picks the bracket
13
+ * style (`(testId)` for batch members, `[role]` for closure members) so the
14
+ * two kinds of tag stay visually distinct.
15
+ */
16
+ export declare function formatRunProgressLine(run: RunResponse, elapsedMs: number, tag?: string): string;
17
+ export interface LiveRunProgress {
18
+ /** Feed a poll result; renders immediately and becomes the refresher's snapshot. */
19
+ onTick(run: RunResponse, elapsedMs: number): void;
20
+ /** Stop the 1s refresher. Idempotent; call before the ticker's final line. */
21
+ stop(): void;
22
+ }
23
+ export interface LiveRunProgressOptions {
24
+ /**
25
+ * Whether to run the between-polls refresher. Defaults to
26
+ * `ticker.redrawsInPlace` — a ticker that prints a NEW line per `update()`
27
+ * (non-TTY, NO_COLOR) must not be redrawn once a second.
28
+ */
29
+ enabled?: boolean;
30
+ intervalMs?: number;
31
+ now?: () => number;
32
+ setIntervalFn?: (cb: () => void, ms: number) => NodeJS.Timeout;
33
+ clearIntervalFn?: (handle: NodeJS.Timeout) => void;
34
+ }
35
+ /**
36
+ * Wraps a {@link Ticker} so the elapsed counter keeps moving between polls.
37
+ * In long-poll mode a `getRun` returns every ~25s, so a ticker driven only by
38
+ * `onTick` freezes for the whole wait; this re-renders the LAST snapshot
39
+ * every second with the wall-clock time that has passed since it arrived.
40
+ */
41
+ export declare function createLiveRunProgress(ticker: Ticker, opts?: LiveRunProgressOptions, tag?: string): LiveRunProgress;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The in-place progress line for a polled run.
3
+ *
4
+ * Deliberately NO `completed/total` counter: on both the V2 and V3 read paths
5
+ * `stepSummary.total` and `.completed` are computed from the same array of
6
+ * already-finished step rows (a row is inserted only once its step has a
7
+ * verdict), so the two can never differ — `0/0 steps` at the start and `N/N`
8
+ * thereafter carried no information. Show the recorded count, or nothing.
9
+ *
10
+ * `tag` is inserted verbatim after the run id — the caller picks the bracket
11
+ * style (`(testId)` for batch members, `[role]` for closure members) so the
12
+ * two kinds of tag stay visually distinct.
13
+ */
14
+ export function formatRunProgressLine(run, elapsedMs, tag) {
15
+ const elapsed = Math.round(elapsedMs / 1000);
16
+ const total = run.stepSummary?.total ?? 0;
17
+ const head = tag === undefined ? `Run ${run.runId}` : `Run ${run.runId} ${tag}`;
18
+ const steps = total > 0 ? ` · ${total} step${total === 1 ? '' : 's'}` : '';
19
+ return `${head} — ${run.status}${steps} · ${elapsed}s`;
20
+ }
21
+ /**
22
+ * Wraps a {@link Ticker} so the elapsed counter keeps moving between polls.
23
+ * In long-poll mode a `getRun` returns every ~25s, so a ticker driven only by
24
+ * `onTick` freezes for the whole wait; this re-renders the LAST snapshot
25
+ * every second with the wall-clock time that has passed since it arrived.
26
+ */
27
+ export function createLiveRunProgress(ticker, opts = {}, tag) {
28
+ const now = opts.now ?? Date.now;
29
+ const setIntervalFn = opts.setIntervalFn ?? setInterval;
30
+ const clearIntervalFn = opts.clearIntervalFn ?? clearInterval;
31
+ const enabled = opts.enabled ?? ticker.redrawsInPlace;
32
+ let snapshot;
33
+ let handle;
34
+ if (enabled) {
35
+ handle = setIntervalFn(() => {
36
+ if (!snapshot)
37
+ return;
38
+ ticker.update(formatRunProgressLine(snapshot.run, snapshot.elapsedMs + (now() - snapshot.at), tag));
39
+ }, opts.intervalMs ?? 1000);
40
+ // Never let the refresher keep the process alive on its own.
41
+ handle.unref?.();
42
+ }
43
+ return {
44
+ onTick(run, elapsedMs) {
45
+ snapshot = { run, elapsedMs, at: now() };
46
+ ticker.update(formatRunProgressLine(run, elapsedMs, tag));
47
+ },
48
+ stop() {
49
+ if (handle !== undefined) {
50
+ clearIntervalFn(handle);
51
+ handle = undefined;
52
+ }
53
+ },
54
+ };
55
+ }
56
+ //# sourceMappingURL=run-progress.js.map
@@ -11,6 +11,17 @@ export interface TriggerRunBody {
11
11
  source: 'cli';
12
12
  /** Optional override for the project's configured target URL. */
13
13
  targetUrl?: string;
14
+ /**
15
+ * DEV-747: id of a tunnel client minted through `POST /api/cli/v1/tunnel`.
16
+ *
17
+ * An ID, never a proxy string — the caller does not choose the proxy host.
18
+ * The server loads the binding, checks it belongs to the calling principal
19
+ * and that the tunnel is connected, and only then builds the proxy string
20
+ * from its own configuration. Sent ONLY alongside a loopback `targetUrl`;
21
+ * the server refuses the pairing in every other combination rather than
22
+ * dropping the field.
23
+ */
24
+ tunnelClientId?: string;
14
25
  }
15
26
  /**
16
27
  * Body sent to `POST /api/cli/v1/tests/{testId}/runs/rerun`.
@@ -192,6 +203,11 @@ export interface RunStepDto {
192
203
  export interface RunResponse {
193
204
  runId: string;
194
205
  testId: string;
206
+ /**
207
+ * The test's human title, for CI output. `null`/absent on older servers or
208
+ * when it can't be resolved — consumers fall back to `testId`.
209
+ */
210
+ testTitle?: string | null;
195
211
  projectId: string;
196
212
  userId: string;
197
213
  status: RunStatus;
@@ -237,6 +253,14 @@ export interface RunResponse {
237
253
  * `withRunDashboardUrl` in `commands/test.ts`.
238
254
  */
239
255
  dashboardUrl?: string | null;
256
+ /**
257
+ * Portal deep link to THIS RUN's result page (`…/projects/{pid}/execution/{eid}`),
258
+ * the run-scoped companion to `dashboardUrl` (which opens the test case). Same
259
+ * server-built / omit-not-null contract as `dashboardUrl`: **V3-served runs
260
+ * only** — a V2 run has no execution page, so the field is absent there and the
261
+ * CLI keeps `dashboardUrl` (the test-case link) for the run cell.
262
+ */
263
+ executionUrl?: string | null;
240
264
  /**
241
265
  * Full ordered step list. Only present when the request includes
242
266
  * `?includeSteps=true`. Absent (undefined) when the flag was not sent.
@@ -148,11 +148,11 @@ export async function probeTargetUrl(rawUrl, deps = {}) {
148
148
  // "can't tell from here" result, and a false positive has a documented
149
149
  // escape hatch (`--skip-preflight`) rather than a broken workflow.
150
150
  for (const address of resolvedAddresses(lookupResult)) {
151
- const blockedReason = disallowedIpReason(address);
152
- if (blockedReason !== undefined) {
151
+ const blocked = disallowedIpReason(address);
152
+ if (blocked !== undefined) {
153
153
  return {
154
154
  verdict: 'refuse',
155
- reason: `--target-url host "${host}" resolves to ${address} (${blockedReason})`,
155
+ reason: `--target-url host "${host}" resolves to ${address} (${blocked.reason})`,
156
156
  };
157
157
  }
158
158
  }
@@ -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 **string/literal-only** checks
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,24 +12,61 @@
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 IPv4-mapped IPv6 (`::ffff:…`), IPv6 link-local (`fe80::/10`), unique-local (`fc00::/7`)
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
  */
20
27
  /**
21
28
  * 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.
29
+ * disallowed target — localhost or a private/reserved literal IP. Also rejects
30
+ * non-http(s) schemes.
24
31
  *
25
32
  * Silently returns on allowed URLs.
26
33
  */
27
34
  export declare function assertNotLocal(rawUrl: string): void;
35
+ /**
36
+ * One disallowed-address classification: the human-readable reason (used
37
+ * verbatim in the rejection message — unchanged wording, not a new
38
+ * classification) plus a `hintKind` telling `assertNotLocal` which hint, if
39
+ * any, is honest to attach:
40
+ * - `'loopback'` — exactly the host set `--local-host` accepts
41
+ * (`localhost`, `127.0.0.1`, `::1`) plus the two unspecified addresses
42
+ * (`0.0.0.0`, `::`), which `--local`'s default dial also reaches because
43
+ * binding to "all interfaces" includes the loopback one; hint `--local`.
44
+ * - `'loopback-other'` — the REST of `127.0.0.0/8` (e.g. `127.0.0.2`). This
45
+ * is loopback-range and unreachable from outside the machine, same as
46
+ * `'loopback'` above, but `--local-host` cannot dial it by name — an app
47
+ * bound only to `127.0.0.2` does not answer on `127.0.0.1`. Hinting
48
+ * `--local` here would recommend a command that cannot reach the address
49
+ * it was just told about, so this gets no hint (a caller who reads the
50
+ * reason can rebind their dev server onto `127.0.0.1` and get `--local`
51
+ * to work, but that's their call to make, not a claim this code asserts).
52
+ * - `'private'` — `--local` can never reach this class even in principle;
53
+ * hint that plainly, with no tunnel suggestion.
54
+ * - `'undecided'` — the address genuinely cannot be decoded safely (currently
55
+ * RFC 8215's `/48` NAT64 local-use range, whose embedded bit position differs
56
+ * from the `/96` well-known prefix), so neither hint is knowably true.
57
+ *
58
+ * `target-url-preflight.ts` uses only `.reason` and is unaffected by this
59
+ * field's addition.
60
+ */
61
+ export interface DisallowedIpClassification {
62
+ reason: string;
63
+ hintKind: 'loopback' | 'loopback-other' | 'private' | 'undecided';
64
+ }
28
65
  /**
29
66
  * Classify a bare IP-address literal — IPv4 dotted form, or IPv6 optionally
30
67
  * wrapped in the `[...]` bracket notation `URL.hostname` uses — against the
31
68
  * private/loopback/link-local/metadata blocklist. Returns the disallowed
32
- * reason string, or `undefined` when the address is allowed.
69
+ * classification, or `undefined` when the address is allowed.
33
70
  *
34
71
  * This is the single source of truth for the range list: `assertNotLocal`
35
72
  * calls it for the literal `--target-url` string above, and the reachability
@@ -39,4 +76,4 @@ export declare function assertNotLocal(rawUrl: string): void;
39
76
  * literal private IP typed on the command line, and both need the same
40
77
  * range list, not two drifting copies of it.
41
78
  */
42
- export declare function disallowedIpReason(host: string): string | undefined;
79
+ export declare function disallowedIpReason(host: string): DisallowedIpClassification | undefined;