Skip to content

ci: run every suite through one shuffled runner and rehearse releases - #81

Merged
fadwen merged 4 commits into
mainfrom
ci/standards-gates
Nov 23, 2026
Merged

fadwen merged 4 commits into
mainfrom
ci/standards-gates

Conversation

@fadwen

@fadwen fadwen commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

The Pester steps of quality-gates.yml failed on FailedCount and FailedContainersCount only, so a failed BeforeAll or AfterAll passed and so did a run that found no tests. Only the PowerShell 7 job was shuffled, the build tools were not installed at fixed versions, and the release was rehearsed only after a tag had been pushed. This change addresses the CI and test-run rules of ai-powershell-standards 2.0.0 that #62 lists, except the line endings, which follow in the next pull request of the stack. Refs #62.

Changes

  • New: Tests/Invoke-Tests.ps1, the one script that runs the suites, locally and in CI. It shuffles the order, fails unless Pester's result is Passed and at least one test passed or failed, so a run in which a filter leaves every test out fails too, enforces the 80 percent coverage gate with -CodeCoverage, and puts the seed in its failure message and in the job summary (TST-42, TST-46). -ShuffleSeed runs an order again, -TestType picks the unit or the integration suites, and -ExcludeTag leaves tests out by tag. It runs on PowerShell 7 and on Windows PowerShell 5.1.
  • The tests, desktop and arm64 jobs call that script in place of their own Pester configuration. Each uploads its reports folder.
  • Pester 6.2.0 and PSScriptAnalyzer 1.25.0 are installed at those exact versions in every job (CIC-02).
  • A new rehearsal job runs ./Build/Publish-Module.ps1 -WhatIf on every pull request (CIC-10). release.yml gets it too, through workflow_call.
  • The workflow also runs every night at 04:30 UTC (CIC-17).
  • The comment on the analyzer step records that the default rules at Error and Warning include the five rules of PSScriptAnalyzer's ScriptSecurity preset, so that step is the static analysis of a security gate (CIC-12). A separate step that ran the preset over the same files could report nothing more and was removed again. The workflow has no credential scan and no dependency scan; Standards rules that need a decision before any work (SEC-16, ERR-16, MOD-20, TST-43 and others) #74 holds that decision.
  • New: Tests/Unit/Build/Invoke-Tests.Tests.ps1 starts the script in a new process with a filter that leaves out every unit test and checks that it fails.
  • Every install step sets $ErrorActionPreference = 'Stop' (CIC-05).
  • The comment on MAX_LINE_LENGTH names powershell-style.instructions.md, the file that replaced style-enforcement.instructions.md, and the comment about a mirrored standards folder that no longer exists is gone.
  • CLAUDE.md, CONTRIBUTING.md and the Tests section of README.md name the script where they named Invoke-Pester, and CHANGELOG.md has the entries.

Verification

Run on Windows 11 26H2 with PowerShell 7.6.10 and Windows PowerShell 5.1.26100.

  • PSScriptAnalyzer 1.25.0 on Tests/Invoke-Tests.ps1, Error and Warning: 0 findings. The standards' Test-StandardsCompliance.ps1 on it: 0 findings.
  • Both workflow files parse as YAML; quality-gates.yml has the jobs tests, desktop, arm64, help and rehearsal.
  • All five rules of the ScriptSecurity preset have the severity Error or Warning in PSScriptAnalyzer 1.25.0 (Get-ScriptAnalyzerRule), and the analyzer step, which runs the default rules at those severities, reports 0 findings over the gated files.
  • ./Tests/Invoke-Tests.ps1 -TestType Unit -ExcludeTag Unit printed passed 0, failed 0, skipped 0 and ended with exit code 0 before the fix. It now ends with Pester ran no tests for 'Unit': 999 found, 0 skipped, 999 left out by a filter. and exit code 1, on PowerShell 7.6.10 and on Windows PowerShell 5.1.
  • ./Tests/Invoke-Tests.ps1 -CodeCoverage -OutputPath <folder> -SummaryPath <file> on PowerShell 7.6.10: 1,052 tests, 1,041 passed, 8 skipped, 3 failed, coverage 95.11 percent. The script ended with Pester result is 'Failed'. Failed tests: 3. Failed blocks: 0. Failed files: 0. Run the same order with -ShuffleSeed 915623611., and testResults.xml, coverage.xml and the summary were written before it did. The three failures are the ones Repair-IntuneScript corrupts an ANSI script on a host with a UTF-8 system code page #75 and In-box module table does not list UOPProviders, present on Windows 11 26H2 #76 describe, which fail on main on this computer and pass in CI.
  • ./Tests/Invoke-Tests.ps1 -OutputPath <folder> -SummaryPath <file> on Windows PowerShell 5.1: 1,052 tests, 1,005 passed, 44 skipped, 3 failed, the same three, and the same ending.
  • Started with -File, where the script's scope is the global scope, on both PowerShell versions with -TestType Unit: the two unit failures among those three, and exit code 1.
  • quality-gates.yml started by hand on this branch, run 44976510596: Tests and analysis, Windows PowerShell 5.1, Windows on ARM, Command help and the new Release rehearsal all passed. After the two changes above, run 45145177440 on this branch: the same five jobs passed.

Notes

The Pester steps of quality-gates.yml failed on FailedCount and
FailedContainersCount only, so a failed BeforeAll or AfterAll passed,
and so did a run that found no tests. Only the PowerShell 7 job was
shuffled, and locally the suites were run with a plain Invoke-Pester
call, unshuffled.

Tests/Invoke-Tests.ps1 is now the one way the suites are run. It
shuffles the order, fails unless Pester's result is Passed and at
least one test ran, enforces the coverage gate, and puts the seed in
its failure message and in the job summary. All three Pester jobs
call it. It sets strict mode for itself and turns it off around the
Pester run, because the suites, the validation kit and the module are
not written for strict mode yet.

The workflow also installs Pester 6.2.0 and PSScriptAnalyzer 1.25.0 at
fixed versions, checks the ScriptSecurity rules, rehearses the release
with Publish-Module.ps1 -WhatIf on every pull request, and runs every
night.

Refs #62

@fadwen fadwen left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes on the lines whose reason the diff does not show.

# Nightly, so that a change outside the repository shows up within a day: a new runner image,
# a Windows update that adds an in-box module, a Gallery that stops serving a pinned tool.
schedule:
- cron: '30 4 * * *'

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time is a free choice. 04:30 UTC is off the top of the hour, when scheduled workflows queue longest, and well before the downloads badge job at 06:17.

Comment thread .github/workflows/quality-gates.yml Outdated
$folders = 'Public', 'Private', 'PSScriptAnalyzer', 'Examples', 'Build', 'Tests', 'Validation'
$files = @(Get-ChildItem -Path $folders -Recurse -Include *.ps1, *.psm1, *.psd1 -File) +
@(Get-Item ./IntuneScriptLab.psd1, ./IntuneScriptLab.psm1)
$issues = @($files | ForEach-Object { Invoke-ScriptAnalyzer -Path $_.FullName -Settings ScriptSecurity })

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preset reports nothing on the 176 files today, so the step starts green. It runs at every severity because the preset is five rules that are all about credentials and hard-coded computer names.

path: |
testResults.xml
coverage.xml
path: reports/

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The artifact names are unchanged. The files inside are now testResults.xml and coverage.xml in each job, where the 5.1 and ARM64 jobs wrote testResults-desktop.xml and testResults-arm64.xml: the script writes fixed names into the folder it is given.

Comment thread Tests/Invoke-Tests.ps1
# mode, and when the script is started with -File this scope is the global one, which the
# module's functions see as well. The suites, the validation kit and the module are not yet
# written for strict mode (#63, #70, #71), so it is off for the run and on again after it.
Set-StrictMode -Off

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Measured before this line was added: with the script's strict mode left on, 62 of the 998 unit tests failed on PowerShell 7.6.10 when the script was called as a command, and when it was started with -File, where its scope is the global one, module functions failed as well. Turning it off in a child scope would not cover the second case, because the module's functions look up strict mode through the global scope, not through the scope that calls Pester.

@fadwen fadwen left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: changes requested (one should-fix before merge).

Reviewed against ai-powershell-standards. Re-checked in a Linux sandbox with pwsh 7.6.0, Pester 6.2.0 and PSScriptAnalyzer 1.25.0.

Verified

  • A failed AfterAll fails the run ("Failed blocks: 1", exit code 1).
  • The real seed is reported even with the default seed 0 (TST-46).
  • Pester 6.2.0 and PSScriptAnalyzer 1.25.0 pins (CIC-02).
  • Rehearsal job (CIC-10).
  • Nightly schedule (CIC-17).
  • $ErrorActionPreference = 'Stop' set in every install step (CIC-05).

Unverified: manual run 44976510596. I couldn't check it, and this PR has no checks because its base isn't main.

Contradicted: "fails when no tests ran" (TST-42). Line 194 of Tests/Invoke-Tests.ps1 checks $result.TotalCount, and that count includes tests a filter left out (NotRun).

  • Reproduced: -TestType Unit -ExcludeTag Unit printed "passed 0, failed 0, skipped 0" (Total=2, NotRun=2), exit code 0.
  • Suggested fix: if ($null -eq $result -or ($result.PassedCount + $result.FailedCount) -eq 0).
  • The standards' sample in powershell-pester.md has the same gap.

Should-fix: "PSScriptAnalyzer security rules" step. All five ScriptSecurity rules are Error or Warning severity, so the default-rules step already runs them. The new step only checks the same rules again.

  • Either say that in the comment and in the CIC-12 claim, or add a real credential scanner (gitleaks or trufflehog, per #74).

Nits

  • The rehearsal job doesn't check the rebuilt MAML against the committed copy (git diff --exit-code en-US), unless the help job already covers that.
  • The 5.1 job is now shuffled and includes the integration tests. That's right per TST-46, but some orders may fail at first.

Tests/Invoke-Tests.ps1 tested Pester's TotalCount to tell that no
tests ran. That count includes the tests a filter left out, and
Pester's result for a run of only those is Passed, so
-TestType Unit -ExcludeTag Unit printed "passed 0, failed 0, skipped
0" and ended with exit code 0. A gate that was started with the wrong
filter passed without running anything.

The script now counts the tests that passed or failed and fails when
there are none, after the check of Pester's result, so that a run
which failed discovery is still reported as that. A run in which every
test was skipped fails as well. The new test starts the runner in a
new process with a filter that leaves out every unit test.

Refs #62
The "PSScriptAnalyzer security rules" step ran the ScriptSecurity
preset over the files the step before it had just analyzed. All five
rules of that preset have the severity Error or Warning, so the
default rules at those severities already include them, and the step
could not report anything the first one had not.

The step is removed. The comment on the analyzer step says that it
covers the static analysis of a security gate and that the workflow
has no credential scan and no dependency scan, which is an open
decision in #74. The changelog no longer claims a separate check.

Refs #62
@fadwen

fadwen commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Follow-up review of the new commits on this branch.

Verdict: approve. Both should-fix items are resolved.

d65d978, Invoke-Tests.ps1: now fails when nothing ran.

  • -TestType Unit -ExcludeTag Unit exits 1 with "Pester ran no tests for 'Unit': 2 found, 0 skipped, 2 left out by a filter".
  • A normal run still exits 0.
  • The check comes after the Result check, so a discovery failure is still reported as a failure.

6f2d0ea: the redundant ScriptSecurity step is gone, and the comment now says the default rules cover those five.

99e05ac (on #79): the positional Join-Path calls are named (STY-30).

Nit on the new self-test in Tests/Unit/Build/Invoke-Tests.Tests.ps1: the child process discovers the whole unit suite, which adds noticeable time to every unit run (TST-47 sets a budget of 30 s). Pointing the child at a small fixture folder would be cheaper. That needs a -Path override on the runner, so it can wait.

@fadwen

fadwen commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Both findings of the review were confirmed and are fixed on this branch. The description above is updated to match.

"Fails when no tests ran" (TST-42): fixed in d65d978.

  • Reproduced on Windows: ./Tests/Invoke-Tests.ps1 -TestType Unit -ExcludeTag Unit printed passed 0, failed 0, skipped 0 and ended with exit code 0.
  • The script now counts the tests that passed or failed, as suggested. It does so after the check of Pester's result, so that a run which failed discovery is still reported as that and not as "no tests".
  • The same run now ends with Pester ran no tests for 'Unit': 999 found, 0 skipped, 999 left out by a filter. and exit code 1, on PowerShell 7.6.10 and on Windows PowerShell 5.1. A run in which every test is skipped fails too.
  • Tests/Unit/Build/Invoke-Tests.Tests.ps1 is the regression test: it starts the script in a new process with that filter.
  • The sample in the standards has the same gap. It is not changed here, because the installed standards files are replaced by the next sync (PRQ-33); that needs a change in the standards repository.

"PSScriptAnalyzer security rules" step: removed in 6f2d0ea.

  • Confirmed with Get-ScriptAnalyzerRule on PSScriptAnalyzer 1.25.0: PSAvoidUsingUsernameAndPasswordParams, PSAvoidUsingComputerNameHardcoded and PSAvoidUsingConvertToSecureStringWithPlainText are Error, PSAvoidUsingPlainTextForPassword and PSUsePSCredentialType are Warning.
  • The step ran those five rules over the same files as the step before it, so it could report nothing more. It is gone, not reworded.
  • The comment on the analyzer step now says that it is the static analysis of a security gate, and that the workflow has no credential scan and no dependency scan. Whether a scanner is added stays with Standards rules that need a decision before any work (SEC-16, ERR-16, MOD-20, TST-43 and others) #74. The changelog no longer claims a separate check.

Nits

  • Rebuilt MAML against the committed copy: the help job already does this. It builds the help with -SkipUpdate and fails when the result differs from en-US/IntuneScriptLab-Help.xml byte for byte, so the rehearsal job does not repeat it.
  • Shuffled 5.1 job with the integration tests: no order has failed so far on this branch or on the ones stacked on it.

The run that could not be checked: run 45145177440 on this branch, after the two commits, passed all five jobs.

Base automatically changed from test/agent-log-event-order to main November 23, 2026 10:09
@fadwen
fadwen merged commit c37036d into main Nov 23, 2026
5 checks passed
@fadwen
fadwen deleted the ci/standards-gates branch November 23, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant