@testsprite/testsprite-cli 0.1.2 → 0.2.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.
- package/dist/commands/agent.d.ts +9 -0
- package/dist/commands/agent.js +145 -79
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.js +42 -12
- package/dist/commands/project.js +6 -1
- package/dist/commands/test.d.ts +26 -11
- package/dist/commands/test.js +226 -97
- package/dist/index.js +38 -16
- package/dist/lib/agent-targets.d.ts +102 -21
- package/dist/lib/agent-targets.js +153 -34
- package/dist/lib/bundle.d.ts +17 -1
- package/dist/lib/bundle.js +110 -53
- package/dist/lib/client-factory.d.ts +18 -0
- package/dist/lib/client-factory.js +42 -2
- package/dist/lib/credentials.d.ts +7 -0
- package/dist/lib/credentials.js +30 -0
- package/dist/lib/dry-run/samples.js +26 -9
- package/dist/lib/render-error.d.ts +13 -0
- package/dist/lib/render-error.js +27 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/skills/testsprite-onboard.skill.md +162 -0
- package/skills/testsprite-verify.codex.md +2 -0
- package/skills/testsprite-verify.skill.md +19 -1
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
**Assertion rule (this is the whole game for FE):** every `assertion` step must name a
|
|
95
|
+
**concrete, observable** outcome — an element, text, URL, count, or status. Never write
|
|
96
|
+
`"verify it works"`, `"check the page loads"`, or other narrative that an AI judge can
|
|
97
|
+
rubber-stamp. Vague assertions are how false-PASS sneaks in.
|
|
98
|
+
|
|
99
|
+
Aim for ~8–15 tests covering the core flows. Don't pad.
|
|
100
|
+
|
|
101
|
+
### 4. Batch-create
|
|
102
|
+
|
|
103
|
+
Frontend (one call, up to 50 plans from the directory — `create-batch` is FE-only and has
|
|
104
|
+
**no `--project` flag**; the project comes from each plan file's `projectId`):
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
testsprite test create-batch --plan-from-dir ./testsprite-plans
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Backend (one call per file — `create-batch` is FE-only; `--name` is required):
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
testsprite test create --type backend --name "<behavior being tested>" \
|
|
114
|
+
--code-file ./tests/<endpoint>.py --project <projectId>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Capture the created `testId`s from the output.
|
|
118
|
+
|
|
119
|
+
### 5. Smoke-run a few — NOT all (protect credits)
|
|
120
|
+
|
|
121
|
+
Pick the **2–3 highest-value happy-path** tests (prefer ones you're most confident are green)
|
|
122
|
+
and run only those:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
testsprite test run <testId> --wait
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Do **not** run the whole suite automatically — a 20-test FE suite is ~40 credits and a free
|
|
129
|
+
account only has 150. Running the full suite is the user's explicit choice.
|
|
130
|
+
|
|
131
|
+
### 6. Report
|
|
132
|
+
|
|
133
|
+
Tell the user, plainly:
|
|
134
|
+
|
|
135
|
+
- "Your project now has **N** tests covering: <list the flows>."
|
|
136
|
+
- "I smoke-ran **M** — here's the result: <pass/fail + the dashboard link from the run output>."
|
|
137
|
+
- "To run the rest (≈X credits — state the cost so they choose knowingly):
|
|
138
|
+
- frontend — run each remaining test by id: `testsprite test run <testId> --wait` (there is
|
|
139
|
+
**no `--all` for frontend**);
|
|
140
|
+
- backend — `testsprite test run --all --project <id>` (wave-ordered, runs every BE test)."
|
|
141
|
+
|
|
142
|
+
## Quality checklist (self-check before reporting done)
|
|
143
|
+
|
|
144
|
+
- [ ] FE project has a real `--url`; login configured if the app needs it.
|
|
145
|
+
- [ ] Every FE assertion names a concrete, observable outcome (no "verify it works").
|
|
146
|
+
- [ ] Tests cover the core flows you found in the code, not just one page.
|
|
147
|
+
- [ ] Smoke-ran 2–3 happy-path tests, not the whole suite.
|
|
148
|
+
- [ ] Reported test count, smoke result + dashboard link, and the cost to run the rest.
|
|
149
|
+
|
|
150
|
+
## Don'ts
|
|
151
|
+
|
|
152
|
+
- Don't auto-run the full suite (credit wall / surprise 402).
|
|
153
|
+
- Don't write narrative assertions an AI judge can't fail.
|
|
154
|
+
- Don't call backend endpoints directly — only the `testsprite` CLI.
|
|
155
|
+
- Don't create a FE project without a URL.
|
|
156
|
+
- Don't re-seed a project that already has tests — that's not this skill's job.
|
|
157
|
+
|
|
158
|
+
## Hand off to verify
|
|
159
|
+
|
|
160
|
+
This skill's job ends once the project has a seeded suite and a first green run. From here on,
|
|
161
|
+
the **`testsprite-verify`** skill takes over: after the user changes code, it runs the tests
|
|
162
|
+
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,23 @@ 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()
|
|
148
154
|
```
|
|
149
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
|
+
|
|
150
168
|
**Backend tests that share state declare dependencies at create time.** For a
|
|
151
169
|
one-off verification, prefer a single self-contained script (log in inside the
|
|
152
170
|
same file). But when the coverage set splits naturally into producer → consumer
|