From 232e45bee25c1d4706a06faa6fad0f6dd463249c Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 24 Dec 2025 00:00:25 +0900 Subject: [PATCH 1/8] fix(flags): flags commands do not forward context parameters to synth --- packages/aws-cdk/lib/cli/cli.ts | 2 +- packages/aws-cdk/lib/commands/flags/flags.ts | 10 +- .../aws-cdk/lib/commands/flags/operations.ts | 10 +- .../test/commands/flag-operations.test.ts | 148 +++++++++++++++++- 4 files changed, 161 insertions(+), 9 deletions(-) diff --git a/packages/aws-cdk/lib/cli/cli.ts b/packages/aws-cdk/lib/cli/cli.ts index cba6bc509..01ef7e138 100644 --- a/packages/aws-cdk/lib/cli/cli.ts +++ b/packages/aws-cdk/lib/cli/cli.ts @@ -498,7 +498,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise = {}, + ) { this.flags = flagData.filter(flag => !OBSOLETE_FLAGS.includes(flag.name)); this.options = { ...options, concurrency: options.concurrency ?? 4 }; this.ioHelper = ioHelper; const validator = new FlagValidator(ioHelper); - const flagOperations = new FlagOperations(this.flags, toolkit, ioHelper); + const flagOperations = new FlagOperations(this.flags, toolkit, ioHelper, cliContextValues); const interactiveHandler = new InteractiveHandler(this.flags, flagOperations); this.router = new FlagOperationRouter(validator, interactiveHandler, flagOperations); diff --git a/packages/aws-cdk/lib/commands/flags/operations.ts b/packages/aws-cdk/lib/commands/flags/operations.ts index 8ecef959c..d3d117027 100644 --- a/packages/aws-cdk/lib/commands/flags/operations.ts +++ b/packages/aws-cdk/lib/commands/flags/operations.ts @@ -48,6 +48,7 @@ export class FlagOperations { private readonly flags: FeatureFlag[], private readonly toolkit: Toolkit, private readonly ioHelper: IoHelper, + private readonly cliContextValues: Record = {}, ) { this.app = ''; this.baseContextValues = {}; @@ -159,11 +160,12 @@ export class FlagOperations { /** Initializes the safety check by reading context and synthesizing baseline templates */ private async initializeSafetyCheck(): Promise { const baseContext = new CdkAppMultiContext(process.cwd()); - this.baseContextValues = await baseContext.read(); + this.baseContextValues = { ...await baseContext.read(), ...this.cliContextValues }; this.baselineTempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cdk-baseline-')); + const mergedContext = new MemoryContext(this.baseContextValues); const baseSource = await this.toolkit.fromCdkApp(this.app, { - contextStore: baseContext, + contextStore: mergedContext, outdir: this.baselineTempDir, }); @@ -270,14 +272,14 @@ export class FlagOperations { /** Prototypes flag changes by synthesizing templates and showing diffs to the user */ private async prototypeChanges(flagNames: string[], params: FlagOperationsParams): Promise { const baseContext = new CdkAppMultiContext(process.cwd()); - const baseContextValues = await baseContext.read(); + const baseContextValues = { ...await baseContext.read(), ...this.cliContextValues }; const memoryContext = new MemoryContext(baseContextValues); const cdkJson = await JSON.parse(await fs.readFile(path.join(process.cwd(), 'cdk.json'), 'utf-8')); const app = cdkJson.app; const source = await this.toolkit.fromCdkApp(app, { - contextStore: baseContext, + contextStore: memoryContext, outdir: fs.mkdtempSync(path.join(os.tmpdir(), 'cdk-original-')), }); diff --git a/packages/aws-cdk/test/commands/flag-operations.test.ts b/packages/aws-cdk/test/commands/flag-operations.test.ts index 3bc5b99d2..ed6a1a740 100644 --- a/packages/aws-cdk/test/commands/flag-operations.test.ts +++ b/packages/aws-cdk/test/commands/flag-operations.test.ts @@ -1197,6 +1197,144 @@ describe('interactive prompts lead to the correct function calls', () => { }); }); +describe('CLI context parameters', () => { + beforeEach(() => { + setupMockToolkitForPrototyping(mockToolkit); + jest.clearAllMocks(); + }); + + test('CLI context values are merged with file context during prototyping', async () => { + const cdkJsonPath = await createCdkJsonFile({ + '@aws-cdk/core:existingFlag': true, + }); + + setupMockToolkitForPrototyping(mockToolkit); + + const requestResponseSpy = jest.spyOn(ioHelper, 'requestResponse'); + requestResponseSpy.mockResolvedValue(false); + + const cliContextValues = { + foo: 'bar', + myContextParam: 'myValue', + }; + + const options: FlagsOptions = { + FLAGNAME: ['@aws-cdk/core:testFlag'], + set: true, + value: 'true', + }; + + const flagOperations = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit, cliContextValues); + await flagOperations.processFlagsCommand(); + + // Verify that fromCdkApp was called with a context store + expect(mockToolkit.fromCdkApp).toHaveBeenCalledTimes(2); + + // Get the first call's context store + const firstCallArgs = mockToolkit.fromCdkApp.mock.calls[0]; + const contextStore = firstCallArgs[1]?.contextStore; + + // Verify the context store is a MemoryContext that contains both file and CLI context + expect(contextStore).toBeDefined(); + + await cleanupCdkJsonFile(cdkJsonPath); + requestResponseSpy.mockRestore(); + }); + + test('CLI context values are passed to synthesis during safe flag checking', async () => { + const cdkJsonPath = await createCdkJsonFile({}); + + mockToolkit.diff.mockResolvedValue({ + TestStack: { differenceCount: 0 } as any, + }); + + const requestResponseSpy = jest.spyOn(ioHelper, 'requestResponse'); + requestResponseSpy.mockResolvedValue(false); + + const cliContextValues = { + myCliParam: 'cliValue', + }; + + const options: FlagsOptions = { + safe: true, + concurrency: 4, + }; + + const flagOperations = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit, cliContextValues); + await flagOperations.processFlagsCommand(); + + // Verify that fromCdkApp was called during safe flag checking + expect(mockToolkit.fromCdkApp).toHaveBeenCalled(); + + await cleanupCdkJsonFile(cdkJsonPath); + requestResponseSpy.mockRestore(); + }); + + test('works correctly when no CLI context is provided', async () => { + const cdkJsonPath = await createCdkJsonFile({ + '@aws-cdk/core:existingFlag': false, + }); + + setupMockToolkitForPrototyping(mockToolkit); + + const requestResponseSpy = jest.spyOn(ioHelper, 'requestResponse'); + requestResponseSpy.mockResolvedValue(false); + + const options: FlagsOptions = { + FLAGNAME: ['@aws-cdk/core:testFlag'], + set: true, + value: 'true', + }; + + // Not passing cliContextValues (defaults to empty object) + const flagOperations = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit); + await flagOperations.processFlagsCommand(); + + expect(mockToolkit.fromCdkApp).toHaveBeenCalledTimes(2); + expect(mockToolkit.synth).toHaveBeenCalledTimes(2); + + await cleanupCdkJsonFile(cdkJsonPath); + requestResponseSpy.mockRestore(); + }); + + test('FlagCommandHandler constructor accepts CLI context values', () => { + const cliContextValues = { + myParam: 'myValue', + foo: 'bar', + }; + + const options: FlagsOptions = { + all: true, + }; + + // Verify that constructor accepts CLI context values parameter + const handler = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit, cliContextValues); + expect(handler).toBeDefined(); + }); + + test('FlagCommandHandler passes CLI context to FlagOperations', async () => { + const cdkJsonPath = await createCdkJsonFile({}); + + setupMockToolkitForPrototyping(mockToolkit); + + const cliContextValues = { + cliParam: 'cliValue', + }; + + const options: FlagsOptions = { + all: true, + }; + + const handler = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit, cliContextValues); + await handler.processFlagsCommand(); + + // Just verify it doesn't throw and completes successfully + expect(mockToolkit.fromCdkApp).not.toHaveBeenCalled(); // Display mode doesn't call synthesis + + await cleanupCdkJsonFile(cdkJsonPath); + }); +}); + describe('setSafeFlags', () => { beforeEach(() => { setupMockToolkitForPrototyping(mockToolkit); @@ -1390,7 +1528,13 @@ async function displayFlags(params: FlagOperationsParams): Promise { await f.displayFlags(params); } -async function handleFlags(flagData: FeatureFlag[], _ioHelper: IoHelper, options: FlagsOptions, toolkit: Toolkit) { - const f = new FlagCommandHandler(flagData, _ioHelper, options, toolkit); +async function handleFlags( + flagData: FeatureFlag[], + _ioHelper: IoHelper, + options: FlagsOptions, + toolkit: Toolkit, + cliContextValues: Record = {}, +) { + const f = new FlagCommandHandler(flagData, _ioHelper, options, toolkit, cliContextValues); await f.processFlagsCommand(); } From a58f867d6e8f218bac80d87cbb5beb86d186af37 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 24 Dec 2025 17:38:25 +0900 Subject: [PATCH 2/8] integ --- .../resources/cdk-apps/context-app/app.js | 21 ++++++++++++++++ .../resources/cdk-apps/context-app/cdk.json | 6 +++++ .../cdk-flags-with-cli-context.integtest.ts | 25 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/context-app/app.js create mode 100644 packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/context-app/cdk.json create mode 100644 packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/flags/cdk-flags-with-cli-context.integtest.ts diff --git a/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/context-app/app.js b/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/context-app/app.js new file mode 100644 index 000000000..54cf3ca92 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/context-app/app.js @@ -0,0 +1,21 @@ +const cdk = require('aws-cdk-lib'); + +const app = new cdk.App(); + +const contextValue = app.node.tryGetContext('myContextParam'); + +if (!contextValue) { + throw new Error('Context parameter "myContextParam" is required'); +} + +const stack = new cdk.Stack(app, 'TestStack', { + description: `Stack created with context value: ${contextValue}`, +}); + +// Add a simple resource +new cdk.CfnOutput(stack, 'ContextValue', { + value: contextValue, + description: 'The context value passed via CLI', +}); + +app.synth(); diff --git a/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/context-app/cdk.json b/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/context-app/cdk.json new file mode 100644 index 000000000..b291e31a9 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/context-app/cdk.json @@ -0,0 +1,6 @@ +{ + "app": "node app.js", + "context": { + "@aws-cdk/core:newStyleStackSynthesis": true + } +} diff --git a/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/flags/cdk-flags-with-cli-context.integtest.ts b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/flags/cdk-flags-with-cli-context.integtest.ts new file mode 100644 index 000000000..a1266e497 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/flags/cdk-flags-with-cli-context.integtest.ts @@ -0,0 +1,25 @@ +import { integTest, withAws, withSpecificCdkApp } from '../../../lib'; + +jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime + +integTest( + 'flags command works with CLI context parameters', + withAws( + withSpecificCdkApp('context-app', async (fixture) => { + await fixture.cdk(['bootstrap', '-c', 'myContextParam=testValue']); + + const output = await fixture.cdk([ + 'flags', + '--unstable=flags', + '--set', + '--recommended', + '--all', + '-c', 'myContextParam=testValue', + '--yes', + ]); + + expect(output).toContain('Flag changes:'); + }), + true, + ), +); From 63d03596473037e259175a82e3af3db2d21c16d8 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 24 Dec 2025 18:30:49 +0900 Subject: [PATCH 3/8] test --- packages/aws-cdk/test/cli/cli.test.ts | 77 +++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/packages/aws-cdk/test/cli/cli.test.ts b/packages/aws-cdk/test/cli/cli.test.ts index 7acbc533c..98d032443 100644 --- a/packages/aws-cdk/test/cli/cli.test.ts +++ b/packages/aws-cdk/test/cli/cli.test.ts @@ -4,6 +4,7 @@ import { exec } from '../../lib/cli/cli'; import { CliIoHost } from '../../lib/cli/io-host'; import { Configuration } from '../../lib/cli/user-configuration'; import { TestIoHost } from '../_helpers/io-host'; +import { Toolkit } from '@aws-cdk/toolkit-lib'; // Store original version module exports so we don't conflict with other tests const originalVersion = jest.requireActual('../../lib/cli/version'); @@ -65,6 +66,8 @@ jest.mock('../../lib/cli/parse-command-line-arguments', () => ({ _: ['deploy'], parameters: [], }; + } else if (args.includes('flags')) { + result = { ...result, _: ['flags'] }; } // Handle notices flags @@ -93,6 +96,22 @@ jest.mock('../../lib/cli/parse-command-line-arguments', () => ({ }), })); +// Mock FlagCommandHandler to capture constructor calls +const mockFlagCommandHandlerConstructor = jest.fn(); +const mockProcessFlagsCommand = jest.fn().mockResolvedValue(undefined); + +jest.mock('../../lib/commands/flags/flags', () => { + return { + FlagCommandHandler: jest.fn().mockImplementation((...args) => { + mockFlagCommandHandlerConstructor(...args); + return { + processFlagsCommand: mockProcessFlagsCommand, + }; + }), + }; +}); + + describe('exec verbose flag tests', () => { beforeEach(() => { jest.clearAllMocks(); @@ -513,3 +532,61 @@ describe('--yes', () => { execSpy.mockRestore(); }); }); + +describe('flags command tests', () => { + let mockConfig: any; + let flagsSpy: jest.SpyInstance; + + beforeEach(() => { + jest.clearAllMocks(); + mockFlagCommandHandlerConstructor.mockClear(); + mockProcessFlagsCommand.mockClear(); + + flagsSpy = jest.spyOn(Toolkit.prototype, 'flags').mockResolvedValue([]); + + mockConfig = { + loadConfigFiles: jest.fn().mockResolvedValue(undefined), + settings: { + get: jest.fn().mockImplementation((key: string[]) => { + if (key[0] === 'unstable') return ['flags']; + return undefined; + }), + }, + context: { + all: { + 'myContextParam': 'testValue', + }, + get: jest.fn().mockReturnValue([]), + }, + }; + + Configuration.fromArgsAndFiles = jest.fn().mockResolvedValue(mockConfig); + }); + + afterEach(() => { + flagsSpy.mockRestore(); + }); + + test('passes CLI context to FlagCommandHandler', async () => { + // WHEN + await exec([ + 'flags', + '--unstable=flags', + '--set', + '--recommended', + '--all', + '-c', 'myContextParam=testValue', + '--yes', + ]); + + // THEN + expect(mockFlagCommandHandlerConstructor).toHaveBeenCalledWith( + expect.anything(), // flagsData + expect.anything(), // ioHelper + expect.anything(), // args + expect.anything(), // toolkit + mockConfig.context.all, // cliContextValues + ); + expect(mockProcessFlagsCommand).toHaveBeenCalled(); + }); +}); \ No newline at end of file From f166f97576a1a19248873c68fd9a028cb1c7d99b Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Thu, 25 Dec 2025 15:46:02 +0900 Subject: [PATCH 4/8] fix style in tests --- packages/aws-cdk/test/cli/cli.test.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk/test/cli/cli.test.ts b/packages/aws-cdk/test/cli/cli.test.ts index 98d032443..df753f36b 100644 --- a/packages/aws-cdk/test/cli/cli.test.ts +++ b/packages/aws-cdk/test/cli/cli.test.ts @@ -1,10 +1,10 @@ +import { Toolkit } from '@aws-cdk/toolkit-lib'; import { Notices } from '../../lib/api/notices'; import * as cdkToolkitModule from '../../lib/cli/cdk-toolkit'; import { exec } from '../../lib/cli/cli'; import { CliIoHost } from '../../lib/cli/io-host'; import { Configuration } from '../../lib/cli/user-configuration'; import { TestIoHost } from '../_helpers/io-host'; -import { Toolkit } from '@aws-cdk/toolkit-lib'; // Store original version module exports so we don't conflict with other tests const originalVersion = jest.requireActual('../../lib/cli/version'); @@ -111,7 +111,6 @@ jest.mock('../../lib/commands/flags/flags', () => { }; }); - describe('exec verbose flag tests', () => { beforeEach(() => { jest.clearAllMocks(); @@ -554,7 +553,7 @@ describe('flags command tests', () => { }, context: { all: { - 'myContextParam': 'testValue', + myContextParam: 'testValue', }, get: jest.fn().mockReturnValue([]), }, @@ -589,4 +588,4 @@ describe('flags command tests', () => { ); expect(mockProcessFlagsCommand).toHaveBeenCalled(); }); -}); \ No newline at end of file +}); From 54685594e7ee73aa8227cf78dddd293a68df8c84 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Mon, 5 Jan 2026 02:51:52 +0900 Subject: [PATCH 5/8] improve tests --- .../test/commands/flag-operations.test.ts | 101 ++++++------------ 1 file changed, 33 insertions(+), 68 deletions(-) diff --git a/packages/aws-cdk/test/commands/flag-operations.test.ts b/packages/aws-cdk/test/commands/flag-operations.test.ts index ed6a1a740..0cb08b571 100644 --- a/packages/aws-cdk/test/commands/flag-operations.test.ts +++ b/packages/aws-cdk/test/commands/flag-operations.test.ts @@ -1227,22 +1227,34 @@ describe('CLI context parameters', () => { const flagOperations = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit, cliContextValues); await flagOperations.processFlagsCommand(); - // Verify that fromCdkApp was called with a context store + // Verify that fromCdkApp was called expect(mockToolkit.fromCdkApp).toHaveBeenCalledTimes(2); - // Get the first call's context store - const firstCallArgs = mockToolkit.fromCdkApp.mock.calls[0]; - const contextStore = firstCallArgs[1]?.contextStore; - - // Verify the context store is a MemoryContext that contains both file and CLI context + // Get the first call's context store and verify it contains merged context + // fromCdkApp(app, { contextStore: ..., outdir: ... }) was called + const firstCallArgs = mockToolkit.fromCdkApp.mock.calls[0]; // Get first call arguments + const contextStore = firstCallArgs[1]?.contextStore; // Extract contextStore from second argument (options object) expect(contextStore).toBeDefined(); + // contextStore is defined as we've verified above + const contextData = await contextStore!.read(); + + // Verify both file context and CLI context are present + expect(contextData).toEqual({ + '@aws-cdk/core:existingFlag': true, // from cdk.json + '@aws-cdk/core:testFlag': true, // set by the operation + foo: 'bar', // from CLI + myContextParam: 'myValue', // from CLI + }); + await cleanupCdkJsonFile(cdkJsonPath); requestResponseSpy.mockRestore(); }); test('CLI context values are passed to synthesis during safe flag checking', async () => { - const cdkJsonPath = await createCdkJsonFile({}); + const cdkJsonPath = await createCdkJsonFile({ + '@aws-cdk/core:fileFlag': false, + }); mockToolkit.diff.mockResolvedValue({ TestStack: { differenceCount: 0 } as any, @@ -1253,6 +1265,7 @@ describe('CLI context parameters', () => { const cliContextValues = { myCliParam: 'cliValue', + anotherParam: 'anotherValue', }; const options: FlagsOptions = { @@ -1266,73 +1279,25 @@ describe('CLI context parameters', () => { // Verify that fromCdkApp was called during safe flag checking expect(mockToolkit.fromCdkApp).toHaveBeenCalled(); - await cleanupCdkJsonFile(cdkJsonPath); - requestResponseSpy.mockRestore(); - }); - - test('works correctly when no CLI context is provided', async () => { - const cdkJsonPath = await createCdkJsonFile({ - '@aws-cdk/core:existingFlag': false, - }); - - setupMockToolkitForPrototyping(mockToolkit); - - const requestResponseSpy = jest.spyOn(ioHelper, 'requestResponse'); - requestResponseSpy.mockResolvedValue(false); - - const options: FlagsOptions = { - FLAGNAME: ['@aws-cdk/core:testFlag'], - set: true, - value: 'true', - }; + // Get the first call's context store and verify it contains merged context + // fromCdkApp(app, { contextStore: ..., outdir: ... }) was called + const firstCallArgs = mockToolkit.fromCdkApp.mock.calls[0]; // Get first call arguments + const contextStore = firstCallArgs[1]?.contextStore; // Extract contextStore from second argument (options object) + expect(contextStore).toBeDefined(); - // Not passing cliContextValues (defaults to empty object) - const flagOperations = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit); - await flagOperations.processFlagsCommand(); + // contextStore is defined as we've verified above + const contextData = await contextStore!.read(); - expect(mockToolkit.fromCdkApp).toHaveBeenCalledTimes(2); - expect(mockToolkit.synth).toHaveBeenCalledTimes(2); + // Verify both file context and CLI context are merged + expect(contextData).toEqual({ + '@aws-cdk/core:fileFlag': false, // from cdk.json + myCliParam: 'cliValue', // from CLI + anotherParam: 'anotherValue', // from CLI + }); await cleanupCdkJsonFile(cdkJsonPath); requestResponseSpy.mockRestore(); }); - - test('FlagCommandHandler constructor accepts CLI context values', () => { - const cliContextValues = { - myParam: 'myValue', - foo: 'bar', - }; - - const options: FlagsOptions = { - all: true, - }; - - // Verify that constructor accepts CLI context values parameter - const handler = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit, cliContextValues); - expect(handler).toBeDefined(); - }); - - test('FlagCommandHandler passes CLI context to FlagOperations', async () => { - const cdkJsonPath = await createCdkJsonFile({}); - - setupMockToolkitForPrototyping(mockToolkit); - - const cliContextValues = { - cliParam: 'cliValue', - }; - - const options: FlagsOptions = { - all: true, - }; - - const handler = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit, cliContextValues); - await handler.processFlagsCommand(); - - // Just verify it doesn't throw and completes successfully - expect(mockToolkit.fromCdkApp).not.toHaveBeenCalled(); // Display mode doesn't call synthesis - - await cleanupCdkJsonFile(cdkJsonPath); - }); }); describe('setSafeFlags', () => { From 00e0bf0d6ad9ccd8a5bda710880e65ee63a13582 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Mon, 5 Jan 2026 02:56:25 +0900 Subject: [PATCH 6/8] modify --- .../test/commands/flag-operations.test.ts | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/packages/aws-cdk/test/commands/flag-operations.test.ts b/packages/aws-cdk/test/commands/flag-operations.test.ts index 0cb08b571..b1ef4ce52 100644 --- a/packages/aws-cdk/test/commands/flag-operations.test.ts +++ b/packages/aws-cdk/test/commands/flag-operations.test.ts @@ -1227,9 +1227,6 @@ describe('CLI context parameters', () => { const flagOperations = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit, cliContextValues); await flagOperations.processFlagsCommand(); - // Verify that fromCdkApp was called - expect(mockToolkit.fromCdkApp).toHaveBeenCalledTimes(2); - // Get the first call's context store and verify it contains merged context // fromCdkApp(app, { contextStore: ..., outdir: ... }) was called const firstCallArgs = mockToolkit.fromCdkApp.mock.calls[0]; // Get first call arguments @@ -1239,12 +1236,11 @@ describe('CLI context parameters', () => { // contextStore is defined as we've verified above const contextData = await contextStore!.read(); - // Verify both file context and CLI context are present expect(contextData).toEqual({ - '@aws-cdk/core:existingFlag': true, // from cdk.json - '@aws-cdk/core:testFlag': true, // set by the operation - foo: 'bar', // from CLI - myContextParam: 'myValue', // from CLI + '@aws-cdk/core:existingFlag': true, + '@aws-cdk/core:testFlag': true, + foo: 'bar', + myContextParam: 'myValue', }); await cleanupCdkJsonFile(cdkJsonPath); @@ -1276,9 +1272,6 @@ describe('CLI context parameters', () => { const flagOperations = new FlagCommandHandler(mockFlagsData, ioHelper, options, mockToolkit, cliContextValues); await flagOperations.processFlagsCommand(); - // Verify that fromCdkApp was called during safe flag checking - expect(mockToolkit.fromCdkApp).toHaveBeenCalled(); - // Get the first call's context store and verify it contains merged context // fromCdkApp(app, { contextStore: ..., outdir: ... }) was called const firstCallArgs = mockToolkit.fromCdkApp.mock.calls[0]; // Get first call arguments @@ -1288,11 +1281,10 @@ describe('CLI context parameters', () => { // contextStore is defined as we've verified above const contextData = await contextStore!.read(); - // Verify both file context and CLI context are merged expect(contextData).toEqual({ - '@aws-cdk/core:fileFlag': false, // from cdk.json - myCliParam: 'cliValue', // from CLI - anotherParam: 'anotherValue', // from CLI + '@aws-cdk/core:fileFlag': false, + myCliParam: 'cliValue', + anotherParam: 'anotherValue', }); await cleanupCdkJsonFile(cdkJsonPath); From 82090bc2f0702586b5950f3e5aa6b1eb22fea5b6 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Mon, 5 Jan 2026 03:10:54 +0900 Subject: [PATCH 7/8] fix --- packages/aws-cdk/test/commands/flag-operations.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk/test/commands/flag-operations.test.ts b/packages/aws-cdk/test/commands/flag-operations.test.ts index b1ef4ce52..5a723ef4e 100644 --- a/packages/aws-cdk/test/commands/flag-operations.test.ts +++ b/packages/aws-cdk/test/commands/flag-operations.test.ts @@ -1239,8 +1239,8 @@ describe('CLI context parameters', () => { expect(contextData).toEqual({ '@aws-cdk/core:existingFlag': true, '@aws-cdk/core:testFlag': true, - foo: 'bar', - myContextParam: 'myValue', + 'foo': 'bar', + 'myContextParam': 'myValue', }); await cleanupCdkJsonFile(cdkJsonPath); @@ -1283,8 +1283,8 @@ describe('CLI context parameters', () => { expect(contextData).toEqual({ '@aws-cdk/core:fileFlag': false, - myCliParam: 'cliValue', - anotherParam: 'anotherValue', + 'myCliParam': 'cliValue', + 'anotherParam': 'anotherValue', }); await cleanupCdkJsonFile(cdkJsonPath); From eb058cc074c8cbd3ee85ba140218616e43dee3f2 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Mon, 5 Jan 2026 03:14:00 +0900 Subject: [PATCH 8/8] tweak --- .../aws-cdk/test/commands/flag-operations.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk/test/commands/flag-operations.test.ts b/packages/aws-cdk/test/commands/flag-operations.test.ts index 5a723ef4e..ba99f4cf9 100644 --- a/packages/aws-cdk/test/commands/flag-operations.test.ts +++ b/packages/aws-cdk/test/commands/flag-operations.test.ts @@ -1249,7 +1249,7 @@ describe('CLI context parameters', () => { test('CLI context values are passed to synthesis during safe flag checking', async () => { const cdkJsonPath = await createCdkJsonFile({ - '@aws-cdk/core:fileFlag': false, + '@aws-cdk/core:existingFlag': true, }); mockToolkit.diff.mockResolvedValue({ @@ -1260,8 +1260,8 @@ describe('CLI context parameters', () => { requestResponseSpy.mockResolvedValue(false); const cliContextValues = { - myCliParam: 'cliValue', - anotherParam: 'anotherValue', + foo: 'bar', + myContextParam: 'myValue', }; const options: FlagsOptions = { @@ -1282,9 +1282,9 @@ describe('CLI context parameters', () => { const contextData = await contextStore!.read(); expect(contextData).toEqual({ - '@aws-cdk/core:fileFlag': false, - 'myCliParam': 'cliValue', - 'anotherParam': 'anotherValue', + '@aws-cdk/core:existingFlag': true, + 'foo': 'bar', + 'myContextParam': 'myValue', }); await cleanupCdkJsonFile(cdkJsonPath);