Repository navigation
test: decide the skip conditions of four tests during discovery - #85
Conversation
The three tests of the SYSTEM-context integration suite and the file-version test of Test-IntuneWin32Rule were skipped on every run, in an elevated session and on a computer that has notepad.exe as well. Their -Skip condition read a script-scoped variable that the file set in BeforeAll. Pester evaluates -Skip during discovery, before any BeforeAll runs, so the variable was unset, the condition was true, and a skipped test still leaves the run Passed. Both variables are now set in BeforeDiscovery, as the other suites with a skip condition do. The SYSTEM-context tests are the only ones that launch a script through a scheduled task as NT AUTHORITY\SYSTEM, so that path is tested again wherever the session is elevated. Refs #83
# Conflicts: # CHANGELOG.md
fadwen
left a comment
There was a problem hiding this comment.
Verdict: approve after the workflow comment is corrected.
Verified
- Closes #83: both files now decide their skip condition in
BeforeDiscovery, and Pester evaluates-Skipduring discovery (TST rules on Pester 6 discovery).Test-IntuneWin32Rulechecks again inBeforeAll, which is right: a variable set during discovery doesn't reach the run.
Unverified (needs Windows, a lab device or CI): the lab-device run as SYSTEM and CI run 45140123789. This PR has no checks because its base isn't main.
Should-fix: .github/workflows/quality-gates.yml, around line 188 on this branch
- The comment says "The hosted runner's token is not elevated (IsInRole Administrator is false), so the SYSTEM-context tests skip here".
- Your own CI figures show the opposite.
Tests and analysisandWindows PowerShell 5.1each gained 3 passed tests fromSystemContext.Tests.ps1, and the file went from 62 ms to 14 s. So the hosted runners are elevated, and the old skip had been hiding that. - Update that comment and the header summary at line 10. Say plainly that CI now registers and removes
IntuneScriptLab-*scheduled tasks as SYSTEM on the runner.
Nit: the timeout test adds about 5 s to every Windows job. If that's unwanted on pull requests, the runner already supports -ExcludeTag Elevated.
fadwen
left a comment
There was a problem hiding this comment.
Follow-up review. The base is now #87, and #87 has been merged into this branch. The test changes themselves are unchanged and still correct.
Verdict: still approve after the workflow comment is corrected. This should-fix is open from my last review.
The workflow comment is still stale. .github/workflows/quality-gates.yml line 188 on this branch still says: "The hosted runner's token is not elevated (IsInRole Administrator is false), so the SYSTEM-context tests skip here".
- This PR's own runs prove the opposite: the timeout test ran, and in run 45145190738 it failed on the 5.1 job.
- Correct that comment and the summary at line 10. Say that CI now registers and removes
IntuneScriptLab-*scheduled tasks as SYSTEM on the hosted runners.
Restacking on #87 is the right call: it keeps these tests from running without the cleanup fix.
Dependency on #87's should-fix: the timeout test in this suite would hang a session where $WhatIfPreference is $true until #87 passes -WhatIf:$false (see my review there).
Two comments in quality-gates.yml said that the hosted runner's token is not elevated and that the SYSTEM-context tests therefore skip in CI. They never ran because their skip condition was evaluated before its variable was set, not because of the runner: with the condition decided during discovery, the tests job and the Windows PowerShell 5.1 job each run the three tests, and the file takes 14 seconds where it took 62 milliseconds. The comments now say that the runner is elevated and that those jobs register and remove IntuneScriptLab-* scheduled tasks as SYSTEM on it. Refs #83
|
The workflow comments are corrected in 693aa7e, and this pull request has moved in the stack since the review. Comments in
What running these tests in CI found.
Nit, five seconds for the timeout test in every Windows job: left as it is. The test is the one that found #86, and The checks that could not be made in the sandbox
|
|
The follow-up review was made against d710ce5. Both of its points are settled by commits that came after it.
|
fadwen
left a comment
There was a problem hiding this comment.
Re-review after 693aa7e and the merges. Verdict: approve. The open should-fix is resolved.
- Workflow comments (693aa7e):
quality-gates.ymllines 11–12 and 190–191 now say that the hosted runner is elevated, and that the SYSTEM-context tests register and removeIntuneScriptLab-*scheduled tasks as SYSTEM on it. - Diff against #87: only this PR's change is left: the workflow comments, the CHANGELOG, and the two
BeforeDiscoveryblocks, which are unchanged from my earlier review. - Stacking: #87, with the
-WhatIf:$falsefix, is underneath, so the timeout test can't run without it.
Unverified: I couldn't check run 45153308602 (the SYSTEM-context tests on this branch) from the sandbox. Once #87 merges and this PR's base becomes main, its own checks will confirm it.
Summary
Four tests were skipped on every run, wherever they ran: the three tests of the SYSTEM-context integration suite and the file-version test of
Test-IntuneWin32Rule. Their-Skipcondition read a script-scoped variable that the file set inBeforeAll, and Pester evaluates-Skipduring discovery, before anyBeforeAllruns. A skipped test leaves the runPassed, so nothing reported it. The SYSTEM-context tests are the only ones that launch a script through a scheduled task asNT AUTHORITY\SYSTEM. Closes #83.This pull request is stacked on #87 (
fix/process-tree-cleanup) and merges after it. It was first stacked on #84. Once the SYSTEM-context tests ran in CI, the timeout test failed in one run out of two on Windows PowerShell 5.1, on a defect in the module's cleanup after a timeout (#86). #87 fixes that and sits below this change, so that these tests never run without it.Changes
Tests/Integration/SystemContext.Tests.ps1decides whether the session is elevated inBeforeDiscovery.Tests/Unit/Public/Test-IntuneWin32Rule.Tests.ps1decides whethernotepad.exeis there inBeforeDiscovery.BeforeAllstill looks again before it copies the file, because a variable set during discovery does not reach the run.CHANGELOG.mdhas the entry under Fixed.Verification
NT AUTHORITY\SYSTEMunder Windows PowerShell 5.1.26100.9818:SystemContext.Tests.ps13 passed, 0 skipped, where the file as it was gave 0 passed, 3 skipped in the same session;Test-IntuneWin32Rule.Tests.ps123 passed, 0 skipped. NoIntuneScriptLab-*scheduled task was left behind.Test-IntuneWin32Rule.Tests.ps123 passed, 0 skipped, where it was 22 passed, 1 skipped;SystemContext.Tests.ps10 passed, 3 skipped, which is right for a session that is not elevated.Invoke-ScriptAnalyzerwith-Severity Error, Warning -ExcludeRule PSAvoidLongLineson the two files: no findings.quality-gates.yml, dispatched on this branch (run 45140123789): all five jobs passed, and the four tests run there now. Against the run on fix(module): run under strict mode and fail the import on a load error #84, theTests and analysisjob went from 1,062 passed and 11 skipped to 1,066 passed and 7 skipped, the Windows PowerShell 5.1 job from 1,026 and 47 to 1,030 and 43, and the Windows on ARM job, which runs the unit suites only, from 1,017 and 2 to 1,018 and 1. The SYSTEM-context file took 62 ms on fix(module): run under strict mode and fail the import on a load error #84 and 14 s here.SYSTEM context.times out and cleans up the taskended withRemoteException: ERROR: The process "2020" not found.atInvoke-IslProcess.ps1:241. That is A timed-out run throws on Windows PowerShell 5.1 when the caller's error preference is Stop #86. With fix(harness): end a timed-out run without taskkill's errors #87 merged into this branch the workflow passed three times out of three (runs 45148797974, 45148802814 and 45148807467).Notes
BeforeDiscoveryor need no variable; Four tests never run: their -Skip condition reads a variable that BeforeAll sets after discovery #83 lists them.IntuneScriptLab-*, and the timeout test takes five seconds.