@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
@@ -0,0 +1,183 @@
1
+ <!--
2
+ User-facing content for `testsprite agent install` (skill: testsprite-onboard).
3
+ Body only — name + description frontmatter is emitted by the install wrapper.
4
+ The cursor (.mdc), cline (.clinerules), and antigravity (experimental)
5
+ wrappers reuse this body verbatim and swap only the frontmatter/header.
6
+ -->
7
+
8
+ # TestSprite: onboard a repo with a seed test suite
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.
14
+
15
+ This skill only uses shipped CLI commands. It works the same whether the user is on the V2
16
+ or V3 backend — the CLI routes internally. Do **not** call backend APIs directly.
17
+
18
+ ## When to use
19
+
20
+ - Right after `testsprite setup`, or any time the active project has 0–1 tests.
21
+ - The user says "set up tests", "bootstrap", "seed a suite", "get me started", or similar.
22
+
23
+ ## When NOT to use
24
+
25
+ - The project already has tests — that's the `testsprite-verify` skill's job, not this one.
26
+ - The user only changed code and wants it checked — again, `testsprite-verify`.
27
+
28
+ ## Prerequisites
29
+
30
+ `testsprite setup` has run (an API key is configured). If `testsprite project list` errors on
31
+ auth, stop and tell the user to run `testsprite setup` first — don't try to configure for them.
32
+
33
+ ## Steps
34
+
35
+ ### 1. Understand the app (don't skip — this is where coverage quality comes from)
36
+
37
+ Read the repo to establish, concretely:
38
+
39
+ - **Frontend**: the deployed/local **URL**, the 4–8 most important user flows (auth, core
40
+ CRUD, checkout, search, settings…), and whether flows need **login**.
41
+ - **Backend**: the key **API endpoints** and their success/error contracts.
42
+
43
+ Prefer **code-derived** routes/handlers over guessing — you have the source; use it. This
44
+ beats a blind crawl.
45
+
46
+ ### 2. Create the project (FE must have a URL)
47
+
48
+ Frontend:
49
+
50
+ ```bash
51
+ testsprite project create --type frontend --name "<repo name>" --url <app-url> \
52
+ [--username <user> --password-file <path-to-secret>]
53
+ ```
54
+
55
+ Backend:
56
+
57
+ ```bash
58
+ testsprite project create --type backend --name "<repo name>"
59
+ ```
60
+
61
+ Capture the returned `projectId`.
62
+
63
+ > **Critical for FE**: a frontend test with no resolvable target URL fails immediately with
64
+ > `No environment URL configured` — the suite goes all-red. Always pass `--url`. If flows need
65
+ > login, pass `--username/--password-file` now so authenticated pages are reachable.
66
+
67
+ ### 3. Author the tests (quality over quantity)
68
+
69
+ **Frontend** — one JSON plan file per flow, in a directory (e.g. `./testsprite-plans/`).
70
+ Each file is a COMPLETE plan and must include `projectId` (from step 2), `type: "frontend"`,
71
+ `name`, and `planSteps` — `create-batch` reads the project from each file, not from a flag:
72
+
73
+ ```json
74
+ {
75
+ "projectId": "<projectId from step 2>",
76
+ "type": "frontend",
77
+ "name": "Checkout — guest can complete a purchase",
78
+ "planSteps": [
79
+ { "type": "action", "description": "Navigate to /products and open the first product" },
80
+ { "type": "action", "description": "Click 'Add to cart', then go to /cart" },
81
+ {
82
+ "type": "assertion",
83
+ "description": "The cart shows exactly 1 line item with the product's name and price"
84
+ },
85
+ { "type": "action", "description": "Proceed to checkout as guest and submit the test payment" },
86
+ { "type": "assertion", "description": "A confirmation page appears showing an order number" }
87
+ ]
88
+ }
89
+ ```
90
+
91
+ **Backend** — one `.py` file per endpoint, using `requests` with concrete assertions on
92
+ status code and response body.
93
+
94
+ **Backend auth — read the injected `__AUTH_HEADERS__`, NEVER hardcode any credential.** This
95
+ covers **every** secret the API needs — Bearer/JWT tokens **and** API keys (`sk-…`,
96
+ `x-api-key`), basic-auth blobs, cookies. TestSprite prepends a managed credential block
97
+ (`__AUTH_CREDENTIAL__` / `__AUTH_TYPE__` / `__AUTH_HEADERS__`) to every backend test from the
98
+ project's Authentication settings, and `__AUTH_HEADERS__` already holds the right header(s) for
99
+ the configured type (Bearer → `{"Authorization": "Bearer …"}`; API key → `{"X-API-Key": "…"}`;
100
+ basic → `{"Authorization": "Basic …"}`). Spread it into your request headers — never paste a
101
+ literal `Bearer …` / `sk-…` / key value into the script:
102
+
103
+ ```python
104
+ r = requests.get(f"{TARGET_URL}/orders", headers={**__AUTH_HEADERS__})
105
+ ```
106
+
107
+ Configure the credential once on the project (ask the user for the value — never invent it or
108
+ reuse a key you happened to see): a static credential with
109
+ `testsprite project credential <projectId> --type "Bearer token"|"API key"|"basic token" --credential <value>`,
110
+ or an auto-refreshing login with `testsprite project auto-auth <projectId> …` so scheduled/repeat
111
+ runs keep working after the token expires. A hardcoded token expires within hours and a hardcoded
112
+ key can't be rotated centrally — `test create` emits a `[warn]` on an inlined credential; treat it
113
+ as a must-fix.
114
+
115
+ **Assertion rule (this is the whole game for FE):** every `assertion` step must name a
116
+ **concrete, observable** outcome — an element, text, URL, count, or status. Never write
117
+ `"verify it works"`, `"check the page loads"`, or other narrative that an AI judge can
118
+ rubber-stamp. Vague assertions are how false-PASS sneaks in.
119
+
120
+ Aim for ~8–15 tests covering the core flows. Don't pad.
121
+
122
+ ### 4. Batch-create
123
+
124
+ Frontend (one call, up to 50 plans from the directory — `create-batch` is FE-only and has
125
+ **no `--project` flag**; the project comes from each plan file's `projectId`):
126
+
127
+ ```bash
128
+ testsprite test create-batch --plan-from-dir ./testsprite-plans
129
+ ```
130
+
131
+ Backend (one call per file — `create-batch` is FE-only; `--name` is required):
132
+
133
+ ```bash
134
+ testsprite test create --type backend --name "<behavior being tested>" \
135
+ --code-file ./tests/<endpoint>.py --project <projectId>
136
+ ```
137
+
138
+ Capture the created `testId`s from the output.
139
+
140
+ ### 5. Smoke-run a few — NOT all (protect credits)
141
+
142
+ Pick the **2–3 highest-value happy-path** tests (prefer ones you're most confident are green)
143
+ and run only those:
144
+
145
+ ```bash
146
+ testsprite test run <testId> --wait
147
+ ```
148
+
149
+ Do **not** run the whole suite automatically — a 20-test FE suite is ~40 credits and a free
150
+ account only has 150. Running the full suite is the user's explicit choice.
151
+
152
+ ### 6. Report
153
+
154
+ Tell the user, plainly:
155
+
156
+ - "Your project now has **N** tests covering: <list the flows>."
157
+ - "I smoke-ran **M** — here's the result: <pass/fail + the dashboard link from the run output>."
158
+ - "To run the rest (≈X credits — state the cost so they choose knowingly):
159
+ - frontend — run each remaining test by id: `testsprite test run <testId> --wait` (there is
160
+ **no `--all` for frontend**);
161
+ - backend — `testsprite test run --all --project <id>` (wave-ordered, runs every BE test)."
162
+
163
+ ## Quality checklist (self-check before reporting done)
164
+
165
+ - [ ] FE project has a real `--url`; login configured if the app needs it.
166
+ - [ ] Every FE assertion names a concrete, observable outcome (no "verify it works").
167
+ - [ ] Tests cover the core flows you found in the code, not just one page.
168
+ - [ ] Smoke-ran 2–3 happy-path tests, not the whole suite.
169
+ - [ ] Reported test count, smoke result + dashboard link, and the cost to run the rest.
170
+
171
+ ## Don'ts
172
+
173
+ - Don't auto-run the full suite (credit wall / surprise 402).
174
+ - Don't write narrative assertions an AI judge can't fail.
175
+ - Don't call backend endpoints directly — only the `testsprite` CLI.
176
+ - Don't create a FE project without a URL.
177
+ - Don't re-seed a project that already has tests — that's not this skill's job.
178
+
179
+ ## Hand off to verify
180
+
181
+ This skill's job ends once the project has a seeded suite and a first green run. From here on,
182
+ the **`testsprite-verify`** skill takes over: after the user changes code, it runs the tests
183
+ covering that change before they report the work done. Onboard once; verify continuously.
@@ -64,6 +64,8 @@ testsprite test run --all --project <id> [--filter <substr>] \
64
64
  already have the change deployed (e.g. a CI preview deploy) — the CLI tests a
65
65
  deployed URL, it doesn't host your environment. Running earlier verifies the
66
66
  previous build.
67
+ - 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.
68
+ - 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.
67
69
  - `--wait` long-polls until terminal. Do not wrap it in a retry loop.
68
70
  - Exit `0` = passed; `1` = failed/blocked; `7` = timeout (resume with `test wait <run-id>`).
69
71
  - BE dependency flags (`--produces`/`--needs`/`--category`) are backend-only and
@@ -135,7 +135,10 @@ language; you don't write browser code.
135
135
  **Backend — write the Python yourself and use `--code-file`.** There is no
136
136
  server-side codegen on the CLI. Read the API surface that changed (OpenAPI, the
137
137
  route handler, request/response shapes) and write a pytest-style assertion script
138
- to a tempfile:
138
+ to a tempfile. **End the file by calling your `test_*` function(s)** — the runner
139
+ executes the file top-to-bottom and does NOT auto-discover/collect test functions
140
+ the way `pytest` does, so a test that is only _defined_ (never called) silently
141
+ passes regardless of its assertions:
139
142
 
140
143
  ```python
141
144
  # /tmp/login-empty-password.py — runs against the project's target URL, creds injected.
@@ -145,8 +148,56 @@ def test_login_rejects_empty_password():
145
148
  r = requests.post(f"{TARGET_URL}/login", json={"email": "a@b.c", "password": ""})
146
149
  assert r.status_code == 400
147
150
  assert r.json().get("error") == "invalid password"
151
+
152
+ # Required: actually invoke the test so its assertions run.
153
+ test_login_rejects_empty_password()
154
+ ```
155
+
156
+ **Execution environment (backend).** The code runs in a locked-down sandbox with
157
+ only the Python **standard library + `requests` + `pytest` + `numpy` + `scipy`**
158
+ (plus `requests`' own deps like `urllib3`). So:
159
+
160
+ - **Test the API over HTTP** with `requests` against the target URL — that's what a
161
+ backend test verifies.
162
+ - **Do NOT `import` the project's own source modules** (e.g. `from app.services import …`,
163
+ `import core`, `import model`) or other third-party/ML packages (e.g. `torch`,
164
+ `pandas`, `django`). They are not installed, so the test fails to even run.
165
+ - Get values from the API's responses (and captured variables), not by importing and
166
+ calling the app's internals.
167
+
168
+ **Authentication — read the injected credential, NEVER hardcode any credential.** This
169
+ applies to **every** secret the API needs — Bearer/JWT tokens **and** API keys, basic-auth
170
+ blobs, session cookies. Do not paste a literal `Bearer …`, `sk-…`, `x-api-key` value, or any
171
+ other credential into the test. Before your script runs, TestSprite prepends a managed
172
+ credential block built from the project's Authentication settings, and `__AUTH_HEADERS__`
173
+ already contains the right header(s) for the configured auth type:
174
+
175
+ ```python
176
+ # Auto-injected credentials — do not modify
177
+ __AUTH_CREDENTIAL__ = "..."
178
+ __AUTH_TYPE__ = "Bearer token" # or "API key" / "basic token" / "public"
179
+ __AUTH_HEADERS__ = {"Authorization": "Bearer ..."} # API key → {"X-API-Key": "..."}; basic → {"Authorization": "Basic ..."}
180
+ ```
181
+
182
+ Spread `__AUTH_HEADERS__` into every authenticated request — it adapts to whatever auth type
183
+ the project is configured for, so the same line works for Bearer, API-key, or basic auth:
184
+
185
+ ```python
186
+ r = requests.get(f"{TARGET_URL}/profile", headers={**__AUTH_HEADERS__})
148
187
  ```
149
188
 
189
+ Configure the credential **once on the project** (ask the user for the value — never invent
190
+ or reuse a key you happened to see), and the block stays correct + refreshable:
191
+
192
+ - **Bearer / API key / basic (static):**
193
+ `testsprite project credential <projectId> --type "Bearer token"|"API key"|"basic token" --credential <value>`
194
+ - **Auto-refreshing login (recurring token):** `testsprite project auto-auth <projectId> …`
195
+
196
+ A hardcoded token expires within hours (and a hardcoded key can't be rotated centrally), so
197
+ the test breaks on later runs; the managed block is rewritten with a fresh value each run.
198
+ `test create` emits a `[warn]` when it detects an inlined credential literal — treat that as
199
+ a must-fix, not a nuisance.
200
+
150
201
  **Backend tests that share state declare dependencies at create time.** For a
151
202
  one-off verification, prefer a single self-contained script (log in inside the
152
203
  same file). But when the coverage set splits naturally into producer → consumer