@testsprite/testsprite-cli 0.10.0 → 0.12.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 +65 -41
- package/dist/commands/auth.d.ts +5 -1
- package/dist/commands/auth.js +17 -5
- package/dist/commands/ci.js +34 -4
- package/dist/commands/init.d.ts +6 -1
- package/dist/commands/init.js +13 -5
- package/dist/commands/project-env.d.ts +90 -0
- package/dist/commands/project-env.js +486 -0
- package/dist/commands/project.d.ts +19 -0
- package/dist/commands/project.js +92 -25
- package/dist/commands/test.d.ts +42 -4
- package/dist/commands/test.js +344 -49
- package/dist/commands/testlist.js +29 -3
- package/dist/commands/tunnel.d.ts +2 -2
- package/dist/commands/tunnel.js +139 -31
- package/dist/index.js +42 -14
- package/dist/lib/client-factory.d.ts +4 -1
- package/dist/lib/client-factory.js +14 -4
- package/dist/lib/client-tag.d.ts +13 -0
- package/dist/lib/client-tag.js +44 -0
- package/dist/lib/conflict-reason.d.ts +43 -2
- package/dist/lib/conflict-reason.js +100 -14
- package/dist/lib/credentials.d.ts +4 -0
- package/dist/lib/credentials.js +43 -4
- package/dist/lib/cron.js +8 -1
- package/dist/lib/errors.d.ts +44 -1
- package/dist/lib/errors.js +69 -12
- package/dist/lib/gh-output.d.ts +25 -11
- package/dist/lib/gh-output.js +36 -13
- package/dist/lib/http.d.ts +21 -2
- package/dist/lib/http.js +45 -8
- package/dist/lib/local-target.d.ts +32 -0
- package/dist/lib/local-target.js +77 -0
- package/dist/lib/output.d.ts +27 -1
- package/dist/lib/output.js +22 -3
- package/dist/lib/response-schemas.d.ts +5 -2
- package/dist/lib/response-schemas.js +39 -1
- package/dist/lib/runs.types.d.ts +50 -2
- package/dist/lib/target-url.d.ts +1 -1
- package/dist/lib/target-url.js +35 -12
- package/dist/lib/telemetry.d.ts +174 -4
- package/dist/lib/telemetry.js +286 -13
- package/dist/lib/tunnel-session.d.ts +13 -2
- package/dist/lib/tunnel-session.js +92 -23
- package/dist/lib/tunnel.types.d.ts +3 -1
- package/dist/lib/version-notice.d.ts +20 -1
- package/dist/lib/version-notice.js +59 -12
- package/dist/vendor/tunnel-client/client.d.ts +11 -0
- package/dist/vendor/tunnel-client/client.js +383 -56
- package/dist/vendor/tunnel-client/config.d.ts +11 -3
- package/dist/vendor/tunnel-client/config.js +11 -3
- package/dist/vendor/tunnel-client/types.d.ts +26 -1
- package/dist/vendor/tunnel-client/types.js +1 -0
- package/dist/vendor/tunnel-client/ws-compat.d.ts +3 -2
- package/dist/vendor/tunnel-client/ws-compat.js +3 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
- package/skills/testsprite-onboard.skill.md +74 -59
- package/skills/testsprite-verify.codex.md +82 -97
- package/skills/testsprite-verify.skill.md +64 -15
|
@@ -6,10 +6,18 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Absent ⇒ a legacy / pre-discriminator backend: treated as `in_flight` (the
|
|
8
8
|
* historical rendering) for backward compatibility.
|
|
9
|
+
*
|
|
10
|
+
* `insufficient_credits` / `billing_hold` are billing refusals the backend folds
|
|
11
|
+
* into `conflicts[]` for a MIXED batch (some cases dispatched, some refused). A
|
|
12
|
+
* batch where nothing dispatched and every refusal was credits comes back as a
|
|
13
|
+
* plain 402 `INSUFFICIENT_CREDITS` envelope instead — the same shape the
|
|
14
|
+
* single-run route answers — so both surfaces exit 12.
|
|
9
15
|
*/
|
|
10
|
-
|
|
16
|
+
import { ApiError } from './errors.js';
|
|
17
|
+
export type ConflictReason = 'in_flight' | 'mcp_view_only' | 'local_address' | 'not_found' | 'insufficient_credits' | 'billing_hold' | 'error';
|
|
11
18
|
/** A conflict entry on a run response. `message` carries actionable detail for
|
|
12
|
-
* `local_address` / `
|
|
19
|
+
* `local_address` / `insufficient_credits` / `billing_hold` / `error` (the
|
|
20
|
+
* backend's nextAction). */
|
|
13
21
|
export interface RunConflict {
|
|
14
22
|
testId: string;
|
|
15
23
|
currentRunId?: string;
|
|
@@ -28,3 +36,36 @@ export declare function describeConflict(c: RunConflict): string;
|
|
|
28
36
|
* must stand in for the whole `conflicts[]` (exit-message / advisory).
|
|
29
37
|
*/
|
|
30
38
|
export declare function summarizeConflicts(conflicts: readonly RunConflict[]): string;
|
|
39
|
+
/**
|
|
40
|
+
* The most frequent conflict reason in a batch (ties → the one seen first), as
|
|
41
|
+
* the raw wire string so a reason this CLI version does not know yet still
|
|
42
|
+
* surfaces. Undefined for an empty set. Feeds the telemetry `conflictReason`
|
|
43
|
+
* field, which allowlists the value before it is sent.
|
|
44
|
+
*/
|
|
45
|
+
export declare function dominantConflictReason(conflicts: readonly RunConflict[]): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* True when the set is non-empty and EVERY entry carries `reason`. Absent
|
|
48
|
+
* reasons never match (they are `in_flight` by the legacy rule above), so an old
|
|
49
|
+
* backend can never be read as "all insufficient credits".
|
|
50
|
+
*/
|
|
51
|
+
export declare function everyConflictIs(conflicts: readonly RunConflict[], reason: ConflictReason): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* True for the one batch shape that is really a credits refusal: nothing was
|
|
54
|
+
* dispatched, nothing is rate-deferred (that is exit 7 first), and every
|
|
55
|
+
* conflict says `insufficient_credits`. A newer backend answers this case with
|
|
56
|
+
* a plain 402 envelope itself; this covers a backend that still folds it into
|
|
57
|
+
* `conflicts[]`, so both wire shapes land on the same exit 12.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isAllCreditsRefusal(resp: {
|
|
60
|
+
accepted: readonly unknown[];
|
|
61
|
+
deferred: readonly unknown[];
|
|
62
|
+
conflicts: readonly RunConflict[];
|
|
63
|
+
}): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The exit-12 refusal for an all-credits batch — the SAME `INSUFFICIENT_CREDITS`
|
|
66
|
+
* envelope the single-run route answers (code, exit code, billing `nextAction`),
|
|
67
|
+
* so `index.ts` renders it identically and automation sees one shape. The
|
|
68
|
+
* server's own message (carried on the conflicts) is preferred over the local
|
|
69
|
+
* wording; `apiUrl` resolves the environment-correct portal link.
|
|
70
|
+
*/
|
|
71
|
+
export declare function insufficientCreditsConflictError(conflicts: readonly RunConflict[], apiUrl?: string): ApiError;
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a case landed in a run response's `conflicts[]` instead of dispatching.
|
|
3
|
+
* The backend (`batchRunFresh` / `dispatchTestListGroups`) tags each conflict so
|
|
4
|
+
* the CLI stops rendering every non-dispatch as "already in flight" — which is
|
|
5
|
+
* wrong for a view-only mirror, an un-runnable environment, or an unknown id.
|
|
6
|
+
*
|
|
7
|
+
* Absent ⇒ a legacy / pre-discriminator backend: treated as `in_flight` (the
|
|
8
|
+
* historical rendering) for backward compatibility.
|
|
9
|
+
*
|
|
10
|
+
* `insufficient_credits` / `billing_hold` are billing refusals the backend folds
|
|
11
|
+
* into `conflicts[]` for a MIXED batch (some cases dispatched, some refused). A
|
|
12
|
+
* batch where nothing dispatched and every refusal was credits comes back as a
|
|
13
|
+
* plain 402 `INSUFFICIENT_CREDITS` envelope instead — the same shape the
|
|
14
|
+
* single-run route answers — so both surfaces exit 12.
|
|
15
|
+
*/
|
|
16
|
+
import { ApiError, insufficientCreditsNextAction } from './errors.js';
|
|
1
17
|
/**
|
|
2
18
|
* Short human label for a conflict's cause — the reason a case did NOT dispatch.
|
|
3
19
|
* Absent reason renders as the legacy "already in flight" so an old backend's
|
|
@@ -11,6 +27,10 @@ export function describeConflict(c) {
|
|
|
11
27
|
return c.message || 'environment not runnable (local/private/unresolvable URL)';
|
|
12
28
|
case 'not_found':
|
|
13
29
|
return 'not found in this workspace';
|
|
30
|
+
case 'insufficient_credits':
|
|
31
|
+
return c.message || 'insufficient credits';
|
|
32
|
+
case 'billing_hold':
|
|
33
|
+
return c.message || 'billing hold';
|
|
14
34
|
case 'error':
|
|
15
35
|
return c.message || 'dispatch failed';
|
|
16
36
|
case 'in_flight':
|
|
@@ -18,28 +38,94 @@ export function describeConflict(c) {
|
|
|
18
38
|
return c.currentRunId ? `already in flight (run ${c.currentRunId})` : 'already in flight';
|
|
19
39
|
}
|
|
20
40
|
}
|
|
41
|
+
const CONFLICT_LABELS = {
|
|
42
|
+
in_flight: 'already in flight',
|
|
43
|
+
mcp_view_only: 'view-only (MCP) project',
|
|
44
|
+
local_address: 'environment not runnable',
|
|
45
|
+
not_found: 'not found',
|
|
46
|
+
insufficient_credits: 'insufficient credits',
|
|
47
|
+
billing_hold: 'billing hold',
|
|
48
|
+
error: 'dispatch error',
|
|
49
|
+
};
|
|
50
|
+
/** Per-reason occurrence counts, insertion-ordered; absent reason ⇒ `in_flight`. */
|
|
51
|
+
function countByReason(conflicts) {
|
|
52
|
+
const counts = new Map();
|
|
53
|
+
for (const c of conflicts) {
|
|
54
|
+
const reason = c.reason ?? 'in_flight';
|
|
55
|
+
counts.set(reason, (counts.get(reason) ?? 0) + 1);
|
|
56
|
+
}
|
|
57
|
+
return counts;
|
|
58
|
+
}
|
|
21
59
|
/**
|
|
22
60
|
* One-line summary of a conflict set grouped by reason, e.g.
|
|
23
61
|
* `2 already in flight, 1 environment not runnable`. Used where a single line
|
|
24
62
|
* must stand in for the whole `conflicts[]` (exit-message / advisory).
|
|
25
63
|
*/
|
|
26
64
|
export function summarizeConflicts(conflicts) {
|
|
27
|
-
const labels = {
|
|
28
|
-
in_flight: 'already in flight',
|
|
29
|
-
mcp_view_only: 'view-only (MCP) project',
|
|
30
|
-
local_address: 'environment not runnable',
|
|
31
|
-
not_found: 'not found',
|
|
32
|
-
error: 'dispatch error',
|
|
33
|
-
};
|
|
34
|
-
const counts = new Map();
|
|
35
|
-
for (const c of conflicts) {
|
|
36
|
-
const reason = c.reason ?? 'in_flight';
|
|
37
|
-
counts.set(reason, (counts.get(reason) ?? 0) + 1);
|
|
38
|
-
}
|
|
39
65
|
// A future/unknown reason the loose wire schema admits (describeConflict covers
|
|
40
66
|
// it via its default arm) must not render as "N undefined" here.
|
|
41
|
-
return [...
|
|
42
|
-
.map(([reason, n]) => `${n} ${
|
|
67
|
+
return [...countByReason(conflicts).entries()]
|
|
68
|
+
.map(([reason, n]) => `${n} ${CONFLICT_LABELS[reason] ?? 'not dispatched'}`)
|
|
43
69
|
.join(', ');
|
|
44
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* The most frequent conflict reason in a batch (ties → the one seen first), as
|
|
73
|
+
* the raw wire string so a reason this CLI version does not know yet still
|
|
74
|
+
* surfaces. Undefined for an empty set. Feeds the telemetry `conflictReason`
|
|
75
|
+
* field, which allowlists the value before it is sent.
|
|
76
|
+
*/
|
|
77
|
+
export function dominantConflictReason(conflicts) {
|
|
78
|
+
let best;
|
|
79
|
+
let bestCount = 0;
|
|
80
|
+
for (const [reason, n] of countByReason(conflicts)) {
|
|
81
|
+
if (n > bestCount) {
|
|
82
|
+
best = reason;
|
|
83
|
+
bestCount = n;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return best;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* True when the set is non-empty and EVERY entry carries `reason`. Absent
|
|
90
|
+
* reasons never match (they are `in_flight` by the legacy rule above), so an old
|
|
91
|
+
* backend can never be read as "all insufficient credits".
|
|
92
|
+
*/
|
|
93
|
+
export function everyConflictIs(conflicts, reason) {
|
|
94
|
+
return conflicts.length > 0 && conflicts.every(c => c.reason === reason);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* True for the one batch shape that is really a credits refusal: nothing was
|
|
98
|
+
* dispatched, nothing is rate-deferred (that is exit 7 first), and every
|
|
99
|
+
* conflict says `insufficient_credits`. A newer backend answers this case with
|
|
100
|
+
* a plain 402 envelope itself; this covers a backend that still folds it into
|
|
101
|
+
* `conflicts[]`, so both wire shapes land on the same exit 12.
|
|
102
|
+
*/
|
|
103
|
+
export function isAllCreditsRefusal(resp) {
|
|
104
|
+
return (resp.accepted.length === 0 &&
|
|
105
|
+
resp.deferred.length === 0 &&
|
|
106
|
+
everyConflictIs(resp.conflicts, 'insufficient_credits'));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The exit-12 refusal for an all-credits batch — the SAME `INSUFFICIENT_CREDITS`
|
|
110
|
+
* envelope the single-run route answers (code, exit code, billing `nextAction`),
|
|
111
|
+
* so `index.ts` renders it identically and automation sees one shape. The
|
|
112
|
+
* server's own message (carried on the conflicts) is preferred over the local
|
|
113
|
+
* wording; `apiUrl` resolves the environment-correct portal link.
|
|
114
|
+
*/
|
|
115
|
+
export function insufficientCreditsConflictError(conflicts, apiUrl) {
|
|
116
|
+
const serverMessage = conflicts
|
|
117
|
+
.map(c => c.message?.trim())
|
|
118
|
+
.find((m) => m !== undefined && m !== '');
|
|
119
|
+
const n = conflicts.length;
|
|
120
|
+
return ApiError.fromEnvelope({
|
|
121
|
+
error: {
|
|
122
|
+
code: 'INSUFFICIENT_CREDITS',
|
|
123
|
+
message: serverMessage ??
|
|
124
|
+
`Insufficient credits — nothing was queued (${n} test${n !== 1 ? 's' : ''} refused).`,
|
|
125
|
+
nextAction: insufficientCreditsNextAction(apiUrl),
|
|
126
|
+
requestId: 'local',
|
|
127
|
+
details: { reason: 'insufficient_credits', conflicts: conflicts.map(c => c.testId) },
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
45
131
|
//# sourceMappingURL=conflict-reason.js.map
|
|
@@ -16,6 +16,10 @@ export type CredentialsFile = Record<string, ProfileEntry>;
|
|
|
16
16
|
export interface CredentialsOptions {
|
|
17
17
|
path?: string;
|
|
18
18
|
}
|
|
19
|
+
type CredentialsWritePermissionError = NodeJS.ErrnoException & {
|
|
20
|
+
code: 'EPERM' | 'EACCES' | 'EROFS';
|
|
21
|
+
};
|
|
22
|
+
export declare function isCredentialsWritePermissionError(error: unknown): error is CredentialsWritePermissionError;
|
|
19
23
|
interface RestrictiveModeOptions {
|
|
20
24
|
platform?: NodeJS.Platform;
|
|
21
25
|
env?: NodeJS.ProcessEnv;
|
package/dist/lib/credentials.js
CHANGED
|
@@ -34,6 +34,19 @@ export function assertValidProfileName(profile) {
|
|
|
34
34
|
export function defaultCredentialsPath() {
|
|
35
35
|
return join(homedir(), '.testsprite', 'credentials');
|
|
36
36
|
}
|
|
37
|
+
// Keep the original errno object and distinguish write permissions from errors
|
|
38
|
+
// while reading profiles, recovering locks, or tightening file permissions.
|
|
39
|
+
const writePermissionErrors = new WeakSet();
|
|
40
|
+
export function isCredentialsWritePermissionError(error) {
|
|
41
|
+
return error instanceof Error && writePermissionErrors.has(error);
|
|
42
|
+
}
|
|
43
|
+
function rethrowCredentialsWriteError(error) {
|
|
44
|
+
if (isErrnoException(error) &&
|
|
45
|
+
(error.code === 'EPERM' || error.code === 'EACCES' || error.code === 'EROFS')) {
|
|
46
|
+
writePermissionErrors.add(error);
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
37
50
|
const FILE_KEY_TO_FIELD = {
|
|
38
51
|
api_key: 'apiKey',
|
|
39
52
|
api_url: 'apiUrl',
|
|
@@ -195,7 +208,13 @@ function resolvePath(options) {
|
|
|
195
208
|
return options.path ?? defaultCredentialsPath();
|
|
196
209
|
}
|
|
197
210
|
function mutateCredentialsFile(path, mutate) {
|
|
198
|
-
|
|
211
|
+
try {
|
|
212
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- `path` is the credentials-file path this module already operates on (default `~/.testsprite/credentials`, or the caller-supplied `CredentialsOptions.path`), not new external input; same risk profile as the baselined fs calls in this file.
|
|
213
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
rethrowCredentialsWriteError(error);
|
|
217
|
+
}
|
|
199
218
|
const lock = acquireCredentialsLock(path);
|
|
200
219
|
try {
|
|
201
220
|
const file = readCredentialsFile({ path });
|
|
@@ -211,8 +230,28 @@ function mutateCredentialsFile(path, mutate) {
|
|
|
211
230
|
}
|
|
212
231
|
function writeCredentialsAtomic(path, file) {
|
|
213
232
|
const tmp = `${path}.tmp.${process.pid}`;
|
|
214
|
-
|
|
215
|
-
|
|
233
|
+
try {
|
|
234
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- `tmp` is `${path}.tmp.${pid}`, derived from the same internal credentials-file path; same baselined risk profile as the other fs calls in this file.
|
|
235
|
+
writeFileSync(tmp, serializeCredentials(file), { mode: 0o600, encoding: 'utf8' });
|
|
236
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- both operands derive from the internal credentials-file path (see above).
|
|
237
|
+
renameSync(tmp, path);
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
try {
|
|
241
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- best-effort cleanup of the temp file this function just created; same internal path.
|
|
242
|
+
unlinkSync(tmp);
|
|
243
|
+
}
|
|
244
|
+
catch (cleanupError) {
|
|
245
|
+
if (!isErrnoException(cleanupError) || cleanupError.code !== 'ENOENT') {
|
|
246
|
+
// Do not mark this as a permission error eligible for session-only setup:
|
|
247
|
+
// the temporary file can still contain the API key.
|
|
248
|
+
throw new Error(`Temporary credentials could not be cleaned up at ${tmp}.`, {
|
|
249
|
+
cause: cleanupError,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
rethrowCredentialsWriteError(error);
|
|
254
|
+
}
|
|
216
255
|
ensureRestrictiveMode(path);
|
|
217
256
|
}
|
|
218
257
|
function acquireCredentialsLock(path) {
|
|
@@ -238,7 +277,7 @@ function acquireCredentialsLock(path) {
|
|
|
238
277
|
}
|
|
239
278
|
catch (error) {
|
|
240
279
|
if (!isErrnoException(error) || error.code !== 'EEXIST') {
|
|
241
|
-
|
|
280
|
+
rethrowCredentialsWriteError(error);
|
|
242
281
|
}
|
|
243
282
|
reclaimStaleCredentialsLock(lockPath);
|
|
244
283
|
if (Date.now() >= deadline) {
|
package/dist/lib/cron.js
CHANGED
|
@@ -133,9 +133,16 @@ export function describeCron(cron) {
|
|
|
133
133
|
const f = fields(cron);
|
|
134
134
|
if (f.length !== FIELD_COUNT)
|
|
135
135
|
return cron.trim();
|
|
136
|
-
const [minute, hour, dayOfMonth, , dayOfWeek] = f;
|
|
136
|
+
const [minute, hour, dayOfMonth, month, dayOfWeek] = f;
|
|
137
137
|
if (!isPinned(minute) || !isPinned(hour))
|
|
138
138
|
return cron.trim();
|
|
139
|
+
// A restricted month makes every phrasing below wrong, because none of them
|
|
140
|
+
// can say "except in the months this cron skips": `0 3 * 6 *` is not "daily
|
|
141
|
+
// at 03:00", it is daily *during June*. runsPerMonth already divides by the
|
|
142
|
+
// month count, so describing it as daily contradicts the frequency printed
|
|
143
|
+
// beside it in the same sentence.
|
|
144
|
+
if (!isWildcard(month))
|
|
145
|
+
return cron.trim();
|
|
139
146
|
const at = `${hour.padStart(2, '0')}:${minute.padStart(2, '0')}`;
|
|
140
147
|
if (isWildcard(dayOfMonth) && isWildcard(dayOfWeek))
|
|
141
148
|
return `daily at ${at}`;
|
package/dist/lib/errors.d.ts
CHANGED
|
@@ -22,8 +22,34 @@ export declare function exitCodeFor(code: ErrorCode): number;
|
|
|
22
22
|
export declare function isAuthCode(code: string): boolean;
|
|
23
23
|
export declare class CLIError extends Error {
|
|
24
24
|
readonly exitCode: number;
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Stable machine error code — mirrored into telemetry's `errorCode` field
|
|
27
|
+
* and into the `--output json` error envelope (`{error:{code,...}}`).
|
|
28
|
+
* Defaults to the generic, deliberately out-of-catalog `'CLI_ERROR'`
|
|
29
|
+
* bucket for a plain `CLIError` (same convention as `InterruptError`'s
|
|
30
|
+
* `'INTERRUPTED'` and `RequestTimeoutError`'s `'REQUEST_TIMEOUT'` below —
|
|
31
|
+
* none of these are backend-issued codes, so they don't belong in
|
|
32
|
+
* `ERROR_CODES`). `ApiError` overrides this with the real catalog
|
|
33
|
+
* `ErrorCode` parsed from the server envelope.
|
|
34
|
+
*
|
|
35
|
+
* Before this field existed, `classifyCliError()`'s plain-`CLIError`
|
|
36
|
+
* fallback branch had nothing to report and telemetry events landed with
|
|
37
|
+
* `errorCode=None` — the same silent gap the final uncaught-exception
|
|
38
|
+
* branch had.
|
|
39
|
+
*/
|
|
40
|
+
readonly code: string;
|
|
41
|
+
constructor(message: string, exitCode?: number, code?: string);
|
|
26
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Best-effort extraction of a `.code` string off an arbitrary thrown value —
|
|
45
|
+
* covers Node built-in errors (`ENOENT`, `ECONNREFUSED`, …) that reach the
|
|
46
|
+
* top-level catch without ever being wrapped in a `CLIError`. Used by the
|
|
47
|
+
* genuinely-uncaught-exception fallback in both `classifyCliError()` and
|
|
48
|
+
* `index.ts`'s final catch branch, so a filesystem/network error reports its
|
|
49
|
+
* real code instead of falling into the generic `'UNCAUGHT_EXCEPTION'`
|
|
50
|
+
* bucket.
|
|
51
|
+
*/
|
|
52
|
+
export declare function extractNodeErrorCode(err: unknown): string | undefined;
|
|
27
53
|
/**
|
|
28
54
|
* Termination signals with graceful handling, mapped to their conventional
|
|
29
55
|
* `128 + signum` exit code. sourceRef: POSIX signal numbers (SIGHUP=1,
|
|
@@ -157,3 +183,20 @@ export declare class RequestTimeoutError extends CLIError {
|
|
|
157
183
|
readonly timeoutMs: number;
|
|
158
184
|
constructor(timeoutMs: number, requestId?: string);
|
|
159
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* The synthesized `nextAction` for an INSUFFICIENT_CREDITS refusal when the
|
|
188
|
+
* backend supplied none (older backends; the CLI's own all-credits batch
|
|
189
|
+
* refusal). Portal links resolve per environment from the API endpoint (dev and
|
|
190
|
+
* prod portals live on different domains); an unknown host gets the route only —
|
|
191
|
+
* a hardcoded domain would point at the wrong environment.
|
|
192
|
+
*
|
|
193
|
+
* V3 API keys are membership-bound: a key minted for a team org spends THAT
|
|
194
|
+
* org's wallet, not the holder's personal one, and there is no request-scoped
|
|
195
|
+
* signal at this layer to tell which kind of key just failed. So the hint
|
|
196
|
+
* deliberately does NOT assert "top up your (personal) credits" as the only
|
|
197
|
+
* path — it offers the personal-key link (still correct for the common case)
|
|
198
|
+
* alongside an honest org-bound alternative, rather than guessing. The
|
|
199
|
+
* `testsprite usage` pointer is the CLI-native way to check the balance before
|
|
200
|
+
* a large run fan-out.
|
|
201
|
+
*/
|
|
202
|
+
export declare function insufficientCreditsNextAction(apiUrl?: string): string;
|
package/dist/lib/errors.js
CHANGED
|
@@ -115,12 +115,44 @@ export function isAuthCode(code) {
|
|
|
115
115
|
}
|
|
116
116
|
export class CLIError extends Error {
|
|
117
117
|
exitCode;
|
|
118
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Stable machine error code — mirrored into telemetry's `errorCode` field
|
|
120
|
+
* and into the `--output json` error envelope (`{error:{code,...}}`).
|
|
121
|
+
* Defaults to the generic, deliberately out-of-catalog `'CLI_ERROR'`
|
|
122
|
+
* bucket for a plain `CLIError` (same convention as `InterruptError`'s
|
|
123
|
+
* `'INTERRUPTED'` and `RequestTimeoutError`'s `'REQUEST_TIMEOUT'` below —
|
|
124
|
+
* none of these are backend-issued codes, so they don't belong in
|
|
125
|
+
* `ERROR_CODES`). `ApiError` overrides this with the real catalog
|
|
126
|
+
* `ErrorCode` parsed from the server envelope.
|
|
127
|
+
*
|
|
128
|
+
* Before this field existed, `classifyCliError()`'s plain-`CLIError`
|
|
129
|
+
* fallback branch had nothing to report and telemetry events landed with
|
|
130
|
+
* `errorCode=None` — the same silent gap the final uncaught-exception
|
|
131
|
+
* branch had.
|
|
132
|
+
*/
|
|
133
|
+
code;
|
|
134
|
+
constructor(message, exitCode = 1, code = 'CLI_ERROR') {
|
|
119
135
|
super(message);
|
|
120
136
|
this.name = 'CLIError';
|
|
121
137
|
this.exitCode = exitCode;
|
|
138
|
+
this.code = code;
|
|
122
139
|
}
|
|
123
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Best-effort extraction of a `.code` string off an arbitrary thrown value —
|
|
143
|
+
* covers Node built-in errors (`ENOENT`, `ECONNREFUSED`, …) that reach the
|
|
144
|
+
* top-level catch without ever being wrapped in a `CLIError`. Used by the
|
|
145
|
+
* genuinely-uncaught-exception fallback in both `classifyCliError()` and
|
|
146
|
+
* `index.ts`'s final catch branch, so a filesystem/network error reports its
|
|
147
|
+
* real code instead of falling into the generic `'UNCAUGHT_EXCEPTION'`
|
|
148
|
+
* bucket.
|
|
149
|
+
*/
|
|
150
|
+
export function extractNodeErrorCode(err) {
|
|
151
|
+
if (typeof err !== 'object' || err === null || !('code' in err))
|
|
152
|
+
return undefined;
|
|
153
|
+
const code = err.code;
|
|
154
|
+
return typeof code === 'string' && code.length > 0 ? code : undefined;
|
|
155
|
+
}
|
|
124
156
|
/**
|
|
125
157
|
* Termination signals with graceful handling, mapped to their conventional
|
|
126
158
|
* `128 + signum` exit code. sourceRef: POSIX signal numbers (SIGHUP=1,
|
|
@@ -146,14 +178,14 @@ export const TERMINATION_EXIT_CODES = {
|
|
|
146
178
|
export class InterruptError extends CLIError {
|
|
147
179
|
signal;
|
|
148
180
|
constructor(signal) {
|
|
149
|
-
super(`Interrupted by ${signal}.`, TERMINATION_EXIT_CODES[signal]);
|
|
181
|
+
super(`Interrupted by ${signal}.`, TERMINATION_EXIT_CODES[signal], 'INTERRUPTED');
|
|
150
182
|
this.name = 'InterruptError';
|
|
151
183
|
this.signal = signal;
|
|
152
184
|
}
|
|
153
185
|
}
|
|
154
186
|
export class NotImplementedError extends CLIError {
|
|
155
187
|
constructor(commandPath) {
|
|
156
|
-
super(`Command not yet implemented: ${commandPath}`, 2);
|
|
188
|
+
super(`Command not yet implemented: ${commandPath}`, 2, 'NOT_IMPLEMENTED');
|
|
157
189
|
this.name = 'NotImplementedError';
|
|
158
190
|
}
|
|
159
191
|
}
|
|
@@ -165,6 +197,15 @@ export class NotImplementedError extends CLIError {
|
|
|
165
197
|
* wording across paths).
|
|
166
198
|
*/
|
|
167
199
|
export class ApiError extends CLIError {
|
|
200
|
+
// `override`: CLIError now declares its own `code: string` (defaulting
|
|
201
|
+
// 'CLI_ERROR'), so `noImplicitOverride` requires this modifier on the
|
|
202
|
+
// narrowed redeclaration. Under useDefineForClassFields (the default at
|
|
203
|
+
// this tsconfig's ES2022 target) this field IS re-initialized to
|
|
204
|
+
// `undefined` right after `super(...)` returns — but the constructor body
|
|
205
|
+
// below unconditionally reassigns `this.code = envelope.code` afterward,
|
|
206
|
+
// so the final value is always the envelope's code, never the CLIError
|
|
207
|
+
// base default. See the pinned regression test in errors.test.ts
|
|
208
|
+
// ("ApiError.code overrides the CLIError base default").
|
|
168
209
|
code;
|
|
169
210
|
requestId;
|
|
170
211
|
nextAction;
|
|
@@ -306,7 +347,7 @@ export class RequestTimeoutError extends CLIError {
|
|
|
306
347
|
constructor(timeoutMs, requestId = 'local') {
|
|
307
348
|
const timeoutSec = Math.round(timeoutMs / 1000);
|
|
308
349
|
super(`Request timed out after ${timeoutSec}s (client-side). ` +
|
|
309
|
-
`Use --request-timeout <seconds> or TESTSPRITE_REQUEST_TIMEOUT_MS to extend the deadline.`, 7);
|
|
350
|
+
`Use --request-timeout <seconds> or TESTSPRITE_REQUEST_TIMEOUT_MS to extend the deadline.`, 7, 'REQUEST_TIMEOUT');
|
|
310
351
|
this.name = 'RequestTimeoutError';
|
|
311
352
|
this.requestId = requestId;
|
|
312
353
|
this.timeoutMs = timeoutMs;
|
|
@@ -372,6 +413,29 @@ function isInsufficientCredits(rawCode, message, details) {
|
|
|
372
413
|
const hasCreditsMessage = /insufficient credits/i.test(message);
|
|
373
414
|
return hasRequiredField || hasCreditsMessage;
|
|
374
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* The synthesized `nextAction` for an INSUFFICIENT_CREDITS refusal when the
|
|
418
|
+
* backend supplied none (older backends; the CLI's own all-credits batch
|
|
419
|
+
* refusal). Portal links resolve per environment from the API endpoint (dev and
|
|
420
|
+
* prod portals live on different domains); an unknown host gets the route only —
|
|
421
|
+
* a hardcoded domain would point at the wrong environment.
|
|
422
|
+
*
|
|
423
|
+
* V3 API keys are membership-bound: a key minted for a team org spends THAT
|
|
424
|
+
* org's wallet, not the holder's personal one, and there is no request-scoped
|
|
425
|
+
* signal at this layer to tell which kind of key just failed. So the hint
|
|
426
|
+
* deliberately does NOT assert "top up your (personal) credits" as the only
|
|
427
|
+
* path — it offers the personal-key link (still correct for the common case)
|
|
428
|
+
* alongside an honest org-bound alternative, rather than guessing. The
|
|
429
|
+
* `testsprite usage` pointer is the CLI-native way to check the balance before
|
|
430
|
+
* a large run fan-out.
|
|
431
|
+
*/
|
|
432
|
+
export function insufficientCreditsNextAction(apiUrl) {
|
|
433
|
+
const portalBase = apiUrl === undefined ? undefined : resolvePortalBase(apiUrl);
|
|
434
|
+
return ((portalBase !== undefined
|
|
435
|
+
? `Top up credits at ${portalBase}/dashboard/settings/billing (personal keys) — ask an org admin if this key is organization-bound — or upgrade your plan at ${portalBase}/pricing.`
|
|
436
|
+
: 'Top up credits on the portal Billing page (/dashboard/settings/billing) if this is a personal key — ask an org admin if it is organization-bound — or upgrade your plan (/pricing).') +
|
|
437
|
+
' Run `testsprite usage` to check your current balance before the next run.');
|
|
438
|
+
}
|
|
375
439
|
/**
|
|
376
440
|
* Detect the "ambiguous org" sub-case of a CONFLICT (409) envelope: a
|
|
377
441
|
* membership-key caller's testId resolved to projects in more than one of
|
|
@@ -450,17 +514,10 @@ function parseEnvelopeBody(raw, httpStatus, apiUrl) {
|
|
|
450
514
|
// (personal) credits" as the only path — it offers the personal-key
|
|
451
515
|
// link (still correct for the common case) alongside an honest
|
|
452
516
|
// org-bound alternative, rather than guessing.
|
|
453
|
-
const portalBase = apiUrl === undefined ? undefined : resolvePortalBase(apiUrl);
|
|
454
|
-
const billingNextAction = nextAction !== ''
|
|
455
|
-
? nextAction
|
|
456
|
-
: (portalBase !== undefined
|
|
457
|
-
? `Top up credits at ${portalBase}/dashboard/settings/billing (personal keys) — ask an org admin if this key is organization-bound — or upgrade your plan at ${portalBase}/pricing.`
|
|
458
|
-
: 'Top up credits on the portal Billing page (/dashboard/settings/billing) if this is a personal key — ask an org admin if it is organization-bound — or upgrade your plan (/pricing).') +
|
|
459
|
-
' Run `testsprite usage` to check your current balance before the next run.';
|
|
460
517
|
return {
|
|
461
518
|
code: 'INSUFFICIENT_CREDITS',
|
|
462
519
|
message,
|
|
463
|
-
nextAction:
|
|
520
|
+
nextAction: nextAction !== '' ? nextAction : insufficientCreditsNextAction(apiUrl),
|
|
464
521
|
requestId,
|
|
465
522
|
details,
|
|
466
523
|
};
|
package/dist/lib/gh-output.d.ts
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* single `test run <test-id> --wait` and the `test run --all --wait` batch.
|
|
5
5
|
*
|
|
6
6
|
* A `--wait` run presents its result in the formats CI consumes:
|
|
7
|
-
* (a) a stable machine summary `{total, passed, failed, timedOut,
|
|
8
|
-
* written to `--summary-file <path>` when requested,
|
|
7
|
+
* (a) a stable machine summary `{total, passed, failed, skipped, timedOut,
|
|
8
|
+
* runs[]}` written to `--summary-file <path>` when requested,
|
|
9
9
|
* (b) a Markdown results table appended to `$GITHUB_STEP_SUMMARY` when
|
|
10
10
|
* running under GitHub Actions,
|
|
11
|
-
* (c) one
|
|
12
|
-
*
|
|
11
|
+
* (c) one workflow-command line per non-passed run so it annotates the PR
|
|
12
|
+
* checks tab — `::error::` for a dispatched run that failed or timed
|
|
13
|
+
* out, `::warning::` for a test that never dispatched.
|
|
13
14
|
* Activation: `GITHUB_ACTIONS=true` in the environment, or the explicit
|
|
14
15
|
* `--gh-output` flag (which forces the annotations even off-Actions, so the
|
|
15
16
|
* behavior is previewable locally). All writes are best-effort: a broken
|
|
@@ -31,6 +32,14 @@ export interface CiSummary {
|
|
|
31
32
|
total: number;
|
|
32
33
|
passed: number;
|
|
33
34
|
failed: number;
|
|
35
|
+
/**
|
|
36
|
+
* Requested tests that never dispatched (deferred / conflict / not_found /
|
|
37
|
+
* skipped / no_tests rows). Kept OUT of `failed`: `failed` claiming
|
|
38
|
+
* a test failed while the exit code says otherwise is the artifacts-disagree
|
|
39
|
+
* bug this field fixes. Non-dispatch still gates the exit where it should
|
|
40
|
+
* (deferred → 7, all-conflict → 6, all-not-found rerun → 4, zero-dispatch → 5).
|
|
41
|
+
*/
|
|
42
|
+
skipped: number;
|
|
34
43
|
timedOut: number;
|
|
35
44
|
runs: CiRunRow[];
|
|
36
45
|
}
|
|
@@ -41,11 +50,13 @@ export interface CiSummary {
|
|
|
41
50
|
* after a timeout) reduces to an empty run list rather than a crash.
|
|
42
51
|
*
|
|
43
52
|
* Non-dispatched work (`deferred` / `conflicts` / `notFound`) is folded in as
|
|
44
|
-
* non-passed rows
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
53
|
+
* non-passed rows so a partial batch like `1 accepted passed + 1 deferred`
|
|
54
|
+
* cannot read as "1/1 passed" with no annotation — but it counts as `skipped`,
|
|
55
|
+
* never `failed`: whether non-dispatch fails the job is the exit-code
|
|
56
|
+
* gates' call, and a `failed` count the gates disagree with is exactly the
|
|
57
|
+
* artifacts-contradict-the-exit bug. (`skippedFrontend` / `skippedIntegration`
|
|
58
|
+
* are NOT folded in — they exit 0 and are the Action layer's allow-partial
|
|
59
|
+
* concern.)
|
|
49
60
|
*/
|
|
50
61
|
export declare function summarizeAcceptedPayload(capturedJson: string, opts?: {
|
|
51
62
|
notFoundNote?: string;
|
|
@@ -71,8 +82,11 @@ export declare function renderJobSummaryMarkdown(summary: CiSummary): string;
|
|
|
71
82
|
/**
|
|
72
83
|
* Emit the GitHub-native surfaces. Self-gating on the standard env vars:
|
|
73
84
|
* `$GITHUB_STEP_SUMMARY` (a file path Actions provides) receives the Markdown
|
|
74
|
-
* table; `GITHUB_ACTIONS=true` enables one
|
|
75
|
-
*
|
|
85
|
+
* table; `GITHUB_ACTIONS=true` enables one workflow command per non-passed run
|
|
86
|
+
* on stdout (Actions parses workflow commands from stdout) — `::error::` for a
|
|
87
|
+
* dispatched run that failed or timed out, `::warning::` for a test that never
|
|
88
|
+
* ran (deferred / conflict / not_found / skipped), so a red annotation always
|
|
89
|
+
* means a red-worthy outcome and never contradicts the exit code.
|
|
76
90
|
* `force` (the `--gh-output` flag) emits the annotations even off-Actions;
|
|
77
91
|
* the step summary still requires the env-provided file path to exist.
|
|
78
92
|
* Both writes are best-effort: a broken summary file must not mask the gate.
|
package/dist/lib/gh-output.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { appendFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* Row statuses that mean "this test never ran" as opposed to "this run did not
|
|
4
|
+
* pass". They count as `skipped` in the summary (not `failed`) and annotate as
|
|
5
|
+
* `::warning::` (not `::error::`) so every CI surface tells the same story as
|
|
6
|
+
* the exit code.
|
|
7
|
+
*/
|
|
8
|
+
const NON_DISPATCHED_STATUSES = new Set([
|
|
9
|
+
'deferred',
|
|
10
|
+
'conflict',
|
|
11
|
+
'not_found',
|
|
12
|
+
'skipped',
|
|
13
|
+
'no_tests',
|
|
14
|
+
]);
|
|
2
15
|
/**
|
|
3
16
|
* Reduce a non-dispatched bucket (`deferred` / `conflicts` / `notFound`) into
|
|
4
17
|
* CI rows. Items are either bare testId strings (`notFound`) or
|
|
@@ -27,11 +40,13 @@ function bucketRows(bucket, status, note) {
|
|
|
27
40
|
* after a timeout) reduces to an empty run list rather than a crash.
|
|
28
41
|
*
|
|
29
42
|
* Non-dispatched work (`deferred` / `conflicts` / `notFound`) is folded in as
|
|
30
|
-
* non-passed rows
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
43
|
+
* non-passed rows so a partial batch like `1 accepted passed + 1 deferred`
|
|
44
|
+
* cannot read as "1/1 passed" with no annotation — but it counts as `skipped`,
|
|
45
|
+
* never `failed`: whether non-dispatch fails the job is the exit-code
|
|
46
|
+
* gates' call, and a `failed` count the gates disagree with is exactly the
|
|
47
|
+
* artifacts-contradict-the-exit bug. (`skippedFrontend` / `skippedIntegration`
|
|
48
|
+
* are NOT folded in — they exit 0 and are the Action layer's allow-partial
|
|
49
|
+
* concern.)
|
|
35
50
|
*/
|
|
36
51
|
export function summarizeAcceptedPayload(capturedJson, opts = {}) {
|
|
37
52
|
let parsed;
|
|
@@ -75,8 +90,9 @@ export function summarizeAcceptedPayload(capturedJson, opts = {}) {
|
|
|
75
90
|
];
|
|
76
91
|
const passed = rows.filter(row => row.status === 'passed').length;
|
|
77
92
|
const timedOut = rows.filter(row => row.status === 'timeout').length;
|
|
78
|
-
const
|
|
79
|
-
|
|
93
|
+
const skipped = rows.filter(row => NON_DISPATCHED_STATUSES.has(row.status)).length;
|
|
94
|
+
const failed = rows.length - passed - timedOut - skipped;
|
|
95
|
+
return { total: rows.length, passed, failed, skipped, timedOut, runs: rows };
|
|
80
96
|
}
|
|
81
97
|
/**
|
|
82
98
|
* Reduce a single `test run <test-id> --wait` result into the same CI summary
|
|
@@ -97,8 +113,9 @@ export function summarizeSingleRun(run) {
|
|
|
97
113
|
};
|
|
98
114
|
const passed = row.status === 'passed' ? 1 : 0;
|
|
99
115
|
const timedOut = row.status === 'timeout' ? 1 : 0;
|
|
100
|
-
const
|
|
101
|
-
|
|
116
|
+
const skipped = NON_DISPATCHED_STATUSES.has(row.status) ? 1 : 0;
|
|
117
|
+
const failed = 1 - passed - timedOut - skipped;
|
|
118
|
+
return { total: 1, passed, failed, skipped, timedOut, runs: [row] };
|
|
102
119
|
}
|
|
103
120
|
/**
|
|
104
121
|
* Escape a value for a Markdown table cell. A raw `|` would break the column
|
|
@@ -147,7 +164,7 @@ export function renderJobSummaryMarkdown(summary) {
|
|
|
147
164
|
return [
|
|
148
165
|
'## TestSprite results',
|
|
149
166
|
'',
|
|
150
|
-
`**${summary.passed}/${summary.total} passed** (${summary.failed} failed, ${summary.timedOut} timed out)`,
|
|
167
|
+
`**${summary.passed}/${summary.total} passed** (${summary.failed} failed, ${summary.skipped} skipped, ${summary.timedOut} timed out)`,
|
|
151
168
|
'',
|
|
152
169
|
'| Test | Status | Run |',
|
|
153
170
|
'| --- | --- | --- |',
|
|
@@ -195,8 +212,11 @@ function escapeCommandProperty(value) {
|
|
|
195
212
|
/**
|
|
196
213
|
* Emit the GitHub-native surfaces. Self-gating on the standard env vars:
|
|
197
214
|
* `$GITHUB_STEP_SUMMARY` (a file path Actions provides) receives the Markdown
|
|
198
|
-
* table; `GITHUB_ACTIONS=true` enables one
|
|
199
|
-
*
|
|
215
|
+
* table; `GITHUB_ACTIONS=true` enables one workflow command per non-passed run
|
|
216
|
+
* on stdout (Actions parses workflow commands from stdout) — `::error::` for a
|
|
217
|
+
* dispatched run that failed or timed out, `::warning::` for a test that never
|
|
218
|
+
* ran (deferred / conflict / not_found / skipped), so a red annotation always
|
|
219
|
+
* means a red-worthy outcome and never contradicts the exit code.
|
|
200
220
|
* `force` (the `--gh-output` flag) emits the annotations even off-Actions;
|
|
201
221
|
* the step summary still requires the env-provided file path to exist.
|
|
202
222
|
* Both writes are best-effort: a broken summary file must not mask the gate.
|
|
@@ -227,7 +247,10 @@ export function emitGithubOutputs(summary, env, sinks, opts = {}) {
|
|
|
227
247
|
// able to smuggle a second workflow command into the Actions stream.
|
|
228
248
|
const title = `TestSprite ${escapeCommandProperty(row.title?.trim() || row.testId)}`;
|
|
229
249
|
const message = escapeCommandData(`status=${row.status}${detail}${link}`);
|
|
230
|
-
|
|
250
|
+
// Severity mirrors the summary counters: never-dispatched rows are
|
|
251
|
+
// warnings (they may not even gate the exit), real failures are errors.
|
|
252
|
+
const severity = NON_DISPATCHED_STATUSES.has(row.status) ? 'warning' : 'error';
|
|
253
|
+
annotate(`::${severity} title=${title}::${message}`);
|
|
231
254
|
}
|
|
232
255
|
}
|
|
233
256
|
}
|