From 40453a5be59a45d4b14d803e7c0e317f02aede86 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Tue, 27 Oct 2026 18:09:23 +0000 Subject: [PATCH 1/3] Add targeted test file option to build script --- build.ps1 | 4 ++++ build.psm1 | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index 5dade48fe..f05e1cbc7 100644 --- a/build.ps1 +++ b/build.ps1 @@ -30,6 +30,9 @@ param( [Parameter(Mandatory=$true,ParameterSetName='Test')] [switch] $Test, + [Parameter(ParameterSetName='Test')] + [string] $TestPath, + [Parameter(ParameterSetName='Test')] [switch] $InProcess, [string] $WithPowerShell, @@ -88,6 +91,7 @@ END { "Test" { $testArgs = @{ InProcess = $InProcess + TestPath = $TestPath WithPowerShell = $WithPowerShell Verbose = $verboseWanted } diff --git a/build.psm1 b/build.psm1 index 041b207a9..39d02c07f 100644 --- a/build.psm1 +++ b/build.psm1 @@ -296,6 +296,7 @@ function Test-ScriptAnalyzer [CmdletBinding()] param ( [switch] $InProcess, + [string] $TestPath, [string] $WithPowerShell ) @@ -318,7 +319,16 @@ function Test-ScriptAnalyzer # # $testModulePath = Join-Path "${projectRoot}" -ChildPath out - $testScripts = "'${projectRoot}\Tests\Build','${projectRoot}\Tests\Engine','${projectRoot}\Tests\Rules','${projectRoot}\Tests\Documentation'" + if ($TestPath) { + $resolvedTestPath = (Resolve-Path -LiteralPath $TestPath -ErrorAction Stop).Path + if ((Get-Item -LiteralPath $resolvedTestPath).PSIsContainer) { + throw "TestPath must point to a test file." + } + $testScripts = "'{0}'" -f $resolvedTestPath.Replace("'", "''") + } + else { + $testScripts = "'${projectRoot}\Tests\Build','${projectRoot}\Tests\Engine','${projectRoot}\Tests\Rules','${projectRoot}\Tests\Documentation'" + } try { $savedModulePath = $env:PSModulePath $env:PSModulePath = "${testModulePath}{0}${env:PSModulePath}" -f [System.IO.Path]::PathSeparator From 6a4cc32fb46e66ce2b45e06457862b779f5b8beb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:20:14 +0000 Subject: [PATCH 2/3] Add Test-ScriptAnalyzer path selection tests Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Tests/Build/BuildModule.tests.ps1 | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Tests/Build/BuildModule.tests.ps1 b/Tests/Build/BuildModule.tests.ps1 index ebc4e2a6a..8c2f13f40 100644 --- a/Tests/Build/BuildModule.tests.ps1 +++ b/Tests/Build/BuildModule.tests.ps1 @@ -48,6 +48,56 @@ Describe "Build Module Tests" { } } + Context "Test-ScriptAnalyzer test path selection" { + BeforeEach { + Mock Invoke-Pester { $Path } -ModuleName build + } + + It "selects only the supplied test file" { + $testPath = Join-Path $TestDrive "single.tests.ps1" + New-Item -Path $testPath -ItemType File | Out-Null + + $selectedPaths = @(Test-ScriptAnalyzer -InProcess -TestPath $testPath) + + $selectedPaths.Count | Should -Be 1 + $selectedPaths[0] | Should -Be (Resolve-Path -LiteralPath $testPath).Path + } + + It "passes test paths containing apostrophes intact" { + $testPath = Join-Path $TestDrive "one'two.tests.ps1" + New-Item -Path $testPath -ItemType File | Out-Null + + $selectedPaths = @(Test-ScriptAnalyzer -InProcess -TestPath $testPath) + + $selectedPaths.Count | Should -Be 1 + $selectedPaths[0] | Should -Be (Resolve-Path -LiteralPath $testPath).Path + } + + It "fails when the supplied test path does not exist" { + { Test-ScriptAnalyzer -InProcess -TestPath (Join-Path $TestDrive "missing.tests.ps1") } | Should -Throw + } + + It "fails when the supplied test path is a directory" { + { Test-ScriptAnalyzer -InProcess -TestPath $TestDrive } | Should -Throw "TestPath must point to a test file." + } + + It "selects the four default test suite directories when no path is supplied" { + $selectedPaths = @(Test-ScriptAnalyzer -InProcess) + $repoRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..\..")).Path + $expectedPaths = @( + "${repoRoot}\Tests\Build" + "${repoRoot}\Tests\Engine" + "${repoRoot}\Tests\Rules" + "${repoRoot}\Tests\Documentation" + ) + + $selectedPaths.Count | Should -Be 4 + foreach ($expectedPath in $expectedPaths) { + $selectedPaths | Should -Contain $expectedPath + } + } + } + Context "Test result functions" { BeforeAll { $xmlFile = @' From 9252e0adb0fb040fc2ba99a4544615c6353449ed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:27:55 +0000 Subject: [PATCH 3/3] Use provider paths for test selection Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Tests/Build/BuildModule.tests.ps1 | 4 ++-- build.psm1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Build/BuildModule.tests.ps1 b/Tests/Build/BuildModule.tests.ps1 index 8c2f13f40..c5efbd819 100644 --- a/Tests/Build/BuildModule.tests.ps1 +++ b/Tests/Build/BuildModule.tests.ps1 @@ -60,7 +60,7 @@ Describe "Build Module Tests" { $selectedPaths = @(Test-ScriptAnalyzer -InProcess -TestPath $testPath) $selectedPaths.Count | Should -Be 1 - $selectedPaths[0] | Should -Be (Resolve-Path -LiteralPath $testPath).Path + $selectedPaths[0] | Should -Be (Resolve-Path -LiteralPath $testPath).ProviderPath } It "passes test paths containing apostrophes intact" { @@ -70,7 +70,7 @@ Describe "Build Module Tests" { $selectedPaths = @(Test-ScriptAnalyzer -InProcess -TestPath $testPath) $selectedPaths.Count | Should -Be 1 - $selectedPaths[0] | Should -Be (Resolve-Path -LiteralPath $testPath).Path + $selectedPaths[0] | Should -Be (Resolve-Path -LiteralPath $testPath).ProviderPath } It "fails when the supplied test path does not exist" { diff --git a/build.psm1 b/build.psm1 index 39d02c07f..17d364f59 100644 --- a/build.psm1 +++ b/build.psm1 @@ -320,7 +320,7 @@ function Test-ScriptAnalyzer # $testModulePath = Join-Path "${projectRoot}" -ChildPath out if ($TestPath) { - $resolvedTestPath = (Resolve-Path -LiteralPath $TestPath -ErrorAction Stop).Path + $resolvedTestPath = (Resolve-Path -LiteralPath $TestPath -ErrorAction Stop).ProviderPath if ((Get-Item -LiteralPath $resolvedTestPath).PSIsContainer) { throw "TestPath must point to a test file." }