@testsprite/testsprite-cli 0.2.0 → 0.4.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 (68) hide show
  1. package/README.md +35 -26
  2. package/dist/commands/agent.d.ts +43 -0
  3. package/dist/commands/agent.js +200 -18
  4. package/dist/commands/auth.d.ts +5 -0
  5. package/dist/commands/auth.js +38 -27
  6. package/dist/commands/doctor.d.ts +49 -0
  7. package/dist/commands/doctor.js +233 -0
  8. package/dist/commands/init.d.ts +1 -1
  9. package/dist/commands/init.js +24 -14
  10. package/dist/commands/project.d.ts +75 -2
  11. package/dist/commands/project.js +326 -47
  12. package/dist/commands/test.d.ts +281 -2
  13. package/dist/commands/test.js +1658 -177
  14. package/dist/commands/usage.js +13 -12
  15. package/dist/index.js +71 -3
  16. package/dist/lib/agent-targets.d.ts +72 -6
  17. package/dist/lib/agent-targets.js +188 -6
  18. package/dist/lib/bundle.d.ts +34 -0
  19. package/dist/lib/bundle.js +63 -11
  20. package/dist/lib/client-factory.d.ts +31 -0
  21. package/dist/lib/client-factory.js +63 -0
  22. package/dist/lib/config.d.ts +2 -0
  23. package/dist/lib/config.js +11 -2
  24. package/dist/lib/credentials.js +10 -1
  25. package/dist/lib/dry-run/samples.d.ts +5 -0
  26. package/dist/lib/dry-run/samples.js +64 -0
  27. package/dist/lib/errors.d.ts +28 -1
  28. package/dist/lib/errors.js +40 -0
  29. package/dist/lib/failing-fe-resolver.d.ts +15 -0
  30. package/dist/lib/failing-fe-resolver.js +49 -1
  31. package/dist/lib/flaky.d.ts +80 -0
  32. package/dist/lib/flaky.js +76 -0
  33. package/dist/lib/http.d.ts +73 -1
  34. package/dist/lib/http.js +327 -135
  35. package/dist/lib/interrupt.d.ts +116 -0
  36. package/dist/lib/interrupt.js +182 -0
  37. package/dist/lib/junit-report.d.ts +58 -0
  38. package/dist/lib/junit-report.js +210 -0
  39. package/dist/lib/output.d.ts +16 -1
  40. package/dist/lib/output.js +24 -2
  41. package/dist/lib/pagination.d.ts +4 -3
  42. package/dist/lib/pagination.js +34 -6
  43. package/dist/lib/poll.d.ts +11 -0
  44. package/dist/lib/poll.js +70 -5
  45. package/dist/lib/prompt.js +52 -8
  46. package/dist/lib/proxy.d.ts +29 -0
  47. package/dist/lib/proxy.js +30 -0
  48. package/dist/lib/render-error.js +3 -1
  49. package/dist/lib/runs.types.d.ts +9 -0
  50. package/dist/lib/skill-nudge.d.ts +2 -2
  51. package/dist/lib/skill-nudge.js +13 -4
  52. package/dist/lib/target-url.js +8 -1
  53. package/dist/lib/ticker.d.ts +11 -1
  54. package/dist/lib/ticker.js +33 -1
  55. package/dist/lib/update-check.d.ts +67 -0
  56. package/dist/lib/update-check.js +246 -0
  57. package/dist/lib/v3-advisory.d.ts +13 -0
  58. package/dist/lib/v3-advisory.js +24 -0
  59. package/dist/lib/version-notice.d.ts +37 -0
  60. package/dist/lib/version-notice.js +87 -0
  61. package/dist/version-guard.d.ts +33 -0
  62. package/dist/version-guard.js +39 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +3 -2
  66. package/skills/testsprite-onboard.skill.md +21 -0
  67. package/skills/testsprite-verify.codex.md +6 -0
  68. package/skills/testsprite-verify.skill.md +48 -4
@@ -0,0 +1,67 @@
1
+ import * as v from 'valibot';
2
+ import type { FetchImpl } from './http.js';
3
+ /** Re-check interval: 24 hours, expressed in milliseconds. */
4
+ export declare const UPDATE_CHECK_TTL_MS: number;
5
+ /**
6
+ * Env var that disables the update notice entirely. Presence-style: any
7
+ * non-empty value (including "0") opts out. Deliberately stricter than the
8
+ * truthy-style `TESTSPRITE_NO_SKILL_WARNING` because it matches the
9
+ * convention users already know from gh's GH_NO_UPDATE_NOTIFIER.
10
+ */
11
+ export declare const UPDATE_CHECK_OPT_OUT_ENV = "TESTSPRITE_NO_UPDATE_NOTIFIER";
12
+ /** On-disk cache shape at `cachePath`; unknown keys are stripped on read. */
13
+ declare const UPDATE_CHECK_CACHE_SCHEMA: v.ObjectSchema<{
14
+ readonly lastCheckMs: v.NumberSchema<undefined>;
15
+ readonly latestKnown: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
16
+ }, undefined>;
17
+ export type UpdateCheckCache = v.InferOutput<typeof UPDATE_CHECK_CACHE_SCHEMA>;
18
+ export interface UpdateCheckDeps {
19
+ env?: NodeJS.ProcessEnv;
20
+ fetchImpl?: FetchImpl;
21
+ /** Clock, epoch milliseconds. */
22
+ now?: () => number;
23
+ /** Cache file; lives next to credentials/config under ~/.testsprite. */
24
+ cachePath?: string;
25
+ readFile?: (path: string) => string;
26
+ writeFile?: (path: string, content: string) => void;
27
+ /** Must create missing parent directories (recursive). */
28
+ mkdir?: (dir: string) => void;
29
+ /** Whether stderr is an interactive terminal. */
30
+ isTTY?: boolean;
31
+ /** Sink for the single advisory line. */
32
+ stderr?: (line: string) => void;
33
+ /** Version the running binary reports. */
34
+ currentVersion?: string;
35
+ }
36
+ /**
37
+ * True when every gate documented in the module header passes: no opt-out
38
+ * env, not CI (unless CI=false), stderr is a TTY, and the cached check is
39
+ * stale or absent. Order matters: the cheap env gates run before any fs read.
40
+ */
41
+ export declare function shouldCheckForUpdate(deps?: UpdateCheckDeps): boolean;
42
+ /**
43
+ * Probe the npm registry for the `latest` dist-tag version of this package.
44
+ * Hard 1.5s timeout via AbortSignal.timeout. ANY failure (network error,
45
+ * timeout, non-2xx status, invalid JSON, wrong shape) resolves to undefined;
46
+ * this function never rejects.
47
+ */
48
+ export declare function fetchLatestVersion(deps?: UpdateCheckDeps): Promise<string | undefined>;
49
+ /**
50
+ * Compare two semver strings numerically. Returns -1 when versionA is older
51
+ * than versionB, 1 when newer, 0 when equal. A version carrying a prerelease
52
+ * tag sorts OLDER than the plain release with the same x.y.z core. Prerelease
53
+ * identifiers themselves are not ranked (two prereleases on the same core
54
+ * compare as 0): the registry `latest` tag points at releases, so identifier
55
+ * ordering never decides whether the notice fires. Unparseable input on
56
+ * either side compares as 0, so garbage can never produce a false notice.
57
+ */
58
+ export declare function compareSemver(versionA: string, versionB: string): number;
59
+ /**
60
+ * Fire-and-forget update notice. Gates, probes, stamps the cache, and prints
61
+ * at most one stderr line when the registry version is strictly newer than
62
+ * the running one. Never throws and never rejects: any failure in any
63
+ * injected dependency (clock, fs, network, the stderr sink itself) is
64
+ * swallowed, because an advisory must never break or delay a real command.
65
+ */
66
+ export declare function maybeNotifyUpdate(deps?: UpdateCheckDeps): Promise<void>;
67
+ export {};
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Non-blocking "new version available" notice (issue #122), following the
3
+ * pattern of the gh and npm CLIs: at most one npm-registry probe per 24 hours,
4
+ * result cached on disk, advisory printed to stderr so stdout stays parseable.
5
+ *
6
+ * Behavior (`maybeNotifyUpdate`):
7
+ * 1. Gate through `shouldCheckForUpdate`; every gate below must pass.
8
+ * 2. Probe the npm registry for the `latest` dist-tag (1.5s hard timeout).
9
+ * 3. Stamp the cache with `lastCheckMs` (plus `latestKnown` when the probe
10
+ * succeeded) so the next 24h of invocations skip the network entirely.
11
+ * The stamp happens even after a failed probe: a dead registry must not
12
+ * trigger a retry on every command.
13
+ * 4. When `latest` is strictly newer than the running version, write exactly
14
+ * one advisory line to stderr. The function never throws or rejects and
15
+ * never alters the exit status of the command it rides along with.
16
+ *
17
+ * Gates, in order (`shouldCheckForUpdate`):
18
+ * - `TESTSPRITE_NO_UPDATE_NOTIFIER` set to any non-empty value: opted out.
19
+ * Presence-style, mirroring gh's GH_NO_UPDATE_NOTIFIER: even "0" disables.
20
+ * - `CI` set to anything except the literal "false": CI logs are not the
21
+ * place for update nags. `CI=false` explicitly re-enables the notice.
22
+ * - stderr is not a TTY: piped or redirected output stays clean.
23
+ * - the on-disk cache is fresh (last probe within the TTL). A missing,
24
+ * unreadable, corrupt, or wrong-shape cache counts as stale, and so does a
25
+ * `lastCheckMs` in the future (clock rollback or corrupt data).
26
+ *
27
+ * Why not the npm `update-notifier` package: this CLI's runtime dependency
28
+ * budget is commander + valibot only (package.json). `update-notifier` would
29
+ * add a transitive dependency tree for what Node 20 already ships as
30
+ * primitives (fetch, AbortSignal.timeout, sync fs). Owning the ~100 lines
31
+ * keeps the install size flat and every effect injectable for tests.
32
+ *
33
+ * All effects (env, network, clock, fs, tty, stderr sink) are injectable via
34
+ * `UpdateCheckDeps`, the same dependency-injection style as `skill-nudge.ts`.
35
+ */
36
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
37
+ import { homedir } from 'node:os';
38
+ import { dirname, join } from 'node:path';
39
+ import * as v from 'valibot';
40
+ import { VERSION } from '../version.js';
41
+ /** Re-check interval: 24 hours, expressed in milliseconds. */
42
+ export const UPDATE_CHECK_TTL_MS = 24 * 60 * 60 * 1000;
43
+ /**
44
+ * Env var that disables the update notice entirely. Presence-style: any
45
+ * non-empty value (including "0") opts out. Deliberately stricter than the
46
+ * truthy-style `TESTSPRITE_NO_SKILL_WARNING` because it matches the
47
+ * convention users already know from gh's GH_NO_UPDATE_NOTIFIER.
48
+ */
49
+ export const UPDATE_CHECK_OPT_OUT_ENV = 'TESTSPRITE_NO_UPDATE_NOTIFIER';
50
+ /**
51
+ * Hard cap for the registry probe, in milliseconds. The probe rides along a
52
+ * real command, so unlike the 120s API budget in `http.ts` it gets a tiny
53
+ * window: a slow registry means "no update info", never a visible delay.
54
+ */
55
+ const REGISTRY_TIMEOUT_MS = 1_500;
56
+ /**
57
+ * npm registry `latest` dist-tag endpoint for this package. Package name from
58
+ * package.json (`@testsprite/testsprite-cli`); the scope separator must be
59
+ * URL-encoded as %2F per the npm registry API.
60
+ */
61
+ const REGISTRY_LATEST_URL = 'https://registry.npmjs.org/@testsprite%2Ftestsprite-cli/latest';
62
+ /** On-disk cache shape at `cachePath`; unknown keys are stripped on read. */
63
+ const UPDATE_CHECK_CACHE_SCHEMA = v.object({
64
+ lastCheckMs: v.number(),
65
+ latestKnown: v.optional(v.string()),
66
+ });
67
+ /** Minimal slice of the registry response the notice needs. */
68
+ const REGISTRY_LATEST_BODY_SCHEMA = v.object({ version: v.string() });
69
+ function resolveUpdateCheckDeps(deps) {
70
+ return {
71
+ env: deps.env ?? process.env,
72
+ fetchImpl: deps.fetchImpl ?? globalThis.fetch,
73
+ now: deps.now ?? Date.now,
74
+ cachePath: deps.cachePath ?? join(homedir(), '.testsprite', 'update-check.json'),
75
+ readFile: deps.readFile ?? ((path) => readFileSync(path, 'utf8')),
76
+ writeFile: deps.writeFile ?? ((path, content) => writeFileSync(path, content, 'utf8')),
77
+ mkdir: deps.mkdir ??
78
+ ((dir) => {
79
+ mkdirSync(dir, { recursive: true });
80
+ }),
81
+ isTTY: deps.isTTY ?? process.stderr.isTTY === true,
82
+ stderr: deps.stderr ?? ((line) => process.stderr.write(`${line}\n`)),
83
+ currentVersion: deps.currentVersion ?? VERSION,
84
+ };
85
+ }
86
+ /**
87
+ * Read and validate the cache file. Every failure mode (missing file,
88
+ * unreadable file, invalid JSON, wrong shape) returns undefined, which the
89
+ * caller treats as "stale, probe again".
90
+ */
91
+ function readUpdateCheckCache(resolved) {
92
+ try {
93
+ const raw = resolved.readFile(resolved.cachePath);
94
+ const body = JSON.parse(raw);
95
+ const parsed = v.safeParse(UPDATE_CHECK_CACHE_SCHEMA, body);
96
+ return parsed.success ? parsed.output : undefined;
97
+ }
98
+ catch {
99
+ // Missing or unreadable cache: treat as stale.
100
+ return undefined;
101
+ }
102
+ }
103
+ /**
104
+ * Persist the cache, creating the parent directory when missing. Best-effort:
105
+ * every error (read-only home, quota, fs races) is swallowed. A failed write
106
+ * only means the next invocation probes the registry again.
107
+ */
108
+ function writeUpdateCheckCache(resolved, cache) {
109
+ try {
110
+ resolved.mkdir(dirname(resolved.cachePath));
111
+ resolved.writeFile(resolved.cachePath, `${JSON.stringify(cache)}\n`);
112
+ }
113
+ catch {
114
+ // Cache persistence is optional; never surface fs errors to the command.
115
+ }
116
+ }
117
+ /**
118
+ * True when every gate documented in the module header passes: no opt-out
119
+ * env, not CI (unless CI=false), stderr is a TTY, and the cached check is
120
+ * stale or absent. Order matters: the cheap env gates run before any fs read.
121
+ */
122
+ export function shouldCheckForUpdate(deps = {}) {
123
+ const resolved = resolveUpdateCheckDeps(deps);
124
+ const optOutValue = resolved.env[UPDATE_CHECK_OPT_OUT_ENV];
125
+ if (optOutValue !== undefined && optOutValue !== '')
126
+ return false;
127
+ // Any set CI value except the literal "false" counts as CI. The empty
128
+ // string still signals a CI-managed environment; silence wins in doubt.
129
+ const ciValue = resolved.env.CI;
130
+ if (ciValue !== undefined && ciValue !== 'false')
131
+ return false;
132
+ if (!resolved.isTTY)
133
+ return false;
134
+ const cache = readUpdateCheckCache(resolved);
135
+ if (cache !== undefined) {
136
+ const elapsedMs = resolved.now() - cache.lastCheckMs;
137
+ // A negative elapsed (lastCheckMs in the future) means clock rollback or
138
+ // corrupt data: treat as stale instead of suppressing the check forever.
139
+ // A NaN lastCheckMs fails both comparisons and lands on stale too.
140
+ if (elapsedMs >= 0 && elapsedMs < UPDATE_CHECK_TTL_MS)
141
+ return false;
142
+ }
143
+ return true;
144
+ }
145
+ /**
146
+ * Probe the npm registry for the `latest` dist-tag version of this package.
147
+ * Hard 1.5s timeout via AbortSignal.timeout. ANY failure (network error,
148
+ * timeout, non-2xx status, invalid JSON, wrong shape) resolves to undefined;
149
+ * this function never rejects.
150
+ */
151
+ export async function fetchLatestVersion(deps = {}) {
152
+ const resolved = resolveUpdateCheckDeps(deps);
153
+ try {
154
+ const response = await resolved.fetchImpl(REGISTRY_LATEST_URL, {
155
+ signal: AbortSignal.timeout(REGISTRY_TIMEOUT_MS),
156
+ });
157
+ if (!response.ok)
158
+ return undefined;
159
+ const body = await response.json();
160
+ const parsed = v.safeParse(REGISTRY_LATEST_BODY_SCHEMA, body);
161
+ return parsed.success ? parsed.output.version : undefined;
162
+ }
163
+ catch {
164
+ // Offline, DNS failure, abort, or a non-JSON body: no update info.
165
+ return undefined;
166
+ }
167
+ }
168
+ /**
169
+ * x.y.z with optional prerelease (after "-") and optional build metadata
170
+ * (after "+"), per the semver 2.0.0 grammar. A leading "v" is tolerated
171
+ * because humans type it; the npm registry never returns one.
172
+ */
173
+ const SEMVER_RE = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
174
+ function parseSemver(version) {
175
+ const match = SEMVER_RE.exec(version.trim());
176
+ if (!match)
177
+ return undefined;
178
+ const [, majorRaw, minorRaw, patchRaw, prerelease] = match;
179
+ if (majorRaw === undefined || minorRaw === undefined || patchRaw === undefined)
180
+ return undefined;
181
+ return {
182
+ major: Number(majorRaw),
183
+ minor: Number(minorRaw),
184
+ patch: Number(patchRaw),
185
+ hasPrerelease: prerelease !== undefined,
186
+ };
187
+ }
188
+ /**
189
+ * Compare two semver strings numerically. Returns -1 when versionA is older
190
+ * than versionB, 1 when newer, 0 when equal. A version carrying a prerelease
191
+ * tag sorts OLDER than the plain release with the same x.y.z core. Prerelease
192
+ * identifiers themselves are not ranked (two prereleases on the same core
193
+ * compare as 0): the registry `latest` tag points at releases, so identifier
194
+ * ordering never decides whether the notice fires. Unparseable input on
195
+ * either side compares as 0, so garbage can never produce a false notice.
196
+ */
197
+ export function compareSemver(versionA, versionB) {
198
+ const left = parseSemver(versionA);
199
+ const right = parseSemver(versionB);
200
+ if (left === undefined || right === undefined)
201
+ return 0;
202
+ if (left.major !== right.major)
203
+ return left.major < right.major ? -1 : 1;
204
+ if (left.minor !== right.minor)
205
+ return left.minor < right.minor ? -1 : 1;
206
+ if (left.patch !== right.patch)
207
+ return left.patch < right.patch ? -1 : 1;
208
+ if (left.hasPrerelease !== right.hasPrerelease)
209
+ return left.hasPrerelease ? -1 : 1;
210
+ return 0;
211
+ }
212
+ /**
213
+ * Fire-and-forget update notice. Gates, probes, stamps the cache, and prints
214
+ * at most one stderr line when the registry version is strictly newer than
215
+ * the running one. Never throws and never rejects: any failure in any
216
+ * injected dependency (clock, fs, network, the stderr sink itself) is
217
+ * swallowed, because an advisory must never break or delay a real command.
218
+ */
219
+ export async function maybeNotifyUpdate(deps = {}) {
220
+ try {
221
+ const resolved = resolveUpdateCheckDeps(deps);
222
+ if (!shouldCheckForUpdate(resolved))
223
+ return;
224
+ const latest = await fetchLatestVersion(resolved);
225
+ // Stamp even on a failed probe so a dead registry is retried at most
226
+ // once per TTL window, not on every invocation.
227
+ writeUpdateCheckCache(resolved, {
228
+ lastCheckMs: resolved.now(),
229
+ ...(latest === undefined ? {} : { latestKnown: latest }),
230
+ });
231
+ if (latest === undefined)
232
+ return;
233
+ if (compareSemver(latest, resolved.currentVersion) !== 1)
234
+ return;
235
+ // User-facing advisory copy (exact format specified by issue #122), not a
236
+ // diagnostic log line; stderr keeps stdout parseable for scripts.
237
+ resolved.stderr(`A new version of testsprite-cli is available: ${resolved.currentVersion} -> ${latest}. ` +
238
+ `Run npm install -g @testsprite/testsprite-cli to update. ` +
239
+ `(Disable with ${UPDATE_CHECK_OPT_OUT_ENV}=1)`);
240
+ }
241
+ catch {
242
+ // An update notice must never break, delay, or alter the exit status of
243
+ // the command it accompanies. Swallow everything.
244
+ }
245
+ }
246
+ //# sourceMappingURL=update-check.js.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Shared V3-routing text surfaces for `auth status` and `doctor`.
3
+ *
4
+ * `v3Enabled` on the `/me` response is the authoritative routing bit. When it
5
+ * is on, some commands behave differently while the V3 gaps stay open — the
6
+ * advisory names them. Copy lives here so both commands stay in sync.
7
+ */
8
+ /** One-word routing label for the text card. */
9
+ export declare function routingLabel(v3Enabled: boolean): 'v3' | 'v2';
10
+ /** Consolidated advisory (stderr) emitted when V3 routing is on. */
11
+ export declare const V3_ROUTING_ADVISORY: string[];
12
+ /** Write the advisory to a stderr sink, one line per call. */
13
+ export declare function emitV3RoutingAdvisory(stderr: (line: string) => void): void;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Shared V3-routing text surfaces for `auth status` and `doctor`.
3
+ *
4
+ * `v3Enabled` on the `/me` response is the authoritative routing bit. When it
5
+ * is on, some commands behave differently while the V3 gaps stay open — the
6
+ * advisory names them. Copy lives here so both commands stay in sync.
7
+ */
8
+ /** One-word routing label for the text card. */
9
+ export function routingLabel(v3Enabled) {
10
+ return v3Enabled ? 'v3' : 'v2';
11
+ }
12
+ /** Consolidated advisory (stderr) emitted when V3 routing is on. */
13
+ export const V3_ROUTING_ADVISORY = [
14
+ '[advisory] V3 routing is on for this account. While these gaps are open:',
15
+ ' - `test cancel` may return 404',
16
+ ' - `test delete` may leave a zombie run',
17
+ ' - `--target-url` is ignored on frontend runs',
18
+ ];
19
+ /** Write the advisory to a stderr sink, one line per call. */
20
+ export function emitV3RoutingAdvisory(stderr) {
21
+ for (const line of V3_ROUTING_ADVISORY)
22
+ stderr(line);
23
+ }
24
+ //# sourceMappingURL=v3-advisory.js.map
@@ -0,0 +1,37 @@
1
+ /** Version-compatibility signal observed on a backend response (the floor). */
2
+ export interface ServerVersionInfo {
3
+ minVersion?: string;
4
+ }
5
+ export interface VersionNoticeDeps {
6
+ /** Version the running binary reports. Defaults to the built-in `VERSION`. */
7
+ currentVersion?: string;
8
+ env?: NodeJS.ProcessEnv;
9
+ /** Whether stderr is an interactive terminal. */
10
+ isTTY?: boolean;
11
+ /** The command's `--output` mode; `'json'` suppresses the advisory. */
12
+ outputMode?: string;
13
+ /** Suppress under `--dry-run` (the dry-run fetch returns no real headers). */
14
+ dryRun?: boolean;
15
+ /** Sink for the single advisory line. */
16
+ stderr?: (line: string) => void;
17
+ }
18
+ /**
19
+ * True when every gate passes and the running version is strictly below the
20
+ * advertised floor. Gates mirror the update notice: opt-out env, JSON output,
21
+ * dry-run, and non-TTY all suppress. Pure — no side effects, no process state.
22
+ */
23
+ export declare function shouldWarnBelowFloor(info: ServerVersionInfo, deps?: VersionNoticeDeps): boolean;
24
+ /**
25
+ * The single advisory line. Names the floor (the backend's authority) and the
26
+ * upgrade command — it deliberately does NOT name a target release; the npm
27
+ * update-notice is the single source of truth for the newest version.
28
+ */
29
+ export declare function formatBelowFloorNotice(currentVersion: string, minVersion: string): string;
30
+ /** Test-only: reset the once-per-process guard between cases. */
31
+ export declare function resetBelowFloorNoticeState(): void;
32
+ /**
33
+ * Emit the below-floor advisory at most once per process. Wired to the HTTP
34
+ * client's `onServerVersion` hook. Never throws — an advisory must not break or
35
+ * delay the command it rides along with.
36
+ */
37
+ export declare function noteServerVersion(info: ServerVersionInfo, deps?: VersionNoticeDeps): void;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Inline "your CLI is below the backend's minimum supported version" advisory.
3
+ *
4
+ * The backend advertises its supported floor on every `/api/cli/v1` response via
5
+ * the `X-TestSprite-CLI-Min-Version` header. Unlike the npm-registry update
6
+ * notice (`update-check.ts`, which runs in a Commander `preAction` hook before
7
+ * any HTTP request), this advisory reacts to a header observed *during* the
8
+ * request, so it is emitted from the HTTP layer's `onServerVersion` hook (wired
9
+ * in `client-factory.ts`) rather than the pre-request notifier — no cross-run
10
+ * cache needed.
11
+ *
12
+ * Distinct from the update notice on purpose, and non-redundant: this names the
13
+ * backend FLOOR and fires only when the running version is strictly below it (a
14
+ * serious "you will be rejected once enforcement is on" state); the update
15
+ * notice names the npm LATEST and fires whenever a newer release exists. Each
16
+ * owns its own number — the backend never advertises "latest".
17
+ *
18
+ * Reuses `compareSemver` and the `TESTSPRITE_NO_UPDATE_NOTIFIER` opt-out from
19
+ * `update-check.ts` so the gating and semver semantics stay consistent.
20
+ */
21
+ import { compareSemver, UPDATE_CHECK_OPT_OUT_ENV } from './update-check.js';
22
+ import { VERSION } from '../version.js';
23
+ /**
24
+ * True when every gate passes and the running version is strictly below the
25
+ * advertised floor. Gates mirror the update notice: opt-out env, JSON output,
26
+ * dry-run, and non-TTY all suppress. Pure — no side effects, no process state.
27
+ */
28
+ export function shouldWarnBelowFloor(info, deps = {}) {
29
+ const env = deps.env ?? process.env;
30
+ const currentVersion = deps.currentVersion ?? VERSION;
31
+ const isTTY = deps.isTTY ?? process.stderr.isTTY === true;
32
+ const optOut = env[UPDATE_CHECK_OPT_OUT_ENV];
33
+ if (optOut !== undefined && optOut !== '')
34
+ return false;
35
+ if (deps.outputMode === 'json')
36
+ return false;
37
+ if (deps.dryRun === true)
38
+ return false;
39
+ if (!isTTY)
40
+ return false;
41
+ const minVersion = info.minVersion;
42
+ if (!minVersion)
43
+ return false;
44
+ // compareSemver returns -1 when the first arg is OLDER than the second.
45
+ // Unparseable input on either side compares as 0, so garbage never warns.
46
+ return compareSemver(currentVersion, minVersion) === -1;
47
+ }
48
+ /**
49
+ * The single advisory line. Names the floor (the backend's authority) and the
50
+ * upgrade command — it deliberately does NOT name a target release; the npm
51
+ * update-notice is the single source of truth for the newest version.
52
+ */
53
+ export function formatBelowFloorNotice(currentVersion, minVersion) {
54
+ return (`Your testsprite-cli (${currentVersion}) is below the minimum supported version ${minVersion}. ` +
55
+ `Upgrade: npm install -g @testsprite/testsprite-cli ` +
56
+ `(disable this notice with ${UPDATE_CHECK_OPT_OUT_ENV}=1).`);
57
+ }
58
+ /** Module-level guard: at most one below-floor advisory per process. */
59
+ let warnedThisProcess = false;
60
+ /** Test-only: reset the once-per-process guard between cases. */
61
+ export function resetBelowFloorNoticeState() {
62
+ warnedThisProcess = false;
63
+ }
64
+ /**
65
+ * Emit the below-floor advisory at most once per process. Wired to the HTTP
66
+ * client's `onServerVersion` hook. Never throws — an advisory must not break or
67
+ * delay the command it rides along with.
68
+ */
69
+ export function noteServerVersion(info, deps = {}) {
70
+ try {
71
+ if (warnedThisProcess)
72
+ return;
73
+ if (!shouldWarnBelowFloor(info, deps))
74
+ return;
75
+ const minVersion = info.minVersion;
76
+ if (!minVersion)
77
+ return;
78
+ const currentVersion = deps.currentVersion ?? VERSION;
79
+ const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
80
+ stderr(formatBelowFloorNotice(currentVersion, minVersion));
81
+ warnedThisProcess = true;
82
+ }
83
+ catch {
84
+ // Advisory is best-effort; never surface its failures to the command.
85
+ }
86
+ }
87
+ //# sourceMappingURL=version-notice.js.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Node.js runtime version guard.
3
+ *
4
+ * The CLI targets modern Node (see `engines.node` in package.json). Running on
5
+ * an older runtime tends to fail later with a cryptic ESM/syntax error, so the
6
+ * entrypoint (`src/index.ts`) uses {@link shouldRejectNodeVersion} to exit early
7
+ * with a clear, actionable message instead.
8
+ *
9
+ * The logic lives here (rather than inline) so it can be unit-tested against the
10
+ * real implementation the entrypoint uses — not a copy.
11
+ */
12
+ /** Minimum Node.js major version supported by the CLI (matches package.json `engines.node`). */
13
+ export declare const MIN_SUPPORTED_NODE_MAJOR = 20;
14
+ /**
15
+ * Parse the leading major version number from a Node.js version string.
16
+ *
17
+ * @param nodeVersion - a dot-separated version string such as `process.versions.node`
18
+ * (e.g. `"20.11.1"`). A leading `v` is not expected (Node does not include one here).
19
+ * @returns the major version as a number, or `NaN` if the string has no numeric leading segment.
20
+ */
21
+ export declare function parseMajorVersion(nodeVersion: string): number;
22
+ /**
23
+ * Decide whether the given Node.js version is too old to run the CLI.
24
+ *
25
+ * A version is rejected only when its major number is a real value below
26
+ * {@link MIN_SUPPORTED_NODE_MAJOR}. An unparseable string yields `NaN`, which is
27
+ * treated as "do not reject" so the guard never blocks on a version string it
28
+ * cannot understand (the runtime would surface any real incompatibility itself).
29
+ *
30
+ * @param nodeVersion - a `process.versions.node` style string (e.g. `"18.19.1"`).
31
+ * @returns `true` when the runtime is below the supported floor and should be rejected.
32
+ */
33
+ export declare function shouldRejectNodeVersion(nodeVersion: string): boolean;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Node.js runtime version guard.
3
+ *
4
+ * The CLI targets modern Node (see `engines.node` in package.json). Running on
5
+ * an older runtime tends to fail later with a cryptic ESM/syntax error, so the
6
+ * entrypoint (`src/index.ts`) uses {@link shouldRejectNodeVersion} to exit early
7
+ * with a clear, actionable message instead.
8
+ *
9
+ * The logic lives here (rather than inline) so it can be unit-tested against the
10
+ * real implementation the entrypoint uses — not a copy.
11
+ */
12
+ /** Minimum Node.js major version supported by the CLI (matches package.json `engines.node`). */
13
+ export const MIN_SUPPORTED_NODE_MAJOR = 20;
14
+ /**
15
+ * Parse the leading major version number from a Node.js version string.
16
+ *
17
+ * @param nodeVersion - a dot-separated version string such as `process.versions.node`
18
+ * (e.g. `"20.11.1"`). A leading `v` is not expected (Node does not include one here).
19
+ * @returns the major version as a number, or `NaN` if the string has no numeric leading segment.
20
+ */
21
+ export function parseMajorVersion(nodeVersion) {
22
+ return Number(nodeVersion.split('.')[0]);
23
+ }
24
+ /**
25
+ * Decide whether the given Node.js version is too old to run the CLI.
26
+ *
27
+ * A version is rejected only when its major number is a real value below
28
+ * {@link MIN_SUPPORTED_NODE_MAJOR}. An unparseable string yields `NaN`, which is
29
+ * treated as "do not reject" so the guard never blocks on a version string it
30
+ * cannot understand (the runtime would surface any real incompatibility itself).
31
+ *
32
+ * @param nodeVersion - a `process.versions.node` style string (e.g. `"18.19.1"`).
33
+ * @returns `true` when the runtime is below the supported floor and should be rejected.
34
+ */
35
+ export function shouldRejectNodeVersion(nodeVersion) {
36
+ const major = parseMajorVersion(nodeVersion);
37
+ return !Number.isNaN(major) && major < MIN_SUPPORTED_NODE_MAJOR;
38
+ }
39
+ //# sourceMappingURL=version-guard.js.map
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.2.0";
1
+ export declare const VERSION = "0.4.0";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // AUTO-GENERATED by scripts/generate-version.mjs — do not edit by hand.
2
2
  // Run `npm run build` (or `npm run generate:version`) to regenerate.
3
- export const VERSION = '0.2.0';
3
+ export const VERSION = '0.4.0';
4
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testsprite/testsprite-cli",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Official TestSprite command-line interface",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "test:e2e": "npm run build && vitest run -c vitest.e2e.config.ts"
29
29
  },
30
30
  "engines": {
31
- "node": ">=20"
31
+ "node": "^20.19.0 || ^22.13.0 || >=24"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
@@ -50,6 +50,7 @@
50
50
  "license": "Apache-2.0",
51
51
  "dependencies": {
52
52
  "commander": "^12.1.0",
53
+ "undici": "^7.16.0",
53
54
  "valibot": "^1.4.1"
54
55
  },
55
56
  "devDependencies": {
@@ -91,6 +91,27 @@ Each file is a COMPLETE plan and must include `projectId` (from step 2), `type:
91
91
  **Backend** — one `.py` file per endpoint, using `requests` with concrete assertions on
92
92
  status code and response body.
93
93
 
94
+ **Backend auth — read the injected `__AUTH_HEADERS__`, NEVER hardcode any credential.** This
95
+ covers **every** secret the API needs — Bearer/JWT tokens **and** API keys (`sk-…`,
96
+ `x-api-key`), basic-auth blobs, cookies. TestSprite prepends a managed credential block
97
+ (`__AUTH_CREDENTIAL__` / `__AUTH_TYPE__` / `__AUTH_HEADERS__`) to every backend test from the
98
+ project's Authentication settings, and `__AUTH_HEADERS__` already holds the right header(s) for
99
+ the configured type (Bearer → `{"Authorization": "Bearer …"}`; API key → `{"X-API-Key": "…"}`;
100
+ basic → `{"Authorization": "Basic …"}`). Spread it into your request headers — never paste a
101
+ literal `Bearer …` / `sk-…` / key value into the script:
102
+
103
+ ```python
104
+ r = requests.get(f"{TARGET_URL}/orders", headers={**__AUTH_HEADERS__})
105
+ ```
106
+
107
+ Configure the credential once on the project (ask the user for the value — never invent it or
108
+ reuse a key you happened to see): a static credential with
109
+ `testsprite project credential <projectId> --type "Bearer token"|"API key"|"basic token" --credential <value>`,
110
+ or an auto-refreshing login with `testsprite project auto-auth <projectId> …` so scheduled/repeat
111
+ runs keep working after the token expires. A hardcoded token expires within hours and a hardcoded
112
+ key can't be rotated centrally — `test create` emits a `[warn]` on an inlined credential; treat it
113
+ as a must-fix.
114
+
94
115
  **Assertion rule (this is the whole game for FE):** every `assertion` step must name a
95
116
  **concrete, observable** outcome — an element, text, URL, count, or status. Never write
96
117
  `"verify it works"`, `"check the page loads"`, or other narrative that an AI judge can
@@ -10,6 +10,12 @@ docs/config and is about to be reported complete.
10
10
  Run after a feature or fix lands. Skip only for: docs-only edits, pure
11
11
  build/config changes, or when the repo has no TestSprite project linked.
12
12
 
13
+ The CLI only tests a reachable deployed URL (it rejects localhost). If the
14
+ change is only running locally, hand off to the TestSprite MCP when it's
15
+ available — it tunnels your local server; otherwise report the change as
16
+ unverified-because-undeployed and stop. If the user explicitly named a tool
17
+ (the CLI or the MCP), honor that over this reachability heuristic.
18
+
13
19
  ## Core loop
14
20
 
15
21
  ### 1. Preflight