@testsprite/testsprite-cli 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +34 -26
  2. package/dist/commands/agent.d.ts +43 -0
  3. package/dist/commands/agent.js +200 -18
  4. package/dist/commands/auth.js +29 -27
  5. package/dist/commands/doctor.d.ts +49 -0
  6. package/dist/commands/doctor.js +211 -0
  7. package/dist/commands/init.d.ts +1 -1
  8. package/dist/commands/init.js +24 -14
  9. package/dist/commands/project.d.ts +50 -1
  10. package/dist/commands/project.js +252 -43
  11. package/dist/commands/test.d.ts +188 -1
  12. package/dist/commands/test.js +1088 -81
  13. package/dist/commands/usage.js +13 -12
  14. package/dist/index.js +33 -2
  15. package/dist/lib/agent-targets.d.ts +72 -6
  16. package/dist/lib/agent-targets.js +188 -6
  17. package/dist/lib/bundle.d.ts +34 -0
  18. package/dist/lib/bundle.js +44 -10
  19. package/dist/lib/client-factory.d.ts +25 -0
  20. package/dist/lib/client-factory.js +47 -0
  21. package/dist/lib/config.d.ts +2 -0
  22. package/dist/lib/config.js +11 -2
  23. package/dist/lib/credentials.js +10 -1
  24. package/dist/lib/dry-run/samples.d.ts +5 -0
  25. package/dist/lib/dry-run/samples.js +28 -0
  26. package/dist/lib/flaky.d.ts +80 -0
  27. package/dist/lib/flaky.js +76 -0
  28. package/dist/lib/http.d.ts +20 -0
  29. package/dist/lib/http.js +216 -132
  30. package/dist/lib/interrupt.d.ts +61 -0
  31. package/dist/lib/interrupt.js +97 -0
  32. package/dist/lib/junit-report.d.ts +58 -0
  33. package/dist/lib/junit-report.js +210 -0
  34. package/dist/lib/output.d.ts +16 -1
  35. package/dist/lib/output.js +24 -2
  36. package/dist/lib/pagination.d.ts +4 -3
  37. package/dist/lib/pagination.js +34 -6
  38. package/dist/lib/prompt.js +52 -8
  39. package/dist/lib/proxy.d.ts +29 -0
  40. package/dist/lib/proxy.js +30 -0
  41. package/dist/lib/render-error.js +3 -1
  42. package/dist/lib/skill-nudge.d.ts +2 -2
  43. package/dist/lib/skill-nudge.js +13 -4
  44. package/dist/lib/target-url.js +8 -1
  45. package/dist/lib/ticker.d.ts +11 -1
  46. package/dist/lib/ticker.js +33 -1
  47. package/dist/lib/update-check.d.ts +67 -0
  48. package/dist/lib/update-check.js +246 -0
  49. package/dist/version-guard.d.ts +33 -0
  50. package/dist/version-guard.js +39 -0
  51. package/dist/version.d.ts +1 -1
  52. package/dist/version.js +1 -1
  53. package/package.json +3 -2
  54. package/skills/testsprite-onboard.skill.md +21 -0
  55. package/skills/testsprite-verify.skill.md +33 -0
@@ -8,6 +8,9 @@
8
8
  * - Uses `\r` + ANSI clear-line to overwrite in place on TTY
9
9
  * - On terminal, emits one final line + newline then prints the result
10
10
  * - `--output json` disables the ticker (caller doesn't create one)
11
+ * - Respects the NO_COLOR env var (https://no-color.org/): when set,
12
+ * ANSI escape sequences are suppressed and updates are emitted as
13
+ * plain lines instead of in-place overwrites.
11
14
  *
12
15
  * Overhead: <2ms per update (no syscalls beyond a single write).
13
16
  *
@@ -23,6 +26,11 @@ export interface Ticker {
23
26
  */
24
27
  finalize(line?: string): void;
25
28
  }
29
+ /**
30
+ * Returns true when NO_COLOR is present in the environment and is not
31
+ * an empty string, per https://no-color.org/.
32
+ */
33
+ export declare function isNoColor(env?: NodeJS.ProcessEnv): boolean;
26
34
  /**
27
35
  * Create a ticker bound to the given stderr writer. Respects
28
36
  * `isTTY` to silently no-op in CI environments.
@@ -33,5 +41,7 @@ export interface Ticker {
33
41
  * @param stderrRaw - optional raw writer (no \n appended); used for
34
42
  * the carriage-return + clear-line trick. Defaults to
35
43
  * `process.stderr.write.bind(process.stderr)`.
44
+ * @param noColor - whether to suppress ANSI escape sequences.
45
+ * Defaults to checking `NO_COLOR` env var per https://no-color.org/.
36
46
  */
37
- export declare function createTicker(stderrWrite: (line: string) => void, isTTY?: boolean, stderrRaw?: (text: string) => void): Ticker;
47
+ export declare function createTicker(stderrWrite: (line: string) => void, isTTY?: boolean, stderrRaw?: (text: string) => void, noColor?: boolean): Ticker;
@@ -8,12 +8,23 @@
8
8
  * - Uses `\r` + ANSI clear-line to overwrite in place on TTY
9
9
  * - On terminal, emits one final line + newline then prints the result
10
10
  * - `--output json` disables the ticker (caller doesn't create one)
11
+ * - Respects the NO_COLOR env var (https://no-color.org/): when set,
12
+ * ANSI escape sequences are suppressed and updates are emitted as
13
+ * plain lines instead of in-place overwrites.
11
14
  *
12
15
  * Overhead: <2ms per update (no syscalls beyond a single write).
13
16
  *
14
17
  * Timestamps: each tick prefixes an ISO 8601 timestamp so engineers
15
18
  * can correlate spinner output with --debug logs (dogfood item 2).
16
19
  */
20
+ /**
21
+ * Returns true when NO_COLOR is present in the environment and is not
22
+ * an empty string, per https://no-color.org/.
23
+ */
24
+ export function isNoColor(env = process.env) {
25
+ const value = env.NO_COLOR;
26
+ return typeof value === 'string' && value.length > 0;
27
+ }
17
28
  /**
18
29
  * Create a ticker bound to the given stderr writer. Respects
19
30
  * `isTTY` to silently no-op in CI environments.
@@ -24,13 +35,16 @@
24
35
  * @param stderrRaw - optional raw writer (no \n appended); used for
25
36
  * the carriage-return + clear-line trick. Defaults to
26
37
  * `process.stderr.write.bind(process.stderr)`.
38
+ * @param noColor - whether to suppress ANSI escape sequences.
39
+ * Defaults to checking `NO_COLOR` env var per https://no-color.org/.
27
40
  */
28
- export function createTicker(stderrWrite, isTTY, stderrRaw) {
41
+ export function createTicker(stderrWrite, isTTY, stderrRaw, noColor) {
29
42
  const tty = isTTY ?? (typeof process !== 'undefined' ? process.stderr.isTTY === true : false);
30
43
  const rawWrite = stderrRaw ??
31
44
  (typeof process !== 'undefined'
32
45
  ? (text) => process.stderr.write(text)
33
46
  : (_text) => undefined);
47
+ const suppressAnsi = noColor ?? isNoColor();
34
48
  let lastLength = 0;
35
49
  if (!tty) {
36
50
  // Non-TTY: completely silent.
@@ -39,6 +53,24 @@ export function createTicker(stderrWrite, isTTY, stderrRaw) {
39
53
  finalize: () => undefined,
40
54
  };
41
55
  }
56
+ if (suppressAnsi) {
57
+ // TTY but NO_COLOR: emit plain-text lines without ANSI escape sequences.
58
+ return {
59
+ update(line) {
60
+ const stamped = `${new Date().toISOString()} ${line}`;
61
+ stderrWrite(stamped);
62
+ lastLength = stamped.length;
63
+ },
64
+ finalize(line) {
65
+ if (line !== undefined) {
66
+ const stamped = `${new Date().toISOString()} ${line}`;
67
+ stderrWrite(stamped);
68
+ lastLength = stamped.length;
69
+ }
70
+ void stderrWrite;
71
+ },
72
+ };
73
+ }
42
74
  return {
43
75
  update(line) {
44
76
  // ANSI ESC[2K clears the entire line; \r moves to column 0.
@@ -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,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.3.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.3.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.3.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
@@ -165,6 +165,39 @@ only the Python **standard library + `requests` + `pytest` + `numpy` + `scipy`**
165
165
  - Get values from the API's responses (and captured variables), not by importing and
166
166
  calling the app's internals.
167
167
 
168
+ **Authentication — read the injected credential, NEVER hardcode any credential.** This
169
+ applies to **every** secret the API needs — Bearer/JWT tokens **and** API keys, basic-auth
170
+ blobs, session cookies. Do not paste a literal `Bearer …`, `sk-…`, `x-api-key` value, or any
171
+ other credential into the test. Before your script runs, TestSprite prepends a managed
172
+ credential block built from the project's Authentication settings, and `__AUTH_HEADERS__`
173
+ already contains the right header(s) for the configured auth type:
174
+
175
+ ```python
176
+ # Auto-injected credentials — do not modify
177
+ __AUTH_CREDENTIAL__ = "..."
178
+ __AUTH_TYPE__ = "Bearer token" # or "API key" / "basic token" / "public"
179
+ __AUTH_HEADERS__ = {"Authorization": "Bearer ..."} # API key → {"X-API-Key": "..."}; basic → {"Authorization": "Basic ..."}
180
+ ```
181
+
182
+ Spread `__AUTH_HEADERS__` into every authenticated request — it adapts to whatever auth type
183
+ the project is configured for, so the same line works for Bearer, API-key, or basic auth:
184
+
185
+ ```python
186
+ r = requests.get(f"{TARGET_URL}/profile", headers={**__AUTH_HEADERS__})
187
+ ```
188
+
189
+ Configure the credential **once on the project** (ask the user for the value — never invent
190
+ or reuse a key you happened to see), and the block stays correct + refreshable:
191
+
192
+ - **Bearer / API key / basic (static):**
193
+ `testsprite project credential <projectId> --type "Bearer token"|"API key"|"basic token" --credential <value>`
194
+ - **Auto-refreshing login (recurring token):** `testsprite project auto-auth <projectId> …`
195
+
196
+ A hardcoded token expires within hours (and a hardcoded key can't be rotated centrally), so
197
+ the test breaks on later runs; the managed block is rewritten with a fresh value each run.
198
+ `test create` emits a `[warn]` when it detects an inlined credential literal — treat that as
199
+ a must-fix, not a nuisance.
200
+
168
201
  **Backend tests that share state declare dependencies at create time.** For a
169
202
  one-off verification, prefer a single self-contained script (log in inside the
170
203
  same file). But when the coverage set splits naturally into producer → consumer