From 5ba0adef02c8f13aa0a43ac0a2f101180f18add8 Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Sun, 27 Sep 2026 14:47:49 -0500 Subject: [PATCH] ci: don't run the full test suite for pure export additions to PiHoleShell.psm1 Every feature PR adds its new functions' names to PiHoleShell.psm1's Export-ModuleMember list, which previously always forced the full Pester suite to run on a PR build - the one file nearly every PR touches was exactly the one that defeated the changed-file scoping added in an earlier PR. A pure addition to the export list can't break any existing, already-passing test, so only fall back to the full suite when an existing export was actually removed. Comparing whole diff lines doesn't work here since several exports share one line - adding a new function to an existing category's line shows as that whole line being removed and re-added, even though nothing already there was dropped. Instead, this extracts the quoted names from just the removed lines and just the added lines and compares those sets: a name that reappears in the added lines was only reformatted, not actually removed. Verified against real PR diffs from this session (via git worktree, without touching the live pipeline): a pure-addition change (adding Config's new functions to the Config category's existing line) correctly skips the fallback, and a synthetic removal correctly still triggers it. Co-Authored-By: Claude Sonnet 5 --- azuredevops-pihole-pester-tests.yml | 30 +++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/azuredevops-pihole-pester-tests.yml b/azuredevops-pihole-pester-tests.yml index 8c59fba..c954956 100644 --- a/azuredevops-pihole-pester-tests.yml +++ b/azuredevops-pihole-pester-tests.yml @@ -82,8 +82,34 @@ steps: foreach ($file in $changedFiles) { if ($runFullSuite) { break } - if ($file -match '^PiHoleShell/Private/' -or - $file -eq 'PiHoleShell/PiHoleShell.psm1' -or + if ($file -eq 'PiHoleShell/PiHoleShell.psm1') { + # A pure addition to the export list can't break any existing, already- + # passing test, so only fall back to the full suite when an existing + # export was actually removed. Comparing whole diff lines doesn't work + # here since several exports share one line - adding a new function to + # an existing category's line shows as that whole line being removed + # and re-added, even though nothing already there was dropped. Instead, + # extract the quoted names from just the removed lines and just the + # added lines and compare those sets: a name that reappears in the + # added lines was only reformatted, not actually removed. + $manifestDiff = git diff "origin/$targetBranch...HEAD" -- $file + if ($LASTEXITCODE -ne 0) { throw "git diff failed for '$file'" } + + $removedLines = ($manifestDiff | Where-Object { $_ -match '^-' -and $_ -notmatch '^---' }) -join "`n" + $addedLines = ($manifestDiff | Where-Object { $_ -match '^\+' -and $_ -notmatch '^\+\+\+' }) -join "`n" + $removedNames = [regex]::Matches($removedLines, "'([A-Za-z0-9-]+)'") | ForEach-Object { $_.Groups[1].Value } + $addedNames = [regex]::Matches($addedLines, "'([A-Za-z0-9-]+)'") | ForEach-Object { $_.Groups[1].Value } + + $trulyRemoved = $removedNames | Where-Object { $_ -notin $addedNames } + if ($trulyRemoved) { + Write-Host "Export(s) removed from $file ($($trulyRemoved -join ', ')) - running the full suite" + $runFullSuite = $true + } + else { + Write-Host "Only additions in $file - no full-suite fallback needed" + } + } + elseif ($file -match '^PiHoleShell/Private/' -or $file -eq 'PiHoleShell/PiHoleShell.psd1' -or $file -eq 'PiHoleShell/Public/Authentication/Request-PiHoleAuth.ps1' -or $file -eq 'tests/Initialize-PiHoleTestData.ps1' -or