mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-13 08:15:14 +02:00
fix(cli): classify ktx setup abandonment as aborted, not a blank error (#278)
* fix(cli): classify ktx setup abandonment as aborted, not a blank error ktx setup returned a non-zero exit code without throwing when a user abandoned the interactive wizard, so the command telemetry recorded outcome=error with no errorClass/errorDetail — an unactionable blank in the errors dashboard, where most ktx setup "errors" were really people backing out of the wizard. Add annotateCommandOutcome() to the command span so the setup flow (the decision-maker) records the true outcome: genuine step failures and --no-input missing input become outcome=error with a self-diagnosing reason, while interactive abandonment and project cancellation become outcome=aborted and drop out of the error view. Unify the exit code and telemetry through setupTerminalOutcome() so they can never diverge: aborts now exit 0 (matching the entry-menu Exit, project cancel, and a confirmed Ctrl+C), while failures and automation errors still exit 1. * fix(cli): treat non-TTY setup missing-input as an error, not an abort setupTerminalOutcome classified `missing-input` by `args.inputMode`, but `auto` only means "interactive if a TTY is attached". A piped/CI `ktx setup` without `--no-input` and without `--yes` is still `auto`, yet the project and agents steps return `missing-input` there without ever prompting (e.g. "pass --yes to create a project outside an interactive terminal"). Classifying that as `aborted` made a broken automation run exit 0 — a silent failure. Key the classification off actual interactivity instead: input enabled AND `io.stdout.isTTY === true`. Non-interactive missing-input now exits 1 with a `KtxSetupMissingInput` reason; only a genuine interactive abort exits 0. Adds a non-TTY regression test and fixes the abandonment test to use a real TTY.
This commit is contained in:
parent
66517fc320
commit
470802e58e
6 changed files with 493 additions and 14 deletions
|
|
@ -135,6 +135,57 @@ describe('runCommanderKtxCli telemetry', () => {
|
|||
expect(io.stderr()).not.toContain(missingProjectDir);
|
||||
});
|
||||
|
||||
it('emits aborted (not error) when setup exits non-zero after the user abandons the wizard', async () => {
|
||||
const io = makeIo(true);
|
||||
const deps: KtxCliDeps = {
|
||||
setup: async () => {
|
||||
// What runKtxSetup does when an interactive step is abandoned: it
|
||||
// annotates the span and returns a non-zero exit code without throwing.
|
||||
const { annotateCommandOutcome } = await import('../src/telemetry/index.js');
|
||||
annotateCommandOutcome({ outcome: 'aborted' });
|
||||
return 1;
|
||||
},
|
||||
};
|
||||
|
||||
await expect(
|
||||
runCommanderKtxCli(['--project-dir', tempDir, 'setup'], io.io, deps, info, { runInit: async () => 0 }),
|
||||
).resolves.toBe(1);
|
||||
|
||||
expect(io.stderr()).toContain('"event":"command"');
|
||||
expect(io.stderr()).toContain('"commandPath":["ktx","setup"]');
|
||||
// The non-zero exit alone would have produced a blank "error"; the
|
||||
// annotation reclassifies it as a user abort that leaves the error view.
|
||||
expect(io.stderr()).toContain('"outcome":"aborted"');
|
||||
expect(io.stderr()).not.toContain('"outcome":"error"');
|
||||
expect(reportExceptionMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('emits a self-diagnosing error reason when a setup step genuinely fails without throwing', async () => {
|
||||
const io = makeIo(true);
|
||||
const deps: KtxCliDeps = {
|
||||
setup: async () => {
|
||||
const { annotateCommandOutcome } = await import('../src/telemetry/index.js');
|
||||
annotateCommandOutcome({
|
||||
outcome: 'error',
|
||||
errorClass: 'KtxSetupStepFailed',
|
||||
errorDetail: 'runtime setup step failed',
|
||||
});
|
||||
return 1;
|
||||
},
|
||||
};
|
||||
|
||||
await expect(
|
||||
runCommanderKtxCli(['--project-dir', tempDir, 'setup'], io.io, deps, info, { runInit: async () => 0 }),
|
||||
).resolves.toBe(1);
|
||||
|
||||
expect(io.stderr()).toContain('"outcome":"error"');
|
||||
expect(io.stderr()).toContain('"errorClass":"KtxSetupStepFailed"');
|
||||
expect(io.stderr()).toContain('"errorDetail":"runtime setup step failed"');
|
||||
// Non-throwing failures have no exception twin; the command event carries
|
||||
// the reason on its own.
|
||||
expect(reportExceptionMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not import or emit telemetry for help, version, bare non-TTY, or unknown top-level command', async () => {
|
||||
const helpIo = makeIo(true);
|
||||
await expect(runCommanderKtxCli(['--help'], helpIo.io, {}, info, { runInit: async () => 0 })).resolves.toBe(0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue