fix(cli): 统一 full raw 输入错误输出

This commit is contained in:
Codex
2026-07-12 02:19:35 +02:00
parent bcc7807c3d
commit 3704777b12
2 changed files with 32 additions and 4 deletions
+29 -1
View File
@@ -15,7 +15,12 @@ describe("CLI input error hierarchy", () => {
});
test("explicit machine output returns a JSON input-error envelope without a stack", () => {
for (const args of [["definitely-not-a-command", "--json"], ["definitely-not-a-command", "-o", "json"]]) {
for (const args of [
["definitely-not-a-command", "--json"],
["definitely-not-a-command", "--full"],
["definitely-not-a-command", "--raw"],
["definitely-not-a-command", "-o", "json"],
]) {
const result = runCli(...args);
expect(result.status).toBe(1);
expect(result.stderr).toBe("");
@@ -30,6 +35,11 @@ describe("CLI input error hierarchy", () => {
expect(payload.error.stack).toBeUndefined();
expect(result.stdout).not.toContain("stackOmitted");
}
const nonJsonOutput = runCli("definitely-not-a-command", "-o", "yaml");
expect(nonJsonOutput.status).toBe(1);
expect(nonJsonOutput.stdout).toContain("ERROR cli-input/unknown-command");
expect(() => JSON.parse(nonJsonOutput.stdout)).toThrow();
});
test("predictable Gitea option validation is compact and stack-free", () => {
@@ -43,6 +53,24 @@ describe("CLI input error hierarchy", () => {
expect(result.stdout).not.toContain("platform-infra-gitea.ts:");
});
test("Gitea full and raw input errors preserve machine JSON without a stack", () => {
for (const outputFlag of ["--full", "--raw"]) {
const result = runCli("platform-infra", "gitea", "status", "--target", "NC01", outputFlag, "--definitely-unsupported");
expect(result.status).toBe(1);
expect(result.stderr).toBe("");
const payload = JSON.parse(result.stdout) as {
ok: boolean;
error: { kind: string; code: string; argument: string; debug: boolean; stack?: string };
};
expect(payload.ok).toBe(false);
expect(payload.error.kind).toBe("cli-input");
expect(payload.error.code).toBe("unsupported-option");
expect(payload.error.argument).toBe("--definitely-unsupported");
expect(payload.error.debug).toBe(false);
expect(payload.error.stack).toBeUndefined();
}
});
test("only an explicitly unknown command target is converted to a compact input error", () => {
const unknownTarget = runCli("platform-infra", "gitea", "status", "--target", "definitely-nope");
expect(unknownTarget.status).toBe(1);