@testsprite/testsprite-cli 0.7.0 → 0.8.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 +51 -38
- package/dist/commands/agent.js +47 -3
- package/dist/commands/ci.d.ts +88 -0
- package/dist/commands/ci.js +429 -0
- package/dist/commands/doctor.js +100 -1
- package/dist/commands/init.js +8 -0
- package/dist/commands/project.d.ts +78 -0
- package/dist/commands/project.js +426 -3
- package/dist/commands/test.d.ts +162 -2
- package/dist/commands/test.js +1814 -392
- 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/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 +94 -0
- package/dist/lib/http.js +120 -5
- 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 +32 -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 +24 -0
- package/dist/lib/target-url-preflight.js +3 -3
- package/dist/lib/target-url.d.ts +44 -7
- package/dist/lib/target-url.js +250 -61
- 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 +129 -0
- package/dist/lib/tunnel-session.js +232 -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 +83 -0
- package/dist/vendor/tunnel-client/client.js +871 -0
- package/dist/vendor/tunnel-client/config.d.ts +41 -0
- package/dist/vendor/tunnel-client/config.js +42 -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 +96 -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/index.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
import { Command, CommanderError } from 'commander';
|
|
3
3
|
import { createAgentCommand } from './commands/agent.js';
|
|
4
4
|
import { createAuthCommand } from './commands/auth.js';
|
|
5
|
+
import { createCiCommand } from './commands/ci.js';
|
|
5
6
|
import { createCompletionCommand } from './commands/completion.js';
|
|
6
7
|
import { createDoctorCommand } from './commands/doctor.js';
|
|
7
8
|
import { addSetupOptions, createDeprecatedInitCommand, createSetupCommand, runConfigureViaSetup, } from './commands/init.js';
|
|
8
9
|
import { createProjectCommand } from './commands/project.js';
|
|
9
10
|
import { createScheduleCommand } from './commands/schedule.js';
|
|
11
|
+
import { createTunnelCommand } from './commands/tunnel.js';
|
|
10
12
|
import { createTestCommand } from './commands/test.js';
|
|
11
13
|
import { createTestListCommand } from './commands/testlist.js';
|
|
12
14
|
import { createUsageCommand } from './commands/usage.js';
|
|
@@ -68,7 +70,9 @@ program.addCommand(authCommand);
|
|
|
68
70
|
program.addCommand(createProjectCommand({}));
|
|
69
71
|
program.addCommand(createTestCommand());
|
|
70
72
|
program.addCommand(createTestListCommand());
|
|
73
|
+
program.addCommand(createCiCommand({}));
|
|
71
74
|
program.addCommand(createScheduleCommand({}));
|
|
75
|
+
program.addCommand(createTunnelCommand({}));
|
|
72
76
|
program.addCommand(createAgentCommand({}));
|
|
73
77
|
program.addCommand(createUsageCommand());
|
|
74
78
|
program.addCommand(createDoctorCommand());
|
|
@@ -111,6 +115,13 @@ let telemetryEmit = false;
|
|
|
111
115
|
// Auth resolved in the preAction hook, before the command's action runs, so
|
|
112
116
|
// `auth remove` (which deletes the profile) is still reported on the key it used.
|
|
113
117
|
let telemetryAuth;
|
|
118
|
+
// True when the leaf command that is about to run carries a `--local` option
|
|
119
|
+
// value — i.e. `test run --local <port>` (no other command declares `--local`).
|
|
120
|
+
// Set by the preAction hook, BEFORE the command's own validation runs, so a
|
|
121
|
+
// zero-network `--local` refusal (dead port, an incompatible flag combo) is
|
|
122
|
+
// still reported: the whole point of this field is to see the attempts a
|
|
123
|
+
// backend-side mint/attach event never observes.
|
|
124
|
+
let telemetryLocal = false;
|
|
114
125
|
// Propagate exitOverride AND the buffered outputError config to every
|
|
115
126
|
// subcommand in the tree. Commander's addCommand() does NOT inherit either
|
|
116
127
|
// from the parent, so commands built externally (createTestCommand, etc.) and
|
|
@@ -130,6 +141,36 @@ function applyExitOverrideDeep(cmd) {
|
|
|
130
141
|
}
|
|
131
142
|
}
|
|
132
143
|
applyExitOverrideDeep(program);
|
|
144
|
+
function isRegisteredRootCommand(name) {
|
|
145
|
+
return (name === 'help' ||
|
|
146
|
+
program.commands.some(command => command.name() === name || command.aliases().includes(name)));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Commander checks its implicit help option before reporting an unknown root
|
|
150
|
+
* command. It also falls back to root help when `help <command>` names a
|
|
151
|
+
* missing command. Detect both cases while help is being rendered so the
|
|
152
|
+
* normal unknown-command error wins before any misleading help is written.
|
|
153
|
+
*/
|
|
154
|
+
function unknownRootCommandMaskedByHelp(args) {
|
|
155
|
+
const [first, second] = args;
|
|
156
|
+
if (first === 'help') {
|
|
157
|
+
return second && !isRegisteredRootCommand(second) ? second : undefined;
|
|
158
|
+
}
|
|
159
|
+
if (!first || first.startsWith('-') || isRegisteredRootCommand(first))
|
|
160
|
+
return undefined;
|
|
161
|
+
return args.slice(1).some(arg => arg === '--help' || arg === '-h') ? first : undefined;
|
|
162
|
+
}
|
|
163
|
+
program.addHelpText('beforeAll', context => {
|
|
164
|
+
if (context.command !== program)
|
|
165
|
+
return '';
|
|
166
|
+
const unknownCommand = unknownRootCommandMaskedByHelp(program.args);
|
|
167
|
+
if (unknownCommand) {
|
|
168
|
+
program.error(`error: unknown command '${unknownCommand}'`, {
|
|
169
|
+
code: 'commander.unknownCommand',
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return '';
|
|
173
|
+
});
|
|
133
174
|
/**
|
|
134
175
|
* Render a leaf command's full path (group + leaf), e.g. `test run` /
|
|
135
176
|
* `auth whoami`, by walking parents up to (but not including) the root program.
|
|
@@ -158,6 +199,10 @@ program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
|
158
199
|
const commandPath = commandPathOf(actionCommand);
|
|
159
200
|
// Record which leaf command ran, for the telemetry emit around parseAsync.
|
|
160
201
|
ranCommandPath = commandPath;
|
|
202
|
+
// `--local` is only declared on `test run`, so this is false for every
|
|
203
|
+
// other command. The raw opt is a port string; only its presence is
|
|
204
|
+
// recorded (see `telemetryLocal`'s own comment — never the value).
|
|
205
|
+
telemetryLocal = globals.local !== undefined;
|
|
161
206
|
// See `isPlanTemplateInvocation` for why this one case is
|
|
162
207
|
// filtered here rather than in skill-nudge.ts / update-check.ts.
|
|
163
208
|
const isPlanTemplate = isPlanTemplateInvocation(commandPath, globals.planTemplate);
|
|
@@ -223,15 +268,26 @@ try {
|
|
|
223
268
|
exitCode: 0,
|
|
224
269
|
durationMs: Date.now() - telemetryStartedAt,
|
|
225
270
|
...telemetryGlobals(),
|
|
271
|
+
local: telemetryLocal,
|
|
226
272
|
}, { resolvedAuth: telemetryAuth });
|
|
227
273
|
}
|
|
228
274
|
}
|
|
229
275
|
catch (err) {
|
|
230
276
|
const telemetryOutcome = classifyCliError(err);
|
|
231
277
|
// Flush the outcome AFTER the error is rendered to stderr below (via each
|
|
232
|
-
// branch's `
|
|
233
|
-
// The classification mirrors the exit-code mapping the
|
|
234
|
-
|
|
278
|
+
// branch's `flushThenSetExitCode`), so a slow backend never delays the
|
|
279
|
+
// user's error. The classification mirrors the exit-code mapping the
|
|
280
|
+
// branches apply.
|
|
281
|
+
//
|
|
282
|
+
// DEV-673: SET `process.exitCode` and let the event loop drain instead of
|
|
283
|
+
// forcing `process.exit()`. A forced exit tears the process down while the
|
|
284
|
+
// just-completed HTTPS request's TLS socket is still mid-close; on Windows
|
|
285
|
+
// libuv asserts on the half-closed handle (src/win/async.c) and the process
|
|
286
|
+
// dies with 0xC0000409 (-1073740791) — overwriting the mapped exit code
|
|
287
|
+
// with a crash code and voiding the documented exit-code contract for every
|
|
288
|
+
// script/CI/agent that branches on it. Draining takes milliseconds and is
|
|
289
|
+
// exactly how the success path above already exits.
|
|
290
|
+
const flushThenSetExitCode = async (code) => {
|
|
235
291
|
if (telemetryEmit) {
|
|
236
292
|
await recordOutcome({
|
|
237
293
|
command: ranCommandPath,
|
|
@@ -240,12 +296,14 @@ catch (err) {
|
|
|
240
296
|
errorCode: telemetryOutcome.errorCode,
|
|
241
297
|
durationMs: Date.now() - telemetryStartedAt,
|
|
242
298
|
...telemetryGlobals(),
|
|
299
|
+
local: telemetryLocal,
|
|
243
300
|
}, { resolvedAuth: telemetryAuth });
|
|
244
301
|
}
|
|
245
|
-
process.
|
|
302
|
+
process.exitCode = code;
|
|
246
303
|
};
|
|
247
304
|
const rawMode = program.opts().output;
|
|
248
305
|
const mode = isOutputMode(rawMode) ? rawMode : 'text';
|
|
306
|
+
const output = new Output(mode);
|
|
249
307
|
if (err instanceof ApiError) {
|
|
250
308
|
if (mode === 'json') {
|
|
251
309
|
const envelope = {
|
|
@@ -295,24 +353,31 @@ catch (err) {
|
|
|
295
353
|
}
|
|
296
354
|
}
|
|
297
355
|
}
|
|
298
|
-
await
|
|
356
|
+
await flushThenSetExitCode(err.exitCode);
|
|
299
357
|
}
|
|
300
|
-
|
|
301
|
-
if (err instanceof InterruptError) {
|
|
358
|
+
else if (err instanceof InterruptError) {
|
|
302
359
|
// Graceful detach (DEV-331 piece 1, errors.md §8.1): the wait-path catch
|
|
303
360
|
// block already printed the honest partial + re-attach hint. Exit with
|
|
304
361
|
// the conventional 128+signum code; `INTERRUPTED` is deliberately outside
|
|
305
362
|
// the error catalog. Note: Ctrl-C does NOT cancel the server-side run.
|
|
306
363
|
if (mode === 'json') {
|
|
364
|
+
const tunnelDetach = err
|
|
365
|
+
.tunnelDetach;
|
|
307
366
|
const envelope = {
|
|
308
367
|
error: {
|
|
309
368
|
code: 'INTERRUPTED',
|
|
310
369
|
message: err.message,
|
|
311
|
-
nextAction:
|
|
312
|
-
'
|
|
313
|
-
|
|
370
|
+
nextAction: tunnelDetach?.nextAction ??
|
|
371
|
+
'The server-side run (if any) keeps executing and billing. ' +
|
|
372
|
+
'Re-attach with: testsprite test wait <runId>, or stop it with: testsprite test cancel <runId> ' +
|
|
373
|
+
'(runId is in the partial JSON on stdout).',
|
|
314
374
|
requestId: 'local',
|
|
315
|
-
details: {
|
|
375
|
+
details: {
|
|
376
|
+
signal: err.signal,
|
|
377
|
+
...(tunnelDetach
|
|
378
|
+
? { runId: tunnelDetach.runId, cancelOutcome: tunnelDetach.cancel }
|
|
379
|
+
: {}),
|
|
380
|
+
},
|
|
316
381
|
},
|
|
317
382
|
};
|
|
318
383
|
process.stderr.write(`${JSON.stringify(envelope, null, 2)}\n`);
|
|
@@ -320,9 +385,9 @@ catch (err) {
|
|
|
320
385
|
else {
|
|
321
386
|
process.stderr.write(`Error: ${err.message}\n`);
|
|
322
387
|
}
|
|
323
|
-
await
|
|
388
|
+
await flushThenSetExitCode(err.exitCode);
|
|
324
389
|
}
|
|
325
|
-
if (err instanceof RequestTimeoutError) {
|
|
390
|
+
else if (err instanceof RequestTimeoutError) {
|
|
326
391
|
// Structured rendering for per-request timeouts: JSON mode emits a
|
|
327
392
|
// machine-readable envelope; text mode emits the message with a hint.
|
|
328
393
|
if (mode === 'json') {
|
|
@@ -341,9 +406,9 @@ catch (err) {
|
|
|
341
406
|
else {
|
|
342
407
|
process.stderr.write(`Error: ${err.message}\n`);
|
|
343
408
|
}
|
|
344
|
-
await
|
|
409
|
+
await flushThenSetExitCode(err.exitCode);
|
|
345
410
|
}
|
|
346
|
-
if (err instanceof CommanderError) {
|
|
411
|
+
else if (err instanceof CommanderError) {
|
|
347
412
|
// Map exit codes per the CLI taxonomy:
|
|
348
413
|
// help / version → 0 (user asked for it; Commander already wrote the text)
|
|
349
414
|
// parse errors → 5 (VALIDATION_ERROR family: missing arg, invalid
|
|
@@ -360,33 +425,37 @@ catch (err) {
|
|
|
360
425
|
if (err.code === 'commander.helpDisplayed' ||
|
|
361
426
|
err.code === 'commander.help' ||
|
|
362
427
|
err.code === 'commander.version') {
|
|
363
|
-
await
|
|
428
|
+
await flushThenSetExitCode(0);
|
|
364
429
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
for (let i = 2; i < process.argv.length; i++) {
|
|
374
|
-
const arg = process.argv[i];
|
|
375
|
-
if (arg === '--output' && process.argv[i + 1] === 'json')
|
|
376
|
-
return 'json';
|
|
377
|
-
if (arg === '--output=json')
|
|
430
|
+
else {
|
|
431
|
+
// For parse errors, write the buffered message in the correct format.
|
|
432
|
+
// rawMode from program.opts() is reliable when --output was parsed before
|
|
433
|
+
// the error. When the error occurs first (e.g. `testsprite badcmd --output
|
|
434
|
+
// json`), rawMode is the default 'text'; scan argv as a best-effort
|
|
435
|
+
// fallback so machine consumers still receive a JSON envelope.
|
|
436
|
+
const commanderMode = (() => {
|
|
437
|
+
if (rawMode === 'json')
|
|
378
438
|
return 'json';
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
439
|
+
for (let i = 2; i < process.argv.length; i++) {
|
|
440
|
+
const arg = process.argv[i];
|
|
441
|
+
if (arg === '--output' && process.argv[i + 1] === 'json')
|
|
442
|
+
return 'json';
|
|
443
|
+
if (arg === '--output=json')
|
|
444
|
+
return 'json';
|
|
445
|
+
}
|
|
446
|
+
return mode;
|
|
447
|
+
})();
|
|
448
|
+
process.stderr.write(renderCommanderError(pendingCommanderErrorMsg, err.message, commanderMode));
|
|
449
|
+
await flushThenSetExitCode(5);
|
|
450
|
+
}
|
|
384
451
|
}
|
|
385
|
-
if (err instanceof CLIError) {
|
|
452
|
+
else if (err instanceof CLIError) {
|
|
386
453
|
output.error(err.message);
|
|
387
|
-
await
|
|
454
|
+
await flushThenSetExitCode(err.exitCode);
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
output.error(err instanceof Error ? err.message : String(err));
|
|
458
|
+
await flushThenSetExitCode(1);
|
|
388
459
|
}
|
|
389
|
-
output.error(err instanceof Error ? err.message : String(err));
|
|
390
|
-
await flushThenExit(1);
|
|
391
460
|
}
|
|
392
461
|
//# sourceMappingURL=index.js.map
|
|
@@ -50,6 +50,15 @@ export interface DryRunSampleEntry {
|
|
|
50
50
|
* `putPlanSteps`, `createTestBatch`) so their responses reflect the
|
|
51
51
|
* user's actual flags rather than static canned values.
|
|
52
52
|
*/
|
|
53
|
+
/**
|
|
54
|
+
* Like {@link findSample}, but a missing sample throws instead of returning
|
|
55
|
+
* `undefined`. For dry-run paths that resolve samples DIRECTLY (bypassing the
|
|
56
|
+
* dry-run fetch impl, which has its own loud INTERNAL envelope for this):
|
|
57
|
+
* without the throw, a lost registry entry surfaces as a raw TypeError deep
|
|
58
|
+
* in a renderer (DEV-384 review F6 — `samples.ts` is a real merge-conflict
|
|
59
|
+
* hotspot, so a silently dropped entry is a live hazard, not a hypothetical).
|
|
60
|
+
*/
|
|
61
|
+
export declare function findSampleOrThrow(method: string, url: string, requestBody?: unknown): DryRunSampleEntry;
|
|
53
62
|
export declare function findSample(method: string, url: string, requestBody?: unknown): DryRunSampleEntry | undefined;
|
|
54
63
|
/** Test-only export so `samples.test.ts` can iterate the catalog. */
|
|
55
64
|
export declare const DRY_RUN_SAMPLE_ENTRIES: ReadonlyArray<DryRunSampleEntry>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ApiError } from '../errors.js';
|
|
1
2
|
import { buildJUnitReport } from '../junit-report.js';
|
|
2
3
|
const SAMPLE_USER_ID = '11111111-1111-4111-8111-111111111111';
|
|
3
4
|
const SAMPLE_KEY_ID = 'key_dryrun_2026';
|
|
@@ -441,6 +442,97 @@ const PATH_PREFIX = '/api/cli/v1';
|
|
|
441
442
|
const ENTRIES = [
|
|
442
443
|
entry('whoami', 'GET', '/me', me),
|
|
443
444
|
entry('listProjects', 'GET', '/projects', pageOf(projects)),
|
|
445
|
+
// DEV-384 V3-B — plan-generation surface. All three MUST be registered
|
|
446
|
+
// BEFORE `getProject`: findSample is first-match-wins and the projects/*
|
|
447
|
+
// family shares the `/projects/…` prefix, so the more specific plans
|
|
448
|
+
// paths are listed first (same defensive convention as `/tests/{id}/runs`
|
|
449
|
+
// before the `/tests/{id}` catch-all; `samples.test.ts` proves the
|
|
450
|
+
// ordering with shadowing tests).
|
|
451
|
+
//
|
|
452
|
+
// The trigger sample reports the PROPOSALS rung starting
|
|
453
|
+
// (`stagesRemaining: []`) and the plans sample shows the settled result
|
|
454
|
+
// (idle + two staged proposals), so a dry-run learner sees a coherent
|
|
455
|
+
// story: trigger → stage runs → staged batch with stable proposalIds.
|
|
456
|
+
entry('generatePlans', 'POST', '/projects/{projectId}/plans/generate', {
|
|
457
|
+
status: 'accepted',
|
|
458
|
+
projectId: SAMPLE_PROJECT_ID,
|
|
459
|
+
stage: 'proposals',
|
|
460
|
+
stagesRemaining: [],
|
|
461
|
+
enqueuedAt: '2026-07-28T09:00:00.000Z',
|
|
462
|
+
}),
|
|
463
|
+
// One frontend proposal (with action/assertion steps) and one backend
|
|
464
|
+
// proposal (with endpointPath/captures/consumes) so both wire shapes are
|
|
465
|
+
// learnable offline. `credits` shows the charged-actions breakdown the
|
|
466
|
+
// real facade fills best-effort.
|
|
467
|
+
entry('getPlans', 'GET', '/projects/{projectId}/plans', {
|
|
468
|
+
generation: { status: 'idle', errorCode: null, errorMessage: null },
|
|
469
|
+
proposals: [
|
|
470
|
+
{
|
|
471
|
+
proposalId: 'prop_1',
|
|
472
|
+
title: 'Login happy path',
|
|
473
|
+
description: 'Sign in with valid credentials and land on the dashboard.',
|
|
474
|
+
priority: 'p1',
|
|
475
|
+
category: 'auth',
|
|
476
|
+
feature: 'login',
|
|
477
|
+
type: 'frontend',
|
|
478
|
+
steps: [
|
|
479
|
+
{ type: 'action', description: 'Enter valid credentials and submit the login form' },
|
|
480
|
+
{ type: 'assertion', description: 'Dashboard heading is visible' },
|
|
481
|
+
],
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
proposalId: 'prop_2',
|
|
485
|
+
title: 'Create order — success',
|
|
486
|
+
description: 'POST a valid order and capture its id for downstream tests.',
|
|
487
|
+
priority: 'p2',
|
|
488
|
+
category: 'orders',
|
|
489
|
+
feature: 'create-order',
|
|
490
|
+
type: 'backend',
|
|
491
|
+
endpointPath: '/v1/orders',
|
|
492
|
+
captures: ['orderId'],
|
|
493
|
+
consumes: ['authToken'],
|
|
494
|
+
},
|
|
495
|
+
],
|
|
496
|
+
credits: {
|
|
497
|
+
charged: [
|
|
498
|
+
{ action: 'strategy', amount: 1 },
|
|
499
|
+
{ action: 'proposals', amount: 2 },
|
|
500
|
+
],
|
|
501
|
+
balance: 147,
|
|
502
|
+
},
|
|
503
|
+
}),
|
|
504
|
+
// Input-derived: echoes the explicit id list the CLI always sends (never
|
|
505
|
+
// the omitted or empty forms — §3.3 safety rules), so `accept --only
|
|
506
|
+
// prop_2 --dry-run` shows acceptedCount: 1 rather than a canned 2.
|
|
507
|
+
entry('acceptPlans', 'POST', '/projects/{projectId}/plans/accept', (req) => {
|
|
508
|
+
const body = req != null && typeof req === 'object' ? req : {};
|
|
509
|
+
const only = Array.isArray(body.only)
|
|
510
|
+
? body.only.filter((id) => typeof id === 'string')
|
|
511
|
+
: null;
|
|
512
|
+
const ids = only !== null && only.length > 0 ? only : ['prop_1', 'prop_2'];
|
|
513
|
+
return {
|
|
514
|
+
acceptedCount: ids.length,
|
|
515
|
+
caseKeys: ids.map(id => `case_dryrun_${id}`),
|
|
516
|
+
};
|
|
517
|
+
}),
|
|
518
|
+
// DEV-384 piece V3-D — `project docs upload` two-step facade routes.
|
|
519
|
+
// Registered BEFORE the broader project patterns (design doc §7 ordering
|
|
520
|
+
// rule; findSample is first-match-wins) and with `/docs/upload-url` before
|
|
521
|
+
// `/docs`. NOT consumed by the command's dry-run path: `project docs
|
|
522
|
+
// upload --dry-run` is an inline early-exit (zero network, stat only —
|
|
523
|
+
// the presigned S3 PUT leg cannot be expressed as a canned fetch sample).
|
|
524
|
+
// These are documentation/shape-guards, same family as `deleteBatch`.
|
|
525
|
+
entry('docsUploadUrl', 'POST', '/projects/{projectId}/docs/upload-url', {
|
|
526
|
+
uploadUrl: 'https://s3.dry-run.invalid/testsprite-usercontent/u_dryrun/p_dryrun_2026/openapi.yaml?X-Amz-Signature=dryrun',
|
|
527
|
+
s3Key: 'u_dryrun/p_dryrun_2026/openapi.yaml',
|
|
528
|
+
expiresInSeconds: 3600,
|
|
529
|
+
}),
|
|
530
|
+
entry('docsRegister', 'POST', '/projects/{projectId}/docs', {
|
|
531
|
+
resourceId: 'res_dryrun_2026',
|
|
532
|
+
displayName: 'openapi.yaml',
|
|
533
|
+
docRole: 'API_DOC',
|
|
534
|
+
processStatus: 'Pending',
|
|
535
|
+
}),
|
|
444
536
|
entry('getProject', 'GET', '/projects/{projectId}', projects[0]),
|
|
445
537
|
// P6 — POST /projects (create project). The id uses a stable dry-run
|
|
446
538
|
// sentinel so agents can see a coherent field shape without a real key.
|
|
@@ -861,6 +953,30 @@ function pageOf(items) {
|
|
|
861
953
|
* `putPlanSteps`, `createTestBatch`) so their responses reflect the
|
|
862
954
|
* user's actual flags rather than static canned values.
|
|
863
955
|
*/
|
|
956
|
+
/**
|
|
957
|
+
* Like {@link findSample}, but a missing sample throws instead of returning
|
|
958
|
+
* `undefined`. For dry-run paths that resolve samples DIRECTLY (bypassing the
|
|
959
|
+
* dry-run fetch impl, which has its own loud INTERNAL envelope for this):
|
|
960
|
+
* without the throw, a lost registry entry surfaces as a raw TypeError deep
|
|
961
|
+
* in a renderer (DEV-384 review F6 — `samples.ts` is a real merge-conflict
|
|
962
|
+
* hotspot, so a silently dropped entry is a live hazard, not a hypothetical).
|
|
963
|
+
*/
|
|
964
|
+
export function findSampleOrThrow(method, url, requestBody) {
|
|
965
|
+
const entry = findSample(method, url, requestBody);
|
|
966
|
+
if (entry === undefined) {
|
|
967
|
+
throw ApiError.fromEnvelope({
|
|
968
|
+
error: {
|
|
969
|
+
code: 'INTERNAL',
|
|
970
|
+
message: `dry-run sample registry has no entry for ${method.toUpperCase()} ${extractPath(url)} — ` +
|
|
971
|
+
'a sample was removed or shadowed in src/lib/dry-run/samples.ts (internal CLI bug).',
|
|
972
|
+
nextAction: 'Please report this to support@testsprite.com.',
|
|
973
|
+
requestId: SAMPLE_DRY_RUN_REQUEST_ID,
|
|
974
|
+
details: { method: method.toUpperCase(), path: extractPath(url) },
|
|
975
|
+
},
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
return entry;
|
|
979
|
+
}
|
|
864
980
|
export function findSample(method, url, requestBody) {
|
|
865
981
|
const upper = method.toUpperCase();
|
|
866
982
|
const pathOnly = extractPath(url);
|
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
|
*
|
|
@@ -177,6 +188,11 @@ export declare class HttpClient {
|
|
|
177
188
|
private readonly shutdownSignal?;
|
|
178
189
|
private readonly maxResponseBytes;
|
|
179
190
|
constructor(options: HttpClientOptions);
|
|
191
|
+
/** The resolved facade base URL (trailing slash trimmed). Read-only —
|
|
192
|
+
* callers that bypass the client for a side-channel request (e.g. the
|
|
193
|
+
* presigned S3 PUT) use it to reason about the facade's locality
|
|
194
|
+
* (DEV-384 review F3). */
|
|
195
|
+
get resolvedBaseUrl(): string;
|
|
180
196
|
/**
|
|
181
197
|
* Read the backend's supported-floor header off a response and forward it to
|
|
182
198
|
* `onServerVersion` when present. Never throws — a bad header must not break
|
|
@@ -305,6 +321,44 @@ export declare class HttpClient {
|
|
|
305
321
|
includeSteps?: boolean;
|
|
306
322
|
signal?: AbortSignal;
|
|
307
323
|
}): Promise<RunResponse>;
|
|
324
|
+
/**
|
|
325
|
+
* POST /api/cli/v1/tunnel — mint a tunnel client for `test run --local`.
|
|
326
|
+
*
|
|
327
|
+
* The ONLY response on this surface that carries a secret. Deliberately NOT
|
|
328
|
+
* sent with an `Idempotency-Key`: the interceptor persists the response body
|
|
329
|
+
* for the whole replay window, so an idempotent mint would put a live
|
|
330
|
+
* credential in the idempotency store — the exact copy the server-side
|
|
331
|
+
* binding exists to avoid. The server rate-limits this route instead.
|
|
332
|
+
*
|
|
333
|
+
* `retryOnConflict: false` for the same reason `triggerRun` opts out: a 409
|
|
334
|
+
* here means the per-principal live-binding cap is reached, which is a
|
|
335
|
+
* standing condition, not a transient snapshot conflict.
|
|
336
|
+
*/
|
|
337
|
+
mintTunnel(body: MintTunnelBody, options?: {
|
|
338
|
+
signal?: AbortSignal;
|
|
339
|
+
}): Promise<TunnelMintResponse>;
|
|
340
|
+
/**
|
|
341
|
+
* GET /api/cli/v1/tunnel/{clientId} — is this binding's client connected?
|
|
342
|
+
*
|
|
343
|
+
* A 404 covers unknown, another tenant's, and expired alike; the surface is
|
|
344
|
+
* deliberately not an existence oracle for client ids. Callers must not
|
|
345
|
+
* translate a transport failure or a non-200 into `offline` — "the tunnel is
|
|
346
|
+
* down" and "we could not reach TestSprite to ask" are different answers,
|
|
347
|
+
* and collapsing them is what DEV-1005 was.
|
|
348
|
+
*/
|
|
349
|
+
getTunnelStatus(clientId: string, options?: {
|
|
350
|
+
signal?: AbortSignal;
|
|
351
|
+
}): Promise<TunnelStatusResponse>;
|
|
352
|
+
/**
|
|
353
|
+
* DELETE /api/cli/v1/tunnel/{clientId} — destroy a binding. 204, idempotent.
|
|
354
|
+
*
|
|
355
|
+
* No body, no `Idempotency-Key`: the operation is idempotent by definition
|
|
356
|
+
* and this is the call made from a `finally` block, including after a
|
|
357
|
+
* signal, where there is least room for extra ceremony.
|
|
358
|
+
*/
|
|
359
|
+
deleteTunnel(clientId: string, options?: {
|
|
360
|
+
signal?: AbortSignal;
|
|
361
|
+
}): Promise<void>;
|
|
308
362
|
/**
|
|
309
363
|
* POST /api/cli/v1/runs/{runId}/cancel
|
|
310
364
|
* User-initiated cancel of a queued/running run (DEV-331 piece 3). No
|
|
@@ -319,6 +373,46 @@ export declare class HttpClient {
|
|
|
319
373
|
cancelRun(runId: string, options?: {
|
|
320
374
|
signal?: AbortSignal;
|
|
321
375
|
}): Promise<CancelRunResponse>;
|
|
376
|
+
/**
|
|
377
|
+
* POST /api/cli/v1/projects/{projectId}/plans/generate (DEV-384 V3-B)
|
|
378
|
+
* Start whichever generation stage the project is missing next. The body
|
|
379
|
+
* is empty by contract — the server decides which rung fires. 202 both
|
|
380
|
+
* for `accepted` (a stage started) and `nothing_to_start` (proposals are
|
|
381
|
+
* already staged; the facade's no-restart guard refuses a duplicate
|
|
382
|
+
* append because it would wipe the batch and re-bill 2 credits).
|
|
383
|
+
*
|
|
384
|
+
* `retryOnConflict: false` — a 409 here is `stage_in_flight`, a flow
|
|
385
|
+
* signal the ladder answers by attaching and polling, never a transient
|
|
386
|
+
* snapshot conflict to paper over with a retry.
|
|
387
|
+
*/
|
|
388
|
+
generatePlans(projectId: string, options: {
|
|
389
|
+
idempotencyKey: string;
|
|
390
|
+
signal?: AbortSignal;
|
|
391
|
+
}): Promise<CliGeneratePlansResponse>;
|
|
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
|
+
getPlans(projectId: string, options?: {
|
|
401
|
+
waitSeconds?: number;
|
|
402
|
+
signal?: AbortSignal;
|
|
403
|
+
}): Promise<CliGetPlansResponse>;
|
|
404
|
+
/**
|
|
405
|
+
* POST /api/cli/v1/projects/{projectId}/plans/accept (DEV-384 V3-B)
|
|
406
|
+
* Convert staged proposals into real test cases. `only` is ALWAYS an
|
|
407
|
+
* explicit, non-empty id list — the caller enforces the two §3.3 safety
|
|
408
|
+
* rules (full list when the user didn't subset; an empty selection is a
|
|
409
|
+
* client-side validation error because `[]` is server-destructive:
|
|
410
|
+
* it means "reject everything" and clears the staged batch).
|
|
411
|
+
*/
|
|
412
|
+
acceptPlans(projectId: string, only: string[], options: {
|
|
413
|
+
idempotencyKey: string;
|
|
414
|
+
signal?: AbortSignal;
|
|
415
|
+
}): Promise<CliAcceptPlansResponse>;
|
|
322
416
|
/**
|
|
323
417
|
* Classify an error thrown while issuing OR reading a request. When it is an
|
|
324
418
|
* abort/timeout and our per-request timeout signal fired (and the caller had
|