@testsprite/testsprite-cli 0.15.0 → 0.17.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 (207) hide show
  1. package/README.md +53 -141
  2. package/dist/commands/agent.d.ts +12 -4
  3. package/dist/commands/agent.js +55 -65
  4. package/dist/commands/auth.d.ts +6 -10
  5. package/dist/commands/auth.js +44 -56
  6. package/dist/commands/ci.d.ts +23 -100
  7. package/dist/commands/ci.js +297 -489
  8. package/dist/commands/completion.js +2 -1
  9. package/dist/commands/conversation.d.ts +27 -0
  10. package/dist/commands/conversation.js +702 -0
  11. package/dist/commands/doctor.d.ts +5 -1
  12. package/dist/commands/doctor.js +130 -34
  13. package/dist/commands/init.d.ts +4 -45
  14. package/dist/commands/init.js +116 -68
  15. package/dist/commands/project-env.d.ts +62 -2
  16. package/dist/commands/project-env.js +426 -53
  17. package/dist/commands/project-sign-in.d.ts +0 -48
  18. package/dist/commands/project-sign-in.js +1 -224
  19. package/dist/commands/project.d.ts +15 -186
  20. package/dist/commands/project.js +93 -921
  21. package/dist/commands/result.d.ts +10 -0
  22. package/dist/commands/result.js +215 -0
  23. package/dist/commands/schedule.d.ts +0 -29
  24. package/dist/commands/schedule.js +47 -97
  25. package/dist/commands/test.d.ts +315 -1824
  26. package/dist/commands/test.js +1962 -13733
  27. package/dist/commands/testlist.d.ts +128 -5
  28. package/dist/commands/testlist.js +269 -329
  29. package/dist/commands/tunnel.d.ts +2 -2
  30. package/dist/commands/tunnel.js +43 -41
  31. package/dist/commands/usage.d.ts +12 -45
  32. package/dist/commands/usage.js +51 -131
  33. package/dist/index.js +189 -108
  34. package/dist/lib/agent-detect.js +9 -5
  35. package/dist/lib/agent-targets.d.ts +21 -2
  36. package/dist/lib/agent-targets.js +88 -11
  37. package/dist/lib/args.d.ts +13 -0
  38. package/dist/lib/args.js +49 -0
  39. package/dist/lib/basic-auth.d.ts +3 -0
  40. package/dist/lib/basic-auth.js +15 -0
  41. package/dist/lib/billing-refusal.js +4 -3
  42. package/dist/lib/ci-linkage.d.ts +4 -82
  43. package/dist/lib/ci-linkage.js +4 -157
  44. package/dist/lib/ci-run.js +1 -1
  45. package/dist/lib/client-factory.d.ts +10 -2
  46. package/dist/lib/client-factory.js +38 -26
  47. package/dist/lib/commit-signal.d.ts +65 -0
  48. package/dist/lib/commit-signal.js +305 -0
  49. package/dist/lib/concurrency-limiter.d.ts +6 -0
  50. package/dist/lib/concurrency-limiter.js +29 -0
  51. package/dist/lib/config.js +10 -5
  52. package/dist/lib/conflict-reason.d.ts +31 -4
  53. package/dist/lib/conflict-reason.js +38 -4
  54. package/dist/lib/conversation/answers.d.ts +9 -0
  55. package/dist/lib/conversation/answers.js +49 -0
  56. package/dist/lib/conversation/api.d.ts +71 -0
  57. package/dist/lib/conversation/api.js +150 -0
  58. package/dist/lib/conversation/change.d.ts +31 -0
  59. package/dist/lib/conversation/change.js +124 -0
  60. package/dist/lib/conversation/context.d.ts +19 -0
  61. package/dist/lib/conversation/context.js +70 -0
  62. package/dist/lib/conversation/environment.d.ts +15 -0
  63. package/dist/lib/conversation/environment.js +33 -0
  64. package/dist/lib/conversation/follow.d.ts +24 -0
  65. package/dist/lib/conversation/follow.js +42 -0
  66. package/dist/lib/conversation/render.d.ts +33 -0
  67. package/dist/lib/conversation/render.js +315 -0
  68. package/dist/lib/conversation/title.d.ts +2 -0
  69. package/dist/lib/conversation/title.js +18 -0
  70. package/dist/lib/conversation/types.d.ts +156 -0
  71. package/dist/lib/conversation/types.js +6 -0
  72. package/dist/lib/credentials.js +67 -11
  73. package/dist/lib/cron.d.ts +1 -1
  74. package/dist/lib/cron.js +2 -2
  75. package/dist/lib/dispatch-stop.d.ts +20 -0
  76. package/dist/lib/dispatch-stop.js +30 -0
  77. package/dist/lib/download.d.ts +71 -0
  78. package/dist/lib/download.js +274 -0
  79. package/dist/lib/dry-run/fetch.d.ts +10 -0
  80. package/dist/lib/dry-run/fetch.js +20 -0
  81. package/dist/lib/dry-run/samples.d.ts +6 -34
  82. package/dist/lib/dry-run/samples.js +389 -751
  83. package/dist/lib/environment-tunnel.d.ts +16 -26
  84. package/dist/lib/environment-tunnel.js +161 -157
  85. package/dist/lib/errors.d.ts +20 -4
  86. package/dist/lib/errors.js +36 -16
  87. package/dist/lib/facade.d.ts +7 -29
  88. package/dist/lib/facade.js +7 -36
  89. package/dist/lib/failing-fe-resolver.d.ts +13 -58
  90. package/dist/lib/failing-fe-resolver.js +47 -132
  91. package/dist/lib/first-suite-hint.d.ts +16 -22
  92. package/dist/lib/first-suite-hint.js +38 -47
  93. package/dist/lib/gh-output.d.ts +76 -21
  94. package/dist/lib/gh-output.js +171 -90
  95. package/dist/lib/git-utils.d.ts +56 -0
  96. package/dist/lib/git-utils.js +212 -0
  97. package/dist/lib/github-context.d.ts +2 -0
  98. package/dist/lib/github-context.js +40 -8
  99. package/dist/lib/history-retention.d.ts +6 -2
  100. package/dist/lib/history-retention.js +10 -7
  101. package/dist/lib/http.d.ts +58 -134
  102. package/dist/lib/http.js +352 -271
  103. package/dist/lib/interrupt.d.ts +14 -8
  104. package/dist/lib/interrupt.js +28 -10
  105. package/dist/lib/junit-report.d.ts +60 -4
  106. package/dist/lib/junit-report.js +209 -32
  107. package/dist/lib/local-target.d.ts +3 -3
  108. package/dist/lib/local-target.js +3 -3
  109. package/dist/lib/output.d.ts +0 -29
  110. package/dist/lib/output.js +10 -33
  111. package/dist/lib/pagination.d.ts +2 -5
  112. package/dist/lib/pagination.js +2 -5
  113. package/dist/lib/presigned-url.d.ts +22 -0
  114. package/dist/lib/presigned-url.js +90 -0
  115. package/dist/lib/prompt.js +36 -2
  116. package/dist/lib/proxy.js +2 -1
  117. package/dist/lib/redact.d.ts +2 -2
  118. package/dist/lib/redact.js +3 -4
  119. package/dist/lib/removed-commands.d.ts +18 -0
  120. package/dist/lib/removed-commands.js +154 -0
  121. package/dist/lib/render-error.d.ts +31 -6
  122. package/dist/lib/render-error.js +88 -25
  123. package/dist/lib/response-schemas.d.ts +38 -30
  124. package/dist/lib/response-schemas.js +210 -207
  125. package/dist/lib/result/api.d.ts +24 -0
  126. package/dist/lib/result/api.js +28 -0
  127. package/dist/lib/result/evidence.d.ts +71 -0
  128. package/dist/lib/result/evidence.js +420 -0
  129. package/dist/lib/result/render.d.ts +20 -0
  130. package/dist/lib/result/render.js +194 -0
  131. package/dist/lib/result/types.d.ts +122 -0
  132. package/dist/lib/result/types.js +19 -0
  133. package/dist/lib/run-output.d.ts +275 -0
  134. package/dist/lib/run-output.js +227 -0
  135. package/dist/lib/run-render.d.ts +101 -0
  136. package/dist/lib/run-render.js +183 -0
  137. package/dist/lib/run-wait.d.ts +192 -0
  138. package/dist/lib/run-wait.js +452 -0
  139. package/dist/lib/runs.types.d.ts +134 -367
  140. package/dist/lib/runs.types.js +0 -14
  141. package/dist/lib/secret-file.d.ts +1 -1
  142. package/dist/lib/secret-file.js +11 -2
  143. package/dist/lib/skill-nudge.d.ts +7 -27
  144. package/dist/lib/skill-nudge.js +9 -37
  145. package/dist/lib/target-path.d.ts +15 -0
  146. package/dist/lib/target-path.js +35 -0
  147. package/dist/lib/target-url-advisory.d.ts +19 -0
  148. package/dist/lib/target-url-advisory.js +31 -0
  149. package/dist/lib/target-url-preflight.d.ts +9 -0
  150. package/dist/lib/target-url-preflight.js +214 -106
  151. package/dist/lib/target-url.d.ts +1 -1
  152. package/dist/lib/target-url.js +6 -16
  153. package/dist/lib/telemetry.d.ts +32 -12
  154. package/dist/lib/telemetry.js +39 -8
  155. package/dist/lib/terminal-text.d.ts +41 -0
  156. package/dist/lib/terminal-text.js +127 -0
  157. package/dist/lib/testlist.types.d.ts +16 -8
  158. package/dist/lib/testlist.types.js +1 -1
  159. package/dist/lib/text-equality.d.ts +2 -0
  160. package/dist/lib/text-equality.js +5 -0
  161. package/dist/lib/text-file.d.ts +16 -0
  162. package/dist/lib/text-file.js +41 -0
  163. package/dist/lib/text-table.d.ts +46 -0
  164. package/dist/lib/text-table.js +72 -4
  165. package/dist/lib/ticker.d.ts +9 -2
  166. package/dist/lib/ticker.js +16 -3
  167. package/dist/lib/transport-failure.d.ts +22 -0
  168. package/dist/lib/transport-failure.js +126 -0
  169. package/dist/lib/tunnel-session.d.ts +7 -1
  170. package/dist/lib/tunnel-session.js +22 -9
  171. package/dist/lib/update-check.js +3 -2
  172. package/dist/lib/url-template.d.ts +43 -0
  173. package/dist/lib/url-template.js +151 -0
  174. package/dist/lib/validate.d.ts +0 -64
  175. package/dist/lib/validate.js +2 -131
  176. package/dist/lib/version-notice.js +4 -3
  177. package/dist/lib/wait-exit.d.ts +37 -2
  178. package/dist/lib/wait-exit.js +88 -30
  179. package/dist/lib/workspace-status.js +10 -2
  180. package/dist/version.d.ts +1 -1
  181. package/dist/version.js +1 -1
  182. package/package.json +3 -4
  183. package/skills/testsprite-ci.skill.md +48 -18
  184. package/skills/testsprite-onboard.skill.md +66 -151
  185. package/skills/testsprite-verify.codex.md +54 -56
  186. package/skills/testsprite-verify.skill.md +194 -358
  187. package/dist/lib/browser.d.ts +0 -6
  188. package/dist/lib/browser.js +0 -54
  189. package/dist/lib/bundle.d.ts +0 -234
  190. package/dist/lib/bundle.js +0 -781
  191. package/dist/lib/deprecate.d.ts +0 -10
  192. package/dist/lib/deprecate.js +0 -13
  193. package/dist/lib/flaky.d.ts +0 -91
  194. package/dist/lib/flaky.js +0 -71
  195. package/dist/lib/plan-poll.d.ts +0 -171
  196. package/dist/lib/plan-poll.js +0 -441
  197. package/dist/lib/plans.types.d.ts +0 -130
  198. package/dist/lib/plans.types.js +0 -31
  199. package/dist/lib/poll.d.ts +0 -100
  200. package/dist/lib/poll.js +0 -290
  201. package/dist/lib/rate-throttle.d.ts +0 -49
  202. package/dist/lib/rate-throttle.js +0 -75
  203. package/dist/lib/run-progress.d.ts +0 -41
  204. package/dist/lib/run-progress.js +0 -56
  205. package/dist/lib/v3-advisory.d.ts +0 -55
  206. package/dist/lib/v3-advisory.js +0 -74
  207. package/schemas/plan.schema.json +0 -61
package/README.md CHANGED
@@ -24,7 +24,7 @@ AI ships code in minutes — verifying it hasn't. `testsprite` opens your live a
24
24
 
25
25
  <p>
26
26
  <a href="https://www.testsprite.com"><img src="https://img.shields.io/badge/testsprite.com-19C379?style=for-the-badge&logoColor=white" alt="Website"></a>
27
- <a href="https://www.testsprite.com/docs"><img src="https://img.shields.io/badge/Docs-0A0A0A?style=for-the-badge" alt="Docs"></a>
27
+ <a href="https://docs.testsprite.com/cli/getting-started/overview"><img src="https://img.shields.io/badge/Docs-0A0A0A?style=for-the-badge" alt="Docs"></a>
28
28
  <a href="https://x.com/Test_Sprite"><img src="https://img.shields.io/badge/Follow%20on%20X-000000?style=for-the-badge&logo=x&logoColor=white" alt="Follow on X"></a>
29
29
  <a href="https://www.linkedin.com/company/testsprite"><img src="https://img.shields.io/badge/LinkedIn-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white" alt="LinkedIn"></a>
30
30
  <a href="https://discord.gg/GXWFjCe4an"><img src="https://img.shields.io/badge/Join%20our%20Discord-5865F2?style=for-the-badge&logo=discord&logoColor=white" alt="Join our Discord"></a>
@@ -44,7 +44,7 @@ AI ships code in minutes — verifying it hasn't. `testsprite` opens your live a
44
44
 
45
45
  [TestSprite](https://www.testsprite.com) is the AI testing platform 100,000+ teams use to test their software, frontend and backend — in the cloud, against the live product, not mocks. This repo is its official CLI.
46
46
 
47
- It puts that platform in your coding agent's hands: the agent verifies every behavior it ships, and what broke comes back as **one self-consistent bundle** it can act on — no dashboard scraping. Humans drive the same surface from a terminal or CI.
47
+ It puts that platform in your coding agent's hands: the agent verifies every behavior it ships, and what broke comes back as **one result** — the failed step, its cause and a fix — it can act on, with no dashboard scraping. Humans drive the same surface from a terminal or CI.
48
48
 
49
49
  ## ⭐️ Star the Repository
50
50
 
@@ -54,179 +54,91 @@ If you find `testsprite` useful, a GitHub Star ⭐️ would be greatly appreciat
54
54
 
55
55
  ## Quickstart
56
56
 
57
- Requires **Node.js 20.19+**, **22.13+**, or **24+**. (No global install? `npx @testsprite/testsprite-cli` works too.)
57
+ You need Node.js 20.19+ on the 20.x line, 22.13+ on 22.x, or 24 or later. [Using 0.16? Read its command reference.](https://github.com/TestSprite/testsprite-cli/blob/v0.16.0/DOCUMENTATION.md)
58
+
59
+ From your app's repository, install the CLI and run setup. It prompts for your [workspace API key](https://www.testsprite.com/dashboard-v3/settings/apikey) and installs the skills for the coding agents it detects.
58
60
 
59
61
  ```bash
60
62
  npm install -g @testsprite/testsprite-cli
63
+ testsprite --version
61
64
  testsprite setup
65
+ testsprite auth status
62
66
  ```
63
67
 
64
- `testsprite setup` prompts for your [API key](https://www.testsprite.com/dashboard/settings/apikey), verifies it, and installs the verification-loop skill for the coding agents this project uses — one command, so your agent is wired to verify its own work.
65
-
66
- **Which agent it installs for.** Each of the eight supported targets — `claude`, `cursor`, `cline`, `windsurf`, `antigravity`, `kiro`, `copilot`, `codex` — lands its skill in a different place, so `setup` works out which you use: the agent calling it, if it identifies itself, together with every agent whose config is already in the project. It installs for all of them and prints what it found — in a terminal it shows you that list first, so you can accept it or narrow it before anything is written. If nothing identifies an agent, it installs for `claude` and says so — that is the one case where you want `--agent <target>` to name one yourself. Check the result any time with `testsprite agent status`.
67
-
68
- Non-interactive (CI / onboarding scripts):
68
+ **Choose your project and target.** Run `testsprite project list` to find an existing project. For a new frontend project, create it and add the URL where your app is running. Replace the URL below with yours and set `PROJECT_ID` to the ID printed by `project create`.
69
69
 
70
70
  ```bash
71
- TESTSPRITE_API_KEY=sk-... testsprite setup --from-env --yes
71
+ testsprite project create --type frontend --name "Checkout"
72
+ PROJECT_ID=your-project-id
73
+ testsprite project env create "$PROJECT_ID" --name staging --url https://staging.example.com
72
74
  ```
73
75
 
74
- > **Pointing a coding agent (Claude Code, Cursor, Codex, Cline, …) at TestSprite?** Have it run `testsprite setup` first — that installs the verification skill, so the agent knows how to create, run, and triage tests on its own (instead of guessing from this README). `setup` reports which agents it installed for; add `--agent <target>` if that list is not the one you wanted. New here? Start with the **[getting-started overview](https://docs.testsprite.com/cli/getting-started/overview)**.
75
-
76
- > **Privacy note:** interactive runs check the npm registry at most once per 24 h to offer a "new version available" notice — package name only, never your key or data; `TESTSPRITE_NO_UPDATE_NOTIFIER=1` disables it. The backend also advertises its minimum supported CLI version — a below-floor CLI prints a one-line upgrade advisory on stderr, and a too-old client may be rejected with exit 14 (`CLIENT_TOO_OLD`). Details in [DOCUMENTATION.md → Update notice](./DOCUMENTATION.md#update-notice).
77
-
78
- From there, the loop runs on its own — an example session, typed by the coding agent:
76
+ **Get your first test.** Ask the project's agent to propose coverage. If it asks a question in a text message, answer with `testsprite reply "your answer"`. Review the proposed steps in the terminal and apply the plan when they match what you want to verify. For a backend project, attach the API specification with `--file ./openapi.yaml`.
79
77
 
80
78
  ```bash
81
- # 1 — describe the behavior you want to guarantee, run it, wait
82
- testsprite test create --project proj_8f0f6 --type frontend \
83
- --plan-from ./checkout-flow.plan.json --run --wait --output json
84
- # → exits 1: the run failed
85
-
86
- # 2 — pull ONE self-consistent failure bundle
87
- testsprite test failure get test_3a9f21c7 --out ./.testsprite/failure
88
-
89
- # 3 — the agent reads the bundle, fixes the code, then replays
90
- testsprite test rerun test_3a9f21c7 --wait --output json
91
- # → exits 0: passed. The test now lives in your durable suite.
79
+ testsprite plan "Verify that a guest can place an order with a test card" --project "$PROJECT_ID" --steps
92
80
  ```
93
81
 
94
- `./checkout-flow.plan.json` (the `--plan-from` argument above) is a JSON file describing the test in plain language — no browser code required. This is the exact, byte-identical output of `testsprite test create --plan-template` (also embedded verbatim in `test create --help`):
95
-
96
- ```json
97
- {
98
- "$schema": "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.4.0/schemas/plan.schema.json",
99
- "projectId": "prj_abc123",
100
- "type": "frontend",
101
- "name": "Login rejects an empty password",
102
- "planSteps": [
103
- {
104
- "type": "action",
105
- "description": "Navigate to /login and submit the form with an empty password"
106
- },
107
- {
108
- "type": "assertion",
109
- "description": "Verify an inline error says the password is required"
110
- }
111
- ]
112
- }
82
+ ```bash
83
+ testsprite apply
84
+ testsprite test list --project "$PROJECT_ID"
113
85
  ```
114
86
 
115
- Get this exact skeleton without hand-copying it (and without the risk of it drifting from your installed version — see below): `testsprite test create --plan-template`. Full field reference (including the `{{...}}`-placeholder caveat, size caps, and the `$schema` hook for live editor validation): [Plan file format](./DOCUMENTATION.md#plan-file-format).
116
-
117
- > The `$schema` URL above is pinned to the CLI version that generated this doc (`v0.4.0`) — `--plan-template`'s live output always pins to **your installed version** instead, which is what actually resolves. If you're reading this on a later release, run the command yourself rather than trusting this snippet verbatim.
118
-
119
- **Don't want to write the first tests yourself?** For a deployed target, ask TestSprite to propose them. Local projects use the authored-plan flow below. `testsprite test plan generate --project <id>` explores your app (or reads the API spec you uploaded with `project docs upload`), drafts test cases, and stages them for review — nothing is written to your disk. You read the printed table and keep what you want:
87
+ **Run and inspect.** A project run waits for the suite when you pass `--wait`. Exit 0 means it passed. On exit 1, look for a failed or blocked row in `results[]` and copy its `resultId` to inspect the error and available evidence. If no row failed, check `runFailures` for an execution-level error such as cancellation. Without `--output json`, each run also prints a `Dashboard:` link that opens it in the Portal.
120
88
 
121
89
  ```bash
122
- testsprite test plan generate --project proj_8f0f6 # stages proposals for review
123
- testsprite test plan accept --project proj_8f0f6 # → real tests
124
- testsprite test plan accept --project proj_8f0f6 --only prop_2 prop_5 # or just these
90
+ testsprite run --project "$PROJECT_ID" --wait --output json
125
91
  ```
126
92
 
127
- It only runs what the project is still missing, so a second call picks up where the first left off. Generation spends workspace credits per stage that actually runs (the result line reports the spend), and a PRD uploaded with `project docs upload --role prd` bills 0.5 credits for its embedding — an API spec is free. Full walkthrough, including what happens on Ctrl-C and every precondition error: [Generate commands](./DOCUMENTATION.md#generate-commands).
93
+ ```bash
94
+ RESULT_ID=your-result-id
95
+ testsprite result get "$RESULT_ID" --out ".testsprite/results/$RESULT_ID"
96
+ ```
128
97
 
129
- Prefer to configure each step by hand (or learn the surface offline with `--dry-run` first)? See [Manual setup](./DOCUMENTATION.md#manual-setup) and [Install & verify](./DOCUMENTATION.md#install--verify).
98
+ After deploying a fix, run the affected test again with `testsprite run "$TEST_ID" --wait`, using its ID from `test list`. To resume waiting for a run you already started, use its **run ID** with `testsprite run wait "$RUN_ID"`. The [scripting example](./DOCUMENTATION.md#output--scripting) shows how to extract both IDs and preserve the verdict in CI.
130
99
 
131
100
  ## Testing an environment on your machine
132
101
 
133
- Frontend tests can reach your running app through a TestSprite tunnel, including on the Free plan (ordinary run credits apply).
134
- Use an API key with `run:tunnel`; the CLI names the missing scope if the key cannot open a tunnel. Existing keys receive this scope on backend v0.18.0 or later unless deliberately narrowed.
102
+ Start your frontend app on port 3000. To run the project's saved tests against the app on this machine, supply the port. The CLI opens a tunnel and waits for the cloud runner.
135
103
 
136
104
  ```bash
137
- testsprite project create --type frontend --name "My local app" --local 3000
138
- testsprite test create --plan-from ./checkout.plan.json --project <project-id>
139
- testsprite test run <test-id> # the saved loopback URL opens a tunnel and waits
140
- testsprite test run <id> <id> --max-concurrency 5
141
- testsprite test run --all --project <project-id>
142
- # Or keep one tunnel open in terminal A (no port argument)
143
- testsprite tunnel start --ttl 3600
144
- # Terminal B: borrow the clientId printed above; keep terminal A running
145
- testsprite test run <test-id> --tunnel-client <client-uuid>
146
- testsprite tunnel list
147
- testsprite tunnel stop <client-uuid>
148
- # Stop every live tunnel on this account only when you intend to revoke them all
149
- testsprite tunnel stop --all --confirm
105
+ testsprite run --project "$PROJECT_ID" --local 3000
150
106
  ```
151
107
 
152
- Run several local frontend tests in one invocation to share one tunnel binding. The batch runs up to 5 tests at once by default; `--max-concurrency` accepts 1–10. `--all --local` skips backend tests. An owned batch cancels unfinished runs on Ctrl-C or tunnel loss; JSON output lists every requested test in input order, including tests that did not start. The minted client id is printed before the tunnel connects.
153
- Hit the tunnel limit? Run `testsprite tunnel list`, then `testsprite tunnel stop <client-uuid>` for an unused binding, or `testsprite tunnel stop --all --confirm` to revoke them all. An older server without listing returns exit 4; a key without `run:tunnel` returns exit 3.
154
- A second `tunnel start` or process using the same credential takes over, and the first exits **10**.
155
- An environment is one origin (scheme, host and port) plus its sign-in configuration. Frontend runs automatically open a tunnel for a saved `localhost`, `127.0.0.1` or `[::1]` URL: `test run`, `test rerun`, `test create --run`, `test create-batch --run` and `testlist run` use this behavior. `--env <name>` selects the environment; omit it for the project default. `--no-wait` disables automatic tunnels; drop it to run through one. If environment reads are unavailable, the command keeps the previous server behavior. Several fresh-run IDs require a tunnel; public targets retain the exit-5 refusal. A named public environment used against a local origin prints a sign-in advisory on stderr. Reruns and test-list runs share one timeout including capacity waits and require the server to confirm tunnel support; an older server triggers a cancellation attempt and a clear error.
156
-
157
- `--local <port>` remains a shorthand and defaults new project/environment URLs to `http://localhost:<port>`. On a test run it preserves the host of a selected loopback environment, or the one host agreed by saved non-temporary loopback environments on that port; otherwise it uses `localhost`. If environment reads fail, it retains the legacy `127.0.0.1` host. Saved URLs retain their exact spelling, and aliases are not merged. `--local-host` remains accepted but is deprecated and hidden from project/environment help; prefer `--url http://127.0.0.1:<port>` or `--url http://[::1]:<port>` when the host matters. Dev servers can take a minute per page through a tunnel; test a built server with `npm run build` and your framework's preview/start command for heavy apps.
158
- The control plane is WebSocket over TLS (`wss://control.tun.testsprite.com/ws`). The data plane, which carries the tunnel secret and proxied traffic, uses TLS at `data.tun.testsprite.com:443` and verifies the certificate with Node's default trust store: its bundled Mozilla roots, plus certificates supplied through `NODE_EXTRA_CA_CERTS` and the system CAs when Node is started with `--use-system-ca`. Node 20 is supported without losing `NODE_EXTRA_CA_CERTS`. Verification cannot be disabled, and the CLI never falls back from TLS to plaintext. On a network that re-signs TLS, export your organisation's root CA to a PEM file and set `NODE_EXTRA_CA_CERTS=/path/to/ca.pem` before running `testsprite`. Plaintext connects and TLS handshakes each time out after 10 seconds. The first failed attempt starts a **60-second** retry episode; writing `TunnelHello` is not enough to reset it. The episode ends only after the first inbound tunnel stream or after the socket remains open for 5 seconds following the hello. A real deadline timer stays armed across retries and destroys an in-flight socket when it expires. After that, an owned `test run --local` run is cancelled and refunded and the command exits **10**; `tunnel start` exits **10**. If a self-hosted or older TestSprite server does not advertise a TLS endpoint, the CLI prints a one-time warning and uses legacy plaintext port **7400** under the same timeout and retry rules. `tunnel start` prints `transport: tls` or `transport: plaintext`.
159
- An owned tunnel's timeout or Ctrl-C cancels unfinished runs by default. A borrowed run still detaches without cancellation on Ctrl-C/SIGTERM because its owner keeps the tunnel alive; if that owner disappears while a run is active, the borrower cancels its own run and reports `cancelled`, `already finished`, or `skipped`. A run cancelled before it finishes is refunded. `--no-cancel-on-interrupt` also skips this owner-gone cancellation. Keep the early stderr run-id receipts (`Run <runId>` for one test, `[i/N] <testId> → run <runId>` for a batch) and read the reported runs before re-running.
160
- Local projects skip exploration/plan generation; author plans with `test create --plan-from`. Portal runs are blocked for free until you set a public project URL.
161
- See [the full local-testing reference](./DOCUMENTATION.md#local-frontend-testing-and-tunnels) for flags, login, billing/refunds, timeouts, and retargeting.
108
+ For a local-only project, you can save the port as its first environment with `testsprite project env create "$PROJECT_ID" --name local --local 3000`. Give the project's agent a Git diff or a spec so it can propose tests without browsing localhost. Review and apply the test plan, then run with `--env local`. An ordinary Ctrl-C detaches a public run. With a tunnel this command opened, Ctrl-C cancels unfinished work by default and closes the tunnel. [Local frontend testing and tunnels](./DOCUMENTATION.md#local-frontend-testing-and-tunnels)
162
109
 
163
110
  ## Commands
164
111
 
165
- | Group | Command | What it does |
166
- | -------------- | --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
167
- | **Setup** | `setup` | **Start here** — one command: configure your API key, verify it, and install the agent verification skill |
168
- | | `doctor` | Environment diagnostic — CLI/Node versions, profile, endpoint, credentials, connectivity, agent skill; exits non-zero on failure |
169
- | **Auth** | `auth status` | Resolve the active profile to its user, key, env, and scopes |
170
- | | `auth remove` | Remove the active profile from the credentials file |
171
- | | `usage` (alias `credits`) | Account pre-flight: identity, plus credit balance / plan info when the backend supplies them |
172
- | **Read** | `project list` / `project get` | List projects / fetch one by id, including the default environment and environment count when the server reports them |
173
- | | `test list` / `test get` | List tests under a project / fetch one by id; `test list --env <name>` selects frontend status and the ENV column names its source |
174
- | | `test code get` | Print (or write) the generated test source |
175
- | | `test steps` | List the latest run's steps with screenshot / DOM pointers |
176
- | | `test result` | Latest result; `--history` lists a test's prior runs (ENV column; `--env <name>` filters by environment) |
177
- | | `test failure get` | The agent entry point: one self-contained latest-failure bundle |
178
- | | `test failure summary` | One-screen triage card (no media download) |
179
- | | `test diff` | Compare two runs — verdict, failure kind, per-step status flips, code-version drift |
180
- | **Write** | `test scaffold` / `test lint` | Author plans locally: emit a schema-correct starter, validate plan files offline — no network, no credentials |
181
- | | `test create` / `test create-batch` | Create a test (or bulk-create from a plan file); `--step-timeout <ms>` sets a per-test timeout; dependency flags wire BE metadata |
182
- | | `test update` / `test delete` / `test delete-batch` | Edit metadata, set/clear the step timeout (`--step-timeout` / `--clear-step-timeout`), or permanently delete (`--confirm` required) |
183
- | | `test code put` | Replace generated code (etag-guarded) |
184
- | | `test plan put` | Replace a frontend test's plan-steps |
185
- | | `project create` / `project update` / `project delete` | Manage projects; `--test-id-attributes <list>` registers the app's own test-hook attributes (priority order) for exported locators, `--clear-test-id-attributes` reverts; `delete` removes a project and everything under it (`--confirm` required, no restore window) |
186
- | | `project credential` / `project auto-auth` | Configure backend-test auth: a static injected credential, or auto-refresh login (Pro) |
187
- | | `project env list` / `get` / `create` / `update` / `delete` / `set-default` | Manage a project's named URL + login bundles. `get` shows safe login details and variables; `create` / `update` accept repeatable `--var KEY=VALUE` (plain text — not for secrets, use `--username`/`--password`), and `update --clear-credentials` disables account login. Use `--url http://localhost:<port>` or `--local <port>` for an app on this machine; runs open its tunnel automatically. `delete` refuses the default environment. |
188
- | | `project sign-in get` / `set` | Inspect or change an environment's app sign-in mode; choose OTP with `project env create --sign-in otp`. SSO selection requires the per-account manual-login feature flag; capture the session in the Portal. |
189
- | **Generate** | `test plan generate` | Ask TestSprite to propose test cases for a project — proposals are staged server-side for review, never written to disk; only the stages the project is missing actually run |
190
- | | `test plan accept` | Turn staged proposals into real tests — all of them, or a subset with `--only` |
191
- | | `project docs upload` | Upload an API spec or PRD as a project source, so generation has something to read |
192
- | **Run** | `test run` | Trigger a fresh run; saved loopback environments open a tunnel and wait automatically; `--wait` blocks until terminal; `--all --project <id>` runs all tests in a project in wave order `--env <name>` runs against a named environment. |
193
- | | `test rerun` | Replay one/many tests (FE verbatim; BE with deps); billed as a run (0.5 credits FE / 0.2 BE); `--all --project <id>` reruns all tests `--env <name>` replays against a named environment; loopback URLs open a tunnel automatically when the server supports it. |
194
- | | `test flaky` | Replay a test several times (auto-heal off) and report a stability score |
195
- | | `test wait` | Block on one or more `runId`s until terminal |
196
- | | `test cancel` | Cancel one or more in-flight runs (Ctrl-C during `--wait` only detaches, `cancel` is the real stop — except a run with an owned tunnel, which Ctrl-C cancels by default) |
197
- | | `test artifact get` | Download the failure bundle for a specific `runId` |
198
- | **Test lists** | `testlist list` / `testlist get` | Inspect saved test lists — named, cross-project collections with per-project environment pins (V3-only) |
199
- | | `testlist create` / `update` / `add` / `remove` / `delete` | Manage a list and its cases; `--project-env <id>:<env>` pins environments; `delete` requires `--confirm` |
200
- | | `testlist run` | Run every case (or a `--case` subset) through its pinned environment; loopback environments open a tunnel automatically; `--wait` polls all runs, `--report junit` writes a CI sidecar |
201
- | **Schedule** | `schedule list` / `schedule get` | List schedules visible to the key / fetch one by id, including a project schedule's pinned or inherited environment (status is `ENABLED`, `PAUSED`, or `AUTO_PAUSED` after repeated failures) |
202
- | | `schedule create` | Run a project or test list on a 5-field cron; `--env <name>` pins a project schedule, while omission inherits the live default; states frequency and estimated cost |
203
- | | `schedule update` | Retime or rename a schedule, change recipients, pin a project schedule with `--env <name>`, or `--pause` / `--resume` it |
204
- | | `schedule delete` | Remove a schedule and its run history, stopping future triggers (`--confirm` required, no restore window) |
205
- | | `schedule run list` | A schedule's past runs, with per-run pass / fail / blocked counts |
206
- | **CI** | `ci init github` | Write a GitHub Actions PR gate that runs `ci run` against each pull request's preview deployment — one placeholder step to fill in: your platform deploys every PR (`on: deployment_status`) or the workflow deploys |
207
- | | `ci run` | The CI gate in one command: every project test (or `--filter`) against `--target-url`, signed in as `--env`, in a temporary `github-pr-<N>` environment, one execution; waits and exits with the verdict. Job summary = the execution report (the GitHub App comment); `--summary-file`, `--report junit`, step outputs |
208
- | **Agent** | `agent install` / `agent list` / `agent status` | Add, list, or health-check coding-agent skills (pure-local): `claude`, `codex`, `cursor`, `cline`, `antigravity`, `kiro`, `windsurf`, `copilot` |
209
-
210
- > The earlier command names — `init`, `auth configure`, `auth whoami`, `auth logout` — still work as hidden, deprecated aliases (each prints a one-line notice pointing at the new name), so existing scripts keep running. `auth configure` now runs the full `setup` (it also installs the skill).
211
-
212
- 📚 **Full reference — every command, flag, and example:** [DOCUMENTATION.md](./DOCUMENTATION.md), including [configuration & profiles](./DOCUMENTATION.md#configuration), [scripting](./DOCUMENTATION.md#output--scripting), and [exit codes](./DOCUMENTATION.md#exit-codes).
112
+ | Task | Command |
113
+ | ------------------------------------------------ | -------------------------------------------------------------------------------------- |
114
+ | Check credentials or install coding-agent skills | `auth status`, `setup`, `agent status` |
115
+ | Manage a project and its targets | `project list`, `project create`, `project env` |
116
+ | Propose tests, review them and save them | `plan`, `status`, `reply`, `reject`, `apply` |
117
+ | Find the ID or steps of a saved test | `test list --project <id>`, `test get <test-id>` |
118
+ | Launch a project, named tests or a saved list | `run --project <id>`, `run <test-id...>`, `run --testlist <list-id>` |
119
+ | Follow or cancel an execution | `run wait <run-id...>`, `run cancel <run-id...>` |
120
+ | Read results and download evidence | `result list --run <run-id>`, `result list --test <test-id>`, `result get <result-id>` |
121
+ | Automate scheduled tests or a pull-request gate | `schedule`, `ci init github`, `ci run` |
122
+
123
+ For test lists, tunnel management, usage, diagnostics, profiles and exit codes, see the [command reference](./DOCUMENTATION.md#command-reference). To migrate shell scripts or previously installed agent skills from 0.16, see [Upgrading from 0.16](./DOCUMENTATION.md#upgrading-from-016).
213
124
 
214
125
  ## Why a CLI for coding agents?
215
126
 
216
127
  - 🧪 **Tests like a real user.** Runs against a live browser or API in the cloud — real clicks, real navigation, real assertions. Not a mock.
217
- - 🤖 **Agent-shaped output.** `test failure get` returns **one bundle** — the failing step, its neighbors, screenshots, DOM snapshots, the test source, a root-cause hypothesis, and a recommended fix target — all sharing a single `snapshotId`. The CLI _refuses_ to stitch data from two different runs, so an agent never reasons over a frankenstein context.
218
- - ♻️ **A loop, not a one-shot.** `create → run → failure get → fix → rerun` — every pass is banked, not thrown away.
219
- - 📐 **Scriptable & deterministic.** Stable `--output json` contract, predictable [exit codes](./DOCUMENTATION.md#exit-codes), and a `--dry-run` that exercises the full code path offline with canned data.
220
- - 🚦 **CI-native.** `testsprite ci init github` writes a PR gate; `testsprite ci run --env <name> --target-url "$PREVIEW_URL"` tests each pull request's preview deployment as one execution and exits with the verdict. The job summary is the execution report — the same content as the GitHub App's PR comment — plus `::error::` annotations on the checks tab, step outputs, `--summary-file` for a machine summary and `--report junit` for a JUnit sidecar. In any other CI, `testsprite ci run --project <id> --env <name> --target-url <url>` still runs the suite as one execution and makes the exit code the verdict — the pull-request context, draft skip and job summary are GitHub Actions only. [Details →](./DOCUMENTATION.md#continuous-integration)
128
+ - 🤖 **Agent-shaped output.** `run` names the run (`runId`) and each test's result in it (`resultId`). `result get <result-id>` returns that one result — the verdict, the error, its cause and fix, the failed step with its screenshot, a backend test's traceback and output, and every step — and `--out <dir>` downloads its video and each step's screenshot and page. The agent reads the run it just started, never an older one.
129
+ - **Whole-run results.** Every selector and `run wait` use the same JSON: `runs[]` describes executions, `results[]` lists individual results, and `summary` counts outcomes when waiting. A complete run can fail. Only a timeout or interruption that leaves work unfinished adds `partial: true`. A cancelled execution fails even if its existing results passed. Read detailed evidence with `result get <result-id>`.
130
+ - ♻️ **A loop, not a one-shot.** `plan → apply → run → result get → fix → run` — every pass is banked, not thrown away.
131
+ - 📐 **Scriptable & deterministic.** Stable `--output json` contract, predictable [exit codes](./DOCUMENTATION.md#exit-codes), and a `--dry-run` for previewing commands. A credentialed run preview can read environment metadata to determine whether it would open a tunnel.
132
+ - 🚦 **CI-native.** `testsprite ci init github` writes a PR gate; `testsprite ci run --project "$PROJECT_ID" --env <name> --target-url "$PREVIEW_URL"` tests each pull request's preview deployment as one run and exits with the verdict. The job summary is the execution report — the same content as the GitHub App's PR comment — plus `::error::` annotations on the checks tab, step outputs, `--summary-file` for a machine summary and `--report junit` for a JUnit sidecar. In any other CI, `testsprite ci run --project <id> --env <name> --target-url <url>` still runs the suite as one run and makes the exit code the verdict — the pull-request context, draft skip and job summary are GitHub Actions only. [Details →](./DOCUMENTATION.md#continuous-integration)
221
133
  - 🔌 **One command to onboard your agent.** `testsprite setup` drops ready-made skill files into your repo — for the agents it detects you using — so your coding agent knows how to drive the loop on its own.
222
134
 
223
135
  ## How it works
224
136
 
225
137
  Every time your agent changes code, it asks one question: **is this behavior already covered by the suite?**
226
138
 
227
- - **Not yet covered** → `testsprite test create` — describe the new behavior, run it.
228
- - **Already covered** → `testsprite test rerun` — replay the existing tests, so nothing that used to work breaks silently.
229
- - **Something fails** → `testsprite test failure get` — one self-consistent bundle; the agent fixes the code and reruns.
139
+ - **Not yet covered** → `testsprite plan` — the project's agent writes a test for the new behavior; `testsprite apply` saves it, then run it.
140
+ - **Already covered** → `testsprite run --project <project-id> --wait` — run the existing tests, so nothing that used to work breaks silently.
141
+ - **Something fails** → `testsprite result get <result-id>` — the failed step, its cause and a fix; the agent fixes the code and runs again.
230
142
 
231
143
  Every pass is banked into a durable suite, so coverage compounds as the project grows — a lasting record of every requirement it has ever gotten right, far bigger than any context window.
232
144
 
@@ -234,20 +146,20 @@ Every pass is banked into a durable suite, so coverage compounds as the project
234
146
  flowchart TD
235
147
  A["🤖 Your coding agent<br/>Claude Code · Codex · Antigravity · Kimi · Cursor · Trae …"]
236
148
  D{"behavior already<br/>covered by the suite?"}
237
- B["<b>testsprite test create</b><br/>new behavior → new test"]
238
- R["<b>testsprite test rerun</b><br/>replay the existing tests"]
149
+ B["<b>testsprite plan → apply</b><br/>the project's agent writes a test<br/>for the new behavior"]
150
+ R["<b>testsprite run --project &lt;project-id&gt; --wait</b><br/>run the existing tests"]
239
151
  C{{"☁️ TestSprite testing agent<br/>runs the test like a real user against<br/>real browsers & real APIs on Cloud"}}
240
- F["<b>testsprite test failure get</b><br/>ONE self-consistent bundle:<br/>failing step · screenshots · DOM ·<br/>root-cause · recommended fix"]
152
+ F["<b>testsprite result get</b><br/>one test's result in the run:<br/>failed step · screenshots · video ·<br/>cause · fix"]
241
153
  S[("📚 Durable integration suite<br/>grows with every pass")]
242
154
 
243
155
  A -->|"writes / changes code"| D
244
156
  D -->|"no — new behavior"| B
245
157
  D -->|"yes"| R
246
- B --> C
158
+ B --> R
247
159
  R --> C
248
160
  C -->|"pass ✅"| S
249
161
  C -->|"fail ❌"| F
250
- F -->|"agent reads the bundle<br/>& fixes the code"| A
162
+ F -->|"agent reads the result<br/>& fixes the code"| A
251
163
  S -.->|"defines what's covered"| D
252
164
  ```
253
165
 
@@ -262,9 +174,9 @@ That's the point of all of this: you no longer need the biggest, most expensive
262
174
  ## Getting help
263
175
 
264
176
  - 📚 **CLI reference** — [DOCUMENTATION.md](./DOCUMENTATION.md)
265
- - 🌐 **Platform docs** — [testsprite.com/docs](https://www.testsprite.com/docs)
177
+ - 🌐 **Platform docs** — [docs.testsprite.com](https://docs.testsprite.com)
266
178
  - 🐛 **Issues & feature requests** — [GitHub issues](https://github.com/TestSprite/testsprite-cli/issues)
267
- - 💬 **Quick questions** — [Discord](https://discord.gg/GXWFjCe4an), or `testsprite --help` / `testsprite test run --help` right in your terminal
179
+ - 💬 **Quick questions** — [Discord](https://discord.gg/GXWFjCe4an), or `testsprite --help` / `testsprite run --help` right in your terminal
268
180
  - 📝 **Changelog** — [CHANGELOG.md](./CHANGELOG.md)
269
181
 
270
182
  ## Contributing
@@ -71,10 +71,12 @@ export declare function runList(opts: CommonOptions, deps?: AgentDeps): Promise<
71
71
  * - 'unmarked' : artifact present but carries no testsprite-skill marker
72
72
  * (installed before markers existed), or the landing path is
73
73
  * occupied by a non-regular file (never followed).
74
- * - 'stale' : marker present, but its hash differs from the current
75
- * canonical body: a re-install would change the content. Edits
76
- * on top of an OLD install also read stale (older renders
77
- * cannot be reproduced); the remedy is the same re-install.
74
+ * - 'stale' : marker present, but either its hash differs from the current
75
+ * canonical body, or the bytes are exactly a legacy (v0.15.0)
76
+ * render of that body: a re-install would change the content
77
+ * and repair it without --force. Edits on top of an OLD install
78
+ * also read stale (older renders cannot be reproduced); the
79
+ * remedy is the same re-install.
78
80
  * - 'modified' : marker hash matches the current body, but the artifact bytes
79
81
  * differ from the canonical render carrying that same marker
80
82
  * line: the user edited the artifact after install.
@@ -101,6 +103,12 @@ interface StatusOptions extends CommonOptions {
101
103
  * (exit 0) when every row is 'ok' or 'absent'; throws CLIError exit 1 when any
102
104
  * row is stale/modified/unmarked/corrupt, so the command can gate CI.
103
105
  */
106
+ /**
107
+ * Each target's state for each default skill under `root`: what `agent
108
+ * status` prints and `doctor` reads. Absent artifacts never touch the skill
109
+ * assets.
110
+ */
111
+ export declare function skillStates(root: string, agentFs?: AgentFs): Promise<StatusResult[]>;
104
112
  export declare function runStatus(opts: StatusOptions, deps?: AgentDeps): Promise<void>;
105
113
  export declare function createAgentCommand(deps?: AgentDeps): Command;
106
114
  export {};
@@ -1,12 +1,15 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs/promises';
3
3
  import { Command } from 'commander';
4
+ import { equalIgnoringCrlf } from '../lib/text-equality.js';
4
5
  import { resolveProfileName } from '../lib/config.js';
5
6
  import { CLIError, localValidationError } from '../lib/errors.js';
6
7
  import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
8
+ import { inspectTargetPath } from '../lib/target-path.js';
7
9
  import { promptText } from '../lib/prompt.js';
8
10
  import { FALLBACK_TARGET, resolveAgentTargets } from '../lib/agent-detect.js';
9
- import { TARGETS, SKILLS, DEFAULT_SKILLS, MARKER_SKILL_SEPARATOR, pathFor, ownFileBodyFor, bodyHash12, buildCodexAggregate, buildSkillMarker, parseSkillMarker, renderForTarget, renderOwnFileWithMarker, MANAGED_SECTION_BEGIN, MANAGED_SECTION_END, } from '../lib/agent-targets.js';
11
+ import { TARGETS, SKILLS, DEFAULT_SKILLS, MARKER_SKILL_SEPARATOR, pathFor, ownFileBodyFor, bodyHash12, buildCodexAggregate, buildSkillMarker, parseSkillMarker, renderForTarget, renderOwnFileWithMarker, isLegacyOwnFileRender, MANAGED_SECTION_BEGIN, MANAGED_SECTION_END, } from '../lib/agent-targets.js';
12
+ import { terminalSafeWriter } from '../lib/terminal-text.js';
10
13
  // ---------------------------------------------------------------------------
11
14
  // Constants
12
15
  // ---------------------------------------------------------------------------
@@ -43,44 +46,6 @@ const defaultAgentFs = {
43
46
  // ---------------------------------------------------------------------------
44
47
  // Path safety
45
48
  // ---------------------------------------------------------------------------
46
- /**
47
- * Walk each component of `relPath` beneath `root`, refusing to traverse or
48
- * write through a symlink. `fs.mkdir`/`writeFile` follow symlinks, so a planted
49
- * symlink at any existing path component (e.g. `.claude` -> /etc, or the final
50
- * `SKILL.md` -> ~/.bashrc) could place or clobber files outside `--dir`. The
51
- * lexical containment guard in `runInstall` is a string compare and cannot see
52
- * this; only an `lstat`-per-component walk can. Fail-closed: any symlink is
53
- * rejected (exit 5).
54
- *
55
- * Returns the target's `{ isFile }` when it already exists, or `null` when it
56
- * (or any ancestor) does not yet exist — in which case the missing tail is
57
- * created fresh and cannot be a pre-planted symlink. A small TOCTOU window
58
- * remains between this check and the write; that is acceptable for a local,
59
- * single-user CLI and avoids non-portable O_NOFOLLOW / rename gymnastics.
60
- */
61
- async function inspectTargetPath(agentFs, root, relPath) {
62
- const segments = relPath.split(/[/\\]+/).filter(Boolean);
63
- let current = root;
64
- let finalIsFile = false;
65
- for (const [i, seg] of segments.entries()) {
66
- current = path.join(current, seg);
67
- const ls = await agentFs.lstat(current);
68
- if (ls === null) {
69
- // This component and everything below it does not exist yet.
70
- return null;
71
- }
72
- if (ls.isSymbolicLink) {
73
- const shown = segments.slice(0, i + 1).join('/');
74
- throw new CLIError(`refusing to write through a symlink: "${shown}" — installing here could place files outside --dir. Remove the symlink or choose a different --dir.`, 5);
75
- }
76
- if (i < segments.length - 1 && ls.isFile) {
77
- const shown = segments.slice(0, i + 1).join('/');
78
- throw new CLIError(`cannot create ${relPath}: "${shown}" exists and is not a directory.`, 5);
79
- }
80
- finalIsFile = ls.isFile;
81
- }
82
- return { isFile: finalIsFile };
83
- }
84
49
  /**
85
50
  * Back up the current bytes at `abs` next to it without clobbering any existing
86
51
  * backup or writing through a symlink. Exclusive create (`wx`) fails with
@@ -192,7 +157,7 @@ function classifySection(existing, section) {
192
157
  const before = existing.slice(0, beginByteIdx);
193
158
  const after = existing.slice(endOfEndByte + trailingNewline);
194
159
  const currentSection = existing.slice(beginByteIdx, endOfEndByte + trailingNewline);
195
- if (currentSection === section) {
160
+ if (equalIgnoringCrlf(currentSection, section)) {
196
161
  return { kind: 'unchanged' };
197
162
  }
198
163
  return { kind: 'replace', existing, before, after };
@@ -255,7 +220,7 @@ function makeOwnFileBodyResolver() {
255
220
  // ---------------------------------------------------------------------------
256
221
  export async function runInstall(opts, deps = {}) {
257
222
  const agentFs = deps.fs ?? defaultAgentFs;
258
- const stderrFn = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
223
+ const stderrFn = terminalSafeWriter(deps.stderr);
259
224
  const out = makeOutput(opts.output, deps);
260
225
  // 1. Parse targets
261
226
  const rawTargets = opts.target
@@ -564,24 +529,30 @@ export async function runInstall(opts, deps = {}) {
564
529
  }
565
530
  else {
566
531
  const existing = await agentFs.readFile(abs);
567
- if (existing === content) {
532
+ // A v0.15.0 render whose canonical body is unchanged is a stale
533
+ // install, not a user edit: repair it without --force.
534
+ const legacyRender = isLegacyOwnFileRender(t, skill, existing);
535
+ if (equalIgnoringCrlf(existing, content)) {
568
536
  // Byte-identical — skip
569
537
  results.push({ target: t, path: relPath, action: 'skipped', skills: [skill] });
570
538
  }
571
- else if (!opts.force) {
539
+ else if (!opts.force && !legacyRender) {
572
540
  // Differs and no --force → blocked
573
541
  results.push({ target: t, path: relPath, action: 'blocked', skills: [skill] });
574
542
  }
575
543
  else {
576
- // Differs and --force → back up the current bytes to a fresh slot
577
- // (never clobbering an existing backup or following a symlink), then
578
- // overwrite. The overwrite itself can follow a symlink swapped in after
579
- // the check — an accepted TOCTOU residual for a local, single-user CLI.
580
- const backupPath = await writeBackup(agentFs, abs, existing);
581
- await agentFs.writeFile(abs, content);
582
- if (opts.output === 'text') {
583
- stderrFn(`backed up ${relPath} to ${path.relative(root, backupPath)}`);
544
+ // Overwrite. With --force, back up the current bytes to a fresh slot
545
+ // (never clobbering an existing backup or following a symlink) first;
546
+ // a legacy render needs no backup because nothing of the user's is
547
+ // lost. The overwrite itself can follow a symlink swapped in after the
548
+ // check — an accepted TOCTOU residual for a local, single-user CLI.
549
+ if (opts.force) {
550
+ const backupPath = await writeBackup(agentFs, abs, existing);
551
+ if (opts.output === 'text') {
552
+ stderrFn(`backed up ${relPath} to ${path.relative(root, backupPath)}`);
553
+ }
584
554
  }
555
+ await agentFs.writeFile(abs, content);
585
556
  results.push({ target: t, path: relPath, action: 'updated', skills: [skill] });
586
557
  }
587
558
  }
@@ -635,7 +606,7 @@ function agentDisplayName(target, status) {
635
606
  }
636
607
  export async function runList(opts, deps = {}) {
637
608
  const out = makeOutput(opts.output, deps);
638
- const stderrFn = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
609
+ const stderrFn = terminalSafeWriter(deps.stderr);
639
610
  // One row per (target × default skill). Own-file targets land each skill at a
640
611
  // distinct path; the codex managed-section target merges all skills into the
641
612
  // single AGENTS.md (so every codex row shares that path — truthful, since both
@@ -699,7 +670,13 @@ async function classifyOwnFileState(agentFs, abs, target, skill, canonicalBody)
699
670
  // render carrying its own marker line, so a marker whose version string lags
700
671
  // behind an unchanged body still reads ok.
701
672
  const reRender = renderOwnFileWithMarker(target, skill, marker.line, body);
702
- return existing === reRender ? 'ok' : 'modified';
673
+ if (equalIgnoringCrlf(existing, reRender))
674
+ return 'ok';
675
+ // v0.15.0 wrote the same body with an unquoted frontmatter description; that
676
+ // is a stale install a plain re-install repairs, not a user edit.
677
+ if (isLegacyOwnFileRender(target, skill, existing, body))
678
+ return 'stale';
679
+ return 'modified';
703
680
  }
704
681
  /**
705
682
  * Classify the codex managed section per skill. The section is ONE artifact
@@ -765,16 +742,12 @@ async function classifyManagedSectionStates(agentFs, abs) {
765
742
  * (exit 0) when every row is 'ok' or 'absent'; throws CLIError exit 1 when any
766
743
  * row is stale/modified/unmarked/corrupt, so the command can gate CI.
767
744
  */
768
- export async function runStatus(opts, deps = {}) {
769
- const agentFs = deps.fs ?? defaultAgentFs;
770
- const out = makeOutput(opts.output, deps);
771
- // An explicit but empty --dir must not silently resolve to cwd
772
- // (path.resolve('') === cwd).
773
- if (opts.dir !== undefined && opts.dir.trim() === '') {
774
- throw localValidationError('dir', 'must not be empty');
775
- }
776
- const dir = opts.dir !== undefined ? opts.dir.trim() : (deps.cwd ?? process.cwd());
777
- const root = path.resolve(dir);
745
+ /**
746
+ * Each target's state for each default skill under `root`: what `agent
747
+ * status` prints and `doctor` reads. Absent artifacts never touch the skill
748
+ * assets.
749
+ */
750
+ export async function skillStates(root, agentFs = defaultAgentFs) {
778
751
  // The SAME resolver the installer stamps its marker hashes from — a
779
752
  // separate copy here is exactly how install and status end up disagreeing.
780
753
  const ownFileBodyFor = makeOwnFileBodyResolver();
@@ -800,6 +773,18 @@ export async function runStatus(opts, deps = {}) {
800
773
  });
801
774
  }
802
775
  }
776
+ return results;
777
+ }
778
+ export async function runStatus(opts, deps = {}) {
779
+ const agentFs = deps.fs ?? defaultAgentFs;
780
+ const out = makeOutput(opts.output, deps);
781
+ // An explicit but empty --dir must not silently resolve to cwd
782
+ // (path.resolve('') === cwd).
783
+ if (opts.dir !== undefined && opts.dir.trim() === '') {
784
+ throw localValidationError('dir', 'must not be empty');
785
+ }
786
+ const dir = opts.dir !== undefined ? opts.dir.trim() : (deps.cwd ?? process.cwd());
787
+ const results = await skillStates(path.resolve(dir), agentFs);
803
788
  out.print(results, data => {
804
789
  const items = data;
805
790
  const header = `${'TARGET'.padEnd(14)} ${'SKILL'.padEnd(20)} ${'STATE'.padEnd(10)} PATH`;
@@ -818,11 +803,14 @@ function collect(v, prev) {
818
803
  return prev.concat(v);
819
804
  }
820
805
  export function createAgentCommand(deps = {}) {
821
- const agent = new Command('agent').description('Install TestSprite guidance into coding-agent config (Claude Code, Cursor, Cline, Antigravity, Kiro, Windsurf, Copilot, Codex)');
806
+ const agent = new Command('agent')
807
+ .summary('Install TestSprite guidance into coding-agent config')
808
+ .description('Install TestSprite guidance into coding-agent config (Claude Code, Cursor, Cline, Antigravity, Kiro, Windsurf, Copilot, Codex)');
822
809
  agent
823
810
  .command('install [targets...]')
811
+ .summary('Write the TestSprite agent skills into a project')
824
812
  .description('Write the TestSprite agent skills (verification loop + first-run onboarding) into a project for a coding agent. ' +
825
- 'Target(s) may be given positionally (e.g. `agent install cursor codex`) and/or via --target; the two are merged.')
813
+ 'Targets may be positional (`agent install cursor codex`) and/or via --target; they are merged.')
826
814
  .option('--target <t>', 'Agent target(s): claude, cursor, cline, antigravity, kiro, windsurf, copilot, codex (comma-separated or repeated). Merged with any positional target(s).', collect, [])
827
815
  .option('--skill <name>', `Skill(s) to install: ${Object.keys(SKILLS).join(', ')} (comma-separated or repeated; default: all)`, collect, [])
828
816
  .option('--dir <path>', 'Project root to write into (default: cwd)')
@@ -850,6 +838,7 @@ export function createAgentCommand(deps = {}) {
850
838
  });
851
839
  agent
852
840
  .command('list')
841
+ .summary('List installable agent targets and skills')
853
842
  .description('List the agent targets and skills this CLI can install and where each lands (run `testsprite agent status` to see what is installed here)')
854
843
  .addHelpText('after', GLOBAL_OPTS_HINT)
855
844
  .action(async (_o, command) => {
@@ -857,6 +846,7 @@ export function createAgentCommand(deps = {}) {
857
846
  });
858
847
  agent
859
848
  .command('status')
849
+ .summary('Check installed skill files against this CLI version')
860
850
  .description('Check installed TestSprite skill files against this CLI version: ok, stale, modified, unmarked, absent, or corrupt (exits 1 when anything needs attention, so it can gate CI)')
861
851
  .option('--dir <path>', 'Project root to inspect (default: cwd)')
862
852
  .addHelpText('after', GLOBAL_OPTS_HINT)