@testsprite/testsprite-cli 0.7.0 → 0.9.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 (74) hide show
  1. package/README.md +62 -45
  2. package/dist/commands/agent.d.ts +3 -0
  3. package/dist/commands/agent.js +79 -10
  4. package/dist/commands/ci.d.ts +88 -0
  5. package/dist/commands/ci.js +432 -0
  6. package/dist/commands/doctor.js +100 -1
  7. package/dist/commands/init.d.ts +45 -2
  8. package/dist/commands/init.js +198 -29
  9. package/dist/commands/project.d.ts +78 -0
  10. package/dist/commands/project.js +439 -5
  11. package/dist/commands/test.d.ts +193 -4
  12. package/dist/commands/test.js +1948 -398
  13. package/dist/commands/testlist.js +15 -9
  14. package/dist/commands/tunnel.d.ts +72 -0
  15. package/dist/commands/tunnel.js +367 -0
  16. package/dist/index.js +107 -38
  17. package/dist/lib/agent-detect.d.ts +53 -0
  18. package/dist/lib/agent-detect.js +198 -0
  19. package/dist/lib/dry-run/samples.d.ts +9 -0
  20. package/dist/lib/dry-run/samples.js +116 -0
  21. package/dist/lib/gh-output.d.ts +7 -0
  22. package/dist/lib/gh-output.js +50 -7
  23. package/dist/lib/http.d.ts +104 -0
  24. package/dist/lib/http.js +126 -7
  25. package/dist/lib/interrupt.d.ts +38 -13
  26. package/dist/lib/interrupt.js +130 -15
  27. package/dist/lib/local-target.d.ts +95 -0
  28. package/dist/lib/local-target.js +184 -0
  29. package/dist/lib/plan-poll.d.ts +171 -0
  30. package/dist/lib/plan-poll.js +442 -0
  31. package/dist/lib/plans.types.d.ts +130 -0
  32. package/dist/lib/plans.types.js +31 -0
  33. package/dist/lib/poll-support.d.ts +26 -0
  34. package/dist/lib/poll-support.js +65 -0
  35. package/dist/lib/poll.d.ts +1 -0
  36. package/dist/lib/poll.js +2 -40
  37. package/dist/lib/response-schemas.d.ts +13 -0
  38. package/dist/lib/response-schemas.js +46 -0
  39. package/dist/lib/run-progress.d.ts +41 -0
  40. package/dist/lib/run-progress.js +56 -0
  41. package/dist/lib/runs.types.d.ts +50 -0
  42. package/dist/lib/skill-nudge.d.ts +13 -5
  43. package/dist/lib/skill-nudge.js +40 -14
  44. package/dist/lib/target-url-preflight.js +3 -3
  45. package/dist/lib/target-url.d.ts +54 -8
  46. package/dist/lib/target-url.js +274 -68
  47. package/dist/lib/telemetry.d.ts +11 -0
  48. package/dist/lib/telemetry.js +1 -0
  49. package/dist/lib/ticker.d.ts +8 -0
  50. package/dist/lib/ticker.js +3 -0
  51. package/dist/lib/tunnel-session.d.ts +138 -0
  52. package/dist/lib/tunnel-session.js +249 -0
  53. package/dist/lib/tunnel.types.d.ts +54 -0
  54. package/dist/lib/tunnel.types.js +8 -0
  55. package/dist/vendor/tunnel-client/client.d.ts +82 -0
  56. package/dist/vendor/tunnel-client/client.js +924 -0
  57. package/dist/vendor/tunnel-client/config.d.ts +49 -0
  58. package/dist/vendor/tunnel-client/config.js +50 -0
  59. package/dist/vendor/tunnel-client/index.d.ts +9 -0
  60. package/dist/vendor/tunnel-client/index.js +9 -0
  61. package/dist/vendor/tunnel-client/lodash-lite.d.ts +14 -0
  62. package/dist/vendor/tunnel-client/lodash-lite.js +24 -0
  63. package/dist/vendor/tunnel-client/protocol.d.ts +60 -0
  64. package/dist/vendor/tunnel-client/protocol.js +143 -0
  65. package/dist/vendor/tunnel-client/types.d.ts +101 -0
  66. package/dist/vendor/tunnel-client/types.js +10 -0
  67. package/dist/vendor/tunnel-client/ws-compat.d.ts +206 -0
  68. package/dist/vendor/tunnel-client/ws-compat.js +316 -0
  69. package/dist/version.d.ts +1 -1
  70. package/dist/version.js +1 -1
  71. package/package.json +2 -1
  72. package/skills/testsprite-onboard.skill.md +60 -4
  73. package/skills/testsprite-verify.codex.md +22 -16
  74. 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';
5
- import { ApiError } from '../lib/errors.js';
4
+ import { type JUnitReportFormat, type JUnitTestResult } from '../lib/junit-report.js';
5
+ import { ApiError, InterruptError } 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 { RunResponse, TriggerRunResponse, RerunResponse, BatchRerunResponse, ListRunsResponse, RunSource, BatchRunFreshResponse, CancelRunResponse } from '../lib/runs.types.js';
9
+ import type { CliGetPlansResponse } from '../lib/plans.types.js';
10
+ import type { RunResponse, RunStatus, 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
@@ -55,6 +59,12 @@ export interface CliTest {
55
59
  * count after a `test plan put --expected-step-count` 412.
56
60
  */
57
61
  planStepCount?: number | null;
62
+ /**
63
+ * Full FE plan steps when the single-test read endpoint provides them.
64
+ * Optional/nullable for older backends and test types without plan steps;
65
+ * JSON output preserves the wire objects unchanged.
66
+ */
67
+ planSteps?: CliPlanStep[] | null;
58
68
  /**
59
69
  * M2.1: structured `processingStatus` / `testStatus` pair plus the
60
70
  * deprecated `rawStatus` mirror. Pre-M2.1 servers may still emit
@@ -69,6 +79,12 @@ export interface CliTest {
69
79
  * no priority has been set. Text mode surfaces it only when truthy.
70
80
  */
71
81
  priority?: string | null;
82
+ /**
83
+ * Per-test step timeout in milliseconds. The execution engine applies it
84
+ * to every step. Optional/nullable for older backends and tests that use
85
+ * the engine defaults; text mode surfaces it only when it is a number.
86
+ */
87
+ stepTimeoutMs?: number | null;
72
88
  /**
73
89
  * Backend-only dependency declarations that drive wave ordering.
74
90
  * Optional on the wire so older facades that don't ship them still
@@ -323,7 +339,45 @@ export interface TestDeps {
323
339
  * pattern as `sleep` / `fetchImpl`).
324
340
  */
325
341
  shutdown?: ShutdownHandle;
342
+ /**
343
+ * Tunnel-client factory for `test run --local` (DEV-747 piece 3). Defaults
344
+ * to the vendored `TunnelClient`; tests inject a fake so the command's
345
+ * contract can be exercised without a real control plane — same pattern as
346
+ * `sleep` / `fetchImpl` / `shutdown`.
347
+ */
348
+ createTunnelClient?: (options: TunnelClientOptions) => TunnelClientHandle;
349
+ }
350
+ /**
351
+ * How a `--local` run's wait ended while the run was still non-terminal.
352
+ * `tunnel-lost` is the one that is not a detach at all — it is the tunnel
353
+ * dying under a run that is otherwise fine.
354
+ */
355
+ export type TunnelDetachReason = 'interrupt' | 'timeout' | 'request-timeout' | 'rate-limited' | 'tunnel-lost' | 'poll-error';
356
+ /** What happened when we tried to stop a doomed tunnel run. */
357
+ export type TunnelCancelOutcome = 'cancelled' | 'already-terminal' | 'failed' | 'skipped';
358
+ export interface TunnelDetach {
359
+ runId: string;
360
+ testId: string;
361
+ localPort: number;
362
+ reason: TunnelDetachReason;
363
+ cancel: TunnelCancelOutcome;
364
+ terminalStatus?: RunStatus;
365
+ }
366
+ /** Tunnel-specific interrupt outcome consumed by the top-level JSON renderer. */
367
+ export interface TunnelInterruptDetach {
368
+ runId: string;
369
+ cancel: TunnelCancelOutcome;
370
+ nextAction: string;
326
371
  }
372
+ /**
373
+ * The stderr line for a tunnel run whose wait is ending.
374
+ *
375
+ * Deliberately NOT built from `stillRunningAndBillingSubject`: that sentence
376
+ * is true for an ordinary run and false here, and the whole point of D1 (a)
377
+ * is that the four detach paths stop telling a tunnel user something untrue.
378
+ */
379
+ export declare function tunnelDetachMessage(detach: TunnelDetach, interrupt?: InterruptError): string;
380
+ export declare function tunnelInterruptNextAction(detach: TunnelDetach, err: InterruptError): string;
327
381
  type CommonOptions = FactoryCommonOptions;
328
382
  interface ListOptions extends CommonOptions {
329
383
  projectId?: string;
@@ -380,6 +434,8 @@ interface CreateOptions extends CommonOptions {
380
434
  name: string;
381
435
  description?: string;
382
436
  priority?: CliCreatePriority;
437
+ /** Per-test timeout applied by the execution engine to every step. */
438
+ stepTimeoutMs?: number;
383
439
  /** Source path to the test code. Read into memory; capped at 350 KB. */
384
440
  codeFile: string;
385
441
  /** Caller-supplied idempotency token; UUIDv4 minted client-side if absent. */
@@ -509,6 +565,10 @@ interface UpdateOptions extends CommonOptions {
509
565
  description?: string;
510
566
  /** Optional new priority. Enum-validated CLI-side. */
511
567
  priority?: CliCreatePriority;
568
+ /** Set the per-test timeout applied by the execution engine to every step. */
569
+ stepTimeoutMs?: number;
570
+ /** Clear the per-test step timeout and restore execution engine defaults. */
571
+ clearStepTimeout?: boolean;
512
572
  /** Backend-only: variable names this test produces (repeatable --produces). */
513
573
  produces?: string[];
514
574
  /** Backend-only: variable names this test consumes (repeatable --needs); wire field `consumes`. */
@@ -685,7 +745,7 @@ export interface CliCreateFromPlanResponse extends CliCreateTestResponse {
685
745
  * Caveat: the pinned tag only resolves once that version is actually
686
746
  * released — a locally-built/pre-release checkout may see a 404 until then.
687
747
  */
688
- export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.7.0/schemas/plan.schema.json";
748
+ export declare const PLAN_SCHEMA_URL = "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.9.0/schemas/plan.schema.json";
689
749
  /**
690
750
  * The SINGLE canonical example plan. This
691
751
  * exact value (via `PLAN_TEMPLATE_TEXT` below) is:
@@ -1433,6 +1493,33 @@ interface RunTestRunOptions extends CommonOptions {
1433
1493
  * the `resolveAlternate` probe (an extra round-trip we deliberately avoid).
1434
1494
  */
1435
1495
  type?: 'frontend' | 'backend';
1496
+ /**
1497
+ * `--local <port>` — run against an app on THIS machine, reached through a
1498
+ * TestSprite tunnel. Implies `--wait` (the tunnel's lifetime is this
1499
+ * process's lifetime) and is mutually exclusive with `--target-url`.
1500
+ */
1501
+ localPort?: number;
1502
+ /**
1503
+ * `--local-host` — which loopback spelling to name in the run's target URL.
1504
+ * Already normalised and validated by the command wiring; the accepted set
1505
+ * is `lib/local-target.ts::LOOPBACK_HOSTS`, which mirrors the server's.
1506
+ */
1507
+ localHost?: LoopbackHost;
1508
+ /**
1509
+ * `--tunnel-client <id>` — attach to a tunnel someone else already started
1510
+ * (`testsprite tunnel start`) instead of minting one. The client id is a
1511
+ * non-secret handle; the secret never leaves the process that minted it,
1512
+ * and this run neither owns nor deletes that binding.
1513
+ */
1514
+ tunnelClientId?: string;
1515
+ /**
1516
+ * `--cancel-on-interrupt` / `--no-cancel-on-interrupt`. Default ON, and
1517
+ * scoped to tunnel runs only. A tunnel run whose tunnel is closing is
1518
+ * already doomed, so cancelling stops the billing instead of paying for a
1519
+ * guaranteed failure — which is exactly why this was correctly shelved for
1520
+ * ordinary runs, where detaching leaves a run that can still pass.
1521
+ */
1522
+ cancelOnInterrupt?: boolean;
1436
1523
  }
1437
1524
  interface RunTestWaitOptions extends CommonOptions {
1438
1525
  runId: string;
@@ -1504,6 +1591,22 @@ interface RunTestRerunOptions extends CommonOptions {
1504
1591
  /** --summary-file: also write the reduced machine summary JSON to this path. */
1505
1592
  summaryFile?: string;
1506
1593
  }
1594
+ /** Minimal client surface the backend-test wait fallback needs. */
1595
+ interface ResultReadClient {
1596
+ get<T>(path: string, options?: {
1597
+ signal?: AbortSignal;
1598
+ }): Promise<T>;
1599
+ }
1600
+ /**
1601
+ * Overlay a terminal testId-scoped {@link CliLatestResult} onto the polled
1602
+ * (non-terminal) {@link RunResponse} so a backend test whose run-surface row
1603
+ * never finalizes still renders a complete, correctly-correlated run envelope.
1604
+ * The real correlation metadata (`runId`, `testId`, `projectId`, `userId`,
1605
+ * `source`, `createdAt`, `createdFrom`) is preserved from the polled run row;
1606
+ * only the verdict/result fields are taken from the test record (codex
1607
+ * round-2: don't fabricate blank correlation fields).
1608
+ */
1609
+ export declare function backendResultToRunResponse(result: CliLatestResult, run: RunResponse, testTitle?: string | null): RunResponse;
1507
1610
  /**
1508
1611
  * Decide whether a testId-scoped result belongs to THIS run (vs a stale
1509
1612
  * verdict from a prior run of the same test). Backend serializes runs per
@@ -1514,6 +1617,26 @@ interface RunTestRerunOptions extends CommonOptions {
1514
1617
  * - result has no runId (legacy) → accept iff finishedAt >= notBefore.
1515
1618
  */
1516
1619
  export declare function backendResultIsForThisRun(result: CliLatestResult, runId: string, notBefore: string | undefined): boolean;
1620
+ /**
1621
+ * Build a `resolveAlternate` callback for `pollRunUntilTerminal` that falls
1622
+ * back to the testId-scoped verdict for **backend** tests (dogfood L1888).
1623
+ *
1624
+ * - The first non-terminal run tick does a one-time `GET /tests/{id}` to learn
1625
+ * the test type (cached). Frontend tests → no-op forever, so the FE path is
1626
+ * byte-identical to before.
1627
+ * - For backend tests, each later non-terminal tick reads
1628
+ * `GET /tests/{id}/result`; once that record is terminal AND belongs to this
1629
+ * run, a synthesized terminal `RunResponse` resolves the wait (exit 0/1)
1630
+ * instead of timing out (exit 7).
1631
+ * - Every lookup is best-effort: any error → "keep polling the run row", so
1632
+ * the fallback can never make either path worse than the prior timeout.
1633
+ */
1634
+ export declare function makeBackendWaitFallback(args: {
1635
+ client: ResultReadClient;
1636
+ resolveTestId: (run: RunResponse) => string;
1637
+ resolveNotBefore: (run: RunResponse) => string | undefined;
1638
+ onResolved?: (testId: string, status: CliPublicStatus) => void;
1639
+ }): (run: RunResponse, elapsedMs: number, signal: AbortSignal) => Promise<RunResponse | null>;
1517
1640
  /**
1518
1641
  * `test run <test-id>` — M3.3 piece-3.
1519
1642
  *
@@ -1632,7 +1755,24 @@ interface RunTestRunAllOptions extends CommonOptions {
1632
1755
  ghOutput?: boolean;
1633
1756
  /** --summary-file: also write the reduced machine summary JSON to this path. */
1634
1757
  summaryFile?: string;
1758
+ /**
1759
+ * --allow-empty: exit 0 (instead of failing) when the batch dispatches ZERO
1760
+ * tests (all skipped / empty project / --filter matched nothing). Default off:
1761
+ * a zero-dispatch `--all` is a CI false-green, so it fails with exit 5 by
1762
+ * default and still emits the summary / annotation / JUnit report (DEV-1046).
1763
+ */
1764
+ allowEmpty?: boolean;
1635
1765
  }
1766
+ export declare function writeBatchJUnitReportIfRequested(opts: {
1767
+ report?: JUnitReportFormat;
1768
+ reportFile?: string;
1769
+ reportSuiteName?: string;
1770
+ projectId?: string;
1771
+ }, results: readonly (JUnitTestResult & {
1772
+ startedAt?: string | null;
1773
+ finishedAt?: string | null;
1774
+ testTitle?: string | null;
1775
+ })[], nameByTestId?: ReadonlyMap<string, string>): Promise<void>;
1636
1776
  /**
1637
1777
  * `test run --all --project <id>` — M4 piece-2.
1638
1778
  *
@@ -1739,5 +1879,54 @@ export declare function resolveWaitRequestTimeoutMs(opts: {
1739
1879
  }): number | undefined;
1740
1880
  /** A presigned `code` body is any `https://` URL — never anything else. */
1741
1881
  export declare function isPresignedCodeUrl(code: string): boolean;
1882
+ interface PlanGenerateOptions extends CommonOptions {
1883
+ projectId?: string;
1884
+ timeoutSeconds: number;
1885
+ idempotencyKey?: string;
1886
+ }
1887
+ interface PlanAcceptOptions extends CommonOptions {
1888
+ projectId?: string;
1889
+ /** Raw `--only` tokens from Commander (variadic); undefined = flag absent. */
1890
+ only?: string[];
1891
+ idempotencyKey?: string;
1892
+ }
1893
+ /** Text card for a settled successful generate (or `--dry-run`). */
1894
+ /** Exported for the renderer-level spec: the zero-proposals branch is not
1895
+ * reachable through `runGenerationLadder` today (after the proposals rung it
1896
+ * polls until staged/failed/timeout), so it is pinned directly. */
1897
+ export declare function renderPlanGenerateResultText(plans: CliGetPlansResponse, projectId: string, creditsUsed: number | null, skippedCategories?: number | null): string;
1898
+ /**
1899
+ * `test plan generate --project <id>` — DEV-384 V3-B.
1900
+ *
1901
+ * Drives the server's generation ladder (exploration → strategy →
1902
+ * proposals) through `runGenerationLadder` and renders the staged
1903
+ * proposals. Exit 0 on staged proposals, 1 on a server-side stage failure,
1904
+ * 7 on timeout (typed `UNSUPPORTED` envelope — the raw ladder timeout is
1905
+ * not a CLI error), 130/143 on Ctrl-C detach (honest: work and charges
1906
+ * continue server-side), plus the usual catalog exits for trigger errors
1907
+ * (412 → 6 with the exact fix command, 402 → 12, 404 → 4, 429 → 11).
1908
+ */
1909
+ export declare function runPlanGenerate(opts: PlanGenerateOptions, deps?: TestDeps): Promise<unknown>;
1910
+ /** Derived, additive result the CLI prints for `accept` — the server truth
1911
+ * (`acceptedCount`, `caseKeys`) plus the client-side discard count. A
1912
+ * frontend/API split used to be derived from the selected proposals' `type`
1913
+ * fields; it was dropped (DEV-384 review F10) — the backend fills every
1914
+ * proposal's `type` from the PROJECT, so the split was always (all, 0) or
1915
+ * (0, all) and would be actively wrong for mixed projects. */
1916
+ interface PlanAcceptResult {
1917
+ projectId: string;
1918
+ acceptedCount: number;
1919
+ caseKeys: string[];
1920
+ discardedCount: number;
1921
+ }
1922
+ /**
1923
+ * `test plan accept --project <id> [--only <ids...>]` — DEV-384 V3-B.
1924
+ *
1925
+ * Reads the staged batch, selects all of it (or the `--only` subset),
1926
+ * and POSTs an EXPLICIT id list. Free — the generation charge already
1927
+ * covered it. Exit 0 on success, 5 on a bad `--only` selection (request
1928
+ * never sent), 6 when nothing is staged (pointer at `test plan generate`).
1929
+ */
1930
+ export declare function runPlanAccept(opts: PlanAcceptOptions, deps?: TestDeps): Promise<PlanAcceptResult | undefined>;
1742
1931
  export declare function createTestArtifactCommand(deps: TestDeps): Command;
1743
1932
  export {};