Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions packages/@aws-cdk/toolkit-lib/lib/api/refactoring/digest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ function stripConstructPath(resource: any): any {
return resource;
}

const copy = JSON.parse(JSON.stringify(resource));
delete copy.Metadata['aws:cdk:path'];
return copy;
// A shallow copy is enough: the only thing being removed is one key of
// `Metadata`, and the caller only reads the result.
const { 'aws:cdk:path': _, ...metadata } = resource.Metadata;
return { ...resource, Metadata: metadata };
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,38 @@ describe(computeResourceDigests, () => {
expect(result['Stack1.Q1']).toBe(result['Stack1.Q2']);
});

test('other metadata still contributes to the digest, and the input is not modified', () => {
const makeTemplate = (assetPath: string) => ({
Resources: {
Q1: {
Type: 'AWS::SQS::Queue',
Properties: { Foo: 'Bar' },
Metadata: {
'aws:cdk:path': 'Stack/Q1/Resource',
'aws:asset:path': assetPath,
},
},
},
});

const template = makeTemplate('asset.1234');
const stacks = makeStacks([template]);
const digest = computeResourceDigests(stacks)['Stack1.Q1'];

// Metadata other than the construct path is part of the digest
const other = computeResourceDigests(makeStacks([makeTemplate('asset.5678')]))['Stack1.Q1'];
expect(digest).not.toBe(other);

// Computing the digest leaves the caller's template alone
expect(template.Resources.Q1.Metadata).toEqual({
'aws:cdk:path': 'Stack/Q1/Resource',
'aws:asset:path': 'asset.1234',
});

// ...and is stable across repeated calls
expect(computeResourceDigests(stacks)['Stack1.Q1']).toBe(digest);
});

test('different physical IDs lead to different digests', () => {
mockLoadResourceModel.mockReturnValue({
primaryIdentifier: ['FooName'],
Expand Down
Loading