@testsprite/testsprite-cli 0.7.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 (68) hide show
  1. package/README.md +51 -38
  2. package/dist/commands/agent.js +47 -3
  3. package/dist/commands/ci.d.ts +88 -0
  4. package/dist/commands/ci.js +429 -0
  5. package/dist/commands/doctor.js +100 -1
  6. package/dist/commands/init.js +8 -0
  7. package/dist/commands/project.d.ts +78 -0
  8. package/dist/commands/project.js +426 -3
  9. package/dist/commands/test.d.ts +162 -2
  10. package/dist/commands/test.js +1814 -392
  11. package/dist/commands/testlist.js +15 -9
  12. package/dist/commands/tunnel.d.ts +72 -0
  13. package/dist/commands/tunnel.js +367 -0
  14. package/dist/index.js +107 -38
  15. package/dist/lib/dry-run/samples.d.ts +9 -0
  16. package/dist/lib/dry-run/samples.js +116 -0
  17. package/dist/lib/gh-output.d.ts +7 -0
  18. package/dist/lib/gh-output.js +50 -7
  19. package/dist/lib/http.d.ts +94 -0
  20. package/dist/lib/http.js +120 -5
  21. package/dist/lib/interrupt.d.ts +38 -13
  22. package/dist/lib/interrupt.js +130 -15
  23. package/dist/lib/local-target.d.ts +95 -0
  24. package/dist/lib/local-target.js +184 -0
  25. package/dist/lib/plan-poll.d.ts +171 -0
  26. package/dist/lib/plan-poll.js +442 -0
  27. package/dist/lib/plans.types.d.ts +130 -0
  28. package/dist/lib/plans.types.js +31 -0
  29. package/dist/lib/poll-support.d.ts +26 -0
  30. package/dist/lib/poll-support.js +65 -0
  31. package/dist/lib/poll.d.ts +1 -0
  32. package/dist/lib/poll.js +2 -40
  33. package/dist/lib/response-schemas.d.ts +13 -0
  34. package/dist/lib/response-schemas.js +32 -0
  35. package/dist/lib/run-progress.d.ts +41 -0
  36. package/dist/lib/run-progress.js +56 -0
  37. package/dist/lib/runs.types.d.ts +24 -0
  38. package/dist/lib/target-url-preflight.js +3 -3
  39. package/dist/lib/target-url.d.ts +44 -7
  40. package/dist/lib/target-url.js +250 -61
  41. package/dist/lib/telemetry.d.ts +11 -0
  42. package/dist/lib/telemetry.js +1 -0
  43. package/dist/lib/ticker.d.ts +8 -0
  44. package/dist/lib/ticker.js +3 -0
  45. package/dist/lib/tunnel-session.d.ts +129 -0
  46. package/dist/lib/tunnel-session.js +232 -0
  47. package/dist/lib/tunnel.types.d.ts +54 -0
  48. package/dist/lib/tunnel.types.js +8 -0
  49. package/dist/vendor/tunnel-client/client.d.ts +83 -0
  50. package/dist/vendor/tunnel-client/client.js +871 -0
  51. package/dist/vendor/tunnel-client/config.d.ts +41 -0
  52. package/dist/vendor/tunnel-client/config.js +42 -0
  53. package/dist/vendor/tunnel-client/index.d.ts +9 -0
  54. package/dist/vendor/tunnel-client/index.js +9 -0
  55. package/dist/vendor/tunnel-client/lodash-lite.d.ts +14 -0
  56. package/dist/vendor/tunnel-client/lodash-lite.js +24 -0
  57. package/dist/vendor/tunnel-client/protocol.d.ts +60 -0
  58. package/dist/vendor/tunnel-client/protocol.js +143 -0
  59. package/dist/vendor/tunnel-client/types.d.ts +96 -0
  60. package/dist/vendor/tunnel-client/types.js +10 -0
  61. package/dist/vendor/tunnel-client/ws-compat.d.ts +206 -0
  62. package/dist/vendor/tunnel-client/ws-compat.js +316 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +2 -1
  66. package/skills/testsprite-onboard.skill.md +60 -4
  67. package/skills/testsprite-verify.codex.md +22 -16
  68. 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. */
@@ -509,6 +536,10 @@ interface UpdateOptions extends CommonOptions {
509
536
  description?: string;
510
537
  /** Optional new priority. Enum-validated CLI-side. */
511
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;
512
543
  /** Backend-only: variable names this test produces (repeatable --produces). */
513
544
  produces?: string[];
514
545
  /** Backend-only: variable names this test consumes (repeatable --needs); wire field `consumes`. */
@@ -685,7 +716,7 @@ export interface CliCreateFromPlanResponse extends CliCreateTestResponse {
685
716
  * Caveat: the pinned tag only resolves once that version is actually
686
717
  * released — a locally-built/pre-release checkout may see a 404 until then.
687
718
  */
688
- export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.7.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";
689
720
  /**
690
721
  * The SINGLE canonical example plan. This
691
722
  * exact value (via `PLAN_TEMPLATE_TEXT` below) is:
@@ -1433,6 +1464,33 @@ interface RunTestRunOptions extends CommonOptions {
1433
1464
  * the `resolveAlternate` probe (an extra round-trip we deliberately avoid).
1434
1465
  */
1435
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;
1436
1494
  }
1437
1495
  interface RunTestWaitOptions extends CommonOptions {
1438
1496
  runId: string;
@@ -1504,6 +1562,22 @@ interface RunTestRerunOptions extends CommonOptions {
1504
1562
  /** --summary-file: also write the reduced machine summary JSON to this path. */
1505
1563
  summaryFile?: string;
1506
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;
1507
1581
  /**
1508
1582
  * Decide whether a testId-scoped result belongs to THIS run (vs a stale
1509
1583
  * verdict from a prior run of the same test). Backend serializes runs per
@@ -1514,6 +1588,26 @@ interface RunTestRerunOptions extends CommonOptions {
1514
1588
  * - result has no runId (legacy) → accept iff finishedAt >= notBefore.
1515
1589
  */
1516
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>;
1517
1611
  /**
1518
1612
  * `test run <test-id>` — M3.3 piece-3.
1519
1613
  *
@@ -1632,7 +1726,24 @@ interface RunTestRunAllOptions extends CommonOptions {
1632
1726
  ghOutput?: boolean;
1633
1727
  /** --summary-file: also write the reduced machine summary JSON to this path. */
1634
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;
1635
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>;
1636
1747
  /**
1637
1748
  * `test run --all --project <id>` — M4 piece-2.
1638
1749
  *
@@ -1739,5 +1850,54 @@ export declare function resolveWaitRequestTimeoutMs(opts: {
1739
1850
  }): number | undefined;
1740
1851
  /** A presigned `code` body is any `https://` URL — never anything else. */
1741
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>;
1742
1902
  export declare function createTestArtifactCommand(deps: TestDeps): Command;
1743
1903
  export {};