@testsprite/testsprite-cli 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +26 -1
  2. package/dist/commands/agent.js +17 -6
  3. package/dist/commands/auth.d.ts +46 -0
  4. package/dist/commands/auth.js +37 -2
  5. package/dist/commands/completion.d.ts +36 -0
  6. package/dist/commands/completion.js +111 -0
  7. package/dist/commands/doctor.js +20 -2
  8. package/dist/commands/init.d.ts +32 -1
  9. package/dist/commands/init.js +40 -10
  10. package/dist/commands/project.d.ts +77 -3
  11. package/dist/commands/project.js +176 -43
  12. package/dist/commands/test.d.ts +160 -10
  13. package/dist/commands/test.js +1261 -303
  14. package/dist/commands/usage.d.ts +56 -17
  15. package/dist/commands/usage.js +144 -29
  16. package/dist/index.js +132 -26
  17. package/dist/lib/browser.d.ts +6 -0
  18. package/dist/lib/browser.js +54 -0
  19. package/dist/lib/bundle.d.ts +32 -31
  20. package/dist/lib/bundle.js +125 -83
  21. package/dist/lib/client-factory.d.ts +23 -0
  22. package/dist/lib/client-factory.js +33 -1
  23. package/dist/lib/config.js +7 -3
  24. package/dist/lib/credentials.d.ts +17 -1
  25. package/dist/lib/credentials.js +175 -16
  26. package/dist/lib/dry-run/samples.js +15 -1
  27. package/dist/lib/errors.d.ts +6 -1
  28. package/dist/lib/errors.js +70 -19
  29. package/dist/lib/flaky.d.ts +12 -1
  30. package/dist/lib/flaky.js +7 -12
  31. package/dist/lib/gh-output.d.ts +62 -0
  32. package/dist/lib/gh-output.js +99 -0
  33. package/dist/lib/http.d.ts +33 -15
  34. package/dist/lib/http.js +68 -6
  35. package/dist/lib/org-render.d.ts +52 -0
  36. package/dist/lib/org-render.js +59 -0
  37. package/dist/lib/poll.js +1 -1
  38. package/dist/lib/render-error.d.ts +14 -0
  39. package/dist/lib/render-error.js +30 -0
  40. package/dist/lib/response-schemas.d.ts +83 -0
  41. package/dist/lib/response-schemas.js +272 -0
  42. package/dist/lib/runs.types.d.ts +53 -8
  43. package/dist/lib/skill-nudge.d.ts +17 -0
  44. package/dist/lib/skill-nudge.js +19 -0
  45. package/dist/lib/telemetry.d.ts +90 -0
  46. package/dist/lib/telemetry.js +171 -0
  47. package/dist/lib/text-table.d.ts +14 -0
  48. package/dist/lib/text-table.js +45 -0
  49. package/dist/lib/v3-advisory.d.ts +10 -1
  50. package/dist/lib/v3-advisory.js +12 -4
  51. package/dist/version.d.ts +1 -1
  52. package/dist/version.js +1 -1
  53. package/package.json +16 -5
  54. package/schemas/plan.schema.json +61 -0
  55. package/skills/testsprite-verify.codex.md +2 -2
  56. package/skills/testsprite-verify.skill.md +3 -3
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Valibot schemas for the run-path wire shapes (issue #102).
3
+ *
4
+ * `requestWithMeta` used to return `(await response.json()) as T` with zero
5
+ * runtime validation, so a drifted or partial server response surfaced as
6
+ * `undefined` output or an opaque TypeError deep inside a command. These
7
+ * schemas are wired (opt-in, via `RequestOptions.schema`) into the typed
8
+ * HttpClient helpers only: `triggerRun`, `triggerRunWithMeta`, `triggerRerun`,
9
+ * `triggerBatchRerun`, `triggerBatchRunFresh`, `getRun`, `listTestRuns`.
10
+ * The generic `get`/`post`/`put`/`patch`/`delete` paths stay schema-free.
11
+ *
12
+ * Resilience rules (additive server changes must never hard-fail the CLI):
13
+ *
14
+ * 1. Every object is `v.looseObject`: unknown extra keys pass validation AND
15
+ * are preserved in the output, so a new server field still reaches
16
+ * `--output json` consumers untouched.
17
+ * 2. Enum-ish string fields (`status`, `source`, `role`, step `type`, ...) are
18
+ * validated as open strings via {@link openWireLiteral}: the CLI already
19
+ * treats unknown values as open (e.g. `isTerminalStatus` returns false and
20
+ * the poll continues; renderers print the raw value), so a new server enum
21
+ * member must degrade gracefully, never reject the whole response.
22
+ * 3. REQUIRED-nullable interface fields use `v.nullish(inner, null)`: the wire
23
+ * may omit a nullable field entirely (real fixture evidence: the chained
24
+ * `test create --run` poll bodies in `test.test.ts` omit `error`), and
25
+ * every consumer already null-checks these, so absence normalizes to
26
+ * `null` instead of failing. OPTIONAL interface fields (`?`) use
27
+ * `v.optional` with NO default so presence/absence semantics that commands
28
+ * branch on (e.g. `RerunResponse.closure`, `RunResponse.steps`) survive
29
+ * validation byte-identically.
30
+ *
31
+ * Each schema is annotated `v.GenericSchema<unknown, T>` against the
32
+ * interface it mirrors, so schema/interface drift fails `tsc` in this file.
33
+ */
34
+ import * as v from 'valibot';
35
+ /**
36
+ * Compile-time literal union, runtime open string.
37
+ *
38
+ * Keeps `InferOutput` aligned with the union declared in `runs.types.ts`
39
+ * while accepting any string on the wire, per resilience rule 2 above.
40
+ * `v.custom` is valibot's documented escape hatch for exactly this
41
+ * "caller-asserted type, custom runtime check" pattern.
42
+ */
43
+ function openWireLiteral() {
44
+ return v.custom(value => typeof value === 'string');
45
+ }
46
+ // ---------------------------------------------------------------------------
47
+ // GET /runs/{runId}
48
+ // ---------------------------------------------------------------------------
49
+ /** Mirrors `RunStepSummary` (runs.types.ts): per-run step counters. */
50
+ const RUN_STEP_SUMMARY_SCHEMA = v.looseObject({
51
+ total: v.number(),
52
+ completed: v.number(),
53
+ passedCount: v.number(),
54
+ failedCount: v.number(),
55
+ });
56
+ /** Mirrors `RunStepDto` (runs.types.ts): one `?includeSteps=true` step row. */
57
+ const RUN_STEP_DTO_SCHEMA = v.looseObject({
58
+ stepIndex: v.string(),
59
+ type: openWireLiteral(),
60
+ action: v.string(),
61
+ status: v.nullish(openWireLiteral(), null),
62
+ description: v.nullish(v.string(), null),
63
+ error: v.nullish(v.string(), null),
64
+ screenshotUrl: v.nullish(v.string(), null),
65
+ htmlSnapshotUrl: v.nullish(v.string(), null),
66
+ createdAt: v.string(),
67
+ });
68
+ /** Mirrors `RunResponse` (runs.types.ts): `GET /api/cli/v1/runs/{runId}`. */
69
+ export const RUN_RESPONSE_SCHEMA = v.looseObject({
70
+ runId: v.string(),
71
+ testId: v.string(),
72
+ projectId: v.string(),
73
+ userId: v.string(),
74
+ status: openWireLiteral(),
75
+ source: v.string(),
76
+ createdAt: v.string(),
77
+ startedAt: v.nullish(v.string(), null),
78
+ finishedAt: v.nullish(v.string(), null),
79
+ // Both are nullable on the wire (`RunEnvelope` declares
80
+ // `[string, 'null']`): `codeVersion` is null on pre-M3.1 rows and on tests
81
+ // with no stored code body, `targetUrl` is null for backend runs and for
82
+ // execution backends that record no URL. Renderers already omit the line
83
+ // when either is null (rule 3).
84
+ codeVersion: v.nullish(v.string(), null),
85
+ targetUrl: v.nullish(v.string(), null),
86
+ createdFrom: v.nullish(v.string(), null),
87
+ failedStepIndex: v.nullish(v.number(), null),
88
+ failureKind: v.nullish(v.string(), null),
89
+ // Loosened per fixture evidence (rule 3): several real poll bodies omit
90
+ // `error` entirely; consumers render it only when non-null.
91
+ error: v.nullish(v.string(), null),
92
+ videoUrl: v.nullish(v.string(), null),
93
+ stepSummary: RUN_STEP_SUMMARY_SCHEMA,
94
+ retryAfterSeconds: v.optional(v.number()),
95
+ // Portal link. Newer backends DO send this (they alone know which store
96
+ // answered the read and can resolve a non-prod portal origin); older ones
97
+ // omit it and the CLI computes its own. `nullish` rather than `optional`
98
+ // deliberately: the backend omits the field when no correct link exists, but
99
+ // a `null` from any other producer must not fail validation and take down
100
+ // `test wait` — the same trap that had to be un-sprung for a null
101
+ // `targetUrl`/`codeVersion`.
102
+ //
103
+ // The `undefined` default (NOT `null`, unlike every field above) is load-bearing
104
+ // and measured: valibot applies a default only when the key is absent, and
105
+ // skips the assignment entirely when that default is `undefined` — so an
106
+ // omitted field stays an ABSENT key, which is exactly what
107
+ // `withRunDashboardUrl`'s `'dashboardUrl' in run` test reads to decide
108
+ // "old backend, compute the link myself". Aligning this with the
109
+ // `nullish(..., null)` fields above would materialize the key on every
110
+ // response and silently kill that fallback. A wire `null` is preserved as
111
+ // null here (nullable passes it through untouched) and normalized at the
112
+ // consumer, not in the schema. Locked by tests in response-schemas.test.ts.
113
+ dashboardUrl: v.nullish(v.string(), undefined),
114
+ // Absence means "steps not requested" and drives command branching, so no
115
+ // default is applied (rule 3, optional branch).
116
+ steps: v.optional(v.nullable(v.array(RUN_STEP_DTO_SCHEMA))),
117
+ });
118
+ // ---------------------------------------------------------------------------
119
+ // POST /tests/{testId}/runs
120
+ // ---------------------------------------------------------------------------
121
+ /** Mirrors `TriggerRunResponse` (runs.types.ts): `POST /tests/{testId}/runs`. */
122
+ export const TRIGGER_RUN_RESPONSE_SCHEMA = v.looseObject({
123
+ runId: v.string(),
124
+ status: openWireLiteral(),
125
+ enqueuedAt: v.string(),
126
+ codeVersion: v.string(),
127
+ targetUrl: v.string(),
128
+ });
129
+ // ---------------------------------------------------------------------------
130
+ // POST /tests/{testId}/runs/rerun
131
+ // ---------------------------------------------------------------------------
132
+ /** Mirrors `RerunClosureMember` (runs.types.ts): one BE closure member. */
133
+ const RERUN_CLOSURE_MEMBER_SCHEMA = v.looseObject({
134
+ testId: v.string(),
135
+ runId: v.string(),
136
+ role: openWireLiteral(),
137
+ });
138
+ /** Mirrors `RerunClosure` (runs.types.ts): BE closure breakdown. */
139
+ const RERUN_CLOSURE_SCHEMA = v.looseObject({
140
+ members: v.array(RERUN_CLOSURE_MEMBER_SCHEMA),
141
+ addedProducers: v.array(v.string()),
142
+ addedTeardowns: v.array(v.string()),
143
+ clearedCaptured: v.number(),
144
+ });
145
+ /**
146
+ * Mirrors `RerunAdvisory` (runs.types.ts): a server-side note that a
147
+ * requested option was forwarded to the execution engine but is not yet
148
+ * honored there. Present only on a V3-routed rerun that explicitly opted
149
+ * out of auto-heal — absent everywhere else, so this schema is only ever
150
+ * used inside an `v.optional(v.array(...))` wrapper.
151
+ */
152
+ const RERUN_ADVISORY_SCHEMA = v.looseObject({
153
+ feature: v.string(),
154
+ message: v.string(),
155
+ });
156
+ /** Mirrors `RerunResponse` (runs.types.ts): `POST /tests/{testId}/runs/rerun`. */
157
+ export const RERUN_RESPONSE_SCHEMA = v.looseObject({
158
+ runId: v.string(),
159
+ status: openWireLiteral(),
160
+ enqueuedAt: v.string(),
161
+ codeVersion: v.string(),
162
+ autoHeal: v.boolean(),
163
+ // FE reruns omit `closure`; the CLI's `!!closure` truthy check relies on
164
+ // absent staying absent, so optional with no default (rule 3).
165
+ closure: v.optional(v.nullable(RERUN_CLOSURE_SCHEMA)),
166
+ // Absent on every response except a V3-routed rerun with an explicit
167
+ // autoHeal:false opt-out (rule 3: optional, no default, so presence/absence
168
+ // survives validation byte-identically). Older backends that predate the
169
+ // field simply omit it — never fails validation.
170
+ advisories: v.optional(v.array(RERUN_ADVISORY_SCHEMA)),
171
+ });
172
+ // ---------------------------------------------------------------------------
173
+ // POST /tests/batch/rerun
174
+ // ---------------------------------------------------------------------------
175
+ /** Mirrors `BatchRerunResponse` (runs.types.ts): `POST /tests/batch/rerun`. */
176
+ export const BATCH_RERUN_RESPONSE_SCHEMA = v.looseObject({
177
+ // Mirrors BatchRerunAccepted (runs.types.ts).
178
+ accepted: v.array(v.looseObject({ testId: v.string(), runId: v.string(), enqueuedAt: v.string() })),
179
+ // Mirrors BatchRerunDeferred (runs.types.ts).
180
+ deferred: v.array(v.looseObject({ testId: v.string(), reason: v.string() })),
181
+ // Mirrors BatchRerunConflict (runs.types.ts).
182
+ conflicts: v.array(v.looseObject({ testId: v.string(), currentRunId: v.string() })),
183
+ // Mirrors BatchRerunClosure / BatchRerunClosureByProject (runs.types.ts).
184
+ closure: v.looseObject({
185
+ byProject: v.array(v.looseObject({
186
+ projectId: v.string(),
187
+ testIds: v.array(v.string()),
188
+ addedProducers: v.array(v.string()),
189
+ addedTeardowns: v.array(v.string()),
190
+ clearedCaptured: v.number(),
191
+ })),
192
+ }),
193
+ // Optional on the wire for back-compat with older backends (D2-CLI).
194
+ notFound: v.optional(v.array(v.string())),
195
+ // Absent on every response except a V3-routed batch containing at least
196
+ // one FE test with an explicit autoHeal:false opt-out. Same resilience
197
+ // rule as RERUN_RESPONSE_SCHEMA.advisories above.
198
+ advisories: v.optional(v.array(RERUN_ADVISORY_SCHEMA)),
199
+ });
200
+ // ---------------------------------------------------------------------------
201
+ // POST /tests/batch/run
202
+ // ---------------------------------------------------------------------------
203
+ /** Mirrors `BatchRunFreshResponse` (runs.types.ts): `POST /tests/batch/run`. */
204
+ export const BATCH_RUN_FRESH_RESPONSE_SCHEMA = v.looseObject({
205
+ // Mirrors BatchRunFreshAccepted (runs.types.ts); dashboardUrl is
206
+ // client-synthesized, tolerated as optional.
207
+ accepted: v.array(v.looseObject({
208
+ testId: v.string(),
209
+ runId: v.string(),
210
+ enqueuedAt: v.string(),
211
+ dashboardUrl: v.optional(v.string()),
212
+ })),
213
+ conflicts: v.array(v.looseObject({ testId: v.string() })),
214
+ deferred: v.array(v.looseObject({ testId: v.string() })),
215
+ skippedFrontend: v.array(v.string()),
216
+ skippedIntegration: v.array(v.looseObject({ testId: v.string() })),
217
+ });
218
+ // ---------------------------------------------------------------------------
219
+ // GET /tests/{testId}/runs
220
+ // ---------------------------------------------------------------------------
221
+ /** Mirrors `RunHistoryItem` (runs.types.ts): one run-history row. */
222
+ const RUN_HISTORY_ITEM_SCHEMA = v.looseObject({
223
+ runId: v.string(),
224
+ status: openWireLiteral(),
225
+ source: openWireLiteral(),
226
+ isRerun: v.boolean(),
227
+ createdFrom: v.nullish(v.string(), null),
228
+ createdAt: v.string(),
229
+ startedAt: v.nullish(v.string(), null),
230
+ finishedAt: v.nullish(v.string(), null),
231
+ // Nullable on the wire (`RunHistoryRow.codeVersion` is `[string, 'null']`).
232
+ codeVersion: v.nullish(v.string(), null),
233
+ failureKind: v.nullish(v.string(), null),
234
+ // G1b fields: optional on the wire for back-compat with older backends.
235
+ targetUrl: v.optional(v.nullable(v.string())),
236
+ targetUrlSource: v.optional(v.nullable(openWireLiteral())),
237
+ });
238
+ /** Mirrors `ListRunsResponse` (runs.types.ts): `GET /tests/{testId}/runs`. */
239
+ export const LIST_RUNS_RESPONSE_SCHEMA = v.looseObject({
240
+ runs: v.array(RUN_HISTORY_ITEM_SCHEMA),
241
+ nextCursor: v.nullish(v.string(), null),
242
+ // Mirrors RunHistoryMeta (runs.types.ts): every field optional, and the
243
+ // history command reads `resp.meta.note` / `resp.meta.portalUrl` directly,
244
+ // so the container itself stays required like the interface declares.
245
+ meta: v.looseObject({
246
+ testKind: v.optional(openWireLiteral()),
247
+ historyStartsAt: v.optional(v.string()),
248
+ note: v.optional(v.string()),
249
+ portalUrl: v.optional(v.string()),
250
+ }),
251
+ });
252
+ /** Mirrors `CliOrgSummary` (lib/org-render.ts): one `Me.organizations[]` entry. */
253
+ const ORG_SUMMARY_SCHEMA = v.looseObject({
254
+ id: v.string(),
255
+ name: v.string(),
256
+ role: v.string(),
257
+ isPersonal: v.boolean(),
258
+ });
259
+ /** Mirrors `CliOrgBinding` (lib/org-render.ts): `Me.org`. */
260
+ const ORG_BINDING_SCHEMA = v.looseObject({
261
+ id: v.string(),
262
+ name: v.nullable(v.string()),
263
+ role: v.string(),
264
+ });
265
+ /** Mirrors `MeIdentity` (commands/doctor.ts): `GET /api/cli/v1/me` core. */
266
+ export const ME_IDENTITY_SCHEMA = v.looseObject({
267
+ userId: v.optional(v.string()),
268
+ keyId: v.optional(v.string()),
269
+ organizations: v.optional(v.array(ORG_SUMMARY_SCHEMA)),
270
+ org: v.optional(ORG_BINDING_SCHEMA),
271
+ });
272
+ //# sourceMappingURL=response-schemas.js.map
@@ -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
- codeVersion: string;
178
- targetUrl: string;
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
- * CLIENT-synthesized Portal deep link — never sent by the server. The CLI
190
- * adds it to terminal run output (`test run --wait`, `test wait`,
191
- * `test rerun --wait`) when projectId+testId are present and the API
192
- * endpoint maps to a known portal host (see `resolvePortalUrl`).
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
- codeVersion: string;
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;
@@ -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>;