@testsprite/testsprite-cli 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +35 -26
  2. package/dist/commands/agent.d.ts +43 -0
  3. package/dist/commands/agent.js +200 -18
  4. package/dist/commands/auth.d.ts +5 -0
  5. package/dist/commands/auth.js +38 -27
  6. package/dist/commands/doctor.d.ts +49 -0
  7. package/dist/commands/doctor.js +233 -0
  8. package/dist/commands/init.d.ts +1 -1
  9. package/dist/commands/init.js +24 -14
  10. package/dist/commands/project.d.ts +75 -2
  11. package/dist/commands/project.js +326 -47
  12. package/dist/commands/test.d.ts +281 -2
  13. package/dist/commands/test.js +1658 -177
  14. package/dist/commands/usage.js +13 -12
  15. package/dist/index.js +71 -3
  16. package/dist/lib/agent-targets.d.ts +72 -6
  17. package/dist/lib/agent-targets.js +188 -6
  18. package/dist/lib/bundle.d.ts +34 -0
  19. package/dist/lib/bundle.js +63 -11
  20. package/dist/lib/client-factory.d.ts +31 -0
  21. package/dist/lib/client-factory.js +63 -0
  22. package/dist/lib/config.d.ts +2 -0
  23. package/dist/lib/config.js +11 -2
  24. package/dist/lib/credentials.js +10 -1
  25. package/dist/lib/dry-run/samples.d.ts +5 -0
  26. package/dist/lib/dry-run/samples.js +64 -0
  27. package/dist/lib/errors.d.ts +28 -1
  28. package/dist/lib/errors.js +40 -0
  29. package/dist/lib/failing-fe-resolver.d.ts +15 -0
  30. package/dist/lib/failing-fe-resolver.js +49 -1
  31. package/dist/lib/flaky.d.ts +80 -0
  32. package/dist/lib/flaky.js +76 -0
  33. package/dist/lib/http.d.ts +73 -1
  34. package/dist/lib/http.js +327 -135
  35. package/dist/lib/interrupt.d.ts +116 -0
  36. package/dist/lib/interrupt.js +182 -0
  37. package/dist/lib/junit-report.d.ts +58 -0
  38. package/dist/lib/junit-report.js +210 -0
  39. package/dist/lib/output.d.ts +16 -1
  40. package/dist/lib/output.js +24 -2
  41. package/dist/lib/pagination.d.ts +4 -3
  42. package/dist/lib/pagination.js +34 -6
  43. package/dist/lib/poll.d.ts +11 -0
  44. package/dist/lib/poll.js +70 -5
  45. package/dist/lib/prompt.js +52 -8
  46. package/dist/lib/proxy.d.ts +29 -0
  47. package/dist/lib/proxy.js +30 -0
  48. package/dist/lib/render-error.js +3 -1
  49. package/dist/lib/runs.types.d.ts +9 -0
  50. package/dist/lib/skill-nudge.d.ts +2 -2
  51. package/dist/lib/skill-nudge.js +13 -4
  52. package/dist/lib/target-url.js +8 -1
  53. package/dist/lib/ticker.d.ts +11 -1
  54. package/dist/lib/ticker.js +33 -1
  55. package/dist/lib/update-check.d.ts +67 -0
  56. package/dist/lib/update-check.js +246 -0
  57. package/dist/lib/v3-advisory.d.ts +13 -0
  58. package/dist/lib/v3-advisory.js +24 -0
  59. package/dist/lib/version-notice.d.ts +37 -0
  60. package/dist/lib/version-notice.js +87 -0
  61. package/dist/version-guard.d.ts +33 -0
  62. package/dist/version-guard.js +39 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +3 -2
  66. package/skills/testsprite-onboard.skill.md +21 -0
  67. package/skills/testsprite-verify.codex.md +6 -0
  68. package/skills/testsprite-verify.skill.md +48 -4
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Pure aggregation + rendering for `test flaky` — the repeat-run flaky-test
3
+ * detector. This module performs no I/O: the orchestrator in
4
+ * `commands/test.ts` feeds it the per-attempt outcomes, and it returns a
5
+ * machine-readable stability report plus the text rendering and exit code.
6
+ *
7
+ * Keeping the scoring logic pure makes it trivially unit-testable in isolation
8
+ * (deterministic, no network / credentials), matching the repo's mock-based
9
+ * test convention.
10
+ */
11
+ /**
12
+ * Outcome of a single flaky-detector attempt. The first four mirror the
13
+ * terminal `RunStatus` values; `timeout` and `error` are orchestration
14
+ * outcomes (per-attempt deadline exceeded, or a non-fatal trigger/transport
15
+ * error that was recorded rather than aborting the whole probe).
16
+ */
17
+ export type FlakyOutcome = 'passed' | 'failed' | 'blocked' | 'cancelled' | 'timeout' | 'error';
18
+ /** Overall stability verdict across all observed attempts. */
19
+ export type FlakyVerdict = 'stable' | 'flaky' | 'failing';
20
+ /** One recorded attempt in a flaky run. */
21
+ export interface FlakyAttempt {
22
+ /** 1-based attempt index. */
23
+ attempt: number;
24
+ /** The runId of this attempt, or `null` when the trigger never returned one. */
25
+ runId: string | null;
26
+ outcome: FlakyOutcome;
27
+ /**
28
+ * Server `failureKind` for non-passing runs (or the error code for `error`
29
+ * outcomes). `null` / omitted when the attempt passed or the kind is unknown.
30
+ */
31
+ failureKind?: string | null;
32
+ }
33
+ /** A single non-passing attempt as surfaced in the report. */
34
+ export interface FlakyFailure {
35
+ attempt: number;
36
+ runId: string | null;
37
+ outcome: FlakyOutcome;
38
+ failureKind: string | null;
39
+ }
40
+ /**
41
+ * Machine-readable stability report. This is also the exact `--output json`
42
+ * shape, so dashboards / agents / CI can consume it directly.
43
+ */
44
+ export interface FlakyReport {
45
+ testId: string;
46
+ /**
47
+ * Attempts actually observed. May be fewer than requested when
48
+ * `--until-fail` short-circuits on the first non-passing attempt.
49
+ */
50
+ runs: number;
51
+ passed: number;
52
+ failed: number;
53
+ /** `passed / runs`, rounded to 4 decimal places. `0` when `runs === 0`. */
54
+ stableRatio: number;
55
+ verdict: FlakyVerdict;
56
+ /** Non-passing attempts, in attempt order. */
57
+ failures: FlakyFailure[];
58
+ }
59
+ /**
60
+ * Aggregate per-attempt outcomes into a stability report.
61
+ *
62
+ * Verdict rules:
63
+ * - every attempt passed → `stable`
64
+ * - no attempt passed → `failing`
65
+ * - a mix of pass and non-pass → `flaky`
66
+ * An empty attempt list (no runs observed) is reported as `failing` with a
67
+ * `0` ratio — there is no evidence the test is stable.
68
+ */
69
+ export declare function summarizeFlaky(testId: string, attempts: FlakyAttempt[]): FlakyReport;
70
+ /**
71
+ * Exit code for the command: `0` only when the verdict is `stable` (every
72
+ * observed attempt passed). Anything else is non-zero so CI can gate a merge
73
+ * on flakiness (`testsprite test flaky <id> --runs 5 || exit 1`).
74
+ */
75
+ export declare function flakyExitCode(report: FlakyReport): number;
76
+ /**
77
+ * Render a report to human-readable text. JSON-mode callers ship the report
78
+ * verbatim via `out.print`; this is the text-mode rendering.
79
+ */
80
+ export declare function renderFlakyText(report: FlakyReport): string;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Pure aggregation + rendering for `test flaky` — the repeat-run flaky-test
3
+ * detector. This module performs no I/O: the orchestrator in
4
+ * `commands/test.ts` feeds it the per-attempt outcomes, and it returns a
5
+ * machine-readable stability report plus the text rendering and exit code.
6
+ *
7
+ * Keeping the scoring logic pure makes it trivially unit-testable in isolation
8
+ * (deterministic, no network / credentials), matching the repo's mock-based
9
+ * test convention.
10
+ */
11
+ /**
12
+ * Aggregate per-attempt outcomes into a stability report.
13
+ *
14
+ * Verdict rules:
15
+ * - every attempt passed → `stable`
16
+ * - no attempt passed → `failing`
17
+ * - a mix of pass and non-pass → `flaky`
18
+ * An empty attempt list (no runs observed) is reported as `failing` with a
19
+ * `0` ratio — there is no evidence the test is stable.
20
+ */
21
+ export function summarizeFlaky(testId, attempts) {
22
+ const runs = attempts.length;
23
+ const passed = attempts.filter(a => a.outcome === 'passed').length;
24
+ const failed = runs - passed;
25
+ const stableRatio = runs === 0 ? 0 : Math.round((passed / runs) * 10000) / 10000;
26
+ const verdict = runs > 0 && passed === runs ? 'stable' : passed === 0 ? 'failing' : 'flaky';
27
+ const failures = attempts
28
+ .filter(a => a.outcome !== 'passed')
29
+ .map(a => ({
30
+ attempt: a.attempt,
31
+ runId: a.runId,
32
+ outcome: a.outcome,
33
+ failureKind: a.failureKind ?? null,
34
+ }));
35
+ return { testId, runs, passed, failed, stableRatio, verdict, failures };
36
+ }
37
+ /**
38
+ * Exit code for the command: `0` only when the verdict is `stable` (every
39
+ * observed attempt passed). Anything else is non-zero so CI can gate a merge
40
+ * on flakiness (`testsprite test flaky <id> --runs 5 || exit 1`).
41
+ */
42
+ export function flakyExitCode(report) {
43
+ return report.verdict === 'stable' ? 0 : 1;
44
+ }
45
+ /** Human-readable label for a verdict. */
46
+ function verdictLabel(verdict) {
47
+ switch (verdict) {
48
+ case 'stable':
49
+ return 'STABLE';
50
+ case 'flaky':
51
+ return 'FLAKY';
52
+ case 'failing':
53
+ return 'FAILING';
54
+ }
55
+ }
56
+ /**
57
+ * Render a report to human-readable text. JSON-mode callers ship the report
58
+ * verbatim via `out.print`; this is the text-mode rendering.
59
+ */
60
+ export function renderFlakyText(report) {
61
+ const pct = Math.round(report.stableRatio * 100);
62
+ const lines = [
63
+ `Ran ${report.testId} ${report.runs}x — ${report.passed} passed, ${report.failed} failed → ` +
64
+ `${verdictLabel(report.verdict)} (${pct}% stable)`,
65
+ ];
66
+ if (report.failures.length > 0) {
67
+ lines.push(' failed attempts:');
68
+ for (const f of report.failures) {
69
+ const kind = f.failureKind ? ` failureKind=${f.failureKind}` : '';
70
+ const rid = f.runId ?? '(no runId)';
71
+ lines.push(` #${f.attempt} ${rid} ${f.outcome}${kind}`);
72
+ }
73
+ }
74
+ return lines.join('\n');
75
+ }
76
+ //# sourceMappingURL=flaky.js.map
@@ -1,5 +1,6 @@
1
1
  import type { ErrorCode } from './errors.js';
2
- import type { TriggerRunBody, TriggerRunResponse, RunResponse, RerunRequest, RerunResponse, BatchRerunRequest, BatchRerunResponse, BatchRunFreshRequest, BatchRunFreshResponse, ListRunsQuery, ListRunsResponse } from './runs.types.js';
2
+ import { ApiError } from './errors.js';
3
+ import type { TriggerRunBody, TriggerRunResponse, RunResponse, RerunRequest, RerunResponse, BatchRerunRequest, BatchRerunResponse, BatchRunFreshRequest, BatchRunFreshResponse, ListRunsQuery, ListRunsResponse, CancelRunResponse } from './runs.types.js';
3
4
  export type FetchImpl = typeof globalThis.fetch;
4
5
  export type DebugEventKind = 'request' | 'response' | 'retry' | 'error';
5
6
  export interface DebugEvent {
@@ -52,6 +53,16 @@ export interface HttpClientOptions {
52
53
  * Stays silent when absent; wired to stderr at `--verbose` level.
53
54
  */
54
55
  onTransition?: (msg: string) => void;
56
+ /**
57
+ * Optional callback fired with the backend's supported-floor header
58
+ * (`X-TestSprite-CLI-Min-Version`) when present on a response. Fires on both
59
+ * success and error responses. The client forwards the value verbatim — it
60
+ * applies no policy itself; the caller (client-factory) decides whether to
61
+ * warn the user.
62
+ */
63
+ onServerVersion?: (info: {
64
+ minVersion?: string;
65
+ }) => void;
55
66
  /**
56
67
  * Per-request wall-clock timeout in milliseconds applied to every outgoing
57
68
  * fetch. The signal fires independently of any caller-supplied signal — the
@@ -65,6 +76,16 @@ export interface HttpClientOptions {
65
76
  * request is well within the 120s default.
66
77
  */
67
78
  requestTimeoutMs?: number;
79
+ /**
80
+ * Process-lifetime shutdown signal (DEV-331 piece 1). Composed into every
81
+ * outgoing fetch so an armed SIGINT/SIGTERM aborts an in-flight request
82
+ * (a `--wait` long-poll can sit inside a single fetch for minutes) instead
83
+ * of waiting out its window. Aborts with an `InterruptError` reason, which
84
+ * is classified before the timeout-vs-caller logic and is never retried or
85
+ * re-wrapped as `TransportError`. Defaults off; production wiring passes
86
+ * `globalShutdown.signal` via the client factory.
87
+ */
88
+ shutdownSignal?: AbortSignal;
68
89
  }
69
90
  export interface RequestOptions {
70
91
  query?: Record<string, string | number | boolean | undefined>;
@@ -125,8 +146,18 @@ export declare class HttpClient {
125
146
  private readonly random;
126
147
  private readonly onDebug?;
127
148
  private readonly onTransition?;
149
+ private readonly onServerVersion?;
128
150
  private readonly requestTimeoutMs;
151
+ private readonly shutdownSignal?;
129
152
  constructor(options: HttpClientOptions);
153
+ /**
154
+ * Read the backend's supported-floor header off a response and forward it to
155
+ * `onServerVersion` when present. Never throws — a bad header must not break
156
+ * the request. Called on every response (success or error) so the advisory
157
+ * covers all paths. (The backend advertises only the floor; "latest" is
158
+ * resolved client-side via the npm update-notice.)
159
+ */
160
+ private captureServerVersion;
130
161
  get<T>(path: string, options?: RequestOptions): Promise<T>;
131
162
  post<T>(path: string, options?: RequestOptions): Promise<T>;
132
163
  put<T>(path: string, options?: RequestOptions): Promise<T>;
@@ -231,6 +262,20 @@ export declare class HttpClient {
231
262
  includeSteps?: boolean;
232
263
  signal?: AbortSignal;
233
264
  }): Promise<RunResponse>;
265
+ /**
266
+ * POST /api/cli/v1/runs/{runId}/cancel
267
+ * User-initiated cancel of a queued/running run (DEV-331 piece 3). No
268
+ * body, no `Idempotency-Key` — the endpoint is naturally idempotent (D10):
269
+ * re-cancel → 200 `alreadyCancelled: true`; already-terminal (passed/
270
+ * failed/blocked) → 409 CONFLICT; unknown/cross-tenant runId → 404.
271
+ *
272
+ * `retryOnConflict: false` — same rationale as `triggerRun`: a 409 here is
273
+ * a truthful terminal answer ("already finished"), not a transient
274
+ * snapshot conflict to paper over with a retry.
275
+ */
276
+ cancelRun(runId: string, options?: {
277
+ signal?: AbortSignal;
278
+ }): Promise<CancelRunResponse>;
234
279
  /**
235
280
  * Classify an error thrown while issuing OR reading a request. When it is an
236
281
  * abort/timeout and our per-request timeout signal fired (and the caller had
@@ -242,6 +287,14 @@ export declare class HttpClient {
242
287
  private rethrowIfAbort;
243
288
  requestWithMeta<T>(method: string, path: string, options?: RequestOptions): Promise<RequestResult<T>>;
244
289
  private buildHeaders;
290
+ /**
291
+ * Retry-delay sleep that bails the moment the shutdown signal fires
292
+ * (DEV-331, codex finding 1): a RATE_LIMITED `Retry-After: 60` or a
293
+ * transport backoff must not delay the honest-detach exit by up to a
294
+ * minute — reject with the InterruptError reason immediately. Mirrors
295
+ * poll.ts::sleepUnlessInterrupted.
296
+ */
297
+ private sleepBeforeRetry;
245
298
  private debug;
246
299
  private transition;
247
300
  /**
@@ -252,4 +305,23 @@ export declare class HttpClient {
252
305
  request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
253
306
  }
254
307
  export declare function buildUrl(baseUrl: string, path: string, query?: Record<string, string | number | boolean | undefined>): string;
308
+ /**
309
+ * Build a typed error for a successful response whose body could not be parsed
310
+ * as JSON.
311
+ *
312
+ * The CLI expects every API response to be a JSON envelope. When a `200 OK`
313
+ * carries a non-JSON body — a misconfigured endpoint, a proxy / captive-portal
314
+ * / SSO login page returning HTML with a success status, or an empty body —
315
+ * `response.json()` throws a raw `SyntaxError`. Left unhandled it escapes to
316
+ * the top-level handler in `index.ts`, which prints a bare
317
+ * `{"error":"<parse message>"}` under `--output json` (breaking the
318
+ * typed-envelope contract every other error honors) and gives the operator no
319
+ * actionable context.
320
+ *
321
+ * This wraps it in a typed `INTERNAL` `ApiError` (exit 1, unchanged) that
322
+ * carries the `requestId`, names the likely cause, and points the operator at
323
+ * their endpoint configuration. `details` includes the HTTP status, the
324
+ * response `content-type` (when present), and the underlying parse message.
325
+ */
326
+ export declare function malformedResponseError(response: Response, requestId: string, cause: unknown): ApiError;
255
327
  export declare function parseRetryAfter(headerValue: string | null): number | undefined;