fix(cli): redact machine-readable CLI error payloads (#124075)

This commit is contained in:
Peter Steinberger
2026-08-15 00:44:18 -07:00
committed by GitHub
parent f2c721b0ac
commit 49e1ea2c9f
19 changed files with 189 additions and 64 deletions
+26 -3
View File
@@ -95,14 +95,14 @@ describe("system-cli", () => {
name: "invalid wake mode",
args: ["system", "event", "--text", "hello", "--mode", "later", "--json"],
gatewayResult: undefined,
expectedError: "Error: --mode must be now or next-heartbeat",
expectedError: "--mode must be now or next-heartbeat",
gatewayCalls: 0,
},
{
name: "rejected Gateway call",
args: ["system", "event", "--text", "hello", "--json"],
gatewayResult: { ok: false, reason: "unwakeable-session-key" },
expectedError: "Error: unwakeable-session-key",
expectedError: "unwakeable-session-key",
gatewayCalls: 1,
},
])(
@@ -122,6 +122,29 @@ describe("system-cli", () => {
},
);
it.each([
{ mode: "human", args: ["system", "event", "--text", "hello"] },
{ mode: "JSON", args: ["system", "event", "--text", "hello", "--json"] },
])("renders named errors without class names in $mode mode", async ({ mode, args }) => {
const error = new Error("Multiple agents are configured, but this operation has no owner.");
error.name = "AgentSelectionRequiredError";
callGatewayFromCli.mockRejectedValueOnce(error);
await runCli(args);
if (mode === "JSON") {
const payload = JSON.parse(runtimeLogs.at(-1) ?? "");
expect(payload).toEqual({ error: error.message });
expect(Object.keys(payload)).toEqual(["error"]);
expect(runtimeErrors).toEqual([]);
} else {
expect(runtimeErrors).toEqual([error.message]);
expect(defaultRuntime.writeJson).not.toHaveBeenCalled();
}
expect([...runtimeLogs, ...runtimeErrors].join("\n")).not.toContain(error.name);
expect(defaultRuntime.exit).toHaveBeenCalledWith(1);
});
it("forwards --session-key on system event", async () => {
await runCli([
"system",
@@ -171,7 +194,7 @@ describe("system-cli", () => {
expect(typeof gatewayOptions).toBe("object");
expect(params).toBeUndefined();
expect(requestOptions).toEqual({ expectFinal: false });
const expectedError = "Error: Gateway unavailable";
const expectedError = "Gateway unavailable";
expect(runtimeLogs).toEqual([JSON.stringify({ error: expectedError }, null, 2)]);
expect(runtimeErrors).toEqual([]);
expect(defaultRuntime.writeJson).toHaveBeenCalledWith({ error: expectedError });