Skip to content
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
114 changes: 114 additions & 0 deletions dotnet/src/Devolutions.Pinget.Core.Tests/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class VersionCompareTests
[InlineData("0.98.1", "0.98.1", 0)]
[InlineData("10.0.0", "9.0.0", 1)]
[InlineData("1.3.18-stable", "1.3.17-stable", 1)]
[InlineData("25.4.1", "< 25.4.1", 1)]
[InlineData("< 25.4.1", "25.4.1", -1)]
public void CompareVersionStrings_ReturnsCorrectOrdering(string a, string b, int expected)
{
var result = RestSource.CompareVersionStrings(a, b);
Expand Down Expand Up @@ -1440,6 +1442,101 @@ public void BuildArguments_AppendsManifestAndCliSwitches()
Assert.Equal(["/i", @"C:\temp\ShareX.msi", "/quiet", "/norestart", "/log", @"C:\temp\winget.log", "ADDLOCAL=Core", "REBOOT=ReallySuppress", @"TARGETDIR=C:\Apps\ShareX"], args);
}

[Fact]
public void BuildArguments_CanOmitMsiTargetForDirectMsiExecution()
{
var installer = new Installer
{
InstallerType = "wix",
Switches = new InstallerSwitches
{
Log = "/log \"<LOGPATH>\"",
InstallLocation = "INSTALLDIR=\"<INSTALLPATH>\"",
}
};

var args = InstallerDispatch.BuildArguments(
"wix",
new InstallRequest
{
Query = new PackageQuery(),
Mode = InstallerMode.Silent,
LogPath = @"C:\temp\node.log",
InstallLocation = @"C:\Program Files\nodejs",
},
new Manifest { Id = "OpenJS.NodeJS.22", Name = "Node.js", Version = "22.22.3" },
installer,
@"C:\temp\node.msi",
includeMsiInstallTarget: false);

Assert.Equal(["/quiet", "/norestart", "/log", @"C:\temp\node.log", @"INSTALLDIR=C:\Program Files\nodejs"], args);
}

[Fact]
public void ParseMsiDirectArguments_EnablesUacOnlyForQuietUi()
{
var parsed = InstallerDispatch.ParseMsiDirectArguments([
"/quiet",
"/norestart",
"/log",
@"C:\temp\node.log",
@"INSTALLDIR=C:\Program Files\nodejs",
]);

Assert.Equal(0x102u, parsed.UiLevel);
Assert.Equal(@"REBOOT=ReallySuppress INSTALLDIR=""C:\Program Files\nodejs""", parsed.Properties);
Assert.Equal(@"C:\temp\node.log", parsed.LogPath);
}

[Fact]
public void ShouldRunMsiDirect_DisablesDirectMsiForMachineScopeSilentInstallers()
{
var request = new InstallRequest { Query = new PackageQuery(), Mode = InstallerMode.Silent };
var installer = new Installer { InstallerType = "wix", Scope = "machine" };

Assert.False(InstallerDispatch.ShouldRunMsiDirect(request, installer));
Assert.True(InstallerDispatch.ShouldElevateMsiShellExecute(installer));
}

[Fact]
public void InstallerDownloadIfRange_PrefersStrongEtagAndRejectsWeakEtag()
{
var strong = new Repository.InstallerDownloadMetadata(
"https://example.test/app.exe",
@"""abc""",
"Wed, 03 Jun 2026 21:00:00 GMT",
100,
50);
var weak = strong with { ETag = @"W/""abc""" };

Assert.Equal(@"""abc""", Repository.InstallerDownloadIfRange(strong));
Assert.Equal("Wed, 03 Jun 2026 21:00:00 GMT", Repository.InstallerDownloadIfRange(weak));
}

[Fact]
public void ParseContentRange_ValidatesResumeStartAndTotal()
{
var range = new System.Net.Http.Headers.ContentRangeHeaderValue(50, 99, 100);

Assert.Equal(100, Repository.ParseContentRange(range, 50));
Assert.Throws<InvalidOperationException>(() => Repository.ParseContentRange(range, 49));
}

[Fact]
public void InstallerDownloadSidecarPaths_AppendSuffixes()
{
Assert.Equal(@"C:\temp\installer.msi.part", Repository.SidecarPath(@"C:\temp\installer.msi", "part"));
Assert.Equal(@"C:\temp\installer.msi.part.json", Repository.SidecarPath(@"C:\temp\installer.msi", "part.json"));
}

[Fact]
public void JoinArguments_QuotesArgumentsWithSpaces()
{
Assert.Equal(
@"/quiet ""INSTALLDIR=C:\Program Files\nodejs"" ""VALUE=has \""quotes\""""",
InstallerDispatch.JoinArguments(["/quiet", @"INSTALLDIR=C:\Program Files\nodejs", "VALUE=has \"quotes\""]));
}

[Fact]
public void BuildArguments_UsesOverrideInsteadOfSynthesizedArguments()
{
Expand Down Expand Up @@ -1643,6 +1740,23 @@ public void MapArpVersionToCatalog_ReturnsNullWhenNoRangeMatches()
Assert.Null(Repository.MapArpVersionToCatalog(entries, ""));
}

[Fact]
public void LessThanLatestArpAnchoredVersion_HandlesCoarseDisplayVersion()
{
// Snagit 2025 reports ARP DisplayVersion `25.4.1`, but the catalog's
// latest ARP build is `25.4.1.10325`. winget renders this as
// installed `< 25.4.1` so the latest installer remains applicable.
var entries = new List<PreIndexedSource.V2VersionDataEntry>
{
new() { Version = "25.4.1", ArpMinVersion = "25.4.1.10325", ArpMaxVersion = "25.4.1.10325" },
new() { Version = "25.4.0", ArpMinVersion = "25.4.0", ArpMaxVersion = "25.4.0.8498" },
};

Assert.Null(Repository.MapArpVersionToCatalog(entries, "25.4.1"));
Assert.Equal("< 25.4.1", Repository.LessThanLatestArpAnchoredVersion(entries, "25.4.1"));
Assert.Null(Repository.LessThanLatestArpAnchoredVersion(entries, "25.4.0"));
}

[Fact]
public void LatestArpAnchoredVersion_SkipsInternalRows()
{
Expand Down
5 changes: 1 addition & 4 deletions dotnet/src/Devolutions.Pinget.Core/InstalledPackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static void CollectArpPackages(
var productCodes = new List<string>();
if (!string.IsNullOrWhiteSpace(productCode))
productCodes.Add(productCode);
if (LooksLikeProductCode(subkeyName))
if (!productCodes.Any(code => code.Equals(subkeyName, StringComparison.OrdinalIgnoreCase)))
productCodes.Add(subkeyName.ToLowerInvariant());

var upgradeCodes = new List<string>();
Expand Down Expand Up @@ -316,9 +316,6 @@ private static bool IsWindowsSystemPath(string? path)
return path.Trim().StartsWith(@"C:\Windows\", StringComparison.OrdinalIgnoreCase);
}

private static bool LooksLikeProductCode(string value) =>
value.StartsWith('{') && value.EndsWith('}');

private static (string Version, string FamilyName)? ParseMsixFullName(string fullName)
{
var parts = fullName.Split('_');
Expand Down
Loading
Loading