Skip to content

Commit 5996013

Browse files
committed
fix(audit): keep cursor errors operator-facing
1 parent dca2b96 commit 5996013

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎src/commands/audit.test.ts‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AUDIT_ACTIVITY_KINDS,
55
AUDIT_ACTIVITY_STATUSES,
66
} from "../../packages/gateway-protocol/src/schema/audit-activity.js";
7+
import { runCommandWithRuntime } from "../cli/cli-utils.js";
78
import type { RuntimeEnv } from "../runtime.js";
89
import { auditListCommand } from "./audit.js";
910

@@ -195,6 +196,8 @@ describe("audit command gateway compatibility", () => {
195196
beforeEach(() => {
196197
callGateway.mockReset();
197198
callGateway.mockResolvedValue({ events: [] });
199+
vi.mocked(runtime.error).mockClear();
200+
vi.mocked(runtime.exit).mockClear();
198201
});
199202

200203
it("forwards all filters to audit.activity.list", async () => {
@@ -316,13 +319,13 @@ describe("audit command gateway compatibility", () => {
316319
});
317320
callGateway.mockRejectedValueOnce(error);
318321

319-
const rejection = await auditListCommand({ limit: "10" }, runtime).catch(
320-
(caught: unknown) => caught,
321-
);
322+
await runCommandWithRuntime(runtime, () => auditListCommand({ limit: "10" }, runtime));
322323

323-
expect(rejection).toBeInstanceOf(Error);
324-
expect(String(rejection)).toBe("Error: invalid audit activity params");
325-
expect(String(rejection)).not.toContain("GatewayClientRequestError");
324+
expect(runtime.error).toHaveBeenCalledWith("Error: invalid audit activity params");
325+
expect(String(vi.mocked(runtime.error).mock.calls[0]?.[0])).not.toContain(
326+
"GatewayClientRequestError",
327+
);
328+
expect(runtime.exit).toHaveBeenCalledWith(1);
326329
expect(callGateway).toHaveBeenCalledTimes(1);
327330
});
328331

@@ -334,9 +337,15 @@ describe("audit command gateway compatibility", () => {
334337
}),
335338
);
336339

337-
await expect(auditListCommand({ cursor: "abc" }, runtime)).rejects.toThrow(
338-
"--cursor must be a continuation token returned by a previous audit result.",
340+
await runCommandWithRuntime(runtime, () => auditListCommand({ cursor: "abc" }, runtime));
341+
342+
expect(runtime.error).toHaveBeenCalledWith(
343+
"Error: --cursor must be a continuation token returned by a previous audit result.",
344+
);
345+
expect(String(vi.mocked(runtime.error).mock.calls[0]?.[0])).not.toContain(
346+
"audit.activity.list",
339347
);
348+
expect(runtime.exit).toHaveBeenCalledWith(1);
340349
});
341350
});
342351

‎src/commands/audit.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function formatAuditGatewayError(error: unknown): Error {
184184
message === "invalid audit.activity.list range or cursor"
185185
? "--cursor must be a continuation token returned by a previous audit result."
186186
: message;
187-
return new Error(operatorMessage, { cause: error });
187+
return new Error(operatorMessage);
188188
}
189189

190190
function toLegacyAuditListParams(params: AuditActivityListParams): AuditListParams {

0 commit comments

Comments
 (0)