-
Notifications
You must be signed in to change notification settings - Fork 55
Fix Npm version parsing for version with build numbers. #528
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -404,6 +404,13 @@ public virtual async Task<IPackageExistence> DetailedPackageVersionExistsAsync(P | |
|
|
||
| /// <inheritdoc /> | ||
| public virtual JsonElement? GetVersionElement(JsonDocument contentJSON, Version version) | ||
| { | ||
| string typeName = GetType().Name; | ||
| throw new NotImplementedException($"{typeName} does not implement GetVersions."); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public virtual JsonElement? GetVersionElement(JsonDocument contentJSON, string version) | ||
| { | ||
| string typeName = GetType().Name; | ||
| throw new NotImplementedException($"{typeName} does not implement GetVersions."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be "does not implement GetVersionElement". |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,7 @@ public class NPMProjectManagerTests | |
| { "https://registry.npmjs.org/%40somosme/webflowutils", Resources.unpublishedpackage_json }, | ||
| { "https://registry.npmjs.org/%40angular/core", Resources.angular_core_json }, | ||
| { "https://registry.npmjs.org/%40achievementify/client", Resources.achievementify_client_json }, | ||
| { "https://registry.npmjs.org/%40adguard/dnr-rulesets", Resources.adguard_dnr_rulesets_json }, | ||
| { "https://registry.npmjs.org/ds-modal", Resources.ds_modal_json }, | ||
| { "https://registry.npmjs.org/monorepolint", Resources.monorepolint_json }, | ||
| { "https://registry.npmjs.org/rly-cli", Resources.rly_cli_json }, | ||
|
|
@@ -414,6 +415,48 @@ public async Task GetPackagesFromOwnerAsyncSucceeds_Async(string owner, string e | |
| packages.Select(p => p.ToString()).Should().Contain(expectedPackage); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetVersionElement_WithNonStandardVersionFormatAsync() | ||
| { | ||
| // Test non-standard version format like "4.0.20260218200111" (can't be parsed as SemVer but can be compared as strings) | ||
| PackageURL purl = new("pkg:npm/%40adguard/dnr-rulesets"); | ||
| string? content = await _projectManager.Object.GetMetadataAsync(purl, useCache: false); | ||
| JsonDocument contentJSON = JsonDocument.Parse(content); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Additional line space is not needed here. |
||
| JsonElement? versionElement = _projectManager.Object.GetVersionElement(contentJSON, "4.0.20260218200111"); | ||
|
|
||
| Assert.NotNull(versionElement); | ||
| Assert.Equal("4.0.20260218200111", versionElement?.GetProperty("version").GetString()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4.0.20260218200111 is the version number? Do we also want to test the package name?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. [InlineData("pkg:npm/%40adguard/dnr-rulesets", "4.0.20260218200111")] This is the package in test |
||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("pkg:npm/lodash", "4.17.21")] | ||
| [InlineData("pkg:npm/%40angular/core", "13.2.6")] | ||
| [InlineData("pkg:npm/%40adguard/dnr-rulesets", "4.0.20260218200111")] | ||
| public async Task GetLatestVersionElement_WithValidJsonDocument_ReturnsLatestVersionElement(string purlString, string expectedLatestVersion) | ||
| { | ||
| // Test that GetLatestVersionElement returns the version element with the latest publish time | ||
| PackageURL purl = new(purlString); | ||
| string? content = await _projectManager.Object.GetMetadataAsync(purl, useCache: false); | ||
| JsonDocument contentJSON = JsonDocument.Parse(content); | ||
|
|
||
| JsonElement? latestVersionElement = _projectManager.Object.GetLatestVersionElement(contentJSON); | ||
|
|
||
| Assert.NotNull(latestVersionElement); | ||
|
|
||
| string? latestVersion = latestVersionElement?.GetProperty("version").GetString(); | ||
| Assert.Equal(expectedLatestVersion, latestVersion); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetLatestVersionElement_WithNullJsonDocument_ReturnsNull() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add another test for testing getting the latest version from the dist tag?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "GetLatestVersionElement_WithValidJsonDocument_ReturnsLatestVersionElement" is to test that scenario |
||
| { | ||
| // Test that GetLatestVersionElement returns null when given a null document | ||
| JsonElement? result = _projectManager.Object.GetLatestVersionElement(null); | ||
|
|
||
| Assert.Null(result); | ||
| } | ||
|
|
||
| private static void MockHttpFetchResponse( | ||
| HttpStatusCode statusCode, | ||
| string url, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this method defined twice?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the new method accepts string versions; I kept the original one for
Versiontypes for backwards compatibility