fix(servicecatalog): avoid asset hash change for latest version in ProductStackHistory #32248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue # (if applicable)
Closes #24561.
Reason for this change
If you use ProductStackHistory to manage the historic versions of your product and add a new version to it, the latest version (before adding the new one) changes because the asset hash computed for the product template changes. This happens because the asset hash for the current version and historic versions is computed in a different way.
Description of changes
I changed the code to make sure that the asset hash for a product template is computed the same way, no matter if derived directly from a ProductStack instance (as is the case for the current version) or read from a snapshot. For the current version, the code used to synthesize the template in memory and hash the string, before writing the template to disk. I changed the order, writing the template to disk and then use FileSystem.fingerprint on the file - which is exactly what is used for snapshot versions.
This way, the asset hashes of historic version of existing products based ProductStack won't change as the code changes affects only the current version.
Description of how you validated changes
I've added a unit test to cover this particular scenario. However, I wasn't able to update the integration tests. I tried but no matter what I did I always got the following error message although I configured the credentials for my account and bootstrapped it correctly. It's my first contribution, so I may have missed something obvious.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license