Skip to content

fix(cli): hide diffs of mangled unicode strings#25525

Closed
laverdet wants to merge 9 commits intoaws:mainfrom
laverdet:main
Closed

fix(cli): hide diffs of mangled unicode strings#25525
laverdet wants to merge 9 commits intoaws:mainfrom
laverdet:main

Conversation

@laverdet
Copy link
Copy Markdown
Contributor

@laverdet laverdet commented May 10, 2023

I am reopening this from #25008

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

and following up on my comments here:
#24557 (comment)
#24557 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)

@aws-cdk-automation @rix0rrr @TheRealAmazonKendra - I'm happy to adjust the approach, add more tests, or do what else needs to be done. I'm not getting any feedback from the team so I'm not sure how to proceed. The diff noise with non-ASCII information in cdk diff makes it difficult to find meaningful changes to our stacks.

🗿🗞️📬 Crucially, this change only affects the CLI output and therefore an integration test isn't possible.


CloudFormation's GetStackTemplate irrecoverably mangles any character not in the 7-bit ASCII range. This causes noisy output from cdk diff when a template contains non-English languages or emoji. We can detect this case and consider these strings equal.

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

Many AWS services accept non-ASCII input, eg many "description" fields. CloudFormation will correctly dispatch these templates but when invoking GetStackTemplate the result is mangled. This causes annoying noise in the output of cdk diff:

Resources
[~] AWS::Lambda::Function Lambda/Resource
 └─ [~] Description
     ├─ [-] ?????
     └─ [+] 🤦🏻‍♂️

This change modifies the diff algorithm to consider the string equal if the lvalue is a mangled version of the rvalue.

Of course this runs the risk of hiding changesets which modify only a single non-ASCII character to another non-ASCII character, but these fields already tend to be informative in nature.

fixes #25309

laverdet added 3 commits March 9, 2023 15:18
CloudFormation's `GetStackTemplate` irrecoverably mangles any character
not in the 7-bit ASCII range. This causes noisy output from `cdk diff`
when a template contains non-English languages or emoji. We can detect
this case and consider these strings equal.

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented May 10, 2023

@aws-cdk-automation aws-cdk-automation requested a review from a team May 10, 2023 20:04
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels May 10, 2023
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@laverdet
Copy link
Copy Markdown
Contributor Author

Exemption Request - This change only affects the CLI output and therefore an integration test isn't possible. I'm happy to spend more time documenting or working through other prerequisites but I do want to make sure that, conceptually, this change is one that the team will accept. I have also included more information about the benefits and tradeoffs of this change in the original PR message.

@aws-cdk-automation aws-cdk-automation added pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels May 10, 2023
@laverdet
Copy link
Copy Markdown
Contributor Author

@skinny85 any chance I could get some eyes on this?

@skinny85
Copy link
Copy Markdown
Contributor

@laverdet unfortunately, I'm no longer on the CDK team, so I can't help with the PR 🙂.

@laverdet
Copy link
Copy Markdown
Contributor Author

@corymhall Is there any chance you or someone on the team could take a quick look at this? It is a 3-line CLI-only QOL improvement and I'm a little confused as to why I haven't gotten any communication from the team in the 2 months since I opened #24557. If this is not something the team wants then that's ok but right now I'm caught in an awkward holding pattern.

@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort labels May 18, 2023
@peterwoodworth peterwoodworth added effort/small Small work item – less than a day of effort and removed effort/medium Medium work item – several days of effort labels May 18, 2023

test('mangled strings', () => {
expect(deepEqual('foo', 'foo')).toBeTruthy();
expect(deepEqual('????', '文字化け')).toBeTruthy();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Equality, being an equivalence relation, should be reflexive, symmetric and transitive. In particular, for the symmetric property, the following should hold:

deepEqual('????', '文字化け') $\iff$ deepEqual('文字化け', '????')

which is not the case. The left-hand side is true and the right-hand side is false. But even if we fix this (and assuming transitivity also holds), we get the following nonsensical implication:

// Given that the following statements are true:
deepEqual('文字化け', '????')
deepEqual('????', '🤦🏻‍♂️')

// Then, by transitivity:
deepEqual('文字化け', '🤦🏻‍♂️')

Copy link
Copy Markdown
Contributor Author

@laverdet laverdet May 23, 2023

Choose a reason for hiding this comment

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

@otaviomacedo thank you for the response.

I agree in principle that equality should be equality but we must confront the reality of CloudFormation's limitations. This is not a general purpose deep equality function and already contains special cases for CloudFormation (see: DependsOn).

  const left = {
    DependsOn: ['a', 'b'],
  };
  const right = {
    DependsOn: ['c', 'd'],
  };
  expect(deepEqual(left, right)).toBeTruthy(); // passes (bug?)

I don't think we should let the notions of ideal mathematical purity get in the way of fixing a very real and plainly observable issue in CDK. GetStackTemplate is not reflexive in relation to CreateChangeSet and therefore this function must operate under the same imperfect framework. Viewing this function under any other lens is incorrect in the same way applying euclidean geometry on a non-euclidean surface is incorrect.

Here lvalue is "what CloudFormation has given us" and rvalue is "what the developer intended." Under this exotic framework, I believe that the implementation is sound.

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@laverdet
Copy link
Copy Markdown
Contributor Author

laverdet commented Jun 1, 2023

Please don't close it again. It is clearly not abandoned.

@laverdet
Copy link
Copy Markdown
Contributor Author

laverdet commented Jun 6, 2023

@otaviomacedo - Could you kindly dismiss the automation error? The diff is not abandoned and I would like to not open a new PR tomorrow.

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 467ccb2
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Jun 9, 2023
@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

mergify bot pushed a commit that referenced this pull request Jun 15, 2023
I am reopening this from #25525

and following up on my comments here:
#24557 (comment)
#24557 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25525 (comment)
#25525 (comment)
🫠 #25525 (comment) 🫠

---

Fixes #25309
Fixes #22203
Fixes #20212
Fixes #13634
Fixes #10523
Fixes #10219
See also: aws-cloudformation/cloudformation-coverage-roadmap#1220
See also: aws-cloudformation/cloudformation-coverage-roadmap#814

---

👻 I have retitled this PR as a `chore` instead of a `fix` because @aws-cdk-automation keeps closing my PRs as abandoned even though they are clearly not abandoned.

> This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

---

@otaviomacedo @rix0rrr @TheRealAmazonKendra - I'm happy to adjust the approach, add more tests, or do what else needs to be done. I'm not getting any feedback from the team so I'm not sure how to proceed. The diff noise with non-ASCII information in cdk diff makes it difficult to find meaningful changes to our stacks.

🗿🗞️📬 **Crucially, this change only affects the CLI output and therefore an integration test isn't possible.**

---

CloudFormation's `GetStackTemplate` irrecoverably mangles any character not in the 7-bit ASCII range. This causes noisy output from `cdk diff` when a template contains non-English languages or emoji. We can detect this case and consider these strings equal.

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

Many AWS services accept non-ASCII input, eg many "description" fields. CloudFormation will correctly dispatch these templates but when invoking `GetStackTemplate` the result is mangled. This causes annoying noise in the output of `cdk diff`:

```
Resources
[~] AWS::Lambda::Function Lambda/Resource
 └─ [~] Description
     ├─ [-] ?????
     └─ [+] 🤦🏻‍♂️
```

This change modifies the diff algorithm to consider the string equal if the lvalue is a mangled version of the rvalue.

Of course this runs the risk of hiding changesets which modify only a single non-ASCII character to another non-ASCII character, but these fields already tend to be informative in nature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/small Small work item – less than a day of effort p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(cdk-core): CDK diff does not work with umlauts

5 participants