@testsprite/testsprite-cli 0.9.0 → 0.11.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 (43) hide show
  1. package/README.md +64 -41
  2. package/dist/commands/auth.d.ts +5 -1
  3. package/dist/commands/auth.js +17 -5
  4. package/dist/commands/init.d.ts +6 -1
  5. package/dist/commands/init.js +13 -5
  6. package/dist/commands/project.d.ts +30 -0
  7. package/dist/commands/project.js +193 -27
  8. package/dist/commands/test.d.ts +14 -2
  9. package/dist/commands/test.js +141 -33
  10. package/dist/commands/tunnel.d.ts +2 -2
  11. package/dist/commands/tunnel.js +139 -31
  12. package/dist/index.js +29 -11
  13. package/dist/lib/client-factory.d.ts +4 -1
  14. package/dist/lib/client-factory.js +12 -4
  15. package/dist/lib/credentials.d.ts +4 -0
  16. package/dist/lib/credentials.js +43 -4
  17. package/dist/lib/dry-run/samples.js +16 -9
  18. package/dist/lib/http.d.ts +14 -2
  19. package/dist/lib/http.js +38 -6
  20. package/dist/lib/response-schemas.d.ts +5 -2
  21. package/dist/lib/response-schemas.js +21 -1
  22. package/dist/lib/runs.types.d.ts +11 -0
  23. package/dist/lib/target-url.d.ts +1 -1
  24. package/dist/lib/target-url.js +4 -0
  25. package/dist/lib/telemetry.d.ts +6 -2
  26. package/dist/lib/telemetry.js +12 -0
  27. package/dist/lib/tunnel-session.d.ts +13 -2
  28. package/dist/lib/tunnel-session.js +92 -23
  29. package/dist/lib/tunnel.types.d.ts +3 -1
  30. package/dist/vendor/tunnel-client/client.d.ts +11 -0
  31. package/dist/vendor/tunnel-client/client.js +383 -56
  32. package/dist/vendor/tunnel-client/config.d.ts +11 -3
  33. package/dist/vendor/tunnel-client/config.js +11 -3
  34. package/dist/vendor/tunnel-client/types.d.ts +26 -1
  35. package/dist/vendor/tunnel-client/types.js +1 -0
  36. package/dist/vendor/tunnel-client/ws-compat.d.ts +3 -2
  37. package/dist/vendor/tunnel-client/ws-compat.js +3 -2
  38. package/dist/version.d.ts +1 -1
  39. package/dist/version.js +1 -1
  40. package/package.json +2 -1
  41. package/skills/testsprite-onboard.skill.md +80 -59
  42. package/skills/testsprite-verify.codex.md +82 -97
  43. package/skills/testsprite-verify.skill.md +67 -16
@@ -7,9 +7,9 @@
7
7
  * - the endpoints are internal infrastructure names, and a default value is
8
8
  * still a value that ships;
9
9
  * - a default endpoint is the failure mode the facade exists to prevent.
10
- * `POST /api/cli/v1/tunnel` returns `controlUrl` and `tunnelAddr` for the
11
- * environment the caller authenticated against, and those are the ONLY
12
- * endpoints this client may dial. A default would let a
10
+ * `POST /api/cli/v1/tunnel` returns `controlUrl`, `tunnelAddr`, and
11
+ * optionally `tunnelTlsAddr` for the environment the caller authenticated
12
+ * against, and those are the ONLY endpoints this client may dial. A default would let a
13
13
  * misconfigured/partially-constructed client silently connect somewhere
14
14
  * else and fail in a way that reads like an auth problem.
15
15
  *
@@ -28,6 +28,14 @@ export const DEFAULT_HEARTBEAT_MS = 10_000;
28
28
  * accepted the transport but never authenticated it.
29
29
  */
30
30
  export const DEFAULT_AUTH_TIMEOUT_MS = 10_000;
31
+ /** Maximum time allowed for each plaintext TCP connect. */
32
+ export const DEFAULT_CONNECT_TIMEOUT_MS = 10_000;
33
+ /** Maximum time allowed for each TLS connect + handshake. */
34
+ export const DEFAULT_TLS_HANDSHAKE_TIMEOUT_MS = 10_000;
35
+ /** Retry window after the first failed data-plane dial. Zero retries forever. */
36
+ export const DEFAULT_DATA_PLANE_RETRY_DEADLINE_MS = 60_000;
37
+ /** Post-hello interval after which an otherwise-idle data-plane session is established. */
38
+ export const DEFAULT_DATA_PLANE_SETTLE_MS = 5_000;
31
39
  /** Delay between control/tunnel reconnect attempts. Upstream default. */
32
40
  export const DEFAULT_RECONNECT_MS = 3_000;
33
41
  /** Log verbosity floor. Upstream default. */
@@ -5,7 +5,8 @@ export declare enum ErrCode {
5
5
  TunnelDisconnected = "0003",
6
6
  TargetConnectFailed = "0004",
7
7
  StreamFailed = "0005",
8
- BlockedTargetRejected = "0006"
8
+ BlockedTargetRejected = "0006",
9
+ DataPlaneUnreachable = "0007"
9
10
  }
10
11
  export interface TunnelClientError {
11
12
  code: ErrCode;
@@ -22,6 +23,30 @@ export interface TunnelClientOptions {
22
23
  controlUrl: string;
23
24
  /** VENDOR DELTA: required. `host:port` of the tunnel DATA plane. */
24
25
  tunnelAddr: string;
26
+ /**
27
+ * TLS `host:port` (or `[v6]:port`) for the tunnel DATA plane. When set,
28
+ * transport is fixed to TLS and `tunnelAddr` is never dialled as fallback.
29
+ */
30
+ tunnelTlsAddr?: string;
31
+ /** TLS SNI/verification name. Defaults to the hostname in `tunnelTlsAddr`. */
32
+ tunnelTlsServername?: string;
33
+ /** Extra PEM roots appended to Node's built-in root certificate set. */
34
+ tunnelTlsCa?: string | Buffer | Array<string | Buffer>;
35
+ /** Maximum time to complete each plaintext TCP connect. Defaults to 10 seconds. */
36
+ connectTimeoutMs?: number;
37
+ /** Maximum time to complete each TLS connect + handshake. Defaults to 10 seconds. */
38
+ tlsHandshakeTimeoutMs?: number;
39
+ /**
40
+ * Maximum retry window after the first failed data-plane attempt. The first
41
+ * inbound yamux stream or the settle interval ends it. Defaults to 60
42
+ * seconds; `0` retries forever.
43
+ */
44
+ dataPlaneRetryDeadlineMs?: number;
45
+ /**
46
+ * Time a post-TunnelHello socket must remain open before the session counts
47
+ * as established without an inbound yamux stream. Defaults to 5 seconds.
48
+ */
49
+ dataPlaneSettleMs?: number;
25
50
  /**
26
51
  * VENDOR DELTA: maximum time `start()` waits for the current control
27
52
  * connection's first Ack, which is the server's authentication acknowledgement.
@@ -6,5 +6,6 @@ export var ErrCode;
6
6
  ErrCode["TargetConnectFailed"] = "0004";
7
7
  ErrCode["StreamFailed"] = "0005";
8
8
  ErrCode["BlockedTargetRejected"] = "0006";
9
+ ErrCode["DataPlaneUnreachable"] = "0007";
9
10
  })(ErrCode || (ErrCode = {}));
10
11
  //# sourceMappingURL=types.js.map
@@ -21,8 +21,9 @@
21
21
  * - **The control socket uses the process-global undici dispatcher**, so an
22
22
  * `HTTP(S)_PROXY` this CLI honours (`lib/proxy.ts`) also carries the
23
23
  * control WebSocket. Deliberate — but note it does NOT help the tunnel
24
- * DATA plane, which is a raw `net.connect` and bypasses proxies entirely.
25
- * `lib/tunnel-session.ts` warns about that asymmetry rather than
24
+ * DATA plane, which uses a direct TLS socket for advertised TLS endpoints
25
+ * and raw TCP only for the explicit legacy transport. Both bypass HTTP
26
+ * proxies. `lib/tunnel-session.ts` warns about that asymmetry rather than
26
27
  * pretending a proxied environment is supported.
27
28
  *
28
29
  * ## Why `close()` cannot just call `WebSocket.close()` and wait
@@ -21,8 +21,9 @@
21
21
  * - **The control socket uses the process-global undici dispatcher**, so an
22
22
  * `HTTP(S)_PROXY` this CLI honours (`lib/proxy.ts`) also carries the
23
23
  * control WebSocket. Deliberate — but note it does NOT help the tunnel
24
- * DATA plane, which is a raw `net.connect` and bypasses proxies entirely.
25
- * `lib/tunnel-session.ts` warns about that asymmetry rather than
24
+ * DATA plane, which uses a direct TLS socket for advertised TLS endpoints
25
+ * and raw TCP only for the explicit legacy transport. Both bypass HTTP
26
+ * proxies. `lib/tunnel-session.ts` warns about that asymmetry rather than
26
27
  * pretending a proxied environment is supported.
27
28
  *
28
29
  * ## Why `close()` cannot just call `WebSocket.close()` and wait
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.9.0";
1
+ export declare const VERSION = "0.11.0";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // AUTO-GENERATED by scripts/generate-version.mjs — do not edit by hand.
2
2
  // Run `npm run build` (or `npm run generate:version`) to regenerate.
3
- export const VERSION = '0.9.0';
3
+ export const VERSION = '0.11.0';
4
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testsprite/testsprite-cli",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Official TestSprite command-line interface",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -75,6 +75,7 @@
75
75
  "globals": "^17.7.0",
76
76
  "msw": "^2.14.3",
77
77
  "prettier": "^3.3.3",
78
+ "selfsigned": "^5.5.0",
78
79
  "typescript": "^5.6.3",
79
80
  "typescript-eslint": "^8.13.0",
80
81
  "vitest": "^2.1.4"
@@ -7,16 +7,12 @@
7
7
 
8
8
  # TestSprite: onboard a repo with a seed test suite
9
9
 
10
- Your job is to take a repo that has **no TestSprite tests yet** and leave it with a
11
- **coherent, runnable suite** plus a couple of **already-green** smoke tests — in one pass.
12
- A new user who can immediately run a real, passing test is an activated user; an empty
13
- project is the #1 drop-off.
10
+ Seed a repo with no tests into a coherent suite and 2–3 passing smoke tests.
14
11
 
15
12
  This skill only uses shipped CLI commands. Do **not** call backend APIs directly.
16
13
 
17
- Step 3 offers two paths to a suite, tried in order: let TestSprite **generate** the tests
18
- (fastest; needs a V3-platform account and a recent CLI), or **author** them by hand
19
- (always works). Everything else here is identical either way.
14
+ For deployed targets, try generation first (V3 required), then author by hand.
15
+ Local projects use authored plans directly; exploration is unavailable.
20
16
 
21
17
  ## When to use
22
18
 
@@ -32,29 +28,46 @@ Step 3 offers two paths to a suite, tried in order: let TestSprite **generate**
32
28
 
33
29
  `testsprite setup` has run (an API key is configured). If `testsprite project list` errors on
34
30
  auth, stop and tell the user to run `testsprite setup` first — don't try to configure for them.
31
+ In a sandbox, `testsprite setup --from-env` can use `TESTSPRITE_API_KEY` even when HOME
32
+ is read-only: credential-write permission failures warn and continue session-only.
33
+ The JSON summary has `credentials.persisted: false`; export the key in every invoking
34
+ shell. Agent installation still needs a writable target; `--no-agent` skips it.
35
35
 
36
36
  ## Steps
37
37
 
38
- ### 1. Understand the app (don't skip — this is where coverage quality comes from)
38
+ ### 1. Understand the app
39
39
 
40
- Read the repo to establish, concretely:
40
+ Read the source to identify:
41
41
 
42
42
  - **Frontend**: the deployed/local **URL**, the 4–8 most important user flows (auth, core
43
43
  CRUD, checkout, search, settings…), and whether flows need **login**.
44
44
  - **Backend**: the key **API endpoints** and their success/error contracts.
45
45
 
46
- Prefer **code-derived** routes/handlers over guessing — you have the source; use it. This
47
- beats a blind crawl.
46
+ Use code-derived routes/handlers; do not guess.
48
47
 
49
- ### 2. Create the project (FE must have a URL)
48
+ ### 2. Create the project
50
49
 
51
- Frontend:
50
+ Deployed frontend:
52
51
 
53
52
  ```bash
54
53
  testsprite project create --type frontend --name "<repo name>" --url <app-url> \
55
54
  [--username <user> --password-file <path-to-secret>]
56
55
  ```
57
56
 
57
+ Local frontend (start the app first; V3 required):
58
+
59
+ ```bash
60
+ testsprite project create --type frontend --name "<repo name>" --local <port> --local-host <host>
61
+ ```
62
+
63
+ `--local` stores `http://<host>:<port>`; `--local-host` sets both probe and URL host:
64
+ `localhost`, `127.0.0.1` (default), or `::1` (`http://[::1]:<port>`).
65
+ Reuse the host on runs; omit for default IPv4.
66
+ `project get/list`: JSON `originMode: 'local'`, text `(Local)`.
67
+ No `--url`. Dead port: exit 5 (`--skip-preflight` bypasses).
68
+ V2-only: exit 7 (`local-origin-requires-v3`). Local runs work on Free and need
69
+ `run:tunnel` (mint a new key if missing).
70
+
58
71
  Backend:
59
72
 
60
73
  ```bash
@@ -63,23 +76,37 @@ testsprite project create --type backend --name "<repo name>"
63
76
 
64
77
  Capture the returned `projectId`.
65
78
 
66
- > **Critical for FE**: a frontend test with no resolvable target URL fails immediately with
67
- > `No environment URL configured` — the suite goes all-red. Always pass `--url`. If flows need
68
- > login, pass `--username/--password-file` now so authenticated pages are reachable.
79
+ For frontend, configure login with
80
+ `--username/--password-file` if needed; the cloud agent logs in through the tunnel
81
+ using the project environment's username/password. OTP environments are refused
82
+ before charge (exit 6).
83
+
84
+ #### 2b. FE: register the app's test-hook attribute
85
+
86
+ If the source tags elements with something other than `data-testid` (e.g. `data-element`),
87
+ run `testsprite project update <projectId> --test-id-attributes data-element,data-testid`
88
+ once; exported locators then use the tag (check: `project get` → `testIdAttrs:`).
89
+
90
+ ### 3. Get the tests
91
+
92
+ **Local project: go directly to 3b.** Creation does no exploration/generation;
93
+ `test plan generate` is refused before charge (exit 6). Author a plan, then use:
94
+
95
+ ```bash
96
+ testsprite test create --plan-from plan.json --project <projectId>
97
+ testsprite test run <testId> --local <port> --local-host <host>
98
+ ```
69
99
 
70
- ### 3. Get the tests — try generation first, author by hand if it isn't available
100
+ Portal runs are blocked for free until `project update <id> --url https://…` sets
101
+ a public URL. For deployed projects, try 3a first.
71
102
 
72
103
  #### 3a. Preferred: generate → review → accept
73
104
 
74
- TestSprite proposes the cases; proposals stage **on the server** (nothing lands in the
75
- repo) and you accept the ones worth keeping.
105
+ Proposals stage on the server for review; no files are written locally.
76
106
 
77
- **API projects need an API spec first** — with none, generation stops at
78
- `no_processed_inputs`. Upload the spec (the file is only read). A PRD is optional and goes
79
- **alongside** the spec, not instead of it: endpoints are read from the spec, and the PRD
80
- shapes the feature map (`--role prd`, 0.5 credits). A PRD alone can charge the strategy
81
- stage and then fail with no endpoints found. Frontend projects skip this, since exploring
82
- the live app creates their inputs.
107
+ API projects require an API spec (`no_processed_inputs` without one). An optional
108
+ PRD supplements it (`--role prd`, 0.5 credits); a PRD alone can charge strategy and
109
+ then fail for missing endpoints. Deployed frontend exploration supplies its inputs.
83
110
 
84
111
  ```bash
85
112
  testsprite project docs upload ./openapi.yaml --project <projectId> --role api-doc
@@ -90,14 +117,11 @@ testsprite project docs upload ./prd.md --project <projectId> --role prd # opt
90
117
  testsprite test plan generate --project <projectId>
91
118
  ```
92
119
 
93
- It runs only the stages the project is missing and prints proposals with stable ids. A
94
- fresh frontend project takes minutes (browser agents visit the app) — that's normal;
95
- Ctrl-C only detaches, the work continues. If it says inputs are still processing, wait
96
- and re-run.
120
+ Only missing stages run. Frontend exploration can take minutes; Ctrl-C detaches
121
+ while generation continues. If inputs are still processing, wait and re-run.
97
122
 
98
- **Review the table before accepting — that's the quality gate, and it's your job.** Check
99
- titles and steps against what you learned in step 1; drop anything testing a flow the repo
100
- doesn't have, duplicating another, or asserting something vague.
123
+ Review titles and steps against the source. Drop nonexistent flows, duplicates,
124
+ and vague assertions before accepting.
101
125
 
102
126
  ```bash
103
127
  testsprite test plan accept --project <projectId> # all of them
@@ -108,12 +132,11 @@ A subset accept **discards the rest**, so name every proposal you want in that o
108
132
  Then `testsprite test list --project <projectId>` for the ids, and go to step 5
109
133
  (**skip step 4** — that's the hand-authoring path).
110
134
 
111
- **If generation isn't available, fall back to 3b — don't stall.** That means an unknown
112
- `test plan generate` command (older CLI), an account not on the V3 platform (exit 6), or
113
- no reachable URL and no source to read. Say which happened, then author the tests
114
- yourself; don't ask the user to upgrade or migrate first.
135
+ If generation is unavailable (older CLI, non-V3 account/exit 6, or missing inputs),
136
+ report the reason and author tests using 3b. Local-project creation itself still
137
+ requires V3.
115
138
 
116
- #### 3b. Fallback: author the tests by hand (quality over quantity)
139
+ #### 3b. Author the tests by hand
117
140
 
118
141
  **Frontend** — one JSON plan file per flow, in a directory (e.g. `./testsprite-plans/`).
119
142
  Each file is a COMPLETE plan and must include `projectId` (from step 2), `type: "frontend"`,
@@ -140,14 +163,11 @@ Each file is a COMPLETE plan and must include `projectId` (from step 2), `type:
140
163
  **Backend** — one `.py` file per endpoint, using `requests` with concrete assertions on
141
164
  status code and response body.
142
165
 
143
- **Backend auth — read the injected `__AUTH_HEADERS__`, NEVER hardcode any credential.** This
144
- covers **every** secret the API needs — Bearer/JWT tokens **and** API keys (`sk-…`,
145
- `x-api-key`), basic-auth blobs, cookies. TestSprite prepends a managed credential block
146
- (`__AUTH_CREDENTIAL__` / `__AUTH_TYPE__` / `__AUTH_HEADERS__`) to every backend test from the
147
- project's Authentication settings, and `__AUTH_HEADERS__` already holds the right header(s) for
148
- the configured type (Bearer → `{"Authorization": "Bearer …"}`; API key → `{"X-API-Key": "…"}`;
149
- basic → `{"Authorization": "Basic …"}`). Spread it into your request headers — never paste a
150
- literal `Bearer …` / `sk-…` / key value into the script:
166
+ **Backend auth:** read injected `__AUTH_HEADERS__`; never hardcode Bearer/JWT tokens,
167
+ API keys, basic-auth blobs, or cookies. TestSprite injects `__AUTH_CREDENTIAL__`,
168
+ `__AUTH_TYPE__`, and `__AUTH_HEADERS__` from project Authentication settings.
169
+ The headers already match the configured type (Authorization for Bearer/basic,
170
+ X-API-Key for API keys). Spread them into each request:
151
171
 
152
172
  ```python
153
173
  r = requests.get(f"{TARGET_URL}/orders", headers={**__AUTH_HEADERS__})
@@ -161,10 +181,8 @@ runs keep working after the token expires. A hardcoded token expires within hour
161
181
  key can't be rotated centrally — `test create` emits a `[warn]` on an inlined credential; treat it
162
182
  as a must-fix.
163
183
 
164
- **Assertion rule (this is the whole game for FE):** every `assertion` step must name a
165
- **concrete, observable** outcome — an element, text, URL, count, or status. Never write
166
- `"verify it works"`, `"check the page loads"`, or other narrative that an AI judge can
167
- rubber-stamp. Vague assertions are how false-PASS sneaks in.
184
+ Each assertion must name an observable element, text, URL, count, or status.
185
+ Avoid "verify it works" or "check the page loads": vague assertions create false passes.
168
186
 
169
187
  Aim for ~8–15 tests covering the core flows. Don't pad.
170
188
 
@@ -192,11 +210,16 @@ Pick the **2–3 highest-value happy-path** tests (prefer ones you're most confi
192
210
  and run only those:
193
211
 
194
212
  ```bash
195
- testsprite test run <testId> --wait
213
+ testsprite test run <testId> --wait # deployed target
214
+ testsprite test run <testId> --local <port> --local-host <host> # local frontend
196
215
  ```
197
216
 
198
- Do **not** run the whole suite automatically — a 20-test FE suite is ~40 credits and a free
199
- account only has 150. Running the full suite is the user's explicit choice.
217
+ Do **not** run the whole suite automatically. V3 frontend runs, including local runs,
218
+ cost 0.5 credit each; check `testsprite usage` before sizing the suite.
219
+ Local runs imply waiting (1200 seconds by default); one test per invocation, parallel
220
+ invocations allowed, 5 live tunnel bindings per user. Keep the early stderr `Run <runId>`
221
+ receipt. An owned local timeout cancels by default: start a new run with
222
+ `--local <port> --local-host <host> --timeout 1800` (same host), not `test wait`. A run cancelled before it finished is refunded.
200
223
 
201
224
  ### 6. Report
202
225
 
@@ -205,13 +228,13 @@ Tell the user, plainly:
205
228
  - "Your project now has **N** tests covering: <list the flows>."
206
229
  - "I smoke-ran **M** — here's the result: <pass/fail + the dashboard link from the run output>."
207
230
  - "To run the rest (≈X credits — state the cost so they choose knowingly):
208
- - frontend — run each remaining test by id: `testsprite test run <testId> --wait` (there is
209
- **no `--all` for frontend**);
231
+ - frontend — use `test run <testId> --wait` for deployed targets or
232
+ `test run <testId> --local <port> --local-host <host>` for local targets (`--all --local` is refused);
210
233
  - backend — `testsprite test run --all --project <id>` (wave-ordered, runs every BE test)."
211
234
 
212
235
  ## Quality checklist (self-check before reporting done)
213
236
 
214
- - [ ] FE project has a real `--url`; login configured if the app needs it.
237
+ - [ ] FE project has a public `--url` or uses `--local`; login configured if needed.
215
238
  - [ ] API project: an API spec uploaded before generating (a PRD is optional, alongside it) — or you used path 3b.
216
239
  - [ ] If you generated: you **read the proposals** and dropped the ones that don't fit,
217
240
  rather than accepting the batch unseen.
@@ -225,7 +248,7 @@ Tell the user, plainly:
225
248
  - Don't auto-run the full suite (credit wall / surprise 402).
226
249
  - Don't write narrative assertions an AI judge can't fail.
227
250
  - Don't call backend endpoints directly — only the `testsprite` CLI.
228
- - Don't create a FE project without a URL.
251
+ - Don't create a FE project without public `--url` or `--local <port>`.
229
252
  - Don't re-seed a project that already has tests — that's not this skill's job.
230
253
  - Don't accept a generated batch unread — reviewing it is the point of the staging step.
231
254
  - Don't stall when generation isn't available — say so and hand-author instead.
@@ -234,6 +257,4 @@ Tell the user, plainly:
234
257
 
235
258
  ## Hand off to verify
236
259
 
237
- This skill's job ends once the project has a seeded suite and a first green run. From here on,
238
- the **`testsprite-verify`** skill takes over: after the user changes code, it runs the tests
239
- covering that change before they report the work done. Onboard once; verify continuously.
260
+ After seeding and a first green run, hand off to `testsprite-verify` for subsequent changes.
@@ -1,133 +1,118 @@
1
1
  # TestSprite Verification Loop
2
2
 
3
- After finishing a feature or fix in a TestSprite-tested repo, use the `testsprite`
4
- CLI to run the relevant TestSprite tests against the change and inspect any failure
5
- artifacts before reporting the work as done. Use whenever code has changed outside
6
- docs/config and is about to be reported complete.
3
+ After a feature/fix, run relevant tests and inspect failures before reporting done.
4
+ Skip docs-only/build-config edits. Missing credentials mean unverified.
5
+ Honor the user's explicit choice of CLI or MCP.
7
6
 
8
- ## When to run
7
+ ## 1. Preflight and project
9
8
 
10
- Run after a feature or fix lands. Skip only for: docs-only edits, pure
11
- build/config changes, or when the repo has no TestSprite project linked.
12
-
13
- The CLI tests a deployed URL via `--target-url`, or a frontend test on this
14
- machine via `--local <port>` (tunnels `localhost`/`127.0.0.1`/`::1` only; needs
15
- a key with the `run:tunnel` scope — 403 there means mint a new key; a backend
16
- test's target is baked into its code, so it can't use `--local`). If the user
17
- named a tool (the CLI or the MCP), honor that even when both could apply.
9
+ ```bash
10
+ testsprite --version
11
+ testsprite auth status
12
+ ```
18
13
 
19
- ## Core loop
14
+ If missing, tell the user to install the CLI or run `testsprite setup` respectively.
15
+ Resolve the project from `$TESTSPRITE_PROJECT_ID`, `.testsprite/config.json`, then
16
+ `testsprite project list --output json`; ask if multiple projects match.
20
17
 
21
- ### 1. Preflight
18
+ For a local app with no project, start it and bootstrap:
22
19
 
23
20
  ```bash
24
- testsprite --version # CLI installed?
25
- testsprite auth status # credentials valid?
21
+ testsprite project create --type frontend --name "<repo name>" --local <port> --local-host <host>
22
+ testsprite test create --plan-from plan.json --project <projectId>
23
+ testsprite test run <test-id> --local <port> --local-host <host> --output json
26
24
  ```
27
25
 
28
- If `--version` fails, tell the user to install the CLI and stop.
29
- If `auth status` fails, tell the user to run `testsprite setup` and stop.
30
-
31
- ### 2. Find the project
26
+ Local projects need V3 (V2-only: exit 7, `local-origin-requires-v3`). They skip
27
+ exploration; `test plan generate` is refused before charge (exit 6). Author plans
28
+ with `test create --plan-from` without `--run`, then run each id with `--local`.
29
+ Portal runs are blocked for free until `project update <id> --url https://…` sets
30
+ a public URL. Deployed projects retain `project create --url`; an empty deployed
31
+ suite can use `test plan generate --project <id>` then `test plan accept`.
32
32
 
33
- In order: `$TESTSPRITE_PROJECT_ID` → `.testsprite/config.json` → `testsprite project list --output json`.
33
+ ## 2. Run against the change
34
34
 
35
- ### 3. Run
35
+ Reuse a test covering the change or create one. Public `--target-url` must contain
36
+ the new deployment. The CLI does not build/host apps. For local-only changes use
37
+ `testsprite test run <test-id> --local <port>` (frontend only).
36
38
 
37
39
  ```bash
38
- # New frontend test from plan (most common)
40
+ # Deployed frontend: create + run, or run an existing test
39
41
  testsprite test create --plan-from plan.json --run --wait \
40
42
  --target-url https://staging.example.com --timeout 600 --output json
41
-
42
- # Existing test
43
43
  testsprite test run <test-id> --target-url https://staging.example.com \
44
44
  --wait --timeout 600 --output json
45
-
46
- # New backend test from Python assertion file
45
+ # Backend Python assertion
47
46
  testsprite test create --type backend --name "Login rejects empty password" \
48
47
  --project <id> --code-file /tmp/test.py --run --wait --timeout 600
49
-
50
- # Replay (cheaper than a fresh run — reuses saved test code)
48
+ # Deployed replay (V3 FE: 0.5 credit)
51
49
  testsprite test rerun <test-id> --wait --output json
52
-
53
- # Backend tests sharing state: declare the dependency graph at create time;
54
- # the wave engine orders runs (producers → consumers → teardown last)
55
- testsprite test create --type backend --project <id> --code-file /tmp/login.py \
56
- --name "login issues an auth token" --produces auth_token
57
- testsprite test create --type backend --project <id> --code-file /tmp/profile.py \
58
- --name "profile update accepts the token" --needs auth_token
59
- testsprite test create --type backend --project <id> --code-file /tmp/cleanup.py \
60
- --name "fixture user is deleted" --category teardown
61
-
62
- # Wave-ordered batch fresh run (BE tests, all or filtered)
63
- testsprite test run --all --project <id> [--filter <substr>] \
64
- --wait --max-concurrency 4 --output json
50
+ # Dependency batch; optional --filter <substring>
51
+ testsprite test run --all --project <id> --wait --max-concurrency 4 --output json
65
52
  ```
66
53
 
67
- **Key behaviors:**
68
-
69
- - `--target-url` must be publicly reachable (no localhost / RFC1918) and must
70
- already have the change deployed (e.g. a CI preview deploy) — running earlier
71
- verifies the previous build, not your change. For a local-only change use
72
- `--local <port>` instead (frontend tests only).
73
- - Backend `--code-file`: the runner executes the file top-to-bottom (not `pytest`), so **call your `test_*` function(s) at the end of the file** — a defined-but-uncalled test silently passes.
74
- - Backend sandbox has only stdlib + `requests` + `pytest` + `numpy` + `scipy`. Test the API over HTTP with `requests`; do **not** `import` the project's own source modules or other packages (e.g. `torch`) — they aren't installed and the test won't run.
75
- - `--wait` long-polls until terminal; don't wrap it in a retry loop. A
76
- `--local` timeout has nothing to resume — re-run with `--local`.
77
- - Exit `0` = passed; `1` = failed/blocked; `7` = timeout (resume with `test wait <run-id>`).
78
- - BE dependency flags (`--produces`/`--needs`/`--category`) are backend-only,
79
- repeatable, and **editable** — `test update` amends them, so never delete and
80
- recreate a test to change the graph. Don't hand-sequence `test run` calls to
81
- fake ordering; use `test run --all` so the engine passes captured variables
82
- between waves.
83
- - A BE `test rerun` dispatches the whole producer/teardown closure, side effects
84
- included; `--skip-dependencies` reruns only the named test. If a producer failed
85
- in the same closure, the consumer's failure is starvation (missing token/fixture)
86
- — triage the producer first; it does not implicate your change.
87
- - `create` and `--wait` output a `dashboardUrl` — point the user there to
88
- inspect a test or run.
89
-
90
- ### 4. On failure — download the artifact
54
+ - Local runs need `run:tunnel`; keys minted before that scope existed must be
55
+ replaced if the CLI names it as missing (exit 3). Free-plan local runs work;
56
+ a V3 frontend run costs 0.5 credit. Backend tests cannot use `--local`.
57
+ - `--local` implies `--wait`; timeout defaults to 1200 seconds, ordinary waits
58
+ to 600. `--local-host` accepts `localhost`, `127.0.0.1` (default), or `::1`.
59
+ A dead port exits 5 before charge; `--skip-preflight` bypasses the probe.
60
+ Public `--target-url` rejects localhost/private addresses and excludes `--local`.
61
+ - One test per local invocation; parallel invocations are fine. `--all --local`
62
+ exits 5. A user has 5 live tunnel bindings; `tunnel_binding_limit` is exit 11,
63
+ not auto-retried. Stop an unused tunnel or reuse one with `--tunnel-client`.
64
+ - Keep the early **stderr** `Run <runId>` receipt, emitted after triggering;
65
+ `Dashboard: <url>` follows when supplied. Stdout remains the JSON result channel.
66
+ - An **owned** local timeout, Ctrl-C, or polling failure cancels the run by
67
+ default and closes the tunnel. Check the reported cancellation outcome.
68
+ A run cancelled before it finished is refunded. `--no-cancel-on-interrupt`
69
+ detaches instead, but the owned tunnel still closes and the run remains billable.
70
+ - Owned local timeout: start a **new**
71
+ `testsprite test run <test-id> --local <port> --timeout 1800`,
72
+ keeping `--local-host <host>` if used. `test wait` cannot reopen the tunnel.
73
+ Ordinary/adopted waits can resume with `testsprite test wait <run-id>`
74
+ while the target is reachable.
75
+ - `tunnel start` (no port) holds a tunnel in a terminal; keep it alive.
76
+ Borrow via `--local <port> --tunnel-client <uuid>`; no automatic cancel or close.
77
+ A second `tunnel start`/process using the same credential takes over; the first exits **10**.
78
+ - A case last run through a tunnel stays local: later Portal Run, schedules, or
79
+ bare CLI runs are free BLOCKED (`tunnel-required`, exit 6). Use `--local` again
80
+ or explicitly retarget with public `--target-url`. V3 local runs use the agent
81
+ path, never saved-code replay, and preserve saved code.
82
+ - `--wait` handles polling/backoff; do not wrap it in a retry loop.
83
+ - Backend Python runs top-to-bottom, not via pytest: call your `test_*` functions.
84
+ The sandbox has stdlib, `requests`, `pytest`, `numpy`, and `scipy`; use HTTP,
85
+ not imports from the project's source or uninstalled packages.
86
+ - Backend `--produces`/`--needs` are repeatable; `--category teardown` marks cleanup.
87
+ Set dependencies with `test create` or edit with `test update`; do not delete
88
+ and recreate. Use `test run --all` for producer → consumer → teardown ordering
89
+ and variable passing. A BE `test rerun` includes that closure and its side effects;
90
+ `--skip-dependencies` selects only the named test. Triage failed producers before
91
+ blaming consumers starved of their token/fixture.
92
+
93
+ ## 3. Inspect and report
91
94
 
92
95
  ```bash
93
96
  testsprite test artifact get <run-id> --out ./.testsprite/runs/<run-id>/
97
+ testsprite test steps <test-id> --run-id <run-id> --output json
94
98
  ```
95
99
 
96
- Inspect the bundle (failing step, screenshots, root-cause hypothesis) before
97
- deciding whether your change caused the failure.
100
+ Read the failing step, screenshots and root cause. Bare `test steps <test-id>`
101
+ means the latest run's steps; pin the receipt's
102
+ run id. An empty latest run does not substitute earlier steps; choose an earlier
103
+ id from `test result <test-id> --history`. Report the verdict and dashboard link.
98
104
 
99
- ### 5. Dry-run for learning
105
+ Exits: 0 passed; 1 failed/blocked/cancelled; 3 auth/scope; 4 not found;
106
+ 5 validation; 6 conflict/precondition; 7 timeout/unsupported; 10 unavailable;
107
+ 11 rate limited; 12 insufficient credits.
100
108
 
101
- Every command works without credentials under `--dry-run`:
109
+ ## Dry-run and setup
110
+
111
+ `--dry-run` works without credentials:
102
112
 
103
113
  ```bash
104
114
  testsprite test run <test-id> --dry-run --output json
105
115
  testsprite test create --plan-from plan.json --dry-run --output json
106
116
  ```
107
117
 
108
- ## Exit-code quick reference
109
-
110
- | Code | Meaning |
111
- | ---- | ------------------------------------------------- |
112
- | 0 | Success (passed) |
113
- | 1 | Failed / blocked / cancelled |
114
- | 3 | Auth error |
115
- | 4 | Not found |
116
- | 5 | Validation error |
117
- | 6 | Conflict (already running) |
118
- | 7 | Timeout — resume: `testsprite test wait <run-id>` |
119
- | 11 | Rate limited (retriable) |
120
- | 12 | Insufficient credits |
121
-
122
- ## Bootstrap (first-time setup)
123
-
124
- ```bash
125
- npm install -g @testsprite/testsprite-cli
126
- testsprite setup # configure + verify + install agent skill in one shot
127
- ```
128
-
129
- Verify your setup anytime: `testsprite auth status`.
130
-
131
- Project with **no tests at all**? Seed a suite first — that's setup, not verification.
132
- `testsprite test plan generate --project <id>` proposes cases and `test plan accept`
133
- promotes them; or author plans by hand.
118
+ Setup: `npm install -g @testsprite/testsprite-cli`, then `testsprite setup`.