diff --git a/.github/workflows/quality-gates.yml b/.github/workflows/quality-gates.yml index 41ffb01..717a811 100644 --- a/.github/workflows/quality-gates.yml +++ b/.github/workflows/quality-gates.yml @@ -5,10 +5,12 @@ # tests Windows, PowerShell 7. PSScriptAnalyzer at Error and Warning over the module, the # kit and the tests, the 115-character line limit, then the whole Pester suite (the # module's unit and integration suites and the validation kit's unit suite) with an -# 80% coverage gate over Public/ and Private/. Nothing here -# reaches a tenant: every Graph call in the suites goes through the mocked -# Invoke-IslGraphRequest seam, and the suites that need an elevated session, a lab -# account or a Graph connection skip themselves. +# 80% coverage gate over Public/ and Private/. Nothing here reaches a tenant: every +# Graph call in the suites goes through the mocked Invoke-IslGraphRequest seam, and +# the suites that need a lab account or a Graph connection skip themselves. The +# hosted Windows runner is elevated, so the SYSTEM-context tests run: they register +# scheduled tasks named IntuneScriptLab-* as NT AUTHORITY\SYSTEM on the runner, run +# a script through each and remove them. # # Every Pester run goes through Tests/Invoke-Tests.ps1, the script a developer runs as well. It # shuffles the order, so a test that only passes because of what ran before it fails here @@ -185,8 +187,9 @@ jobs: "Pester $((Get-Module Pester).Version) on PowerShell $($PSVersionTable.PSVersion)" | Write-Host # The integration suite as well: it launches the 5.1 hosts the harness uses on a device. - # The hosted runner's token is not elevated (IsInRole Administrator is false), so the - # SYSTEM-context tests skip here as they do under pwsh; they run on the lab devices + # The hosted runner is elevated, so the SYSTEM-context tests run here as they do under + # pwsh: they register and remove IntuneScriptLab-* scheduled tasks as SYSTEM on the runner. + # The user-context suite needs a lab account and skips itself. - name: Pester under Windows PowerShell 5.1 shell: powershell run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 302d74b..2d2e9b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,11 @@ entries are carried over from the manifest's release notes. process that is already gone on its error stream, and 5.1 made a terminating error of that line. The process tree is now ended without that stream reaching PowerShell as errors, and a warning is written when a process could not be ended. +- Four tests were skipped on every run: the three of the SYSTEM-context integration suite, which + are the only ones that launch a script through a scheduled task as SYSTEM, and the file-version + test of `Test-IntuneWin32Rule`. Their skip condition read a variable that was set only after + Pester had evaluated the condition. It is decided during discovery now, so the SYSTEM-context + suite runs in an elevated session and is skipped in any other. ## [0.34.0] - 2026-10-15 diff --git a/Tests/Integration/SystemContext.Tests.ps1 b/Tests/Integration/SystemContext.Tests.ps1 index 3e95942..4e2ad71 100644 --- a/Tests/Integration/SystemContext.Tests.ps1 +++ b/Tests/Integration/SystemContext.Tests.ps1 @@ -8,13 +8,18 @@ #pester:no-parallel +BeforeDiscovery { + # Pester evaluates -Skip during discovery, before any BeforeAll runs. Set there, this was still + # unset when the conditions read it, and the tests were skipped in an elevated session too + $identity = [Security.Principal.WindowsIdentity]::GetCurrent() + $script:IsAdmin = ([Security.Principal.WindowsPrincipal]$identity).IsInRole( + [Security.Principal.WindowsBuiltInRole]::Administrator) +} + BeforeAll { $script:ModuleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) Import-Module (Join-Path $script:ModuleRoot 'IntuneScriptLab.psd1') -Force . (Join-Path $script:ModuleRoot 'Tests\TestHelpers\TestHelpers.ps1') - $identity = [Security.Principal.WindowsIdentity]::GetCurrent() - $script:IsAdmin = ([Security.Principal.WindowsPrincipal]$identity).IsInRole( - [Security.Principal.WindowsBuiltInRole]::Administrator) } AfterAll { diff --git a/Tests/Unit/Public/Test-IntuneWin32Rule.Tests.ps1 b/Tests/Unit/Public/Test-IntuneWin32Rule.Tests.ps1 index 0a4db38..5766165 100644 --- a/Tests/Unit/Public/Test-IntuneWin32Rule.Tests.ps1 +++ b/Tests/Unit/Public/Test-IntuneWin32Rule.Tests.ps1 @@ -7,6 +7,13 @@ afterwards; the 32-bit registry view is read from a Windows value that differs between views. #> +BeforeDiscovery { + # Pester evaluates -Skip during discovery, before any BeforeAll runs, so the condition of the + # file-version test is decided here. BeforeAll looks again, because a variable set during + # discovery does not reach the run + $script:HasVersioned = Test-Path -LiteralPath (Join-Path $env:WINDIR 'System32\notepad.exe') +} + BeforeAll { $script:ModuleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) Import-Module (Join-Path $script:ModuleRoot 'IntuneScriptLab.psd1') -Force