@testsprite/testsprite-cli 0.1.2 → 0.3.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 (58) hide show
  1. package/README.md +34 -26
  2. package/dist/commands/agent.d.ts +52 -0
  3. package/dist/commands/agent.js +341 -93
  4. package/dist/commands/auth.js +29 -27
  5. package/dist/commands/doctor.d.ts +49 -0
  6. package/dist/commands/doctor.js +211 -0
  7. package/dist/commands/init.d.ts +7 -1
  8. package/dist/commands/init.js +66 -26
  9. package/dist/commands/project.d.ts +50 -1
  10. package/dist/commands/project.js +257 -43
  11. package/dist/commands/test.d.ts +214 -12
  12. package/dist/commands/test.js +1310 -174
  13. package/dist/commands/usage.js +13 -12
  14. package/dist/index.js +71 -18
  15. package/dist/lib/agent-targets.d.ts +169 -22
  16. package/dist/lib/agent-targets.js +335 -34
  17. package/dist/lib/bundle.d.ts +51 -1
  18. package/dist/lib/bundle.js +146 -55
  19. package/dist/lib/client-factory.d.ts +43 -0
  20. package/dist/lib/client-factory.js +89 -2
  21. package/dist/lib/config.d.ts +2 -0
  22. package/dist/lib/config.js +11 -2
  23. package/dist/lib/credentials.d.ts +7 -0
  24. package/dist/lib/credentials.js +40 -1
  25. package/dist/lib/dry-run/samples.d.ts +5 -0
  26. package/dist/lib/dry-run/samples.js +54 -9
  27. package/dist/lib/flaky.d.ts +80 -0
  28. package/dist/lib/flaky.js +76 -0
  29. package/dist/lib/http.d.ts +20 -0
  30. package/dist/lib/http.js +216 -132
  31. package/dist/lib/interrupt.d.ts +61 -0
  32. package/dist/lib/interrupt.js +97 -0
  33. package/dist/lib/junit-report.d.ts +58 -0
  34. package/dist/lib/junit-report.js +210 -0
  35. package/dist/lib/output.d.ts +16 -1
  36. package/dist/lib/output.js +24 -2
  37. package/dist/lib/pagination.d.ts +4 -3
  38. package/dist/lib/pagination.js +34 -6
  39. package/dist/lib/prompt.js +52 -8
  40. package/dist/lib/proxy.d.ts +29 -0
  41. package/dist/lib/proxy.js +30 -0
  42. package/dist/lib/render-error.d.ts +13 -0
  43. package/dist/lib/render-error.js +30 -7
  44. package/dist/lib/skill-nudge.d.ts +2 -2
  45. package/dist/lib/skill-nudge.js +13 -4
  46. package/dist/lib/target-url.js +8 -1
  47. package/dist/lib/ticker.d.ts +11 -1
  48. package/dist/lib/ticker.js +33 -1
  49. package/dist/lib/update-check.d.ts +67 -0
  50. package/dist/lib/update-check.js +246 -0
  51. package/dist/version-guard.d.ts +33 -0
  52. package/dist/version-guard.js +39 -0
  53. package/dist/version.d.ts +1 -1
  54. package/dist/version.js +1 -1
  55. package/package.json +3 -2
  56. package/skills/testsprite-onboard.skill.md +183 -0
  57. package/skills/testsprite-verify.codex.md +2 -0
  58. package/skills/testsprite-verify.skill.md +52 -1
@@ -1,3 +1,4 @@
1
+ import { buildJUnitReport } from '../junit-report.js';
1
2
  const SAMPLE_USER_ID = '11111111-1111-4111-8111-111111111111';
2
3
  const SAMPLE_KEY_ID = 'key_dryrun_2026';
3
4
  const SAMPLE_PROJECT_ID = 'project_b3c91efa';
@@ -25,6 +26,33 @@ const SAMPLE_SNAPSHOT_ID = 'snap_2026_05_05_b2f9a1c8';
25
26
  const SAMPLE_TARGET_URL = 'https://staging.example.com/checkout';
26
27
  const SAMPLE_REQUEST_ID = 'req_dry-run';
27
28
  export const SAMPLE_DRY_RUN_REQUEST_ID = SAMPLE_REQUEST_ID;
29
+ /**
30
+ * Canned JUnit XML for batch `--wait --report junit --dry-run`. Mirrors the
31
+ * fresh batch-run sample ids so agents can learn the sidecar shape offline.
32
+ */
33
+ export function sampleJUnitReportXml(projectId = SAMPLE_PROJECT_ID, reportSuiteName) {
34
+ return buildJUnitReport({
35
+ suiteName: reportSuiteName ?? `testsprite:${projectId}`,
36
+ classname: projectId,
37
+ results: [
38
+ {
39
+ testId: SAMPLE_TEST_ID_FRESH_1,
40
+ runId: SAMPLE_BATCH_FRESH_RUN_ID_1,
41
+ status: 'passed',
42
+ },
43
+ {
44
+ testId: SAMPLE_TEST_ID_FRESH_2,
45
+ runId: SAMPLE_BATCH_FRESH_RUN_ID_2,
46
+ status: 'failed',
47
+ error: {
48
+ code: 'ASSERTION',
49
+ message: 'Expected checkout heading to be visible',
50
+ exitCode: 1,
51
+ },
52
+ },
53
+ ],
54
+ });
55
+ }
28
56
  const me = {
29
57
  userId: SAMPLE_USER_ID,
30
58
  keyId: SAMPLE_KEY_ID,
@@ -106,16 +134,31 @@ const tests = [
106
134
  ];
107
135
  const testCode = {
108
136
  testId: SAMPLE_TEST_ID_FAILED,
109
- language: 'typescript',
137
+ language: 'python',
110
138
  framework: 'playwright',
139
+ // TestSprite test code is Python: frontend tests are Playwright
140
+ // (`playwright.async_api`); backend tests use `requests` + assertions.
111
141
  code: [
112
- "import { test, expect } from '@playwright/test';",
113
- "test('checkout happy path', async ({ page }) => {",
114
- ' await page.goto(process.env.TARGET_URL!);',
115
- ' await page.click(\'[data-testid="cart"]\');',
116
- ' await page.click(\'[data-testid="submit"]\');',
117
- " await expect(page.getByRole('heading', { name: 'Order placed' })).toBeVisible();",
118
- '});',
142
+ 'import asyncio',
143
+ 'from playwright.async_api import async_playwright, expect',
144
+ '',
145
+ '',
146
+ 'async def run_test():',
147
+ ' async with async_playwright() as pw:',
148
+ ' browser = await pw.chromium.launch(headless=True)',
149
+ ' context = await browser.new_context()',
150
+ ' page = await context.new_page()',
151
+ ' try:',
152
+ ' await page.goto("https://example.com") # target URL injected by the runner',
153
+ ' await page.click(\'[data-testid="cart"]\')',
154
+ ' await page.click(\'[data-testid="submit"]\')',
155
+ ' await expect(page.get_by_role("heading", name="Order placed")).to_be_visible()',
156
+ ' finally:',
157
+ ' await context.close()',
158
+ ' await browser.close()',
159
+ '',
160
+ '',
161
+ 'asyncio.run(run_test())',
119
162
  '',
120
163
  ].join('\n'),
121
164
  codeVersion: 'v3',
@@ -186,7 +229,9 @@ const latestResult = {
186
229
  targetUrlSource: 'run',
187
230
  failedStepIndex: 5,
188
231
  failureKind: 'assertion',
189
- summary: { passed: 4, failed: 1, skipped: 0 },
232
+ verdict: 'failed',
233
+ executionStatus: 'completed',
234
+ summary: 'Failed (assertion) on step 5: expected cart badge to show 1 item, but it was empty.',
190
235
  };
191
236
  const failureContext = {
192
237
  snapshotId: SAMPLE_SNAPSHOT_ID,
@@ -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,4 +1,5 @@
1
1
  import type { ErrorCode } from './errors.js';
2
+ import { ApiError } from './errors.js';
2
3
  import type { TriggerRunBody, TriggerRunResponse, RunResponse, RerunRequest, RerunResponse, BatchRerunRequest, BatchRerunResponse, BatchRunFreshRequest, BatchRunFreshResponse, ListRunsQuery, ListRunsResponse } from './runs.types.js';
3
4
  export type FetchImpl = typeof globalThis.fetch;
4
5
  export type DebugEventKind = 'request' | 'response' | 'retry' | 'error';
@@ -252,4 +253,23 @@ export declare class HttpClient {
252
253
  request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
253
254
  }
254
255
  export declare function buildUrl(baseUrl: string, path: string, query?: Record<string, string | number | boolean | undefined>): string;
256
+ /**
257
+ * Build a typed error for a successful response whose body could not be parsed
258
+ * as JSON.
259
+ *
260
+ * The CLI expects every API response to be a JSON envelope. When a `200 OK`
261
+ * carries a non-JSON body — a misconfigured endpoint, a proxy / captive-portal
262
+ * / SSO login page returning HTML with a success status, or an empty body —
263
+ * `response.json()` throws a raw `SyntaxError`. Left unhandled it escapes to
264
+ * the top-level handler in `index.ts`, which prints a bare
265
+ * `{"error":"<parse message>"}` under `--output json` (breaking the
266
+ * typed-envelope contract every other error honors) and gives the operator no
267
+ * actionable context.
268
+ *
269
+ * This wraps it in a typed `INTERNAL` `ApiError` (exit 1, unchanged) that
270
+ * carries the `requestId`, names the likely cause, and points the operator at
271
+ * their endpoint configuration. `details` includes the HTTP status, the
272
+ * response `content-type` (when present), and the underlying parse message.
273
+ */
274
+ export declare function malformedResponseError(response: Response, requestId: string, cause: unknown): ApiError;
255
275
  export declare function parseRetryAfter(headerValue: string | null): number | undefined;