Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(assertions): throw error or warn when synth is called multiple times on mutated construct tree #31865

Merged
merged 25 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4e1795
WIP - add unit test to synthesis.test.ts
sumupitchayan Oct 23, 2024
fd13c07
remove assembly caching from stage.ts synth() function
sumupitchayan Oct 23, 2024
f780751
fix import order in synthesis.test.ts
sumupitchayan Oct 23, 2024
299733d
WIP - try different approach, comparing construct path sets
sumupitchayan Oct 25, 2024
31afea1
fix linter errors
sumupitchayan Oct 25, 2024
e9cbc48
WIP - cache after running synth
sumupitchayan Oct 28, 2024
1c5cff1
fix pipelines test (environment variables specified in multiple place…
sumupitchayan Oct 28, 2024
c111479
WIP - update unit test for this issue
sumupitchayan Oct 28, 2024
f7e70bb
WIP - improve error/warning messages
sumupitchayan Oct 28, 2024
8e6a194
typo
sumupitchayan Oct 28, 2024
8798232
Merge branch 'main' into sumughan/fix-assertions-unable-to-find-artifact
sumupitchayan Oct 28, 2024
de57d44
Update packages/aws-cdk-lib/core/lib/stage.ts
sumupitchayan Oct 28, 2024
af20ae7
rename warnInsteadOfError to errorOnDuplicateSynth
sumupitchayan Oct 28, 2024
9a2e089
improve error message
sumupitchayan Oct 28, 2024
a78ab0e
make 2 helper functions top-level
sumupitchayan Oct 28, 2024
c7430d8
eslint comment to allow console.error statement
sumupitchayan Oct 28, 2024
ac524e1
Update packages/aws-cdk-lib/core/lib/stage.ts
sumupitchayan Oct 29, 2024
280e2e2
rename parameter in recurse funciton
sumupitchayan Oct 29, 2024
39cc2fd
WIP Momo feedback: improve err/warning messages
sumupitchayan Oct 29, 2024
c133601
edit test err msg assertion
sumupitchayan Oct 29, 2024
02f405c
WIP err msgs again
sumupitchayan Oct 29, 2024
b68519a
WIP err msgs again x2
sumupitchayan Oct 29, 2024
e8b866b
WIP err msgs 3x
sumupitchayan Oct 29, 2024
6f098be
remove force option from error throwing in synth
sumupitchayan Oct 29, 2024
4fec523
Merge branch 'main' into sumughan/fix-assertions-unable-to-find-artifact
sumupitchayan Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions packages/aws-cdk-lib/core/lib/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ export class Stage extends Construct {
*/
public readonly parentStage?: Stage;

/**
* The cached assembly if it was already built
*/
private assembly?: cxapi.CloudAssembly;

/**
* Validation plugins to run during synthesis. If any plugin reports any violation,
* synthesis will be interrupted and the report displayed to the user.
Expand Down Expand Up @@ -210,14 +205,10 @@ export class Stage extends Construct {
* calls will return the same assembly.
*/
public synth(options: StageSynthesisOptions = { }): cxapi.CloudAssembly {
if (!this.assembly || options.force) {
this.assembly = synthesize(this, {
skipValidation: options.skipValidation,
validateOnSynthesis: options.validateOnSynthesis,
});
}

return this.assembly;
return synthesize(this, {
skipValidation: options.skipValidation,
validateOnSynthesis: options.validateOnSynthesis,
});
}

private createBuilder(outdir?: string) {
Expand Down
21 changes: 21 additions & 0 deletions packages/aws-cdk-lib/core/test/synthesis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Construct } from 'constructs';
import * as cxschema from '../../cloud-assembly-schema';
import * as cxapi from '../../cx-api';
import * as cdk from '../lib';
import { Template } from '../../assertions';
import { synthesize } from '../lib/private/synthesis';

function createModernApp() {
Expand Down Expand Up @@ -362,6 +363,26 @@ describe('synthesis', () => {

});

test('can call synth multiple times without caching assembly', () => {
const app = new cdk.App();

const stages = [
{
stage: 'PROD',
},
{
stage: 'BETA',
},
];

stages.forEach(({ stage }) => {
const stack = new cdk.Stack(app, `${stage}-Stack`, {});
// Assert that `Unable to find artifact with id` error is not thrown
expect(() => {
Template.fromStack(stack);
}).not.toThrow();
});
});
});

function list(outdir: string) {
Expand Down
Loading