Skip to content

Commit

Permalink
DYN-7826: pm compatibility bug fix (#15651)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnenov authored Nov 14, 2024
1 parent 2c09b9d commit d40d4da
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/DynamoPackages/PackageManagerSearchElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ internal static bool IsVersionCompatible(Greg.Responses.Compatibility compatibil
bool isListedInVersions = compatibility.versions?.Contains(version.ToString()) ?? false;

// Parse min and max values, if provided, and check for valid range
bool isWithinMinMax = true;
bool isWithinMinMax = false;
if (!string.IsNullOrEmpty(compatibility.min) || !string.IsNullOrEmpty(compatibility.max))
{
Version minVersion = VersionUtilities.Parse(compatibility.min);
Version maxVersion = VersionUtilities.Parse(compatibility.max);

// if max is null, try to parse based on wildcard symantics
// if max is null, try to parse based on wildcard semantics
if(maxVersion == null)
{
maxVersion = VersionUtilities.WildCardParse(compatibility.max);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,32 @@ public void TestComputeVersionNoDynamoCompatibility()
Assert.IsNull(resultNoCompatibility, "Expected unknown compatibility (null) when no compatibility information is provided.");
}

[Test]
public void TestComputeVersionSingleCompatibility()
{
// Arrange
var hostOnlyCompatibilityMatrix = new List<Greg.Responses.Compatibility>
{
new Greg.Responses.Compatibility { name = "dynamo", versions = new List<string> { "3.2.2" } }
};

var compatibleDynamoVersion = new Version("3.2.2"); // Compatible with Dynamo 3.2.2
var incompatibleDynamoVersion = new Version("3.4.0"); // Incompatible with Dynamo 3.4.0

// Act
// Case 1: Single Dynamo version, compatible
var resultDynamoCompatibility = PackageManagerSearchElement.CalculateCompatibility(
hostOnlyCompatibilityMatrix, compatibleDynamoVersion, compatibilityMap);

// Case 2: Single Dynamo version, incompatible
var resultNoDynamoCompatibility = PackageManagerSearchElement.CalculateCompatibility(
hostOnlyCompatibilityMatrix, incompatibleDynamoVersion, compatibilityMap);

// Assert
Assert.IsTrue(resultDynamoCompatibility, "Expected compatible with matching Dynamo versions.");
Assert.IsFalse(resultNoDynamoCompatibility, "Expected incompatible with mismatched Dynamo versions.");
}

[Test]
public void HostCompatibilityFiltersExclusivity()
{
Expand Down Expand Up @@ -1162,6 +1188,20 @@ public void IsVersionCompatible_ExactVersionInList_ReturnsTrue()
Assert.IsTrue(result, "Expected compatibility to be true when version is in the list.");
}

[Test]
public void IsVersionCompatible_NoCompatibleVersion_ReturnsFalse()
{
var compatibility = new Greg.Responses.Compatibility
{
versions = new List<string> { "2.1.0", "2.3.0" }
};
Version version = new Version("2.2.0");

bool result = PackageManagerSearchElement.IsVersionCompatible(compatibility, version);

Assert.IsFalse(result, "Expected compatibility to be false when version is not in the list.");
}

[Test]
public void IsVersionCompatible_MinOnly_ReturnsTrueForCompatibleVersion()
{
Expand Down

0 comments on commit d40d4da

Please sign in to comment.