@testsprite/testsprite-cli 0.7.0 → 0.9.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 +62 -45
- package/dist/commands/agent.d.ts +3 -0
- package/dist/commands/agent.js +79 -10
- package/dist/commands/ci.d.ts +88 -0
- package/dist/commands/ci.js +432 -0
- package/dist/commands/doctor.js +100 -1
- package/dist/commands/init.d.ts +45 -2
- package/dist/commands/init.js +198 -29
- package/dist/commands/project.d.ts +78 -0
- package/dist/commands/project.js +439 -5
- package/dist/commands/test.d.ts +193 -4
- package/dist/commands/test.js +1948 -398
- package/dist/commands/testlist.js +15 -9
- package/dist/commands/tunnel.d.ts +72 -0
- package/dist/commands/tunnel.js +367 -0
- package/dist/index.js +107 -38
- package/dist/lib/agent-detect.d.ts +53 -0
- package/dist/lib/agent-detect.js +198 -0
- package/dist/lib/dry-run/samples.d.ts +9 -0
- package/dist/lib/dry-run/samples.js +116 -0
- package/dist/lib/gh-output.d.ts +7 -0
- package/dist/lib/gh-output.js +50 -7
- package/dist/lib/http.d.ts +104 -0
- package/dist/lib/http.js +126 -7
- package/dist/lib/interrupt.d.ts +38 -13
- package/dist/lib/interrupt.js +130 -15
- package/dist/lib/local-target.d.ts +95 -0
- package/dist/lib/local-target.js +184 -0
- package/dist/lib/plan-poll.d.ts +171 -0
- package/dist/lib/plan-poll.js +442 -0
- package/dist/lib/plans.types.d.ts +130 -0
- package/dist/lib/plans.types.js +31 -0
- package/dist/lib/poll-support.d.ts +26 -0
- package/dist/lib/poll-support.js +65 -0
- package/dist/lib/poll.d.ts +1 -0
- package/dist/lib/poll.js +2 -40
- package/dist/lib/response-schemas.d.ts +13 -0
- package/dist/lib/response-schemas.js +46 -0
- package/dist/lib/run-progress.d.ts +41 -0
- package/dist/lib/run-progress.js +56 -0
- package/dist/lib/runs.types.d.ts +50 -0
- package/dist/lib/skill-nudge.d.ts +13 -5
- package/dist/lib/skill-nudge.js +40 -14
- package/dist/lib/target-url-preflight.js +3 -3
- package/dist/lib/target-url.d.ts +54 -8
- package/dist/lib/target-url.js +274 -68
- package/dist/lib/telemetry.d.ts +11 -0
- package/dist/lib/telemetry.js +1 -0
- package/dist/lib/ticker.d.ts +8 -0
- package/dist/lib/ticker.js +3 -0
- package/dist/lib/tunnel-session.d.ts +138 -0
- package/dist/lib/tunnel-session.js +249 -0
- package/dist/lib/tunnel.types.d.ts +54 -0
- package/dist/lib/tunnel.types.js +8 -0
- package/dist/vendor/tunnel-client/client.d.ts +82 -0
- package/dist/vendor/tunnel-client/client.js +924 -0
- package/dist/vendor/tunnel-client/config.d.ts +49 -0
- package/dist/vendor/tunnel-client/config.js +50 -0
- package/dist/vendor/tunnel-client/index.d.ts +9 -0
- package/dist/vendor/tunnel-client/index.js +9 -0
- package/dist/vendor/tunnel-client/lodash-lite.d.ts +14 -0
- package/dist/vendor/tunnel-client/lodash-lite.js +24 -0
- package/dist/vendor/tunnel-client/protocol.d.ts +60 -0
- package/dist/vendor/tunnel-client/protocol.js +143 -0
- package/dist/vendor/tunnel-client/types.d.ts +101 -0
- package/dist/vendor/tunnel-client/types.js +10 -0
- package/dist/vendor/tunnel-client/ws-compat.d.ts +206 -0
- package/dist/vendor/tunnel-client/ws-compat.js +316 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
- package/skills/testsprite-onboard.skill.md +60 -4
- package/skills/testsprite-verify.codex.md +22 -16
- package/skills/testsprite-verify.skill.md +27 -18
package/dist/lib/gh-output.d.ts
CHANGED
|
@@ -17,9 +17,14 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export interface CiRunRow {
|
|
19
19
|
testId: string;
|
|
20
|
+
/** Human title for the Test column; falls back to `testId` when absent. */
|
|
21
|
+
title?: string;
|
|
20
22
|
runId?: string;
|
|
21
23
|
status: string;
|
|
24
|
+
/** Test-case page link — anchors the Test column title. */
|
|
22
25
|
dashboardUrl?: string;
|
|
26
|
+
/** This run's execution-result page link — anchors the Run column. */
|
|
27
|
+
executionUrl?: string;
|
|
23
28
|
error?: string;
|
|
24
29
|
}
|
|
25
30
|
export interface CiSummary {
|
|
@@ -54,9 +59,11 @@ export declare function summarizeAcceptedPayload(capturedJson: string, opts?: {
|
|
|
54
59
|
*/
|
|
55
60
|
export declare function summarizeSingleRun(run: {
|
|
56
61
|
testId?: string;
|
|
62
|
+
testTitle?: string | null;
|
|
57
63
|
runId?: string;
|
|
58
64
|
status?: string;
|
|
59
65
|
dashboardUrl?: string | null;
|
|
66
|
+
executionUrl?: string | null;
|
|
60
67
|
error?: string | null;
|
|
61
68
|
}): CiSummary;
|
|
62
69
|
/** Markdown table for the GitHub job summary. */
|
package/dist/lib/gh-output.js
CHANGED
|
@@ -54,9 +54,11 @@ export function summarizeAcceptedPayload(capturedJson, opts = {}) {
|
|
|
54
54
|
: undefined;
|
|
55
55
|
return {
|
|
56
56
|
testId: String(row.testId ?? ''),
|
|
57
|
+
...(typeof row.testTitle === 'string' ? { title: row.testTitle } : {}),
|
|
57
58
|
...(typeof row.runId === 'string' ? { runId: row.runId } : {}),
|
|
58
59
|
status: String(row.status ?? 'unknown'),
|
|
59
60
|
...(typeof row.dashboardUrl === 'string' ? { dashboardUrl: row.dashboardUrl } : {}),
|
|
61
|
+
...(typeof row.executionUrl === 'string' ? { executionUrl: row.executionUrl } : {}),
|
|
60
62
|
...(typeof errorMessage === 'string' ? { error: errorMessage } : {}),
|
|
61
63
|
};
|
|
62
64
|
})
|
|
@@ -86,9 +88,11 @@ export function summarizeAcceptedPayload(capturedJson, opts = {}) {
|
|
|
86
88
|
export function summarizeSingleRun(run) {
|
|
87
89
|
const row = {
|
|
88
90
|
testId: String(run.testId ?? ''),
|
|
91
|
+
...(typeof run.testTitle === 'string' ? { title: run.testTitle } : {}),
|
|
89
92
|
...(typeof run.runId === 'string' ? { runId: run.runId } : {}),
|
|
90
93
|
status: String(run.status ?? 'unknown'),
|
|
91
94
|
...(typeof run.dashboardUrl === 'string' ? { dashboardUrl: run.dashboardUrl } : {}),
|
|
95
|
+
...(typeof run.executionUrl === 'string' ? { executionUrl: run.executionUrl } : {}),
|
|
92
96
|
...(typeof run.error === 'string' && run.error.length > 0 ? { error: run.error } : {}),
|
|
93
97
|
};
|
|
94
98
|
const passed = row.status === 'passed' ? 1 : 0;
|
|
@@ -101,9 +105,30 @@ export function summarizeSingleRun(run) {
|
|
|
101
105
|
* layout and a CR/LF would inject extra Markdown lines (rows are newline-joined)
|
|
102
106
|
* — the same injection class the annotation escaping guards against, on the
|
|
103
107
|
* step-summary surface.
|
|
108
|
+
*
|
|
109
|
+
* Backslashes are escaped FIRST: GFM reads `\\` as a literal backslash, so a
|
|
110
|
+
* title's own trailing `\` would otherwise consume the `\` we insert before `|`
|
|
111
|
+
* (turning `\|` back into an unescaped column break). Doubling the value's own
|
|
112
|
+
* backslashes up front keeps every later insert a real escape.
|
|
104
113
|
*/
|
|
105
114
|
function escapeTableCell(value) {
|
|
106
|
-
return value
|
|
115
|
+
return value
|
|
116
|
+
.replace(/\\/g, '\\\\')
|
|
117
|
+
.replace(/\|/g, '\\|')
|
|
118
|
+
.replace(/[\r\n]+/g, ' ');
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Escape a value used as the TEXT half of a Markdown `[text](url)` link inside a
|
|
122
|
+
* table cell. On top of the cell escaping (backslashes, `|`, CR/LF), an unescaped
|
|
123
|
+
* `]` closes the link early — so a bracketed title like `x](https://evil) y` would
|
|
124
|
+
* retarget the visible link at the injected URL. Titles are workspace-authored and
|
|
125
|
+
* often LLM-generated, so brackets are realistic; escape `[` and `]` (backslash).
|
|
126
|
+
* `escapeTableCell` has already doubled the value's own backslashes, so the escape
|
|
127
|
+
* we insert before a bracket can't be consumed by a preceding `\`. Plain (unlinked)
|
|
128
|
+
* cells keep `escapeTableCell`.
|
|
129
|
+
*/
|
|
130
|
+
function escapeMarkdownLinkText(value) {
|
|
131
|
+
return escapeTableCell(value).replace(/([[\]])/g, '\\$1');
|
|
107
132
|
}
|
|
108
133
|
/**
|
|
109
134
|
* Escape a URL for a Markdown `[text](url)` link: a literal `)` closes the link
|
|
@@ -127,10 +152,24 @@ export function renderJobSummaryMarkdown(summary) {
|
|
|
127
152
|
'| Test | Status | Run |',
|
|
128
153
|
'| --- | --- | --- |',
|
|
129
154
|
...summary.runs.map(row => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
155
|
+
// `|| ` not `?? `: an empty / whitespace-only title must fall back to the
|
|
156
|
+
// id (a blank Test cell is useless), matching JUnit's `name?.trim() || id`.
|
|
157
|
+
const label = row.title?.trim() || row.testId;
|
|
158
|
+
const runId = row.runId ?? '';
|
|
159
|
+
// Test cell links the human label to the TEST-CASE page (`dashboardUrl`);
|
|
160
|
+
// Run cell links to THIS RUN's result page (`executionUrl`). The two are
|
|
161
|
+
// distinct destinations — the run link is absent for a V2 run (no execution
|
|
162
|
+
// page), where the run cell degrades to the raw runId. The label sits in
|
|
163
|
+
// link-text position, so it uses the bracket-aware escaper.
|
|
164
|
+
const test = row.dashboardUrl
|
|
165
|
+
? `[${escapeMarkdownLinkText(label)}](${escapeMarkdownUrl(row.dashboardUrl)})`
|
|
166
|
+
: escapeTableCell(label);
|
|
167
|
+
// Keep the run id as the link text (not a constant "result") so it stays
|
|
168
|
+
// scannable while being clickable.
|
|
169
|
+
const run = row.executionUrl && runId
|
|
170
|
+
? `[${escapeMarkdownLinkText(runId)}](${escapeMarkdownUrl(row.executionUrl)})`
|
|
171
|
+
: escapeTableCell(runId);
|
|
172
|
+
return `| ${test} | ${escapeTableCell(row.status)} | ${run} |`;
|
|
134
173
|
}),
|
|
135
174
|
'',
|
|
136
175
|
].join('\n');
|
|
@@ -179,10 +218,14 @@ export function emitGithubOutputs(summary, env, sinks, opts = {}) {
|
|
|
179
218
|
if (row.status === 'passed')
|
|
180
219
|
continue;
|
|
181
220
|
const detail = row.error !== undefined ? ` ${row.error}` : '';
|
|
182
|
-
|
|
221
|
+
// Prefer this run's result page over the test-case page — on a failure the
|
|
222
|
+
// result is what the reviewer wants to open. Falls back to the test-case
|
|
223
|
+
// link (V2 runs, which have no execution page), then to nothing.
|
|
224
|
+
const linkUrl = row.executionUrl ?? row.dashboardUrl;
|
|
225
|
+
const link = linkUrl !== undefined ? ` ${linkUrl}` : '';
|
|
183
226
|
// Escape both halves: a raw multiline run error (or a testId) must not be
|
|
184
227
|
// able to smuggle a second workflow command into the Actions stream.
|
|
185
|
-
const title = `TestSprite ${escapeCommandProperty(row.testId)}`;
|
|
228
|
+
const title = `TestSprite ${escapeCommandProperty(row.title?.trim() || row.testId)}`;
|
|
186
229
|
const message = escapeCommandData(`status=${row.status}${detail}${link}`);
|
|
187
230
|
annotate(`::error title=${title}::${message}`);
|
|
188
231
|
}
|
package/dist/lib/http.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { ErrorCode } from './errors.js';
|
|
|
3
3
|
import { ApiError } from './errors.js';
|
|
4
4
|
import type { CliTestListRunResponse } from './testlist.types.js';
|
|
5
5
|
import type { TriggerRunBody, TriggerRunResponse, RunResponse, RerunRequest, RerunResponse, BatchRerunRequest, BatchRerunResponse, BatchRunFreshRequest, BatchRunFreshResponse, ListRunsQuery, ListRunsResponse, CancelRunResponse } from './runs.types.js';
|
|
6
|
+
import type { CliAcceptPlansResponse, CliGeneratePlansResponse, CliGetPlansResponse } from './plans.types.js';
|
|
7
|
+
import type { MintTunnelBody, TunnelMintResponse, TunnelStatusResponse } from './tunnel.types.js';
|
|
6
8
|
export type FetchImpl = typeof globalThis.fetch;
|
|
7
9
|
export type DebugEventKind = 'request' | 'response' | 'retry' | 'error';
|
|
8
10
|
export interface DebugEvent {
|
|
@@ -101,6 +103,15 @@ export interface RequestOptions<T = unknown> {
|
|
|
101
103
|
query?: Record<string, string | number | boolean | undefined>;
|
|
102
104
|
signal?: AbortSignal;
|
|
103
105
|
requestId?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Accept an HTTP 204 as a successful response with no body.
|
|
108
|
+
*
|
|
109
|
+
* This is deliberately opt-in: the CLI's established response contract is
|
|
110
|
+
* JSON even for schema-less generic callers, so silently returning
|
|
111
|
+
* `undefined` would turn a server-side body regression into apparent
|
|
112
|
+
* success. Use only for endpoints whose documented success response is 204.
|
|
113
|
+
*/
|
|
114
|
+
allowNoContent?: boolean;
|
|
104
115
|
/**
|
|
105
116
|
* Optional valibot schema for the parsed 2xx response body (issue #102).
|
|
106
117
|
*
|
|
@@ -154,6 +165,15 @@ export interface RequestOptions<T = unknown> {
|
|
|
154
165
|
* other callers.
|
|
155
166
|
*/
|
|
156
167
|
retryOnRateLimit?: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Disable every automatic retry for a read whose caller owns its cadence.
|
|
170
|
+
*
|
|
171
|
+
* The borrowed-tunnel liveness probe is one such read: a failed observation
|
|
172
|
+
* is "unknown", and its next attempt belongs to the 15-second wall-clock
|
|
173
|
+
* schedule rather than an HTTP-layer retry burst. Defaults to `true` so all
|
|
174
|
+
* existing request paths retain their retry behaviour.
|
|
175
|
+
*/
|
|
176
|
+
retry?: boolean;
|
|
157
177
|
}
|
|
158
178
|
/**
|
|
159
179
|
* Result of a successful HTTP request, including the parsed body and the
|
|
@@ -177,6 +197,11 @@ export declare class HttpClient {
|
|
|
177
197
|
private readonly shutdownSignal?;
|
|
178
198
|
private readonly maxResponseBytes;
|
|
179
199
|
constructor(options: HttpClientOptions);
|
|
200
|
+
/** The resolved facade base URL (trailing slash trimmed). Read-only —
|
|
201
|
+
* callers that bypass the client for a side-channel request (e.g. the
|
|
202
|
+
* presigned S3 PUT) use it to reason about the facade's locality
|
|
203
|
+
* (DEV-384 review F3). */
|
|
204
|
+
get resolvedBaseUrl(): string;
|
|
180
205
|
/**
|
|
181
206
|
* Read the backend's supported-floor header off a response and forward it to
|
|
182
207
|
* `onServerVersion` when present. Never throws — a bad header must not break
|
|
@@ -305,6 +330,45 @@ export declare class HttpClient {
|
|
|
305
330
|
includeSteps?: boolean;
|
|
306
331
|
signal?: AbortSignal;
|
|
307
332
|
}): Promise<RunResponse>;
|
|
333
|
+
/**
|
|
334
|
+
* POST /api/cli/v1/tunnel — mint a tunnel client for `test run --local`.
|
|
335
|
+
*
|
|
336
|
+
* The ONLY response on this surface that carries a secret. Deliberately NOT
|
|
337
|
+
* sent with an `Idempotency-Key`: the interceptor persists the response body
|
|
338
|
+
* for the whole replay window, so an idempotent mint would put a live
|
|
339
|
+
* credential in the idempotency store — the exact copy the server-side
|
|
340
|
+
* binding exists to avoid. The server rate-limits this route instead.
|
|
341
|
+
*
|
|
342
|
+
* `retryOnConflict: false` for the same reason `triggerRun` opts out: a 409
|
|
343
|
+
* here means the per-principal live-binding cap is reached, which is a
|
|
344
|
+
* standing condition, not a transient snapshot conflict.
|
|
345
|
+
*/
|
|
346
|
+
mintTunnel(body: MintTunnelBody, options?: {
|
|
347
|
+
signal?: AbortSignal;
|
|
348
|
+
}): Promise<TunnelMintResponse>;
|
|
349
|
+
/**
|
|
350
|
+
* GET /api/cli/v1/tunnel/{clientId} — is this binding's client connected?
|
|
351
|
+
*
|
|
352
|
+
* A 404 covers unknown, another tenant's, and expired alike; the surface is
|
|
353
|
+
* deliberately not an existence oracle for client ids. Callers must not
|
|
354
|
+
* translate a transport failure or a non-200 into `offline` — "the tunnel is
|
|
355
|
+
* down" and "we could not reach TestSprite to ask" are different answers,
|
|
356
|
+
* and collapsing them is what DEV-1005 was.
|
|
357
|
+
*/
|
|
358
|
+
getTunnelStatus(clientId: string, options?: {
|
|
359
|
+
signal?: AbortSignal;
|
|
360
|
+
retry?: boolean;
|
|
361
|
+
}): Promise<TunnelStatusResponse>;
|
|
362
|
+
/**
|
|
363
|
+
* DELETE /api/cli/v1/tunnel/{clientId} — destroy a binding. 204, idempotent.
|
|
364
|
+
*
|
|
365
|
+
* No body, no `Idempotency-Key`: the operation is idempotent by definition
|
|
366
|
+
* and this is the call made from a `finally` block, including after a
|
|
367
|
+
* signal, where there is least room for extra ceremony.
|
|
368
|
+
*/
|
|
369
|
+
deleteTunnel(clientId: string, options?: {
|
|
370
|
+
signal?: AbortSignal;
|
|
371
|
+
}): Promise<void>;
|
|
308
372
|
/**
|
|
309
373
|
* POST /api/cli/v1/runs/{runId}/cancel
|
|
310
374
|
* User-initiated cancel of a queued/running run (DEV-331 piece 3). No
|
|
@@ -319,6 +383,46 @@ export declare class HttpClient {
|
|
|
319
383
|
cancelRun(runId: string, options?: {
|
|
320
384
|
signal?: AbortSignal;
|
|
321
385
|
}): Promise<CancelRunResponse>;
|
|
386
|
+
/**
|
|
387
|
+
* POST /api/cli/v1/projects/{projectId}/plans/generate (DEV-384 V3-B)
|
|
388
|
+
* Start whichever generation stage the project is missing next. The body
|
|
389
|
+
* is empty by contract — the server decides which rung fires. 202 both
|
|
390
|
+
* for `accepted` (a stage started) and `nothing_to_start` (proposals are
|
|
391
|
+
* already staged; the facade's no-restart guard refuses a duplicate
|
|
392
|
+
* append because it would wipe the batch and re-bill 2 credits).
|
|
393
|
+
*
|
|
394
|
+
* `retryOnConflict: false` — a 409 here is `stage_in_flight`, a flow
|
|
395
|
+
* signal the ladder answers by attaching and polling, never a transient
|
|
396
|
+
* snapshot conflict to paper over with a retry.
|
|
397
|
+
*/
|
|
398
|
+
generatePlans(projectId: string, options: {
|
|
399
|
+
idempotencyKey: string;
|
|
400
|
+
signal?: AbortSignal;
|
|
401
|
+
}): Promise<CliGeneratePlansResponse>;
|
|
402
|
+
/**
|
|
403
|
+
* GET /api/cli/v1/projects/{projectId}/plans (DEV-384 V3-B)
|
|
404
|
+
* Pure read: the facade-synthesized generation status, the staged
|
|
405
|
+
* proposal list (stable proposalIds — what `accept --only` consumes),
|
|
406
|
+
* and a best-effort credits block. When `waitSeconds` (1–25) is
|
|
407
|
+
* provided the server long-polls: one request per window, answered
|
|
408
|
+
* early on any change.
|
|
409
|
+
*/
|
|
410
|
+
getPlans(projectId: string, options?: {
|
|
411
|
+
waitSeconds?: number;
|
|
412
|
+
signal?: AbortSignal;
|
|
413
|
+
}): Promise<CliGetPlansResponse>;
|
|
414
|
+
/**
|
|
415
|
+
* POST /api/cli/v1/projects/{projectId}/plans/accept (DEV-384 V3-B)
|
|
416
|
+
* Convert staged proposals into real test cases. `only` is ALWAYS an
|
|
417
|
+
* explicit, non-empty id list — the caller enforces the two §3.3 safety
|
|
418
|
+
* rules (full list when the user didn't subset; an empty selection is a
|
|
419
|
+
* client-side validation error because `[]` is server-destructive:
|
|
420
|
+
* it means "reject everything" and clears the staged batch).
|
|
421
|
+
*/
|
|
422
|
+
acceptPlans(projectId: string, only: string[], options: {
|
|
423
|
+
idempotencyKey: string;
|
|
424
|
+
signal?: AbortSignal;
|
|
425
|
+
}): Promise<CliAcceptPlansResponse>;
|
|
322
426
|
/**
|
|
323
427
|
* Classify an error thrown while issuing OR reading a request. When it is an
|
|
324
428
|
* abort/timeout and our per-request timeout signal fired (and the caller had
|
package/dist/lib/http.js
CHANGED
|
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
import { ApiError, InterruptError, RequestTimeoutError, TransportError } from './errors.js';
|
|
4
4
|
import { VERSION } from '../version.js';
|
|
5
|
-
import { BATCH_RERUN_RESPONSE_SCHEMA, BATCH_RUN_FRESH_RESPONSE_SCHEMA, LIST_RUNS_RESPONSE_SCHEMA, RERUN_RESPONSE_SCHEMA, RUN_RESPONSE_SCHEMA, TESTLIST_RUN_RESPONSE_SCHEMA, TRIGGER_RUN_RESPONSE_SCHEMA, } from './response-schemas.js';
|
|
5
|
+
import { BATCH_RERUN_RESPONSE_SCHEMA, BATCH_RUN_FRESH_RESPONSE_SCHEMA, LIST_RUNS_RESPONSE_SCHEMA, RERUN_RESPONSE_SCHEMA, RUN_RESPONSE_SCHEMA, TESTLIST_RUN_RESPONSE_SCHEMA, TRIGGER_RUN_RESPONSE_SCHEMA, TUNNEL_MINT_RESPONSE_SCHEMA, TUNNEL_STATUS_RESPONSE_SCHEMA, } from './response-schemas.js';
|
|
6
6
|
/**
|
|
7
7
|
* Default per-request timeout (120s). Comfortably covers every metadata/read
|
|
8
8
|
* request and every <=25s long-poll request (`?waitSeconds` is capped at 25
|
|
@@ -78,6 +78,13 @@ export class HttpClient {
|
|
|
78
78
|
this.requestTimeoutMs = options.requestTimeoutMs ?? REQUEST_TIMEOUT_DEFAULT_MS;
|
|
79
79
|
this.maxResponseBytes = options.maxResponseBytes ?? MAX_RESPONSE_BYTES_DEFAULT;
|
|
80
80
|
}
|
|
81
|
+
/** The resolved facade base URL (trailing slash trimmed). Read-only —
|
|
82
|
+
* callers that bypass the client for a side-channel request (e.g. the
|
|
83
|
+
* presigned S3 PUT) use it to reason about the facade's locality
|
|
84
|
+
* (DEV-384 review F3). */
|
|
85
|
+
get resolvedBaseUrl() {
|
|
86
|
+
return this.baseUrl;
|
|
87
|
+
}
|
|
81
88
|
/**
|
|
82
89
|
* Read the backend's supported-floor header off a response and forward it to
|
|
83
90
|
* `onServerVersion` when present. Never throws — a bad header must not break
|
|
@@ -294,6 +301,57 @@ export class HttpClient {
|
|
|
294
301
|
schema: RUN_RESPONSE_SCHEMA,
|
|
295
302
|
});
|
|
296
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* POST /api/cli/v1/tunnel — mint a tunnel client for `test run --local`.
|
|
306
|
+
*
|
|
307
|
+
* The ONLY response on this surface that carries a secret. Deliberately NOT
|
|
308
|
+
* sent with an `Idempotency-Key`: the interceptor persists the response body
|
|
309
|
+
* for the whole replay window, so an idempotent mint would put a live
|
|
310
|
+
* credential in the idempotency store — the exact copy the server-side
|
|
311
|
+
* binding exists to avoid. The server rate-limits this route instead.
|
|
312
|
+
*
|
|
313
|
+
* `retryOnConflict: false` for the same reason `triggerRun` opts out: a 409
|
|
314
|
+
* here means the per-principal live-binding cap is reached, which is a
|
|
315
|
+
* standing condition, not a transient snapshot conflict.
|
|
316
|
+
*/
|
|
317
|
+
async mintTunnel(body, options = {}) {
|
|
318
|
+
return this.postWithMeta('/tunnel', {
|
|
319
|
+
body,
|
|
320
|
+
signal: options.signal,
|
|
321
|
+
schema: TUNNEL_MINT_RESPONSE_SCHEMA,
|
|
322
|
+
retryOnConflict: false,
|
|
323
|
+
}).then(r => r.body);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* GET /api/cli/v1/tunnel/{clientId} — is this binding's client connected?
|
|
327
|
+
*
|
|
328
|
+
* A 404 covers unknown, another tenant's, and expired alike; the surface is
|
|
329
|
+
* deliberately not an existence oracle for client ids. Callers must not
|
|
330
|
+
* translate a transport failure or a non-200 into `offline` — "the tunnel is
|
|
331
|
+
* down" and "we could not reach TestSprite to ask" are different answers,
|
|
332
|
+
* and collapsing them is what DEV-1005 was.
|
|
333
|
+
*/
|
|
334
|
+
async getTunnelStatus(clientId, options = {}) {
|
|
335
|
+
return this.get(`/tunnel/${encodeURIComponent(clientId)}`, {
|
|
336
|
+
signal: options.signal,
|
|
337
|
+
retry: options.retry,
|
|
338
|
+
schema: TUNNEL_STATUS_RESPONSE_SCHEMA,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* DELETE /api/cli/v1/tunnel/{clientId} — destroy a binding. 204, idempotent.
|
|
343
|
+
*
|
|
344
|
+
* No body, no `Idempotency-Key`: the operation is idempotent by definition
|
|
345
|
+
* and this is the call made from a `finally` block, including after a
|
|
346
|
+
* signal, where there is least room for extra ceremony.
|
|
347
|
+
*/
|
|
348
|
+
async deleteTunnel(clientId, options = {}) {
|
|
349
|
+
await this.deleteWithMeta(`/tunnel/${encodeURIComponent(clientId)}`, {
|
|
350
|
+
signal: options.signal,
|
|
351
|
+
allowNoContent: true,
|
|
352
|
+
retryOnConflict: false,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
297
355
|
/**
|
|
298
356
|
* POST /api/cli/v1/runs/{runId}/cancel
|
|
299
357
|
* User-initiated cancel of a queued/running run (DEV-331 piece 3). No
|
|
@@ -311,6 +369,56 @@ export class HttpClient {
|
|
|
311
369
|
retryOnConflict: false,
|
|
312
370
|
});
|
|
313
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* POST /api/cli/v1/projects/{projectId}/plans/generate (DEV-384 V3-B)
|
|
374
|
+
* Start whichever generation stage the project is missing next. The body
|
|
375
|
+
* is empty by contract — the server decides which rung fires. 202 both
|
|
376
|
+
* for `accepted` (a stage started) and `nothing_to_start` (proposals are
|
|
377
|
+
* already staged; the facade's no-restart guard refuses a duplicate
|
|
378
|
+
* append because it would wipe the batch and re-bill 2 credits).
|
|
379
|
+
*
|
|
380
|
+
* `retryOnConflict: false` — a 409 here is `stage_in_flight`, a flow
|
|
381
|
+
* signal the ladder answers by attaching and polling, never a transient
|
|
382
|
+
* snapshot conflict to paper over with a retry.
|
|
383
|
+
*/
|
|
384
|
+
async generatePlans(projectId, options) {
|
|
385
|
+
return this.post(`/projects/${encodeURIComponent(projectId)}/plans/generate`, {
|
|
386
|
+
body: {},
|
|
387
|
+
headers: { 'idempotency-key': options.idempotencyKey },
|
|
388
|
+
signal: options.signal,
|
|
389
|
+
retryOnConflict: false,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* GET /api/cli/v1/projects/{projectId}/plans (DEV-384 V3-B)
|
|
394
|
+
* Pure read: the facade-synthesized generation status, the staged
|
|
395
|
+
* proposal list (stable proposalIds — what `accept --only` consumes),
|
|
396
|
+
* and a best-effort credits block. When `waitSeconds` (1–25) is
|
|
397
|
+
* provided the server long-polls: one request per window, answered
|
|
398
|
+
* early on any change.
|
|
399
|
+
*/
|
|
400
|
+
async getPlans(projectId, options) {
|
|
401
|
+
return this.get(`/projects/${encodeURIComponent(projectId)}/plans`, {
|
|
402
|
+
query: options?.waitSeconds !== undefined ? { waitSeconds: options.waitSeconds } : undefined,
|
|
403
|
+
signal: options?.signal,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* POST /api/cli/v1/projects/{projectId}/plans/accept (DEV-384 V3-B)
|
|
408
|
+
* Convert staged proposals into real test cases. `only` is ALWAYS an
|
|
409
|
+
* explicit, non-empty id list — the caller enforces the two §3.3 safety
|
|
410
|
+
* rules (full list when the user didn't subset; an empty selection is a
|
|
411
|
+
* client-side validation error because `[]` is server-destructive:
|
|
412
|
+
* it means "reject everything" and clears the staged batch).
|
|
413
|
+
*/
|
|
414
|
+
async acceptPlans(projectId, only, options) {
|
|
415
|
+
return this.post(`/projects/${encodeURIComponent(projectId)}/plans/accept`, {
|
|
416
|
+
body: { only },
|
|
417
|
+
headers: { 'idempotency-key': options.idempotencyKey },
|
|
418
|
+
signal: options.signal,
|
|
419
|
+
retryOnConflict: false,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
314
422
|
/**
|
|
315
423
|
* Classify an error thrown while issuing OR reading a request. When it is an
|
|
316
424
|
* abort/timeout and our per-request timeout signal fired (and the caller had
|
|
@@ -344,7 +452,8 @@ export class HttpClient {
|
|
|
344
452
|
throw ApiError.authRequired();
|
|
345
453
|
const url = buildUrl(this.baseUrl, path, options.query);
|
|
346
454
|
const requestId = options.requestId ?? newRequestId();
|
|
347
|
-
const
|
|
455
|
+
const allowRetry = options.retry !== false;
|
|
456
|
+
const allowTransportRetry = allowRetry && canRetryTransport(method, options);
|
|
348
457
|
let attempt = 0;
|
|
349
458
|
while (true) {
|
|
350
459
|
// Bail before issuing (or re-issuing after a retry sleep) a request the
|
|
@@ -463,10 +572,18 @@ export class HttpClient {
|
|
|
463
572
|
});
|
|
464
573
|
let raw;
|
|
465
574
|
try {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
575
|
+
if (response.status === 204 && options.allowNoContent === true) {
|
|
576
|
+
// Only explicitly bodyless endpoints may bypass the historical
|
|
577
|
+
// JSON-envelope contract. Every other 204 still falls through
|
|
578
|
+
// to JSON.parse('') and becomes a typed malformed-response error.
|
|
579
|
+
raw = undefined;
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
// Bounded read, then parse — assigning to `raw` rather than returning
|
|
583
|
+
// here keeps the schema validation below on the success path.
|
|
584
|
+
const text = await readBoundedText(response, this.maxResponseBytes, requestId);
|
|
585
|
+
raw = JSON.parse(text);
|
|
586
|
+
}
|
|
470
587
|
}
|
|
471
588
|
catch (err) {
|
|
472
589
|
// Interrupt passthrough (see the fetch catch above).
|
|
@@ -583,7 +700,9 @@ export class HttpClient {
|
|
|
583
700
|
});
|
|
584
701
|
const retryOnConflict = options.retryOnConflict !== false;
|
|
585
702
|
const retryOnRateLimit = options.retryOnRateLimit !== false;
|
|
586
|
-
const decision =
|
|
703
|
+
const decision = allowRetry
|
|
704
|
+
? apiRetryDecision(apiError.code, attempt, retryAfterSec, this.random, retryOnConflict, retryOnRateLimit)
|
|
705
|
+
: { retry: false, delayMs: 0 };
|
|
587
706
|
if (!decision.retry)
|
|
588
707
|
throw apiError;
|
|
589
708
|
const delaySec = Math.round(decision.delayMs / 1000);
|
package/dist/lib/interrupt.d.ts
CHANGED
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
* Broken pipe: when output is piped to a reader that closes early
|
|
13
13
|
* (`testsprite ... | head`), the kernel raises `EPIPE` on the next stdout write.
|
|
14
14
|
* Node turns an `'error'` with no listener into an uncaughtException and dumps a
|
|
15
|
-
* raw `write EPIPE` stack (exit 1).
|
|
16
|
-
* conventional SIGPIPE-equivalent result
|
|
15
|
+
* raw `write EPIPE` stack (exit 1). Outside an armed lifetime the guard exits
|
|
16
|
+
* 0 immediately, the conventional SIGPIPE-equivalent result. While armed it
|
|
17
|
+
* first requests coordinated shutdown so tunnel cleanup can finish, then the
|
|
18
|
+
* same synthetic interrupt reason preserves exit 0.
|
|
17
19
|
*
|
|
18
20
|
* `process` and the streams are injectable so the wiring is unit-testable
|
|
19
21
|
* without spawning a subprocess or sending a real signal.
|
|
@@ -28,10 +30,12 @@ export declare const SIGINT_EXIT_CODE: 130;
|
|
|
28
30
|
* only these members, and tests can supply a lightweight fake.
|
|
29
31
|
*/
|
|
30
32
|
export interface ShutdownHandle {
|
|
31
|
-
/** Aborts
|
|
33
|
+
/** Aborts with the graceful-stop reason when a signal/EPIPE arrives while armed. */
|
|
32
34
|
readonly signal: AbortSignal;
|
|
33
35
|
/** Enter a graceful-detach scope. Returns the disposer that leaves it. */
|
|
34
36
|
arm(): () => void;
|
|
37
|
+
/** Run and track cleanup that a repeated signal may briefly wait for. */
|
|
38
|
+
runCriticalOperation<T>(operation: () => Promise<T>): Promise<T>;
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
41
|
* Process-lifetime coordinator between the signal handler and the `--wait`
|
|
@@ -40,7 +44,7 @@ export interface ShutdownHandle {
|
|
|
40
44
|
* Two modes, chosen by whether a graceful-detach scope is armed when the
|
|
41
45
|
* signal arrives:
|
|
42
46
|
*
|
|
43
|
-
* - **Armed** (inside `pollRunUntilTerminal`): the handler only aborts
|
|
47
|
+
* - **Armed** (inside `pollRunUntilTerminal` or a tunnel lifetime): the handler only aborts
|
|
44
48
|
* `signal` with an `InterruptError` — no I/O, no exit. The in-flight fetch
|
|
45
49
|
* and every backoff sleep bail immediately; the `--wait` catch blocks own
|
|
46
50
|
* the cleanup (finalize the ticker, print the honest partial envelope +
|
|
@@ -50,25 +54,42 @@ export interface ShutdownHandle {
|
|
|
50
54
|
* immediately, preserving the pre-DEV-331 behavior. An abort nobody
|
|
51
55
|
* observes must never leave the process hanging at e.g. a readline prompt.
|
|
52
56
|
*
|
|
53
|
-
* A
|
|
54
|
-
*
|
|
57
|
+
* A repeated signal still provides a bounded escape hatch: the second waits
|
|
58
|
+
* briefly only when critical cleanup is in flight, and the third exits at once.
|
|
55
59
|
*/
|
|
56
60
|
export declare class ShutdownController {
|
|
57
61
|
private readonly controller;
|
|
62
|
+
private readonly criticalOperations;
|
|
58
63
|
private armedCount;
|
|
59
|
-
private
|
|
64
|
+
private receivedCause;
|
|
60
65
|
constructor();
|
|
61
66
|
get signal(): AbortSignal;
|
|
62
|
-
/** The first
|
|
63
|
-
get received(): TerminationSignal | null;
|
|
67
|
+
/** The first graceful-shutdown cause received, or null if none yet. */
|
|
68
|
+
get received(): TerminationSignal | 'EPIPE' | null;
|
|
64
69
|
get isArmed(): boolean;
|
|
65
70
|
/**
|
|
66
71
|
* Enter a graceful-detach scope (re-entrant: fan-out members overlap).
|
|
67
72
|
* Returns an idempotent disposer.
|
|
68
73
|
*/
|
|
69
74
|
arm(): () => void;
|
|
75
|
+
/** Whether teardown currently has work whose abrupt loss is security-sensitive. */
|
|
76
|
+
get hasCriticalOperations(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Register cleanup before it starts and remove it automatically when it
|
|
79
|
+
* settles. Rejections retain their original semantics for the caller.
|
|
80
|
+
*/
|
|
81
|
+
runCriticalOperation<T>(operation: () => Promise<T>): Promise<T>;
|
|
82
|
+
/** Wait until all current and directly chained critical cleanup settles. */
|
|
83
|
+
waitForCriticalOperations(): Promise<void>;
|
|
70
84
|
/** Record the signal and abort with an `InterruptError` carrying it. */
|
|
71
85
|
interrupt(signal: TerminationSignal): void;
|
|
86
|
+
/**
|
|
87
|
+
* Abort an armed lifetime after stdout's reader closes. The InterruptError
|
|
88
|
+
* subtype deliberately keeps the existing graceful-detach catch paths in
|
|
89
|
+
* play (including tunnel cancellation), while its exit code stays the
|
|
90
|
+
* SIGPIPE-equivalent success code 0.
|
|
91
|
+
*/
|
|
92
|
+
brokenPipe(): void;
|
|
72
93
|
}
|
|
73
94
|
/**
|
|
74
95
|
* The process-wide instance: `index.ts` hands it to `installSignalHandlers`,
|
|
@@ -95,8 +116,9 @@ export interface InterruptDeps {
|
|
|
95
116
|
* First signal, armed scope: abort-only — the `--wait` catch paths own the
|
|
96
117
|
* honest-detach UX and the exit (DEV-331 D1: Ctrl-C = detach, never cancel).
|
|
97
118
|
* First signal, disarmed: print the generic explanation + exit `128+signum`.
|
|
98
|
-
* Second signal
|
|
99
|
-
*
|
|
119
|
+
* Second signal: exit immediately unless critical cleanup is registered; when
|
|
120
|
+
* it is, wait at most two seconds before exiting. Third signal: always exit
|
|
121
|
+
* immediately, including while that grace period is active.
|
|
100
122
|
*/
|
|
101
123
|
export declare function installSignalHandlers(deps?: InterruptDeps): void;
|
|
102
124
|
export interface BrokenPipeDeps {
|
|
@@ -106,11 +128,14 @@ export interface BrokenPipeDeps {
|
|
|
106
128
|
stderr?: NodeJS.EventEmitter;
|
|
107
129
|
/** Process exit. Defaults to `process.exit`. */
|
|
108
130
|
exit?: (code: number) => void;
|
|
131
|
+
/** Shutdown coordinator. Defaults to {@link globalShutdown}. */
|
|
132
|
+
shutdown?: ShutdownController;
|
|
109
133
|
}
|
|
110
134
|
/**
|
|
111
135
|
* Guard against `EPIPE` on stdout/stderr so piping to a reader that closes
|
|
112
136
|
* early (`testsprite ... | head`) exits cleanly instead of crashing with an
|
|
113
|
-
* unhandled `write EPIPE` stack.
|
|
114
|
-
*
|
|
137
|
+
* unhandled `write EPIPE` stack. An armed stdout path requests graceful
|
|
138
|
+
* shutdown before exiting 0; a disarmed one exits 0 immediately. Only `EPIPE`
|
|
139
|
+
* is swallowed; any other stream error is left to surface normally.
|
|
115
140
|
*/
|
|
116
141
|
export declare function installBrokenPipeGuard(deps?: BrokenPipeDeps): void;
|