@testsprite/testsprite-cli 0.12.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 +11 -4
- 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 +436 -5
- 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.js +9 -9
- package/dist/commands/project.d.ts +5 -5
- package/dist/commands/project.js +42 -42
- package/dist/commands/schedule.d.ts +2 -0
- package/dist/commands/schedule.js +18 -10
- package/dist/commands/test.d.ts +73 -27
- package/dist/commands/test.js +1756 -413
- package/dist/commands/testlist.js +49 -19
- 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 +34 -20
- 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 +23 -2
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.js +20 -1
- package/dist/lib/conflict-reason.d.ts +27 -3
- package/dist/lib/conflict-reason.js +53 -4
- package/dist/lib/credentials.js +56 -14
- 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 +18 -11
- package/dist/lib/errors.js +111 -13
- 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 +1 -0
- package/dist/lib/gh-output.js +13 -4
- package/dist/lib/history-retention.d.ts +8 -0
- package/dist/lib/history-retention.js +24 -0
- package/dist/lib/http.d.ts +37 -19
- package/dist/lib/http.js +46 -24
- 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 +1 -1
- package/dist/lib/local-target.js +1 -1
- 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 +88 -7
- package/dist/lib/runs.types.d.ts +59 -10
- 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 +6 -6
- package/dist/lib/telemetry.d.ts +4 -1
- package/dist/lib/telemetry.js +13 -13
- 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/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 -38
package/dist/lib/runs.types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Extended by M3.4 piece-5 — `test result --history` command.
|
|
5
5
|
|
|
6
6
|
*/
|
|
7
|
-
import type { RunConflict } from './conflict-reason.js';
|
|
7
|
+
import type { ConflictReason, RunConflict } from './conflict-reason.js';
|
|
8
8
|
/** Literal body sent to `POST /api/cli/v1/tests/{testId}/runs`. */
|
|
9
9
|
export interface TriggerRunBody {
|
|
10
10
|
/** Fixed source literal for CLI-triggered runs. */
|
|
@@ -12,7 +12,7 @@ export interface TriggerRunBody {
|
|
|
12
12
|
/** Optional override for the project's configured target URL. */
|
|
13
13
|
targetUrl?: string;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Id of a tunnel client minted through `POST /api/cli/v1/tunnel`.
|
|
16
16
|
*
|
|
17
17
|
* An ID, never a proxy string — the caller does not choose the proxy host.
|
|
18
18
|
* The server loads the binding, checks it belongs to the calling principal
|
|
@@ -23,11 +23,26 @@ export interface TriggerRunBody {
|
|
|
23
23
|
*/
|
|
24
24
|
tunnelClientId?: string;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
26
|
+
* May the agent re-author this test when its stored code no longer
|
|
27
|
+
* executes?
|
|
28
|
+
*
|
|
29
|
+
* OMITTED on purpose whenever auto-heal is on. The field is tri-state on the
|
|
30
|
+
* wire and the CLI only ever sends one of its three states: `false`, for
|
|
31
|
+
* `--no-auto-heal`. Absent means "heal, but replay a user-authored body
|
|
32
|
+
* rather than rewriting it" — the server-side default — and sending an
|
|
33
|
+
* explicit `true` would mean something DIFFERENT and worse here: an
|
|
34
|
+
* unconditional heal that re-authors code the user wrote. So the default is
|
|
35
|
+
* expressed by saying nothing, which also means an older backend (the field
|
|
36
|
+
* is stripped by `whitelist: true`, never 400'd) behaves exactly as it does
|
|
37
|
+
* today for the default case.
|
|
38
|
+
*/
|
|
39
|
+
autoHeal?: false;
|
|
40
|
+
/**
|
|
41
|
+
* The NAME of the project environment whose credentials, auto-auth and OTP
|
|
42
|
+
* settings this run should use (`unique(project_id, name)` server side).
|
|
43
|
+
* Absent → the project's default environment, exactly as before. Composes
|
|
44
|
+
* with `targetUrl`/`tunnelClientId`: those pick WHERE the browser goes,
|
|
45
|
+
* this picks WHOSE credentials it logs in with.
|
|
31
46
|
*/
|
|
32
47
|
environment?: string;
|
|
33
48
|
}
|
|
@@ -135,10 +150,17 @@ export interface BatchRerunDeferred {
|
|
|
135
150
|
testId: string;
|
|
136
151
|
reason: string;
|
|
137
152
|
}
|
|
138
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* One testId in the batch rerun response that did not dispatch.
|
|
155
|
+
*
|
|
156
|
+
* `currentRunId` is present only when the refusal points at a run already in
|
|
157
|
+
* flight; otherwise `reason` says why it did not start.
|
|
158
|
+
*/
|
|
139
159
|
export interface BatchRerunConflict {
|
|
140
160
|
testId: string;
|
|
141
|
-
currentRunId
|
|
161
|
+
currentRunId?: string;
|
|
162
|
+
reason?: ConflictReason;
|
|
163
|
+
message?: string;
|
|
142
164
|
}
|
|
143
165
|
/** Per-project closure summary in the batch rerun response. */
|
|
144
166
|
export interface BatchRerunClosureByProject {
|
|
@@ -181,6 +203,16 @@ export interface TriggerRunResponse {
|
|
|
181
203
|
runId: string;
|
|
182
204
|
status: 'queued';
|
|
183
205
|
enqueuedAt: string;
|
|
206
|
+
/**
|
|
207
|
+
* The EFFECTIVE heal decision the server made for this run.
|
|
208
|
+
*
|
|
209
|
+
* OPTIONAL on purpose, and the absence is the load-bearing case: the backend
|
|
210
|
+
* runs `whitelist: true`, so a CLI sending `autoHeal` to a server that
|
|
211
|
+
* predates the field has it silently STRIPPED and the run heals anyway. An
|
|
212
|
+
* absent echo is how the CLI learns it is talking to such a server and that
|
|
213
|
+
* `--no-auto-heal` did nothing — without it the opt-out is unfalsifiable.
|
|
214
|
+
*/
|
|
215
|
+
autoHeal?: boolean;
|
|
184
216
|
/** codeVersion resolved at trigger time from the test row. */
|
|
185
217
|
codeVersion: string;
|
|
186
218
|
/** Resolved target URL (project default when --target-url absent). */
|
|
@@ -409,6 +441,11 @@ export interface RunHistoryMeta {
|
|
|
409
441
|
note?: string;
|
|
410
442
|
/** Portal URL where older run history can be viewed. */
|
|
411
443
|
portalUrl?: string;
|
|
444
|
+
/** Plan-limited history details; absent on older backends and V2. */
|
|
445
|
+
tier?: string;
|
|
446
|
+
retentionDays?: number | null;
|
|
447
|
+
hiddenCount?: number;
|
|
448
|
+
billingUrl?: string;
|
|
412
449
|
}
|
|
413
450
|
/**
|
|
414
451
|
* Response from `GET /api/cli/v1/tests/{testId}/runs`.
|
|
@@ -429,7 +466,7 @@ export interface ListRunsQuery {
|
|
|
429
466
|
source?: RunSource;
|
|
430
467
|
/** ISO timestamp (after client-side duration parsing). */
|
|
431
468
|
since?: string;
|
|
432
|
-
/**
|
|
469
|
+
/** Only runs whose credentials came from this environment (by name). */
|
|
433
470
|
environment?: string;
|
|
434
471
|
}
|
|
435
472
|
/**
|
|
@@ -441,8 +478,12 @@ export interface BatchRunFreshRequest {
|
|
|
441
478
|
projectId: string;
|
|
442
479
|
testIds?: string[];
|
|
443
480
|
source: 'cli';
|
|
481
|
+
/** See `TriggerRunBody.autoHeal`, including why `true` is never sent. */
|
|
482
|
+
autoHeal?: false;
|
|
444
483
|
/** See `TriggerRunBody.environment` — applied to every test in the batch. */
|
|
445
484
|
environment?: string;
|
|
485
|
+
/** Per-run URL override for the batch; echoed when the backend honors it. */
|
|
486
|
+
targetUrl?: string;
|
|
446
487
|
}
|
|
447
488
|
/** One accepted run in the batch fresh-run response. */
|
|
448
489
|
export interface BatchRunFreshAccepted {
|
|
@@ -474,6 +515,8 @@ export interface BatchRunFreshAccepted {
|
|
|
474
515
|
*/
|
|
475
516
|
export interface BatchRunFreshResponse {
|
|
476
517
|
accepted: BatchRunFreshAccepted[];
|
|
518
|
+
/** See `TriggerRunResponse.autoHeal`; absence means the same thing. */
|
|
519
|
+
autoHeal?: boolean;
|
|
477
520
|
/**
|
|
478
521
|
* A run-slot conflict. `currentRunId`, when present, is the id of the run
|
|
479
522
|
* ALREADY in flight for this test — under `--wait` the CLI polls it to a
|
|
@@ -498,4 +541,10 @@ export interface BatchRunFreshResponse {
|
|
|
498
541
|
* nothing rather than a dead link.
|
|
499
542
|
*/
|
|
500
543
|
dashboardUrl?: string | null;
|
|
544
|
+
/**
|
|
545
|
+
* Exact echo of the request's `targetUrl` when the backend read the override.
|
|
546
|
+
* A missing or different echo makes the CLI refuse the batch rather than
|
|
547
|
+
* report a verdict for an unconfirmed target.
|
|
548
|
+
*/
|
|
549
|
+
targetUrl?: string;
|
|
501
550
|
}
|
package/dist/lib/secret-file.js
CHANGED
|
@@ -18,8 +18,13 @@
|
|
|
18
18
|
* Callers pass the flag name so the envelope names the flag the user actually
|
|
19
19
|
* typed — one helper serves `--password-file` today and the remaining
|
|
20
20
|
* credential/auto-auth file flags once they are migrated.
|
|
21
|
+
*
|
|
22
|
+
* The check (is this a regular file?) and the use (read its bytes) happen
|
|
23
|
+
* against a single open file descriptor rather than against the path twice,
|
|
24
|
+
* so nothing can be swapped in between: whatever `openSync` resolved is
|
|
25
|
+
* exactly what `fstatSync` classifies and `readFileSync` reads.
|
|
21
26
|
*/
|
|
22
|
-
import { readFileSync, statSync } from 'node:fs';
|
|
27
|
+
import { closeSync, constants, fstatSync, openSync, readFileSync, statSync } from 'node:fs';
|
|
23
28
|
import { isAbsolute, resolve } from 'node:path';
|
|
24
29
|
import { localValidationError } from './errors.js';
|
|
25
30
|
/**
|
|
@@ -38,26 +43,67 @@ import { localValidationError } from './errors.js';
|
|
|
38
43
|
*/
|
|
39
44
|
export function readSecretFileGuarded(flag, path) {
|
|
40
45
|
const absolute = isAbsolute(path) ? path : resolve(process.cwd(), path);
|
|
41
|
-
let
|
|
46
|
+
let fd;
|
|
42
47
|
try {
|
|
43
|
-
//
|
|
44
|
-
|
|
48
|
+
// O_NONBLOCK matters here specifically because this is a *-file flag:
|
|
49
|
+
// a plain `open(path, O_RDONLY)` on a FIFO with no writer blocks the
|
|
50
|
+
// calling thread until one connects (POSIX fifo(7)), and since this is
|
|
51
|
+
// a synchronous fs call on Node's single main thread, that blocks the
|
|
52
|
+
// entire CLI process -- including its SIGINT handler, since delivering
|
|
53
|
+
// that signal to JS requires the (blocked) event loop to run. The old
|
|
54
|
+
// statSync()-first code rejected a FIFO instantly via `isFile()` before
|
|
55
|
+
// ever opening it; O_NONBLOCK restores that instant-fail behavior by
|
|
56
|
+
// making the open itself return right away instead of waiting for a
|
|
57
|
+
// writer, so the existing fstatSync().isFile() check below still does
|
|
58
|
+
// the rejecting. It has no effect on a regular file's read semantics.
|
|
59
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- this is the guard itself: `absolute` is the user-supplied --*-file path after isAbsolute()/resolve(); everything after (fstat, then read) uses the fd this open() returns, not the path string, which is the mitigation for a non-literal fs path here.
|
|
60
|
+
fd = openSync(absolute, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));
|
|
45
61
|
}
|
|
46
62
|
catch (err) {
|
|
63
|
+
// Opening a directory succeeds on POSIX (the fstat().isFile() check
|
|
64
|
+
// below is the gate for that case) but can fail right here on other
|
|
65
|
+
// platforms, and not always with the same errno a directory produces
|
|
66
|
+
// elsewhere. Classify the failure by re-stat'ing the path once,
|
|
67
|
+
// diagnostically, before falling back to errno-based mapping: nothing is
|
|
68
|
+
// read as a result, so this cannot reintroduce a check-then-use race —
|
|
69
|
+
// it only decides which message to throw for an open() that already
|
|
70
|
+
// failed.
|
|
71
|
+
let isDir = false;
|
|
72
|
+
try {
|
|
73
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- diagnostic only, to pick an error message for the open() failure above; no data is read from `absolute` here or afterward.
|
|
74
|
+
isDir = statSync(absolute).isDirectory();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Path vanished or became inaccessible between the failed open() and
|
|
78
|
+
// this diagnostic stat — fall through to the errno-based mapping,
|
|
79
|
+
// which still accurately reports that the open() failed.
|
|
80
|
+
}
|
|
81
|
+
if (isDir) {
|
|
82
|
+
throw localValidationError(flag, `not a regular file: ${path}`);
|
|
83
|
+
}
|
|
47
84
|
throw secretFileError(flag, path, err, 'stat');
|
|
48
85
|
}
|
|
49
|
-
// A directory would otherwise reach readFileSync and throw EISDIR on Linux
|
|
50
|
-
// while resolving to an empty read on some platforms — reject it up front so
|
|
51
|
-
// the contract is the same everywhere.
|
|
52
|
-
if (!stat.isFile()) {
|
|
53
|
-
throw localValidationError(flag, `not a regular file: ${path}`);
|
|
54
|
-
}
|
|
55
86
|
try {
|
|
56
|
-
|
|
57
|
-
|
|
87
|
+
let stat;
|
|
88
|
+
try {
|
|
89
|
+
stat = fstatSync(fd);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
throw secretFileError(flag, path, err, 'stat');
|
|
93
|
+
}
|
|
94
|
+
if (!stat.isFile()) {
|
|
95
|
+
throw localValidationError(flag, `not a regular file: ${path}`);
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- `fd` is the open file descriptor from openSync() above, not a path string; the rule's non-literal-argument check does not distinguish the two, but there is no path re-resolution here for anything to race against.
|
|
99
|
+
return readFileSync(fd, 'utf8').trim();
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
throw secretFileError(flag, path, err, 'read');
|
|
103
|
+
}
|
|
58
104
|
}
|
|
59
|
-
|
|
60
|
-
|
|
105
|
+
finally {
|
|
106
|
+
closeSync(fd);
|
|
61
107
|
}
|
|
62
108
|
}
|
|
63
109
|
/**
|
|
@@ -76,6 +122,18 @@ function secretFileError(flag, path, err, verb) {
|
|
|
76
122
|
if (code === 'EISDIR') {
|
|
77
123
|
return localValidationError(flag, `not a regular file: ${path}`);
|
|
78
124
|
}
|
|
125
|
+
if (code === 'EMFILE' || code === 'ENFILE') {
|
|
126
|
+
// The old stat-then-read code's statSync() opens no file descriptor, so
|
|
127
|
+
// it always succeeded even with the process's fd table exhausted; only
|
|
128
|
+
// the later readFileSync (which does open one) could hit EMFILE/ENFILE,
|
|
129
|
+
// landing in the generic "cannot read" wording. The fd-based guard's
|
|
130
|
+
// openSync is the first fs call here, so the same exhaustion now surfaces
|
|
131
|
+
// at what looks like the "stat" step; route it to the same "cannot read"
|
|
132
|
+
// wording regardless of `verb` so fd-table exhaustion always reads the
|
|
133
|
+
// same as it did before, no matter which syscall actually hit the ceiling.
|
|
134
|
+
const reason = err instanceof Error ? err.message : 'unknown error';
|
|
135
|
+
return localValidationError(flag, `cannot read ${path}: ${reason}`);
|
|
136
|
+
}
|
|
79
137
|
const reason = err instanceof Error ? err.message : 'unknown error';
|
|
80
138
|
return localValidationError(flag, `cannot ${verb} ${path}: ${reason}`);
|
|
81
139
|
}
|
|
@@ -42,6 +42,8 @@ export declare function isPlanTemplateInvocation(commandPath: string, planTempla
|
|
|
42
42
|
export interface SkillPresenceDeps {
|
|
43
43
|
existsSync?: (p: string) => boolean;
|
|
44
44
|
readFileSync?: (p: string) => string;
|
|
45
|
+
/** Best-effort diagnostic hook for an unreadable managed-section target. */
|
|
46
|
+
onReadError?: (path: string, error: unknown) => void;
|
|
45
47
|
/**
|
|
46
48
|
* Narrow the check to specific agents. Pass the agents actually calling: a
|
|
47
49
|
* skill installed for some OTHER agent is not one this caller can read, and
|
|
@@ -80,6 +82,8 @@ export interface SkillNudgeContext {
|
|
|
80
82
|
} | undefined;
|
|
81
83
|
/** Sink for the hint line; defaults to `process.stderr`. */
|
|
82
84
|
stderr?: (line: string) => void;
|
|
85
|
+
/** Emit best-effort diagnostics for swallowed nudge errors. */
|
|
86
|
+
debug?: boolean;
|
|
83
87
|
existsSync?: (p: string) => boolean;
|
|
84
88
|
readFileSync?: (p: string) => string;
|
|
85
89
|
}
|
|
@@ -93,6 +97,7 @@ export interface SkillNudgeContext {
|
|
|
93
97
|
* not `--dry-run`, the command is in {@link SKILL_NUDGE_COMMANDS}, the opt-out
|
|
94
98
|
* env is unset, the active profile has an api key (un-configured callers hit an
|
|
95
99
|
* auth error that already points at setup), and the skill is not already
|
|
96
|
-
* installed. Never throws and never blocks the command — any error is swallowed
|
|
100
|
+
* installed. Never throws and never blocks the command — any error is swallowed;
|
|
101
|
+
* `--debug` callers receive the swallowed reason on stderr.
|
|
97
102
|
*/
|
|
98
103
|
export declare function maybeEmitSkillNudge(ctx: SkillNudgeContext): void;
|
package/dist/lib/skill-nudge.js
CHANGED
|
@@ -78,7 +78,15 @@ export function isVerifySkillInstalled(dir, deps = {}) {
|
|
|
78
78
|
if (hasCompleteManagedSection(read(full)))
|
|
79
79
|
return true;
|
|
80
80
|
}
|
|
81
|
-
catch {
|
|
81
|
+
catch (error) {
|
|
82
|
+
// A diagnostic callback must not change this best-effort probe's
|
|
83
|
+
// behavior, even if the caller's stderr sink itself is unavailable.
|
|
84
|
+
try {
|
|
85
|
+
deps.onReadError?.(full, error);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// ignore diagnostic delivery failures
|
|
89
|
+
}
|
|
82
90
|
// unreadable AGENTS.md → treat this target as absent, keep checking
|
|
83
91
|
}
|
|
84
92
|
continue;
|
|
@@ -105,9 +113,11 @@ function hasCompleteManagedSection(content) {
|
|
|
105
113
|
* not `--dry-run`, the command is in {@link SKILL_NUDGE_COMMANDS}, the opt-out
|
|
106
114
|
* env is unset, the active profile has an api key (un-configured callers hit an
|
|
107
115
|
* auth error that already points at setup), and the skill is not already
|
|
108
|
-
* installed. Never throws and never blocks the command — any error is swallowed
|
|
116
|
+
* installed. Never throws and never blocks the command — any error is swallowed;
|
|
117
|
+
* `--debug` callers receive the swallowed reason on stderr.
|
|
109
118
|
*/
|
|
110
119
|
export function maybeEmitSkillNudge(ctx) {
|
|
120
|
+
const write = ctx.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
111
121
|
try {
|
|
112
122
|
if (ctx.output !== 'text')
|
|
113
123
|
return;
|
|
@@ -122,7 +132,13 @@ export function maybeEmitSkillNudge(ctx) {
|
|
|
122
132
|
const profile = lookup(ctx.profile, { path: credsPath });
|
|
123
133
|
if (!profile?.apiKey)
|
|
124
134
|
return;
|
|
125
|
-
const presence = {
|
|
135
|
+
const presence = {
|
|
136
|
+
existsSync: ctx.existsSync,
|
|
137
|
+
readFileSync: ctx.readFileSync,
|
|
138
|
+
onReadError: ctx.debug
|
|
139
|
+
? (path, error) => emitDebug(write, `skill nudge could not read ${path}; treating target as absent`, error)
|
|
140
|
+
: undefined,
|
|
141
|
+
};
|
|
126
142
|
// When the environment names the calling agent, only that agent's skill
|
|
127
143
|
// counts — an install for a different agent is one this caller cannot read.
|
|
128
144
|
//
|
|
@@ -142,7 +158,6 @@ export function maybeEmitSkillNudge(ctx) {
|
|
|
142
158
|
// No identified caller: the any-target answer is all this can support.
|
|
143
159
|
return;
|
|
144
160
|
}
|
|
145
|
-
const write = ctx.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
146
161
|
// Names the callers actually missing a skill, not every caller detected —
|
|
147
162
|
// with one of two satisfied, "not for cursor" is the actionable half and
|
|
148
163
|
// "not for claude or cursor" would be wrong about claude.
|
|
@@ -154,9 +169,21 @@ export function maybeEmitSkillNudge(ctx) {
|
|
|
154
169
|
'TestSprite. Run `testsprite setup` (or `testsprite agent install`) to set it up. ' +
|
|
155
170
|
`Silence: ${SKILL_NUDGE_OPT_OUT_ENV}=1`);
|
|
156
171
|
}
|
|
157
|
-
catch {
|
|
172
|
+
catch (error) {
|
|
158
173
|
// A nudge must never break, delay, or alter the exit status of a real
|
|
159
174
|
// command. Swallow everything (missing creds file, fs races, etc.).
|
|
175
|
+
if (ctx.debug)
|
|
176
|
+
emitDebug(write, 'skill nudge skipped', error);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** Emit a diagnostic without letting the diagnostic path break the command. */
|
|
180
|
+
function emitDebug(write, context, error) {
|
|
181
|
+
try {
|
|
182
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
183
|
+
write(`[debug] ${context}: ${reason}`);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// A broken stderr sink must not turn a best-effort nudge into a failure.
|
|
160
187
|
}
|
|
161
188
|
}
|
|
162
189
|
/** Interpret common env-var spellings for an enabled opt-out flag. */
|
|
@@ -42,11 +42,14 @@
|
|
|
42
42
|
* so following it would hand an attacker-controlled Location header a
|
|
43
43
|
* live SSRF primitive running on the caller's machine or CI runner.
|
|
44
44
|
*/
|
|
45
|
+
import { type ShutdownHandle } from './interrupt.js';
|
|
45
46
|
export interface TargetUrlPreflightDeps {
|
|
46
47
|
/** DNS resolution hook. Defaults to `dns.promises.lookup`. Injectable for tests. */
|
|
47
48
|
dnsLookup?: (hostname: string) => Promise<unknown>;
|
|
48
49
|
/** HTTP probe hook. Defaults to the global `fetch`. Injectable for tests. */
|
|
49
50
|
fetchImpl?: typeof fetch;
|
|
51
|
+
shutdownSignal?: AbortSignal;
|
|
52
|
+
shutdown?: Pick<ShutdownHandle, 'runCriticalOperation'>;
|
|
50
53
|
/**
|
|
51
54
|
* Whether a proxy dispatcher is actually installed for this process.
|
|
52
55
|
* Defaults to `isProxyAgentActive()` (proxy.ts), which inspects the
|
|
@@ -71,10 +74,9 @@ export type TargetUrlPreflightOutcome = {
|
|
|
71
74
|
};
|
|
72
75
|
/**
|
|
73
76
|
* Probe `rawUrl` for the narrow refusal set described in the module
|
|
74
|
-
* docstring.
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* shape via `assertNotLocal` before this runs).
|
|
77
|
+
* docstring. Network failures classify to `warn` or `refuse`, while a process
|
|
78
|
+
* interruption propagates. A malformed URL degrades to `warn` rather than
|
|
79
|
+
* crashing (callers validate the URL shape via `assertNotLocal` before this runs).
|
|
78
80
|
*/
|
|
79
81
|
export declare function probeTargetUrl(rawUrl: string, deps?: TargetUrlPreflightDeps): Promise<TargetUrlPreflightOutcome>;
|
|
80
82
|
/**
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
*/
|
|
45
45
|
import * as dns from 'node:dns';
|
|
46
46
|
import { isIP } from 'node:net';
|
|
47
|
-
import { ApiError } from './errors.js';
|
|
47
|
+
import { ApiError, InterruptError } from './errors.js';
|
|
48
|
+
import { globalShutdown } from './interrupt.js';
|
|
48
49
|
import { isProxyAgentActive } from './proxy.js';
|
|
49
50
|
import { disallowedIpReason } from './target-url.js';
|
|
50
51
|
/** ~8s, matching the MCP plugin's `checkPortListening` TCP-probe budget. */
|
|
@@ -93,10 +94,9 @@ function bareHost(hostname) {
|
|
|
93
94
|
}
|
|
94
95
|
/**
|
|
95
96
|
* Probe `rawUrl` for the narrow refusal set described in the module
|
|
96
|
-
* docstring.
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* shape via `assertNotLocal` before this runs).
|
|
97
|
+
* docstring. Network failures classify to `warn` or `refuse`, while a process
|
|
98
|
+
* interruption propagates. A malformed URL degrades to `warn` rather than
|
|
99
|
+
* crashing (callers validate the URL shape via `assertNotLocal` before this runs).
|
|
100
100
|
*/
|
|
101
101
|
export async function probeTargetUrl(rawUrl, deps = {}) {
|
|
102
102
|
const proxied = deps.proxyActive ?? isProxyAgentActive();
|
|
@@ -162,64 +162,77 @@ export async function probeTargetUrl(rawUrl, deps = {}) {
|
|
|
162
162
|
// configured — so this step (unlike the DNS step above) is proxy-aware
|
|
163
163
|
// by construction, not just proxy-tolerant.
|
|
164
164
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
|
|
165
|
+
const shutdownSignal = deps.shutdownSignal ?? globalShutdown.signal;
|
|
166
|
+
const shutdown = deps.shutdown ?? globalShutdown;
|
|
167
|
+
return shutdown.runCriticalOperation(async () => {
|
|
168
|
+
try {
|
|
169
|
+
const resp = await fetchImpl(rawUrl, {
|
|
170
|
+
method: 'GET',
|
|
171
|
+
// Never follow — see the module docstring. A 3xx is reachability
|
|
172
|
+
// proof on its own (handled immediately below); the redirect target
|
|
173
|
+
// is unvalidated and must not be dereferenced.
|
|
174
|
+
redirect: 'manual',
|
|
175
|
+
signal: AbortSignal.any([AbortSignal.timeout(PREFLIGHT_TIMEOUT_MS), shutdownSignal]),
|
|
176
|
+
});
|
|
177
|
+
// Never read the body — only the status matters here. Cancel it so the
|
|
178
|
+
// connection is released promptly instead of buffering a full page.
|
|
179
|
+
await resp.body?.cancel().catch(() => undefined);
|
|
180
|
+
if (shutdownSignal.aborted)
|
|
181
|
+
throw shutdownSignal.reason;
|
|
182
|
+
if (resp.status >= 300 && resp.status < 400) {
|
|
183
|
+
// A redirect is a live-server signal (e.g. a real app 302ing an
|
|
184
|
+
// unauthenticated GET to a login page) — reachable, not refused. The
|
|
185
|
+
// Location header is deliberately never inspected or dereferenced.
|
|
186
|
+
return { verdict: 'ok' };
|
|
187
|
+
}
|
|
188
|
+
if (GATEWAY_ERROR_STATUSES.has(resp.status)) {
|
|
189
|
+
if (proxied) {
|
|
190
|
+
return {
|
|
191
|
+
verdict: 'warn',
|
|
192
|
+
reason: `--target-url responded HTTP ${resp.status} — not conclusive behind a configured proxy`,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
verdict: 'refuse',
|
|
197
|
+
reason: `--target-url responded HTTP ${resp.status} (gateway error — the target is unreachable)`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (resp.status >= 400) {
|
|
201
|
+
return { verdict: 'warn', reason: `--target-url responded HTTP ${resp.status}` };
|
|
202
|
+
}
|
|
181
203
|
return { verdict: 'ok' };
|
|
182
204
|
}
|
|
183
|
-
|
|
184
|
-
if (
|
|
205
|
+
catch (err) {
|
|
206
|
+
if (shutdownSignal.aborted)
|
|
207
|
+
throw shutdownSignal.reason;
|
|
208
|
+
if (err instanceof InterruptError)
|
|
209
|
+
throw err;
|
|
210
|
+
if (errorHasCode(err, ['ECONNREFUSED'])) {
|
|
211
|
+
if (proxied) {
|
|
212
|
+
return {
|
|
213
|
+
verdict: 'warn',
|
|
214
|
+
reason: 'connection to --target-url was refused — not conclusive behind a configured proxy',
|
|
215
|
+
};
|
|
216
|
+
}
|
|
185
217
|
return {
|
|
186
|
-
verdict: '
|
|
187
|
-
reason:
|
|
218
|
+
verdict: 'refuse',
|
|
219
|
+
reason: 'connection to --target-url was refused (ECONNREFUSED)',
|
|
188
220
|
};
|
|
189
221
|
}
|
|
190
|
-
|
|
191
|
-
verdict: 'refuse',
|
|
192
|
-
reason: `--target-url responded HTTP ${resp.status} (gateway error — the target is unreachable)`,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
if (resp.status >= 400) {
|
|
196
|
-
return { verdict: 'warn', reason: `--target-url responded HTTP ${resp.status}` };
|
|
197
|
-
}
|
|
198
|
-
return { verdict: 'ok' };
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
if (errorHasCode(err, ['ECONNREFUSED'])) {
|
|
202
|
-
if (proxied) {
|
|
222
|
+
if (isTimeoutError(err)) {
|
|
203
223
|
return {
|
|
204
224
|
verdict: 'warn',
|
|
205
|
-
reason:
|
|
225
|
+
reason: `--target-url did not respond within ${PREFLIGHT_TIMEOUT_MS / 1000}s`,
|
|
206
226
|
};
|
|
207
227
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (isTimeoutError(err)) {
|
|
228
|
+
// TLS errors and anything else unclassified: warn only — the refusal
|
|
229
|
+
// set stays narrow to exactly what that analysis measured.
|
|
211
230
|
return {
|
|
212
231
|
verdict: 'warn',
|
|
213
|
-
reason:
|
|
232
|
+
reason: `could not reach --target-url (${err instanceof Error ? err.message : String(err)})`,
|
|
214
233
|
};
|
|
215
234
|
}
|
|
216
|
-
|
|
217
|
-
// set stays narrow to exactly what that analysis measured.
|
|
218
|
-
return {
|
|
219
|
-
verdict: 'warn',
|
|
220
|
-
reason: `could not reach --target-url (${err instanceof Error ? err.message : String(err)})`,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
235
|
+
});
|
|
223
236
|
}
|
|
224
237
|
/** Shared wording so `--help` and every refuse/warn message agree on the escape hatch. */
|
|
225
238
|
const SKIP_HINT = 'Skip this check entirely with --skip-preflight.';
|
|
@@ -240,7 +253,7 @@ export async function assertTargetUrlReachable(targetUrl, opts, deps, stderrFn)
|
|
|
240
253
|
throw ApiError.fromEnvelope({
|
|
241
254
|
error: {
|
|
242
255
|
code: 'VALIDATION_ERROR',
|
|
243
|
-
message: `--target-url is not reachable: ${outcome.reason}.`,
|
|
256
|
+
message: `--target-url is not reachable: ${outcome.reason}. Retry with --skip-preflight if the preview is still warming up.`,
|
|
244
257
|
nextAction: 'This CLI probes reachability from where the CLI runs, not from the Lambda that ' +
|
|
245
258
|
'executes the test — a false positive is possible (e.g. an IP allowlist that permits ' +
|
|
246
259
|
`the Lambda but not this machine). If you're confident the target is reachable from the ` +
|
package/dist/lib/target-url.js
CHANGED
|
@@ -160,12 +160,12 @@ export function disallowedIpReason(host) {
|
|
|
160
160
|
}
|
|
161
161
|
function disallowedIpv4Reason(address) {
|
|
162
162
|
// Unspecified — binds every interface, including loopback. Named precisely
|
|
163
|
-
// rather than lumped in as "localhost"
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
163
|
+
// rather than lumped in as "localhost": since a loopback URL is now a
|
|
164
|
+
// legitimate STORED target, calling `0.0.0.0` a localhost target produced a
|
|
165
|
+
// self-contradicting refusal — "localhost targets are not allowed" above a
|
|
166
|
+
// hint saying to use `localhost`. It is also simply not loopback: the
|
|
167
|
+
// server refuses it as a stored URL, so the accurate remedy is the loopback
|
|
168
|
+
// address the app is also reachable on.
|
|
169
169
|
if (address === '0.0.0.0') {
|
|
170
170
|
return { reason: UNSPECIFIED_ADDRESS_REASON, hintKind: 'loopback' };
|
|
171
171
|
}
|
package/dist/lib/telemetry.d.ts
CHANGED
|
@@ -104,7 +104,7 @@ export declare function buildCiContext(env: NodeJS.ProcessEnv): {
|
|
|
104
104
|
* `conflict-reason.ts`'s rendering type: `tunnel-required` is a server reason
|
|
105
105
|
* this CLI has no label for yet, and `not_found` is rendered but not counted.
|
|
106
106
|
*/
|
|
107
|
-
export type TelemetryConflictReason = 'in_flight' | 'insufficient_credits' | 'billing_hold' | 'mcp_view_only' | 'local_address' | 'tunnel-required' | 'error';
|
|
107
|
+
export type TelemetryConflictReason = 'in_flight' | 'insufficient_credits' | 'paused' | 'billing_hold' | 'mcp_view_only' | 'local_address' | 'tunnel-required' | 'error';
|
|
108
108
|
/**
|
|
109
109
|
* Low-cardinality facts a command records about its own outcome before it
|
|
110
110
|
* returns, merged into the one event `index.ts` fires. Counts are non-negative
|
|
@@ -121,6 +121,9 @@ export interface TelemetryExtras {
|
|
|
121
121
|
failed?: number;
|
|
122
122
|
blocked?: number;
|
|
123
123
|
timedOut?: number;
|
|
124
|
+
/** Local tunnel pool limit (1–10) and observed peak, without ids or target details. */
|
|
125
|
+
localConcurrencyLimit?: number;
|
|
126
|
+
localPeakInFlight?: number;
|
|
124
127
|
/** The most frequent conflict reason of the batch. */
|
|
125
128
|
conflictReason?: TelemetryConflictReason;
|
|
126
129
|
/** `ci init` facts. */
|
package/dist/lib/telemetry.js
CHANGED
|
@@ -23,17 +23,11 @@
|
|
|
23
23
|
* repository names — `errorCode` is a stable machine code, never the human
|
|
24
24
|
* message, and the CI repository is reduced to a salted, truncated hash so
|
|
25
25
|
* runs from one repo can be grouped without the slug ever leaving the runner.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* than `exitCode` or `durationMs` already do, and is included so a `--wait`
|
|
32
|
-
* timeout is distinguishable from a genuinely slow backend (see `errorOrigin`
|
|
33
|
-
* below). Anyone auditing this allowlist can verify that reasoning against
|
|
34
|
-
* the two call sites that set it (`RequestTimeoutError.timeoutMs`, and the
|
|
35
|
-
* `ApiError` `details.timeoutSeconds` a `--wait` deadline conversion stamps)
|
|
36
|
-
* without having to trust a one-off exception.
|
|
26
|
+
* Flag-derived values are limited to bounded numeric controls:
|
|
27
|
+
* `timeoutSeconds` is the operator's timeout (not a URL or free text) and
|
|
28
|
+
* distinguishes a wait deadline from a slow backend; `localConcurrencyLimit`
|
|
29
|
+
* is an integer 1–10 and lets local batch outcomes be grouped by load.
|
|
30
|
+
* `localPeakInFlight` is the observed count, also bounded by that limit.
|
|
37
31
|
*
|
|
38
32
|
* `errorOrigin` ('client' | 'server') and `timeoutSeconds` are sent by this
|
|
39
33
|
* revision of the CLI. The telemetry endpoint validates against an allowlist
|
|
@@ -126,12 +120,15 @@ const COUNT_KEYS = [
|
|
|
126
120
|
'failed',
|
|
127
121
|
'blocked',
|
|
128
122
|
'timedOut',
|
|
123
|
+
'localConcurrencyLimit',
|
|
124
|
+
'localPeakInFlight',
|
|
129
125
|
];
|
|
130
126
|
const BOOLEAN_KEYS = ['force', 'workflowExisted'];
|
|
131
127
|
const ENUM_KEYS = {
|
|
132
128
|
conflictReason: new Set([
|
|
133
129
|
'in_flight',
|
|
134
130
|
'insufficient_credits',
|
|
131
|
+
'paused',
|
|
135
132
|
'billing_hold',
|
|
136
133
|
'mcp_view_only',
|
|
137
134
|
'local_address',
|
|
@@ -370,8 +367,11 @@ export function buildTelemetryEvent(input, env, isTTY, extras = {}) {
|
|
|
370
367
|
* opted-out call never reads the credentials file.
|
|
371
368
|
*/
|
|
372
369
|
export function resolveTelemetryAuth(opts, deps = {}) {
|
|
370
|
+
// No `?? 'default'`: `loadConfig` resolves the documented
|
|
371
|
+
// flag > TESTSPRITE_PROFILE > default order from the same env, and a
|
|
372
|
+
// pre-collapsed string here would hide the env var from it.
|
|
373
373
|
const config = loadConfig({
|
|
374
|
-
profile: opts.profile
|
|
374
|
+
profile: opts.profile,
|
|
375
375
|
endpointUrl: opts.endpointUrl,
|
|
376
376
|
env: deps.env ?? process.env,
|
|
377
377
|
credentialsPath: deps.credentialsPath ?? defaultCredentialsPath(),
|
|
@@ -406,7 +406,7 @@ export async function recordOutcome(input, deps = {}) {
|
|
|
406
406
|
// `auth remove` could delete the profile); fall back to a fresh read.
|
|
407
407
|
const config = deps.resolvedAuth ??
|
|
408
408
|
loadConfig({
|
|
409
|
-
profile: input.profile
|
|
409
|
+
profile: input.profile,
|
|
410
410
|
endpointUrl: input.endpointUrl,
|
|
411
411
|
env,
|
|
412
412
|
credentialsPath: deps.credentialsPath ?? defaultCredentialsPath(),
|