fix(cli): fail commands returning projected analysis errors (#506)
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,15 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { ConfigurationError, projectAnalysisError } from "./domain/errors.js";
|
||||||
|
|
||||||
import { isCliOperationFailure } from "./cliLogging.js";
|
import { isCliOperationFailure } from "./cliLogging.js";
|
||||||
|
|
||||||
describe("CLI operation status classification", () => {
|
describe("CLI operation status classification", () => {
|
||||||
it.each([
|
it.each([
|
||||||
|
[
|
||||||
|
"projected error",
|
||||||
|
projectAnalysisError(new ConfigurationError("invalid setting")),
|
||||||
|
],
|
||||||
["typed error", { error: "Analysis failed", category: "timeout" }],
|
["typed error", { error: "Analysis failed", category: "timeout" }],
|
||||||
["unhealthy diagnostic", { healthy: false, checks: [] }],
|
["unhealthy diagnostic", { healthy: false, checks: [] }],
|
||||||
["failed status", { status: "failed" }],
|
["failed status", { status: "failed" }],
|
||||||
@@ -15,6 +21,16 @@ describe("CLI operation status classification", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
|
[
|
||||||
|
"ordinary data with code",
|
||||||
|
{ code: "configuration_invalid", message: "source data" },
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"evidence about an error",
|
||||||
|
{
|
||||||
|
result: projectAnalysisError(new ConfigurationError("source setting")),
|
||||||
|
},
|
||||||
|
],
|
||||||
["ready setup", { status: "ready" }],
|
["ready setup", { status: "ready" }],
|
||||||
["complete uninstall", { status: "complete" }],
|
["complete uninstall", { status: "complete" }],
|
||||||
["current version", { status: "current" }],
|
["current version", { status: "current" }],
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { analysisErrorProjectionSchema } from "./contracts/errorSchemas.js";
|
||||||
import type { Logger } from "./logger.js";
|
import type { Logger } from "./logger.js";
|
||||||
|
|
||||||
const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
|
const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
|
||||||
@@ -7,6 +8,7 @@ const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
|
|||||||
export const isCliOperationFailure = (value: unknown): boolean => {
|
export const isCliOperationFailure = (value: unknown): boolean => {
|
||||||
if (!isRecord(value)) return false;
|
if (!isRecord(value)) return false;
|
||||||
if (typeof value.error === "string") return true;
|
if (typeof value.error === "string") return true;
|
||||||
|
if (analysisErrorProjectionSchema.safeParse(value).success) return true;
|
||||||
if (value.healthy === false) return true;
|
if (value.healthy === false) return true;
|
||||||
return (
|
return (
|
||||||
value.status === "failed" ||
|
value.status === "failed" ||
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { describe, expect } from "vitest";
|
||||||
|
|
||||||
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||||
|
|
||||||
|
describe("projected CLI failures", () => {
|
||||||
|
cliTest(
|
||||||
|
"exits unsuccessfully for invalid replay configuration",
|
||||||
|
async ({ cli }) => {
|
||||||
|
const result = await cli.run({
|
||||||
|
arguments: ["run-controlled-replay", "{}", "--json"],
|
||||||
|
environment: { REA_JAVASCRIPT_REPLAY_ENABLED: "not-a-bool" },
|
||||||
|
});
|
||||||
|
expect(result.json).toMatchObject({
|
||||||
|
code: "configuration_invalid",
|
||||||
|
category: "execution_failure",
|
||||||
|
retryable: false,
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
cliTest(
|
||||||
|
"exits unsuccessfully for invalid managed reconstruction input",
|
||||||
|
async ({ cli }) => {
|
||||||
|
const result = await cli.run({
|
||||||
|
arguments: ["import-managed-reconstruction", "{}", "--json"],
|
||||||
|
});
|
||||||
|
expect(result.json).toMatchObject({ code: "invalid_request" });
|
||||||
|
expect(result.exitCode).toBe(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
cliTest(
|
||||||
|
"keeps successful target-free inventory commands successful",
|
||||||
|
async ({ cli }) => {
|
||||||
|
const result = await cli.run({ arguments: ["capabilities", "--json"] });
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.json).toBeDefined();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user