@testsprite/testsprite-cli 0.1.2 → 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.
- package/README.md +34 -26
- package/dist/commands/agent.d.ts +52 -0
- package/dist/commands/agent.js +341 -93
- package/dist/commands/auth.js +29 -27
- package/dist/commands/doctor.d.ts +49 -0
- package/dist/commands/doctor.js +211 -0
- package/dist/commands/init.d.ts +7 -1
- package/dist/commands/init.js +66 -26
- package/dist/commands/project.d.ts +50 -1
- package/dist/commands/project.js +257 -43
- package/dist/commands/test.d.ts +214 -12
- package/dist/commands/test.js +1310 -174
- package/dist/commands/usage.js +13 -12
- package/dist/index.js +71 -18
- package/dist/lib/agent-targets.d.ts +169 -22
- package/dist/lib/agent-targets.js +335 -34
- package/dist/lib/bundle.d.ts +51 -1
- package/dist/lib/bundle.js +146 -55
- package/dist/lib/client-factory.d.ts +43 -0
- package/dist/lib/client-factory.js +89 -2
- package/dist/lib/config.d.ts +2 -0
- package/dist/lib/config.js +11 -2
- package/dist/lib/credentials.d.ts +7 -0
- package/dist/lib/credentials.js +40 -1
- package/dist/lib/dry-run/samples.d.ts +5 -0
- package/dist/lib/dry-run/samples.js +54 -9
- package/dist/lib/flaky.d.ts +80 -0
- package/dist/lib/flaky.js +76 -0
- package/dist/lib/http.d.ts +20 -0
- package/dist/lib/http.js +216 -132
- package/dist/lib/interrupt.d.ts +61 -0
- package/dist/lib/interrupt.js +97 -0
- package/dist/lib/junit-report.d.ts +58 -0
- package/dist/lib/junit-report.js +210 -0
- package/dist/lib/output.d.ts +16 -1
- package/dist/lib/output.js +24 -2
- package/dist/lib/pagination.d.ts +4 -3
- package/dist/lib/pagination.js +34 -6
- package/dist/lib/prompt.js +52 -8
- package/dist/lib/proxy.d.ts +29 -0
- package/dist/lib/proxy.js +30 -0
- package/dist/lib/render-error.d.ts +13 -0
- package/dist/lib/render-error.js +30 -7
- package/dist/lib/skill-nudge.d.ts +2 -2
- package/dist/lib/skill-nudge.js +13 -4
- package/dist/lib/target-url.js +8 -1
- package/dist/lib/ticker.d.ts +11 -1
- package/dist/lib/ticker.js +33 -1
- package/dist/lib/update-check.d.ts +67 -0
- package/dist/lib/update-check.js +246 -0
- package/dist/version-guard.d.ts +33 -0
- package/dist/version-guard.js +39 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -2
- package/skills/testsprite-onboard.skill.md +183 -0
- package/skills/testsprite-verify.codex.md +2 -0
- package/skills/testsprite-verify.skill.md +52 -1
package/dist/lib/skill-nudge.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { MANAGED_SECTION_BEGIN, TARGETS } from './agent-targets.js';
|
|
3
|
+
import { MANAGED_SECTION_BEGIN, MANAGED_SECTION_END, TARGETS } from './agent-targets.js';
|
|
4
4
|
import { defaultCredentialsPath, readProfile } from './credentials.js';
|
|
5
5
|
/**
|
|
6
6
|
* Full command paths (group + leaf) that signal the caller is actively driving
|
|
@@ -35,8 +35,8 @@ export const SKILL_NUDGE_OPT_OUT_ENV = 'TESTSPRITE_NO_SKILL_WARNING';
|
|
|
35
35
|
* True if the `testsprite-verify` skill is installed for ANY supported agent in
|
|
36
36
|
* `dir`. own-file targets (claude/cursor/cline/antigravity): the landing file
|
|
37
37
|
* exists. managed-section target (codex / AGENTS.md): the file exists AND
|
|
38
|
-
* carries
|
|
39
|
-
* does NOT count as our skill.
|
|
38
|
+
* carries one complete managed section — a user-authored AGENTS.md without the
|
|
39
|
+
* sentinels, or with a truncated section, does NOT count as our skill.
|
|
40
40
|
*
|
|
41
41
|
* The TARGETS table is the single source of truth for landing paths, so this
|
|
42
42
|
* stays in lockstep with `agent install` without re-listing paths. Best-effort:
|
|
@@ -51,7 +51,7 @@ export function isVerifySkillInstalled(dir, deps = {}) {
|
|
|
51
51
|
continue;
|
|
52
52
|
if (spec.mode === 'managed-section') {
|
|
53
53
|
try {
|
|
54
|
-
if (read(full)
|
|
54
|
+
if (hasCompleteManagedSection(read(full)))
|
|
55
55
|
return true;
|
|
56
56
|
}
|
|
57
57
|
catch {
|
|
@@ -63,6 +63,14 @@ export function isVerifySkillInstalled(dir, deps = {}) {
|
|
|
63
63
|
}
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
|
+
/** True when a managed-section file contains an ordered TestSprite BEGIN/END pair. */
|
|
67
|
+
function hasCompleteManagedSection(content) {
|
|
68
|
+
const begin = content.indexOf(MANAGED_SECTION_BEGIN);
|
|
69
|
+
if (begin === -1)
|
|
70
|
+
return false;
|
|
71
|
+
const end = content.indexOf(MANAGED_SECTION_END, begin + MANAGED_SECTION_BEGIN.length);
|
|
72
|
+
return end !== -1;
|
|
73
|
+
}
|
|
66
74
|
/**
|
|
67
75
|
* Best-effort onboarding warning. When a configured caller drives a verify-loop
|
|
68
76
|
* command in a project that has NO installed skill, print a one-line `[warn]`
|
|
@@ -106,6 +114,7 @@ export function maybeEmitSkillNudge(ctx) {
|
|
|
106
114
|
// command. Swallow everything (missing creds file, fs races, etc.).
|
|
107
115
|
}
|
|
108
116
|
}
|
|
117
|
+
/** Interpret common env-var spellings for an enabled opt-out flag. */
|
|
109
118
|
function isTruthyEnv(v) {
|
|
110
119
|
if (v === undefined)
|
|
111
120
|
return false;
|
package/dist/lib/target-url.js
CHANGED
|
@@ -36,7 +36,14 @@ export function assertNotLocal(rawUrl) {
|
|
|
36
36
|
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
37
37
|
throw localTargetError('target-url', 'must use http or https scheme');
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
// Normalize a single trailing dot in the hostname. `localhost.` is the
|
|
40
|
+
// fully-qualified form of `localhost` (RFC 6761 reserves both to resolve to
|
|
41
|
+
// loopback), so `http://localhost.` must be rejected just like
|
|
42
|
+
// `http://localhost`. Without this strip, the trailing-dot form (also
|
|
43
|
+
// reachable via `localhost%2e`) slips past the `host === 'localhost'` check.
|
|
44
|
+
// IP literals are already dot-normalized by the WHATWG URL parser, so this
|
|
45
|
+
// only affects named hosts.
|
|
46
|
+
const host = parsed.hostname.toLowerCase().replace(/\.$/, '');
|
|
40
47
|
// Loopback / unspecified.
|
|
41
48
|
if (host === 'localhost' || host === '0.0.0.0') {
|
|
42
49
|
throw localTargetError('target-url', 'localhost targets are not allowed', LOCAL_DEV_HINT);
|
package/dist/lib/ticker.d.ts
CHANGED
|
@@ -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;
|
package/dist/lib/ticker.js
CHANGED
|
@@ -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.
|
|
1
|
+
export declare const VERSION = "0.3.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testsprite/testsprite-cli",
|
|
3
|
-
"version": "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": ">=
|
|
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": {
|