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" ;
78import type { RuntimeEnv } from "../runtime.js" ;
89import { 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
0 commit comments