@testsprite/testsprite-cli 0.1.1 → 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.
@@ -0,0 +1,73 @@
1
+ import type { OutputMode } from './output.js';
2
+ /**
3
+ * Full command paths (group + leaf) that signal the caller is actively driving
4
+ * the verification loop — running or authoring tests, or checking auth in
5
+ * preflight. The skill nudge fires ONLY for these.
6
+ *
7
+ * Deliberately excluded:
8
+ * - `setup` / `init` / `agent install` — they ARE the fix; nudging is circular.
9
+ * - read-only inspection (`test list/get/result/...`, `project list/get`) —
10
+ * keeps an agent that is merely browsing from being nagged.
11
+ * - `auth configure` / `auth remove` (and the deprecated `auth logout`) —
12
+ * credential management, not the loop.
13
+ *
14
+ * Match the strings emitted by `commandPathOf` in `src/index.ts`. `auth status`
15
+ * is the primary identity command; `auth whoami` is its deprecated alias and is
16
+ * listed too so the warning fires regardless of which name the caller uses.
17
+ */
18
+ export declare const SKILL_NUDGE_COMMANDS: ReadonlySet<string>;
19
+ /**
20
+ * Env var that silences the warning. For CI, or users who deliberately drive
21
+ * the CLI by hand without wiring a coding agent.
22
+ */
23
+ export declare const SKILL_NUDGE_OPT_OUT_ENV = "TESTSPRITE_NO_SKILL_WARNING";
24
+ export interface SkillPresenceDeps {
25
+ existsSync?: (p: string) => boolean;
26
+ readFileSync?: (p: string) => string;
27
+ }
28
+ /**
29
+ * True if the `testsprite-verify` skill is installed for ANY supported agent in
30
+ * `dir`. own-file targets (claude/cursor/cline/antigravity): the landing file
31
+ * exists. managed-section target (codex / AGENTS.md): the file exists AND
32
+ * carries our BEGIN sentinel — a user-authored AGENTS.md without the sentinel
33
+ * does NOT count as our skill.
34
+ *
35
+ * The TARGETS table is the single source of truth for landing paths, so this
36
+ * stays in lockstep with `agent install` without re-listing paths. Best-effort:
37
+ * a per-target read error is swallowed (that target is treated as absent).
38
+ */
39
+ export declare function isVerifySkillInstalled(dir: string, deps?: SkillPresenceDeps): boolean;
40
+ export interface SkillNudgeContext {
41
+ /** Full command path, e.g. "test run" / "auth whoami". */
42
+ commandPath: string;
43
+ output: OutputMode;
44
+ dryRun: boolean;
45
+ profile: string;
46
+ cwd: string;
47
+ env: NodeJS.ProcessEnv;
48
+ /** Override the credentials file location (tests). */
49
+ credentialsPath?: string;
50
+ /** Override the profile lookup (tests); defaults to the real `readProfile`. */
51
+ readProfileImpl?: (profile: string, opts: {
52
+ path: string;
53
+ }) => {
54
+ apiKey?: string;
55
+ } | undefined;
56
+ /** Sink for the hint line; defaults to `process.stderr`. */
57
+ stderr?: (line: string) => void;
58
+ existsSync?: (p: string) => boolean;
59
+ readFileSync?: (p: string) => string;
60
+ }
61
+ /**
62
+ * Best-effort onboarding warning. When a configured caller drives a verify-loop
63
+ * command in a project that has NO installed skill, print a one-line `[warn]`
64
+ * line to stderr pointing at `testsprite setup`. Reaches a coding agent at the
65
+ * exact moment it uses the CLI without the skill wired up.
66
+ *
67
+ * Gates (all must pass to emit): text output (never pollutes `--output json`),
68
+ * not `--dry-run`, the command is in {@link SKILL_NUDGE_COMMANDS}, the opt-out
69
+ * env is unset, the active profile has an api key (un-configured callers hit an
70
+ * auth error that already points at setup), and the skill is not already
71
+ * installed. Never throws and never blocks the command — any error is swallowed.
72
+ */
73
+ export declare function maybeEmitSkillNudge(ctx: SkillNudgeContext): void;
@@ -0,0 +1,115 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { MANAGED_SECTION_BEGIN, TARGETS } from './agent-targets.js';
4
+ import { defaultCredentialsPath, readProfile } from './credentials.js';
5
+ /**
6
+ * Full command paths (group + leaf) that signal the caller is actively driving
7
+ * the verification loop — running or authoring tests, or checking auth in
8
+ * preflight. The skill nudge fires ONLY for these.
9
+ *
10
+ * Deliberately excluded:
11
+ * - `setup` / `init` / `agent install` — they ARE the fix; nudging is circular.
12
+ * - read-only inspection (`test list/get/result/...`, `project list/get`) —
13
+ * keeps an agent that is merely browsing from being nagged.
14
+ * - `auth configure` / `auth remove` (and the deprecated `auth logout`) —
15
+ * credential management, not the loop.
16
+ *
17
+ * Match the strings emitted by `commandPathOf` in `src/index.ts`. `auth status`
18
+ * is the primary identity command; `auth whoami` is its deprecated alias and is
19
+ * listed too so the warning fires regardless of which name the caller uses.
20
+ */
21
+ export const SKILL_NUDGE_COMMANDS = new Set([
22
+ 'test run',
23
+ 'test rerun',
24
+ 'test create',
25
+ 'test create-batch',
26
+ 'auth status',
27
+ 'auth whoami',
28
+ ]);
29
+ /**
30
+ * Env var that silences the warning. For CI, or users who deliberately drive
31
+ * the CLI by hand without wiring a coding agent.
32
+ */
33
+ export const SKILL_NUDGE_OPT_OUT_ENV = 'TESTSPRITE_NO_SKILL_WARNING';
34
+ /**
35
+ * True if the `testsprite-verify` skill is installed for ANY supported agent in
36
+ * `dir`. own-file targets (claude/cursor/cline/antigravity): the landing file
37
+ * exists. managed-section target (codex / AGENTS.md): the file exists AND
38
+ * carries our BEGIN sentinel — a user-authored AGENTS.md without the sentinel
39
+ * does NOT count as our skill.
40
+ *
41
+ * The TARGETS table is the single source of truth for landing paths, so this
42
+ * stays in lockstep with `agent install` without re-listing paths. Best-effort:
43
+ * a per-target read error is swallowed (that target is treated as absent).
44
+ */
45
+ export function isVerifySkillInstalled(dir, deps = {}) {
46
+ const exists = deps.existsSync ?? existsSync;
47
+ const read = deps.readFileSync ?? ((p) => readFileSync(p, 'utf8'));
48
+ for (const spec of Object.values(TARGETS)) {
49
+ const full = join(dir, spec.path);
50
+ if (!exists(full))
51
+ continue;
52
+ if (spec.mode === 'managed-section') {
53
+ try {
54
+ if (read(full).includes(MANAGED_SECTION_BEGIN))
55
+ return true;
56
+ }
57
+ catch {
58
+ // unreadable AGENTS.md → treat this target as absent, keep checking
59
+ }
60
+ continue;
61
+ }
62
+ return true; // own-file landing file present
63
+ }
64
+ return false;
65
+ }
66
+ /**
67
+ * Best-effort onboarding warning. When a configured caller drives a verify-loop
68
+ * command in a project that has NO installed skill, print a one-line `[warn]`
69
+ * line to stderr pointing at `testsprite setup`. Reaches a coding agent at the
70
+ * exact moment it uses the CLI without the skill wired up.
71
+ *
72
+ * Gates (all must pass to emit): text output (never pollutes `--output json`),
73
+ * not `--dry-run`, the command is in {@link SKILL_NUDGE_COMMANDS}, the opt-out
74
+ * env is unset, the active profile has an api key (un-configured callers hit an
75
+ * auth error that already points at setup), and the skill is not already
76
+ * installed. Never throws and never blocks the command — any error is swallowed.
77
+ */
78
+ export function maybeEmitSkillNudge(ctx) {
79
+ try {
80
+ if (ctx.output !== 'text')
81
+ return;
82
+ if (ctx.dryRun)
83
+ return;
84
+ if (isTruthyEnv(ctx.env[SKILL_NUDGE_OPT_OUT_ENV]))
85
+ return;
86
+ if (!SKILL_NUDGE_COMMANDS.has(ctx.commandPath))
87
+ return;
88
+ const credsPath = ctx.credentialsPath ?? defaultCredentialsPath();
89
+ const lookup = ctx.readProfileImpl ?? readProfile;
90
+ const profile = lookup(ctx.profile, { path: credsPath });
91
+ if (!profile?.apiKey)
92
+ return;
93
+ if (isVerifySkillInstalled(ctx.cwd, {
94
+ existsSync: ctx.existsSync,
95
+ readFileSync: ctx.readFileSync,
96
+ })) {
97
+ return;
98
+ }
99
+ const write = ctx.stderr ?? ((line) => process.stderr.write(`${line}\n`));
100
+ write('[warn] No TestSprite verification skill is installed in this project — your coding ' +
101
+ 'agent will not verify its changes against TestSprite. Run `testsprite setup` (or ' +
102
+ `\`testsprite agent install\`) to set it up. Silence: ${SKILL_NUDGE_OPT_OUT_ENV}=1`);
103
+ }
104
+ catch {
105
+ // A nudge must never break, delay, or alter the exit status of a real
106
+ // command. Swallow everything (missing creds file, fs races, etc.).
107
+ }
108
+ }
109
+ function isTruthyEnv(v) {
110
+ if (v === undefined)
111
+ return false;
112
+ const s = v.trim().toLowerCase();
113
+ return s !== '' && s !== '0' && s !== 'false' && s !== 'no';
114
+ }
115
+ //# sourceMappingURL=skill-nudge.js.map
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.0";
1
+ export declare const VERSION = "0.2.0";
package/dist/version.js CHANGED
@@ -1,2 +1,4 @@
1
- export const VERSION = '0.1.0';
1
+ // AUTO-GENERATED by scripts/generate-version.mjs — do not edit by hand.
2
+ // Run `npm run build` (or `npm run generate:version`) to regenerate.
3
+ export const VERSION = '0.2.0';
2
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testsprite/testsprite-cli",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Official TestSprite command-line interface",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,9 +9,12 @@
9
9
  },
10
10
  "files": [
11
11
  "dist",
12
+ "skills",
12
13
  "!dist/**/*.map"
13
14
  ],
14
15
  "scripts": {
16
+ "generate:version": "node scripts/generate-version.mjs",
17
+ "prebuild": "node scripts/generate-version.mjs",
15
18
  "build": "tsc -p tsconfig.build.json && node scripts/postbuild.mjs",
16
19
  "clean": "rm -rf dist coverage",
17
20
  "lint": "eslint .",
@@ -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
@@ -113,7 +115,7 @@ testsprite test create --plan-from plan.json --dry-run --output json
113
115
 
114
116
  ```bash
115
117
  npm install -g @testsprite/testsprite-cli
116
- testsprite init # configure + verify + install agent skill in one shot
118
+ testsprite setup # configure + verify + install agent skill in one shot
117
119
  ```
118
120
 
119
- Or step-by-step: `testsprite auth configure` → `testsprite auth whoami`.
121
+ Verify your setup anytime: `testsprite auth status`.
@@ -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