Skip to content

Conversation

@kaizencc
Copy link
Contributor

@kaizencc kaizencc commented Mar 26, 2025

the point of this PR is to refactor formatStackDiff and formatSecurityDiff into the same class. there's more to do to simplify these functions, but i'm making small refactors a priority.

the achievement of this PR is to get rid of the giant laundry list of properties that go into each function in favor of a property bag, and to store the repeated properties within a class.

this is tested by current unit tests -- as long as they still pass, this refactor should have not changed any functionality.


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

@github-actions github-actions bot added the p2 label Mar 26, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team March 26, 2025 22:33
import type * as cxapi from '@aws-cdk/cx-api';
import * as chalk from 'chalk';

import { RequireApproval } from '../../api/require-approval';
Copy link
Contributor

Choose a reason for hiding this comment

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

This should move towards the approach were return a classification and let the CLI deal with interaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes agree. this will be the first follow up PR as i think its most important

Comment on lines 70 to 71
readonly oldTemplate: any;
readonly newTemplate: cxapi.CloudFormationStackArtifact,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these are different types, maybe they do to serve different names.


export interface FormatSecurityDiffOptions {
readonly requireApproval: RequireApproval,
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.

Can we just retrieve this from the stack artifact?

*
* @default false
*/
readonly quiet?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

I still hate this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hehe me too

/**
* @default undefined
*/
readonly nestedStackTemplates?: { [nestedStackLogicalId: string]: NestedStackTemplates };
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. Can this be retrieved from the stack artifact, as part of this API?

readonly ioDefaultHelper: IoDefaultMessages;
}

export class DiffFormatter {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given how to call site works there might be a larger abstraction hiding. Your DiffFormater could take all options as input, does the shared work between full and security diff, and can return both formats:

const diff = new  DiffFormatter(props);

diff.rawDiff // Template diff
diff.fullDiff
diff.securityDiff

This might be preferable for the toolkit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree re: larger abstraction, but for now, i've simply lowered the scope of this PR (or defined it to be what i was initially trying to achieve)

@kaizencc kaizencc marked this pull request as ready for review March 28, 2025 02:44
@codecov-commenter
Copy link

codecov-commenter commented Mar 28, 2025

Codecov Report

Attention: Patch coverage is 88.83610% with 47 lines in your changes missing coverage. Please review.

Project coverage is 85.44%. Comparing base (2a9ee4c) to head (31427a0).

Files with missing lines Patch % Lines
...tmp-toolkit-helpers/src/api/diff/diff-formatter.ts 89.63% 40 Missing ⚠️
packages/aws-cdk/lib/cli/cdk-toolkit.ts 79.41% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #283      +/-   ##
==========================================
- Coverage   85.59%   85.44%   -0.15%     
==========================================
  Files         222      222              
  Lines       36798    36885      +87     
  Branches     4468     4462       -6     
==========================================
+ Hits        31497    31517      +20     
- Misses       5209     5270      +61     
- Partials       92       98       +6     
Flag Coverage Δ
suite.unit 85.44% <88.83%> (-0.15%) ⬇️

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.

Signed-off-by: github-actions <[email protected]>
@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Mar 28, 2025
Merged via the queue into main with commit f9f6d1d Mar 28, 2025
20 checks passed
@aws-cdk-automation aws-cdk-automation deleted the conroy/refactor-format-diffs branch March 28, 2025 17:43
@pahud pahud mentioned this pull request Apr 1, 2025
1 task
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.

4 participants