@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.
- package/README.md +52 -31
- package/dist/commands/agent.js +91 -45
- package/dist/commands/ci.d.ts +88 -0
- package/dist/commands/ci.js +429 -0
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.js +104 -8
- package/dist/commands/init.js +8 -0
- package/dist/commands/project.d.ts +78 -0
- package/dist/commands/project.js +429 -5
- package/dist/commands/schedule.d.ts +120 -0
- package/dist/commands/schedule.js +487 -0
- package/dist/commands/test.d.ts +176 -2
- package/dist/commands/test.js +2235 -609
- package/dist/commands/testlist.d.ts +88 -0
- package/dist/commands/testlist.js +753 -0
- package/dist/commands/tunnel.d.ts +72 -0
- package/dist/commands/tunnel.js +367 -0
- package/dist/index.js +113 -40
- package/dist/lib/agent-targets.d.ts +13 -4
- package/dist/lib/agent-targets.js +11 -2
- package/dist/lib/conflict-reason.d.ts +30 -0
- package/dist/lib/conflict-reason.js +45 -0
- package/dist/lib/credentials.js +42 -1
- package/dist/lib/cron.d.ts +40 -0
- package/dist/lib/cron.js +190 -0
- package/dist/lib/dry-run/samples.d.ts +9 -0
- package/dist/lib/dry-run/samples.js +293 -55
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.js +11 -0
- package/dist/lib/gh-output.d.ts +33 -1
- package/dist/lib/gh-output.js +97 -27
- package/dist/lib/http.d.ts +119 -0
- package/dist/lib/http.js +243 -2
- package/dist/lib/interrupt.d.ts +38 -13
- package/dist/lib/interrupt.js +130 -15
- package/dist/lib/junit-report.d.ts +20 -2
- package/dist/lib/junit-report.js +38 -5
- 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/proxy.d.ts +16 -0
- package/dist/lib/proxy.js +19 -1
- package/dist/lib/response-schemas.d.ts +20 -0
- package/dist/lib/response-schemas.js +55 -1
- package/dist/lib/run-progress.d.ts +41 -0
- package/dist/lib/run-progress.js +56 -0
- package/dist/lib/runs.types.d.ts +32 -3
- package/dist/lib/secret-file.d.ts +15 -0
- package/dist/lib/secret-file.js +82 -0
- package/dist/lib/target-url-preflight.d.ts +91 -0
- package/dist/lib/target-url-preflight.js +259 -0
- package/dist/lib/target-url.d.ts +63 -9
- package/dist/lib/target-url.js +283 -62
- package/dist/lib/telemetry.d.ts +11 -0
- package/dist/lib/telemetry.js +1 -0
- package/dist/lib/testlist.types.d.ts +77 -0
- package/dist/lib/testlist.types.js +9 -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/lib/v3-advisory.d.ts +35 -22
- package/dist/lib/v3-advisory.js +44 -24
- package/dist/lib/wait-exit.d.ts +29 -0
- package/dist/lib/wait-exit.js +103 -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-guard.d.ts +10 -7
- package/dist/version-guard.js +37 -9
- 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,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>;
|
|
@@ -0,0 +1,232 @@
|
|
|
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 { ErrCode, TunnelClient } from '../vendor/tunnel-client/index.js';
|
|
43
|
+
/**
|
|
44
|
+
* How long to wait for the control plane's first successful connection.
|
|
45
|
+
*
|
|
46
|
+
* The vendored client resolves `start()` only on the first
|
|
47
|
+
* `control-connected` event, and its control loop retries every non-auth
|
|
48
|
+
* failure forever. Without a deadline, `--local` against an unreachable
|
|
49
|
+
* control plane hangs with no output at all — the worst possible shape for a
|
|
50
|
+
* command an agent might be driving unattended.
|
|
51
|
+
*/
|
|
52
|
+
export const DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS = 20_000;
|
|
53
|
+
/** Maximum time teardown lets a wedged client delay credential deletion. */
|
|
54
|
+
export const TUNNEL_CLIENT_STOP_TIMEOUT_MS = 2_000;
|
|
55
|
+
const TUNNEL_SECRET_REDACTION = '[REDACTED]';
|
|
56
|
+
/**
|
|
57
|
+
* Thrown when the tunnel a run depends on dies mid-run. `UNAVAILABLE` (exit
|
|
58
|
+
* 10, "retry the command") rather than a run failure: the test did not fail,
|
|
59
|
+
* the transport under it did, and re-running is the right next action.
|
|
60
|
+
*/
|
|
61
|
+
export class TunnelLostError extends ApiError {
|
|
62
|
+
constructor(reason, runId) {
|
|
63
|
+
super({
|
|
64
|
+
code: 'UNAVAILABLE',
|
|
65
|
+
message: `The tunnel carrying run ${runId} was disconnected by the server and cannot be ` +
|
|
66
|
+
`restored for this run (${reason}).`,
|
|
67
|
+
nextAction: 'This usually means the tunnel service was redeployed mid-run. Start the run again: ' +
|
|
68
|
+
'the retry mints a fresh tunnel.',
|
|
69
|
+
requestId: 'local',
|
|
70
|
+
details: { reason, runId },
|
|
71
|
+
});
|
|
72
|
+
this.name = 'TunnelLostError';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function defaultCreateClient(options) {
|
|
76
|
+
return new TunnelClient(options);
|
|
77
|
+
}
|
|
78
|
+
async function stopClientWithDeadline(client) {
|
|
79
|
+
let timer;
|
|
80
|
+
try {
|
|
81
|
+
await Promise.race([
|
|
82
|
+
client.stop(),
|
|
83
|
+
new Promise(resolve => {
|
|
84
|
+
timer = setTimeout(resolve, TUNNEL_CLIENT_STOP_TIMEOUT_MS);
|
|
85
|
+
}),
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
if (timer !== undefined)
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function redactTunnelSecret(line, secret) {
|
|
94
|
+
if (secret.length === 0)
|
|
95
|
+
return line;
|
|
96
|
+
return line.replaceAll(secret, TUNNEL_SECRET_REDACTION);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Mint (or adopt) a tunnel client and connect it.
|
|
100
|
+
*
|
|
101
|
+
* On any failure after the mint, the client gets a bounded chance to stop and
|
|
102
|
+
* the binding is always deleted before the error propagates. A
|
|
103
|
+
* minted-but-unconnected binding is a live credential with nothing watching
|
|
104
|
+
* it, while an un-stopped client can leave ref'd heartbeat/reconnect timers
|
|
105
|
+
* that keep the process alive long after the command has printed its last
|
|
106
|
+
* line. Credential deletion cannot wait indefinitely for those timers.
|
|
107
|
+
*/
|
|
108
|
+
export async function openTunnelSession(options, deps) {
|
|
109
|
+
const { log } = options;
|
|
110
|
+
let fatal;
|
|
111
|
+
let closed = false;
|
|
112
|
+
if (options.adopt) {
|
|
113
|
+
// Adopted: no secret here, so no connection and no teardown obligation.
|
|
114
|
+
return {
|
|
115
|
+
clientId: options.adopt.clientId,
|
|
116
|
+
expiresAt: options.adopt.expiresAt,
|
|
117
|
+
adopted: true,
|
|
118
|
+
fatalReason: () => fatal,
|
|
119
|
+
close: async () => { },
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const minted = await deps.mint(options.ttlSeconds);
|
|
123
|
+
// Treat the vendored client as untrusted at this boundary: every line is
|
|
124
|
+
// scrubbed before the caller-owned sink can observe it. This remains safe if
|
|
125
|
+
// a future client log message accidentally interpolates its options.
|
|
126
|
+
const sessionLog = (line) => log(redactTunnelSecret(line, minted.secret));
|
|
127
|
+
const createClient = deps.createClient ?? defaultCreateClient;
|
|
128
|
+
let client;
|
|
129
|
+
const stopAndDestroy = async () => {
|
|
130
|
+
// Stop first so cooperative clients release their sockets and ref'd
|
|
131
|
+
// timers. A websocket stuck in CONNECTING makes the real stop() await the
|
|
132
|
+
// same pending control handshake as start(), so the hard deadline below
|
|
133
|
+
// must expire before destroy runs. Deleting the binding revokes the live
|
|
134
|
+
// credential and therefore always gets the final say in this ordering.
|
|
135
|
+
if (client !== undefined) {
|
|
136
|
+
try {
|
|
137
|
+
await stopClientWithDeadline(client);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Best-effort: a failure to stop must never mask the original error,
|
|
141
|
+
// and must never skip the binding delete below.
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
await deps.destroy(minted.clientId);
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
sessionLog(`[advisory] could not delete the tunnel credential (${err instanceof Error ? err.message : String(err)}); it expires on its own at ${minted.expiresAt}.`);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
try {
|
|
152
|
+
client = createClient({
|
|
153
|
+
clientId: minted.clientId,
|
|
154
|
+
secret: minted.secret,
|
|
155
|
+
controlUrl: minted.controlUrl,
|
|
156
|
+
tunnelAddr: minted.tunnelAddr,
|
|
157
|
+
logLevel: options.logLevel ?? 'error',
|
|
158
|
+
// Never opened up. The point of `--local` is the caller's own loopback;
|
|
159
|
+
// a run that pivots into the rest of their network is the failure this
|
|
160
|
+
// rail exists to stop. Loopback and public targets are unaffected.
|
|
161
|
+
allowPrivateNetworkTarget: false,
|
|
162
|
+
logSink: (_level, line) => sessionLog(line),
|
|
163
|
+
onError: e => {
|
|
164
|
+
if (e.code === ErrCode.AuthFailed && fatal === undefined) {
|
|
165
|
+
// Terminal: the vendored client has stopped reconnecting, and a
|
|
166
|
+
// remint cannot rescue this run (see the module docstring).
|
|
167
|
+
fatal = 'auth-failed';
|
|
168
|
+
options.onFatal?.('auth-failed');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (e.code === ErrCode.AuthFailed)
|
|
172
|
+
return;
|
|
173
|
+
sessionLog(`[tunnel] ${e.message}`);
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
await stopAndDestroy();
|
|
179
|
+
throw err;
|
|
180
|
+
}
|
|
181
|
+
const timeoutMs = options.connectTimeoutMs ?? DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS;
|
|
182
|
+
let timer;
|
|
183
|
+
try {
|
|
184
|
+
await new Promise((resolve, reject) => {
|
|
185
|
+
timer = setTimeout(() => {
|
|
186
|
+
reject(ApiError.fromEnvelope({
|
|
187
|
+
error: {
|
|
188
|
+
code: 'UNAVAILABLE',
|
|
189
|
+
message: `The tunnel did not connect within ${Math.round(timeoutMs / 1000)}s.`,
|
|
190
|
+
nextAction: 'Check that outbound WebSocket traffic is allowed from this machine, then retry. ' +
|
|
191
|
+
'An HTTP proxy does not help here: the tunnel data plane is a raw TCP connection ' +
|
|
192
|
+
'and does not go through one.',
|
|
193
|
+
requestId: 'local',
|
|
194
|
+
details: { reason: 'tunnel-connect-timeout', timeoutMs },
|
|
195
|
+
},
|
|
196
|
+
}));
|
|
197
|
+
}, timeoutMs);
|
|
198
|
+
client.start().then(resolve, reject);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
await stopAndDestroy();
|
|
203
|
+
if (err instanceof ApiError)
|
|
204
|
+
throw err;
|
|
205
|
+
throw ApiError.fromEnvelope({
|
|
206
|
+
error: {
|
|
207
|
+
code: 'UNAVAILABLE',
|
|
208
|
+
message: `Could not connect the tunnel: ${err instanceof Error ? err.message : String(err)}`,
|
|
209
|
+
nextAction: 'Retry. If this persists, report it to support@testsprite.com.',
|
|
210
|
+
requestId: 'local',
|
|
211
|
+
details: { reason: 'tunnel-connect-failed' },
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
if (timer !== undefined)
|
|
217
|
+
clearTimeout(timer);
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
clientId: minted.clientId,
|
|
221
|
+
expiresAt: minted.expiresAt,
|
|
222
|
+
adopted: false,
|
|
223
|
+
fatalReason: () => fatal,
|
|
224
|
+
close: async () => {
|
|
225
|
+
if (closed)
|
|
226
|
+
return;
|
|
227
|
+
closed = true;
|
|
228
|
+
await stopAndDestroy();
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=tunnel-session.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types for the `/api/cli/v1/tunnel` facade (DEV-747 piece 1).
|
|
3
|
+
*
|
|
4
|
+
* Three routes and deliberately no fourth — there is no resume/adopt route to
|
|
5
|
+
* hand a `{clientId, secret}` back to, so the CLI mints fresh per invocation.
|
|
6
|
+
*/
|
|
7
|
+
/** Body of `POST /api/cli/v1/tunnel`. */
|
|
8
|
+
export interface MintTunnelBody {
|
|
9
|
+
/**
|
|
10
|
+
* Requested binding lifetime in seconds. Server clamps to [60, 28800] and
|
|
11
|
+
* defaults to 2h. The CLI deletes its own binding at run end, so this is a
|
|
12
|
+
* backstop for a crashed process, not the normal cleanup path.
|
|
13
|
+
*/
|
|
14
|
+
ttlSeconds?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The mint response — the ONE place a tunnel secret ever appears.
|
|
18
|
+
*
|
|
19
|
+
* It is never written to disk, never placed in `argv`, never exported into a
|
|
20
|
+
* child process's environment, and never logged. `config.json` credentials are
|
|
21
|
+
* a settled no for this codebase (452 leaked keys of history), and a tunnel
|
|
22
|
+
* secret is strictly worse than an API key: it authorises an inbound network
|
|
23
|
+
* path into the holder's machine.
|
|
24
|
+
*/
|
|
25
|
+
export interface TunnelMintResponse {
|
|
26
|
+
clientId: string;
|
|
27
|
+
/** Returned here and nowhere else, ever. */
|
|
28
|
+
secret: string;
|
|
29
|
+
/**
|
|
30
|
+
* WebSocket CONTROL plane the tunnel client authenticates against.
|
|
31
|
+
*
|
|
32
|
+
* Not the proxy plane. The execution Lambda's browser talks to a third,
|
|
33
|
+
* server-side-only endpoint that the CLI never learns; wiring a client at
|
|
34
|
+
* that port produces a failure that reads like an auth error, which is why
|
|
35
|
+
* the facade returns these two explicitly instead of a host/port pair.
|
|
36
|
+
*/
|
|
37
|
+
controlUrl: string;
|
|
38
|
+
/** `host:port` of the tunnel DATA plane the client dials over raw TCP. */
|
|
39
|
+
tunnelAddr: string;
|
|
40
|
+
/** ISO8601. After this the binding is gone and the run can no longer attach. */
|
|
41
|
+
expiresAt: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* `GET /api/cli/v1/tunnel/{clientId}` — deliberately secret-free.
|
|
45
|
+
*
|
|
46
|
+
* `status` is an open string on the wire (resilience rule 2) even though the
|
|
47
|
+
* server has exactly two values today: an unknown value must degrade, never
|
|
48
|
+
* reject the response.
|
|
49
|
+
*/
|
|
50
|
+
export interface TunnelStatusResponse {
|
|
51
|
+
clientId: string;
|
|
52
|
+
status: 'online' | 'offline' | (string & {});
|
|
53
|
+
expiresAt: string;
|
|
54
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types for the `/api/cli/v1/tunnel` facade (DEV-747 piece 1).
|
|
3
|
+
*
|
|
4
|
+
* Three routes and deliberately no fourth — there is no resume/adopt route to
|
|
5
|
+
* hand a `{clientId, secret}` back to, so the CLI mints fresh per invocation.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=tunnel.types.js.map
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared V3-routing text surfaces
|
|
2
|
+
* Shared V3-routing text surfaces.
|
|
3
3
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `V3_ROUTING_ADVISORY`/`emitV3RoutingAdvisory` back `auth status` and
|
|
5
|
+
* `doctor`: `v3Enabled` on the `/me` response is the authoritative routing
|
|
6
|
+
* bit, and when it is on, some commands behave differently while the V3
|
|
7
|
+
* gaps stay open — the advisory names them. Copy lives here so both
|
|
8
|
+
* commands stay in sync.
|
|
9
|
+
*
|
|
10
|
+
* `targetUrlAdvisoryText`/`emitTargetUrlMismatchAdvisory` back the
|
|
11
|
+
* `--target-url` point-of-use advisory in `commands/test.ts` — a different,
|
|
12
|
+
* response-driven mechanism (see its own docblock below) that does not
|
|
13
|
+
* depend on `v3Enabled` at all.
|
|
7
14
|
*/
|
|
8
15
|
/** One-word routing label for the text card. */
|
|
9
16
|
export declare function routingLabel(v3Enabled: boolean): 'v3' | 'v2';
|
|
@@ -21,22 +28,28 @@ export declare const V3_ROUTING_ADVISORY: string[];
|
|
|
21
28
|
/** Write the advisory to a stderr sink, one line per call. */
|
|
22
29
|
export declare function emitV3RoutingAdvisory(stderr: (line: string) => void): void;
|
|
23
30
|
/**
|
|
24
|
-
* Point-of-use advisory for `test run --target-url
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* (
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* `
|
|
35
|
-
*
|
|
36
|
-
* (no "on
|
|
37
|
-
*
|
|
38
|
-
*
|
|
31
|
+
* Point-of-use advisory for `test run --target-url`, redesigned to be
|
|
32
|
+
* response-driven rather than assumption-driven. The original
|
|
33
|
+
* version probed `GET /me` for `v3Enabled` and warned on that ASSUMPTION —
|
|
34
|
+
* but the backend is the ground truth here, not a proxy for it. V3
|
|
35
|
+
* deliberately returns `targetUrl: ''` rather than echoing an override it
|
|
36
|
+
* did not apply ("so the response doesn't claim a target we didn't use"),
|
|
37
|
+
* while V2 echoes the real applied value. So the advisory now fires purely
|
|
38
|
+
* from comparing what the caller asked for against what the trigger
|
|
39
|
+
* response reports — it self-corrects the day the backend applies the
|
|
40
|
+
* override, needs no `v3Enabled` lookup (and so no extra `/me` round trip,
|
|
41
|
+
* no `X-CLI-Command` tagging machinery), and is exact rather than inferred.
|
|
42
|
+
*
|
|
43
|
+
* Deliberately type-agnostic in its wording (no "on the V3 path" claim):
|
|
44
|
+
* a mismatch is reported purely from the observed response, regardless of
|
|
45
|
+
* why the backend didn't apply the override.
|
|
46
|
+
*/
|
|
47
|
+
export declare function targetUrlAdvisoryText(requested: string, applied: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Compare the requested `--target-url` against what the trigger response
|
|
50
|
+
* reports and write the advisory when they differ. No-op when they match
|
|
51
|
+
* (the override was applied, or the caller didn't supply one — callers are
|
|
52
|
+
* expected to gate the `requested` argument on `opts.targetUrl !== undefined`
|
|
53
|
+
* themselves so this stays a pure comparison).
|
|
39
54
|
*/
|
|
40
|
-
export declare
|
|
41
|
-
/** Write the target-url advisory to a stderr sink. */
|
|
42
|
-
export declare function emitTargetUrlV3Advisory(stderr: (line: string) => void): void;
|
|
55
|
+
export declare function emitTargetUrlMismatchAdvisory(stderr: (line: string) => void, requested: string, applied: string): void;
|
package/dist/lib/v3-advisory.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared V3-routing text surfaces
|
|
2
|
+
* Shared V3-routing text surfaces.
|
|
3
3
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `V3_ROUTING_ADVISORY`/`emitV3RoutingAdvisory` back `auth status` and
|
|
5
|
+
* `doctor`: `v3Enabled` on the `/me` response is the authoritative routing
|
|
6
|
+
* bit, and when it is on, some commands behave differently while the V3
|
|
7
|
+
* gaps stay open — the advisory names them. Copy lives here so both
|
|
8
|
+
* commands stay in sync.
|
|
9
|
+
*
|
|
10
|
+
* `targetUrlAdvisoryText`/`emitTargetUrlMismatchAdvisory` back the
|
|
11
|
+
* `--target-url` point-of-use advisory in `commands/test.ts` — a different,
|
|
12
|
+
* response-driven mechanism (see its own docblock below) that does not
|
|
13
|
+
* depend on `v3Enabled` at all.
|
|
7
14
|
*/
|
|
8
15
|
/** One-word routing label for the text card. */
|
|
9
16
|
export function routingLabel(v3Enabled) {
|
|
@@ -30,26 +37,39 @@ export function emitV3RoutingAdvisory(stderr) {
|
|
|
30
37
|
stderr(line);
|
|
31
38
|
}
|
|
32
39
|
/**
|
|
33
|
-
* Point-of-use advisory for `test run --target-url
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* (
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* `
|
|
44
|
-
*
|
|
45
|
-
* (no "on
|
|
46
|
-
*
|
|
47
|
-
*
|
|
40
|
+
* Point-of-use advisory for `test run --target-url`, redesigned to be
|
|
41
|
+
* response-driven rather than assumption-driven. The original
|
|
42
|
+
* version probed `GET /me` for `v3Enabled` and warned on that ASSUMPTION —
|
|
43
|
+
* but the backend is the ground truth here, not a proxy for it. V3
|
|
44
|
+
* deliberately returns `targetUrl: ''` rather than echoing an override it
|
|
45
|
+
* did not apply ("so the response doesn't claim a target we didn't use"),
|
|
46
|
+
* while V2 echoes the real applied value. So the advisory now fires purely
|
|
47
|
+
* from comparing what the caller asked for against what the trigger
|
|
48
|
+
* response reports — it self-corrects the day the backend applies the
|
|
49
|
+
* override, needs no `v3Enabled` lookup (and so no extra `/me` round trip,
|
|
50
|
+
* no `X-CLI-Command` tagging machinery), and is exact rather than inferred.
|
|
51
|
+
*
|
|
52
|
+
* Deliberately type-agnostic in its wording (no "on the V3 path" claim):
|
|
53
|
+
* a mismatch is reported purely from the observed response, regardless of
|
|
54
|
+
* why the backend didn't apply the override.
|
|
55
|
+
*/
|
|
56
|
+
export function targetUrlAdvisoryText(requested, applied) {
|
|
57
|
+
const appliedClause = applied.length > 0
|
|
58
|
+
? `the run will use ${applied} instead`
|
|
59
|
+
: 'the run reports no target URL for it';
|
|
60
|
+
return (`[advisory] --target-url ${requested} was not applied to this run — ${appliedClause}. ` +
|
|
61
|
+
`The run used its own configured environment.`);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Compare the requested `--target-url` against what the trigger response
|
|
65
|
+
* reports and write the advisory when they differ. No-op when they match
|
|
66
|
+
* (the override was applied, or the caller didn't supply one — callers are
|
|
67
|
+
* expected to gate the `requested` argument on `opts.targetUrl !== undefined`
|
|
68
|
+
* themselves so this stays a pure comparison).
|
|
48
69
|
*/
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
stderr(TARGET_URL_V3_ADVISORY);
|
|
70
|
+
export function emitTargetUrlMismatchAdvisory(stderr, requested, applied) {
|
|
71
|
+
if (applied === requested)
|
|
72
|
+
return;
|
|
73
|
+
stderr(targetUrlAdvisoryText(requested, applied));
|
|
54
74
|
}
|
|
55
75
|
//# sourceMappingURL=v3-advisory.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ApiError, CLIError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* One member of a `--wait` fan-out poll (a single dispatched run's outcome).
|
|
4
|
+
* `status` is the terminal run status (`passed`/`failed`/`blocked`/…), or the
|
|
5
|
+
* synthesized `'timeout'` / `'error'` when the poll itself timed out or the
|
|
6
|
+
* run-read returned a typed `ApiError`. When `status === 'error'`, `error`
|
|
7
|
+
* carries that ApiError's `code` + `exitCode`.
|
|
8
|
+
*/
|
|
9
|
+
export interface WaitMemberResult {
|
|
10
|
+
testId?: string;
|
|
11
|
+
runId?: string;
|
|
12
|
+
status: string;
|
|
13
|
+
error?: {
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
exitCode?: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the process-level failure for a completed `--wait` fan-out, or `null`
|
|
21
|
+
* when every member passed. Shared by `test run --all` / `test rerun` and
|
|
22
|
+
* `testlist run` so their exit-code semantics can't drift.
|
|
23
|
+
*
|
|
24
|
+
* Precedence (see {@link WAIT_EXIT_PRIORITY}): auth / client-too-old → typed
|
|
25
|
+
* operational ApiError → timeout (7) → generic test-failure (1).
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveWaitFailure(results: readonly WaitMemberResult[], opts: {
|
|
28
|
+
timeoutSeconds: number;
|
|
29
|
+
}): CLIError | ApiError | null;
|