@testsprite/testsprite-cli 0.6.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 +52 -31
- package/dist/commands/agent.js +91 -45
- package/dist/commands/ci.d.ts +88 -0
- package/dist/commands/ci.js +429 -0
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.js +104 -8
- package/dist/commands/init.js +8 -0
- package/dist/commands/project.d.ts +78 -0
- package/dist/commands/project.js +429 -5
- package/dist/commands/schedule.d.ts +120 -0
- package/dist/commands/schedule.js +487 -0
- package/dist/commands/test.d.ts +176 -2
- package/dist/commands/test.js +2235 -609
- package/dist/commands/testlist.d.ts +88 -0
- package/dist/commands/testlist.js +753 -0
- package/dist/commands/tunnel.d.ts +72 -0
- package/dist/commands/tunnel.js +367 -0
- package/dist/index.js +113 -40
- package/dist/lib/agent-targets.d.ts +13 -4
- package/dist/lib/agent-targets.js +11 -2
- package/dist/lib/conflict-reason.d.ts +30 -0
- package/dist/lib/conflict-reason.js +45 -0
- package/dist/lib/credentials.js +42 -1
- package/dist/lib/cron.d.ts +40 -0
- package/dist/lib/cron.js +190 -0
- package/dist/lib/dry-run/samples.d.ts +9 -0
- package/dist/lib/dry-run/samples.js +293 -55
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.js +11 -0
- package/dist/lib/gh-output.d.ts +33 -1
- package/dist/lib/gh-output.js +97 -27
- package/dist/lib/http.d.ts +119 -0
- package/dist/lib/http.js +243 -2
- package/dist/lib/interrupt.d.ts +38 -13
- package/dist/lib/interrupt.js +130 -15
- package/dist/lib/junit-report.d.ts +20 -2
- package/dist/lib/junit-report.js +38 -5
- 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/proxy.d.ts +16 -0
- package/dist/lib/proxy.js +19 -1
- package/dist/lib/response-schemas.d.ts +20 -0
- package/dist/lib/response-schemas.js +55 -1
- package/dist/lib/run-progress.d.ts +41 -0
- package/dist/lib/run-progress.js +56 -0
- package/dist/lib/runs.types.d.ts +32 -3
- package/dist/lib/secret-file.d.ts +15 -0
- package/dist/lib/secret-file.js +82 -0
- package/dist/lib/target-url-preflight.d.ts +91 -0
- package/dist/lib/target-url-preflight.js +259 -0
- package/dist/lib/target-url.d.ts +63 -9
- package/dist/lib/target-url.js +283 -62
- package/dist/lib/telemetry.d.ts +11 -0
- package/dist/lib/telemetry.js +1 -0
- package/dist/lib/testlist.types.d.ts +77 -0
- package/dist/lib/testlist.types.js +9 -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/lib/v3-advisory.d.ts +35 -22
- package/dist/lib/v3-advisory.js +44 -24
- package/dist/lib/wait-exit.d.ts +29 -0
- package/dist/lib/wait-exit.js +103 -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-guard.d.ts +10 -7
- package/dist/version-guard.js +37 -9
- 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,15 @@
|
|
|
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';
|
|
10
|
+
import { createScheduleCommand } from './commands/schedule.js';
|
|
11
|
+
import { createTunnelCommand } from './commands/tunnel.js';
|
|
9
12
|
import { createTestCommand } from './commands/test.js';
|
|
13
|
+
import { createTestListCommand } from './commands/testlist.js';
|
|
10
14
|
import { createUsageCommand } from './commands/usage.js';
|
|
11
15
|
import { TARGETS } from './lib/agent-targets.js';
|
|
12
16
|
import { ApiError, CLIError, InterruptError, RequestTimeoutError } from './lib/errors.js';
|
|
@@ -18,11 +22,11 @@ import { isPlanTemplateInvocation, maybeEmitSkillNudge } from './lib/skill-nudge
|
|
|
18
22
|
import { classifyCliError, isTelemetryOptedOut, recordOutcome, resolveTelemetryAuth, } from './lib/telemetry.js';
|
|
19
23
|
import { maybeNotifyUpdate } from './lib/update-check.js';
|
|
20
24
|
import { VERSION } from './version.js';
|
|
21
|
-
import { shouldRejectNodeVersion } from './version-guard.js';
|
|
25
|
+
import { SUPPORTED_NODE_RANGE, shouldRejectNodeVersion } from './version-guard.js';
|
|
22
26
|
// Guard: exit early with a clear message on unsupported Node.js versions,
|
|
23
27
|
// rather than failing later with a cryptic ESM/runtime error.
|
|
24
28
|
if (shouldRejectNodeVersion(process.versions.node)) {
|
|
25
|
-
process.stderr.write(`Error: testsprite requires Node.js
|
|
29
|
+
process.stderr.write(`Error: testsprite requires Node.js ${SUPPORTED_NODE_RANGE} (found ${process.versions.node}).\nInstall a supported Node.js release from https://nodejs.org\n`);
|
|
26
30
|
process.exit(1);
|
|
27
31
|
}
|
|
28
32
|
const program = new Command();
|
|
@@ -65,6 +69,10 @@ addSetupOptions(authCommand.command('configure', { hidden: true }), authConfigur
|
|
|
65
69
|
program.addCommand(authCommand);
|
|
66
70
|
program.addCommand(createProjectCommand({}));
|
|
67
71
|
program.addCommand(createTestCommand());
|
|
72
|
+
program.addCommand(createTestListCommand());
|
|
73
|
+
program.addCommand(createCiCommand({}));
|
|
74
|
+
program.addCommand(createScheduleCommand({}));
|
|
75
|
+
program.addCommand(createTunnelCommand({}));
|
|
68
76
|
program.addCommand(createAgentCommand({}));
|
|
69
77
|
program.addCommand(createUsageCommand());
|
|
70
78
|
program.addCommand(createDoctorCommand());
|
|
@@ -107,6 +115,13 @@ let telemetryEmit = false;
|
|
|
107
115
|
// Auth resolved in the preAction hook, before the command's action runs, so
|
|
108
116
|
// `auth remove` (which deletes the profile) is still reported on the key it used.
|
|
109
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;
|
|
110
125
|
// Propagate exitOverride AND the buffered outputError config to every
|
|
111
126
|
// subcommand in the tree. Commander's addCommand() does NOT inherit either
|
|
112
127
|
// from the parent, so commands built externally (createTestCommand, etc.) and
|
|
@@ -126,6 +141,36 @@ function applyExitOverrideDeep(cmd) {
|
|
|
126
141
|
}
|
|
127
142
|
}
|
|
128
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
|
+
});
|
|
129
174
|
/**
|
|
130
175
|
* Render a leaf command's full path (group + leaf), e.g. `test run` /
|
|
131
176
|
* `auth whoami`, by walking parents up to (but not including) the root program.
|
|
@@ -154,6 +199,10 @@ program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
|
154
199
|
const commandPath = commandPathOf(actionCommand);
|
|
155
200
|
// Record which leaf command ran, for the telemetry emit around parseAsync.
|
|
156
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;
|
|
157
206
|
// See `isPlanTemplateInvocation` for why this one case is
|
|
158
207
|
// filtered here rather than in skill-nudge.ts / update-check.ts.
|
|
159
208
|
const isPlanTemplate = isPlanTemplateInvocation(commandPath, globals.planTemplate);
|
|
@@ -219,15 +268,26 @@ try {
|
|
|
219
268
|
exitCode: 0,
|
|
220
269
|
durationMs: Date.now() - telemetryStartedAt,
|
|
221
270
|
...telemetryGlobals(),
|
|
271
|
+
local: telemetryLocal,
|
|
222
272
|
}, { resolvedAuth: telemetryAuth });
|
|
223
273
|
}
|
|
224
274
|
}
|
|
225
275
|
catch (err) {
|
|
226
276
|
const telemetryOutcome = classifyCliError(err);
|
|
227
277
|
// Flush the outcome AFTER the error is rendered to stderr below (via each
|
|
228
|
-
// branch's `
|
|
229
|
-
// The classification mirrors the exit-code mapping the
|
|
230
|
-
|
|
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) => {
|
|
231
291
|
if (telemetryEmit) {
|
|
232
292
|
await recordOutcome({
|
|
233
293
|
command: ranCommandPath,
|
|
@@ -236,12 +296,14 @@ catch (err) {
|
|
|
236
296
|
errorCode: telemetryOutcome.errorCode,
|
|
237
297
|
durationMs: Date.now() - telemetryStartedAt,
|
|
238
298
|
...telemetryGlobals(),
|
|
299
|
+
local: telemetryLocal,
|
|
239
300
|
}, { resolvedAuth: telemetryAuth });
|
|
240
301
|
}
|
|
241
|
-
process.
|
|
302
|
+
process.exitCode = code;
|
|
242
303
|
};
|
|
243
304
|
const rawMode = program.opts().output;
|
|
244
305
|
const mode = isOutputMode(rawMode) ? rawMode : 'text';
|
|
306
|
+
const output = new Output(mode);
|
|
245
307
|
if (err instanceof ApiError) {
|
|
246
308
|
if (mode === 'json') {
|
|
247
309
|
const envelope = {
|
|
@@ -291,24 +353,31 @@ catch (err) {
|
|
|
291
353
|
}
|
|
292
354
|
}
|
|
293
355
|
}
|
|
294
|
-
await
|
|
356
|
+
await flushThenSetExitCode(err.exitCode);
|
|
295
357
|
}
|
|
296
|
-
|
|
297
|
-
if (err instanceof InterruptError) {
|
|
358
|
+
else if (err instanceof InterruptError) {
|
|
298
359
|
// Graceful detach (DEV-331 piece 1, errors.md §8.1): the wait-path catch
|
|
299
360
|
// block already printed the honest partial + re-attach hint. Exit with
|
|
300
361
|
// the conventional 128+signum code; `INTERRUPTED` is deliberately outside
|
|
301
362
|
// the error catalog. Note: Ctrl-C does NOT cancel the server-side run.
|
|
302
363
|
if (mode === 'json') {
|
|
364
|
+
const tunnelDetach = err
|
|
365
|
+
.tunnelDetach;
|
|
303
366
|
const envelope = {
|
|
304
367
|
error: {
|
|
305
368
|
code: 'INTERRUPTED',
|
|
306
369
|
message: err.message,
|
|
307
|
-
nextAction:
|
|
308
|
-
'
|
|
309
|
-
|
|
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).',
|
|
310
374
|
requestId: 'local',
|
|
311
|
-
details: {
|
|
375
|
+
details: {
|
|
376
|
+
signal: err.signal,
|
|
377
|
+
...(tunnelDetach
|
|
378
|
+
? { runId: tunnelDetach.runId, cancelOutcome: tunnelDetach.cancel }
|
|
379
|
+
: {}),
|
|
380
|
+
},
|
|
312
381
|
},
|
|
313
382
|
};
|
|
314
383
|
process.stderr.write(`${JSON.stringify(envelope, null, 2)}\n`);
|
|
@@ -316,9 +385,9 @@ catch (err) {
|
|
|
316
385
|
else {
|
|
317
386
|
process.stderr.write(`Error: ${err.message}\n`);
|
|
318
387
|
}
|
|
319
|
-
await
|
|
388
|
+
await flushThenSetExitCode(err.exitCode);
|
|
320
389
|
}
|
|
321
|
-
if (err instanceof RequestTimeoutError) {
|
|
390
|
+
else if (err instanceof RequestTimeoutError) {
|
|
322
391
|
// Structured rendering for per-request timeouts: JSON mode emits a
|
|
323
392
|
// machine-readable envelope; text mode emits the message with a hint.
|
|
324
393
|
if (mode === 'json') {
|
|
@@ -337,9 +406,9 @@ catch (err) {
|
|
|
337
406
|
else {
|
|
338
407
|
process.stderr.write(`Error: ${err.message}\n`);
|
|
339
408
|
}
|
|
340
|
-
await
|
|
409
|
+
await flushThenSetExitCode(err.exitCode);
|
|
341
410
|
}
|
|
342
|
-
if (err instanceof CommanderError) {
|
|
411
|
+
else if (err instanceof CommanderError) {
|
|
343
412
|
// Map exit codes per the CLI taxonomy:
|
|
344
413
|
// help / version → 0 (user asked for it; Commander already wrote the text)
|
|
345
414
|
// parse errors → 5 (VALIDATION_ERROR family: missing arg, invalid
|
|
@@ -356,33 +425,37 @@ catch (err) {
|
|
|
356
425
|
if (err.code === 'commander.helpDisplayed' ||
|
|
357
426
|
err.code === 'commander.help' ||
|
|
358
427
|
err.code === 'commander.version') {
|
|
359
|
-
await
|
|
428
|
+
await flushThenSetExitCode(0);
|
|
360
429
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
for (let i = 2; i < process.argv.length; i++) {
|
|
370
|
-
const arg = process.argv[i];
|
|
371
|
-
if (arg === '--output' && process.argv[i + 1] === 'json')
|
|
372
|
-
return 'json';
|
|
373
|
-
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')
|
|
374
438
|
return 'json';
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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
|
+
}
|
|
380
451
|
}
|
|
381
|
-
if (err instanceof CLIError) {
|
|
452
|
+
else if (err instanceof CLIError) {
|
|
382
453
|
output.error(err.message);
|
|
383
|
-
await
|
|
454
|
+
await flushThenSetExitCode(err.exitCode);
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
output.error(err instanceof Error ? err.message : String(err));
|
|
458
|
+
await flushThenSetExitCode(1);
|
|
384
459
|
}
|
|
385
|
-
output.error(err instanceof Error ? err.message : String(err));
|
|
386
|
-
await flushThenExit(1);
|
|
387
460
|
}
|
|
388
461
|
//# sourceMappingURL=index.js.map
|
|
@@ -16,10 +16,12 @@ export interface TargetSpec {
|
|
|
16
16
|
mode: 'own-file' | 'managed-section';
|
|
17
17
|
/**
|
|
18
18
|
* When true, render the budget-friendly body (see {@link compactBodyFor})
|
|
19
|
-
* instead of the full own-file skill body.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* instead of the full own-file skill body. Set for own-file targets that must
|
|
20
|
+
* keep their rule file small: `windsurf` (hard ~12 K-char cap, silently
|
|
21
|
+
* truncated beyond) and `copilot` (no cap, but `applyTo: '**'` injects it into
|
|
22
|
+
* every request, so context cost is the constraint).
|
|
23
|
+
*
|
|
24
|
+
* Read it via {@link ownFileBodyFor}, never by testing target names (DEV-672).
|
|
23
25
|
*/
|
|
24
26
|
compactBody?: boolean;
|
|
25
27
|
/**
|
|
@@ -148,6 +150,13 @@ export declare function loadSkillBodyFor(skill: string, read?: ReadFn): string;
|
|
|
148
150
|
* used.
|
|
149
151
|
*/
|
|
150
152
|
export declare function compactBodyFor(skill: string, read?: ReadFn): string;
|
|
153
|
+
/**
|
|
154
|
+
* The canonical own-file body for a (target, skill) pair, and therefore the body
|
|
155
|
+
* the install marker's hash covers. Every producer AND consumer of an own-file
|
|
156
|
+
* body must resolve through here — install and status keeping separate copies of
|
|
157
|
+
* this rule is what caused DEV-672.
|
|
158
|
+
*/
|
|
159
|
+
export declare function ownFileBodyFor(target: AgentTarget, skill: string, read?: ReadFn): string;
|
|
151
160
|
/**
|
|
152
161
|
* Resolve a skill's codex (AGENTS.md) contribution as a Markdown string.
|
|
153
162
|
* 'full' → read the `*.codex.md` asset; 'line' → the inline one-liner; 'none' → ''.
|
|
@@ -284,6 +284,15 @@ export function compactBodyFor(skill, read = defaultRead) {
|
|
|
284
284
|
? readSkillAsset(spec.codex.file, read)
|
|
285
285
|
: loadSkillBodyFor(skill, read);
|
|
286
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* The canonical own-file body for a (target, skill) pair, and therefore the body
|
|
289
|
+
* the install marker's hash covers. Every producer AND consumer of an own-file
|
|
290
|
+
* body must resolve through here — install and status keeping separate copies of
|
|
291
|
+
* this rule is what caused DEV-672.
|
|
292
|
+
*/
|
|
293
|
+
export function ownFileBodyFor(target, skill, read = defaultRead) {
|
|
294
|
+
return TARGETS[target].compactBody ? compactBodyFor(skill, read) : loadSkillBodyFor(skill, read);
|
|
295
|
+
}
|
|
287
296
|
/**
|
|
288
297
|
* Resolve a skill's codex (AGENTS.md) contribution as a Markdown string.
|
|
289
298
|
* 'full' → read the `*.codex.md` asset; 'line' → the inline one-liner; 'none' → ''.
|
|
@@ -367,7 +376,7 @@ export function renderOwnFileWithMarker(target, skill, markerLine, body) {
|
|
|
367
376
|
const skillSpec = SKILLS[skill];
|
|
368
377
|
if (!skillSpec)
|
|
369
378
|
throw new Error(`unknown skill: ${skill}`);
|
|
370
|
-
const resolvedBody = body !== undefined ? body :
|
|
379
|
+
const resolvedBody = body !== undefined ? body : ownFileBodyFor(target, skill);
|
|
371
380
|
return injectMarkerLine(spec.wrap(skillSpec.name, skillSpec.description, resolvedBody), markerLine);
|
|
372
381
|
}
|
|
373
382
|
/**
|
|
@@ -393,7 +402,7 @@ export function renderForTarget(t, skill, body) {
|
|
|
393
402
|
const resolvedBody = body !== undefined ? body : codexContentFor(skill);
|
|
394
403
|
return { path, content: spec.wrap(skillSpec.name, skillSpec.description, resolvedBody) };
|
|
395
404
|
}
|
|
396
|
-
const resolvedBody = body !== undefined ? body :
|
|
405
|
+
const resolvedBody = body !== undefined ? body : ownFileBodyFor(t, skill);
|
|
397
406
|
return {
|
|
398
407
|
path,
|
|
399
408
|
content: renderOwnFileWithMarker(t, skill, buildSkillMarker(skill, resolvedBody), resolvedBody),
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a case landed in a run response's `conflicts[]` instead of dispatching.
|
|
3
|
+
* The backend (`batchRunFresh` / `dispatchTestListGroups`) tags each conflict so
|
|
4
|
+
* the CLI stops rendering every non-dispatch as "already in flight" — which is
|
|
5
|
+
* wrong for a view-only mirror, an un-runnable environment, or an unknown id.
|
|
6
|
+
*
|
|
7
|
+
* Absent ⇒ a legacy / pre-discriminator backend: treated as `in_flight` (the
|
|
8
|
+
* historical rendering) for backward compatibility.
|
|
9
|
+
*/
|
|
10
|
+
export type ConflictReason = 'in_flight' | 'mcp_view_only' | 'local_address' | 'not_found' | 'error';
|
|
11
|
+
/** A conflict entry on a run response. `message` carries actionable detail for
|
|
12
|
+
* `local_address` / `error` (the backend env guard's nextAction). */
|
|
13
|
+
export interface RunConflict {
|
|
14
|
+
testId: string;
|
|
15
|
+
currentRunId?: string;
|
|
16
|
+
reason?: ConflictReason;
|
|
17
|
+
message?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Short human label for a conflict's cause — the reason a case did NOT dispatch.
|
|
21
|
+
* Absent reason renders as the legacy "already in flight" so an old backend's
|
|
22
|
+
* bare `{testId, currentRunId?}` conflicts read exactly as they did before.
|
|
23
|
+
*/
|
|
24
|
+
export declare function describeConflict(c: RunConflict): string;
|
|
25
|
+
/**
|
|
26
|
+
* One-line summary of a conflict set grouped by reason, e.g.
|
|
27
|
+
* `2 already in flight, 1 environment not runnable`. Used where a single line
|
|
28
|
+
* must stand in for the whole `conflicts[]` (exit-message / advisory).
|
|
29
|
+
*/
|
|
30
|
+
export declare function summarizeConflicts(conflicts: readonly RunConflict[]): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Short human label for a conflict's cause — the reason a case did NOT dispatch.
|
|
3
|
+
* Absent reason renders as the legacy "already in flight" so an old backend's
|
|
4
|
+
* bare `{testId, currentRunId?}` conflicts read exactly as they did before.
|
|
5
|
+
*/
|
|
6
|
+
export function describeConflict(c) {
|
|
7
|
+
switch (c.reason) {
|
|
8
|
+
case 'mcp_view_only':
|
|
9
|
+
return 'project is view-only (MCP-mirrored) — not runnable';
|
|
10
|
+
case 'local_address':
|
|
11
|
+
return c.message || 'environment not runnable (local/private/unresolvable URL)';
|
|
12
|
+
case 'not_found':
|
|
13
|
+
return 'not found in this workspace';
|
|
14
|
+
case 'error':
|
|
15
|
+
return c.message || 'dispatch failed';
|
|
16
|
+
case 'in_flight':
|
|
17
|
+
default:
|
|
18
|
+
return c.currentRunId ? `already in flight (run ${c.currentRunId})` : 'already in flight';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* One-line summary of a conflict set grouped by reason, e.g.
|
|
23
|
+
* `2 already in flight, 1 environment not runnable`. Used where a single line
|
|
24
|
+
* must stand in for the whole `conflicts[]` (exit-message / advisory).
|
|
25
|
+
*/
|
|
26
|
+
export function summarizeConflicts(conflicts) {
|
|
27
|
+
const labels = {
|
|
28
|
+
in_flight: 'already in flight',
|
|
29
|
+
mcp_view_only: 'view-only (MCP) project',
|
|
30
|
+
local_address: 'environment not runnable',
|
|
31
|
+
not_found: 'not found',
|
|
32
|
+
error: 'dispatch error',
|
|
33
|
+
};
|
|
34
|
+
const counts = new Map();
|
|
35
|
+
for (const c of conflicts) {
|
|
36
|
+
const reason = c.reason ?? 'in_flight';
|
|
37
|
+
counts.set(reason, (counts.get(reason) ?? 0) + 1);
|
|
38
|
+
}
|
|
39
|
+
// A future/unknown reason the loose wire schema admits (describeConflict covers
|
|
40
|
+
// it via its default arm) must not render as "N undefined" here.
|
|
41
|
+
return [...counts.entries()]
|
|
42
|
+
.map(([reason, n]) => `${n} ${labels[reason] ?? 'not dispatched'}`)
|
|
43
|
+
.join(', ');
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=conflict-reason.js.map
|
package/dist/lib/credentials.js
CHANGED
|
@@ -248,6 +248,34 @@ function acquireCredentialsLock(path) {
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Age is normally read from the lock body's own `createdAt` (unchanged from
|
|
253
|
+
* before — this is what lets a legitimately abandoned lock from a crashed
|
|
254
|
+
* process, or a test simulating one, report an age older than the file's own
|
|
255
|
+
* mtime). It is ONLY when the body cannot be read/parsed that this falls back
|
|
256
|
+
* to the lock file's filesystem mtime (`statSync`) rather than treating an
|
|
257
|
+
* unreadable body as `Number.POSITIVE_INFINITY` (i.e. "infinitely stale"), as
|
|
258
|
+
* an earlier version of this function did.
|
|
259
|
+
*
|
|
260
|
+
* That fallback-to-infinity was the bug: a transient, benign read/parse
|
|
261
|
+
* failure — e.g. this reader's `readFileSync` landing in the brief window
|
|
262
|
+
* where the current holder is rewriting or releasing the file — was
|
|
263
|
+
* indistinguishable from "no `createdAt` at all", which always cleared the
|
|
264
|
+
* staleness check regardless of true age. That could unlink a lock that was
|
|
265
|
+
* milliseconds old and actively held, so the real owner's later
|
|
266
|
+
* `assertHeld()` call failed with "lost ownership" even though nothing had
|
|
267
|
+
* actually gone stale — reproduced locally under concurrent-writer load
|
|
268
|
+
* (multiple `writeProfile` calls racing for the same credentials file) and
|
|
269
|
+
* matches the failure signature seen under CI contention. `statSync` is a
|
|
270
|
+
* single atomic syscall, so — unlike reading-then-parsing a small file — it
|
|
271
|
+
* cannot itself be fooled by a torn write; when it also fails (ENOENT because
|
|
272
|
+
* the holder already released it, or a transient EPERM/EBUSY on Windows
|
|
273
|
+
* while a handle is still closing) that is treated as "nothing to safely
|
|
274
|
+
* reclaim right now" rather than "definitely gone" — the acquire loop's own
|
|
275
|
+
* retry/deadline handles the ordinary case of the file being gone by simply
|
|
276
|
+
* succeeding on the next `wx` attempt, so there is no need for this function
|
|
277
|
+
* to draw that conclusion itself.
|
|
278
|
+
*/
|
|
251
279
|
function reclaimStaleCredentialsLock(lockPath) {
|
|
252
280
|
let lockInfo;
|
|
253
281
|
try {
|
|
@@ -257,7 +285,20 @@ function reclaimStaleCredentialsLock(lockPath) {
|
|
|
257
285
|
lockInfo = undefined;
|
|
258
286
|
}
|
|
259
287
|
const createdAt = typeof lockInfo?.createdAt === 'number' ? lockInfo.createdAt : undefined;
|
|
260
|
-
|
|
288
|
+
let ageMs;
|
|
289
|
+
if (createdAt !== undefined) {
|
|
290
|
+
ageMs = Date.now() - createdAt;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
try {
|
|
294
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- `lockPath` is `${credentialsPath}.lock`, derived internally from the same credentials-file path this whole module already operates on (default `~/.testsprite/credentials`, or the caller-supplied path in `CredentialsOptions.path`) — the identical, already-baselined risk profile as this file's other lock/credentials fs calls, not new external input.
|
|
295
|
+
ageMs = Date.now() - statSync(lockPath).mtimeMs;
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
// Already gone (or otherwise inaccessible) — nothing to reclaim.
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
261
302
|
const pid = typeof lockInfo?.pid === 'number' ? lockInfo.pid : undefined;
|
|
262
303
|
if (ageMs <= CREDENTIALS_LOCK_STALE_MS && (pid === undefined || isProcessAlive(pid))) {
|
|
263
304
|
return;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron helpers for the `schedule` commands.
|
|
3
|
+
*
|
|
4
|
+
* Everything here produces human-facing text only — none of it affects when a
|
|
5
|
+
* schedule fires.
|
|
6
|
+
*
|
|
7
|
+
* Field order is standard 5-field cron: minute hour day-of-month month day-of-week.
|
|
8
|
+
* That is the format the API takes on `schedule create`/`update` and hands back
|
|
9
|
+
* on `schedule get`, so an expression read from one command is valid input to
|
|
10
|
+
* the other.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Approximate number of times a cron fires per month, or null when the
|
|
14
|
+
* expression is not a 5-field cron we can read.
|
|
15
|
+
*
|
|
16
|
+
* Every field is counted, so a cron that pins a coarse field and leaves a finer
|
|
17
|
+
* one open (`* 3 * * *` — every minute of 03:00) is not mistaken for its coarse
|
|
18
|
+
* unit. day-of-month and day-of-week are OR'd when both are restricted, which
|
|
19
|
+
* is what standard cron does.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runsPerMonth(cron: string): number | null;
|
|
22
|
+
/**
|
|
23
|
+
* Human phrasing for a cron, or the expression itself when it names no exact
|
|
24
|
+
* time — a wrong description is worse than the raw expression.
|
|
25
|
+
*/
|
|
26
|
+
export declare function describeCron(cron: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Advisory shown before a schedule is created: how often it will run, and that
|
|
29
|
+
* each run is a full test run.
|
|
30
|
+
*
|
|
31
|
+
* States frequency only. Credit cost is deliberately not quoted — the API does
|
|
32
|
+
* not expose a per-action rate for the workspace wallet, and a figure derived
|
|
33
|
+
* from anything else would be wrong. Same reason `usage` does not print a
|
|
34
|
+
* "~N runs" estimate.
|
|
35
|
+
*
|
|
36
|
+
* An expression we cannot read still gets the advisory, without a frequency —
|
|
37
|
+
* the server is the authority on the cron, so refusing to say anything about a
|
|
38
|
+
* schedule we are about to create would be worse than saying less.
|
|
39
|
+
*/
|
|
40
|
+
export declare function formatScheduleFrequencyAdvisory(cron: string): string;
|