@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,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Valibot schemas for the
|
|
2
|
+
* Valibot schemas for the API wire shapes (issue #102, extended by #277).
|
|
3
3
|
*
|
|
4
4
|
* `requestWithMeta` used to return `(await response.json()) as T` with zero
|
|
5
5
|
* runtime validation, so a drifted or partial server response surfaced as
|
|
6
6
|
* `undefined` output or an opaque TypeError deep inside a command. These
|
|
7
7
|
* schemas are wired (opt-in, via `RequestOptions.schema`) into the typed
|
|
8
|
-
* HttpClient helpers
|
|
8
|
+
* HttpClient helpers `triggerRun`, `triggerRunWithMeta`, `triggerRerun`,
|
|
9
9
|
* `triggerBatchRerun`, `triggerBatchRunFresh`, `getRun`, `listTestRuns`,
|
|
10
|
-
* `cancelRun
|
|
11
|
-
*
|
|
10
|
+
* `cancelRun`, and — for the account surfaces below — the `client.get` call
|
|
11
|
+
* sites that own a `/me` or usage read. Every other generic
|
|
12
|
+
* `get`/`post`/`put`/`patch`/`delete` caller stays schema-free and opt-in.
|
|
12
13
|
*
|
|
13
14
|
* Resilience rules (additive server changes must never hard-fail the CLI):
|
|
14
15
|
*
|
|
@@ -44,6 +45,18 @@ import * as v from 'valibot';
|
|
|
44
45
|
function openWireLiteral() {
|
|
45
46
|
return v.custom(value => typeof value === 'string');
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Mirrors `RunEnvironmentRef` (runs.types.ts): the environment a run resolved to.
|
|
50
|
+
* Optional + nullable everywhere it appears: absent on an older backend, `null`
|
|
51
|
+
* when the row carries no stamp — both mean "unknown" to every renderer.
|
|
52
|
+
*/
|
|
53
|
+
const RUN_ENVIRONMENT_REF_SCHEMA = v.looseObject({
|
|
54
|
+
// Either half may be null: a backfilled row whose environment was deleted
|
|
55
|
+
// keeps the denormalised name but no id, and a pre-name row keeps the id only.
|
|
56
|
+
id: v.nullable(v.string()),
|
|
57
|
+
name: v.nullable(v.string()),
|
|
58
|
+
});
|
|
59
|
+
const OPTIONAL_ENVIRONMENT_SCHEMA = v.optional(v.nullable(RUN_ENVIRONMENT_REF_SCHEMA));
|
|
47
60
|
// ---------------------------------------------------------------------------
|
|
48
61
|
// GET /runs/{runId}
|
|
49
62
|
// ---------------------------------------------------------------------------
|
|
@@ -87,6 +100,8 @@ export const RUN_RESPONSE_SCHEMA = v.looseObject({
|
|
|
87
100
|
// when either is null (rule 3).
|
|
88
101
|
codeVersion: v.nullish(v.string(), null),
|
|
89
102
|
targetUrl: v.nullish(v.string(), null),
|
|
103
|
+
// The run's environment — optional with no default (rule 3, optional branch).
|
|
104
|
+
environment: OPTIONAL_ENVIRONMENT_SCHEMA,
|
|
90
105
|
createdFrom: v.nullish(v.string(), null),
|
|
91
106
|
failedStepIndex: v.nullish(v.number(), null),
|
|
92
107
|
failureKind: v.nullish(v.string(), null),
|
|
@@ -161,6 +176,14 @@ export const TRIGGER_RUN_RESPONSE_SCHEMA = v.looseObject({
|
|
|
161
176
|
enqueuedAt: v.string(),
|
|
162
177
|
codeVersion: v.string(),
|
|
163
178
|
targetUrl: v.string(),
|
|
179
|
+
// Optional with NO default (rule 3). The default must stay
|
|
180
|
+
// absent: `undefined` here means "this backend predates the field and
|
|
181
|
+
// stripped what we sent", which is precisely what the opt-out advisory
|
|
182
|
+
// keys on. Defaulting it to `false` would make an old backend look like
|
|
183
|
+
// it had honoured `--no-auto-heal`.
|
|
184
|
+
autoHeal: v.optional(v.boolean()),
|
|
185
|
+
// The run's environment — optional with no default (rule 3, optional branch).
|
|
186
|
+
environment: OPTIONAL_ENVIRONMENT_SCHEMA,
|
|
164
187
|
// Server-built portal links (backend ≥ the run-links change). Optional
|
|
165
188
|
// with no default (rule 3): an older backend omits them, and a V3 run
|
|
166
189
|
// the server could not link stays ABSENT — the renderer prints a
|
|
@@ -223,8 +246,15 @@ export const BATCH_RERUN_RESPONSE_SCHEMA = v.looseObject({
|
|
|
223
246
|
accepted: v.array(v.looseObject({ testId: v.string(), runId: v.string(), enqueuedAt: v.string() })),
|
|
224
247
|
// Mirrors BatchRerunDeferred (runs.types.ts).
|
|
225
248
|
deferred: v.array(v.looseObject({ testId: v.string(), reason: v.string() })),
|
|
226
|
-
// Mirrors BatchRerunConflict (runs.types.ts).
|
|
227
|
-
|
|
249
|
+
// Mirrors BatchRerunConflict (runs.types.ts). `currentRunId` is optional,
|
|
250
|
+
// as in the two schemas below: a refusal only carries a run id when there
|
|
251
|
+
// is a run to point at.
|
|
252
|
+
conflicts: v.array(v.looseObject({
|
|
253
|
+
testId: v.string(),
|
|
254
|
+
currentRunId: v.optional(v.string()),
|
|
255
|
+
reason: v.optional(v.string()),
|
|
256
|
+
message: v.optional(v.string()),
|
|
257
|
+
})),
|
|
228
258
|
// Mirrors BatchRerunClosure / BatchRerunClosureByProject (runs.types.ts).
|
|
229
259
|
closure: v.looseObject({
|
|
230
260
|
byProject: v.array(v.looseObject({
|
|
@@ -247,6 +277,8 @@ export const BATCH_RERUN_RESPONSE_SCHEMA = v.looseObject({
|
|
|
247
277
|
// ---------------------------------------------------------------------------
|
|
248
278
|
/** Mirrors `BatchRunFreshResponse` (runs.types.ts): `POST /tests/batch/run`. */
|
|
249
279
|
export const BATCH_RUN_FRESH_RESPONSE_SCHEMA = v.looseObject({
|
|
280
|
+
// See TRIGGER_RUN_RESPONSE_SCHEMA; absence carries the same meaning.
|
|
281
|
+
autoHeal: v.optional(v.boolean()),
|
|
250
282
|
// Mirrors BatchRunFreshAccepted (runs.types.ts); dashboardUrl is
|
|
251
283
|
// client-synthesized, tolerated as optional.
|
|
252
284
|
accepted: v.array(v.looseObject({
|
|
@@ -269,6 +301,8 @@ export const BATCH_RUN_FRESH_RESPONSE_SCHEMA = v.looseObject({
|
|
|
269
301
|
// keeps computing its legacy template for an older backend / the V2 engine;
|
|
270
302
|
// `null` passes through as a present key meaning "no correct page".
|
|
271
303
|
dashboardUrl: v.nullish(v.string(), undefined),
|
|
304
|
+
// An exact echo confirms that the backend read the target URL override.
|
|
305
|
+
targetUrl: v.optional(v.string()),
|
|
272
306
|
});
|
|
273
307
|
/**
|
|
274
308
|
* `POST /api/cli/v1/testlist/{listId}/run`. Mirrors the batch-run-fresh shape so
|
|
@@ -306,6 +340,8 @@ const RUN_HISTORY_ITEM_SCHEMA = v.looseObject({
|
|
|
306
340
|
// G1b fields: optional on the wire for back-compat with older backends.
|
|
307
341
|
targetUrl: v.optional(v.nullable(v.string())),
|
|
308
342
|
targetUrlSource: v.optional(v.nullable(openWireLiteral())),
|
|
343
|
+
// The run's environment — optional with no default.
|
|
344
|
+
environment: OPTIONAL_ENVIRONMENT_SCHEMA,
|
|
309
345
|
});
|
|
310
346
|
/** Mirrors `ListRunsResponse` (runs.types.ts): `GET /tests/{testId}/runs`. */
|
|
311
347
|
export const LIST_RUNS_RESPONSE_SCHEMA = v.looseObject({
|
|
@@ -319,6 +355,10 @@ export const LIST_RUNS_RESPONSE_SCHEMA = v.looseObject({
|
|
|
319
355
|
historyStartsAt: v.optional(v.string()),
|
|
320
356
|
note: v.optional(v.string()),
|
|
321
357
|
portalUrl: v.optional(v.string()),
|
|
358
|
+
tier: v.optional(v.string()),
|
|
359
|
+
retentionDays: v.optional(v.nullable(v.number())),
|
|
360
|
+
hiddenCount: v.optional(v.number()),
|
|
361
|
+
billingUrl: v.optional(v.string()),
|
|
322
362
|
}),
|
|
323
363
|
});
|
|
324
364
|
/** Mirrors `CliOrgSummary` (lib/org-render.ts): one `Me.organizations[]` entry. */
|
|
@@ -338,11 +378,61 @@ const ORG_BINDING_SCHEMA = v.looseObject({
|
|
|
338
378
|
export const ME_IDENTITY_SCHEMA = v.looseObject({
|
|
339
379
|
userId: v.optional(v.string()),
|
|
340
380
|
keyId: v.optional(v.string()),
|
|
381
|
+
v3Enabled: v.optional(v.boolean()),
|
|
341
382
|
organizations: v.optional(v.array(ORG_SUMMARY_SCHEMA)),
|
|
342
383
|
org: v.optional(ORG_BINDING_SCHEMA),
|
|
343
384
|
});
|
|
385
|
+
/**
|
|
386
|
+
* Mirrors `MeResponse` (commands/auth.ts): the full `GET /me` projection read
|
|
387
|
+
* by `auth whoami` (and, through it, `init`).
|
|
388
|
+
*
|
|
389
|
+
* `scopes` is required and array-typed on purpose — this is the shape drift
|
|
390
|
+
* that actually bites today. `runWhoami` renders `m.scopes.join(', ')` and
|
|
391
|
+
* computes `missingScopes` via `m.scopes.includes(...)` with no guard, so a
|
|
392
|
+
* `/me` body without `scopes` crashes with a raw `TypeError` (exit 1) instead
|
|
393
|
+
* of a typed envelope. Every `/me` fixture in the suite supplies it
|
|
394
|
+
* (`auth.test.ts`, `init.test.ts`, `usage.test.ts`, `cli.subprocess.test.ts`,
|
|
395
|
+
* `test/mock-backend/fixtures.ts`), so requiring it matches observed wire
|
|
396
|
+
* reality; `email` / `displayName` / `v3Enabled` are the genuinely absent-safe
|
|
397
|
+
* ones and stay `v.optional` with no default (rule 3, optional branch).
|
|
398
|
+
*
|
|
399
|
+
* `init` calls this through `runWhoami` inside a try/catch that falls back to
|
|
400
|
+
* a placeholder identity, so a drifted `/me` degrades the setup summary
|
|
401
|
+
* instead of failing the whole `init`.
|
|
402
|
+
*/
|
|
403
|
+
export const ME_RESPONSE_SCHEMA = v.looseObject({
|
|
404
|
+
userId: v.string(),
|
|
405
|
+
keyId: v.string(),
|
|
406
|
+
scopes: v.array(v.string()),
|
|
407
|
+
env: openWireLiteral(),
|
|
408
|
+
email: v.optional(v.string()),
|
|
409
|
+
displayName: v.optional(v.string()),
|
|
410
|
+
v3Enabled: v.optional(v.boolean()),
|
|
411
|
+
});
|
|
412
|
+
// ---------------------------------------------------------------------------
|
|
413
|
+
// GET /me (usage projection)
|
|
414
|
+
// ---------------------------------------------------------------------------
|
|
415
|
+
/**
|
|
416
|
+
* Mirrors `UsageResponse` (commands/usage.ts): the credits/plan projection the
|
|
417
|
+
* `usage` command reads off the same `GET /me` body.
|
|
418
|
+
*
|
|
419
|
+
* `renderUsage` prints `userId`/`keyId`/`env` unconditionally as its "identity
|
|
420
|
+
* block", so those three are required; `credits`, `subPlan` and
|
|
421
|
+
* `creditsPerRun` are forward-compat fields the backend does not send today
|
|
422
|
+
* (see the BACKEND FOLLOW-UP note in usage.ts) and every renderer branch is
|
|
423
|
+
* gated on `!== undefined`, so they stay optional with no default. `scopes`
|
|
424
|
+
* rides along as an unknown extra key and is preserved by `looseObject`.
|
|
425
|
+
*/
|
|
426
|
+
export const USAGE_RESPONSE_SCHEMA = v.looseObject({
|
|
427
|
+
userId: v.string(),
|
|
428
|
+
keyId: v.string(),
|
|
429
|
+
env: openWireLiteral(),
|
|
430
|
+
credits: v.optional(v.number()),
|
|
431
|
+
subPlan: v.optional(v.string()),
|
|
432
|
+
creditsPerRun: v.optional(v.number()),
|
|
433
|
+
});
|
|
344
434
|
// ---------------------------------------------------------------------------
|
|
345
|
-
// /tunnel
|
|
435
|
+
// /tunnel facade
|
|
346
436
|
// ---------------------------------------------------------------------------
|
|
347
437
|
/**
|
|
348
438
|
* Mirrors `TunnelMintResponse` (tunnel.types.ts): `POST /tunnel`.
|
|
@@ -367,4 +457,13 @@ export const TUNNEL_STATUS_RESPONSE_SCHEMA = v.looseObject({
|
|
|
367
457
|
status: openWireLiteral(),
|
|
368
458
|
expiresAt: v.string(),
|
|
369
459
|
});
|
|
460
|
+
/** Mirrors `TunnelListResponse`: a server may add status values or omit creation time. */
|
|
461
|
+
export const TUNNEL_LIST_RESPONSE_SCHEMA = v.looseObject({
|
|
462
|
+
tunnels: v.array(v.looseObject({
|
|
463
|
+
clientId: v.string(),
|
|
464
|
+
status: openWireLiteral(),
|
|
465
|
+
expiresAt: v.string(),
|
|
466
|
+
createdAt: v.optional(v.nullable(v.string())),
|
|
467
|
+
})),
|
|
468
|
+
});
|
|
370
469
|
//# sourceMappingURL=response-schemas.js.map
|
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
|
|
@@ -22,6 +22,36 @@ export interface TriggerRunBody {
|
|
|
22
22
|
* dropping the field.
|
|
23
23
|
*/
|
|
24
24
|
tunnelClientId?: string;
|
|
25
|
+
/**
|
|
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.
|
|
46
|
+
*/
|
|
47
|
+
environment?: string;
|
|
48
|
+
}
|
|
49
|
+
/** The environment a run resolved to — its credentials, its config, its address. */
|
|
50
|
+
export interface RunEnvironmentRef {
|
|
51
|
+
/** `test_environment.id`; null when the row keeps only the denormalised name. */
|
|
52
|
+
id: string | null;
|
|
53
|
+
/** Environment name at seed time; null on an id-only row. */
|
|
54
|
+
name: string | null;
|
|
25
55
|
}
|
|
26
56
|
/**
|
|
27
57
|
* Body sent to `POST /api/cli/v1/tests/{testId}/runs/rerun`.
|
|
@@ -34,6 +64,8 @@ export interface RerunRequest {
|
|
|
34
64
|
autoHeal?: boolean;
|
|
35
65
|
/** BE only: rerun only the named test without expanding the producer/teardown closure. */
|
|
36
66
|
skipDependencies?: boolean;
|
|
67
|
+
/** See `TriggerRunBody.environment` — the named environment to replay against. */
|
|
68
|
+
environment?: string;
|
|
37
69
|
}
|
|
38
70
|
/** One closure member returned in `RerunResponse.closure.members[]`. */
|
|
39
71
|
export interface RerunClosureMember {
|
|
@@ -103,6 +135,8 @@ export interface BatchRerunRequest {
|
|
|
103
135
|
testIds: string[];
|
|
104
136
|
autoHeal?: boolean;
|
|
105
137
|
skipDependencies?: boolean;
|
|
138
|
+
/** See `TriggerRunBody.environment` — applied to every test in the batch. */
|
|
139
|
+
environment?: string;
|
|
106
140
|
}
|
|
107
141
|
/** One accepted run in the batch rerun response. */
|
|
108
142
|
export interface BatchRerunAccepted {
|
|
@@ -116,10 +150,17 @@ export interface BatchRerunDeferred {
|
|
|
116
150
|
testId: string;
|
|
117
151
|
reason: string;
|
|
118
152
|
}
|
|
119
|
-
/**
|
|
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
|
+
*/
|
|
120
159
|
export interface BatchRerunConflict {
|
|
121
160
|
testId: string;
|
|
122
|
-
currentRunId
|
|
161
|
+
currentRunId?: string;
|
|
162
|
+
reason?: ConflictReason;
|
|
163
|
+
message?: string;
|
|
123
164
|
}
|
|
124
165
|
/** Per-project closure summary in the batch rerun response. */
|
|
125
166
|
export interface BatchRerunClosureByProject {
|
|
@@ -162,10 +203,25 @@ export interface TriggerRunResponse {
|
|
|
162
203
|
runId: string;
|
|
163
204
|
status: 'queued';
|
|
164
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;
|
|
165
216
|
/** codeVersion resolved at trigger time from the test row. */
|
|
166
217
|
codeVersion: string;
|
|
167
218
|
/** Resolved target URL (project default when --target-url absent). */
|
|
168
219
|
targetUrl: string;
|
|
220
|
+
/**
|
|
221
|
+
* The environment this run resolved to. Absent on an older backend; `null`
|
|
222
|
+
* when the server resolved no environment row.
|
|
223
|
+
*/
|
|
224
|
+
environment?: RunEnvironmentRef | null;
|
|
169
225
|
/**
|
|
170
226
|
* Portal deep link for the run's test, built by the server for the store
|
|
171
227
|
* that dispatched it. Present-or-absent (never null): an older backend, a
|
|
@@ -244,6 +300,11 @@ export interface RunResponse {
|
|
|
244
300
|
* (`RunEnvelope.targetUrl` is `[string, 'null']`).
|
|
245
301
|
*/
|
|
246
302
|
targetUrl: string | null;
|
|
303
|
+
/**
|
|
304
|
+
* The environment this run resolved to. Absent on an older backend (or a
|
|
305
|
+
* V2-served run); `null` when the row names no environment.
|
|
306
|
+
*/
|
|
307
|
+
environment?: RunEnvironmentRef | null;
|
|
247
308
|
createdFrom: string | null;
|
|
248
309
|
failedStepIndex: number | null;
|
|
249
310
|
failureKind: string | null;
|
|
@@ -351,11 +412,15 @@ export interface RunHistoryItem {
|
|
|
351
412
|
targetUrl?: string | null;
|
|
352
413
|
/**
|
|
353
414
|
* G1b — provenance of `targetUrl`.
|
|
354
|
-
* - `'run'`: stamped at run-trigger time (authoritative).
|
|
415
|
+
* - `'run'`: stamped at run-trigger time (authoritative; V2).
|
|
355
416
|
* - `'unresolved'`: backend could not resolve a URL for this run.
|
|
356
|
-
* - `null
|
|
417
|
+
* - `null`: a V3 run — the environment in `environment` IS the target and
|
|
418
|
+
* `targetUrl` is its address, so there is no separate provenance.
|
|
419
|
+
* - absent: pre-G1b backend; treat as unknown.
|
|
357
420
|
*/
|
|
358
421
|
targetUrlSource?: 'run' | 'unresolved' | null;
|
|
422
|
+
/** The environment this run resolved to. Absent on older backends. */
|
|
423
|
+
environment?: RunEnvironmentRef | null;
|
|
359
424
|
}
|
|
360
425
|
/**
|
|
361
426
|
* Pre-cutover metadata block present when the test has no CLI-tracked
|
|
@@ -376,6 +441,11 @@ export interface RunHistoryMeta {
|
|
|
376
441
|
note?: string;
|
|
377
442
|
/** Portal URL where older run history can be viewed. */
|
|
378
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;
|
|
379
449
|
}
|
|
380
450
|
/**
|
|
381
451
|
* Response from `GET /api/cli/v1/tests/{testId}/runs`.
|
|
@@ -396,6 +466,8 @@ export interface ListRunsQuery {
|
|
|
396
466
|
source?: RunSource;
|
|
397
467
|
/** ISO timestamp (after client-side duration parsing). */
|
|
398
468
|
since?: string;
|
|
469
|
+
/** Only runs whose credentials came from this environment (by name). */
|
|
470
|
+
environment?: string;
|
|
399
471
|
}
|
|
400
472
|
/**
|
|
401
473
|
* Body sent to `POST /api/cli/v1/tests/batch/run`.
|
|
@@ -406,6 +478,12 @@ export interface BatchRunFreshRequest {
|
|
|
406
478
|
projectId: string;
|
|
407
479
|
testIds?: string[];
|
|
408
480
|
source: 'cli';
|
|
481
|
+
/** See `TriggerRunBody.autoHeal`, including why `true` is never sent. */
|
|
482
|
+
autoHeal?: false;
|
|
483
|
+
/** See `TriggerRunBody.environment` — applied to every test in the batch. */
|
|
484
|
+
environment?: string;
|
|
485
|
+
/** Per-run URL override for the batch; echoed when the backend honors it. */
|
|
486
|
+
targetUrl?: string;
|
|
409
487
|
}
|
|
410
488
|
/** One accepted run in the batch fresh-run response. */
|
|
411
489
|
export interface BatchRunFreshAccepted {
|
|
@@ -437,6 +515,8 @@ export interface BatchRunFreshAccepted {
|
|
|
437
515
|
*/
|
|
438
516
|
export interface BatchRunFreshResponse {
|
|
439
517
|
accepted: BatchRunFreshAccepted[];
|
|
518
|
+
/** See `TriggerRunResponse.autoHeal`; absence means the same thing. */
|
|
519
|
+
autoHeal?: boolean;
|
|
440
520
|
/**
|
|
441
521
|
* A run-slot conflict. `currentRunId`, when present, is the id of the run
|
|
442
522
|
* ALREADY in flight for this test — under `--wait` the CLI polls it to a
|
|
@@ -461,4 +541,10 @@ export interface BatchRunFreshResponse {
|
|
|
461
541
|
* nothing rather than a dead link.
|
|
462
542
|
*/
|
|
463
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;
|
|
464
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
|
/**
|