@testsprite/testsprite-cli 0.1.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/LICENSE +201 -0
- package/README.md +190 -0
- package/dist/assets/agent-skill/testsprite-verify.codex.md +119 -0
- package/dist/assets/agent-skill/testsprite-verify.skill.md +423 -0
- package/dist/commands/agent.d.ts +51 -0
- package/dist/commands/agent.js +552 -0
- package/dist/commands/auth.d.ts +38 -0
- package/dist/commands/auth.js +247 -0
- package/dist/commands/init.d.ts +63 -0
- package/dist/commands/init.js +350 -0
- package/dist/commands/project.d.ts +72 -0
- package/dist/commands/project.js +400 -0
- package/dist/commands/test.d.ts +1245 -0
- package/dist/commands/test.js +6214 -0
- package/dist/commands/usage.d.ts +63 -0
- package/dist/commands/usage.js +156 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +146 -0
- package/dist/lib/agent-targets.d.ts +50 -0
- package/dist/lib/agent-targets.js +99 -0
- package/dist/lib/bundle.d.ts +178 -0
- package/dist/lib/bundle.js +600 -0
- package/dist/lib/client-factory.d.ts +72 -0
- package/dist/lib/client-factory.js +120 -0
- package/dist/lib/config.d.ts +24 -0
- package/dist/lib/config.js +30 -0
- package/dist/lib/credentials.d.ts +17 -0
- package/dist/lib/credentials.js +122 -0
- package/dist/lib/dry-run/fetch.d.ts +18 -0
- package/dist/lib/dry-run/fetch.js +52 -0
- package/dist/lib/dry-run/samples.d.ts +50 -0
- package/dist/lib/dry-run/samples.js +676 -0
- package/dist/lib/errors.d.ts +118 -0
- package/dist/lib/errors.js +388 -0
- package/dist/lib/facade.d.ts +48 -0
- package/dist/lib/facade.js +104 -0
- package/dist/lib/failing-fe-resolver.d.ts +60 -0
- package/dist/lib/failing-fe-resolver.js +103 -0
- package/dist/lib/http.d.ts +255 -0
- package/dist/lib/http.js +608 -0
- package/dist/lib/output.d.ts +55 -0
- package/dist/lib/output.js +70 -0
- package/dist/lib/pagination.d.ts +56 -0
- package/dist/lib/pagination.js +81 -0
- package/dist/lib/poll.d.ts +88 -0
- package/dist/lib/poll.js +221 -0
- package/dist/lib/prompt.d.ts +8 -0
- package/dist/lib/prompt.js +97 -0
- package/dist/lib/rate-throttle.d.ts +49 -0
- package/dist/lib/rate-throttle.js +75 -0
- package/dist/lib/render-error.d.ts +15 -0
- package/dist/lib/render-error.js +44 -0
- package/dist/lib/runs.types.d.ts +344 -0
- package/dist/lib/runs.types.js +25 -0
- package/dist/lib/target-url.d.ts +25 -0
- package/dist/lib/target-url.js +127 -0
- package/dist/lib/ticker.d.ts +37 -0
- package/dist/lib/ticker.js +63 -0
- package/dist/lib/validate.d.ts +82 -0
- package/dist/lib/validate.js +165 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/package.json +65 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TTY-gated single-line stderr progress ticker for `test run --wait`
|
|
3
|
+
* and `test wait`. On non-TTY (CI) the ticker is completely silent —
|
|
4
|
+
* logs stay clean for shell-script consumers.
|
|
5
|
+
*
|
|
6
|
+
* Behavior:
|
|
7
|
+
* - Updates on every poll
|
|
8
|
+
* - Uses `\r` + ANSI clear-line to overwrite in place on TTY
|
|
9
|
+
* - On terminal, emits one final line + newline then prints the result
|
|
10
|
+
* - `--output json` disables the ticker (caller doesn't create one)
|
|
11
|
+
*
|
|
12
|
+
* Overhead: <2ms per update (no syscalls beyond a single write).
|
|
13
|
+
*
|
|
14
|
+
* Timestamps: each tick prefixes an ISO 8601 timestamp so engineers
|
|
15
|
+
* can correlate spinner output with --debug logs (dogfood item 2).
|
|
16
|
+
*/
|
|
17
|
+
export interface Ticker {
|
|
18
|
+
/** Update the in-place progress line. No-op on non-TTY. */
|
|
19
|
+
update(line: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Print the final line (with a trailing newline so the prompt
|
|
22
|
+
* doesn't run into the result block). No-op on non-TTY.
|
|
23
|
+
*/
|
|
24
|
+
finalize(line?: string): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a ticker bound to the given stderr writer. Respects
|
|
28
|
+
* `isTTY` to silently no-op in CI environments.
|
|
29
|
+
*
|
|
30
|
+
* @param stderrWrite - single-line writer (appends \n)
|
|
31
|
+
* @param isTTY - whether the terminal supports in-place updates.
|
|
32
|
+
* Defaults to `process.stderr.isTTY`. Pass a boolean in tests.
|
|
33
|
+
* @param stderrRaw - optional raw writer (no \n appended); used for
|
|
34
|
+
* the carriage-return + clear-line trick. Defaults to
|
|
35
|
+
* `process.stderr.write.bind(process.stderr)`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createTicker(stderrWrite: (line: string) => void, isTTY?: boolean, stderrRaw?: (text: string) => void): Ticker;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TTY-gated single-line stderr progress ticker for `test run --wait`
|
|
3
|
+
* and `test wait`. On non-TTY (CI) the ticker is completely silent —
|
|
4
|
+
* logs stay clean for shell-script consumers.
|
|
5
|
+
*
|
|
6
|
+
* Behavior:
|
|
7
|
+
* - Updates on every poll
|
|
8
|
+
* - Uses `\r` + ANSI clear-line to overwrite in place on TTY
|
|
9
|
+
* - On terminal, emits one final line + newline then prints the result
|
|
10
|
+
* - `--output json` disables the ticker (caller doesn't create one)
|
|
11
|
+
*
|
|
12
|
+
* Overhead: <2ms per update (no syscalls beyond a single write).
|
|
13
|
+
*
|
|
14
|
+
* Timestamps: each tick prefixes an ISO 8601 timestamp so engineers
|
|
15
|
+
* can correlate spinner output with --debug logs (dogfood item 2).
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Create a ticker bound to the given stderr writer. Respects
|
|
19
|
+
* `isTTY` to silently no-op in CI environments.
|
|
20
|
+
*
|
|
21
|
+
* @param stderrWrite - single-line writer (appends \n)
|
|
22
|
+
* @param isTTY - whether the terminal supports in-place updates.
|
|
23
|
+
* Defaults to `process.stderr.isTTY`. Pass a boolean in tests.
|
|
24
|
+
* @param stderrRaw - optional raw writer (no \n appended); used for
|
|
25
|
+
* the carriage-return + clear-line trick. Defaults to
|
|
26
|
+
* `process.stderr.write.bind(process.stderr)`.
|
|
27
|
+
*/
|
|
28
|
+
export function createTicker(stderrWrite, isTTY, stderrRaw) {
|
|
29
|
+
const tty = isTTY ?? (typeof process !== 'undefined' ? process.stderr.isTTY === true : false);
|
|
30
|
+
const rawWrite = stderrRaw ??
|
|
31
|
+
(typeof process !== 'undefined'
|
|
32
|
+
? (text) => process.stderr.write(text)
|
|
33
|
+
: (_text) => undefined);
|
|
34
|
+
let lastLength = 0;
|
|
35
|
+
if (!tty) {
|
|
36
|
+
// Non-TTY: completely silent.
|
|
37
|
+
return {
|
|
38
|
+
update: () => undefined,
|
|
39
|
+
finalize: () => undefined,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
update(line) {
|
|
44
|
+
// ANSI ESC[2K clears the entire line; \r moves to column 0.
|
|
45
|
+
const stamped = `${new Date().toISOString()} ${line}`;
|
|
46
|
+
rawWrite(`\x1b[2K\r${stamped}`);
|
|
47
|
+
lastLength = stamped.length;
|
|
48
|
+
},
|
|
49
|
+
finalize(line) {
|
|
50
|
+
if (line !== undefined) {
|
|
51
|
+
const stamped = `${new Date().toISOString()} ${line}`;
|
|
52
|
+
rawWrite(`\x1b[2K\r${stamped}`);
|
|
53
|
+
lastLength = stamped.length;
|
|
54
|
+
}
|
|
55
|
+
if (lastLength > 0) {
|
|
56
|
+
// Move to a fresh line so the result block doesn't run into the ticker.
|
|
57
|
+
rawWrite('\n');
|
|
58
|
+
}
|
|
59
|
+
void stderrWrite; // reference to suppress unused warning
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=ticker.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Shared option bag for helpers that accept both flag and field paths. */
|
|
2
|
+
interface KindOpts {
|
|
3
|
+
/** Controls how `nextAction` is phrased in the error envelope. */
|
|
4
|
+
kind?: 'flag' | 'field';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Assert that `value` is a string, throwing a typed VALIDATION_ERROR
|
|
8
|
+
* envelope on failure.
|
|
9
|
+
*
|
|
10
|
+
* @param field Field name (used in the error envelope `details.field`
|
|
11
|
+
* and the `nextAction` line).
|
|
12
|
+
* @param value The raw value to check.
|
|
13
|
+
* @param opts.kind `'field'` (default) or `'flag'`.
|
|
14
|
+
* @param opts.minLength When set, rejects strings shorter than this length
|
|
15
|
+
* (default: 1, i.e. non-empty unless allowEmpty).
|
|
16
|
+
* @param opts.maxLength When set, rejects strings longer than this length.
|
|
17
|
+
* @param opts.allowEmpty When `true`, a zero-length string is accepted.
|
|
18
|
+
* Overrides `minLength` — if both are set, the string
|
|
19
|
+
* is accepted as long as it is a string (length ≥ 0).
|
|
20
|
+
* Defaults to `false`. Whitespace-only strings (e.g.
|
|
21
|
+
* `" "`) are treated as empty when `allowEmpty` is
|
|
22
|
+
* false — they are rejected the same as `""` so junk
|
|
23
|
+
* records cannot reach the backend (dogfood P1 fix).
|
|
24
|
+
*/
|
|
25
|
+
export declare function requireString(field: string, value: unknown, opts?: KindOpts & {
|
|
26
|
+
minLength?: number;
|
|
27
|
+
maxLength?: number;
|
|
28
|
+
allowEmpty?: boolean;
|
|
29
|
+
}): asserts value is string;
|
|
30
|
+
/**
|
|
31
|
+
* Assert that `value` is one of the accepted enum members, throwing a
|
|
32
|
+
* typed VALIDATION_ERROR envelope on failure.
|
|
33
|
+
*
|
|
34
|
+
* The error message format is:
|
|
35
|
+
* `must be one of: "v1", "v2", ...`
|
|
36
|
+
*
|
|
37
|
+
* with each accepted value quoted, comma-separated. This is the canonical
|
|
38
|
+
* format for agent-facing JSON paths (dogfood L625 option 2).
|
|
39
|
+
*
|
|
40
|
+
* @param field Field name used in the error envelope.
|
|
41
|
+
* @param value The raw value to check.
|
|
42
|
+
* @param accepted Tuple/array of the accepted string literals.
|
|
43
|
+
* @param opts.kind `'field'` (default) or `'flag'`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function requireEnum<T extends string>(field: string, value: unknown, accepted: readonly T[], opts?: KindOpts): asserts value is T;
|
|
46
|
+
/**
|
|
47
|
+
* Validate a caller-supplied `--idempotency-key` value before it is sent as
|
|
48
|
+
* an HTTP header. The HTTP spec (RFC 7230) requires header values to be ASCII
|
|
49
|
+
* printable characters (0x21–0x7E plus SP/HTAB). A value that contains
|
|
50
|
+
* non-ASCII bytes causes Node's `fetch` to throw a `TypeError: ByteString`
|
|
51
|
+
* exception at the transport layer, which surfaces as an opaque exit 10
|
|
52
|
+
* UNAVAILABLE — completely unhelpful for the operator (dogfood P1 fix #2).
|
|
53
|
+
*
|
|
54
|
+
* Client-side rules enforced here:
|
|
55
|
+
* - 1–256 characters (inclusive)
|
|
56
|
+
* - All characters must be in the ASCII printable range (0x20–0x7E)
|
|
57
|
+
*
|
|
58
|
+
* On rejection throws a `VALIDATION_ERROR` (exit 5) with a clear message.
|
|
59
|
+
* On `undefined` (auto-generated key path) this is a no-op.
|
|
60
|
+
*
|
|
61
|
+
* @param key The raw flag value, or `undefined` when the key is auto-minted.
|
|
62
|
+
*/
|
|
63
|
+
export declare function assertIdempotencyKey(key: string | undefined): void;
|
|
64
|
+
/**
|
|
65
|
+
* Assert that `arr` is an Array and that its length is within the given
|
|
66
|
+
* bounds, throwing a typed VALIDATION_ERROR envelope on failure.
|
|
67
|
+
*
|
|
68
|
+
* @param field Field name used in the error envelope.
|
|
69
|
+
* @param arr The raw value to check.
|
|
70
|
+
* @param opts.min Minimum length (inclusive). Defaults to 0.
|
|
71
|
+
* @param opts.max Maximum length (inclusive). Omit for no upper cap.
|
|
72
|
+
* @param opts.kind `'field'` (default) or `'flag'`.
|
|
73
|
+
* @param opts.itemNoun Singular noun used in min/max messages (e.g. `'step'`).
|
|
74
|
+
* Defaults to `'item'`. The helper pluralises to `<noun>s`
|
|
75
|
+
* for the max message.
|
|
76
|
+
*/
|
|
77
|
+
export declare function requireArrayLength(field: string, arr: unknown, opts: KindOpts & {
|
|
78
|
+
min?: number;
|
|
79
|
+
max?: number;
|
|
80
|
+
itemNoun?: string;
|
|
81
|
+
}): asserts arr is unknown[];
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin internal validation helpers shared across JSON-body validation
|
|
3
|
+
* paths (assertPlanShape, assertPlanStepsShape, and future agent-facing
|
|
4
|
+
* JSON input). Implemented with valibot (tree-shakeable, ~1.5 KB gzipped)
|
|
5
|
+
* for structural detection; error envelope construction delegates to the
|
|
6
|
+
* existing `localValidationError` helper so wording and exit codes stay
|
|
7
|
+
* consistent with the rest of the CLI.
|
|
8
|
+
*
|
|
9
|
+
* Design notes:
|
|
10
|
+
* - `kind` defaults to `'field'` on every helper because these are all
|
|
11
|
+
* JSON body paths, not CLI flags. Pass `kind: 'flag'` when validating
|
|
12
|
+
* a real `--flag` value (e.g. in runList / runCreate input guards).
|
|
13
|
+
* - These helpers are assertion-style (`asserts value is T`) so
|
|
14
|
+
* TypeScript narrows the type at the call site without a cast.
|
|
15
|
+
* - Valibot is used purely as the structural detector (safeParse). Custom
|
|
16
|
+
* message strings are composed here so error envelope text matches the
|
|
17
|
+
* legacy inline checks byte-for-byte — never valibot's built-in messages.
|
|
18
|
+
* - Implements dogfood L625 option 2: valibot adoption on the plan-input
|
|
19
|
+
* path. Future schemas can use raw `v.object({...})` directly when
|
|
20
|
+
* more complex shape validation is needed.
|
|
21
|
+
*
|
|
22
|
+
* Precedence rules (documented here to prevent ambiguity):
|
|
23
|
+
* - `allowEmpty: true` overrides `minLength` — if `allowEmpty` is set,
|
|
24
|
+
* a zero-length string is always accepted regardless of `minLength`.
|
|
25
|
+
* - `allowEmpty: true` and `minLength > 0` are mutually exclusive in
|
|
26
|
+
* intent; the type system permits both but `allowEmpty` wins.
|
|
27
|
+
*/
|
|
28
|
+
import * as v from 'valibot';
|
|
29
|
+
import { localValidationError } from './errors.js';
|
|
30
|
+
/**
|
|
31
|
+
* Assert that `value` is a string, throwing a typed VALIDATION_ERROR
|
|
32
|
+
* envelope on failure.
|
|
33
|
+
*
|
|
34
|
+
* @param field Field name (used in the error envelope `details.field`
|
|
35
|
+
* and the `nextAction` line).
|
|
36
|
+
* @param value The raw value to check.
|
|
37
|
+
* @param opts.kind `'field'` (default) or `'flag'`.
|
|
38
|
+
* @param opts.minLength When set, rejects strings shorter than this length
|
|
39
|
+
* (default: 1, i.e. non-empty unless allowEmpty).
|
|
40
|
+
* @param opts.maxLength When set, rejects strings longer than this length.
|
|
41
|
+
* @param opts.allowEmpty When `true`, a zero-length string is accepted.
|
|
42
|
+
* Overrides `minLength` — if both are set, the string
|
|
43
|
+
* is accepted as long as it is a string (length ≥ 0).
|
|
44
|
+
* Defaults to `false`. Whitespace-only strings (e.g.
|
|
45
|
+
* `" "`) are treated as empty when `allowEmpty` is
|
|
46
|
+
* false — they are rejected the same as `""` so junk
|
|
47
|
+
* records cannot reach the backend (dogfood P1 fix).
|
|
48
|
+
*/
|
|
49
|
+
export function requireString(field, value, opts = {}) {
|
|
50
|
+
const { kind = 'field', allowEmpty = false, minLength, maxLength } = opts;
|
|
51
|
+
// Structural check: must be a string.
|
|
52
|
+
const typeResult = v.safeParse(v.string(), value);
|
|
53
|
+
if (!typeResult.success) {
|
|
54
|
+
throw localValidationError(field, 'is required and must be a non-empty string', undefined, kind);
|
|
55
|
+
}
|
|
56
|
+
// Whitespace-only rejection: a string composed solely of spaces/tabs/
|
|
57
|
+
// newlines is treated as empty unless `allowEmpty` is set. This catches
|
|
58
|
+
// cases like `--name " "` that pass the type check but produce junk
|
|
59
|
+
// records in the backend (dogfood P1 fix #1).
|
|
60
|
+
if (!allowEmpty && typeof value === 'string' && value.trim().length === 0 && value.length > 0) {
|
|
61
|
+
throw localValidationError(field, 'is required and must be a non-empty string', undefined, kind);
|
|
62
|
+
}
|
|
63
|
+
// Length lower bound. `allowEmpty` overrides `minLength` per the
|
|
64
|
+
// documented precedence above.
|
|
65
|
+
const effectiveMin = allowEmpty ? 0 : (minLength ?? 1);
|
|
66
|
+
if (effectiveMin > 0) {
|
|
67
|
+
const minResult = v.safeParse(v.pipe(v.string(), v.minLength(effectiveMin)), value);
|
|
68
|
+
if (!minResult.success) {
|
|
69
|
+
throw localValidationError(field, 'is required and must be a non-empty string', undefined, kind);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Length upper bound.
|
|
73
|
+
if (maxLength !== undefined) {
|
|
74
|
+
const maxResult = v.safeParse(v.pipe(v.string(), v.maxLength(maxLength)), value);
|
|
75
|
+
if (!maxResult.success) {
|
|
76
|
+
throw localValidationError(field, `must be at most ${maxLength} characters`, undefined, kind);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Assert that `value` is one of the accepted enum members, throwing a
|
|
82
|
+
* typed VALIDATION_ERROR envelope on failure.
|
|
83
|
+
*
|
|
84
|
+
* The error message format is:
|
|
85
|
+
* `must be one of: "v1", "v2", ...`
|
|
86
|
+
*
|
|
87
|
+
* with each accepted value quoted, comma-separated. This is the canonical
|
|
88
|
+
* format for agent-facing JSON paths (dogfood L625 option 2).
|
|
89
|
+
*
|
|
90
|
+
* @param field Field name used in the error envelope.
|
|
91
|
+
* @param value The raw value to check.
|
|
92
|
+
* @param accepted Tuple/array of the accepted string literals.
|
|
93
|
+
* @param opts.kind `'field'` (default) or `'flag'`.
|
|
94
|
+
*/
|
|
95
|
+
export function requireEnum(field, value, accepted, opts = {}) {
|
|
96
|
+
const { kind = 'field' } = opts;
|
|
97
|
+
// Use valibot picklist for structural detection. Custom message is
|
|
98
|
+
// composed here so the envelope text is explicit and stable.
|
|
99
|
+
const result = v.safeParse(v.picklist(accepted), value);
|
|
100
|
+
if (!result.success) {
|
|
101
|
+
const acceptedList = accepted.map(a => `"${a}"`).join(', ');
|
|
102
|
+
throw localValidationError(field, `must be one of: ${acceptedList}`, [...accepted], kind);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Validate a caller-supplied `--idempotency-key` value before it is sent as
|
|
107
|
+
* an HTTP header. The HTTP spec (RFC 7230) requires header values to be ASCII
|
|
108
|
+
* printable characters (0x21–0x7E plus SP/HTAB). A value that contains
|
|
109
|
+
* non-ASCII bytes causes Node's `fetch` to throw a `TypeError: ByteString`
|
|
110
|
+
* exception at the transport layer, which surfaces as an opaque exit 10
|
|
111
|
+
* UNAVAILABLE — completely unhelpful for the operator (dogfood P1 fix #2).
|
|
112
|
+
*
|
|
113
|
+
* Client-side rules enforced here:
|
|
114
|
+
* - 1–256 characters (inclusive)
|
|
115
|
+
* - All characters must be in the ASCII printable range (0x20–0x7E)
|
|
116
|
+
*
|
|
117
|
+
* On rejection throws a `VALIDATION_ERROR` (exit 5) with a clear message.
|
|
118
|
+
* On `undefined` (auto-generated key path) this is a no-op.
|
|
119
|
+
*
|
|
120
|
+
* @param key The raw flag value, or `undefined` when the key is auto-minted.
|
|
121
|
+
*/
|
|
122
|
+
export function assertIdempotencyKey(key) {
|
|
123
|
+
if (key === undefined)
|
|
124
|
+
return;
|
|
125
|
+
// ASCII-printable check: every codepoint must be in U+0020–U+007E (space through tilde).
|
|
126
|
+
// Non-ASCII chars (codepoint > 127) trigger a TypeError in Node's fetch ByteString header.
|
|
127
|
+
if (key.length === 0 || !/^[ -~]+$/.test(key)) {
|
|
128
|
+
throw localValidationError('idempotencyKey', 'must be 1–256 printable ASCII characters (no non-ASCII, control chars, or empty string)', undefined, 'flag');
|
|
129
|
+
}
|
|
130
|
+
if (key.length > 256) {
|
|
131
|
+
throw localValidationError('idempotencyKey', 'must be at most 256 characters', undefined, 'flag');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Assert that `arr` is an Array and that its length is within the given
|
|
136
|
+
* bounds, throwing a typed VALIDATION_ERROR envelope on failure.
|
|
137
|
+
*
|
|
138
|
+
* @param field Field name used in the error envelope.
|
|
139
|
+
* @param arr The raw value to check.
|
|
140
|
+
* @param opts.min Minimum length (inclusive). Defaults to 0.
|
|
141
|
+
* @param opts.max Maximum length (inclusive). Omit for no upper cap.
|
|
142
|
+
* @param opts.kind `'field'` (default) or `'flag'`.
|
|
143
|
+
* @param opts.itemNoun Singular noun used in min/max messages (e.g. `'step'`).
|
|
144
|
+
* Defaults to `'item'`. The helper pluralises to `<noun>s`
|
|
145
|
+
* for the max message.
|
|
146
|
+
*/
|
|
147
|
+
export function requireArrayLength(field, arr, opts) {
|
|
148
|
+
const { kind = 'field', min = 0, max, itemNoun = 'item' } = opts;
|
|
149
|
+
// Structural check: must be an array.
|
|
150
|
+
const typeResult = v.safeParse(v.array(v.unknown()), arr);
|
|
151
|
+
if (!typeResult.success) {
|
|
152
|
+
throw localValidationError(field, 'is required and must be an array', undefined, kind);
|
|
153
|
+
}
|
|
154
|
+
const arrVal = arr;
|
|
155
|
+
// Lower bound.
|
|
156
|
+
if (arrVal.length < min) {
|
|
157
|
+
const minLabel = min === 1 ? `one ${itemNoun}` : `${min} ${itemNoun}s`;
|
|
158
|
+
throw localValidationError(field, `must contain at least ${minLabel}`, undefined, kind);
|
|
159
|
+
}
|
|
160
|
+
// Upper bound.
|
|
161
|
+
if (max !== undefined && arrVal.length > max) {
|
|
162
|
+
throw localValidationError(field, `must contain at most ${max} ${itemNoun}s (got ${arrVal.length})`, undefined, kind);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "0.1.0";
|
package/dist/version.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@testsprite/testsprite-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official TestSprite command-line interface",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"testsprite": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"!dist/**/*.map"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.build.json && node scripts/postbuild.mjs",
|
|
16
|
+
"clean": "rm -rf dist coverage",
|
|
17
|
+
"lint": "eslint .",
|
|
18
|
+
"lint:fix": "eslint . --fix",
|
|
19
|
+
"format": "prettier --write .",
|
|
20
|
+
"format:check": "prettier --check .",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"test:coverage": "vitest run --coverage",
|
|
25
|
+
"test:e2e": "npm run build && vitest run -c vitest.e2e.config.ts"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/TestSprite/testsprite-cli.git"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/TestSprite/testsprite-cli/issues"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"testsprite",
|
|
42
|
+
"cli",
|
|
43
|
+
"testing",
|
|
44
|
+
"automation"
|
|
45
|
+
],
|
|
46
|
+
"author": "TestSprite team",
|
|
47
|
+
"license": "Apache-2.0",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"commander": "^12.1.0",
|
|
50
|
+
"valibot": "^1.4.1"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@eslint/js": "^9.14.0",
|
|
54
|
+
"@types/node": "^22.9.0",
|
|
55
|
+
"@vitest/coverage-v8": "^2.1.4",
|
|
56
|
+
"eslint": "^9.14.0",
|
|
57
|
+
"eslint-config-prettier": "^9.1.0",
|
|
58
|
+
"globals": "^15.12.0",
|
|
59
|
+
"msw": "^2.14.3",
|
|
60
|
+
"prettier": "^3.3.3",
|
|
61
|
+
"typescript": "^5.6.3",
|
|
62
|
+
"typescript-eslint": "^8.13.0",
|
|
63
|
+
"vitest": "^2.1.4"
|
|
64
|
+
}
|
|
65
|
+
}
|