@testsprite/testsprite-cli 0.6.0 → 0.8.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 (96) hide show
  1. package/README.md +52 -31
  2. package/dist/commands/agent.js +91 -45
  3. package/dist/commands/ci.d.ts +88 -0
  4. package/dist/commands/ci.js +429 -0
  5. package/dist/commands/doctor.d.ts +1 -1
  6. package/dist/commands/doctor.js +104 -8
  7. package/dist/commands/init.js +8 -0
  8. package/dist/commands/project.d.ts +78 -0
  9. package/dist/commands/project.js +429 -5
  10. package/dist/commands/schedule.d.ts +120 -0
  11. package/dist/commands/schedule.js +487 -0
  12. package/dist/commands/test.d.ts +176 -2
  13. package/dist/commands/test.js +2235 -609
  14. package/dist/commands/testlist.d.ts +88 -0
  15. package/dist/commands/testlist.js +753 -0
  16. package/dist/commands/tunnel.d.ts +72 -0
  17. package/dist/commands/tunnel.js +367 -0
  18. package/dist/index.js +113 -40
  19. package/dist/lib/agent-targets.d.ts +13 -4
  20. package/dist/lib/agent-targets.js +11 -2
  21. package/dist/lib/conflict-reason.d.ts +30 -0
  22. package/dist/lib/conflict-reason.js +45 -0
  23. package/dist/lib/credentials.js +42 -1
  24. package/dist/lib/cron.d.ts +40 -0
  25. package/dist/lib/cron.js +190 -0
  26. package/dist/lib/dry-run/samples.d.ts +9 -0
  27. package/dist/lib/dry-run/samples.js +293 -55
  28. package/dist/lib/errors.d.ts +9 -0
  29. package/dist/lib/errors.js +11 -0
  30. package/dist/lib/gh-output.d.ts +33 -1
  31. package/dist/lib/gh-output.js +97 -27
  32. package/dist/lib/http.d.ts +119 -0
  33. package/dist/lib/http.js +243 -2
  34. package/dist/lib/interrupt.d.ts +38 -13
  35. package/dist/lib/interrupt.js +130 -15
  36. package/dist/lib/junit-report.d.ts +20 -2
  37. package/dist/lib/junit-report.js +38 -5
  38. package/dist/lib/local-target.d.ts +95 -0
  39. package/dist/lib/local-target.js +184 -0
  40. package/dist/lib/plan-poll.d.ts +171 -0
  41. package/dist/lib/plan-poll.js +442 -0
  42. package/dist/lib/plans.types.d.ts +130 -0
  43. package/dist/lib/plans.types.js +31 -0
  44. package/dist/lib/poll-support.d.ts +26 -0
  45. package/dist/lib/poll-support.js +65 -0
  46. package/dist/lib/poll.d.ts +1 -0
  47. package/dist/lib/poll.js +2 -40
  48. package/dist/lib/proxy.d.ts +16 -0
  49. package/dist/lib/proxy.js +19 -1
  50. package/dist/lib/response-schemas.d.ts +20 -0
  51. package/dist/lib/response-schemas.js +55 -1
  52. package/dist/lib/run-progress.d.ts +41 -0
  53. package/dist/lib/run-progress.js +56 -0
  54. package/dist/lib/runs.types.d.ts +32 -3
  55. package/dist/lib/secret-file.d.ts +15 -0
  56. package/dist/lib/secret-file.js +82 -0
  57. package/dist/lib/target-url-preflight.d.ts +91 -0
  58. package/dist/lib/target-url-preflight.js +259 -0
  59. package/dist/lib/target-url.d.ts +63 -9
  60. package/dist/lib/target-url.js +283 -62
  61. package/dist/lib/telemetry.d.ts +11 -0
  62. package/dist/lib/telemetry.js +1 -0
  63. package/dist/lib/testlist.types.d.ts +77 -0
  64. package/dist/lib/testlist.types.js +9 -0
  65. package/dist/lib/ticker.d.ts +8 -0
  66. package/dist/lib/ticker.js +3 -0
  67. package/dist/lib/tunnel-session.d.ts +129 -0
  68. package/dist/lib/tunnel-session.js +232 -0
  69. package/dist/lib/tunnel.types.d.ts +54 -0
  70. package/dist/lib/tunnel.types.js +8 -0
  71. package/dist/lib/v3-advisory.d.ts +35 -22
  72. package/dist/lib/v3-advisory.js +44 -24
  73. package/dist/lib/wait-exit.d.ts +29 -0
  74. package/dist/lib/wait-exit.js +103 -0
  75. package/dist/vendor/tunnel-client/client.d.ts +83 -0
  76. package/dist/vendor/tunnel-client/client.js +871 -0
  77. package/dist/vendor/tunnel-client/config.d.ts +41 -0
  78. package/dist/vendor/tunnel-client/config.js +42 -0
  79. package/dist/vendor/tunnel-client/index.d.ts +9 -0
  80. package/dist/vendor/tunnel-client/index.js +9 -0
  81. package/dist/vendor/tunnel-client/lodash-lite.d.ts +14 -0
  82. package/dist/vendor/tunnel-client/lodash-lite.js +24 -0
  83. package/dist/vendor/tunnel-client/protocol.d.ts +60 -0
  84. package/dist/vendor/tunnel-client/protocol.js +143 -0
  85. package/dist/vendor/tunnel-client/types.d.ts +96 -0
  86. package/dist/vendor/tunnel-client/types.js +10 -0
  87. package/dist/vendor/tunnel-client/ws-compat.d.ts +206 -0
  88. package/dist/vendor/tunnel-client/ws-compat.js +316 -0
  89. package/dist/version-guard.d.ts +10 -7
  90. package/dist/version-guard.js +37 -9
  91. package/dist/version.d.ts +1 -1
  92. package/dist/version.js +1 -1
  93. package/package.json +2 -1
  94. package/skills/testsprite-onboard.skill.md +60 -4
  95. package/skills/testsprite-verify.codex.md +22 -16
  96. package/skills/testsprite-verify.skill.md +27 -18
@@ -1,12 +1,16 @@
1
1
  import { Command } from 'commander';
2
2
  import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factory.js';
3
3
  import { type WriteBundleResult } from '../lib/bundle.js';
4
- import { type JUnitReportFormat } from '../lib/junit-report.js';
4
+ import { type JUnitReportFormat, type JUnitTestResult } from '../lib/junit-report.js';
5
5
  import { ApiError } from '../lib/errors.js';
6
6
  import { type ShutdownHandle } from '../lib/interrupt.js';
7
7
  import type { FetchImpl } from '../lib/http.js';
8
8
  import { type Page } from '../lib/pagination.js';
9
+ import type { CliGetPlansResponse } from '../lib/plans.types.js';
9
10
  import type { RunResponse, TriggerRunResponse, RerunResponse, BatchRerunResponse, ListRunsResponse, RunSource, BatchRunFreshResponse, CancelRunResponse } from '../lib/runs.types.js';
11
+ import { type LoopbackHost } from '../lib/local-target.js';
12
+ import { type TunnelClientHandle } from '../lib/tunnel-session.js';
13
+ import { type TunnelClientOptions } from '../vendor/tunnel-client/index.js';
10
14
  import { type FlakyReport } from '../lib/flaky.js';
11
15
  /**
12
16
  * `details` debug block per the CLI OpenAPI `Test` schema
@@ -69,6 +73,12 @@ export interface CliTest {
69
73
  * no priority has been set. Text mode surfaces it only when truthy.
70
74
  */
71
75
  priority?: string | null;
76
+ /**
77
+ * Per-test step timeout in milliseconds. The execution engine applies it
78
+ * to every step. Optional/nullable for older backends and tests that use
79
+ * the engine defaults; text mode surfaces it only when it is a number.
80
+ */
81
+ stepTimeoutMs?: number | null;
72
82
  /**
73
83
  * Backend-only dependency declarations that drive wave ordering.
74
84
  * Optional on the wire so older facades that don't ship them still
@@ -323,6 +333,21 @@ export interface TestDeps {
323
333
  * pattern as `sleep` / `fetchImpl`).
324
334
  */
325
335
  shutdown?: ShutdownHandle;
336
+ /**
337
+ * Tunnel-client factory for `test run --local` (DEV-747 piece 3). Defaults
338
+ * to the vendored `TunnelClient`; tests inject a fake so the command's
339
+ * contract can be exercised without a real control plane — same pattern as
340
+ * `sleep` / `fetchImpl` / `shutdown`.
341
+ */
342
+ createTunnelClient?: (options: TunnelClientOptions) => TunnelClientHandle;
343
+ }
344
+ /** What happened when we tried to stop a doomed tunnel run. */
345
+ export type TunnelCancelOutcome = 'cancelled' | 'already-terminal' | 'failed' | 'skipped';
346
+ /** Tunnel-specific interrupt outcome consumed by the top-level JSON renderer. */
347
+ export interface TunnelInterruptDetach {
348
+ runId: string;
349
+ cancel: TunnelCancelOutcome;
350
+ nextAction: string;
326
351
  }
327
352
  type CommonOptions = FactoryCommonOptions;
328
353
  interface ListOptions extends CommonOptions {
@@ -380,6 +405,8 @@ interface CreateOptions extends CommonOptions {
380
405
  name: string;
381
406
  description?: string;
382
407
  priority?: CliCreatePriority;
408
+ /** Per-test timeout applied by the execution engine to every step. */
409
+ stepTimeoutMs?: number;
383
410
  /** Source path to the test code. Read into memory; capped at 350 KB. */
384
411
  codeFile: string;
385
412
  /** Caller-supplied idempotency token; UUIDv4 minted client-side if absent. */
@@ -414,6 +441,8 @@ interface CreateOptions extends CommonOptions {
414
441
  timeoutIsDefault?: boolean;
415
442
  /** M3.3 chain: per-run target URL override. */
416
443
  targetUrl?: string;
444
+ /** Skip the pre-charge --target-url reachability preflight (zero network calls). */
445
+ skipPreflight?: boolean;
417
446
  }
418
447
  /**
419
448
  * `test create --code-file <path>` — M3.2 piece-2 first mutation.
@@ -507,6 +536,10 @@ interface UpdateOptions extends CommonOptions {
507
536
  description?: string;
508
537
  /** Optional new priority. Enum-validated CLI-side. */
509
538
  priority?: CliCreatePriority;
539
+ /** Set the per-test timeout applied by the execution engine to every step. */
540
+ stepTimeoutMs?: number;
541
+ /** Clear the per-test step timeout and restore execution engine defaults. */
542
+ clearStepTimeout?: boolean;
510
543
  /** Backend-only: variable names this test produces (repeatable --produces). */
511
544
  produces?: string[];
512
545
  /** Backend-only: variable names this test consumes (repeatable --needs); wire field `consumes`. */
@@ -683,7 +716,7 @@ export interface CliCreateFromPlanResponse extends CliCreateTestResponse {
683
716
  * Caveat: the pinned tag only resolves once that version is actually
684
717
  * released — a locally-built/pre-release checkout may see a 404 until then.
685
718
  */
686
- export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.6.0/schemas/plan.schema.json";
719
+ export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.8.0/schemas/plan.schema.json";
687
720
  /**
688
721
  * The SINGLE canonical example plan. This
689
722
  * exact value (via `PLAN_TEMPLATE_TEXT` below) is:
@@ -900,6 +933,8 @@ interface CreateFromPlanOptions extends CommonOptions {
900
933
  timeoutIsDefault?: boolean;
901
934
  /** Reserved for the M3.3 chain. Per-run target URL override. */
902
935
  targetUrl?: string;
936
+ /** Skip the pre-charge --target-url reachability preflight (zero network calls). */
937
+ skipPreflight?: boolean;
903
938
  /**
904
939
  * Names of `test create` flags the caller supplied that `--plan-from`
905
940
  * ignores (identity lives in the JSON). Surfaced as a stderr advisory
@@ -951,6 +986,8 @@ interface CreateBatchOptions extends CommonOptions {
951
986
  timeoutSeconds?: number;
952
987
  /** With `--run`, override the project default env URL for each triggered run. */
953
988
  targetUrl?: string;
989
+ /** Skip the pre-charge --target-url reachability preflight (zero network calls). */
990
+ skipPreflight?: boolean;
954
991
  }
955
992
  /**
956
993
  * `test create-batch --plans <plans.jsonl>` — M3.2 piece-5.
@@ -1383,6 +1420,14 @@ export declare function runFailureGet(opts: FailureGetOptions, deps?: TestDeps):
1383
1420
  interface RunTestRunOptions extends CommonOptions {
1384
1421
  testId: string;
1385
1422
  targetUrl?: string;
1423
+ /**
1424
+ * Skip the pre-charge --target-url reachability preflight (zero
1425
+ * network calls). Also set by a delegating caller (`runCreate`/
1426
+ * `runCreateFromPlan` chaining `--run`) that already ran the same probe
1427
+ * against the same URL before its own create POST, so this run doesn't
1428
+ * probe twice.
1429
+ */
1430
+ skipPreflight?: boolean;
1386
1431
  wait: boolean;
1387
1432
  timeoutSeconds: number;
1388
1433
  /**
@@ -1419,6 +1464,33 @@ interface RunTestRunOptions extends CommonOptions {
1419
1464
  * the `resolveAlternate` probe (an extra round-trip we deliberately avoid).
1420
1465
  */
1421
1466
  type?: 'frontend' | 'backend';
1467
+ /**
1468
+ * `--local <port>` — run against an app on THIS machine, reached through a
1469
+ * TestSprite tunnel. Implies `--wait` (the tunnel's lifetime is this
1470
+ * process's lifetime) and is mutually exclusive with `--target-url`.
1471
+ */
1472
+ localPort?: number;
1473
+ /**
1474
+ * `--local-host` — which loopback spelling to name in the run's target URL.
1475
+ * Already normalised and validated by the command wiring; the accepted set
1476
+ * is `lib/local-target.ts::LOOPBACK_HOSTS`, which mirrors the server's.
1477
+ */
1478
+ localHost?: LoopbackHost;
1479
+ /**
1480
+ * `--tunnel-client <id>` — attach to a tunnel someone else already started
1481
+ * (`testsprite tunnel start`) instead of minting one. The client id is a
1482
+ * non-secret handle; the secret never leaves the process that minted it,
1483
+ * and this run neither owns nor deletes that binding.
1484
+ */
1485
+ tunnelClientId?: string;
1486
+ /**
1487
+ * `--cancel-on-interrupt` / `--no-cancel-on-interrupt`. Default ON, and
1488
+ * scoped to tunnel runs only. A tunnel run whose tunnel is closing is
1489
+ * already doomed, so cancelling stops the billing instead of paying for a
1490
+ * guaranteed failure — which is exactly why this was correctly shelved for
1491
+ * ordinary runs, where detaching leaves a run that can still pass.
1492
+ */
1493
+ cancelOnInterrupt?: boolean;
1422
1494
  }
1423
1495
  interface RunTestWaitOptions extends CommonOptions {
1424
1496
  runId: string;
@@ -1490,6 +1562,22 @@ interface RunTestRerunOptions extends CommonOptions {
1490
1562
  /** --summary-file: also write the reduced machine summary JSON to this path. */
1491
1563
  summaryFile?: string;
1492
1564
  }
1565
+ /** Minimal client surface the backend-test wait fallback needs. */
1566
+ interface ResultReadClient {
1567
+ get<T>(path: string, options?: {
1568
+ signal?: AbortSignal;
1569
+ }): Promise<T>;
1570
+ }
1571
+ /**
1572
+ * Overlay a terminal testId-scoped {@link CliLatestResult} onto the polled
1573
+ * (non-terminal) {@link RunResponse} so a backend test whose run-surface row
1574
+ * never finalizes still renders a complete, correctly-correlated run envelope.
1575
+ * The real correlation metadata (`runId`, `testId`, `projectId`, `userId`,
1576
+ * `source`, `createdAt`, `createdFrom`) is preserved from the polled run row;
1577
+ * only the verdict/result fields are taken from the test record (codex
1578
+ * round-2: don't fabricate blank correlation fields).
1579
+ */
1580
+ export declare function backendResultToRunResponse(result: CliLatestResult, run: RunResponse, testTitle?: string | null): RunResponse;
1493
1581
  /**
1494
1582
  * Decide whether a testId-scoped result belongs to THIS run (vs a stale
1495
1583
  * verdict from a prior run of the same test). Backend serializes runs per
@@ -1500,6 +1588,26 @@ interface RunTestRerunOptions extends CommonOptions {
1500
1588
  * - result has no runId (legacy) → accept iff finishedAt >= notBefore.
1501
1589
  */
1502
1590
  export declare function backendResultIsForThisRun(result: CliLatestResult, runId: string, notBefore: string | undefined): boolean;
1591
+ /**
1592
+ * Build a `resolveAlternate` callback for `pollRunUntilTerminal` that falls
1593
+ * back to the testId-scoped verdict for **backend** tests (dogfood L1888).
1594
+ *
1595
+ * - The first non-terminal run tick does a one-time `GET /tests/{id}` to learn
1596
+ * the test type (cached). Frontend tests → no-op forever, so the FE path is
1597
+ * byte-identical to before.
1598
+ * - For backend tests, each later non-terminal tick reads
1599
+ * `GET /tests/{id}/result`; once that record is terminal AND belongs to this
1600
+ * run, a synthesized terminal `RunResponse` resolves the wait (exit 0/1)
1601
+ * instead of timing out (exit 7).
1602
+ * - Every lookup is best-effort: any error → "keep polling the run row", so
1603
+ * the fallback can never make either path worse than the prior timeout.
1604
+ */
1605
+ export declare function makeBackendWaitFallback(args: {
1606
+ client: ResultReadClient;
1607
+ resolveTestId: (run: RunResponse) => string;
1608
+ resolveNotBefore: (run: RunResponse) => string | undefined;
1609
+ onResolved?: (testId: string, status: CliPublicStatus) => void;
1610
+ }): (run: RunResponse, elapsedMs: number, signal: AbortSignal) => Promise<RunResponse | null>;
1503
1611
  /**
1504
1612
  * `test run <test-id>` — M3.3 piece-3.
1505
1613
  *
@@ -1618,7 +1726,24 @@ interface RunTestRunAllOptions extends CommonOptions {
1618
1726
  ghOutput?: boolean;
1619
1727
  /** --summary-file: also write the reduced machine summary JSON to this path. */
1620
1728
  summaryFile?: string;
1729
+ /**
1730
+ * --allow-empty: exit 0 (instead of failing) when the batch dispatches ZERO
1731
+ * tests (all skipped / empty project / --filter matched nothing). Default off:
1732
+ * a zero-dispatch `--all` is a CI false-green, so it fails with exit 5 by
1733
+ * default and still emits the summary / annotation / JUnit report (DEV-1046).
1734
+ */
1735
+ allowEmpty?: boolean;
1621
1736
  }
1737
+ export declare function writeBatchJUnitReportIfRequested(opts: {
1738
+ report?: JUnitReportFormat;
1739
+ reportFile?: string;
1740
+ reportSuiteName?: string;
1741
+ projectId?: string;
1742
+ }, results: readonly (JUnitTestResult & {
1743
+ startedAt?: string | null;
1744
+ finishedAt?: string | null;
1745
+ testTitle?: string | null;
1746
+ })[], nameByTestId?: ReadonlyMap<string, string>): Promise<void>;
1622
1747
  /**
1623
1748
  * `test run --all --project <id>` — M4 piece-2.
1624
1749
  *
@@ -1725,5 +1850,54 @@ export declare function resolveWaitRequestTimeoutMs(opts: {
1725
1850
  }): number | undefined;
1726
1851
  /** A presigned `code` body is any `https://` URL — never anything else. */
1727
1852
  export declare function isPresignedCodeUrl(code: string): boolean;
1853
+ interface PlanGenerateOptions extends CommonOptions {
1854
+ projectId?: string;
1855
+ timeoutSeconds: number;
1856
+ idempotencyKey?: string;
1857
+ }
1858
+ interface PlanAcceptOptions extends CommonOptions {
1859
+ projectId?: string;
1860
+ /** Raw `--only` tokens from Commander (variadic); undefined = flag absent. */
1861
+ only?: string[];
1862
+ idempotencyKey?: string;
1863
+ }
1864
+ /** Text card for a settled successful generate (or `--dry-run`). */
1865
+ /** Exported for the renderer-level spec: the zero-proposals branch is not
1866
+ * reachable through `runGenerationLadder` today (after the proposals rung it
1867
+ * polls until staged/failed/timeout), so it is pinned directly. */
1868
+ export declare function renderPlanGenerateResultText(plans: CliGetPlansResponse, projectId: string, creditsUsed: number | null, skippedCategories?: number | null): string;
1869
+ /**
1870
+ * `test plan generate --project <id>` — DEV-384 V3-B.
1871
+ *
1872
+ * Drives the server's generation ladder (exploration → strategy →
1873
+ * proposals) through `runGenerationLadder` and renders the staged
1874
+ * proposals. Exit 0 on staged proposals, 1 on a server-side stage failure,
1875
+ * 7 on timeout (typed `UNSUPPORTED` envelope — the raw ladder timeout is
1876
+ * not a CLI error), 130/143 on Ctrl-C detach (honest: work and charges
1877
+ * continue server-side), plus the usual catalog exits for trigger errors
1878
+ * (412 → 6 with the exact fix command, 402 → 12, 404 → 4, 429 → 11).
1879
+ */
1880
+ export declare function runPlanGenerate(opts: PlanGenerateOptions, deps?: TestDeps): Promise<unknown>;
1881
+ /** Derived, additive result the CLI prints for `accept` — the server truth
1882
+ * (`acceptedCount`, `caseKeys`) plus the client-side discard count. A
1883
+ * frontend/API split used to be derived from the selected proposals' `type`
1884
+ * fields; it was dropped (DEV-384 review F10) — the backend fills every
1885
+ * proposal's `type` from the PROJECT, so the split was always (all, 0) or
1886
+ * (0, all) and would be actively wrong for mixed projects. */
1887
+ interface PlanAcceptResult {
1888
+ projectId: string;
1889
+ acceptedCount: number;
1890
+ caseKeys: string[];
1891
+ discardedCount: number;
1892
+ }
1893
+ /**
1894
+ * `test plan accept --project <id> [--only <ids...>]` — DEV-384 V3-B.
1895
+ *
1896
+ * Reads the staged batch, selects all of it (or the `--only` subset),
1897
+ * and POSTs an EXPLICIT id list. Free — the generation charge already
1898
+ * covered it. Exit 0 on success, 5 on a bad `--only` selection (request
1899
+ * never sent), 6 when nothing is staged (pointer at `test plan generate`).
1900
+ */
1901
+ export declare function runPlanAccept(opts: PlanAcceptOptions, deps?: TestDeps): Promise<PlanAcceptResult | undefined>;
1728
1902
  export declare function createTestArtifactCommand(deps: TestDeps): Command;
1729
1903
  export {};