Skip to content

feat(toolkit-lib): add a return type for toolkit.diff() #368

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

Merged
merged 5 commits into from
Apr 15, 2025

Conversation

kaizencc
Copy link
Contributor

toolkit.diff() now returns a TemplateDiff for each stack it diffs.

Closes aws/aws-cdk#33182


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team April 14, 2025 20:56
@github-actions github-actions bot added the p2 label Apr 14, 2025
expect(ioHost.notifySpy).toHaveBeenCalledWith(expect.objectContaining({
action: 'diff',
level: 'warn',
code: 'CDK_TOOLKIT_W0000',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the broadest warning code, should be consider one more specific to CDK Diff?

CDK_TOOLKIT_W4xx?

Copy link
Contributor Author

@kaizencc kaizencc Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Momo specifically wanted this lol. The new directive is default warning code unless its returning data

@@ -184,11 +192,12 @@ export class DiffFormatter {

private formatStackDiffHelper(
oldTemplate: any,
stackName: string | undefined,
stackName: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's an empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldn't be. but even if it is, i don't think my code would fail. obviously right now if you somehow call formatStackDiff() or formatSecurityDiff on the same stack in the same DiffFormatter, we'd write over the previous diff object.

  1. we are not calling formatXxx multiple times per CLI / toolkit call, so I don't expect this to happen in practice at all.
  2. even if we did overwrite, we'd be writing the same object as the fullDiff is the same.

*/
readonly stackName?: string;
readonly stackName: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change? Not sure if it matters, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff-formatter isn't public so this isn't breaking. i made this change because we do always have the stackName, since we have the stack

stacks: { strategy: StackSelectionStrategy.ALL_STACKS },
});

console.log(JSON.stringify(result));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build is failing due to this

constructor(props: DiffFormatterProps) {
this.ioHelper = props.ioHelper;
this.oldTemplate = props.templateInfo.oldTemplate;
this.newTemplate = props.templateInfo.newTemplate;
this.stackName = props.templateInfo.stackName;
this.stackName = props.templateInfo.newTemplate.stackName;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are now always taking the stack name from the new template. this always exists. this is what we were doing in practice previously, we are now codifying that and removing stackName as an option

@kaizencc kaizencc requested a review from iankhou April 15, 2025 19:38
@codecov-commenter
Copy link

codecov-commenter commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.01%. Comparing base (4771ed8) to head (3247e2a).
Report is 174 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #368      +/-   ##
==========================================
- Coverage   85.61%   80.01%   -5.60%     
==========================================
  Files         219       65     -154     
  Lines       24250     6885   -17365     
  Branches     2588      790    -1798     
==========================================
- Hits        20761     5509   -15252     
+ Misses       3440     1354    -2086     
+ Partials       49       22      -27     
Flag Coverage Δ
suite.unit 80.01% <ø> (-5.60%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Apr 15, 2025
Merged via the queue into main with commit 25db152 Apr 15, 2025
20 checks passed
@aws-cdk-automation aws-cdk-automation deleted the conroy/returnDiff branch April 15, 2025 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Toolkit Action: diff & typed return
4 participants