@@ -51,6 +51,14 @@ jest.mock('../../lib/cli/parse-command-line-arguments', () => ({
5151 if ( args . includes ( 'ts' ) ) {
5252 result = { ...result , language : 'typescript' } ;
5353 }
54+ } else if ( args . includes ( 'gc' ) ) {
55+ result = { ...result , _ : [ 'gc' ] } ;
56+
57+ // Handle role-arn flag for gc command validation testing
58+ // This simulates parser behavior to test that the CLI properly rejects roleArn
59+ if ( args . includes ( '--role-arn' ) ) {
60+ result = { ...result , roleArn : 'arn:aws:iam::123456789012:role/TestRole' } ;
61+ }
5462 }
5563
5664 // Handle notices flags
@@ -427,3 +435,49 @@ describe('notices configuration tests', () => {
427435 ) ;
428436 } ) ;
429437} ) ;
438+
439+ describe ( 'gc command tests' , ( ) => {
440+ let originalCliIoHostInstance : any ;
441+
442+ beforeEach ( ( ) => {
443+ jest . clearAllMocks ( ) ;
444+ originalCliIoHostInstance = CliIoHost . instance ;
445+ } ) ;
446+
447+ afterEach ( ( ) => {
448+ CliIoHost . instance = originalCliIoHostInstance ;
449+ } ) ;
450+
451+ test ( 'should warn when --role-arn is used with gc command' , async ( ) => {
452+ const gcSpy = jest . spyOn ( cdkToolkitModule . CdkToolkit . prototype , 'garbageCollect' ) . mockResolvedValue ( ) ;
453+
454+ // Make exec use our TestIoHost and adds properties to TestIoHost to match CliIoHost
455+ const warnSpy = jest . fn ( ) ;
456+ ( ioHost as any ) . defaults = { warn : warnSpy , debug : jest . fn ( ) , result : jest . fn ( ) } ;
457+ ( ioHost as any ) . asIoHelper = ( ) => ioHelper ;
458+ ( ioHost as any ) . logLevel = 'info' ;
459+ jest . spyOn ( CliIoHost , 'instance' ) . mockReturnValue ( ioHost as any ) ;
460+
461+ const mockConfig = {
462+ loadConfigFiles : jest . fn ( ) . mockResolvedValue ( undefined ) ,
463+ settings : {
464+ get : jest . fn ( ) . mockImplementation ( ( key : string [ ] ) => {
465+ if ( key [ 0 ] === 'unstable' ) return [ 'gc' ] ;
466+ return [ ] ;
467+ } ) ,
468+ } ,
469+ context : {
470+ get : jest . fn ( ) . mockReturnValue ( [ ] ) ,
471+ } ,
472+ } ;
473+
474+ Configuration . fromArgsAndFiles = jest . fn ( ) . mockResolvedValue ( mockConfig ) ;
475+
476+ await exec ( [ 'gc' , '--unstable=gc' , '--role-arn' , 'arn:aws:iam::123456789012:role/TestRole' ] ) ;
477+
478+ expect ( warnSpy ) . toHaveBeenCalledWith (
479+ 'The --role-arn option is not supported for the gc command and will be ignored.' ,
480+ ) ;
481+ expect ( gcSpy ) . toHaveBeenCalled ( ) ;
482+ } ) ;
483+ } ) ;
0 commit comments