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/2] 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/2] 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" } }