Skip to content

Conversation

john-h-kastner-aws
Copy link
Contributor

The formatter fuzz target only checked that all comments in the original policy were present in the output without checking that they appeared in the same order. This allowed cedar-policy/cedar#787 to exist. The fuzz target with the new, stronger, assertion passed local fuzzing after applying the fixes in cedar-policy/cedar#861.

As a pleasant side effect, it's actually more efficient to check for the comments in the order they were inserted than in an arbitrary order. The check is now a single linear scan rather than a linear scan for each comment, likely resolving the slow units noted in #268. The slow input in that issue is improved from 16 second to about 4 seconds.

assert!(formatted_policy_str.contains(u), "missing comment: {}\n", u);
match formatted_policy_tail.split_once(u) {
Some((_, after_uuid)) => formatted_policy_tail = after_uuid,
None => {
Copy link
Contributor

@shaobo-he-aws shaobo-he-aws May 13, 2024

Choose a reason for hiding this comment

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

Nit: remove the println?

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's printed only once we know the test case is an error, so no reason to remove it, and it makes debugging failures much easier

@john-h-kastner-aws john-h-kastner-aws merged commit 5a6a0ca into main May 13, 2024
khieta pushed a commit that referenced this pull request May 15, 2024
khieta added a commit that referenced this pull request May 15, 2024
aaronjeline pushed a commit that referenced this pull request May 16, 2024
@john-h-kastner-aws john-h-kastner-aws deleted the formatter-check-order branch May 21, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants