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 floating version comparison in new dependency resolver #6187

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1504,9 +1504,9 @@ public bool Equals(LibraryRange? x, LibraryRange? y)
break;
}

return typeConstraint1 == typeConstraint2 &&
VersionRangeComparer.Default.Equals(x.VersionRange, y.VersionRange) &&
x.Name.Equals(y.Name, StringComparison.OrdinalIgnoreCase);
return typeConstraint1 == typeConstraint2
&& x.Name.Equals(y.Name, StringComparison.OrdinalIgnoreCase)
&& x.VersionRange.Equals(y.VersionRange);
}

public int GetHashCode(LibraryRange obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,94 @@ await SimpleTestPackageUtility.CreatePackagesAsync(
result.Success.Should().BeFalse();
}

// Project1 -> A 1.0.* -> C 1.0.0
// B 1.0.* -> C 1.0.0
// Project2 -> C 1.0.*
[Theory]
[InlineData("*")]
[InlineData("1.*")]
[InlineData("1.0.*")]
public async Task RestoreCommand_WithTransitiveFloatingVersion_ResolvesCorrectly(string floatingVersion)
{
// Arrange
using var pathContext = new SimpleTestPathContext();

var packageA = new SimpleTestPackageContext("A", "1.0.0")
{
Dependencies =
[
new SimpleTestPackageContext("C", "1.0.0")
]
};

var packageB = new SimpleTestPackageContext("B", "1.0.0")
{
Dependencies =
[
new SimpleTestPackageContext("C", "1.0.0")
]
};

var packageC101 = new SimpleTestPackageContext("C", "1.0.1");

await SimpleTestPackageUtility.CreateFolderFeedV3Async(
pathContext.PackageSource,
PackageSaveMode.Defaultv3,
packageA,
packageB,
packageC101);

var project2Spec = ProjectTestHelpers.GetPackageSpecWithProjectNameAndSpec(
"Project2",
pathContext.SolutionRoot,
@"
{
""frameworks"": {
""net472"": {
""dependencies"": {
""C"": """ + floatingVersion + @""",
}
}
}
}");

var project1Spec = ProjectTestHelpers.GetPackageSpecWithProjectNameAndSpec(
"Project1",
pathContext.SolutionRoot,
@"
{
""frameworks"": {
""net472"": {
""dependencies"": {
""A"": ""1.0.*"",
""B"": ""1.0.*""
}
}
}
}")
.WithTestProjectReference(project2Spec);

// Act & Assert
(var result, _) = await ValidateRestoreAlgorithmEquivalency(pathContext, project1Spec, project2Spec);

// Additional assert
result.Success.Should().BeTrue();
result.LogMessages.Should().BeEmpty();
result.LockFile.Targets.Should().HaveCount(1);
result.LockFile.Targets[0].Libraries.Should().HaveCount(4);
result.LockFile.Targets[0].Libraries[0].Name.Should().Be("A");
result.LockFile.Targets[0].Libraries[0].Version.Should().Be(new NuGetVersion("1.0.0"));

result.LockFile.Targets[0].Libraries[1].Name.Should().Be("B");
result.LockFile.Targets[0].Libraries[1].Version.Should().Be(new NuGetVersion("1.0.0"));

result.LockFile.Targets[0].Libraries[2].Name.Should().Be("C");
result.LockFile.Targets[0].Libraries[2].Version.Should().Be(new NuGetVersion("1.0.1"));

result.LockFile.Targets[0].Libraries[3].Name.Should().Be("Project2");
result.LockFile.Targets[0].Libraries[3].Version.Should().Be(new NuGetVersion("1.0.0"));
}

// P1 -> P2 -> B *
// P1 -> A -> B 1.0.0
[Theory]
Expand Down