@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.
Files changed (56) hide show
  1. package/README.md +27 -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 +200 -10
  13. package/dist/commands/test.js +1636 -351
  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 +84 -0
  32. package/dist/lib/gh-output.js +202 -0
  33. package/dist/lib/http.d.ts +33 -15
  34. package/dist/lib/http.js +141 -7
  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 +72 -36
  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 +282 -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 +30 -1
  50. package/dist/lib/v3-advisory.js +35 -4
  51. package/dist/version.d.ts +1 -1
  52. package/dist/version.js +1 -1
  53. package/package.json +17 -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
@@ -326,7 +326,7 @@ export interface TestDeps {
326
326
  }
327
327
  type CommonOptions = FactoryCommonOptions;
328
328
  interface ListOptions extends CommonOptions {
329
- projectId: string;
329
+ projectId?: string;
330
330
  type?: 'frontend' | 'backend';
331
331
  createdFrom?: 'portal' | 'mcp' | 'cli';
332
332
  /**
@@ -339,6 +339,8 @@ interface ListOptions extends CommonOptions {
339
339
  pageSize?: number;
340
340
  startingToken?: string;
341
341
  maxItems?: number;
342
+ columns?: string;
343
+ noHeader?: boolean;
342
344
  }
343
345
  export declare function runList(opts: ListOptions, deps?: TestDeps): Promise<Page<CliTest>>;
344
346
  /**
@@ -357,11 +359,23 @@ export interface CliCreateTestResponse {
357
359
  * still succeeded.
358
360
  */
359
361
  warnings?: string[];
362
+ /**
363
+ * Server-built Portal deep link for the created test (DEV-737). Same
364
+ * presence/absence contract as `RunResponse.dashboardUrl`
365
+ * (`withRunDashboardUrl` below): PRESENT (string or falsy) on a backend
366
+ * that resolved the question at all — a falsy value means "there is no
367
+ * correct link for this test" (e.g. a V3-native create with no DynamoDB
368
+ * mirror row for the client's V2-shaped guess to land on) and must never
369
+ * be replaced by the client fallback; ABSENT on an older backend that
370
+ * predates this field, which safely reopens the client fallback via
371
+ * `resolveDashboardUrl` below. See that function's doc for the reasoning.
372
+ */
373
+ dashboardUrl?: string | null;
360
374
  }
361
375
  export declare const CLI_CREATE_PRIORITIES: readonly ["p0", "p1", "p2", "p3"];
362
376
  export type CliCreatePriority = (typeof CLI_CREATE_PRIORITIES)[number];
363
377
  interface CreateOptions extends CommonOptions {
364
- projectId: string;
378
+ projectId?: string;
365
379
  type: 'frontend' | 'backend';
366
380
  name: string;
367
381
  description?: string;
@@ -644,6 +658,64 @@ export interface CliPlanInput {
644
658
  export interface CliCreateFromPlanResponse extends CliCreateTestResponse {
645
659
  planSteps?: CliPlanStep[];
646
660
  }
661
+ /**
662
+ * Public raw-content URL for
663
+ * `schemas/plan.schema.json`, shipped in both the npm package (see
664
+ * `package.json` `files`) and the repo. Points at the PUBLIC mirror
665
+ * (`TestSprite/testsprite-cli`) since that's what ships to npm consumers;
666
+ * the private atlas repo syncs to it via `scripts/make-public-snapshot.sh`.
667
+ *
668
+ * Pinned to the running CLI's own `v<VERSION>` git tag (the same `VERSION`
669
+ * constant `--version` / `doctor` / the update-check registry probe already
670
+ * read from `src/version.ts`) rather than the mutable `main` branch — a plan
671
+ * file authored against one CLI version should resolve the SAME schema
672
+ * forever, not whatever `main` happens to contain when the file is opened
673
+ * months later (`main` can gain new required fields between versions).
674
+ *
675
+ * This is deliberately DIFFERENT from `schemas/plan.schema.json`'s own
676
+ * internal `$id`, which stays the canonical `main` URL — `$id` is a schema
677
+ * IDENTITY (what this document calls itself, used for cross-referencing),
678
+ * not a fetch instruction, so it is intentionally version-independent.
679
+ * `PLAN_SCHEMA_URL` is the fetch instruction embedded in generated plan
680
+ * files and is intentionally version-PINNED. See DOCUMENTATION.md's "Plan
681
+ * file format" section for the same distinction spelled out for humans.
682
+ *
683
+ * Caveat: the pinned tag only resolves once that version is actually
684
+ * released — a locally-built/pre-release checkout may see a 404 until then.
685
+ */
686
+ export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.6.0/schemas/plan.schema.json";
687
+ /**
688
+ * The SINGLE canonical example plan. This
689
+ * exact value (via `PLAN_TEMPLATE_TEXT` below) is:
690
+ * - printed to stdout by `test create --plan-template`
691
+ * - embedded verbatim in `test create --help` (`PLAN_TEMPLATE_HELP_TEXT`)
692
+ * - asserted in tests against `schemas/plan.schema.json` and against
693
+ * `assertPlanShape` so the three surfaces can't drift
694
+ *
695
+ * Deliberately minimal (no optional `description`/`priority`) — this is
696
+ * the smallest shape `assertPlanShape` accepts, not a fully-annotated
697
+ * showcase (that lives in `skills/testsprite-verify.skill.md`).
698
+ */
699
+ export declare const PLAN_TEMPLATE: CliPlanInput;
700
+ /** `CliPlanInput` plus the optional editor-discoverability hint. */
701
+ export interface PlanFileTemplate extends CliPlanInput {
702
+ $schema: string;
703
+ }
704
+ /**
705
+ * `$schema` is an ordinary extra property from `assertPlanShape`'s point of
706
+ * view (no `additionalProperties` check exists on the plan-from path) — it
707
+ * validates exactly like a bare `CliPlanInput` while giving editors (VS
708
+ * Code's JSON language service, and by extension Copilot inline
709
+ * completions) something to resolve for live validation as the file is
710
+ * edited.
711
+ */
712
+ export declare const PLAN_TEMPLATE_WITH_SCHEMA: PlanFileTemplate;
713
+ /**
714
+ * Rendered once from the object above (never hand-formatted separately) so
715
+ * `test create --plan-template`'s stdout and `test create --help`'s example
716
+ * are generated from — not merely modeled on — the same source.
717
+ */
718
+ export declare const PLAN_TEMPLATE_TEXT: string;
647
719
  /** Per-spec result from `POST /tests/batch`. */
648
720
  export interface CliBatchSpecResult {
649
721
  /** Position of the spec in the input JSONL, preserved across the response. */
@@ -658,6 +730,12 @@ export interface CliBatchSpecResult {
658
730
  message: string;
659
731
  field?: string;
660
732
  };
733
+ /**
734
+ * Server-built Portal deep link for this created item (DEV-737). Same
735
+ * presence/absence contract as `CliCreateTestResponse.dashboardUrl` —
736
+ * see that field's doc.
737
+ */
738
+ dashboardUrl?: string | null;
661
739
  }
662
740
  export interface CliCreateBatchResponse {
663
741
  results: CliBatchSpecResult[];
@@ -691,6 +769,13 @@ export interface CliBatchRunResult {
691
769
  message: string;
692
770
  exitCode: number;
693
771
  };
772
+ /**
773
+ * Portal deep link (R3b), threaded through from the SAME per-item
774
+ * create-time decision `test create-batch`'s own output carries — never
775
+ * recomputed at run time. Absent when unresolvable OR explicitly
776
+ * suppressed by the server (see `resolveDashboardUrl`'s doc).
777
+ */
778
+ dashboardUrl?: string;
694
779
  }
695
780
  /** Envelope emitted by `test create-batch --run` in JSON mode. */
696
781
  export interface CliCreateBatchRunResponse {
@@ -723,6 +808,39 @@ export declare const BATCH_RUN_RATE_LIMIT = 50;
723
808
  export declare const BATCH_RUN_RATE_WINDOW_MS = 60000;
724
809
  /** Maximum number of outer RATE_LIMITED retries inside the batch fan-out (beyond HTTP-layer retries). */
725
810
  export declare const BATCH_RUN_RATE_MAX_OUTER_RETRIES = 5;
811
+ /**
812
+ * Maximum number of outer RATE_LIMITED retries per member inside the multi-id
813
+ * `test wait` fan-out (beyond HTTP-layer retries). Lower than the trigger
814
+ * fan-out's budget on purpose: a throttled *poll* costs nothing but latency and
815
+ * the run is already executing, so a couple of Retry-After-length backoffs is
816
+ * enough to ride out one limiter window — burning the whole `--timeout` on
817
+ * backoff instead of reporting the throttle would be worse than reporting it.
818
+ */
819
+ export declare const WAIT_POLL_RATE_MAX_OUTER_RETRIES = 3;
820
+ /**
821
+ * Backoff to honour before retrying a `RATE_LIMITED` response, in ms.
822
+ *
823
+ * Precedence: `ApiError.retryAfterMs` (set by `HttpClient` from the HTTP
824
+ * `Retry-After` header, already clamped to [1s, 300s]) → `details.retryAfterSeconds`
825
+ * from the envelope body, capped at 120s → 60s. Callers clamp the result to their
826
+ * own remaining deadline; this function only decides "how long does the server
827
+ * want us to wait."
828
+ *
829
+ * Shared by the `test run --all` trigger fan-out and the multi-id `test wait`
830
+ * poll fan-out so the two can't drift — they were hand-copies of the same
831
+ * precedence rule.
832
+ */
833
+ /**
834
+ * Sleep that a termination signal cuts short by rejecting with the signal's
835
+ * `InterruptError`, so the caller's existing DEV-331 catch owns the detach UX.
836
+ *
837
+ * Mirrors `HttpClient.sleepBeforeRetry` — an in-flight backoff must not be a
838
+ * window where a first Ctrl-C hard-exits with empty stdout. The caller is
839
+ * responsible for having ARMED the shutdown scope; a disarmed controller never
840
+ * aborts its signal, so this would otherwise sleep straight through the signal.
841
+ */
842
+ export declare function sleepUntilOrInterrupt(ms: number, signal: AbortSignal | undefined, sleep: (ms: number) => Promise<void>): Promise<void>;
843
+ export declare function resolveRateLimitRetryMs(err: ApiError): number;
726
844
  /**
727
845
  * D3: max automatic retry attempts for deferred tests under `--wait`.
728
846
  * Each attempt is preceded by a Retry-After-aware sleep (server value if
@@ -1047,7 +1165,10 @@ export interface CliRunDiff {
1047
1165
  * green run?"). Pure client-side composition of the existing per-run read
1048
1166
  * (`GET /runs/{id}?includeSteps=true`); the endpoint accepts any two run-ids,
1049
1167
  * so a cross-test pair is a WARNING, not an error. Exit 0 when the verdicts
1050
- * match, exit 1 when they differ, so the command is CI-scriptable.
1168
+ * match, exit 1 when they differ, so the command is CI-scriptable —
1169
+ * `--dry-run` honors the same contract: the canned sample has a
1170
+ * changed verdict, so `test diff --dry-run` (with no overrides) exits 1,
1171
+ * same as a real regressed pair would.
1051
1172
  */
1052
1173
  export declare function runDiff(opts: DiffOptions, deps?: TestDeps): Promise<CliRunDiff>;
1053
1174
  export interface LintOptions extends CommonOptions {
@@ -1074,6 +1195,15 @@ export interface CliLintReport {
1074
1195
  * so authoring a 12-plan directory meant one error per paid round-trip. Zero
1075
1196
  * network, zero credentials: exit 0 when everything is valid, 5 otherwise, so
1076
1197
  * it drops into a pre-commit hook or CI step before `create-batch`.
1198
+ *
1199
+ * The collection granularity used to be per-FILE, not per-PROBLEM — a single
1200
+ * plan with 6 independent field errors reported one at a time across 6
1201
+ * fix-and-rerun cycles, because each file was validated through the
1202
+ * throw-on-first `assertPlanShape`/`assertPlanStepsShape`. Every branch below
1203
+ * now separates "parse the file" (still a single fatal issue on I/O/JSON
1204
+ * failure — there's nothing left to validate) from "check the parsed shape"
1205
+ * (routed through `collectPlanIssues` / `collectPlanStepsIssues`, which
1206
+ * report every failing field in one pass).
1077
1207
  */
1078
1208
  export declare function runLint(opts: LintOptions, deps?: TestDeps): Promise<CliLintReport>;
1079
1209
  export interface ScaffoldOptions extends CommonOptions {
@@ -1099,6 +1229,38 @@ export interface CliBackendScaffold {
1099
1229
  * would pass without asserting anything).
1100
1230
  */
1101
1231
  export declare function runScaffold(opts: ScaffoldOptions, deps?: TestDeps): Promise<CliPlanInput | CliBackendScaffold>;
1232
+ /**
1233
+ * `test create --plan-template` — prints the canonical minimal
1234
+ * valid plan file (`PLAN_TEMPLATE_WITH_SCHEMA` / `PLAN_TEMPLATE_TEXT`,
1235
+ * defined above near `CliPlanInput`) to stdout and exits — before any of
1236
+ * `test create`'s other flag handling runs. Pure-local: no network, no
1237
+ * credentials, no filesystem I/O.
1238
+ *
1239
+ * Deliberately simpler than `test scaffold --type frontend` (which
1240
+ * substitutes a live `TESTSPRITE_PROJECT_ID` when set, and supports
1241
+ * `--out`): `--plan-template`'s job is a single deterministic ground-truth
1242
+ * document that is BYTE-IDENTICAL every invocation, because it doubles as
1243
+ * the literal example embedded in `test create --help` and the
1244
+ * fixture asserted against `schemas/plan.schema.json` in tests.
1245
+ */
1246
+ export declare function runPlanTemplate(opts: CommonOptions, deps?: TestDeps): PlanFileTemplate;
1247
+ export interface OpenOptions extends CommonOptions {
1248
+ testId: string;
1249
+ /** Print the URL only; never spawn a browser (SSH/headless/CI/agents). */
1250
+ noBrowser: boolean;
1251
+ }
1252
+ /**
1253
+ * `test open <test-id>` (issue #121): jump from the terminal to the test's
1254
+ * dashboard page. The CLI already computes this deep-link and prints it as
1255
+ * text on other commands; this closes the last inch (the `gh browse` /
1256
+ * `cypress open` hop). The URL is ALWAYS printed to stdout (so `--no-browser`
1257
+ * and headless use still compose), then the OS browser is spawned unless
1258
+ * --no-browser. An endpoint with no known portal mapping is a hard error
1259
+ * rather than a silent no-op.
1260
+ */
1261
+ export declare function runOpen(opts: OpenOptions, deps?: TestDeps, opener?: (url: string) => void): Promise<{
1262
+ dashboardUrl: string;
1263
+ }>;
1102
1264
  export declare function runSteps(opts: StepsOptions, deps?: TestDeps): Promise<Page<CliTestStep>>;
1103
1265
  interface ResultOptions extends CommonOptions {
1104
1266
  testId: string;
@@ -1138,6 +1300,13 @@ interface ResultHistoryOptions extends CommonOptions {
1138
1300
  pageSize?: number;
1139
1301
  /** Opaque cursor from a prior page's `nextCursor`. */
1140
1302
  cursor?: string;
1303
+ /**
1304
+ * Client-side rerun filter. `true` → only reruns (isRerun), `false` → only
1305
+ * fresh runs, `undefined` → no filter. Applied to each page after the fetch.
1306
+ */
1307
+ rerun?: boolean;
1308
+ columns?: string;
1309
+ noHeader?: boolean;
1141
1310
  }
1142
1311
  /**
1143
1312
  * `test result <test-id> --history [options]`
@@ -1224,6 +1393,14 @@ interface RunTestRunOptions extends CommonOptions {
1224
1393
  */
1225
1394
  timeoutIsDefault?: boolean;
1226
1395
  idempotencyKey?: string;
1396
+ /**
1397
+ * --gh-output: force the GitHub-native output layer (::error:: annotations +
1398
+ * job-summary table) even off-Actions. On the single-test `--wait` path the
1399
+ * result is reduced to a one-row CI summary (`summarizeSingleRun`).
1400
+ */
1401
+ ghOutput?: boolean;
1402
+ /** --summary-file: also write the reduced machine summary JSON to this path. */
1403
+ summaryFile?: string;
1227
1404
  /**
1228
1405
  * Per codex round-1 P1: when chained from `test create --run`, the caller
1229
1406
  * passes the create response here so `runTestRun` can emit a single merged
@@ -1305,6 +1482,13 @@ interface RunTestRerunOptions extends CommonOptions {
1305
1482
  reportFile?: string;
1306
1483
  /** --report-suite-name: optional override for the JUnit <testsuite name=...>. */
1307
1484
  reportSuiteName?: string;
1485
+ /**
1486
+ * --gh-output: force the GitHub-native output layer (::error:: annotations +
1487
+ * job-summary table) on the batch-rerun `--wait` result, even off-Actions.
1488
+ */
1489
+ ghOutput?: boolean;
1490
+ /** --summary-file: also write the reduced machine summary JSON to this path. */
1491
+ summaryFile?: string;
1308
1492
  }
1309
1493
  /**
1310
1494
  * Decide whether a testId-scoped result belongs to THIS run (vs a stale
@@ -1412,8 +1596,8 @@ export declare function createTestCancelCommand(deps: TestDeps): Command;
1412
1596
  */
1413
1597
  export declare function runTestWait(opts: RunTestWaitOptions, deps?: TestDeps): Promise<RunResponse>;
1414
1598
  interface RunTestRunAllOptions extends CommonOptions {
1415
- /** projectId to run all tests in. */
1416
- projectId: string;
1599
+ /** projectId to run all tests in; may be resolved from --project or TESTSPRITE_PROJECT_ID. */
1600
+ projectId?: string;
1417
1601
  /** --filter <substr>: only run tests whose name contains this substring (case-insensitive). */
1418
1602
  nameFilter?: string;
1419
1603
  /** --wait: block until terminal or --timeout. */
@@ -1430,6 +1614,10 @@ interface RunTestRunAllOptions extends CommonOptions {
1430
1614
  reportFile?: string;
1431
1615
  /** --report-suite-name: optional override for the JUnit <testsuite name=...>. */
1432
1616
  reportSuiteName?: string;
1617
+ /** --gh-output: force the GitHub-native output layer even off-Actions (issue #99). */
1618
+ ghOutput?: boolean;
1619
+ /** --summary-file: also write the reduced machine summary JSON to this path. */
1620
+ summaryFile?: string;
1433
1621
  }
1434
1622
  /**
1435
1623
  * `test run --all --project <id>` — M4 piece-2.
@@ -1442,8 +1630,9 @@ export declare function runTestRunAll(opts: RunTestRunAllOptions, deps?: TestDep
1442
1630
  /**
1443
1631
  * `test rerun` — M3.4 piece-3.
1444
1632
  *
1445
- * FE: `POST /tests/{id}/runs/rerun` → verbatim replay (no credit). With
1446
- * `--wait`, polls `GET /runs/{runId}` until terminal.
1633
+ * FE: `POST /tests/{id}/runs/rerun` → verbatim replay, billed at 0.5 credits
1634
+ * (same as a fresh run; legacy V2 accounts: free). With `--wait`, polls
1635
+ * `GET /runs/{runId}` until terminal.
1447
1636
  *
1448
1637
  * BE: same route → closure + per-member runIds. With `--wait`, polls every
1449
1638
  * closure-member runId; exits on the named test's verdict; failed closure
@@ -1508,9 +1697,10 @@ interface RunTestFlakyOptions extends CommonOptions {
1508
1697
  * `test flaky <test-id>` — replay a test N times and report a stability score.
1509
1698
  *
1510
1699
  * Each attempt is a `POST /tests/{id}/runs/rerun` with auto-heal OFF (a strict
1511
- * verbatim replay) followed by `pollRunUntilTerminal`. Frontend replays are
1512
- * free verbatim script replays; backend replays re-run the dependency closure
1513
- * (a one-line credit advisory is printed). The pure scoring lives in
1700
+ * verbatim replay) followed by `pollRunUntilTerminal`. Each replay is billed
1701
+ * as a rerun (0.5 credits FE / 0.2 credits BE, same as a fresh run; legacy V2
1702
+ * accounts: FE rerun remains free) — a one-line credit advisory is printed
1703
+ * for backend tests. The pure scoring lives in
1514
1704
  * `lib/flaky.ts`; this function is the I/O orchestrator.
1515
1705
  *
1516
1706
  * Exit code: 0 when every observed attempt passed (stable), else 1 — so CI can