@testsprite/testsprite-cli 0.11.0 → 0.13.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 -44
- package/dist/commands/agent.js +16 -13
- package/dist/commands/auth.d.ts +19 -0
- package/dist/commands/auth.js +60 -24
- package/dist/commands/ci.d.ts +86 -1
- package/dist/commands/ci.js +470 -9
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +22 -9
- package/dist/commands/init.js +14 -11
- package/dist/commands/project-env.d.ts +90 -0
- package/dist/commands/project-env.js +486 -0
- package/dist/commands/project.d.ts +15 -5
- package/dist/commands/project.js +88 -92
- package/dist/commands/schedule.d.ts +2 -0
- package/dist/commands/schedule.js +18 -10
- package/dist/commands/test.d.ts +102 -30
- package/dist/commands/test.js +1949 -419
- package/dist/commands/testlist.js +77 -21
- package/dist/commands/tunnel.d.ts +26 -3
- package/dist/commands/tunnel.js +211 -14
- package/dist/commands/usage.d.ts +3 -0
- package/dist/commands/usage.js +12 -5
- package/dist/index.js +47 -23
- package/dist/lib/agent-targets.d.ts +3 -3
- package/dist/lib/agent-targets.js +2 -2
- package/dist/lib/billing-refusal.d.ts +43 -0
- package/dist/lib/billing-refusal.js +171 -0
- package/dist/lib/bundle.d.ts +5 -0
- package/dist/lib/bundle.js +43 -13
- package/dist/lib/ci-linkage.d.ts +90 -0
- package/dist/lib/ci-linkage.js +181 -0
- package/dist/lib/client-factory.d.ts +4 -1
- package/dist/lib/client-factory.js +25 -2
- package/dist/lib/client-tag.d.ts +13 -0
- package/dist/lib/client-tag.js +44 -0
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.js +20 -1
- package/dist/lib/conflict-reason.d.ts +67 -2
- package/dist/lib/conflict-reason.js +148 -13
- package/dist/lib/credentials.js +56 -14
- package/dist/lib/cron.js +8 -1
- package/dist/lib/dry-run/samples.d.ts +13 -1
- package/dist/lib/dry-run/samples.js +51 -7
- package/dist/lib/errors.d.ts +62 -12
- package/dist/lib/errors.js +180 -25
- package/dist/lib/failing-fe-resolver.d.ts +1 -1
- package/dist/lib/failing-fe-resolver.js +3 -3
- package/dist/lib/gh-output.d.ts +26 -11
- package/dist/lib/gh-output.js +47 -15
- package/dist/lib/history-retention.d.ts +8 -0
- package/dist/lib/history-retention.js +24 -0
- package/dist/lib/http.d.ts +44 -19
- package/dist/lib/http.js +53 -26
- package/dist/lib/interrupt.d.ts +21 -13
- package/dist/lib/interrupt.js +32 -21
- package/dist/lib/junit-report.d.ts +11 -1
- package/dist/lib/junit-report.js +15 -3
- package/dist/lib/local-target.d.ts +33 -1
- package/dist/lib/local-target.js +78 -1
- package/dist/lib/output.d.ts +27 -1
- package/dist/lib/output.js +22 -3
- package/dist/lib/plan-poll.d.ts +11 -11
- package/dist/lib/plan-poll.js +12 -12
- package/dist/lib/plans.types.d.ts +9 -9
- package/dist/lib/plans.types.js +3 -3
- package/dist/lib/poll.d.ts +2 -2
- package/dist/lib/poll.js +9 -3
- package/dist/lib/render-error.d.ts +2 -0
- package/dist/lib/render-error.js +13 -0
- package/dist/lib/response-schemas.d.ts +54 -12
- package/dist/lib/response-schemas.js +106 -7
- package/dist/lib/runs.types.d.ts +92 -6
- package/dist/lib/secret-file.js +72 -14
- package/dist/lib/skill-nudge.d.ts +6 -1
- package/dist/lib/skill-nudge.js +32 -5
- package/dist/lib/target-url-preflight.d.ts +6 -4
- package/dist/lib/target-url-preflight.js +64 -51
- package/dist/lib/target-url.js +31 -12
- package/dist/lib/telemetry.d.ts +172 -3
- package/dist/lib/telemetry.js +276 -15
- package/dist/lib/ticker.js +93 -4
- package/dist/lib/tunnel-session.d.ts +13 -0
- package/dist/lib/tunnel-session.js +4 -1
- package/dist/lib/tunnel.types.d.ts +12 -2
- package/dist/lib/tunnel.types.js +2 -2
- package/dist/lib/version-notice.d.ts +20 -1
- package/dist/lib/version-notice.js +59 -12
- package/dist/lib/wait-exit.d.ts +8 -0
- package/dist/lib/wait-exit.js +76 -4
- package/dist/lib/workspace-status.d.ts +23 -0
- package/dist/lib/workspace-status.js +15 -0
- package/dist/version-guard.d.ts +7 -1
- package/dist/version-guard.js +19 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/skills/testsprite-onboard.skill.md +4 -4
- package/skills/testsprite-verify.codex.md +59 -57
- package/skills/testsprite-verify.skill.md +53 -36
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
*/
|
|
45
45
|
import * as dns from 'node:dns';
|
|
46
46
|
import { isIP } from 'node:net';
|
|
47
|
-
import { ApiError } from './errors.js';
|
|
47
|
+
import { ApiError, InterruptError } from './errors.js';
|
|
48
|
+
import { globalShutdown } from './interrupt.js';
|
|
48
49
|
import { isProxyAgentActive } from './proxy.js';
|
|
49
50
|
import { disallowedIpReason } from './target-url.js';
|
|
50
51
|
/** ~8s, matching the MCP plugin's `checkPortListening` TCP-probe budget. */
|
|
@@ -93,10 +94,9 @@ function bareHost(hostname) {
|
|
|
93
94
|
}
|
|
94
95
|
/**
|
|
95
96
|
* Probe `rawUrl` for the narrow refusal set described in the module
|
|
96
|
-
* docstring.
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* shape via `assertNotLocal` before this runs).
|
|
97
|
+
* docstring. Network failures classify to `warn` or `refuse`, while a process
|
|
98
|
+
* interruption propagates. A malformed URL degrades to `warn` rather than
|
|
99
|
+
* crashing (callers validate the URL shape via `assertNotLocal` before this runs).
|
|
100
100
|
*/
|
|
101
101
|
export async function probeTargetUrl(rawUrl, deps = {}) {
|
|
102
102
|
const proxied = deps.proxyActive ?? isProxyAgentActive();
|
|
@@ -162,64 +162,77 @@ export async function probeTargetUrl(rawUrl, deps = {}) {
|
|
|
162
162
|
// configured — so this step (unlike the DNS step above) is proxy-aware
|
|
163
163
|
// by construction, not just proxy-tolerant.
|
|
164
164
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
|
|
165
|
+
const shutdownSignal = deps.shutdownSignal ?? globalShutdown.signal;
|
|
166
|
+
const shutdown = deps.shutdown ?? globalShutdown;
|
|
167
|
+
return shutdown.runCriticalOperation(async () => {
|
|
168
|
+
try {
|
|
169
|
+
const resp = await fetchImpl(rawUrl, {
|
|
170
|
+
method: 'GET',
|
|
171
|
+
// Never follow — see the module docstring. A 3xx is reachability
|
|
172
|
+
// proof on its own (handled immediately below); the redirect target
|
|
173
|
+
// is unvalidated and must not be dereferenced.
|
|
174
|
+
redirect: 'manual',
|
|
175
|
+
signal: AbortSignal.any([AbortSignal.timeout(PREFLIGHT_TIMEOUT_MS), shutdownSignal]),
|
|
176
|
+
});
|
|
177
|
+
// Never read the body — only the status matters here. Cancel it so the
|
|
178
|
+
// connection is released promptly instead of buffering a full page.
|
|
179
|
+
await resp.body?.cancel().catch(() => undefined);
|
|
180
|
+
if (shutdownSignal.aborted)
|
|
181
|
+
throw shutdownSignal.reason;
|
|
182
|
+
if (resp.status >= 300 && resp.status < 400) {
|
|
183
|
+
// A redirect is a live-server signal (e.g. a real app 302ing an
|
|
184
|
+
// unauthenticated GET to a login page) — reachable, not refused. The
|
|
185
|
+
// Location header is deliberately never inspected or dereferenced.
|
|
186
|
+
return { verdict: 'ok' };
|
|
187
|
+
}
|
|
188
|
+
if (GATEWAY_ERROR_STATUSES.has(resp.status)) {
|
|
189
|
+
if (proxied) {
|
|
190
|
+
return {
|
|
191
|
+
verdict: 'warn',
|
|
192
|
+
reason: `--target-url responded HTTP ${resp.status} — not conclusive behind a configured proxy`,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
verdict: 'refuse',
|
|
197
|
+
reason: `--target-url responded HTTP ${resp.status} (gateway error — the target is unreachable)`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (resp.status >= 400) {
|
|
201
|
+
return { verdict: 'warn', reason: `--target-url responded HTTP ${resp.status}` };
|
|
202
|
+
}
|
|
181
203
|
return { verdict: 'ok' };
|
|
182
204
|
}
|
|
183
|
-
|
|
184
|
-
if (
|
|
205
|
+
catch (err) {
|
|
206
|
+
if (shutdownSignal.aborted)
|
|
207
|
+
throw shutdownSignal.reason;
|
|
208
|
+
if (err instanceof InterruptError)
|
|
209
|
+
throw err;
|
|
210
|
+
if (errorHasCode(err, ['ECONNREFUSED'])) {
|
|
211
|
+
if (proxied) {
|
|
212
|
+
return {
|
|
213
|
+
verdict: 'warn',
|
|
214
|
+
reason: 'connection to --target-url was refused — not conclusive behind a configured proxy',
|
|
215
|
+
};
|
|
216
|
+
}
|
|
185
217
|
return {
|
|
186
|
-
verdict: '
|
|
187
|
-
reason:
|
|
218
|
+
verdict: 'refuse',
|
|
219
|
+
reason: 'connection to --target-url was refused (ECONNREFUSED)',
|
|
188
220
|
};
|
|
189
221
|
}
|
|
190
|
-
|
|
191
|
-
verdict: 'refuse',
|
|
192
|
-
reason: `--target-url responded HTTP ${resp.status} (gateway error — the target is unreachable)`,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
if (resp.status >= 400) {
|
|
196
|
-
return { verdict: 'warn', reason: `--target-url responded HTTP ${resp.status}` };
|
|
197
|
-
}
|
|
198
|
-
return { verdict: 'ok' };
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
if (errorHasCode(err, ['ECONNREFUSED'])) {
|
|
202
|
-
if (proxied) {
|
|
222
|
+
if (isTimeoutError(err)) {
|
|
203
223
|
return {
|
|
204
224
|
verdict: 'warn',
|
|
205
|
-
reason:
|
|
225
|
+
reason: `--target-url did not respond within ${PREFLIGHT_TIMEOUT_MS / 1000}s`,
|
|
206
226
|
};
|
|
207
227
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (isTimeoutError(err)) {
|
|
228
|
+
// TLS errors and anything else unclassified: warn only — the refusal
|
|
229
|
+
// set stays narrow to exactly what that analysis measured.
|
|
211
230
|
return {
|
|
212
231
|
verdict: 'warn',
|
|
213
|
-
reason:
|
|
232
|
+
reason: `could not reach --target-url (${err instanceof Error ? err.message : String(err)})`,
|
|
214
233
|
};
|
|
215
234
|
}
|
|
216
|
-
|
|
217
|
-
// set stays narrow to exactly what that analysis measured.
|
|
218
|
-
return {
|
|
219
|
-
verdict: 'warn',
|
|
220
|
-
reason: `could not reach --target-url (${err instanceof Error ? err.message : String(err)})`,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
235
|
+
});
|
|
223
236
|
}
|
|
224
237
|
/** Shared wording so `--help` and every refuse/warn message agree on the escape hatch. */
|
|
225
238
|
const SKIP_HINT = 'Skip this check entirely with --skip-preflight.';
|
|
@@ -240,7 +253,7 @@ export async function assertTargetUrlReachable(targetUrl, opts, deps, stderrFn)
|
|
|
240
253
|
throw ApiError.fromEnvelope({
|
|
241
254
|
error: {
|
|
242
255
|
code: 'VALIDATION_ERROR',
|
|
243
|
-
message: `--target-url is not reachable: ${outcome.reason}.`,
|
|
256
|
+
message: `--target-url is not reachable: ${outcome.reason}. Retry with --skip-preflight if the preview is still warming up.`,
|
|
244
257
|
nextAction: 'This CLI probes reachability from where the CLI runs, not from the Lambda that ' +
|
|
245
258
|
'executes the test — a false positive is possible (e.g. an IP allowlist that permits ' +
|
|
246
259
|
`the Lambda but not this machine). If you're confident the target is reachable from the ` +
|
package/dist/lib/target-url.js
CHANGED
|
@@ -34,14 +34,22 @@ import { ApiError } from './errors.js';
|
|
|
34
34
|
// the rest of `127.0.0.0/8`, which `--local` cannot dial by name at all. See
|
|
35
35
|
// `'loopback-other'` below for that distinction.
|
|
36
36
|
const LOCAL_DEV_RUNTIME_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
|
-
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
// Creation-time callers that take a per-run target (`test create
|
|
38
|
+
// --target-url`, which only applies with `--run`). A project or environment
|
|
39
|
+
// that names an app on this machine is created with `--local <port>`, so this
|
|
40
|
+
// says that instead of sending the reader after a public URL they may not have.
|
|
41
|
+
// It also serves the bind-all addresses (`0.0.0.0` / `::`), which are not
|
|
42
|
+
// loopback and are refused everywhere.
|
|
43
|
+
const LOCAL_DEV_BOOTSTRAP_HINT = 'TestSprite executes tests from the cloud, so the runner needs an address it can reach: ' +
|
|
44
|
+
'a deployed or staging URL. For an app that only runs on this machine, create the project ' +
|
|
45
|
+
'or environment with `--local <port>` instead of a URL, then run with ' +
|
|
46
|
+
'`testsprite test run <test-id> --local <port>`.';
|
|
47
|
+
/**
|
|
48
|
+
* `0.0.0.0` / `::` bind every interface, so an app listening there IS reachable
|
|
49
|
+
* on loopback — but the address itself is not loopback and the server refuses
|
|
50
|
+
* it as a stored URL. Naming the remedy is the whole point of the message.
|
|
51
|
+
*/
|
|
52
|
+
const UNSPECIFIED_ADDRESS_REASON = 'the unspecified address (0.0.0.0 / ::) is not allowed — use 127.0.0.1 or ::1 instead';
|
|
45
53
|
const LOCAL_PROJECT_CREATE_HINT = 'Use --local <port> instead of --url for an app on this machine. ' +
|
|
46
54
|
'Local projects are frontend-only and require the V3 project platform.';
|
|
47
55
|
const DEFAULT_TARGET_URL_CALLER = {
|
|
@@ -151,9 +159,15 @@ export function disallowedIpReason(host) {
|
|
|
151
159
|
return addressFamily === 4 ? disallowedIpv4Reason(bare) : undefined;
|
|
152
160
|
}
|
|
153
161
|
function disallowedIpv4Reason(address) {
|
|
154
|
-
// Unspecified — binds every interface, including loopback.
|
|
162
|
+
// Unspecified — binds every interface, including loopback. Named precisely
|
|
163
|
+
// rather than lumped in as "localhost": since a loopback URL is now a
|
|
164
|
+
// legitimate STORED target, calling `0.0.0.0` a localhost target produced a
|
|
165
|
+
// self-contradicting refusal — "localhost targets are not allowed" above a
|
|
166
|
+
// hint saying to use `localhost`. It is also simply not loopback: the
|
|
167
|
+
// server refuses it as a stored URL, so the accurate remedy is the loopback
|
|
168
|
+
// address the app is also reachable on.
|
|
155
169
|
if (address === '0.0.0.0') {
|
|
156
|
-
return { reason:
|
|
170
|
+
return { reason: UNSPECIFIED_ADDRESS_REASON, hintKind: 'loopback' };
|
|
157
171
|
}
|
|
158
172
|
// Only the literal 127.0.0.1 is in `--local-host`'s exact accepted set.
|
|
159
173
|
if (ipv4LoopbackBlocklist.check(address, 'ipv4')) {
|
|
@@ -323,8 +337,13 @@ function reclassifyEmbeddedIpv4(address, label) {
|
|
|
323
337
|
* it on the way in rather than trusting every caller to.
|
|
324
338
|
*/
|
|
325
339
|
function disallowedIpv6Reason(inner) {
|
|
326
|
-
//
|
|
327
|
-
|
|
340
|
+
// Unspecified (`::`) — see `disallowedIpv4Reason`'s note on why this is named
|
|
341
|
+
// separately from loopback.
|
|
342
|
+
if (inner === '::') {
|
|
343
|
+
return { reason: UNSPECIFIED_ADDRESS_REASON, hintKind: 'loopback' };
|
|
344
|
+
}
|
|
345
|
+
// Loopback (::1).
|
|
346
|
+
if (inner === '::1') {
|
|
328
347
|
return { reason: 'localhost targets are not allowed', hintKind: 'loopback' };
|
|
329
348
|
}
|
|
330
349
|
// Embedded-IPv4 family, checked mapped → NAT64 → compatible. Standard /96
|
package/dist/lib/telemetry.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RunConflict } from './conflict-reason.js';
|
|
1
2
|
/**
|
|
2
3
|
* Max time the flush-before-exit will wait on the beacon POST. Kept short so a
|
|
3
4
|
* slow/unreachable backend adds at most this to a command's exit (including
|
|
@@ -17,6 +18,23 @@ export interface TelemetryOutcomeInput extends Partial<WaitTimeoutTelemetry> {
|
|
|
17
18
|
exitCode: number;
|
|
18
19
|
/** Stable machine error code (e.g. `VALIDATION_ERROR`) — never a message. */
|
|
19
20
|
errorCode?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether `errorCode` was actually classified by the backend
|
|
23
|
+
* ('server') or fabricated client-side ('client' — a `--wait` timeout
|
|
24
|
+
* conversion, local pre-flight validation, a transport failure, an
|
|
25
|
+
* uncaught exception, …). Without this, a client-fabricated `UNSUPPORTED`
|
|
26
|
+
* (the `--wait` timeout bucket, exit 7) is indistinguishable in telemetry
|
|
27
|
+
* from a genuine backend 501 — see `classifyCliError()` for the exact
|
|
28
|
+
* discriminator.
|
|
29
|
+
*/
|
|
30
|
+
errorOrigin?: 'client' | 'server';
|
|
31
|
+
/**
|
|
32
|
+
* The effective timeout deadline (seconds) for an error event caused by a
|
|
33
|
+
* client-side timeout — either a per-request timeout (`RequestTimeoutError`)
|
|
34
|
+
* or a `--wait`/`--timeout` poll deadline surfaced as `UNSUPPORTED`. Absent
|
|
35
|
+
* for every other error.
|
|
36
|
+
*/
|
|
37
|
+
timeoutSeconds?: number;
|
|
20
38
|
durationMs: number;
|
|
21
39
|
/** Global flags, used to resolve config + fill context. */
|
|
22
40
|
profile?: string;
|
|
@@ -52,12 +70,123 @@ export interface ResolvedTelemetryAuth {
|
|
|
52
70
|
apiKey?: string;
|
|
53
71
|
apiUrl: string;
|
|
54
72
|
}
|
|
73
|
+
export type CiProvider = 'github' | 'gitlab' | 'circleci' | 'buildkite' | 'other' | 'none';
|
|
74
|
+
export type CiEvent = 'push' | 'pull_request' | 'schedule' | 'workflow_dispatch' | 'other';
|
|
75
|
+
/**
|
|
76
|
+
* Which CI system the process is running under, from the standard env markers
|
|
77
|
+
* each vendor documents. `other` is any CI that only sets the generic `CI`
|
|
78
|
+
* variable; `none` is an interactive/unknown context.
|
|
79
|
+
*/
|
|
80
|
+
export declare function detectCiProvider(env: NodeJS.ProcessEnv): CiProvider;
|
|
81
|
+
/**
|
|
82
|
+
* The GitHub Actions event that triggered the workflow, bucketed to a fixed
|
|
83
|
+
* vocabulary (`other` for everything outside it, e.g. `release`). Only
|
|
84
|
+
* meaningful under GitHub; undefined for every other provider and when the
|
|
85
|
+
* runner did not set `GITHUB_EVENT_NAME`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function detectCiEvent(env: NodeJS.ProcessEnv, provider: CiProvider): CiEvent | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Stable, non-reversible grouping key for a CI repository: the first 16 hex
|
|
90
|
+
* chars of `sha256('testsprite-ci-repo:' + slug)`. The salt prefix keeps the
|
|
91
|
+
* digest from matching a plain `sha256(slug)` lookup table; the slug itself
|
|
92
|
+
* never leaves the runner.
|
|
93
|
+
*/
|
|
94
|
+
export declare function hashRepository(slug: string): string;
|
|
95
|
+
/** The CI-context slice of the event (provider always present; the rest only when known). */
|
|
96
|
+
export declare function buildCiContext(env: NodeJS.ProcessEnv): {
|
|
97
|
+
ciProvider: CiProvider;
|
|
98
|
+
ciEvent?: CiEvent;
|
|
99
|
+
repoHash?: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Conflict reasons the beacon accepts for `conflictReason` (the backend DTO
|
|
103
|
+
* whitelist-strips anything else). Deliberately a SEPARATE vocabulary from
|
|
104
|
+
* `conflict-reason.ts`'s rendering type: `tunnel-required` is a server reason
|
|
105
|
+
* this CLI has no label for yet, and `not_found` is rendered but not counted.
|
|
106
|
+
*/
|
|
107
|
+
export type TelemetryConflictReason = 'in_flight' | 'insufficient_credits' | 'paused' | 'billing_hold' | 'mcp_view_only' | 'local_address' | 'tunnel-required' | 'error';
|
|
108
|
+
/**
|
|
109
|
+
* Low-cardinality facts a command records about its own outcome before it
|
|
110
|
+
* returns, merged into the one event `index.ts` fires. Counts are non-negative
|
|
111
|
+
* integers; enums are closed. Nothing here can carry an id, a URL, or a message.
|
|
112
|
+
*/
|
|
113
|
+
export interface TelemetryExtras {
|
|
114
|
+
/** Batch dispatch accounting (`test run --all`, `testlist run`). */
|
|
115
|
+
accepted?: number;
|
|
116
|
+
conflicts?: number;
|
|
117
|
+
deferred?: number;
|
|
118
|
+
skipped?: number;
|
|
119
|
+
/** Terminal verdict counts over the polled runs (`--wait` paths; 0/1 for a single run). */
|
|
120
|
+
passed?: number;
|
|
121
|
+
failed?: number;
|
|
122
|
+
blocked?: number;
|
|
123
|
+
timedOut?: number;
|
|
124
|
+
/** Local tunnel pool limit (1–10) and observed peak, without ids or target details. */
|
|
125
|
+
localConcurrencyLimit?: number;
|
|
126
|
+
localPeakInFlight?: number;
|
|
127
|
+
/** The most frequent conflict reason of the batch. */
|
|
128
|
+
conflictReason?: TelemetryConflictReason;
|
|
129
|
+
/** `ci init` facts. */
|
|
130
|
+
platform?: 'github';
|
|
131
|
+
force?: boolean;
|
|
132
|
+
workflowExisted?: boolean;
|
|
133
|
+
projectResolved?: 'flag' | 'auto';
|
|
134
|
+
}
|
|
135
|
+
/** What callers may hand the sanitizer: the typed shape, or an arbitrary bag it filters. */
|
|
136
|
+
export type TelemetryExtrasInput = TelemetryExtras | Readonly<Record<string, unknown>>;
|
|
137
|
+
/**
|
|
138
|
+
* Keep only the allowlisted keys with a value of the right shape. Pure: this is
|
|
139
|
+
* the single gate both the sink and the event builder run, so a stray field or
|
|
140
|
+
* a mistyped value can never reach the wire from either direction.
|
|
141
|
+
*/
|
|
142
|
+
export declare function sanitizeTelemetryExtras(partial: TelemetryExtrasInput): TelemetryExtras;
|
|
143
|
+
/**
|
|
144
|
+
* Record outcome facts for the event this process will fire. Called by a
|
|
145
|
+
* command just before it returns/throws; merged per key, so a later call for
|
|
146
|
+
* the same key wins and different commands' keys never collide. Values outside
|
|
147
|
+
* the allowlist (or of the wrong shape) are dropped silently — a caller can
|
|
148
|
+
* never widen the wire contract from here.
|
|
149
|
+
*/
|
|
150
|
+
export declare function recordTelemetryExtras(partial: TelemetryExtrasInput): void;
|
|
151
|
+
/** Return everything recorded so far and clear the sink (one event per process). */
|
|
152
|
+
export declare function takeTelemetryExtras(): TelemetryExtras;
|
|
153
|
+
/**
|
|
154
|
+
* Disjoint verdict counts over a set of polled runs — `passed` + `failed` +
|
|
155
|
+
* `blocked` + `timedOut` = total. Unlike the CI summary's `failed` (which folds
|
|
156
|
+
* blocked in), `blocked` is split out here because it is the signal that
|
|
157
|
+
* separates a broken target from a failing assertion.
|
|
158
|
+
*/
|
|
159
|
+
export declare function batchOutcomeCounts(results: ReadonlyArray<{
|
|
160
|
+
status: string;
|
|
161
|
+
}>): {
|
|
162
|
+
passed: number;
|
|
163
|
+
failed: number;
|
|
164
|
+
blocked: number;
|
|
165
|
+
timedOut: number;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Record a batch command's dispatch accounting (and, under `--wait`, its
|
|
169
|
+
* verdict counts) in one call, so `test run --all` and `testlist run` cannot
|
|
170
|
+
* drift in how they count. `conflictReason` is the dominant reason of the
|
|
171
|
+
* batch; `results` are the polled runs (omit for a non-wait dispatch).
|
|
172
|
+
*/
|
|
173
|
+
export declare function recordBatchOutcome(batch: {
|
|
174
|
+
accepted: number;
|
|
175
|
+
conflicts: readonly RunConflict[];
|
|
176
|
+
deferred: number;
|
|
177
|
+
skipped: number;
|
|
178
|
+
results?: ReadonlyArray<{
|
|
179
|
+
status: string;
|
|
180
|
+
}>;
|
|
181
|
+
}): void;
|
|
55
182
|
/** The exact wire body — a flat allowlist mirroring the backend DTO. */
|
|
56
|
-
export interface TelemetryEvent extends Partial<WaitTimeoutTelemetry
|
|
183
|
+
export interface TelemetryEvent extends Partial<WaitTimeoutTelemetry>, TelemetryExtras {
|
|
57
184
|
command: string;
|
|
58
185
|
outcome: TelemetryOutcome;
|
|
59
186
|
exitCode?: number;
|
|
60
187
|
errorCode?: string;
|
|
188
|
+
errorOrigin?: 'client' | 'server';
|
|
189
|
+
timeoutSeconds?: number;
|
|
61
190
|
durationMs?: number;
|
|
62
191
|
cliVersion?: string;
|
|
63
192
|
os?: string;
|
|
@@ -66,21 +195,61 @@ export interface TelemetryEvent extends Partial<WaitTimeoutTelemetry> {
|
|
|
66
195
|
ci?: boolean;
|
|
67
196
|
/** Present (always `true`) only for a `test run --local` invocation; absent otherwise. */
|
|
68
197
|
local?: boolean;
|
|
198
|
+
/** The validated `TESTSPRITE_CLIENT` tag (e.g. `github-action/v1`); absent when unset/invalid. */
|
|
199
|
+
client?: string;
|
|
200
|
+
ciProvider?: CiProvider;
|
|
201
|
+
ciEvent?: CiEvent;
|
|
202
|
+
repoHash?: string;
|
|
69
203
|
}
|
|
70
204
|
/**
|
|
71
205
|
* Map a thrown CLI error to its telemetry disposition — mirrors the exit-code
|
|
72
206
|
* mapping in `index.ts`'s top-level catch so telemetry and the process exit
|
|
73
207
|
* code never disagree. Pure; safe to unit-test.
|
|
208
|
+
*
|
|
209
|
+
* Every branch below now fills `errorCode` — the two fallback branches
|
|
210
|
+
* (`CLIError`, and the final catch-all for a non-CLIError throw) previously
|
|
211
|
+
* left it `undefined`, which is why a meaningful share of `test run`
|
|
212
|
+
* invocations and `setup` failures landed in telemetry with `errorCode=None`.
|
|
213
|
+
*
|
|
214
|
+
* `errorOrigin` ('client' | 'server') resolves a real UNSUPPORTED
|
|
215
|
+
* misclassification: prod data showed genuine backend 501 UNSUPPORTED
|
|
216
|
+
* responses are rare compared to the PostHog events carrying that code,
|
|
217
|
+
* because every `--wait` timeout is ALSO converted to a client-fabricated
|
|
218
|
+
* `UNSUPPORTED`/exit-7 envelope (exit 7 is the timeout bucket by design;
|
|
219
|
+
* this patch does not touch that contract, only observability).
|
|
220
|
+
*
|
|
221
|
+
* Discriminator: for an `ApiError`, `err.httpStatus !== undefined` iff the
|
|
222
|
+
* code came from a real HTTP response (http.ts passes `response.status` into
|
|
223
|
+
* `ApiError.fromEnvelope` on every non-OK response it parses) — every
|
|
224
|
+
* CLI-fabricated envelope (`localValidationError`, `ApiError.authRequired()`,
|
|
225
|
+
* `TransportError`, and every `throw ApiError.fromEnvelope({... requestId:
|
|
226
|
+
* 'local' ...})` timeout conversion in commands/test.ts) never passes an
|
|
227
|
+
* `httpStatus`, so it reads `undefined`. `requestId` was considered and
|
|
228
|
+
* REJECTED as the discriminator: http.ts stamps a real, non-'local'
|
|
229
|
+
* `x-request-id` (`newRequestId()`) on every OUTGOING request before it knows
|
|
230
|
+
* whether a response will ever arrive, so `TransportError` (a DNS/TLS
|
|
231
|
+
* failure that never got a response) carries a real requestId despite being
|
|
232
|
+
* 100% client-side — `requestId === 'local'` would have misclassified it as
|
|
233
|
+
* 'server'. All non-`ApiError` branches (`RequestTimeoutError`,
|
|
234
|
+
* `InterruptError`, a plain `CLIError`, `CommanderError`, and a genuinely
|
|
235
|
+
* uncaught exception) never involve an HTTP response at all, so they are
|
|
236
|
+
* unconditionally 'client'.
|
|
74
237
|
*/
|
|
75
238
|
export declare function classifyCliError(err: unknown): {
|
|
76
239
|
outcome: TelemetryOutcome;
|
|
77
240
|
exitCode: number;
|
|
78
241
|
errorCode?: string;
|
|
242
|
+
errorOrigin?: 'client' | 'server';
|
|
243
|
+
timeoutSeconds?: number;
|
|
79
244
|
};
|
|
80
245
|
/** True when the operator has opted out via either supported env var. */
|
|
81
246
|
export declare function isTelemetryOptedOut(env: NodeJS.ProcessEnv): boolean;
|
|
82
|
-
/**
|
|
83
|
-
|
|
247
|
+
/**
|
|
248
|
+
* Assemble the allowlisted wire event. No URL / message / flag value ever.
|
|
249
|
+
* `extras` are the per-command facts the sink collected (re-sanitized here so a
|
|
250
|
+
* direct caller cannot bypass the allowlist).
|
|
251
|
+
*/
|
|
252
|
+
export declare function buildTelemetryEvent(input: TelemetryOutcomeInput, env: NodeJS.ProcessEnv, isTTY: boolean, extras?: TelemetryExtrasInput): TelemetryEvent;
|
|
84
253
|
/**
|
|
85
254
|
* Resolve just the (apiKey, apiUrl) pair telemetry needs. Called once from the
|
|
86
255
|
* `index.ts` preAction hook — BEFORE the command's own action runs — so a
|