From 5840fa6f6b2fbb00adf34d409022688d524ea22c Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 18 Feb 2025 01:18:33 -0500 Subject: [PATCH 1/7] fix install for a package from MAR that may have different version than its normalized version --- src/code/InstallHelper.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index e31c2b86c..8ac7fa8fe 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -824,6 +824,14 @@ private Hashtable BeginPackageInstall( pkgVersion += $"-{pkgToInstall.Prerelease}"; } } + + // For most repositories/providers the server will use the normalized version, which pkgVersion originally reflects + // However, for container registries the version must exactly match what was in the artifact manifest and then reflected in PSResourceInfo.Version.ToString() + if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.ContainerRegistry) + { + pkgVersion = pkgToInstall.Version.ToString(); + } + // Check to see if the pkg is already installed (ie the pkg is installed and the version satisfies the version range provided via param) if (!_reinstall) { From 177af2473208a0157e7957534fd4b4b8b9a720f5 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 18 Feb 2025 13:29:02 -0500 Subject: [PATCH 2/7] add find and install tests for 2 digit pkg --- ...SResourceContainerRegistryServer.Tests.ps1 | 20 +++++++++++ ...SResourceContainerRegistryServer.Tests.ps1 | 35 ++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 index b7ffdfb8e..f0e5b6edc 100644 --- a/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 @@ -8,6 +8,7 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { BeforeAll{ $testModuleName = "test-module" + $testModuleWith2DigitVersion = "test-2DigitPkg" $testModuleParentName = "test_parent_mod" $testModuleDependencyName = "test_dependency_mod" $testScriptName = "test-script" @@ -82,6 +83,25 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { $res.Count | Should -BeGreaterOrEqual 1 } + It "Find resource when version contains different number of digits than the normalized version" { + # the resource has version "1.0", but querying with any equivalent version should work + $res1DigitVersion = Find-PSResource -Name $testModuleWith2DigitVersion -Version "1" -Repository $ACRRepoName + $res1DigitVersion | Should -Not -BeNullOrEmpty + $res1DigitVersion.Version | Should -Be "1.0" + + $res2DigitVersion = Find-PSResource -Name $testModuleWith2DigitVersion -Version "1.0" -Repository $ACRRepoName + $res2DigitVersion | Should -Not -BeNullOrEmpty + $res2DigitVersion.Version | Should -Be "1.0" + + $res3DigitVersion = Find-PSResource -Name $testModuleWith2DigitVersion -Version "1.0.0" -Repository $ACRRepoName + $res3DigitVersion | Should -Not -BeNullOrEmpty + $res3DigitVersion.Version | Should -Be "1.0" + + $res4DigitVersion = Find-PSResource -Name $testModuleWith2DigitVersion -Version "1.0.0.0" -Repository $ACRRepoName + $res4DigitVersion | Should -Not -BeNullOrEmpty + $res4DigitVersion.Version | Should -Be "1.0" + } + It "Find module and dependencies when -IncludeDependencies is specified" { $res = Find-PSResource -Name $testModuleParentName -Repository $ACRRepoName -IncludeDependencies $res | Should -Not -BeNullOrEmpty diff --git a/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 index 2ade007f2..0dbf394f9 100644 --- a/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 @@ -10,6 +10,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { BeforeAll { $testModuleName = "test-module" $testModuleName2 = "test-module2" + $testModuleWith2DigitVersion = "test-2DigitPkg" $testCamelCaseModuleName = "test-camelCaseModule" $testCamelCaseScriptName = "test-camelCaseScript" $testModuleParentName = "test_parent_mod" @@ -33,7 +34,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { } AfterEach { - Uninstall-PSResource $testModuleName, $testModuleName2, $testCamelCaseModuleName, $testScriptName, $testCamelCaseScriptName -Version "*" -SkipDependencyCheck -ErrorAction SilentlyContinue + Uninstall-PSResource $testModuleName, $testModuleName2, $testCamelCaseModuleName, $testScriptName, $testCamelCaseScriptName, $testModuleWith2DigitVersion -Version "*" -SkipDependencyCheck -ErrorAction SilentlyContinue } AfterAll { @@ -75,6 +76,38 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $pkg.Version | Should -BeExactly "1.0.0" } + It "Install resource when version contains different number of digits than the normalized version- 1 digit specified" { + # the resource has version "1.0", but querying with any equivalent version should work + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1" -Repository $ACRRepoName + $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion + $res | Should -Not -BeNullOrEmpty + $res.Version | Should -Be "1.0" + } + + It "Install resource when version contains different number of digits than the normalized version- 2 digits specified" { + # the resource has version "1.0", but querying with any equivalent version should work + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.0" -Repository $ACRRepoName + $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion + $res | Should -Not -BeNullOrEmpty + $res.Version | Should -Be "1.0" + } + + It "Install resource when version contains different number of digits than the normalized version- 3 digits specified" { + # the resource has version "1.0", but querying with any equivalent version should work + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.0.0" -Repository $ACRRepoName + $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion + $res | Should -Not -BeNullOrEmpty + $res.Version | Should -Be "1.0" + } + + It "Install resource when version contains different number of digits than the normalized version- 4 digits specified" { + # the resource has version "1.0", but querying with any equivalent version should work + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.0.0.0" -Repository $ACRRepoName + $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion + $res | Should -Not -BeNullOrEmpty + $res.Version | Should -Be "1.0" + } + It "Install multiple resources by name" { $pkgNames = @($testModuleName, $testModuleName2) Install-PSResource -Name $pkgNames -Repository $ACRRepoName -TrustRepository From 35c9f946f4564d1a5330bfe5182f351aaaed2622 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 18 Feb 2025 14:52:19 -0500 Subject: [PATCH 3/7] add -TrustRepository to install tests --- .../InstallPSResourceContainerRegistryServer.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 index 0dbf394f9..fab2b912d 100644 --- a/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 @@ -78,7 +78,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { It "Install resource when version contains different number of digits than the normalized version- 1 digit specified" { # the resource has version "1.0", but querying with any equivalent version should work - Install-PSResource -Name $testModuleWith2DigitVersion -Version "1" -Repository $ACRRepoName + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1" -Repository $ACRRepoName -TrustRepository $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion $res | Should -Not -BeNullOrEmpty $res.Version | Should -Be "1.0" @@ -86,7 +86,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { It "Install resource when version contains different number of digits than the normalized version- 2 digits specified" { # the resource has version "1.0", but querying with any equivalent version should work - Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.0" -Repository $ACRRepoName + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.0" -Repository $ACRRepoName -TrustRepository $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion $res | Should -Not -BeNullOrEmpty $res.Version | Should -Be "1.0" @@ -94,7 +94,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { It "Install resource when version contains different number of digits than the normalized version- 3 digits specified" { # the resource has version "1.0", but querying with any equivalent version should work - Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.0.0" -Repository $ACRRepoName + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.0.0" -Repository $ACRRepoName -TrustRepository $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion $res | Should -Not -BeNullOrEmpty $res.Version | Should -Be "1.0" @@ -102,7 +102,7 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { It "Install resource when version contains different number of digits than the normalized version- 4 digits specified" { # the resource has version "1.0", but querying with any equivalent version should work - Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.0.0.0" -Repository $ACRRepoName + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.0.0.0" -Repository $ACRRepoName -TrustRepository $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion $res | Should -Not -BeNullOrEmpty $res.Version | Should -Be "1.0" From dd175718f84706ac070baa5d3d42967b19856cbe Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 18 Feb 2025 15:13:00 -0500 Subject: [PATCH 4/7] account for prerelease version when using manifest version --- src/code/InstallHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index 8ac7fa8fe..3e0d8ae9a 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -829,7 +829,7 @@ private Hashtable BeginPackageInstall( // However, for container registries the version must exactly match what was in the artifact manifest and then reflected in PSResourceInfo.Version.ToString() if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.ContainerRegistry) { - pkgVersion = pkgToInstall.Version.ToString(); + pkgVersion = String.IsNullOrEmpty(pkgToInstall.Prerelease) ? pkgToInstall.Version.ToString() : $"{pkgToInstall.Version.ToString()}-{pkgToInstall.Prerelease}"; } // Check to see if the pkg is already installed (ie the pkg is installed and the version satisfies the version range provided via param) From 336d9103c2fbaa5a304618adc2df5d32384a78ec Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 18 Feb 2025 15:38:56 -0500 Subject: [PATCH 5/7] add test for preview install --- .../InstallPSResourceContainerRegistryServer.Tests.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 index fab2b912d..5e4eb76ea 100644 --- a/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 @@ -108,6 +108,15 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $res.Version | Should -Be "1.0" } + It "Install resource when version contains different number of digits than the normalized version- 4 digits specified and prerelease" { + # the resource has version "1.0", but querying with any equivalent version should work + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.5.0.0" -Repository $ACRRepoName -TrustRepository + $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion + $res | Should -Not -BeNullOrEmpty + $res.Version | Should -Be "1.5" + $res.Prerelease | Should -Be "alpha" + } + It "Install multiple resources by name" { $pkgNames = @($testModuleName, $testModuleName2) Install-PSResource -Name $pkgNames -Repository $ACRRepoName -TrustRepository From f51a8b8cd930b65f9f0d1a4a40468e416aff47ff Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 18 Feb 2025 16:13:12 -0500 Subject: [PATCH 6/7] fix error in test logic --- .../InstallPSResourceContainerRegistryServer.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 index 5e4eb76ea..5f80ace08 100644 --- a/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1 @@ -108,9 +108,9 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' { $res.Version | Should -Be "1.0" } - It "Install resource when version contains different number of digits than the normalized version- 4 digits specified and prerelease" { + It "Install resource where version specified is a prerelease version" { # the resource has version "1.0", but querying with any equivalent version should work - Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.5.0.0" -Repository $ACRRepoName -TrustRepository + Install-PSResource -Name $testModuleWith2DigitVersion -Version "1.5-alpha" -Prerelease -Repository $ACRRepoName -TrustRepository $res = Get-InstalledPSResource -Name $testModuleWith2DigitVersion $res | Should -Not -BeNullOrEmpty $res.Version | Should -Be "1.5" From fa0880ba033b5f2aa9de908ff69840ab2d188cd7 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Tue, 25 Feb 2025 00:02:20 -0500 Subject: [PATCH 7/7] account for 2 digit version being concatenated with prerelease when creating version for .xml when installing --- src/code/Utils.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/code/Utils.cs b/src/code/Utils.cs index d51ba0fdb..89de7cd10 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -316,9 +316,11 @@ public static string GetNormalizedVersionString( string versionString, string prerelease) { - // versionString may be like 1.2.0.0 or 1.2.0 + // versionString may be like 1.2.0.0 or 1.2.0 or 1.2 // prerelease may be null or "alpha1" // possible passed in examples: + // versionString: "1.2" <- container registry 2 digit version + // versionString: "1.2" prerelease: "alpha1" <- container registry 2 digit version // versionString: "1.2.0" prerelease: "alpha1" // versionString: "1.2.0" prerelease: "" <- doubtful though // versionString: "1.2.0.0" prerelease: "alpha1" @@ -331,9 +333,10 @@ public static string GetNormalizedVersionString( int numVersionDigits = versionString.Split('.').Count(); - if (numVersionDigits == 3) + if (numVersionDigits == 2 || numVersionDigits == 3) { - // versionString: "1.2.0" prerelease: "alpha1" + // versionString: "1.2.0" prerelease: "alpha1" -> 1.2.0-alpha1 + // versionString: "1.2" prerelease: "alpha1" -> 1.2-alpha1 return versionString + "-" + prerelease; } else if (numVersionDigits == 4)