From f3a52baa8531705188a4ff112b2cd001ec792815 Mon Sep 17 00:00:00 2001 From: SankyRed Date: Mon, 11 Mar 2024 14:51:54 -0500 Subject: [PATCH 1/2] list stack issue fix --- .../tests/cli-integ-tests/cli.integtest.ts | 8 +- packages/aws-cdk/lib/list-stacks.ts | 4 +- packages/aws-cdk/test/list-stacks.test.ts | 92 ++++++++++++++++++- 3 files changed, 96 insertions(+), 8 deletions(-) diff --git a/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts index d3d5b12d94154..3c69673e775ba 100644 --- a/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts +++ b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts @@ -886,10 +886,10 @@ integTest('cdk ls --show-dependencies --json', withDefaultFixture(async (fixture id: 'list-stacks', dependencies: [ { - id: 'liststacksDependentStack', + id: 'list-stacks/DependentStack', dependencies: [ { - id: 'liststacksDependentStackInnerDependentStack', + id: 'list-stacks/DependentStack/InnerDependentStack', dependencies: [], }, ], @@ -900,11 +900,11 @@ integTest('cdk ls --show-dependencies --json', withDefaultFixture(async (fixture id: 'list-multiple-dependent-stacks', dependencies: [ { - id: 'listmultipledependentstacksDependentStack1', + id: 'list-multiple-dependent-stacks/DependentStack1', dependencies: [], }, { - id: 'listmultipledependentstacksDependentStack2', + id: 'list-multiple-dependent-stacks/DependentStack2', dependencies: [], }, ], diff --git a/packages/aws-cdk/lib/list-stacks.ts b/packages/aws-cdk/lib/list-stacks.ts index e76a1f393a0a9..dddf6fda3613e 100644 --- a/packages/aws-cdk/lib/list-stacks.ts +++ b/packages/aws-cdk/lib/list-stacks.ts @@ -56,7 +56,7 @@ export async function listStacks(toolkit: CdkToolkit, options: ListStacksOptions for (const stack of collectionOfStacks.stackArtifacts) { const data: StackDetails = { - id: stack.id, + id: stack.displayName ?? stack.id, name: stack.stackName, environment: stack.environment, dependencies: [], @@ -82,7 +82,7 @@ export async function listStacks(toolkit: CdkToolkit, options: ListStacksOptions } } else { data.dependencies.push({ - id: depStack.stackArtifacts[0].id, + id: depStack.stackArtifacts[0].displayName ?? depStack.stackArtifacts[0].id, dependencies: [], }); } diff --git a/packages/aws-cdk/test/list-stacks.test.ts b/packages/aws-cdk/test/list-stacks.test.ts index e36081e99c1d2..016a7160549a7 100644 --- a/packages/aws-cdk/test/list-stacks.test.ts +++ b/packages/aws-cdk/test/list-stacks.test.ts @@ -171,7 +171,7 @@ describe('list', () => { dependencies: [], }, { - id: 'Test-Stack-B', + id: 'Test-Stack-A/Test-Stack-B', name: 'Test-Stack-B', environment: { account: '123456789012', @@ -185,7 +185,7 @@ describe('list', () => { }])); }); - test('stacks with nested dependencies', async () => { + test('stacks with display names and have nested dependencies', async () => { let cloudExecutable = new MockCloudExecutable({ stacks: [ MockStack.MOCK_STACK_A, @@ -201,9 +201,84 @@ describe('list', () => { ], }, depends: ['Test-Stack-A'], + displayName: 'Test-Stack-A/Test-Stack-B', }, { stackName: 'Test-Stack-C', + template: { Resources: { TemplateName: 'Test-Stack-C' } }, + env: 'aws://123456789012/bermuda-triangle-1', + metadata: { + '/Test-Stack-C': [ + { + type: cxschema.ArtifactMetadataEntryType.STACK_TAGS, + }, + ], + }, + depends: ['Test-Stack-B'], + displayName: 'Test-Stack-A/Test-Stack-B/Test-Stack-C', + }, + ], + }); + + // GIVEN + const toolkit = new CdkToolkit({ + cloudExecutable, + configuration: cloudExecutable.configuration, + sdkProvider: cloudExecutable.sdkProvider, + deployments: cloudFormation, + }); + + // WHEN + const workflow = await listStacks( toolkit, { selectors: ['Test-Stack-A', 'Test-Stack-A/Test-Stack-B', 'Test-Stack-A/Test-Stack-B/Test-Stack-C'] }); + + // THEN + expect(JSON.stringify(workflow)).toEqual(JSON.stringify([{ + id: 'Test-Stack-A', + name: 'Test-Stack-A', + environment: { + account: '123456789012', + region: 'bermuda-triangle-1', + name: 'aws://123456789012/bermuda-triangle-1', + }, + dependencies: [], + }, + { + id: 'Test-Stack-A/Test-Stack-B', + name: 'Test-Stack-B', + environment: { + account: '123456789012', + region: 'bermuda-triangle-1', + name: 'aws://123456789012/bermuda-triangle-1', + }, + dependencies: [{ + id: 'Test-Stack-A', + dependencies: [], + }], + }, + { + id: 'Test-Stack-A/Test-Stack-B/Test-Stack-C', + name: 'Test-Stack-C', + environment: { + account: '123456789012', + region: 'bermuda-triangle-1', + name: 'aws://123456789012/bermuda-triangle-1', + }, + dependencies: [{ + id: 'Test-Stack-A/Test-Stack-B', + dependencies: [{ + id: 'Test-Stack-A', + dependencies: [], + }], + }], + }])); + }); + + test('stacks with nested dependencies', async () => { + let cloudExecutable = new MockCloudExecutable({ + stacks: [ + MockStack.MOCK_STACK_A, + { + stackName: 'Test-Stack-B', template: { Resources: { TemplateName: 'Test-Stack-B' } }, env: 'aws://123456789012/bermuda-triangle-1', metadata: { @@ -213,6 +288,19 @@ describe('list', () => { }, ], }, + depends: ['Test-Stack-A'], + }, + { + stackName: 'Test-Stack-C', + template: { Resources: { TemplateName: 'Test-Stack-C' } }, + env: 'aws://123456789012/bermuda-triangle-1', + metadata: { + '/Test-Stack-C': [ + { + type: cxschema.ArtifactMetadataEntryType.STACK_TAGS, + }, + ], + }, depends: ['Test-Stack-B'], }, ], From 03f27d822dbdbe2261d54b1c7a7a59ce9c29567b Mon Sep 17 00:00:00 2001 From: SankyRed Date: Mon, 11 Mar 2024 18:49:04 -0500 Subject: [PATCH 2/2] skip integ test --- .../resources/cli-regression-patches/v2.132.0/NOTES.md | 1 + .../resources/cli-regression-patches/v2.132.0/skip-tests.txt | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/NOTES.md create mode 100644 packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/skip-tests.txt diff --git a/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/NOTES.md b/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/NOTES.md new file mode 100644 index 0000000000000..6f59e64a3b0b7 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/NOTES.md @@ -0,0 +1 @@ +This patch brings the [fix](https://github.com/aws/aws-cdk/issues/29420) into the regression suite. \ No newline at end of file diff --git a/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/skip-tests.txt b/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/skip-tests.txt new file mode 100644 index 0000000000000..744f3c3396861 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/resources/cli-regression-patches/v2.132.0/skip-tests.txt @@ -0,0 +1,4 @@ +# Skipping the test to fix issue https://github.com/aws/aws-cdk/issues/29420. +# cli-integ tests failing for the old tests with the new cli changes for list stacks. + +cdk ls --show-dependencies --json \ No newline at end of file