@testsprite/testsprite-cli 0.4.0 → 0.6.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 +27 -1
- package/dist/commands/agent.js +17 -6
- package/dist/commands/auth.d.ts +46 -0
- package/dist/commands/auth.js +37 -2
- package/dist/commands/completion.d.ts +36 -0
- package/dist/commands/completion.js +111 -0
- package/dist/commands/doctor.js +20 -2
- package/dist/commands/init.d.ts +32 -1
- package/dist/commands/init.js +40 -10
- package/dist/commands/project.d.ts +77 -3
- package/dist/commands/project.js +176 -43
- package/dist/commands/test.d.ts +200 -10
- package/dist/commands/test.js +1636 -351
- package/dist/commands/usage.d.ts +56 -17
- package/dist/commands/usage.js +144 -29
- package/dist/index.js +132 -26
- package/dist/lib/browser.d.ts +6 -0
- package/dist/lib/browser.js +54 -0
- package/dist/lib/bundle.d.ts +32 -31
- package/dist/lib/bundle.js +125 -83
- package/dist/lib/client-factory.d.ts +23 -0
- package/dist/lib/client-factory.js +33 -1
- package/dist/lib/config.js +7 -3
- package/dist/lib/credentials.d.ts +17 -1
- package/dist/lib/credentials.js +175 -16
- package/dist/lib/dry-run/samples.js +15 -1
- package/dist/lib/errors.d.ts +6 -1
- package/dist/lib/errors.js +70 -19
- package/dist/lib/flaky.d.ts +12 -1
- package/dist/lib/flaky.js +7 -12
- package/dist/lib/gh-output.d.ts +84 -0
- package/dist/lib/gh-output.js +202 -0
- package/dist/lib/http.d.ts +33 -15
- package/dist/lib/http.js +141 -7
- package/dist/lib/org-render.d.ts +52 -0
- package/dist/lib/org-render.js +59 -0
- package/dist/lib/poll.js +72 -36
- package/dist/lib/render-error.d.ts +14 -0
- package/dist/lib/render-error.js +30 -0
- package/dist/lib/response-schemas.d.ts +83 -0
- package/dist/lib/response-schemas.js +282 -0
- package/dist/lib/runs.types.d.ts +53 -8
- package/dist/lib/skill-nudge.d.ts +17 -0
- package/dist/lib/skill-nudge.js +19 -0
- package/dist/lib/telemetry.d.ts +90 -0
- package/dist/lib/telemetry.js +171 -0
- package/dist/lib/text-table.d.ts +14 -0
- package/dist/lib/text-table.js +45 -0
- package/dist/lib/v3-advisory.d.ts +30 -1
- package/dist/lib/v3-advisory.js +35 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +17 -5
- package/schemas/plan.schema.json +61 -0
- package/skills/testsprite-verify.codex.md +2 -2
- package/skills/testsprite-verify.skill.md +3 -3
package/dist/lib/runs.types.d.ts
CHANGED
|
@@ -38,6 +38,19 @@ export interface RerunClosure {
|
|
|
38
38
|
addedTeardowns: string[];
|
|
39
39
|
clearedCaptured: number;
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A machine-readable note that a requested option was forwarded to the
|
|
43
|
+
* execution engine but is not yet honored there. Emitted ONLY on a
|
|
44
|
+
* V3-routed rerun when the caller explicitly requested `autoHeal:false` —
|
|
45
|
+
* absent otherwise, including every V2 response and every V3 response that
|
|
46
|
+
* did not request an opt-out.
|
|
47
|
+
*/
|
|
48
|
+
export interface RerunAdvisory {
|
|
49
|
+
/** Machine-readable feature name the advisory concerns (e.g. "autoHeal"). */
|
|
50
|
+
feature: string;
|
|
51
|
+
/** Human-readable explanation of the current limitation. */
|
|
52
|
+
message: string;
|
|
53
|
+
}
|
|
41
54
|
/**
|
|
42
55
|
* Response from `POST /api/cli/v1/tests/{testId}/runs/rerun`.
|
|
43
56
|
* FE shape: no `closure`. BE shape: includes `closure` with per-member runIds.
|
|
@@ -58,6 +71,12 @@ export interface RerunResponse {
|
|
|
58
71
|
* the `!!closure` truthy check in the CLI already handles both).
|
|
59
72
|
*/
|
|
60
73
|
closure?: RerunClosure | null;
|
|
74
|
+
/**
|
|
75
|
+
* Present only when this rerun was routed to V3 execution AND the caller
|
|
76
|
+
* explicitly requested `autoHeal:false` (see {@link RerunAdvisory}). Absent
|
|
77
|
+
* on every other response, including older backends that predate the field.
|
|
78
|
+
*/
|
|
79
|
+
advisories?: RerunAdvisory[];
|
|
61
80
|
}
|
|
62
81
|
/**
|
|
63
82
|
* Body sent to `POST /api/cli/v1/tests/batch/rerun`.
|
|
@@ -106,6 +125,10 @@ export interface BatchRerunClosure {
|
|
|
106
125
|
* Present when the server supports partial-accept (SOME ids bad → 200 with accepted+notFound).
|
|
107
126
|
* When ALL ids are bad the server returns 404 (caught separately in the catch block).
|
|
108
127
|
* Optional for back-compat with older backends that don't send this field.
|
|
128
|
+
* `advisories` = present only when at least one FE test in the batch was routed to V3
|
|
129
|
+
* execution AND explicitly requested `autoHeal:false` (see {@link RerunAdvisory}).
|
|
130
|
+
* Absent on every other response. The CLI aggregates + dedupes this field across
|
|
131
|
+
* chunked dispatch requests (see `dedupeRerunAdvisories` in `commands/test.ts`).
|
|
109
132
|
*/
|
|
110
133
|
export interface BatchRerunResponse {
|
|
111
134
|
accepted: BatchRerunAccepted[];
|
|
@@ -113,6 +136,7 @@ export interface BatchRerunResponse {
|
|
|
113
136
|
conflicts: BatchRerunConflict[];
|
|
114
137
|
closure: BatchRerunClosure;
|
|
115
138
|
notFound?: string[];
|
|
139
|
+
advisories?: RerunAdvisory[];
|
|
116
140
|
}
|
|
117
141
|
/**
|
|
118
142
|
* Response from `POST /api/cli/v1/tests/{testId}/runs`.
|
|
@@ -174,8 +198,19 @@ export interface RunResponse {
|
|
|
174
198
|
createdAt: string;
|
|
175
199
|
startedAt: string | null;
|
|
176
200
|
finishedAt: string | null;
|
|
177
|
-
|
|
178
|
-
|
|
201
|
+
/**
|
|
202
|
+
* Code version stamped at trigger time. `null` on pre-M3.1 rows and on
|
|
203
|
+
* runs whose test has no stored code body (e.g. a plan-driven frontend
|
|
204
|
+
* test), per the server contract (`RunEnvelope.codeVersion` is
|
|
205
|
+
* `[string, 'null']`).
|
|
206
|
+
*/
|
|
207
|
+
codeVersion: string | null;
|
|
208
|
+
/**
|
|
209
|
+
* Target URL stamped at trigger time. `null` for backend runs and for any
|
|
210
|
+
* run whose execution backend does not record one, per the server contract
|
|
211
|
+
* (`RunEnvelope.targetUrl` is `[string, 'null']`).
|
|
212
|
+
*/
|
|
213
|
+
targetUrl: string | null;
|
|
179
214
|
createdFrom: string | null;
|
|
180
215
|
failedStepIndex: number | null;
|
|
181
216
|
failureKind: string | null;
|
|
@@ -186,12 +221,21 @@ export interface RunResponse {
|
|
|
186
221
|
/** Optional hint from the server; honored by the polling loop. */
|
|
187
222
|
retryAfterSeconds?: number;
|
|
188
223
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
224
|
+
* Portal deep link for this run's test.
|
|
225
|
+
*
|
|
226
|
+
* **Server-provided when present, client-synthesized otherwise.** Newer
|
|
227
|
+
* backends send this field on `GET /runs/{runId}` because only the server
|
|
228
|
+
* knows which store answered the read (a V3-served run's page is a different
|
|
229
|
+
* route family, and the V2 route it replaces cannot render for a V3-native
|
|
230
|
+
* project) and only the server can resolve the portal origin outside prod.
|
|
231
|
+
*
|
|
232
|
+
* A server `null` means "no correct link exists for this run" — the CLI
|
|
233
|
+
* treats it as absent for rendering and does NOT substitute its own guess.
|
|
234
|
+
* A missing field (older backend) reopens the client path: `resolvePortalUrl`
|
|
235
|
+
* from projectId+testId when the endpoint maps to a known portal host. See
|
|
236
|
+
* `withRunDashboardUrl` in `commands/test.ts`.
|
|
193
237
|
*/
|
|
194
|
-
dashboardUrl?: string;
|
|
238
|
+
dashboardUrl?: string | null;
|
|
195
239
|
/**
|
|
196
240
|
* Full ordered step list. Only present when the request includes
|
|
197
241
|
* `?includeSteps=true`. Absent (undefined) when the flag was not sent.
|
|
@@ -242,7 +286,8 @@ export interface RunHistoryItem {
|
|
|
242
286
|
/** May be null — backend doesn't always stamp it. */
|
|
243
287
|
startedAt: string | null;
|
|
244
288
|
finishedAt: string | null;
|
|
245
|
-
|
|
289
|
+
/** May be null — not stamped on pre-M3.2 rows or on tests with no code body. */
|
|
290
|
+
codeVersion: string | null;
|
|
246
291
|
/** Null when the run passed. */
|
|
247
292
|
failureKind: string | null;
|
|
248
293
|
/**
|
|
@@ -21,6 +21,23 @@ export declare const SKILL_NUDGE_COMMANDS: ReadonlySet<string>;
|
|
|
21
21
|
* the CLI by hand without wiring a coding agent.
|
|
22
22
|
*/
|
|
23
23
|
export declare const SKILL_NUDGE_OPT_OUT_ENV = "TESTSPRITE_NO_SKILL_WARNING";
|
|
24
|
+
/**
|
|
25
|
+
* True when this invocation is `test create --plan-template`, a
|
|
26
|
+
* pure-local/informational flag (prints the plan-file skeleton and exits)
|
|
27
|
+
* that must be treated like `setup` / `agent install`: exempt from BOTH the
|
|
28
|
+
* missing-skill nudge above AND the update-registry check
|
|
29
|
+
* (`src/lib/update-check.ts`'s `maybeNotifyUpdate`, which hits the network
|
|
30
|
+
* and writes `~/.testsprite/update-check.json` — both contradict "no
|
|
31
|
+
* network" for this flag). Neither allowlist (`SKILL_NUDGE_COMMANDS` here,
|
|
32
|
+
* the unconditional call site in `src/index.ts`) tracks individual flags,
|
|
33
|
+
* only whole commands, so `src/index.ts`'s `preAction` hook filters this one
|
|
34
|
+
* case via this pure, independently-testable helper instead of teaching
|
|
35
|
+
* either module about flags. Exported from `skill-nudge.ts` (rather than
|
|
36
|
+
* `src/index.ts`, which executes `program.parse()` at import time and so
|
|
37
|
+
* cannot be safely imported by a unit test) purely so it has a home that
|
|
38
|
+
* supports direct unit testing.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isPlanTemplateInvocation(commandPath: string, planTemplate: boolean | undefined): boolean;
|
|
24
41
|
export interface SkillPresenceDeps {
|
|
25
42
|
existsSync?: (p: string) => boolean;
|
|
26
43
|
readFileSync?: (p: string) => string;
|
package/dist/lib/skill-nudge.js
CHANGED
|
@@ -31,6 +31,25 @@ export const SKILL_NUDGE_COMMANDS = new Set([
|
|
|
31
31
|
* the CLI by hand without wiring a coding agent.
|
|
32
32
|
*/
|
|
33
33
|
export const SKILL_NUDGE_OPT_OUT_ENV = 'TESTSPRITE_NO_SKILL_WARNING';
|
|
34
|
+
/**
|
|
35
|
+
* True when this invocation is `test create --plan-template`, a
|
|
36
|
+
* pure-local/informational flag (prints the plan-file skeleton and exits)
|
|
37
|
+
* that must be treated like `setup` / `agent install`: exempt from BOTH the
|
|
38
|
+
* missing-skill nudge above AND the update-registry check
|
|
39
|
+
* (`src/lib/update-check.ts`'s `maybeNotifyUpdate`, which hits the network
|
|
40
|
+
* and writes `~/.testsprite/update-check.json` — both contradict "no
|
|
41
|
+
* network" for this flag). Neither allowlist (`SKILL_NUDGE_COMMANDS` here,
|
|
42
|
+
* the unconditional call site in `src/index.ts`) tracks individual flags,
|
|
43
|
+
* only whole commands, so `src/index.ts`'s `preAction` hook filters this one
|
|
44
|
+
* case via this pure, independently-testable helper instead of teaching
|
|
45
|
+
* either module about flags. Exported from `skill-nudge.ts` (rather than
|
|
46
|
+
* `src/index.ts`, which executes `program.parse()` at import time and so
|
|
47
|
+
* cannot be safely imported by a unit test) purely so it has a home that
|
|
48
|
+
* supports direct unit testing.
|
|
49
|
+
*/
|
|
50
|
+
export function isPlanTemplateInvocation(commandPath, planTemplate) {
|
|
51
|
+
return commandPath === 'test create' && planTemplate === true;
|
|
52
|
+
}
|
|
34
53
|
/**
|
|
35
54
|
* True if the `testsprite-verify` skill is installed for ANY supported agent in
|
|
36
55
|
* `dir`. own-file targets (claude/cursor/cline/antigravity): the landing file
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Max time the flush-before-exit will wait on the beacon POST. Kept short so a
|
|
3
|
+
* slow/unreachable backend adds at most this to a command's exit (including
|
|
4
|
+
* Ctrl-C); a healthy POST completes in well under it, and when it doesn't,
|
|
5
|
+
* dropping the event is the correct best-effort behavior.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TELEMETRY_TIMEOUT_MS = 1000;
|
|
8
|
+
export type TelemetryOutcome = 'success' | 'error' | 'abort';
|
|
9
|
+
export interface TelemetryOutcomeInput {
|
|
10
|
+
/** Leaf command path that ran, e.g. `test run`. Empty → skip (no command). */
|
|
11
|
+
command: string;
|
|
12
|
+
outcome: TelemetryOutcome;
|
|
13
|
+
exitCode: number;
|
|
14
|
+
/** Stable machine error code (e.g. `VALIDATION_ERROR`) — never a message. */
|
|
15
|
+
errorCode?: string;
|
|
16
|
+
durationMs: number;
|
|
17
|
+
/** Global flags, used to resolve config + fill context. */
|
|
18
|
+
profile?: string;
|
|
19
|
+
endpointUrl?: string;
|
|
20
|
+
output?: string;
|
|
21
|
+
dryRun?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface TelemetryDeps {
|
|
24
|
+
env?: NodeJS.ProcessEnv;
|
|
25
|
+
credentialsPath?: string;
|
|
26
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
27
|
+
/** Test seam for TTY detection (CI/non-interactive context prop). */
|
|
28
|
+
isTTY?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Auth pre-resolved by the caller (the preAction hook). When present,
|
|
31
|
+
* recordOutcome uses it verbatim instead of re-reading the credentials file —
|
|
32
|
+
* so a command that mutates that file (`auth remove` deletes the profile) is
|
|
33
|
+
* still reported on the key it ran under.
|
|
34
|
+
*/
|
|
35
|
+
resolvedAuth?: ResolvedTelemetryAuth;
|
|
36
|
+
}
|
|
37
|
+
/** The (apiKey, apiUrl) pair telemetry needs, resolved once per invocation. */
|
|
38
|
+
export interface ResolvedTelemetryAuth {
|
|
39
|
+
apiKey?: string;
|
|
40
|
+
apiUrl: string;
|
|
41
|
+
}
|
|
42
|
+
/** The exact wire body — a flat allowlist mirroring the backend DTO. */
|
|
43
|
+
export interface TelemetryEvent {
|
|
44
|
+
command: string;
|
|
45
|
+
outcome: TelemetryOutcome;
|
|
46
|
+
exitCode?: number;
|
|
47
|
+
errorCode?: string;
|
|
48
|
+
durationMs?: number;
|
|
49
|
+
cliVersion?: string;
|
|
50
|
+
os?: string;
|
|
51
|
+
nodeVersion?: string;
|
|
52
|
+
output?: string;
|
|
53
|
+
ci?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Map a thrown CLI error to its telemetry disposition — mirrors the exit-code
|
|
57
|
+
* mapping in `index.ts`'s top-level catch so telemetry and the process exit
|
|
58
|
+
* code never disagree. Pure; safe to unit-test.
|
|
59
|
+
*/
|
|
60
|
+
export declare function classifyCliError(err: unknown): {
|
|
61
|
+
outcome: TelemetryOutcome;
|
|
62
|
+
exitCode: number;
|
|
63
|
+
errorCode?: string;
|
|
64
|
+
};
|
|
65
|
+
/** True when the operator has opted out via either supported env var. */
|
|
66
|
+
export declare function isTelemetryOptedOut(env: NodeJS.ProcessEnv): boolean;
|
|
67
|
+
/** Assemble the allowlisted wire event. No URL / message / flag value ever. */
|
|
68
|
+
export declare function buildTelemetryEvent(input: TelemetryOutcomeInput, env: NodeJS.ProcessEnv, isTTY: boolean): TelemetryEvent;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve just the (apiKey, apiUrl) pair telemetry needs. Called once from the
|
|
71
|
+
* `index.ts` preAction hook — BEFORE the command's own action runs — so a
|
|
72
|
+
* command that mutates the credentials file (`auth remove` deletes the profile)
|
|
73
|
+
* is still reported on the key it ran under. The hook only calls this for a
|
|
74
|
+
* telemetry-eligible, non-opted-out, non-dry-run invocation, so a gated-out or
|
|
75
|
+
* opted-out call never reads the credentials file.
|
|
76
|
+
*/
|
|
77
|
+
export declare function resolveTelemetryAuth(opts: {
|
|
78
|
+
profile?: string;
|
|
79
|
+
endpointUrl?: string;
|
|
80
|
+
}, deps?: {
|
|
81
|
+
env?: NodeJS.ProcessEnv;
|
|
82
|
+
credentialsPath?: string;
|
|
83
|
+
}): ResolvedTelemetryAuth;
|
|
84
|
+
/**
|
|
85
|
+
* Fire one command-outcome event to the beacon. Awaited by `index.ts` before
|
|
86
|
+
* `process.exit` (the flush) — bounded and fully best-effort, so it can neither
|
|
87
|
+
* hang nor throw. Skips silently when opted out, under dry-run, with no leaf
|
|
88
|
+
* command, or when no api-key is configured.
|
|
89
|
+
*/
|
|
90
|
+
export declare function recordOutcome(input: TelemetryOutcomeInput, deps?: TelemetryDeps): Promise<void>;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side telemetry: one "command outcome" event per CLI invocation,
|
|
3
|
+
* fired to the backend beacon (`POST /api/cli/v1/telemetry`), which forwards it
|
|
4
|
+
* to PostHog server-side. The CLI ships no PostHog SDK / write-key.
|
|
5
|
+
*
|
|
6
|
+
* Contract:
|
|
7
|
+
* - Best-effort: every failure is swallowed; telemetry NEVER changes a
|
|
8
|
+
* command's behavior, output, or exit code.
|
|
9
|
+
* - Bounded: the POST is aborted after {@link TELEMETRY_TIMEOUT_MS}, so the
|
|
10
|
+
* flush-before-exit can add at most that long to a slow/unreachable-backend
|
|
11
|
+
* invocation (normal case is a sub-200ms POST).
|
|
12
|
+
* - Authenticated-only: skipped when no api-key is configured (the backend
|
|
13
|
+
* keys the event on the api-key's user; anonymous events are out of scope).
|
|
14
|
+
* - Opt-out: skipped when `TESTSPRITE_NO_TELEMETRY` or the cross-tool
|
|
15
|
+
* `DO_NOT_TRACK` is set. Also skipped under `--dry-run` (no network) and
|
|
16
|
+
* when no leaf command actually ran (bare `--help` / parse errors).
|
|
17
|
+
* - Never on abort (SIGINT/SIGTERM): Ctrl-C must exit immediately, so the
|
|
18
|
+
* abort path emits nothing (awaiting would delay shutdown; fire-and-forget
|
|
19
|
+
* would be cut off before delivery anyway).
|
|
20
|
+
*
|
|
21
|
+
* Privacy: the event is a fixed allowlist of low-cardinality, PII-free fields.
|
|
22
|
+
* It NEVER carries target URLs, api keys, flag values, arg values, or error
|
|
23
|
+
* messages — `errorCode` is a stable machine code, never the human message.
|
|
24
|
+
*/
|
|
25
|
+
import { CommanderError } from 'commander';
|
|
26
|
+
import { loadConfig } from './config.js';
|
|
27
|
+
import { defaultCredentialsPath } from './credentials.js';
|
|
28
|
+
import { ApiError, CLIError, InterruptError, RequestTimeoutError } from './errors.js';
|
|
29
|
+
import { facadeBaseUrl } from './facade.js';
|
|
30
|
+
import { VERSION } from '../version.js';
|
|
31
|
+
/**
|
|
32
|
+
* Max time the flush-before-exit will wait on the beacon POST. Kept short so a
|
|
33
|
+
* slow/unreachable backend adds at most this to a command's exit (including
|
|
34
|
+
* Ctrl-C); a healthy POST completes in well under it, and when it doesn't,
|
|
35
|
+
* dropping the event is the correct best-effort behavior.
|
|
36
|
+
*/
|
|
37
|
+
export const TELEMETRY_TIMEOUT_MS = 1000;
|
|
38
|
+
/**
|
|
39
|
+
* Map a thrown CLI error to its telemetry disposition — mirrors the exit-code
|
|
40
|
+
* mapping in `index.ts`'s top-level catch so telemetry and the process exit
|
|
41
|
+
* code never disagree. Pure; safe to unit-test.
|
|
42
|
+
*/
|
|
43
|
+
export function classifyCliError(err) {
|
|
44
|
+
if (err instanceof InterruptError) {
|
|
45
|
+
return { outcome: 'abort', exitCode: err.exitCode, errorCode: 'INTERRUPTED' };
|
|
46
|
+
}
|
|
47
|
+
if (err instanceof RequestTimeoutError) {
|
|
48
|
+
return { outcome: 'error', exitCode: err.exitCode, errorCode: 'REQUEST_TIMEOUT' };
|
|
49
|
+
}
|
|
50
|
+
if (err instanceof ApiError) {
|
|
51
|
+
return { outcome: 'error', exitCode: err.exitCode, errorCode: err.code };
|
|
52
|
+
}
|
|
53
|
+
if (err instanceof CommanderError) {
|
|
54
|
+
// Help / version are user-requested successes (exit 0); everything else
|
|
55
|
+
// Commander throws is a parse/validation error (exit 5).
|
|
56
|
+
if (err.code === 'commander.helpDisplayed' ||
|
|
57
|
+
err.code === 'commander.help' ||
|
|
58
|
+
err.code === 'commander.version') {
|
|
59
|
+
return { outcome: 'success', exitCode: 0 };
|
|
60
|
+
}
|
|
61
|
+
return { outcome: 'error', exitCode: 5, errorCode: 'VALIDATION_ERROR' };
|
|
62
|
+
}
|
|
63
|
+
if (err instanceof CLIError) {
|
|
64
|
+
return { outcome: 'error', exitCode: err.exitCode };
|
|
65
|
+
}
|
|
66
|
+
return { outcome: 'error', exitCode: 1 };
|
|
67
|
+
}
|
|
68
|
+
/** True when the operator has opted out via either supported env var. */
|
|
69
|
+
export function isTelemetryOptedOut(env) {
|
|
70
|
+
return isTruthyEnv(env.TESTSPRITE_NO_TELEMETRY) || isTruthyEnv(env.DO_NOT_TRACK);
|
|
71
|
+
}
|
|
72
|
+
function isTruthyEnv(v) {
|
|
73
|
+
if (v === undefined)
|
|
74
|
+
return false;
|
|
75
|
+
const t = v.trim().toLowerCase();
|
|
76
|
+
return t !== '' && t !== '0' && t !== 'false';
|
|
77
|
+
}
|
|
78
|
+
/** Assemble the allowlisted wire event. No URL / message / flag value ever. */
|
|
79
|
+
export function buildTelemetryEvent(input, env, isTTY) {
|
|
80
|
+
return {
|
|
81
|
+
command: input.command,
|
|
82
|
+
outcome: input.outcome,
|
|
83
|
+
exitCode: input.exitCode,
|
|
84
|
+
...(input.errorCode ? { errorCode: input.errorCode } : {}),
|
|
85
|
+
durationMs: input.durationMs,
|
|
86
|
+
cliVersion: VERSION,
|
|
87
|
+
os: process.platform,
|
|
88
|
+
nodeVersion: process.versions.node,
|
|
89
|
+
...(input.output === 'json' || input.output === 'text' ? { output: input.output } : {}),
|
|
90
|
+
ci: isTruthyEnv(env.CI) || !isTTY,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Resolve just the (apiKey, apiUrl) pair telemetry needs. Called once from the
|
|
95
|
+
* `index.ts` preAction hook — BEFORE the command's own action runs — so a
|
|
96
|
+
* command that mutates the credentials file (`auth remove` deletes the profile)
|
|
97
|
+
* is still reported on the key it ran under. The hook only calls this for a
|
|
98
|
+
* telemetry-eligible, non-opted-out, non-dry-run invocation, so a gated-out or
|
|
99
|
+
* opted-out call never reads the credentials file.
|
|
100
|
+
*/
|
|
101
|
+
export function resolveTelemetryAuth(opts, deps = {}) {
|
|
102
|
+
const config = loadConfig({
|
|
103
|
+
profile: opts.profile ?? 'default',
|
|
104
|
+
endpointUrl: opts.endpointUrl,
|
|
105
|
+
env: deps.env ?? process.env,
|
|
106
|
+
credentialsPath: deps.credentialsPath ?? defaultCredentialsPath(),
|
|
107
|
+
});
|
|
108
|
+
return { apiKey: config.apiKey, apiUrl: config.apiUrl };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Fire one command-outcome event to the beacon. Awaited by `index.ts` before
|
|
112
|
+
* `process.exit` (the flush) — bounded and fully best-effort, so it can neither
|
|
113
|
+
* hang nor throw. Skips silently when opted out, under dry-run, with no leaf
|
|
114
|
+
* command, or when no api-key is configured.
|
|
115
|
+
*/
|
|
116
|
+
export async function recordOutcome(input, deps = {}) {
|
|
117
|
+
try {
|
|
118
|
+
const env = deps.env ?? process.env;
|
|
119
|
+
if (isTelemetryOptedOut(env))
|
|
120
|
+
return;
|
|
121
|
+
if (input.dryRun)
|
|
122
|
+
return;
|
|
123
|
+
if (!input.command)
|
|
124
|
+
return; // no leaf command ran (bare --help / parse error)
|
|
125
|
+
// Never on the abort path: Ctrl-C / SIGTERM must exit immediately. Awaiting
|
|
126
|
+
// a beacon post here would delay shutdown by up to the bounded timeout, and
|
|
127
|
+
// a fire-and-forget post would be cut off by process.exit before delivery —
|
|
128
|
+
// so the event would be unreliable anyway. Aborts are simply not reported.
|
|
129
|
+
if (input.outcome === 'abort')
|
|
130
|
+
return;
|
|
131
|
+
// Prefer auth the preAction hook already resolved (before a command like
|
|
132
|
+
// `auth remove` could delete the profile); fall back to a fresh read.
|
|
133
|
+
const config = deps.resolvedAuth ??
|
|
134
|
+
loadConfig({
|
|
135
|
+
profile: input.profile ?? 'default',
|
|
136
|
+
endpointUrl: input.endpointUrl,
|
|
137
|
+
env,
|
|
138
|
+
credentialsPath: deps.credentialsPath ?? defaultCredentialsPath(),
|
|
139
|
+
});
|
|
140
|
+
if (!config.apiKey)
|
|
141
|
+
return; // authenticated-only
|
|
142
|
+
const url = `${facadeBaseUrl(config.apiUrl)}/telemetry`;
|
|
143
|
+
const isTTY = deps.isTTY ?? process.stderr.isTTY === true;
|
|
144
|
+
const body = buildTelemetryEvent(input, env, isTTY);
|
|
145
|
+
const fetchImpl = deps.fetchImpl ?? globalThis.fetch;
|
|
146
|
+
const controller = new AbortController();
|
|
147
|
+
const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
|
|
148
|
+
// Don't keep the event loop alive just for the timer.
|
|
149
|
+
if (typeof timer.unref === 'function')
|
|
150
|
+
timer.unref();
|
|
151
|
+
try {
|
|
152
|
+
await fetchImpl(url, {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
headers: {
|
|
155
|
+
'content-type': 'application/json',
|
|
156
|
+
'x-api-key': config.apiKey,
|
|
157
|
+
'user-agent': `testsprite-cli/${VERSION}`,
|
|
158
|
+
},
|
|
159
|
+
body: JSON.stringify(body),
|
|
160
|
+
signal: controller.signal,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
clearTimeout(timer);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
// Best-effort: telemetry must never affect the command.
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=telemetry.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface TextTableColumn<T> {
|
|
2
|
+
header: string;
|
|
3
|
+
width: number | ((rows: readonly T[]) => number);
|
|
4
|
+
render: (row: T) => string;
|
|
5
|
+
}
|
|
6
|
+
export interface TextTableOptions {
|
|
7
|
+
columns?: string;
|
|
8
|
+
noHeader?: boolean;
|
|
9
|
+
separator?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function renderTextTable<T>(rows: readonly T[], columns: readonly TextTableColumn<T>[], options?: TextTableOptions): string;
|
|
12
|
+
export declare function resolveTextColumns<T>(raw: string | undefined, columns: readonly TextTableColumn<T>[]): readonly TextTableColumn<T>[];
|
|
13
|
+
export declare function measureTextColumns<T>(rows: readonly T[], columns: readonly TextTableColumn<T>[]): number[];
|
|
14
|
+
export declare function formatTextTableRow(values: readonly string[], widths: readonly number[]): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { localValidationError } from './errors.js';
|
|
2
|
+
export function renderTextTable(rows, columns, options = {}) {
|
|
3
|
+
const selected = resolveTextColumns(options.columns, columns);
|
|
4
|
+
const widths = measureTextColumns(rows, selected);
|
|
5
|
+
const body = rows.map(row => formatTextTableRow(selected.map(column => column.render(row)), widths));
|
|
6
|
+
if (options.noHeader === true)
|
|
7
|
+
return body.join('\n');
|
|
8
|
+
const header = formatTextTableRow(selected.map(column => column.header), widths);
|
|
9
|
+
return [header, ...(options.separator === true ? ['-'.repeat(header.length)] : []), ...body].join('\n');
|
|
10
|
+
}
|
|
11
|
+
export function resolveTextColumns(raw, columns) {
|
|
12
|
+
if (raw === undefined || raw.trim() === '')
|
|
13
|
+
return columns;
|
|
14
|
+
const byKey = new Map(columns.map(column => [textColumnKey(column.header), column]));
|
|
15
|
+
const validKeys = columns.map(column => textColumnKey(column.header));
|
|
16
|
+
const requested = raw.split(',').map(token => token.trim());
|
|
17
|
+
if (requested.some(token => token.length === 0)) {
|
|
18
|
+
throw localValidationError('columns', `must be a comma-separated list of: ${validKeys.join(', ')}`, validKeys);
|
|
19
|
+
}
|
|
20
|
+
return requested.map(token => {
|
|
21
|
+
const key = textColumnKey(token);
|
|
22
|
+
const column = byKey.get(key);
|
|
23
|
+
if (column === undefined) {
|
|
24
|
+
throw localValidationError('columns', `unknown column "${token}"; must be one of: ${validKeys.join(', ')}`, validKeys);
|
|
25
|
+
}
|
|
26
|
+
return column;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export function measureTextColumns(rows, columns) {
|
|
30
|
+
return columns.map(column => typeof column.width === 'function' ? column.width(rows) : column.width);
|
|
31
|
+
}
|
|
32
|
+
export function formatTextTableRow(values, widths) {
|
|
33
|
+
return values
|
|
34
|
+
.map((value, index) => (index === values.length - 1 ? value : pad(value, widths[index] ?? 0)))
|
|
35
|
+
.join(' ');
|
|
36
|
+
}
|
|
37
|
+
function textColumnKey(value) {
|
|
38
|
+
return value.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
39
|
+
}
|
|
40
|
+
function pad(value, width) {
|
|
41
|
+
if (value.length >= width)
|
|
42
|
+
return value;
|
|
43
|
+
return value + ' '.repeat(width - value.length);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=text-table.js.map
|
|
@@ -7,7 +7,36 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/** One-word routing label for the text card. */
|
|
9
9
|
export declare function routingLabel(v3Enabled: boolean): 'v3' | 'v2';
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Consolidated advisory (stderr) emitted when V3 routing is on.
|
|
12
|
+
*
|
|
13
|
+
* Only genuinely-open gaps belong here. Two originally-listed items have
|
|
14
|
+
* shipped and were removed: `test cancel` works on V3 runs, and `test delete`
|
|
15
|
+
* mirrors into Postgres instead of leaving a runnable, billable row behind.
|
|
16
|
+
* An advisory that warns about fixed behavior is worse than none — it teaches
|
|
17
|
+
* users to distrust the whole block, and it sends them chasing a failure that
|
|
18
|
+
* cannot happen.
|
|
19
|
+
*/
|
|
11
20
|
export declare const V3_ROUTING_ADVISORY: string[];
|
|
12
21
|
/** Write the advisory to a stderr sink, one line per call. */
|
|
13
22
|
export declare function emitV3RoutingAdvisory(stderr: (line: string) => void): void;
|
|
23
|
+
/**
|
|
24
|
+
* Point-of-use advisory for `test run --target-url` on a V3-routed caller
|
|
25
|
+
* (DEV-749). `V3_ROUTING_ADVISORY` above already names this gap once, in
|
|
26
|
+
* the account-level summary `auth status`/`doctor` print — this is the
|
|
27
|
+
* SAME gap surfaced at the moment the caller actually hits it, matching
|
|
28
|
+
* the existing backend-test `--target-url` advisory in `runCreate`
|
|
29
|
+
* (`commands/test.ts`): unconditional across every `--output` mode. That
|
|
30
|
+
* advisory's family is "a flag the caller just passed has a structural
|
|
31
|
+
* consequence" — `--output json` is precisely the unattended/CI case that
|
|
32
|
+
* needs the warning most, not the case to withhold it from (unlike the
|
|
33
|
+
* routing-advisory family above, which a JSON caller can skip by reading
|
|
34
|
+
* `v3Enabled` directly off that command's own structured output — `test
|
|
35
|
+
* run`'s JSON output carries no such field). Deliberately type-agnostic
|
|
36
|
+
* (no "on frontend runs" claim): the CLI cannot learn a test's type at
|
|
37
|
+
* `test run <existing-test-id>` time without an extra round trip, and the
|
|
38
|
+
* override is equally inert on the V3 backend-run path.
|
|
39
|
+
*/
|
|
40
|
+
export declare const TARGET_URL_V3_ADVISORY: string;
|
|
41
|
+
/** Write the target-url advisory to a stderr sink. */
|
|
42
|
+
export declare function emitTargetUrlV3Advisory(stderr: (line: string) => void): void;
|
package/dist/lib/v3-advisory.js
CHANGED
|
@@ -9,16 +9,47 @@
|
|
|
9
9
|
export function routingLabel(v3Enabled) {
|
|
10
10
|
return v3Enabled ? 'v3' : 'v2';
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Consolidated advisory (stderr) emitted when V3 routing is on.
|
|
14
|
+
*
|
|
15
|
+
* Only genuinely-open gaps belong here. Two originally-listed items have
|
|
16
|
+
* shipped and were removed: `test cancel` works on V3 runs, and `test delete`
|
|
17
|
+
* mirrors into Postgres instead of leaving a runnable, billable row behind.
|
|
18
|
+
* An advisory that warns about fixed behavior is worse than none — it teaches
|
|
19
|
+
* users to distrust the whole block, and it sends them chasing a failure that
|
|
20
|
+
* cannot happen.
|
|
21
|
+
*/
|
|
13
22
|
export const V3_ROUTING_ADVISORY = [
|
|
14
23
|
'[advisory] V3 routing is on for this account. While these gaps are open:',
|
|
15
|
-
' - `
|
|
16
|
-
' -
|
|
17
|
-
' - `--target-url` is ignored on frontend runs',
|
|
24
|
+
' - `--target-url` is ignored on frontend runs (the run uses the project environment)',
|
|
25
|
+
' - a frontend rerun replays the run it was pointed at, not necessarily the latest saved code',
|
|
18
26
|
];
|
|
19
27
|
/** Write the advisory to a stderr sink, one line per call. */
|
|
20
28
|
export function emitV3RoutingAdvisory(stderr) {
|
|
21
29
|
for (const line of V3_ROUTING_ADVISORY)
|
|
22
30
|
stderr(line);
|
|
23
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Point-of-use advisory for `test run --target-url` on a V3-routed caller
|
|
34
|
+
* (DEV-749). `V3_ROUTING_ADVISORY` above already names this gap once, in
|
|
35
|
+
* the account-level summary `auth status`/`doctor` print — this is the
|
|
36
|
+
* SAME gap surfaced at the moment the caller actually hits it, matching
|
|
37
|
+
* the existing backend-test `--target-url` advisory in `runCreate`
|
|
38
|
+
* (`commands/test.ts`): unconditional across every `--output` mode. That
|
|
39
|
+
* advisory's family is "a flag the caller just passed has a structural
|
|
40
|
+
* consequence" — `--output json` is precisely the unattended/CI case that
|
|
41
|
+
* needs the warning most, not the case to withhold it from (unlike the
|
|
42
|
+
* routing-advisory family above, which a JSON caller can skip by reading
|
|
43
|
+
* `v3Enabled` directly off that command's own structured output — `test
|
|
44
|
+
* run`'s JSON output carries no such field). Deliberately type-agnostic
|
|
45
|
+
* (no "on frontend runs" claim): the CLI cannot learn a test's type at
|
|
46
|
+
* `test run <existing-test-id>` time without an extra round trip, and the
|
|
47
|
+
* override is equally inert on the V3 backend-run path.
|
|
48
|
+
*/
|
|
49
|
+
export const TARGET_URL_V3_ADVISORY = "[advisory] --target-url is not applied on the V3 execution path; the run uses the test's " +
|
|
50
|
+
'configured environment instead.';
|
|
51
|
+
/** Write the target-url advisory to a stderr sink. */
|
|
52
|
+
export function emitTargetUrlV3Advisory(stderr) {
|
|
53
|
+
stderr(TARGET_URL_V3_ADVISORY);
|
|
54
|
+
}
|
|
24
55
|
//# sourceMappingURL=v3-advisory.js.map
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.6.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testsprite/testsprite-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Official TestSprite command-line interface",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
12
|
"skills",
|
|
13
|
+
"schemas",
|
|
13
14
|
"!dist/**/*.map"
|
|
14
15
|
],
|
|
15
16
|
"scripts": {
|
|
@@ -44,7 +45,16 @@
|
|
|
44
45
|
"testsprite",
|
|
45
46
|
"cli",
|
|
46
47
|
"testing",
|
|
47
|
-
"automation"
|
|
48
|
+
"automation",
|
|
49
|
+
"test-automation",
|
|
50
|
+
"ai-testing",
|
|
51
|
+
"e2e",
|
|
52
|
+
"qa",
|
|
53
|
+
"api-testing",
|
|
54
|
+
"playwright",
|
|
55
|
+
"mcp",
|
|
56
|
+
"claude-code",
|
|
57
|
+
"agent"
|
|
48
58
|
],
|
|
49
59
|
"author": "TestSprite team",
|
|
50
60
|
"license": "Apache-2.0",
|
|
@@ -54,12 +64,14 @@
|
|
|
54
64
|
"valibot": "^1.4.1"
|
|
55
65
|
},
|
|
56
66
|
"devDependencies": {
|
|
57
|
-
"@eslint/js": "^
|
|
67
|
+
"@eslint/js": "^10.0.1",
|
|
58
68
|
"@types/node": "^22.9.0",
|
|
59
69
|
"@vitest/coverage-v8": "^2.1.4",
|
|
60
|
-
"
|
|
70
|
+
"ajv": "^8.20.0",
|
|
71
|
+
"eslint": "^10.7.0",
|
|
61
72
|
"eslint-config-prettier": "^9.1.0",
|
|
62
|
-
"
|
|
73
|
+
"eslint-plugin-security": "4.0.1",
|
|
74
|
+
"globals": "^17.7.0",
|
|
63
75
|
"msw": "^2.14.3",
|
|
64
76
|
"prettier": "^3.3.3",
|
|
65
77
|
"typescript": "^5.6.3",
|