@testsprite/testsprite-cli 0.11.0 → 0.13.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 +52 -44
- package/dist/commands/agent.js +16 -13
- package/dist/commands/auth.d.ts +19 -0
- package/dist/commands/auth.js +60 -24
- package/dist/commands/ci.d.ts +86 -1
- package/dist/commands/ci.js +470 -9
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +22 -9
- package/dist/commands/init.js +14 -11
- package/dist/commands/project-env.d.ts +90 -0
- package/dist/commands/project-env.js +486 -0
- package/dist/commands/project.d.ts +15 -5
- package/dist/commands/project.js +88 -92
- package/dist/commands/schedule.d.ts +2 -0
- package/dist/commands/schedule.js +18 -10
- package/dist/commands/test.d.ts +102 -30
- package/dist/commands/test.js +1949 -419
- package/dist/commands/testlist.js +77 -21
- package/dist/commands/tunnel.d.ts +26 -3
- package/dist/commands/tunnel.js +211 -14
- package/dist/commands/usage.d.ts +3 -0
- package/dist/commands/usage.js +12 -5
- package/dist/index.js +47 -23
- package/dist/lib/agent-targets.d.ts +3 -3
- package/dist/lib/agent-targets.js +2 -2
- package/dist/lib/billing-refusal.d.ts +43 -0
- package/dist/lib/billing-refusal.js +171 -0
- package/dist/lib/bundle.d.ts +5 -0
- package/dist/lib/bundle.js +43 -13
- package/dist/lib/ci-linkage.d.ts +90 -0
- package/dist/lib/ci-linkage.js +181 -0
- package/dist/lib/client-factory.d.ts +4 -1
- package/dist/lib/client-factory.js +25 -2
- package/dist/lib/client-tag.d.ts +13 -0
- package/dist/lib/client-tag.js +44 -0
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.js +20 -1
- package/dist/lib/conflict-reason.d.ts +67 -2
- package/dist/lib/conflict-reason.js +148 -13
- package/dist/lib/credentials.js +56 -14
- package/dist/lib/cron.js +8 -1
- package/dist/lib/dry-run/samples.d.ts +13 -1
- package/dist/lib/dry-run/samples.js +51 -7
- package/dist/lib/errors.d.ts +62 -12
- package/dist/lib/errors.js +180 -25
- package/dist/lib/failing-fe-resolver.d.ts +1 -1
- package/dist/lib/failing-fe-resolver.js +3 -3
- package/dist/lib/gh-output.d.ts +26 -11
- package/dist/lib/gh-output.js +47 -15
- package/dist/lib/history-retention.d.ts +8 -0
- package/dist/lib/history-retention.js +24 -0
- package/dist/lib/http.d.ts +44 -19
- package/dist/lib/http.js +53 -26
- package/dist/lib/interrupt.d.ts +21 -13
- package/dist/lib/interrupt.js +32 -21
- package/dist/lib/junit-report.d.ts +11 -1
- package/dist/lib/junit-report.js +15 -3
- package/dist/lib/local-target.d.ts +33 -1
- package/dist/lib/local-target.js +78 -1
- package/dist/lib/output.d.ts +27 -1
- package/dist/lib/output.js +22 -3
- package/dist/lib/plan-poll.d.ts +11 -11
- package/dist/lib/plan-poll.js +12 -12
- package/dist/lib/plans.types.d.ts +9 -9
- package/dist/lib/plans.types.js +3 -3
- package/dist/lib/poll.d.ts +2 -2
- package/dist/lib/poll.js +9 -3
- package/dist/lib/render-error.d.ts +2 -0
- package/dist/lib/render-error.js +13 -0
- package/dist/lib/response-schemas.d.ts +54 -12
- package/dist/lib/response-schemas.js +106 -7
- package/dist/lib/runs.types.d.ts +92 -6
- package/dist/lib/secret-file.js +72 -14
- package/dist/lib/skill-nudge.d.ts +6 -1
- package/dist/lib/skill-nudge.js +32 -5
- package/dist/lib/target-url-preflight.d.ts +6 -4
- package/dist/lib/target-url-preflight.js +64 -51
- package/dist/lib/target-url.js +31 -12
- package/dist/lib/telemetry.d.ts +172 -3
- package/dist/lib/telemetry.js +276 -15
- package/dist/lib/ticker.js +93 -4
- package/dist/lib/tunnel-session.d.ts +13 -0
- package/dist/lib/tunnel-session.js +4 -1
- package/dist/lib/tunnel.types.d.ts +12 -2
- package/dist/lib/tunnel.types.js +2 -2
- package/dist/lib/version-notice.d.ts +20 -1
- package/dist/lib/version-notice.js +59 -12
- package/dist/lib/wait-exit.d.ts +8 -0
- package/dist/lib/wait-exit.js +76 -4
- package/dist/lib/workspace-status.d.ts +23 -0
- package/dist/lib/workspace-status.js +15 -0
- package/dist/version-guard.d.ts +7 -1
- package/dist/version-guard.js +19 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/skills/testsprite-onboard.skill.md +4 -4
- package/skills/testsprite-verify.codex.md +59 -57
- package/skills/testsprite-verify.skill.md +53 -36
|
@@ -1,3 +1,21 @@
|
|
|
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` / `paused` (or `billing_hold`, the deprecated spelling
|
|
11
|
+
* older backends send) are billing refusals the backend folds
|
|
12
|
+
* into `conflicts[]` for a MIXED batch (some cases dispatched, some refused). A
|
|
13
|
+
* batch where nothing dispatched and every refusal was credits comes back as a
|
|
14
|
+
* plain 402 `INSUFFICIENT_CREDITS` envelope instead — the same shape the
|
|
15
|
+
* single-run route answers — so both surfaces exit 12.
|
|
16
|
+
*/
|
|
17
|
+
import { ApiError, insufficientCreditsNextAction } from './errors.js';
|
|
18
|
+
import { classifyBillingRefusal, isPausedReason } from './billing-refusal.js';
|
|
1
19
|
/**
|
|
2
20
|
* Short human label for a conflict's cause — the reason a case did NOT dispatch.
|
|
3
21
|
* Absent reason renders as the legacy "already in flight" so an old backend's
|
|
@@ -11,6 +29,11 @@ export function describeConflict(c) {
|
|
|
11
29
|
return c.message || 'environment not runnable (local/private/unresolvable URL)';
|
|
12
30
|
case 'not_found':
|
|
13
31
|
return 'not found in this workspace';
|
|
32
|
+
case 'insufficient_credits':
|
|
33
|
+
return c.message || 'insufficient credits';
|
|
34
|
+
case 'paused':
|
|
35
|
+
case 'billing_hold':
|
|
36
|
+
return c.message || 'workspace paused';
|
|
14
37
|
case 'error':
|
|
15
38
|
return c.message || 'dispatch failed';
|
|
16
39
|
case 'in_flight':
|
|
@@ -18,28 +41,140 @@ export function describeConflict(c) {
|
|
|
18
41
|
return c.currentRunId ? `already in flight (run ${c.currentRunId})` : 'already in flight';
|
|
19
42
|
}
|
|
20
43
|
}
|
|
44
|
+
const CONFLICT_LABELS = {
|
|
45
|
+
in_flight: 'already in flight',
|
|
46
|
+
mcp_view_only: 'view-only (MCP) project',
|
|
47
|
+
local_address: 'environment not runnable',
|
|
48
|
+
not_found: 'not found',
|
|
49
|
+
insufficient_credits: 'insufficient credits',
|
|
50
|
+
paused: 'workspace paused',
|
|
51
|
+
billing_hold: 'workspace paused',
|
|
52
|
+
error: 'dispatch error',
|
|
53
|
+
};
|
|
21
54
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
55
|
+
* True when the set is non-empty and every entry is the legacy in-flight
|
|
56
|
+
* cause (absent reason ⇒ `in_flight` too). Callers use this to restore the
|
|
57
|
+
* original, pre-reason-aware "N test(s) already in flight" wording for the
|
|
58
|
+
* common pure case, while any OTHER reason present (paused,
|
|
59
|
+
* mcp_view_only, …) still falls through to `summarizeConflicts`'s
|
|
60
|
+
* reason-aware summary instead of a misleading blanket "in flight".
|
|
25
61
|
*/
|
|
26
|
-
export function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
not_found: 'not found',
|
|
32
|
-
error: 'dispatch error',
|
|
33
|
-
};
|
|
62
|
+
export function allConflictsInFlight(conflicts) {
|
|
63
|
+
return conflicts.length > 0 && conflicts.every(c => (c.reason ?? 'in_flight') === 'in_flight');
|
|
64
|
+
}
|
|
65
|
+
/** Per-reason occurrence counts, insertion-ordered; absent reason ⇒ `in_flight`. */
|
|
66
|
+
function countByReason(conflicts) {
|
|
34
67
|
const counts = new Map();
|
|
35
68
|
for (const c of conflicts) {
|
|
36
69
|
const reason = c.reason ?? 'in_flight';
|
|
37
70
|
counts.set(reason, (counts.get(reason) ?? 0) + 1);
|
|
38
71
|
}
|
|
72
|
+
return counts;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* One-line summary of a conflict set grouped by reason, e.g.
|
|
76
|
+
* `2 already in flight, 1 environment not runnable`. Used where a single line
|
|
77
|
+
* must stand in for the whole `conflicts[]` (exit-message / advisory).
|
|
78
|
+
*/
|
|
79
|
+
export function summarizeConflicts(conflicts) {
|
|
39
80
|
// A future/unknown reason the loose wire schema admits (describeConflict covers
|
|
40
81
|
// it via its default arm) must not render as "N undefined" here.
|
|
41
|
-
return [...
|
|
42
|
-
.map(([reason, n]) => `${n} ${
|
|
82
|
+
return [...countByReason(conflicts).entries()]
|
|
83
|
+
.map(([reason, n]) => `${n} ${CONFLICT_LABELS[reason] ?? 'not dispatched'}`)
|
|
43
84
|
.join(', ');
|
|
44
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* The most frequent conflict reason in a batch (ties → the one seen first), as
|
|
88
|
+
* the raw wire string so a reason this CLI version does not know yet still
|
|
89
|
+
* surfaces. Undefined for an empty set. Feeds the telemetry `conflictReason`
|
|
90
|
+
* field, which allowlists the value before it is sent.
|
|
91
|
+
*/
|
|
92
|
+
export function dominantConflictReason(conflicts) {
|
|
93
|
+
let best;
|
|
94
|
+
let bestCount = 0;
|
|
95
|
+
for (const [reason, n] of countByReason(conflicts)) {
|
|
96
|
+
if (n > bestCount) {
|
|
97
|
+
best = reason;
|
|
98
|
+
bestCount = n;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return best;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* True when the set is non-empty and EVERY entry carries `reason`. Absent
|
|
105
|
+
* reasons never match (they are `in_flight` by the legacy rule above), so an old
|
|
106
|
+
* backend can never be read as "all insufficient credits".
|
|
107
|
+
*/
|
|
108
|
+
export function everyConflictIs(conflicts, reason) {
|
|
109
|
+
return conflicts.length > 0 && conflicts.every(c => c.reason === reason);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* True for the one batch shape that is really a credits refusal: nothing was
|
|
113
|
+
* dispatched, nothing is rate-deferred (that is exit 7 first), and every
|
|
114
|
+
* conflict says `insufficient_credits`. A newer backend answers this case with
|
|
115
|
+
* a plain 402 envelope itself; this covers a backend that still folds it into
|
|
116
|
+
* `conflicts[]`, so both wire shapes land on the same exit 12.
|
|
117
|
+
*/
|
|
118
|
+
export function isAllCreditsRefusal(resp) {
|
|
119
|
+
return (resp.accepted.length === 0 &&
|
|
120
|
+
resp.deferred.length === 0 &&
|
|
121
|
+
everyConflictIs(resp.conflicts, 'insufficient_credits'));
|
|
122
|
+
}
|
|
123
|
+
export function isPausedRefusal(resp) {
|
|
124
|
+
// Paused takes precedence over credits: topping up cannot resume the workspace.
|
|
125
|
+
return (resp.accepted.length === 0 &&
|
|
126
|
+
resp.deferred.length === 0 &&
|
|
127
|
+
resp.conflicts.some(c => isPausedReason(c.reason)) &&
|
|
128
|
+
resp.conflicts.every(c => isPausedReason(c.reason) || c.reason === 'insufficient_credits'));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The exit-13 refusal for a batch refused because the workspace is paused —
|
|
132
|
+
* the same `FEATURE_GATED` envelope the backend answers a single run with. The server's message on the conflicts says why
|
|
133
|
+
* the workspace is paused; the fallback deliberately doesn't guess.
|
|
134
|
+
*/
|
|
135
|
+
export function pausedConflictError(conflicts, apiUrl) {
|
|
136
|
+
const message = conflicts.find(c => isPausedReason(c.reason) && c.message?.trim())?.message;
|
|
137
|
+
return ApiError.fromEnvelope({
|
|
138
|
+
error: {
|
|
139
|
+
code: 'FEATURE_GATED',
|
|
140
|
+
message: message ?? 'This workspace is paused.',
|
|
141
|
+
nextAction: '',
|
|
142
|
+
requestId: 'local',
|
|
143
|
+
details: { reason: 'paused', conflicts: conflicts.map(c => c.testId) },
|
|
144
|
+
},
|
|
145
|
+
}, 403, undefined, apiUrl);
|
|
146
|
+
}
|
|
147
|
+
export function billingConflictLink(conflicts, apiUrl) {
|
|
148
|
+
const hasPaused = conflicts.some(c => isPausedReason(c.reason));
|
|
149
|
+
const hasCredits = conflicts.some(c => c.reason === 'insufficient_credits');
|
|
150
|
+
if (!hasPaused && !hasCredits)
|
|
151
|
+
return '';
|
|
152
|
+
const refusal = classifyBillingRefusal(hasPaused
|
|
153
|
+
? pausedConflictError(conflicts, apiUrl)
|
|
154
|
+
: insufficientCreditsConflictError(conflicts, apiUrl));
|
|
155
|
+
return refusal ? ` Upgrade: ${refusal.links.pricing}; billing: ${refusal.links.billing}.` : '';
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The exit-12 refusal for an all-credits batch — the SAME `INSUFFICIENT_CREDITS`
|
|
159
|
+
* envelope the single-run route answers (code, exit code, billing `nextAction`),
|
|
160
|
+
* so `index.ts` renders it identically and automation sees one shape. The
|
|
161
|
+
* server's own message (carried on the conflicts) is preferred over the local
|
|
162
|
+
* wording; `apiUrl` resolves the environment-correct portal link.
|
|
163
|
+
*/
|
|
164
|
+
export function insufficientCreditsConflictError(conflicts, apiUrl) {
|
|
165
|
+
const serverMessage = conflicts
|
|
166
|
+
.map(c => c.message?.trim())
|
|
167
|
+
.find((m) => m !== undefined && m !== '');
|
|
168
|
+
const n = conflicts.length;
|
|
169
|
+
return ApiError.fromEnvelope({
|
|
170
|
+
error: {
|
|
171
|
+
code: 'INSUFFICIENT_CREDITS',
|
|
172
|
+
message: serverMessage ??
|
|
173
|
+
`Insufficient credits — nothing was queued (${n} test${n !== 1 ? 's' : ''} refused).`,
|
|
174
|
+
nextAction: insufficientCreditsNextAction(apiUrl),
|
|
175
|
+
requestId: 'local',
|
|
176
|
+
details: { reason: 'insufficient_credits', conflicts: conflicts.map(c => c.testId) },
|
|
177
|
+
},
|
|
178
|
+
}, 402, undefined, apiUrl);
|
|
179
|
+
}
|
|
45
180
|
//# sourceMappingURL=conflict-reason.js.map
|
package/dist/lib/credentials.js
CHANGED
|
@@ -57,6 +57,11 @@ const FIELD_TO_FILE_KEY = {
|
|
|
57
57
|
};
|
|
58
58
|
const CREDENTIALS_LOCK_RETRY_MS = 25;
|
|
59
59
|
const CREDENTIALS_LOCK_WAIT_MS = 5_000;
|
|
60
|
+
// On Windows a lock file that another process is closing or deleting (or that
|
|
61
|
+
// a scanner briefly holds) reports EPERM/EBUSY/EACCES instead of EEXIST. That
|
|
62
|
+
// clears within milliseconds; one that persists this long is a real permission
|
|
63
|
+
// problem and is surfaced as such.
|
|
64
|
+
const CREDENTIALS_LOCK_TRANSIENT_WAIT_MS = 1_000;
|
|
60
65
|
const CREDENTIALS_LOCK_STALE_MS = 30_000;
|
|
61
66
|
export function parseCredentials(content) {
|
|
62
67
|
const result = {};
|
|
@@ -263,6 +268,7 @@ function acquireCredentialsLock(path) {
|
|
|
263
268
|
createdAt: Date.now(),
|
|
264
269
|
token,
|
|
265
270
|
};
|
|
271
|
+
let transientSince;
|
|
266
272
|
while (true) {
|
|
267
273
|
try {
|
|
268
274
|
writeFileSync(lockPath, `${JSON.stringify(lockInfo)}\n`, {
|
|
@@ -276,10 +282,30 @@ function acquireCredentialsLock(path) {
|
|
|
276
282
|
};
|
|
277
283
|
}
|
|
278
284
|
catch (error) {
|
|
279
|
-
|
|
285
|
+
let transient = undefined;
|
|
286
|
+
if (isErrnoException(error) && error.code === 'EEXIST') {
|
|
287
|
+
transient = reclaimStaleCredentialsLock(lockPath);
|
|
288
|
+
}
|
|
289
|
+
else if (isWindowsLockContention(error)) {
|
|
290
|
+
transient = error;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
280
293
|
rethrowCredentialsWriteError(error);
|
|
281
294
|
}
|
|
282
|
-
|
|
295
|
+
if (transient === undefined) {
|
|
296
|
+
transientSince = undefined;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
transientSince ??= Date.now();
|
|
300
|
+
if (Date.now() - transientSince >= CREDENTIALS_LOCK_TRANSIENT_WAIT_MS ||
|
|
301
|
+
Date.now() >= deadline) {
|
|
302
|
+
// Persistent, so not contention: fail exactly as the non-Windows
|
|
303
|
+
// path does for the same error.
|
|
304
|
+
if (transient === error)
|
|
305
|
+
rethrowCredentialsWriteError(error);
|
|
306
|
+
throw transient;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
283
309
|
if (Date.now() >= deadline) {
|
|
284
310
|
throw localValidationError('credentialsLock', 'timed out waiting for another credential update to finish; retry the command', undefined, 'field');
|
|
285
311
|
}
|
|
@@ -315,6 +341,10 @@ function acquireCredentialsLock(path) {
|
|
|
315
341
|
* succeeding on the next `wx` attempt, so there is no need for this function
|
|
316
342
|
* to draw that conclusion itself.
|
|
317
343
|
*/
|
|
344
|
+
/**
|
|
345
|
+
* Returns a Windows lock-contention error from the removal attempt so the
|
|
346
|
+
* caller can retry it within the transient budget; any other failure throws.
|
|
347
|
+
*/
|
|
318
348
|
function reclaimStaleCredentialsLock(lockPath) {
|
|
319
349
|
let lockInfo;
|
|
320
350
|
try {
|
|
@@ -346,10 +376,13 @@ function reclaimStaleCredentialsLock(lockPath) {
|
|
|
346
376
|
unlinkSync(lockPath);
|
|
347
377
|
}
|
|
348
378
|
catch (error) {
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
|
|
379
|
+
if (isErrnoException(error) && error.code === 'ENOENT')
|
|
380
|
+
return undefined;
|
|
381
|
+
if (isWindowsLockContention(error))
|
|
382
|
+
return error;
|
|
383
|
+
throw error;
|
|
352
384
|
}
|
|
385
|
+
return undefined;
|
|
353
386
|
}
|
|
354
387
|
function assertCredentialsLockHeld(lockPath, token) {
|
|
355
388
|
const lockInfo = readCredentialsLockInfo(lockPath);
|
|
@@ -358,18 +391,27 @@ function assertCredentialsLockHeld(lockPath, token) {
|
|
|
358
391
|
throw localValidationError('credentialsLock', 'lost ownership of the credential update lock; retry the command', undefined, 'field');
|
|
359
392
|
}
|
|
360
393
|
function releaseCredentialsLock(lockPath, token) {
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
394
|
+
const deadline = Date.now() + CREDENTIALS_LOCK_TRANSIENT_WAIT_MS;
|
|
395
|
+
while (readCredentialsLockInfo(lockPath)?.token === token) {
|
|
396
|
+
try {
|
|
397
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- `lockPath` is `${path}.lock`, derived from the internal credentials-file path; same risk profile as the other lock fs calls in this file.
|
|
398
|
+
unlinkSync(lockPath);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
catch (error) {
|
|
402
|
+
if (isErrnoException(error) && error.code === 'ENOENT')
|
|
403
|
+
return;
|
|
404
|
+
if (!isWindowsLockContention(error) || Date.now() >= deadline)
|
|
405
|
+
throw error;
|
|
406
|
+
sleepSync(CREDENTIALS_LOCK_RETRY_MS);
|
|
370
407
|
}
|
|
371
408
|
}
|
|
372
409
|
}
|
|
410
|
+
function isWindowsLockContention(error) {
|
|
411
|
+
return (process.platform === 'win32' &&
|
|
412
|
+
isErrnoException(error) &&
|
|
413
|
+
(error.code === 'EPERM' || error.code === 'EBUSY' || error.code === 'EACCES'));
|
|
414
|
+
}
|
|
373
415
|
function readCredentialsLockInfo(lockPath) {
|
|
374
416
|
try {
|
|
375
417
|
return JSON.parse(readFileSync(lockPath, 'utf-8'));
|
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}`;
|
|
@@ -37,6 +37,15 @@ export interface DryRunSampleEntry {
|
|
|
37
37
|
*/
|
|
38
38
|
body: (requestBody?: unknown) => unknown;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Build the matcher RegExp for a route template, e.g.
|
|
42
|
+
* `/tests/{testId}/code` → /^\/tests\/[^/]+\/code$/. Splits on the
|
|
43
|
+
* `{param}` placeholders first, then regex-escapes every literal segment in
|
|
44
|
+
* between (including any literal backslash) so a route literal containing a
|
|
45
|
+
* regex metacharacter is matched literally instead of being reinterpreted as
|
|
46
|
+
* part of the pattern.
|
|
47
|
+
*/
|
|
48
|
+
declare function buildPathPattern(pathTemplate: string): RegExp;
|
|
40
49
|
/**
|
|
41
50
|
* Resolve a fetch URL to its canned sample. Matches against the path
|
|
42
51
|
* portion only (query string is ignored — auto-pagination's `cursor`
|
|
@@ -55,10 +64,13 @@ export interface DryRunSampleEntry {
|
|
|
55
64
|
* `undefined`. For dry-run paths that resolve samples DIRECTLY (bypassing the
|
|
56
65
|
* dry-run fetch impl, which has its own loud INTERNAL envelope for this):
|
|
57
66
|
* without the throw, a lost registry entry surfaces as a raw TypeError deep
|
|
58
|
-
* in a renderer (
|
|
67
|
+
* in a renderer (`samples.ts` is a real merge-conflict
|
|
59
68
|
* hotspot, so a silently dropped entry is a live hazard, not a hypothetical).
|
|
60
69
|
*/
|
|
61
70
|
export declare function findSampleOrThrow(method: string, url: string, requestBody?: unknown): DryRunSampleEntry;
|
|
62
71
|
export declare function findSample(method: string, url: string, requestBody?: unknown): DryRunSampleEntry | undefined;
|
|
63
72
|
/** Test-only export so `samples.test.ts` can iterate the catalog. */
|
|
64
73
|
export declare const DRY_RUN_SAMPLE_ENTRIES: ReadonlyArray<DryRunSampleEntry>;
|
|
74
|
+
/** Test-only export so `samples.test.ts` can verify the route-template matcher directly. */
|
|
75
|
+
export declare const buildDryRunPathPattern: typeof buildPathPattern;
|
|
76
|
+
export {};
|
|
@@ -10,6 +10,8 @@ const SAMPLE_TEST_ID_BLOCKED = 'test_blocked_4f7a';
|
|
|
10
10
|
export const SAMPLE_RUN_ID = 'run_abc';
|
|
11
11
|
const SAMPLE_SCHEDULE_ID = 'sch_7d21ac48';
|
|
12
12
|
const SAMPLE_SCHEDULE_RUN_ID = 'exec_5c08f1b2';
|
|
13
|
+
const SAMPLE_TUNNEL_ID_1 = '00000000-0000-4000-8000-000000000001';
|
|
14
|
+
const SAMPLE_TUNNEL_ID_2 = '00000000-0000-4000-8000-000000000002';
|
|
13
15
|
// Documented sentinel for `test steps --run-id run_failed_sample --dry-run`:
|
|
14
16
|
// keeps wait flows on the default passed sample while still demonstrating a
|
|
15
17
|
// run-scoped failed step offline.
|
|
@@ -440,10 +442,31 @@ const failedRunSample = {
|
|
|
440
442
|
],
|
|
441
443
|
};
|
|
442
444
|
const PATH_PREFIX = '/api/cli/v1';
|
|
445
|
+
// Regex metacharacters that must be escaped when a literal string is spliced
|
|
446
|
+
// into a `new RegExp(...)` source string, so the literal matches only itself.
|
|
447
|
+
const REGEXP_METACHAR = /[.*+?^${}()|[\]\\]/g;
|
|
448
|
+
function escapeRegExpLiteral(literal) {
|
|
449
|
+
return literal.replace(REGEXP_METACHAR, '\\$&');
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Build the matcher RegExp for a route template, e.g.
|
|
453
|
+
* `/tests/{testId}/code` → /^\/tests\/[^/]+\/code$/. Splits on the
|
|
454
|
+
* `{param}` placeholders first, then regex-escapes every literal segment in
|
|
455
|
+
* between (including any literal backslash) so a route literal containing a
|
|
456
|
+
* regex metacharacter is matched literally instead of being reinterpreted as
|
|
457
|
+
* part of the pattern.
|
|
458
|
+
*/
|
|
459
|
+
function buildPathPattern(pathTemplate) {
|
|
460
|
+
const regexSrc = pathTemplate
|
|
461
|
+
.split(/(\{[^}]+\})/g)
|
|
462
|
+
.map(part => (/^\{[^}]+\}$/.test(part) ? '[^/]+' : escapeRegExpLiteral(part)))
|
|
463
|
+
.join('');
|
|
464
|
+
return new RegExp(`^${regexSrc}$`);
|
|
465
|
+
}
|
|
443
466
|
const ENTRIES = [
|
|
444
467
|
entry('whoami', 'GET', '/me', me),
|
|
445
468
|
entry('listProjects', 'GET', '/projects', pageOf(projects)),
|
|
446
|
-
//
|
|
469
|
+
// Plan-generation surface. All three MUST be registered
|
|
447
470
|
// BEFORE `getProject`: findSample is first-match-wins and the projects/*
|
|
448
471
|
// family shares the `/projects/…` prefix, so the more specific plans
|
|
449
472
|
// paths are listed first (same defensive convention as `/tests/{id}/runs`
|
|
@@ -516,7 +539,7 @@ const ENTRIES = [
|
|
|
516
539
|
caseKeys: ids.map(id => `case_dryrun_${id}`),
|
|
517
540
|
};
|
|
518
541
|
}),
|
|
519
|
-
//
|
|
542
|
+
// `project docs upload` two-step facade routes.
|
|
520
543
|
// Registered BEFORE the broader project patterns (design doc §7 ordering
|
|
521
544
|
// rule; findSample is first-match-wins) and with `/docs/upload-url` before
|
|
522
545
|
// `/docs`. NOT consumed by the command's dry-run path: `project docs
|
|
@@ -868,7 +891,7 @@ const ENTRIES = [
|
|
|
868
891
|
// returning status: "failed" for `test wait --dry-run`.
|
|
869
892
|
entry('getRun', 'GET', `/runs/${SAMPLE_FAILED_RUN_ID}`, failedRunSample),
|
|
870
893
|
entry('getRun', 'GET', '/runs/{runId}', passedRunSample),
|
|
871
|
-
//
|
|
894
|
+
// POST /runs/{runId}/cancel. Method-guarded in
|
|
872
895
|
// `findSample` (POST vs `getRun`'s GET), so this can't be shadowed by the
|
|
873
896
|
// broader `/runs/{runId}` pattern above despite sharing its path prefix.
|
|
874
897
|
// `alreadyCancelled: false` — a fresh cancel is the more instructive shape
|
|
@@ -927,16 +950,35 @@ const ENTRIES = [
|
|
|
927
950
|
entry('deleteSchedule', 'DELETE', '/schedules/{scheduleId}', {
|
|
928
951
|
scheduleId: SAMPLE_SCHEDULE_ID,
|
|
929
952
|
}),
|
|
953
|
+
entry('listTunnels', 'GET', '/tunnel', {
|
|
954
|
+
tunnels: [
|
|
955
|
+
{
|
|
956
|
+
clientId: SAMPLE_TUNNEL_ID_1,
|
|
957
|
+
status: 'online',
|
|
958
|
+
createdAt: '2026-01-01T00:00:00.000Z',
|
|
959
|
+
expiresAt: '2026-01-01T01:00:00.000Z',
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
clientId: SAMPLE_TUNNEL_ID_2,
|
|
963
|
+
status: 'offline',
|
|
964
|
+
createdAt: null,
|
|
965
|
+
expiresAt: '2026-01-01T02:00:00.000Z',
|
|
966
|
+
},
|
|
967
|
+
],
|
|
968
|
+
}),
|
|
969
|
+
entry('getTunnelStatus', 'GET', '/tunnel/{clientId}', {
|
|
970
|
+
clientId: SAMPLE_TUNNEL_ID_1,
|
|
971
|
+
status: 'online',
|
|
972
|
+
expiresAt: '2026-01-01T01:00:00.000Z',
|
|
973
|
+
}),
|
|
930
974
|
];
|
|
931
975
|
function entry(operationId, method, pathTemplate, body) {
|
|
932
|
-
// Convert `/tests/{testId}/code` → /^\/tests\/[^/]+\/code$/
|
|
933
|
-
const regexSrc = pathTemplate.replace(/\{[^}]+\}/g, '[^/]+').replace(/\//g, '\\/');
|
|
934
976
|
const bodyFn = typeof body === 'function' ? body : () => body;
|
|
935
977
|
return {
|
|
936
978
|
operationId,
|
|
937
979
|
method,
|
|
938
980
|
pathTemplate,
|
|
939
|
-
pattern:
|
|
981
|
+
pattern: buildPathPattern(pathTemplate),
|
|
940
982
|
body: bodyFn,
|
|
941
983
|
};
|
|
942
984
|
}
|
|
@@ -965,7 +1007,7 @@ function pageOf(items) {
|
|
|
965
1007
|
* `undefined`. For dry-run paths that resolve samples DIRECTLY (bypassing the
|
|
966
1008
|
* dry-run fetch impl, which has its own loud INTERNAL envelope for this):
|
|
967
1009
|
* without the throw, a lost registry entry surfaces as a raw TypeError deep
|
|
968
|
-
* in a renderer (
|
|
1010
|
+
* in a renderer (`samples.ts` is a real merge-conflict
|
|
969
1011
|
* hotspot, so a silently dropped entry is a live hazard, not a hypothetical).
|
|
970
1012
|
*/
|
|
971
1013
|
export function findSampleOrThrow(method, url, requestBody) {
|
|
@@ -1013,4 +1055,6 @@ function extractPath(url) {
|
|
|
1013
1055
|
}
|
|
1014
1056
|
/** Test-only export so `samples.test.ts` can iterate the catalog. */
|
|
1015
1057
|
export const DRY_RUN_SAMPLE_ENTRIES = ENTRIES;
|
|
1058
|
+
/** Test-only export so `samples.test.ts` can verify the route-template matcher directly. */
|
|
1059
|
+
export const buildDryRunPathPattern = buildPathPattern;
|
|
1016
1060
|
//# sourceMappingURL=samples.js.map
|
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,
|
|
@@ -37,10 +63,9 @@ export declare const TERMINATION_EXIT_CODES: {
|
|
|
37
63
|
};
|
|
38
64
|
export type TerminationSignal = keyof typeof TERMINATION_EXIT_CODES;
|
|
39
65
|
/**
|
|
40
|
-
* User-initiated interrupt (SIGINT/SIGTERM/SIGHUP) observed
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* honest partial envelope + re-attach hint, then rethrow to `index.ts`.
|
|
66
|
+
* User-initiated interrupt (SIGINT/SIGTERM/SIGHUP) observed during an armed
|
|
67
|
+
* wait or a disarmed request. Run/wait paths mark the error so `index.ts` can give
|
|
68
|
+
* recovery guidance only when there is a run to re-attach to.
|
|
44
69
|
*
|
|
45
70
|
* Deliberately NOT in `ERROR_CODES` — on a signal the CLI
|
|
46
71
|
* exits 130/143 without consulting the error catalog. The JSON-mode stderr
|
|
@@ -49,6 +74,7 @@ export type TerminationSignal = keyof typeof TERMINATION_EXIT_CODES;
|
|
|
49
74
|
*/
|
|
50
75
|
export declare class InterruptError extends CLIError {
|
|
51
76
|
readonly signal: TerminationSignal;
|
|
77
|
+
runWaitContext: boolean;
|
|
52
78
|
constructor(signal: TerminationSignal);
|
|
53
79
|
}
|
|
54
80
|
export declare class NotImplementedError extends CLIError {
|
|
@@ -65,18 +91,18 @@ export interface ErrorEnvelope {
|
|
|
65
91
|
error: ErrorEnvelopeBody;
|
|
66
92
|
}
|
|
67
93
|
/**
|
|
68
|
-
* Server-returned API error. The CLI
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* constructs an envelope with the same shape so the user sees identical
|
|
72
|
-
* wording across paths).
|
|
94
|
+
* Server-returned API error. The CLI preserves the facade's nonempty
|
|
95
|
+
* `nextAction` and synthesizes one for billing refusals that omit it.
|
|
96
|
+
* Locally-detected pre-flight conditions use the same envelope shape.
|
|
73
97
|
*/
|
|
74
98
|
export declare class ApiError extends CLIError {
|
|
75
99
|
readonly code: ErrorCode;
|
|
76
100
|
readonly requestId: string;
|
|
77
101
|
readonly nextAction: string;
|
|
102
|
+
readonly serverNextAction: string;
|
|
78
103
|
readonly details: Record<string, unknown>;
|
|
79
104
|
readonly httpStatus: number | undefined;
|
|
105
|
+
readonly apiUrl: string | undefined;
|
|
80
106
|
/**
|
|
81
107
|
* Parsed `Retry-After` header value in milliseconds, when present on the
|
|
82
108
|
* HTTP response. Only set for `RATE_LIMITED` (429) responses where the
|
|
@@ -85,7 +111,7 @@ export declare class ApiError extends CLIError {
|
|
|
85
111
|
* absent or unparseable.
|
|
86
112
|
*/
|
|
87
113
|
readonly retryAfterMs: number | undefined;
|
|
88
|
-
constructor(envelope: ErrorEnvelopeBody, httpStatus?: number, retryAfterMs?: number);
|
|
114
|
+
constructor(envelope: ErrorEnvelopeBody, httpStatus?: number, retryAfterMs?: number, apiUrl?: string, serverNextAction?: string);
|
|
89
115
|
/**
|
|
90
116
|
* @param apiUrl Optional API endpoint the failing request targeted. Used to
|
|
91
117
|
* resolve environment-correct portal links in synthesized `nextAction`
|
|
@@ -113,7 +139,14 @@ export declare class ApiError extends CLIError {
|
|
|
113
139
|
* AUTH_REQUIRED template so the user sees the same thing whether the
|
|
114
140
|
* miss was detected before or after sending the request.
|
|
115
141
|
*/
|
|
116
|
-
|
|
142
|
+
/**
|
|
143
|
+
* `profile` is supplied only when a NON-default profile was selected — by
|
|
144
|
+
* `--profile` or by `TESTSPRITE_PROFILE`. Naming it matters because the
|
|
145
|
+
* selection is invisible otherwise: a typo in either one picks a profile
|
|
146
|
+
* that has no credentials, and the generic message sends the reader off to
|
|
147
|
+
* configure the default profile they already have.
|
|
148
|
+
*/
|
|
149
|
+
static authRequired(requestId?: string, profile?: string): ApiError;
|
|
117
150
|
}
|
|
118
151
|
/**
|
|
119
152
|
* Fabricate a locally-detected VALIDATION_ERROR envelope using the same
|
|
@@ -157,3 +190,20 @@ export declare class RequestTimeoutError extends CLIError {
|
|
|
157
190
|
readonly timeoutMs: number;
|
|
158
191
|
constructor(timeoutMs: number, requestId?: string);
|
|
159
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* The synthesized `nextAction` for an INSUFFICIENT_CREDITS refusal when the
|
|
195
|
+
* backend supplied none (older backends; the CLI's own all-credits batch
|
|
196
|
+
* refusal). Portal links resolve per environment from the API endpoint (dev and
|
|
197
|
+
* prod portals live on different domains); an unknown host gets the route only —
|
|
198
|
+
* a hardcoded domain would point at the wrong environment.
|
|
199
|
+
*
|
|
200
|
+
* V3 API keys are membership-bound: a key minted for a team org spends THAT
|
|
201
|
+
* org's wallet, not the holder's personal one, and there is no request-scoped
|
|
202
|
+
* signal at this layer to tell which kind of key just failed. So the hint
|
|
203
|
+
* deliberately does NOT assert "top up your (personal) credits" as the only
|
|
204
|
+
* path — it offers the personal-key link (still correct for the common case)
|
|
205
|
+
* alongside an honest org-bound alternative, rather than guessing. The
|
|
206
|
+
* `testsprite usage` pointer is the CLI-native way to check the balance before
|
|
207
|
+
* a large run fan-out.
|
|
208
|
+
*/
|
|
209
|
+
export declare function insufficientCreditsNextAction(apiUrl?: string): string;
|