@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,10 +1,12 @@
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
5
  import { ApiError } from '../lib/errors.js';
5
6
  import type { FetchImpl } from '../lib/http.js';
6
7
  import { type Page } from '../lib/pagination.js';
7
8
  import type { RunResponse, TriggerRunResponse, RerunResponse, BatchRerunResponse, ListRunsResponse, RunSource, BatchRunFreshResponse } from '../lib/runs.types.js';
9
+ import { type FlakyReport } from '../lib/flaky.js';
8
10
  /**
9
11
  * `details` debug block per the CLI OpenAPI `Test` schema
10
12
  * (M2.1 amendment). `processingStatus` / `testStatus` are the
@@ -102,6 +104,19 @@ export interface CliTestStep {
102
104
  * that don't emit the field still type-check.
103
105
  */
104
106
  outcomeContributesToFailure?: boolean | null;
107
+ /**
108
+ * Per-step failure text, carried from `RunStepDto.error` on the run-scoped
109
+ * endpoint (`GET /runs/{id}?includeSteps=true`). Only present on `--run-id`
110
+ * responses; the cumulative `/tests/{id}/steps` rows do not carry it, so the
111
+ * field stays optional (additive, non-breaking for existing consumers).
112
+ */
113
+ error?: string | null;
114
+ /**
115
+ * Wire step kind from `RunStepDto.type` on the run-scoped endpoint. Same
116
+ * availability rules as `error`. Named `stepType` to avoid colliding with
117
+ * the free-form `action` label above.
118
+ */
119
+ stepType?: 'action' | 'assertion';
105
120
  }
106
121
  /**
107
122
  * §6.5 failureKind enum (M2.1 piece 4 widened from six to nine values).
@@ -110,11 +125,10 @@ export interface CliTestStep {
110
125
  * — agents must not switch on raw strings outside the enumerated set.
111
126
  */
112
127
  export type CliFailureKind = 'assertion' | 'assertion_blocked' | 'routing_404' | 'network_timeout' | 'network' | 'timeout' | 'browser_crash' | 'infra' | 'unknown' | null;
113
- export interface CliResultSummary {
114
- passed: number;
115
- failed: number;
116
- skipped: number;
117
- }
128
+ /** test VERDICT (the outcome of a completed run). */
129
+ export type CliVerdict = 'passed' | 'failed' | 'blocked';
130
+ /** execution LIFECYCLE (where the test is in its run lifecycle). */
131
+ export type CliExecutionStatus = 'draft' | 'ready' | 'queued' | 'running' | 'completed' | 'cancelled' | 'unknown';
118
132
  /** §6.5 LatestResult wire shape. All correlation fields are required. */
119
133
  export interface CliLatestResult {
120
134
  testId: string;
@@ -146,7 +160,20 @@ export interface CliLatestResult {
146
160
  targetUrlSource?: 'run' | 'project-default' | 'unresolved' | null;
147
161
  failedStepIndex: number | null;
148
162
  failureKind: CliFailureKind;
149
- summary: CliResultSummary;
163
+ /**
164
+ * the test VERDICT only (`passed | failed | blocked`), or `null`
165
+ * when the latest run produced no verdict yet (never run / queued / running /
166
+ * cancelled). Lifecycle lives in `executionStatus`; `status` above is the
167
+ * legacy conflated field, retained for back-compat.
168
+ */
169
+ verdict: CliVerdict | null;
170
+ /** the execution LIFECYCLE (terminal runs collapse to `completed`). */
171
+ executionStatus: CliExecutionStatus;
172
+ /**
173
+ * a human/agent-readable description of the latest run (replaces the
174
+ * former `{passed,failed,skipped}` count object).
175
+ */
176
+ summary: string;
150
177
  /**
151
178
  * §6.5.1 (M2.1 piece 3) — inline failure analysis. Present when the
152
179
  * caller passed `--include-analysis` (`?includeAnalysis=true` on
@@ -288,6 +315,12 @@ export interface CliCreateTestResponse {
288
315
  type: 'frontend' | 'backend';
289
316
  codeVersion: string;
290
317
  createdAt: string;
318
+ /**
319
+ * Non-fatal advisories from the backend (e.g. the BE auth guardrail
320
+ * flagging a hardcoded credential). Rendered on stderr; the create
321
+ * still succeeded.
322
+ */
323
+ warnings?: string[];
291
324
  }
292
325
  export declare const CLI_CREATE_PRIORITIES: readonly ["p0", "p1", "p2", "p3"];
293
326
  export type CliCreatePriority = (typeof CLI_CREATE_PRIORITIES)[number];
@@ -815,11 +848,14 @@ interface CodeGetOptions extends CommonOptions {
815
848
  * directly; presigned URLs are dereferenced via the same fetch impl
816
849
  * (without API-key headers — the URL is the bearer of authority).
817
850
  *
818
- * `--out <path>` redirects the same bytes into a file. We open the file
819
- * before issuing the network request so a permission/dir error fails
820
- * fast (exit 5 / VALIDATION_ERROR) without spending an API call. On
821
- * any error after open we tear down the sink so we don't leak a
822
- * half-written artifact.
851
+ * `--out <path>` redirects the same bytes into a file. We validate the
852
+ * path and open a sibling temp file before issuing the network request
853
+ * so a permission/dir error fails fast (exit 5 / VALIDATION_ERROR)
854
+ * without spending an API call. The temp file is renamed onto the real
855
+ * `--out` path only after a successful, complete write; on any error
856
+ * (or the "no code generated yet" branch, which writes nothing) the
857
+ * temp file is discarded and the user's pre-existing `--out` file, if
858
+ * any, is left untouched.
823
859
  */
824
860
  export declare function runCodeGet(opts: CodeGetOptions, deps?: TestDeps): Promise<CliTestCode>;
825
861
  /**
@@ -832,6 +868,12 @@ export interface CliPutTestCodeResponse {
832
868
  testId: string;
833
869
  codeVersion: string;
834
870
  updatedAt: string;
871
+ /**
872
+ * Non-fatal advisories (e.g. the BE auth guardrail flagging a hardcoded
873
+ * credential in the replaced code). Rendered on stderr; the update still
874
+ * succeeded.
875
+ */
876
+ warnings?: string[];
835
877
  }
836
878
  type CodePutLanguage = CliTestCode['language'];
837
879
  interface CodePutOptions extends CommonOptions {
@@ -919,6 +961,102 @@ interface StepsOptions extends CommonOptions {
919
961
  */
920
962
  runId?: string;
921
963
  }
964
+ export interface DiffOptions extends CommonOptions {
965
+ runA: string;
966
+ runB: string;
967
+ }
968
+ /** One step whose status flipped between the two compared runs. */
969
+ export interface CliDiffStep {
970
+ stepIndex: number;
971
+ statusA: string;
972
+ statusB: string;
973
+ /** First divergent failing side's error text, when the wire carried one. */
974
+ errorA?: string | null;
975
+ errorB?: string | null;
976
+ }
977
+ export interface CliRunDiff {
978
+ runA: {
979
+ runId: string;
980
+ testId: string;
981
+ status: string;
982
+ failureKind: string | null;
983
+ failedStepIndex: number | null;
984
+ codeVersion: string | null;
985
+ };
986
+ runB: {
987
+ runId: string;
988
+ testId: string;
989
+ status: string;
990
+ failureKind: string | null;
991
+ failedStepIndex: number | null;
992
+ codeVersion: string | null;
993
+ };
994
+ verdictChanged: boolean;
995
+ failedStepIndexChanged: boolean;
996
+ failureKindChanged: boolean;
997
+ codeVersionChanged: boolean;
998
+ /** True when the two runs belong to DIFFERENT tests (deltas may be meaningless). */
999
+ crossTest: boolean;
1000
+ changedSteps: CliDiffStep[];
1001
+ }
1002
+ /**
1003
+ * `test diff <runA> <runB>` (issue #124): isolate what regressed between two
1004
+ * runs, the first question when CI goes red ("what changed since the last
1005
+ * green run?"). Pure client-side composition of the existing per-run read
1006
+ * (`GET /runs/{id}?includeSteps=true`); the endpoint accepts any two run-ids,
1007
+ * so a cross-test pair is a WARNING, not an error. Exit 0 when the verdicts
1008
+ * match, exit 1 when they differ, so the command is CI-scriptable.
1009
+ */
1010
+ export declare function runDiff(opts: DiffOptions, deps?: TestDeps): Promise<CliRunDiff>;
1011
+ export interface LintOptions extends CommonOptions {
1012
+ planFrom?: string;
1013
+ planFromDir?: string;
1014
+ plans?: string;
1015
+ steps?: string;
1016
+ }
1017
+ export interface CliLintIssue {
1018
+ file: string;
1019
+ field: string;
1020
+ reason: string;
1021
+ }
1022
+ export interface CliLintReport {
1023
+ checked: number;
1024
+ valid: number;
1025
+ issues: CliLintIssue[];
1026
+ }
1027
+ /**
1028
+ * `test lint` (issue #98): validate plan/steps files fully OFFLINE with the
1029
+ * SAME validators the create paths run, but collecting EVERY problem instead
1030
+ * of dying on the first one, and without any network write. The create-batch
1031
+ * reader is first-error-fatal and only reachable through a command that POSTs,
1032
+ * so authoring a 12-plan directory meant one error per paid round-trip. Zero
1033
+ * network, zero credentials: exit 0 when everything is valid, 5 otherwise, so
1034
+ * it drops into a pre-commit hook or CI step before `create-batch`.
1035
+ */
1036
+ export declare function runLint(opts: LintOptions, deps?: TestDeps): Promise<CliLintReport>;
1037
+ export interface ScaffoldOptions extends CommonOptions {
1038
+ scaffoldType: 'frontend' | 'backend';
1039
+ out?: string;
1040
+ force: boolean;
1041
+ }
1042
+ /** JSON payload `test scaffold --type backend` prints under --output json. */
1043
+ export interface CliBackendScaffold {
1044
+ type: 'backend';
1045
+ language: 'python';
1046
+ code: string;
1047
+ }
1048
+ /**
1049
+ * `test scaffold` — emit a schema-correct starter test definition so a first
1050
+ * test never starts from hand-copied JSON. Pure-local: no network, no
1051
+ * credentials, no filesystem reads. The frontend template is a `CliPlanInput`
1052
+ * (the exact shape `--plan-from` ingests; sourceRef: CliPlanInput /
1053
+ * PLAN_STEP_TYPES above), so `scaffold | create --plan-from -`-style flows
1054
+ * validate out of the box. The backend template is the minimal `requests`
1055
+ * script the onboarding skill mandates: define a test function with a
1056
+ * concrete status assertion, then CALL it (a defined-but-never-called test
1057
+ * would pass without asserting anything).
1058
+ */
1059
+ export declare function runScaffold(opts: ScaffoldOptions, deps?: TestDeps): Promise<CliPlanInput | CliBackendScaffold>;
922
1060
  export declare function runSteps(opts: StepsOptions, deps?: TestDeps): Promise<Page<CliTestStep>>;
923
1061
  interface ResultOptions extends CommonOptions {
924
1062
  testId: string;
@@ -1119,6 +1257,12 @@ interface RunTestRerunOptions extends CommonOptions {
1119
1257
  * filters. Client-side only.
1120
1258
  */
1121
1259
  nameFilter?: string;
1260
+ /** --report junit: write a JUnit XML sidecar after batch --wait completes. */
1261
+ report?: JUnitReportFormat;
1262
+ /** --report-file: destination path for the JUnit XML artifact. */
1263
+ reportFile?: string;
1264
+ /** --report-suite-name: optional override for the JUnit <testsuite name=...>. */
1265
+ reportSuiteName?: string;
1122
1266
  }
1123
1267
  /**
1124
1268
  * Decide whether a testId-scoped result belongs to THIS run (vs a stale
@@ -1139,6 +1283,35 @@ export declare function backendResultIsForThisRun(result: CliLatestResult, runId
1139
1283
  * 7 on timeout.
1140
1284
  */
1141
1285
  export declare function runTestRun(opts: RunTestRunOptions, deps?: TestDeps): Promise<TriggerRunResponse | RunResponse>;
1286
+ /** One row of the `test wait <run-id...>` multi-run payload. */
1287
+ export interface CliMultiWaitResult {
1288
+ runId: string;
1289
+ /** Terminal run status, or 'timeout', or 'error:<CODE>' when the poll failed. */
1290
+ status: string;
1291
+ /** Test the run belongs to, when the poll observed it. */
1292
+ testId?: string;
1293
+ }
1294
+ export interface RunTestWaitManyOptions extends CommonOptions {
1295
+ runIds: string[];
1296
+ timeoutSeconds: number;
1297
+ maxConcurrency: number;
1298
+ }
1299
+ /**
1300
+ * `test wait <run-id...>` with two or more ids: attach to N already-dispatched
1301
+ * runs in ONE invocation. This closes the loop the CLI itself opens: every
1302
+ * batch/closure timeout prints one `testsprite test wait <runId>` hint PER
1303
+ * member, which previously meant N sequential blocking invocations. The runs
1304
+ * are polled concurrently under a bounded pool with ONE shared deadline
1305
+ * (`--timeout` bounds the whole invocation, not each member), each member's
1306
+ * poll is total (a transient error on one run never discards the others), and
1307
+ * the exit code is the worst status across members: auth errors escalate to
1308
+ * exit 3, any timeout or poll error exits 7, any non-passed terminal exits 1.
1309
+ * Distinct from a run journal (issue #80): no persistence, just N known ids.
1310
+ */
1311
+ export declare function runTestWaitMany(opts: RunTestWaitManyOptions, deps?: TestDeps): Promise<{
1312
+ results: CliMultiWaitResult[];
1313
+ summary: Record<string, number>;
1314
+ }>;
1142
1315
  /**
1143
1316
  * `test wait <run-id>` — M3.3 piece-3.
1144
1317
  *
@@ -1147,7 +1320,7 @@ export declare function runTestRun(opts: RunTestRunOptions, deps?: TestDeps): Pr
1147
1320
  */
1148
1321
  export declare function runTestWait(opts: RunTestWaitOptions, deps?: TestDeps): Promise<RunResponse>;
1149
1322
  interface RunTestRunAllOptions extends CommonOptions {
1150
- /** projectId to run all BE tests in. */
1323
+ /** projectId to run all tests in. */
1151
1324
  projectId: string;
1152
1325
  /** --filter <substr>: only run tests whose name contains this substring (case-insensitive). */
1153
1326
  nameFilter?: string;
@@ -1159,6 +1332,12 @@ interface RunTestRunAllOptions extends CommonOptions {
1159
1332
  maxConcurrency: number;
1160
1333
  /** Caller-supplied idempotency token; auto-minted if absent. */
1161
1334
  idempotencyKey?: string;
1335
+ /** --report junit: write a JUnit XML sidecar after batch --wait completes. */
1336
+ report?: JUnitReportFormat;
1337
+ /** --report-file: destination path for the JUnit XML artifact. */
1338
+ reportFile?: string;
1339
+ /** --report-suite-name: optional override for the JUnit <testsuite name=...>. */
1340
+ reportSuiteName?: string;
1162
1341
  }
1163
1342
  /**
1164
1343
  * `test run --all --project <id>` — M4 piece-2.
@@ -1200,6 +1379,7 @@ export interface ArtifactGetResult {
1200
1379
  /** Set when bundle was written to disk. */
1201
1380
  bundle?: WriteBundleResult;
1202
1381
  }
1382
+ export declare function resolveDefaultArtifactDir(runId: string, cwd?: string): string;
1203
1383
  /**
1204
1384
  * Validate that the parent directory of `resolvedDir` exists and is a
1205
1385
  * directory. Surfaces `VALIDATION_ERROR` (exit 5) — matches the convention
@@ -1223,6 +1403,28 @@ export declare function assertOutDirParentExists(resolvedDir: string): Promise<v
1223
1403
  */
1224
1404
  export declare function runArtifactGet(opts: ArtifactGetOptions, deps?: TestDeps): Promise<ArtifactGetResult>;
1225
1405
  export declare function createTestCommand(deps?: TestDeps): Command;
1406
+ interface RunTestFlakyOptions extends CommonOptions {
1407
+ testId: string;
1408
+ /** Number of replays to run (1..MAX_FLAKY_RUNS). */
1409
+ runs: number;
1410
+ /** Stop at the first non-passing attempt. */
1411
+ untilFail: boolean;
1412
+ /** Per-attempt polling deadline in seconds. */
1413
+ timeoutSeconds: number;
1414
+ }
1415
+ /**
1416
+ * `test flaky <test-id>` — replay a test N times and report a stability score.
1417
+ *
1418
+ * Each attempt is a `POST /tests/{id}/runs/rerun` with auto-heal OFF (a strict
1419
+ * verbatim replay) followed by `pollRunUntilTerminal`. Frontend replays are
1420
+ * free verbatim script replays; backend replays re-run the dependency closure
1421
+ * (a one-line credit advisory is printed). The pure scoring lives in
1422
+ * `lib/flaky.ts`; this function is the I/O orchestrator.
1423
+ *
1424
+ * Exit code: 0 when every observed attempt passed (stable), else 1 — so CI can
1425
+ * gate a merge on flakiness.
1426
+ */
1427
+ export declare function runFlaky(opts: RunTestFlakyOptions, deps?: TestDeps): Promise<FlakyReport | undefined>;
1226
1428
  /**
1227
1429
  * D4 (dogfood CoderCup 2026-06-05): under `--wait` the user opts into a
1228
1430
  * long-running operation bounded by `--timeout`. The default 120s per-request