@@ -1197,6 +1197,101 @@ describe('interactive prompts lead to the correct function calls', () => {
11971197 } ) ;
11981198} ) ;
11991199
1200+ describe ( 'CLI context parameters' , ( ) => {
1201+ beforeEach ( ( ) => {
1202+ setupMockToolkitForPrototyping ( mockToolkit ) ;
1203+ jest . clearAllMocks ( ) ;
1204+ } ) ;
1205+
1206+ test ( 'CLI context values are merged with file context during prototyping' , async ( ) => {
1207+ const cdkJsonPath = await createCdkJsonFile ( {
1208+ '@aws-cdk/core:existingFlag' : true ,
1209+ } ) ;
1210+
1211+ setupMockToolkitForPrototyping ( mockToolkit ) ;
1212+
1213+ const requestResponseSpy = jest . spyOn ( ioHelper , 'requestResponse' ) ;
1214+ requestResponseSpy . mockResolvedValue ( false ) ;
1215+
1216+ const cliContextValues = {
1217+ foo : 'bar' ,
1218+ myContextParam : 'myValue' ,
1219+ } ;
1220+
1221+ const options : FlagsOptions = {
1222+ FLAGNAME : [ '@aws-cdk/core:testFlag' ] ,
1223+ set : true ,
1224+ value : 'true' ,
1225+ } ;
1226+
1227+ const flagOperations = new FlagCommandHandler ( mockFlagsData , ioHelper , options , mockToolkit , cliContextValues ) ;
1228+ await flagOperations . processFlagsCommand ( ) ;
1229+
1230+ // Get the first call's context store and verify it contains merged context
1231+ // fromCdkApp(app, { contextStore: ..., outdir: ... }) was called
1232+ const firstCallArgs = mockToolkit . fromCdkApp . mock . calls [ 0 ] ; // Get first call arguments
1233+ const contextStore = firstCallArgs [ 1 ] ?. contextStore ; // Extract contextStore from second argument (options object)
1234+ expect ( contextStore ) . toBeDefined ( ) ;
1235+
1236+ // contextStore is defined as we've verified above
1237+ const contextData = await contextStore ! . read ( ) ;
1238+
1239+ expect ( contextData ) . toEqual ( {
1240+ '@aws-cdk/core:existingFlag' : true ,
1241+ '@aws-cdk/core:testFlag' : true ,
1242+ 'foo' : 'bar' ,
1243+ 'myContextParam' : 'myValue' ,
1244+ } ) ;
1245+
1246+ await cleanupCdkJsonFile ( cdkJsonPath ) ;
1247+ requestResponseSpy . mockRestore ( ) ;
1248+ } ) ;
1249+
1250+ test ( 'CLI context values are passed to synthesis during safe flag checking' , async ( ) => {
1251+ const cdkJsonPath = await createCdkJsonFile ( {
1252+ '@aws-cdk/core:existingFlag' : true ,
1253+ } ) ;
1254+
1255+ mockToolkit . diff . mockResolvedValue ( {
1256+ TestStack : { differenceCount : 0 } as any ,
1257+ } ) ;
1258+
1259+ const requestResponseSpy = jest . spyOn ( ioHelper , 'requestResponse' ) ;
1260+ requestResponseSpy . mockResolvedValue ( false ) ;
1261+
1262+ const cliContextValues = {
1263+ foo : 'bar' ,
1264+ myContextParam : 'myValue' ,
1265+ } ;
1266+
1267+ const options : FlagsOptions = {
1268+ safe : true ,
1269+ concurrency : 4 ,
1270+ } ;
1271+
1272+ const flagOperations = new FlagCommandHandler ( mockFlagsData , ioHelper , options , mockToolkit , cliContextValues ) ;
1273+ await flagOperations . processFlagsCommand ( ) ;
1274+
1275+ // Get the first call's context store and verify it contains merged context
1276+ // fromCdkApp(app, { contextStore: ..., outdir: ... }) was called
1277+ const firstCallArgs = mockToolkit . fromCdkApp . mock . calls [ 0 ] ; // Get first call arguments
1278+ const contextStore = firstCallArgs [ 1 ] ?. contextStore ; // Extract contextStore from second argument (options object)
1279+ expect ( contextStore ) . toBeDefined ( ) ;
1280+
1281+ // contextStore is defined as we've verified above
1282+ const contextData = await contextStore ! . read ( ) ;
1283+
1284+ expect ( contextData ) . toEqual ( {
1285+ '@aws-cdk/core:existingFlag' : true ,
1286+ 'foo' : 'bar' ,
1287+ 'myContextParam' : 'myValue' ,
1288+ } ) ;
1289+
1290+ await cleanupCdkJsonFile ( cdkJsonPath ) ;
1291+ requestResponseSpy . mockRestore ( ) ;
1292+ } ) ;
1293+ } ) ;
1294+
12001295describe ( 'setSafeFlags' , ( ) => {
12011296 beforeEach ( ( ) => {
12021297 setupMockToolkitForPrototyping ( mockToolkit ) ;
@@ -1390,7 +1485,13 @@ async function displayFlags(params: FlagOperationsParams): Promise<void> {
13901485 await f . displayFlags ( params ) ;
13911486}
13921487
1393- async function handleFlags ( flagData : FeatureFlag [ ] , _ioHelper : IoHelper , options : FlagsOptions , toolkit : Toolkit ) {
1394- const f = new FlagCommandHandler ( flagData , _ioHelper , options , toolkit ) ;
1488+ async function handleFlags (
1489+ flagData : FeatureFlag [ ] ,
1490+ _ioHelper : IoHelper ,
1491+ options : FlagsOptions ,
1492+ toolkit : Toolkit ,
1493+ cliContextValues : Record < string , any > = { } ,
1494+ ) {
1495+ const f = new FlagCommandHandler ( flagData , _ioHelper , options , toolkit , cliContextValues ) ;
13951496 await f . processFlagsCommand ( ) ;
13961497}
0 commit comments