Skip to content

Conversation

@kaizencc
Copy link
Contributor

@kaizencc kaizencc commented Mar 24, 2025

moves two functions that are relevant to diff into tmp-toolkit-helpers. this will facilitate the adoption of diff in the programmatic toolkit as it will now be able to reuse these functions.

existing tests pass to ensure no breakage. additional tests have been added to tmp-toolkit-helpers to test formatXxxDiff, which were previously not directly tested.


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

try {
// must output the stack name if there are differences, even if quiet
if (stackName && (!quiet || !diff.isEmpty)) {
stream.write(format('Stack %s\n', chalk.bold(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.

welp, these prints don't work yet and im worried im not doing the right thing here:

format and chalk don't exist in this context and i'm not sure how to replicate them.

Copy link
Contributor

Choose a reason for hiding this comment

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

import { format } from 'node:util'l;
import * as chalk from 'chalk';

Copy link
Contributor

Choose a reason for hiding this comment

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

But format you can also just replace with string literals:

`Stack ${chalk.bold(stackName)}\n`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i guess a better question to ask was: are we certain we want it in tmp-toolkit-helpers and not imported here like a lot of other heavy duty imports.

but it sounds like your answer also answers that question too

@aws-cdk-automation aws-cdk-automation requested a review from a team March 24, 2025 20:37
@kaizencc kaizencc changed the title chore(tmp-toolkit-helpers): formatStackDiff and formatSecurityDiff moved to tmp-toolkit-helpesr chore(tmp-toolkit-helpers): formatStackDiff and formatSecurityDiff moved to tmp-toolkit-helpers Mar 24, 2025
[nestedStackLogicalId: string]: NestedStackTemplates;
};
}
export { NestedStackTemplates } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is it reasonable to both export and import NestedStackTemplate here?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, it's just going to annoy me when I do the move :D

await cdkToolkit.deploy({
selector: { patterns: ['Test-Stack-A-Display-Name'] },
requireApproval: RequireApproval.Never,
requireApproval: RequireApproval.NEVER,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is kind of silly but also a breaking change right? what should i have done instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

why is it breaking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i suppose its not because the CLI users have no access to this..

],
deps: [
cloudAssemblySchema.name,
cloudFormationDiff,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

elsewhere we are depending on cloudformationDiff.customizeReference({ versionType: 'exact' }), and i'm not sure why. just thought i'd flag

Comment on lines +122 to +132
export function formatStackDiff(
ioHelper: IoHelper,
oldTemplate: any,
newTemplate: cxapi.CloudFormationStackArtifact,
strict: boolean,
context: number,
quiet: boolean,
stackName?: string,
changeSet?: DescribeChangeSetOutput,
isImport?: boolean,
nestedStackTemplates?: { [nestedStackLogicalId: string]: NestedStackTemplates }): FormatStackDiffOutput {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i agree that this sucks and should be part of a class with formatSecurityDiff. but i don't wanna do it in this PR, it's already too complicated.

@codecov-commenter
Copy link

codecov-commenter commented Mar 25, 2025

Codecov Report

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

Project coverage is 85.39%. Comparing base (a3b9762) to head (e148e1e).

Files with missing lines Patch % Lines
.../@aws-cdk/tmp-toolkit-helpers/src/api/diff/diff.ts 85.47% 43 Missing ⚠️
packages/aws-cdk/lib/cli/cdk-toolkit.ts 73.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #278      +/-   ##
==========================================
+ Coverage   85.22%   85.39%   +0.16%     
==========================================
  Files         221      222       +1     
  Lines       36764    36761       -3     
  Branches     4457     4471      +14     
==========================================
+ Hits        31333    31391      +58     
+ Misses       5331     5273      -58     
+ Partials      100       97       -3     
Flag Coverage Δ
suite.unit 85.39% <85.12%> (+0.16%) ⬆️

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]>
@kaizencc kaizencc marked this pull request as ready for review March 25, 2025 20:59
Signed-off-by: github-actions <[email protected]>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AI disclosure: this file was originally intended to be full AI generated and started off as such but it insisted on mocking @aws-cdk/cloudformation-diff functions and I really didn't want it to. So I spent twice as much time bashing the code into what I wanted. At the end of the day this is <50% AI generated.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are much easier ways to achieve the same mocking results you were after. Check some other files for inspirations.

Specifically all calls end up in an IoHost, so all the helpers could just stay real.

@kaizencc kaizencc requested a review from mrgrain March 25, 2025 21:59
Signed-off-by: github-actions <[email protected]>
});
}
}
export { formatStackDiff, formatSecurityDiff, RequireApproval } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api';
Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine. But you also could have updated any imports.

@aws-cdk-automation aws-cdk-automation added this pull request to the merge queue Mar 26, 2025
Merged via the queue into main with commit 0db3dc2 Mar 26, 2025
20 checks passed
@aws-cdk-automation aws-cdk-automation deleted the conroy/diffs-into-tmp-toolkit-helpers branch March 26, 2025 10:34
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