Repository navigation
ci: run every suite through one shuffled runner and rehearse releases - #81
Conversation
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
left a comment
There was a problem hiding this comment.
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 * * *' |
There was a problem hiding this comment.
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.
| $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 }) |
There was a problem hiding this comment.
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/ |
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
AfterAllfails 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 Unitprinted "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.mdhas 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
|
Follow-up review of the new commits on this branch. Verdict: approve. Both should-fix items are resolved. d65d978,
6f2d0ea: the redundant ScriptSecurity step is gone, and the comment now says the default rules cover those five. 99e05ac (on #79): the positional Nit on the new self-test in |
|
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.
"PSScriptAnalyzer security rules" step: removed in 6f2d0ea.
Nits
The run that could not be checked: run 45145177440 on this branch, after the two commits, passed all five jobs. |
Summary
The Pester steps of
quality-gates.ymlfailed onFailedCountandFailedContainersCountonly, so a failedBeforeAllorAfterAllpassed 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
Tests/Invoke-Tests.ps1, the one script that runs the suites, locally and in CI. It shuffles the order, fails unless Pester's result isPassedand 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).-ShuffleSeedruns an order again,-TestTypepicks the unit or the integration suites, and-ExcludeTagleaves tests out by tag. It runs on PowerShell 7 and on Windows PowerShell 5.1.tests,desktopandarm64jobs call that script in place of their own Pester configuration. Each uploads itsreportsfolder.rehearsaljob runs./Build/Publish-Module.ps1 -WhatIfon every pull request (CIC-10).release.ymlgets it too, throughworkflow_call.ScriptSecuritypreset, 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.Tests/Unit/Build/Invoke-Tests.Tests.ps1starts the script in a new process with a filter that leaves out every unit test and checks that it fails.$ErrorActionPreference = 'Stop'(CIC-05).MAX_LINE_LENGTHnamespowershell-style.instructions.md, the file that replacedstyle-enforcement.instructions.md, and the comment about a mirrored standards folder that no longer exists is gone.CLAUDE.md,CONTRIBUTING.mdand the Tests section ofREADME.mdname the script where they namedInvoke-Pester, andCHANGELOG.mdhas the entries.Verification
Run on Windows 11 26H2 with PowerShell 7.6.10 and Windows PowerShell 5.1.26100.
Tests/Invoke-Tests.ps1, Error and Warning: 0 findings. The standards'Test-StandardsCompliance.ps1on it: 0 findings.quality-gates.ymlhas the jobstests,desktop,arm64,helpandrehearsal.ScriptSecuritypreset 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 Unitprintedpassed 0, failed 0, skipped 0and ended with exit code 0 before the fix. It now ends withPester 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 withPester result is 'Failed'. Failed tests: 3. Failed blocks: 0. Failed files: 0. Run the same order with -ShuffleSeed 915623611., andtestResults.xml,coverage.xmland 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 onmainon 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.-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.ymlstarted by hand on this branch, run 44976510596:Tests and analysis,Windows PowerShell 5.1,Windows on ARM,Command helpand the newRelease rehearsalall passed. After the two changes above, run 45145177440 on this branch: the same five jobs passed.Notes
test/agent-log-event-order, soquality-gates.ymldoes not start for it by itself: the workflow triggers for pull requests intomain. The run above was started by hand on this branch.Tests/Invoke-Tests.ps1sets strict mode for itself, as ERR-01 requires of a script, and turns it off around theInvoke-Pestercall. Pester runs the test files in scopes below the script's, so they inherit its strict mode, and with it on 62 unit tests in 15 files fail (the breakdown is in a comment on Tests reload the module in every file and run longer than the limits (TST-05, TST-47) #70). The switch can go when Root module does not set strict mode or fail the import on a load error (ERR-02, ERR-03, MOD-05) #63, Tests reload the module in every file and run longer than the limits (TST-05, TST-47) #70 and Validation kit scripts lack strict mode, help and terminating errors (ERR-01, ERR-11, DOC-01, FUN-01) #71 are done. If the owner would sooner have the suites made ready for strict mode first, this pull request can wait for those.rehearsaljob needs no secret: no API key is read under-WhatIf.