Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#596) fix issue with semver validation for latest versions #597

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

1yuv
Copy link
Member

@1yuv 1yuv commented Jan 5, 2024

Description

[description]

#596

Code review items

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or integration tests where appropriate
  • Backwards compatible: Works with existing data and configuration. Any breaking changes documented in the release notes.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@1yuv 1yuv requested review from jkuester and kennsippell January 5, 2024 19:45
Copy link
Member

@kennsippell kennsippell left a comment

Choose a reason for hiding this comment

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

Can you please add a test to capture this scenario clearly?

@@ -39,7 +39,7 @@ async function augmentDeclarativeWithNoolsBoilerplate(appSettings) {
}

const actualCoreVersion = await getValidApiVersion(appSettings);
const addNoolsBoilerplate = semver.lt(actualCoreVersion, '4.2.0-dev');
const addNoolsBoilerplate = actualCoreVersion && semver.lt(actualCoreVersion, '4.2.0-dev');
Copy link
Member

@kennsippell kennsippell Jan 6, 2024

Choose a reason for hiding this comment

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

I'm unclear on when actualCoreVersion would be falsy... Why?

It may not be safe to default to nools... for example: a partner using 3rd party library which isn't nools compatible upgrades to a cht-core verison with non-semver version. Now their config is broken when they redeploy...

Copy link
Member Author

Choose a reason for hiding this comment

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

Even though coerce tries to parse versions correctly, it'd be falsy when a custom version like tag number or branch number is being used on production. What do you suggest in this case to avoid scenarios like you mentioned? One option is to use base_Version which is only available in latest CHT versions and ensure this doesn't get changed. This issue was also caused because the way version was written was changed.

Copy link
Member

@kennsippell kennsippell Jan 8, 2024

Choose a reason for hiding this comment

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

Can you share the specific tags you're having trouble with please? I'm testing with coerce and not clear on what tags are failing. Maybe capture them in the test scenarios if they are special considerations that we need to think through?

Copy link
Member Author

Choose a reason for hiding this comment

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

This issue fix was needed for regular CHT versions as well like 4.5.0.6922454971, hence I introduced coerce for that fix. actualCoreVersion could still be falsy if production instances are running on versions like this (private). We won't need falsy check after introducing coerce. I don't see recent instances with unusual versioning though. I am not sure what coreVersion would've returned for particular versions like that since api/deploy-info endpoint has changed frequently.

src/lib/get-api-version.js Show resolved Hide resolved
@@ -20,6 +20,10 @@ describe('upload-app-settings', () => {

// case when testing on dev
{ coreVersion: '4.2.0-dev.1682192676689', isDeclarative: true, expectNools: false },
// https://github.com/medic/cht-conf/issues/596
{ coreVersion: '4.5.0.6922454971', isDeclarative: false, expectNools: false},
Copy link
Member

Choose a reason for hiding this comment

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

can you add the case for isDeclarative: true, expectNools: false with this weird build version? isn't that the case that crashed for you?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was failing with version 4.5.0.6922454971, if we pass weird build version, it'd faill.

Copy link
Member

@kennsippell kennsippell Jan 8, 2024

Choose a reason for hiding this comment

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

If I revert your changes in src, all these tests are still passing... This means that you have not sufficiently captured the scenario you care about in these tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right, because the fix was on getValidApiVersion() and in this example, we're mocking what getValidApiVersion() returns. Previously it was failing on getValidApiVersion() and failing upload-app-settings. I can add unit test for getApiVersion() method if that makes it more useful.

Copy link
Member

Choose a reason for hiding this comment

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

This isn't a super obvious requirement, so if you want it to not break in the future - it is typically nice to have a test which captures the requirement. Ya - that can be a unit test for getApiVersion or an integration test here (change what is mocked to be deeper).

Copy link
Contributor

@jkuester jkuester left a comment

Choose a reason for hiding this comment

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

I have nothing to add on top of what Kenn has said! Approving this preemptively so you can merge as soon as Kenn's concerns are resolved!

@1yuv 1yuv requested a review from kennsippell January 8, 2024 19:25
@1yuv
Copy link
Member Author

1yuv commented Jan 9, 2024

Hi @kennsippell , I've added few more scenarios for unit test. The original inetnt of this issue was to fix the scenarios where valid CHT core versions like 4.5.0.xxxx were not being parsed properly and an error was being thrown.

Before this fix, if you were running upload-app-settings against any CHT instance with 4.5.0, it'd fail because /api/deployinfo returns version 4.5.0.6922454971 causing actualCoreVersion to be falsy and crash when running semver.lt(). semver.coerce would correctly parse 4.5.0.6922454971 to 4.5.0 and fix the problem.

Even after adding coerce, I added check on if actualCoreVersion is undefined or not to stop it from failing.

const addNoolsBoilerplate = actualCoreVersion && semver.lt(actualCoreVersion, '4.2.0-dev');

However, if you think we should still crash the app and prevent users from running cht upload-app-settings in non-standard versions, I can remove that undefined check.

If you're looking for previous isntances where CHT version was not a valid semver, you can see these on this (pvt) scraper output.

Copy link
Member

@kennsippell kennsippell left a comment

Choose a reason for hiding this comment

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

Leave it to you to decide whether to add the last automated tests.

@@ -20,6 +20,10 @@ describe('upload-app-settings', () => {

// case when testing on dev
{ coreVersion: '4.2.0-dev.1682192676689', isDeclarative: true, expectNools: false },
// https://github.com/medic/cht-conf/issues/596
{ coreVersion: '4.5.0.6922454971', isDeclarative: false, expectNools: false},
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a super obvious requirement, so if you want it to not break in the future - it is typically nice to have a test which captures the requirement. Ya - that can be a unit test for getApiVersion or an integration test here (change what is mocked to be deeper).

@1yuv 1yuv merged commit bf7f647 into main Jan 10, 2024
12 checks passed
@1yuv 1yuv deleted the 596_semver_fix branch January 10, 2024 21:43
@1yuv
Copy link
Member Author

1yuv commented Jan 10, 2024

Oops, missed a colon again while merging, sending another PR to release @kennsippell , @jkuester

@medic-ci
Copy link
Collaborator

🎉 This PR is included in version 3.21.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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