@testsprite/testsprite-cli 0.3.0 → 0.5.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 +55 -29
- package/dist/commands/agent.js +17 -6
- package/dist/commands/auth.d.ts +51 -0
- package/dist/commands/auth.js +46 -2
- package/dist/commands/completion.d.ts +36 -0
- package/dist/commands/completion.js +111 -0
- package/dist/commands/doctor.js +56 -16
- package/dist/commands/init.d.ts +32 -1
- package/dist/commands/init.js +40 -10
- package/dist/commands/project.d.ts +102 -4
- package/dist/commands/project.js +250 -47
- package/dist/commands/test.d.ts +253 -11
- package/dist/commands/test.js +1822 -390
- package/dist/commands/usage.d.ts +56 -17
- package/dist/commands/usage.js +144 -29
- package/dist/index.js +172 -29
- package/dist/lib/browser.d.ts +6 -0
- package/dist/lib/browser.js +54 -0
- package/dist/lib/bundle.d.ts +32 -31
- package/dist/lib/bundle.js +144 -84
- package/dist/lib/client-factory.d.ts +29 -0
- package/dist/lib/client-factory.js +49 -1
- package/dist/lib/config.js +7 -3
- package/dist/lib/credentials.d.ts +17 -1
- package/dist/lib/credentials.js +175 -16
- package/dist/lib/dry-run/samples.js +51 -1
- package/dist/lib/errors.d.ts +33 -1
- package/dist/lib/errors.js +110 -19
- package/dist/lib/failing-fe-resolver.d.ts +15 -0
- package/dist/lib/failing-fe-resolver.js +49 -1
- package/dist/lib/flaky.d.ts +12 -1
- package/dist/lib/flaky.js +7 -12
- package/dist/lib/gh-output.d.ts +62 -0
- package/dist/lib/gh-output.js +99 -0
- package/dist/lib/http.d.ts +86 -16
- package/dist/lib/http.js +181 -11
- package/dist/lib/interrupt.d.ts +65 -10
- package/dist/lib/interrupt.js +94 -9
- package/dist/lib/org-render.d.ts +52 -0
- package/dist/lib/org-render.js +59 -0
- package/dist/lib/poll.d.ts +11 -0
- package/dist/lib/poll.js +71 -6
- package/dist/lib/render-error.d.ts +14 -0
- package/dist/lib/render-error.js +30 -0
- package/dist/lib/response-schemas.d.ts +83 -0
- package/dist/lib/response-schemas.js +272 -0
- package/dist/lib/runs.types.d.ts +62 -8
- package/dist/lib/skill-nudge.d.ts +17 -0
- package/dist/lib/skill-nudge.js +19 -0
- package/dist/lib/telemetry.d.ts +90 -0
- package/dist/lib/telemetry.js +171 -0
- package/dist/lib/text-table.d.ts +14 -0
- package/dist/lib/text-table.js +45 -0
- package/dist/lib/v3-advisory.d.ts +22 -0
- package/dist/lib/v3-advisory.js +32 -0
- package/dist/lib/version-notice.d.ts +37 -0
- package/dist/lib/version-notice.js +87 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +16 -5
- package/schemas/plan.schema.json +61 -0
- package/skills/testsprite-verify.codex.md +8 -2
- package/skills/testsprite-verify.skill.md +18 -7
package/dist/index.js
CHANGED
|
@@ -2,17 +2,20 @@
|
|
|
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 { createCompletionCommand } from './commands/completion.js';
|
|
5
6
|
import { createDoctorCommand } from './commands/doctor.js';
|
|
6
|
-
import { createDeprecatedInitCommand, createSetupCommand, runConfigureViaSetup, } from './commands/init.js';
|
|
7
|
+
import { addSetupOptions, createDeprecatedInitCommand, createSetupCommand, runConfigureViaSetup, } from './commands/init.js';
|
|
7
8
|
import { createProjectCommand } from './commands/project.js';
|
|
8
9
|
import { createTestCommand } from './commands/test.js';
|
|
9
10
|
import { createUsageCommand } from './commands/usage.js';
|
|
10
|
-
import {
|
|
11
|
+
import { TARGETS } from './lib/agent-targets.js';
|
|
12
|
+
import { ApiError, CLIError, InterruptError, RequestTimeoutError } from './lib/errors.js';
|
|
11
13
|
import { installBrokenPipeGuard, installSignalHandlers } from './lib/interrupt.js';
|
|
12
14
|
import { Output, isOutputMode } from './lib/output.js';
|
|
13
15
|
import { maybeInstallProxyAgent } from './lib/proxy.js';
|
|
14
|
-
import { renderCommanderError, rephraseUnknownOption } from './lib/render-error.js';
|
|
15
|
-
import { maybeEmitSkillNudge } from './lib/skill-nudge.js';
|
|
16
|
+
import { renderAmbiguousOrgCandidates, renderCommanderError, rephraseUnknownOption, } from './lib/render-error.js';
|
|
17
|
+
import { isPlanTemplateInvocation, maybeEmitSkillNudge } from './lib/skill-nudge.js';
|
|
18
|
+
import { classifyCliError, isTelemetryOptedOut, recordOutcome, resolveTelemetryAuth, } from './lib/telemetry.js';
|
|
16
19
|
import { maybeNotifyUpdate } from './lib/update-check.js';
|
|
17
20
|
import { VERSION } from './version.js';
|
|
18
21
|
import { shouldRejectNodeVersion } from './version-guard.js';
|
|
@@ -48,14 +51,16 @@ program.addCommand(createDeprecatedInitCommand({}), { hidden: true });
|
|
|
48
51
|
// `auth configure` is a hidden, deprecated alias that runs FULL `setup`
|
|
49
52
|
// (configure + skill install), so an agent reaching for the old command still
|
|
50
53
|
// ends up with the skill. `setup` remains the ONLY path that writes credentials.
|
|
54
|
+
// Attach the SAME flag set `setup` has (previously only
|
|
55
|
+
// `--from-env` was wired up, so README's "runs the full setup" claim didn't
|
|
56
|
+
// hold — `--yes`/`--agent`/`--api-key`/`--force`/`--dir`/`--no-agent` were all
|
|
57
|
+
// rejected as `unknown option`).
|
|
51
58
|
const authCommand = createAuthCommand();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
.option('--from-env', 'Read TESTSPRITE_API_KEY (and optionally TESTSPRITE_API_URL) from the environment instead of prompting', false)
|
|
55
|
-
.action(async (cmdOpts, command) => {
|
|
59
|
+
const authConfigureValidTargets = Object.keys(TARGETS);
|
|
60
|
+
addSetupOptions(authCommand.command('configure', { hidden: true }), authConfigureValidTargets, 'claude').action(async (cmdOpts, command) => {
|
|
56
61
|
process.stderr.write('[deprecated] `testsprite auth configure` now runs full setup (configure + skill install) — ' +
|
|
57
62
|
'use `testsprite setup` (add --no-agent to skip the skill).\n');
|
|
58
|
-
await runConfigureViaSetup(command, {},
|
|
63
|
+
await runConfigureViaSetup(command, {}, cmdOpts);
|
|
59
64
|
});
|
|
60
65
|
program.addCommand(authCommand);
|
|
61
66
|
program.addCommand(createProjectCommand({}));
|
|
@@ -63,11 +68,45 @@ program.addCommand(createTestCommand());
|
|
|
63
68
|
program.addCommand(createAgentCommand({}));
|
|
64
69
|
program.addCommand(createUsageCommand());
|
|
65
70
|
program.addCommand(createDoctorCommand());
|
|
71
|
+
program.addCommand(createCompletionCommand(() => buildCompletionSpec()));
|
|
72
|
+
// Derive the shell-completion spec from the fully-assembled command tree at call
|
|
73
|
+
// time (not module-load), so `testsprite completion` can never drift from the
|
|
74
|
+
// real commands, subcommands, and global flags.
|
|
75
|
+
function buildCompletionSpec() {
|
|
76
|
+
const subcommands = {};
|
|
77
|
+
for (const command of program.commands) {
|
|
78
|
+
const subs = command.commands.map(sub => sub.name()).filter(name => name !== 'help');
|
|
79
|
+
if (subs.length > 0)
|
|
80
|
+
subcommands[command.name()] = subs;
|
|
81
|
+
}
|
|
82
|
+
const flags = program.options
|
|
83
|
+
.map(option => option.long)
|
|
84
|
+
.filter((long) => typeof long === 'string');
|
|
85
|
+
if (!flags.includes('--help'))
|
|
86
|
+
flags.push('--help');
|
|
87
|
+
return {
|
|
88
|
+
program: 'testsprite',
|
|
89
|
+
commands: [...new Set([...program.commands.map(command => command.name()), 'help'])],
|
|
90
|
+
subcommands,
|
|
91
|
+
globalFlags: flags,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
66
94
|
// Buffer Commander error messages instead of writing immediately. The catch
|
|
67
95
|
// block re-emits in the correct format (JSON or text) once the requested
|
|
68
96
|
// output mode is known. Safe because applyExitOverrideDeep ensures every
|
|
69
97
|
// command throws CommanderError rather than calling process.exit directly.
|
|
70
98
|
let pendingCommanderErrorMsg = null;
|
|
99
|
+
// Leaf command path that actually reached an action (set by the preAction hook
|
|
100
|
+
// below). Empty when no action ran (bare `--help`, parse error) — telemetry
|
|
101
|
+
// skips those. Read by the success + error telemetry emits around parseAsync.
|
|
102
|
+
let ranCommandPath = '';
|
|
103
|
+
// Whether the command that ran should emit telemetry. `completion` (its stdout
|
|
104
|
+
// is eval'd by shells) and `--plan-template` (pure-local) are kept off the
|
|
105
|
+
// beacon, same as the update notice. Set by the preAction hook.
|
|
106
|
+
let telemetryEmit = false;
|
|
107
|
+
// Auth resolved in the preAction hook, before the command's action runs, so
|
|
108
|
+
// `auth remove` (which deletes the profile) is still reported on the key it used.
|
|
109
|
+
let telemetryAuth;
|
|
71
110
|
// Propagate exitOverride AND the buffered outputError config to every
|
|
72
111
|
// subcommand in the tree. Commander's addCommand() does NOT inherit either
|
|
73
112
|
// from the parent, so commands built externally (createTestCommand, etc.) and
|
|
@@ -100,6 +139,11 @@ function commandPathOf(cmd) {
|
|
|
100
139
|
}
|
|
101
140
|
return names.join(' ');
|
|
102
141
|
}
|
|
142
|
+
/** Global flags the telemetry emit needs (config resolution + context). */
|
|
143
|
+
function telemetryGlobals() {
|
|
144
|
+
const g = program.opts();
|
|
145
|
+
return { profile: g.profile, endpointUrl: g.endpointUrl, output: g.output, dryRun: g.dryRun };
|
|
146
|
+
}
|
|
103
147
|
// Best-effort onboarding nudge (see lib/skill-nudge.ts): when a configured
|
|
104
148
|
// caller drives a verify-loop command in a project with no installed skill,
|
|
105
149
|
// point it at `testsprite setup`. A preAction hook runs before every leaf
|
|
@@ -108,26 +152,53 @@ function commandPathOf(cmd) {
|
|
|
108
152
|
program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
109
153
|
const globals = actionCommand.optsWithGlobals();
|
|
110
154
|
const commandPath = commandPathOf(actionCommand);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
155
|
+
// Record which leaf command ran, for the telemetry emit around parseAsync.
|
|
156
|
+
ranCommandPath = commandPath;
|
|
157
|
+
// See `isPlanTemplateInvocation` for why this one case is
|
|
158
|
+
// filtered here rather than in skill-nudge.ts / update-check.ts.
|
|
159
|
+
const isPlanTemplate = isPlanTemplateInvocation(commandPath, globals.planTemplate);
|
|
160
|
+
// Telemetry gate, same reasons as the update notice below: skip `completion`
|
|
161
|
+
// (its stdout is eval'd by shells) and `--plan-template` (pure-local). Resolve
|
|
162
|
+
// auth now, before the command's action runs, so `auth remove` still reports
|
|
163
|
+
// on the key it used; skip the read for opt-out / dry-run.
|
|
164
|
+
telemetryEmit = commandPath !== 'completion' && !isPlanTemplate;
|
|
165
|
+
if (telemetryEmit && !isTelemetryOptedOut(process.env) && globals.dryRun !== true) {
|
|
166
|
+
telemetryAuth = resolveTelemetryAuth({
|
|
167
|
+
profile: globals.profile,
|
|
168
|
+
endpointUrl: globals.endpointUrl,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
if (!isPlanTemplate) {
|
|
172
|
+
maybeEmitSkillNudge({
|
|
173
|
+
commandPath,
|
|
174
|
+
output: isOutputMode(globals.output) ? globals.output : 'text',
|
|
175
|
+
dryRun: globals.dryRun ?? false,
|
|
176
|
+
profile: globals.profile ?? 'default',
|
|
177
|
+
cwd: process.cwd(),
|
|
178
|
+
env: process.env,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
119
181
|
// Best-effort update notice (see lib/update-check.ts): self-gates on the
|
|
120
182
|
// opt-out env, CI, TTY, and a 24h cache; the wiring adds the flag-level
|
|
121
183
|
// gates the lib cannot see. Skipped for `completion` (its stdout is eval'd
|
|
122
|
-
// by shells), under --output json,
|
|
123
|
-
//
|
|
124
|
-
|
|
184
|
+
// by shells), under --output json, under --dry-run, and for
|
|
185
|
+
// `--plan-template` (pure-local — this check hits the npm registry over
|
|
186
|
+
// the network and writes ~/.testsprite/update-check.json, both of which
|
|
187
|
+
// contradict "no network" for this flag). Deliberately not awaited: an
|
|
188
|
+
// advisory must never delay the real command.
|
|
189
|
+
if (globals.output !== 'json' &&
|
|
190
|
+
globals.dryRun !== true &&
|
|
191
|
+
commandPath !== 'completion' &&
|
|
192
|
+
!isPlanTemplate) {
|
|
125
193
|
void maybeNotifyUpdate();
|
|
126
194
|
}
|
|
127
195
|
});
|
|
128
|
-
// Clean process lifecycle
|
|
129
|
-
//
|
|
130
|
-
//
|
|
196
|
+
// Clean process lifecycle (DEV-331 piece 1, errors.md §8.1): during a `--wait`
|
|
197
|
+
// poll the scope is armed — the first SIGINT/SIGTERM/SIGHUP aborts gracefully
|
|
198
|
+
// and the wait path prints an honest partial (the run KEEPS executing and
|
|
199
|
+
// billing server-side) + re-attach hint before exiting 128+signum; a second
|
|
200
|
+
// signal hard-exits. Outside an armed scope: a clear one-line message +
|
|
201
|
+
// immediate exit (instead of Node's silent abrupt kill). Plus an EPIPE guard
|
|
131
202
|
// so piping to a reader that closes early (`| head`) exits cleanly instead of
|
|
132
203
|
// dumping a raw `write EPIPE` stack.
|
|
133
204
|
installSignalHandlers();
|
|
@@ -135,10 +206,40 @@ installBrokenPipeGuard();
|
|
|
135
206
|
// Corporate/CI proxies: honor HTTPS_PROXY/HTTP_PROXY/NO_PROXY (Node's fetch
|
|
136
207
|
// ignores them by default). No-op when no proxy variable is set.
|
|
137
208
|
maybeInstallProxyAgent();
|
|
209
|
+
const telemetryStartedAt = Date.now();
|
|
138
210
|
try {
|
|
139
211
|
await program.parseAsync(process.argv);
|
|
212
|
+
// Flush a success outcome event before the process exits 0. Bounded +
|
|
213
|
+
// best-effort (see lib/telemetry.ts); skips when no command ran / no key
|
|
214
|
+
// configured / opted out / --dry-run.
|
|
215
|
+
if (telemetryEmit) {
|
|
216
|
+
await recordOutcome({
|
|
217
|
+
command: ranCommandPath,
|
|
218
|
+
outcome: 'success',
|
|
219
|
+
exitCode: 0,
|
|
220
|
+
durationMs: Date.now() - telemetryStartedAt,
|
|
221
|
+
...telemetryGlobals(),
|
|
222
|
+
}, { resolvedAuth: telemetryAuth });
|
|
223
|
+
}
|
|
140
224
|
}
|
|
141
225
|
catch (err) {
|
|
226
|
+
const telemetryOutcome = classifyCliError(err);
|
|
227
|
+
// Flush the outcome AFTER the error is rendered to stderr below (via each
|
|
228
|
+
// branch's `flushThenExit`), so a slow backend never delays the user's error.
|
|
229
|
+
// The classification mirrors the exit-code mapping the branches apply.
|
|
230
|
+
const flushThenExit = async (code) => {
|
|
231
|
+
if (telemetryEmit) {
|
|
232
|
+
await recordOutcome({
|
|
233
|
+
command: ranCommandPath,
|
|
234
|
+
outcome: telemetryOutcome.outcome,
|
|
235
|
+
exitCode: telemetryOutcome.exitCode,
|
|
236
|
+
errorCode: telemetryOutcome.errorCode,
|
|
237
|
+
durationMs: Date.now() - telemetryStartedAt,
|
|
238
|
+
...telemetryGlobals(),
|
|
239
|
+
}, { resolvedAuth: telemetryAuth });
|
|
240
|
+
}
|
|
241
|
+
process.exit(code);
|
|
242
|
+
};
|
|
142
243
|
const rawMode = program.opts().output;
|
|
143
244
|
const mode = isOutputMode(rawMode) ? rawMode : 'text';
|
|
144
245
|
if (err instanceof ApiError) {
|
|
@@ -171,10 +272,52 @@ catch (err) {
|
|
|
171
272
|
process.stderr.write(` granted: ${granted.join(', ')}\n`);
|
|
172
273
|
}
|
|
173
274
|
}
|
|
275
|
+
// Surface the version gap on CLIENT_TOO_OLD so the user sees exactly what
|
|
276
|
+
// moved without parsing the message string. (No "latest" line — the npm
|
|
277
|
+
// update-notice is the single source of truth for the newest release.)
|
|
278
|
+
if (err.code === 'CLIENT_TOO_OLD') {
|
|
279
|
+
const your = err.getDetail('yourVersion');
|
|
280
|
+
const min = err.getDetail('minVersion');
|
|
281
|
+
if (typeof your === 'string' && typeof min === 'string') {
|
|
282
|
+
process.stderr.write(` your version: ${your}, minimum supported: ${min}\n`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// AMBIGUOUS_ORG: the same testId resolved inside more than one of the
|
|
286
|
+
// caller's organizations. List each colliding candidate plus a hint to
|
|
287
|
+
// disambiguate, mirroring the AUTH_FORBIDDEN required/granted pattern above.
|
|
288
|
+
if (err.code === 'AMBIGUOUS_ORG') {
|
|
289
|
+
for (const line of renderAmbiguousOrgCandidates(err.getDetail('candidates'))) {
|
|
290
|
+
process.stderr.write(`${line}\n`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
174
293
|
}
|
|
175
|
-
|
|
294
|
+
await flushThenExit(err.exitCode);
|
|
176
295
|
}
|
|
177
296
|
const output = new Output(mode);
|
|
297
|
+
if (err instanceof InterruptError) {
|
|
298
|
+
// Graceful detach (DEV-331 piece 1, errors.md §8.1): the wait-path catch
|
|
299
|
+
// block already printed the honest partial + re-attach hint. Exit with
|
|
300
|
+
// the conventional 128+signum code; `INTERRUPTED` is deliberately outside
|
|
301
|
+
// the error catalog. Note: Ctrl-C does NOT cancel the server-side run.
|
|
302
|
+
if (mode === 'json') {
|
|
303
|
+
const envelope = {
|
|
304
|
+
error: {
|
|
305
|
+
code: 'INTERRUPTED',
|
|
306
|
+
message: err.message,
|
|
307
|
+
nextAction: 'The server-side run (if any) keeps executing and billing. ' +
|
|
308
|
+
'Re-attach with: testsprite test wait <runId>, or stop it with: testsprite test cancel <runId> ' +
|
|
309
|
+
'(runId is in the partial JSON on stdout).',
|
|
310
|
+
requestId: 'local',
|
|
311
|
+
details: { signal: err.signal },
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
process.stderr.write(`${JSON.stringify(envelope, null, 2)}\n`);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
318
|
+
}
|
|
319
|
+
await flushThenExit(err.exitCode);
|
|
320
|
+
}
|
|
178
321
|
if (err instanceof RequestTimeoutError) {
|
|
179
322
|
// Structured rendering for per-request timeouts: JSON mode emits a
|
|
180
323
|
// machine-readable envelope; text mode emits the message with a hint.
|
|
@@ -194,7 +337,7 @@ catch (err) {
|
|
|
194
337
|
else {
|
|
195
338
|
process.stderr.write(`Error: ${err.message}\n`);
|
|
196
339
|
}
|
|
197
|
-
|
|
340
|
+
await flushThenExit(err.exitCode);
|
|
198
341
|
}
|
|
199
342
|
if (err instanceof CommanderError) {
|
|
200
343
|
// Map exit codes per the CLI taxonomy:
|
|
@@ -213,7 +356,7 @@ catch (err) {
|
|
|
213
356
|
if (err.code === 'commander.helpDisplayed' ||
|
|
214
357
|
err.code === 'commander.help' ||
|
|
215
358
|
err.code === 'commander.version') {
|
|
216
|
-
|
|
359
|
+
await flushThenExit(0);
|
|
217
360
|
}
|
|
218
361
|
// For parse errors, write the buffered message in the correct format.
|
|
219
362
|
// rawMode from program.opts() is reliable when --output was parsed before
|
|
@@ -233,13 +376,13 @@ catch (err) {
|
|
|
233
376
|
return mode;
|
|
234
377
|
})();
|
|
235
378
|
process.stderr.write(renderCommanderError(pendingCommanderErrorMsg, err.message, commanderMode));
|
|
236
|
-
|
|
379
|
+
await flushThenExit(5);
|
|
237
380
|
}
|
|
238
381
|
if (err instanceof CLIError) {
|
|
239
382
|
output.error(err.message);
|
|
240
|
-
|
|
383
|
+
await flushThenExit(err.exitCode);
|
|
241
384
|
}
|
|
242
385
|
output.error(err instanceof Error ? err.message : String(err));
|
|
243
|
-
|
|
386
|
+
await flushThenExit(1);
|
|
244
387
|
}
|
|
245
388
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface OpenInBrowserDeps {
|
|
2
|
+
platform?: NodeJS.Platform;
|
|
3
|
+
/** Process spawner taking an argv array. Defaults to a detached spawn. */
|
|
4
|
+
exec?: (command: string, args: readonly string[]) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function openInBrowser(url: string, deps?: OpenInBrowserDeps): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-platform "open this URL in the default browser" helper for
|
|
3
|
+
* `test open` (issue #121). Spawns the platform opener with an argv array
|
|
4
|
+
* (never a shell string) so a URL can never be shell-injected, and refuses
|
|
5
|
+
* anything that is not http(s) before any process is spawned.
|
|
6
|
+
*
|
|
7
|
+
* Platform openers:
|
|
8
|
+
* darwin open <url>
|
|
9
|
+
* win32 rundll32 url.dll,FileProtocolHandler <url> (avoids `cmd /c start`,
|
|
10
|
+
* whose re-parsing would mangle `&` and other metachars in the URL)
|
|
11
|
+
* other xdg-open <url>
|
|
12
|
+
*
|
|
13
|
+
* The child is detached and unref'd so the CLI exits immediately; failures
|
|
14
|
+
* are the caller's to surface (it already printed the URL as the fallback).
|
|
15
|
+
*/
|
|
16
|
+
import { spawn } from 'node:child_process';
|
|
17
|
+
import { localValidationError } from './errors.js';
|
|
18
|
+
export function openInBrowser(url, deps = {}) {
|
|
19
|
+
let parsed;
|
|
20
|
+
try {
|
|
21
|
+
parsed = new URL(url);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw localValidationError('url', 'must be a valid http(s) URL', undefined, 'field');
|
|
25
|
+
}
|
|
26
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
27
|
+
// User-input error, not an internal failure: classify as VALIDATION_ERROR
|
|
28
|
+
// so it maps to exit 5 (like every other bad-argument path), not exit 1.
|
|
29
|
+
throw localValidationError('url', `must be an http(s) URL (got ${parsed.protocol})`, undefined, 'field');
|
|
30
|
+
}
|
|
31
|
+
const platform = deps.platform ?? process.platform;
|
|
32
|
+
const exec = deps.exec ??
|
|
33
|
+
((command, args) => {
|
|
34
|
+
const child = spawn(command, [...args], { detached: true, stdio: 'ignore' });
|
|
35
|
+
// spawn() reports a missing binary (ENOENT) ASYNCHRONOUSLY on the child,
|
|
36
|
+
// so the caller's try/catch cannot see it — and an unhandled 'error'
|
|
37
|
+
// event would crash the whole CLI. The URL is already on stdout, so
|
|
38
|
+
// degrade to the same manual-open hint the sync failure path prints.
|
|
39
|
+
child.on('error', () => {
|
|
40
|
+
process.stderr.write('could not launch a browser; open the URL above manually (or use --no-browser)\n');
|
|
41
|
+
});
|
|
42
|
+
child.unref();
|
|
43
|
+
});
|
|
44
|
+
if (platform === 'darwin') {
|
|
45
|
+
exec('open', [url]);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (platform === 'win32') {
|
|
49
|
+
exec('rundll32', ['url.dll,FileProtocolHandler', url]);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
exec('xdg-open', [url]);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=browser.js.map
|
package/dist/lib/bundle.d.ts
CHANGED
|
@@ -137,6 +137,15 @@ export declare function resolveBundleDir(rawPath: string): string;
|
|
|
137
137
|
* language, not the user-app code under test.
|
|
138
138
|
*/
|
|
139
139
|
export declare function pickCodeExtension(language: string, framework: string): string;
|
|
140
|
+
/**
|
|
141
|
+
* Pick the on-disk extension for `<dir>/video.<ext>` from the actual
|
|
142
|
+
* `result.videoUrl`, instead of hardcoding `mp4` (the
|
|
143
|
+
* recording is sometimes a `.webm` container; saving it under a `video.mp4`
|
|
144
|
+
* name misleads strict-extension consumers). Falls back to `mp4` when the
|
|
145
|
+
* URL is malformed or its extension isn't a recognized container, so a
|
|
146
|
+
* response-controlled field can never smuggle an arbitrary suffix onto disk.
|
|
147
|
+
*/
|
|
148
|
+
export declare function pickVideoExtension(url: string): string;
|
|
140
149
|
/**
|
|
141
150
|
* Step filename per §7.2 — 1-based index, zero-padded to two digits
|
|
142
151
|
* for indices ≤ 99, three digits for ≥ 100. `${stepIndex}-snapshot.html`
|
|
@@ -163,8 +172,9 @@ export declare function buildMeta(ctx: CliFailureContext, fetchedAt?: Date): Bun
|
|
|
163
172
|
* 2. `applyFailedOnly` — narrow before download (saves bytes).
|
|
164
173
|
* 3. `mkdir <dir>/.tmp/` — fresh; clean any stale temp.
|
|
165
174
|
* 4. `writeFile result.json / failure.json / code.<ext>` — local data.
|
|
166
|
-
* 5. `fetch + stream` for `video
|
|
167
|
-
* snapshot/screenshot/
|
|
175
|
+
* 5. `fetch + stream` for `video.<ext>` (when set; extension matches the
|
|
176
|
+
* actual recording container) and per-step snapshot/screenshot/
|
|
177
|
+
* evidence-json files.
|
|
168
178
|
* 6. `writeFile meta.json` LAST — its presence means "bundle complete".
|
|
169
179
|
* 7. `rename .tmp/<file> -> <file>` for every file. Last rename
|
|
170
180
|
* makes meta.json visible.
|
|
@@ -174,40 +184,31 @@ export declare function buildMeta(ctx: CliFailureContext, fetchedAt?: Date): Bun
|
|
|
174
184
|
* → 10 by default; the original ApiError is preserved when applicable).
|
|
175
185
|
*/
|
|
176
186
|
export declare function writeBundle(ctx: CliFailureContext, options: WriteBundleOptions): Promise<WriteBundleResult>;
|
|
177
|
-
/**
|
|
178
|
-
* Rename `<tmp>/<file>` → `<dir>/<file>` for every file in `files`.
|
|
179
|
-
*
|
|
180
|
-
* Critical ordering for atomicity (the §3 "agent-safe" contract):
|
|
181
|
-
*
|
|
182
|
-
* 1. **Remove the OLD `meta.json` first.** The bundle's completion
|
|
183
|
-
* signal is `meta.json`'s presence; an agent reading `<dir>` while
|
|
184
|
-
* we're mutating it must see "no meta → bundle absent or
|
|
185
|
-
* mid-write" rather than "meta points at a snapshot that's already
|
|
186
|
-
* been partially overwritten." Removing the old meta is what
|
|
187
|
-
* makes the rest of the swap safe to do in place.
|
|
188
|
-
* 2. Wipe stale top-level files (e.g. an old `video.mp4` when the new
|
|
189
|
-
* bundle has no video). Without this, a fresh bundle could ship
|
|
190
|
-
* with a stale video lingering at the top level.
|
|
191
|
-
* 3. Replace `<dir>/steps/` wholesale.
|
|
192
|
-
* 4. Rename top-level files into place.
|
|
193
|
-
* 5. **Rename `meta.json` LAST.** Its visible presence is the atomic
|
|
194
|
-
* completion signal; until step 5 lands, agents see "incomplete."
|
|
195
|
-
*
|
|
196
|
-
* The window between (1) and (5) is bounded by a handful of `rename`
|
|
197
|
-
* syscalls — small enough that a SIGKILL there is rare, and any agent
|
|
198
|
-
* caught reading the dir during it sees no meta and refuses to consume
|
|
199
|
-
* (per §7.3). That's what we want.
|
|
200
|
-
*/
|
|
201
187
|
/**
|
|
202
188
|
* Whether a top-level directory entry belongs to the bundle format —
|
|
203
189
|
* i.e. something a prior `writeBundle` could have produced and this
|
|
204
|
-
* commit is therefore allowed to clean up. `code.<ext>`
|
|
205
|
-
* pattern (not the current run's extension) so a stale
|
|
206
|
-
* still swept when the new bundle writes
|
|
207
|
-
*
|
|
208
|
-
*
|
|
190
|
+
* commit is therefore allowed to clean up. `code.<ext>` and `video.<ext>`
|
|
191
|
+
* are matched by pattern (not the current run's extension) so a stale
|
|
192
|
+
* `code.py` or `video.webm` is still swept when the new bundle writes
|
|
193
|
+
* `code.ts` / `video.mp4` (or no video at all). Everything else in the
|
|
194
|
+
* directory is the user's and must never be deleted (`--out` can point at
|
|
195
|
+
* a pre-existing, populated directory).
|
|
209
196
|
*/
|
|
210
197
|
export declare function isBundleOwnedEntry(entry: string): boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Atomically install the complete bundle staged in `tmpDir` into `dir`.
|
|
200
|
+
*
|
|
201
|
+
* Compatible with the #162 data-loss guard: only `isBundleOwnedEntry`
|
|
202
|
+
* names are moved aside or replaced — foreign files in `--out` survive.
|
|
203
|
+
*
|
|
204
|
+
* Re-commit safety: bundle-owned entries are renamed to a sibling
|
|
205
|
+
* aside directory before the new artifacts land. The prior `meta.json`
|
|
206
|
+
* is moved aside first (§3/§7.3 — no meta ⇒ refuse to consume) so a
|
|
207
|
+
* concurrent reader never sees meta pointing at steps already gone.
|
|
208
|
+
* The new `meta.json` is installed last. On failure, aside entries are
|
|
209
|
+
* restored so a failed re-commit never leaves the directory unusable.
|
|
210
|
+
*/
|
|
211
|
+
export declare function commitBundle(tmpDir: string, dir: string, files: ReadonlyArray<string>): Promise<void>;
|
|
211
212
|
/**
|
|
212
213
|
* Stream a presigned URL into a file with bounded retry on transport
|
|
213
214
|
* failures. 4xx (presigned URL expired or unauthorized) is NOT
|