From fc7943d40288ec8736950b7759a3a7953caa2ec8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:03:41 +0000 Subject: [PATCH 1/6] Initial plan From 12c94f2ce26db67227eb5014c9316e8c426b4c1e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:09:22 +0000 Subject: [PATCH 2/6] Add validation to prevent setting ApiVersion to Unknown in Set-PSResourceRepository Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com> --- src/code/SetPSResourceRepository.cs | 8 ++++++++ .../SetPSResourceRepository.Tests.ps1 | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/code/SetPSResourceRepository.cs b/src/code/SetPSResourceRepository.cs index d46c5ba48..91868af9e 100644 --- a/src/code/SetPSResourceRepository.cs +++ b/src/code/SetPSResourceRepository.cs @@ -162,6 +162,14 @@ protected override void ProcessRecord() PSRepositoryInfo.APIVersion? repoApiVersion = null; if (MyInvocation.BoundParameters.ContainsKey(nameof(ApiVersion))) { + if (ApiVersion == PSRepositoryInfo.APIVersion.Unknown) + { + ThrowTerminatingError(new ErrorRecord( + new ArgumentException("ApiVersion 'Unknown' is not a valid value for Set-PSResourceRepository. Valid values are: V2, V3, Local, NugetServer, ContainerRegistry"), + "InvalidApiVersion", + ErrorCategory.InvalidArgument, + this)); + } repoApiVersion = ApiVersion; } diff --git a/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 b/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 index fa9120dfe..c14df0cb1 100644 --- a/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 +++ b/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 @@ -345,15 +345,16 @@ Describe "Test Set-PSResourceRepository" -tags 'CI' { $repo.Priority | Should -Be 25 } - It "should not change ApiVersion of repository if -ApiVersion parameter was not used" { + It "should throw error when trying to set ApiVersion to unknown" { Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path $repo = Get-PSResourceRepository $TestRepoName1 $repoApiVersion = $repo.ApiVersion $repoApiVersion | Should -Be "local" - Set-PSResourceRepository -Name $TestRepoName1 -ApiVersion "unknown" -ErrorVariable err -ErrorAction SilentlyContinue + {Set-PSResourceRepository -Name $TestRepoName1 -ApiVersion "unknown" -ErrorAction Stop} | Should -Throw -ErrorId "InvalidApiVersion,Microsoft.PowerShell.PSResourceGet.Cmdlets.SetPSResourceRepository" + + # Verify the repository ApiVersion was not changed $repo = Get-PSResourceRepository $TestRepoName1 - $repo.ApiVersion | Should -Be "unknown" - $err.Count | Should -Be 0 + $repo.ApiVersion | Should -Be "local" } } From 4fe37256eec33a05ac43e2540b73dc62cbef9b18 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 21 Nov 2025 20:45:09 +0000 Subject: [PATCH 3/6] Add validation to prevent setting ApiVersion to Unknown in Register-PSResourceRepository Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com> --- src/code/RegisterPSResourceRepository.cs | 8 ++++++++ .../RegisterPSResourceRepository.Tests.ps1 | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/code/RegisterPSResourceRepository.cs b/src/code/RegisterPSResourceRepository.cs index 8d86face3..5b70c5899 100644 --- a/src/code/RegisterPSResourceRepository.cs +++ b/src/code/RegisterPSResourceRepository.cs @@ -145,6 +145,14 @@ protected override void ProcessRecord() PSRepositoryInfo.APIVersion? repoApiVersion = null; if (MyInvocation.BoundParameters.ContainsKey(nameof(ApiVersion))) { + if (ApiVersion == PSRepositoryInfo.APIVersion.Unknown) + { + ThrowTerminatingError(new ErrorRecord( + new ArgumentException("ApiVersion 'Unknown' is not a valid value for Register-PSResourceRepository. Valid values are: V2, V3, Local, NugetServer, ContainerRegistry"), + "InvalidApiVersion", + ErrorCategory.InvalidArgument, + this)); + } repoApiVersion = ApiVersion; } diff --git a/test/ResourceRepositoryTests/RegisterPSResourceRepository.Tests.ps1 b/test/ResourceRepositoryTests/RegisterPSResourceRepository.Tests.ps1 index 93df34b22..1b0aab6f5 100644 --- a/test/ResourceRepositoryTests/RegisterPSResourceRepository.Tests.ps1 +++ b/test/ResourceRepositoryTests/RegisterPSResourceRepository.Tests.ps1 @@ -404,6 +404,14 @@ Describe "Test Register-PSResourceRepository" -tags 'CI' { $res.ApiVersion | Should -Be 'v2' } + It "should throw error when trying to register repository with ApiVersion unknown" { + {Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path -ApiVersion "unknown" -ErrorAction Stop} | Should -Throw -ErrorId "InvalidApiVersion,Microsoft.PowerShell.PSResourceGet.Cmdlets.RegisterPSResourceRepository" + + # Verify the repository was not created + $repo = Get-PSResourceRepository $TestRepoName1 -ErrorAction SilentlyContinue + $repo | Should -BeNullOrEmpty + } + It "should register container registry repository with correct ApiVersion" { $ContainerRegistryName = "ACRRepo" $ContainerRegistryUri = "https://psresourcegettest.azurecr.io/" From 400298291e86fbc28c84a43dbd86a06c70ee28d9 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Fri, 21 Nov 2025 12:49:34 -0800 Subject: [PATCH 4/6] Update src/code/RegisterPSResourceRepository.cs --- src/code/RegisterPSResourceRepository.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/code/RegisterPSResourceRepository.cs b/src/code/RegisterPSResourceRepository.cs index 5b70c5899..9974a46e7 100644 --- a/src/code/RegisterPSResourceRepository.cs +++ b/src/code/RegisterPSResourceRepository.cs @@ -145,7 +145,6 @@ protected override void ProcessRecord() PSRepositoryInfo.APIVersion? repoApiVersion = null; if (MyInvocation.BoundParameters.ContainsKey(nameof(ApiVersion))) { - if (ApiVersion == PSRepositoryInfo.APIVersion.Unknown) { ThrowTerminatingError(new ErrorRecord( new ArgumentException("ApiVersion 'Unknown' is not a valid value for Register-PSResourceRepository. Valid values are: V2, V3, Local, NugetServer, ContainerRegistry"), From 5c9d21edfef7f44757437ecd91f495ca5bfb7c70 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Fri, 21 Nov 2025 13:07:32 -0800 Subject: [PATCH 5/6] Apply suggestions from code review --- src/code/RegisterPSResourceRepository.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/code/RegisterPSResourceRepository.cs b/src/code/RegisterPSResourceRepository.cs index 9974a46e7..8d86face3 100644 --- a/src/code/RegisterPSResourceRepository.cs +++ b/src/code/RegisterPSResourceRepository.cs @@ -145,13 +145,6 @@ protected override void ProcessRecord() PSRepositoryInfo.APIVersion? repoApiVersion = null; if (MyInvocation.BoundParameters.ContainsKey(nameof(ApiVersion))) { - { - ThrowTerminatingError(new ErrorRecord( - new ArgumentException("ApiVersion 'Unknown' is not a valid value for Register-PSResourceRepository. Valid values are: V2, V3, Local, NugetServer, ContainerRegistry"), - "InvalidApiVersion", - ErrorCategory.InvalidArgument, - this)); - } repoApiVersion = ApiVersion; } From c0547b6ec4790e40d413364bf6ee5418db606a31 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 21 Nov 2025 21:17:17 +0000 Subject: [PATCH 6/6] Add ValidateSet attribute to ApiVersion parameter and remove redundant validation code Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com> --- src/code/RegisterPSResourceRepository.cs | 1 + src/code/SetPSResourceRepository.cs | 9 +-------- .../RegisterPSResourceRepository.Tests.ps1 | 2 +- .../SetPSResourceRepository.Tests.ps1 | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/code/RegisterPSResourceRepository.cs b/src/code/RegisterPSResourceRepository.cs index 8d86face3..ddf5cad24 100644 --- a/src/code/RegisterPSResourceRepository.cs +++ b/src/code/RegisterPSResourceRepository.cs @@ -91,6 +91,7 @@ class RegisterPSResourceRepository : PSCmdlet, IDynamicParameters /// Specifies the Api version of the repository to be set. /// [Parameter(ParameterSetName = NameParameterSet)] + [ValidateSet("V2", "V3", "Local", "NugetServer", "ContainerRegistry")] public PSRepositoryInfo.APIVersion ApiVersion { get; set; } /// diff --git a/src/code/SetPSResourceRepository.cs b/src/code/SetPSResourceRepository.cs index 91868af9e..8dc17fe21 100644 --- a/src/code/SetPSResourceRepository.cs +++ b/src/code/SetPSResourceRepository.cs @@ -88,6 +88,7 @@ public SwitchParameter Trusted /// Specifies the Api version of the repository to be set. /// [Parameter(ParameterSetName = NameParameterSet)] + [ValidateSet("V2", "V3", "Local", "NugetServer", "ContainerRegistry")] public PSRepositoryInfo.APIVersion ApiVersion { get; set; } /// @@ -162,14 +163,6 @@ protected override void ProcessRecord() PSRepositoryInfo.APIVersion? repoApiVersion = null; if (MyInvocation.BoundParameters.ContainsKey(nameof(ApiVersion))) { - if (ApiVersion == PSRepositoryInfo.APIVersion.Unknown) - { - ThrowTerminatingError(new ErrorRecord( - new ArgumentException("ApiVersion 'Unknown' is not a valid value for Set-PSResourceRepository. Valid values are: V2, V3, Local, NugetServer, ContainerRegistry"), - "InvalidApiVersion", - ErrorCategory.InvalidArgument, - this)); - } repoApiVersion = ApiVersion; } diff --git a/test/ResourceRepositoryTests/RegisterPSResourceRepository.Tests.ps1 b/test/ResourceRepositoryTests/RegisterPSResourceRepository.Tests.ps1 index 1b0aab6f5..783457d55 100644 --- a/test/ResourceRepositoryTests/RegisterPSResourceRepository.Tests.ps1 +++ b/test/ResourceRepositoryTests/RegisterPSResourceRepository.Tests.ps1 @@ -405,7 +405,7 @@ Describe "Test Register-PSResourceRepository" -tags 'CI' { } It "should throw error when trying to register repository with ApiVersion unknown" { - {Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path -ApiVersion "unknown" -ErrorAction Stop} | Should -Throw -ErrorId "InvalidApiVersion,Microsoft.PowerShell.PSResourceGet.Cmdlets.RegisterPSResourceRepository" + {Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path -ApiVersion "unknown" -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.PSResourceGet.Cmdlets.RegisterPSResourceRepository" # Verify the repository was not created $repo = Get-PSResourceRepository $TestRepoName1 -ErrorAction SilentlyContinue diff --git a/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 b/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 index c14df0cb1..3a4d4f10c 100644 --- a/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 +++ b/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 @@ -351,7 +351,7 @@ Describe "Test Set-PSResourceRepository" -tags 'CI' { $repoApiVersion = $repo.ApiVersion $repoApiVersion | Should -Be "local" - {Set-PSResourceRepository -Name $TestRepoName1 -ApiVersion "unknown" -ErrorAction Stop} | Should -Throw -ErrorId "InvalidApiVersion,Microsoft.PowerShell.PSResourceGet.Cmdlets.SetPSResourceRepository" + {Set-PSResourceRepository -Name $TestRepoName1 -ApiVersion "unknown" -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.PSResourceGet.Cmdlets.SetPSResourceRepository" # Verify the repository ApiVersion was not changed $repo = Get-PSResourceRepository $TestRepoName1