Skip to content

test: decide the skip conditions of four tests during discovery - #85

Merged
fadwen merged 7 commits into
fix/process-tree-cleanupfrom
test/skip-at-discovery
Nov 23, 2026
Merged

fadwen merged 7 commits into
fix/process-tree-cleanupfrom
test/skip-at-discovery

Conversation

@fadwen

@fadwen fadwen commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

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 -Skip condition read a script-scoped variable that the file set in BeforeAll, and Pester evaluates -Skip during discovery, before any BeforeAll runs. A skipped test leaves the run Passed, so nothing reported it. The SYSTEM-context tests are the only ones that launch a script through a scheduled task as NT 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.ps1 decides whether the session is elevated in BeforeDiscovery.
  • Tests/Unit/Public/Test-IntuneWin32Rule.Tests.ps1 decides whether notepad.exe is there in BeforeDiscovery. BeforeAll still looks again before it copies the file, because a variable set during discovery does not reach the run.
  • CHANGELOG.md has the entry under Fixed.

Verification

  • On a lab device, as NT AUTHORITY\SYSTEM under Windows PowerShell 5.1.26100.9818: SystemContext.Tests.ps1 3 passed, 0 skipped, where the file as it was gave 0 passed, 3 skipped in the same session; Test-IntuneWin32Rule.Tests.ps1 23 passed, 0 skipped. No IntuneScriptLab-* scheduled task was left behind.
  • On Windows 11, not elevated, with PowerShell 7.6.10 and with Windows PowerShell 5.1: Test-IntuneWin32Rule.Tests.ps1 23 passed, 0 skipped, where it was 22 passed, 1 skipped; SystemContext.Tests.ps1 0 passed, 3 skipped, which is right for a session that is not elevated.
  • Invoke-ScriptAnalyzer with -Severity Error, Warning -ExcludeRule PSAvoidLongLines on 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, the Tests and analysis job 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.
  • The next run on this branch, 45145190738, failed in the Windows PowerShell 5.1 job: SYSTEM context.times out and cleans up the task ended with RemoteException: ERROR: The process "2020" not found. at Invoke-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

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
@fadwen
fadwen changed the base branch from fix/strict-mode-root-module to fix/process-tree-cleanup November 23, 2026 09:37

@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: approve after the workflow comment is corrected.

Verified

  • Closes #83: both files now decide their skip condition in BeforeDiscovery, and Pester evaluates -Skip during discovery (TST rules on Pester 6 discovery). Test-IntuneWin32Rule checks again in BeforeAll, 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 analysis and Windows PowerShell 5.1 each gained 3 passed tests from SystemContext.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 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.

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
@fadwen

fadwen commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

The workflow comments are corrected in 693aa7e, and this pull request has moved in the stack since the review.

Comments in quality-gates.yml: corrected.

  • Both said that the hosted runner's token is not elevated and that the SYSTEM-context tests skip in CI. The runner is elevated; the tests had been skipped by the defect this pull request fixes.
  • The header summary and the comment on the Windows PowerShell 5.1 step now say that the tests and desktop jobs run those tests, and that they register and remove IntuneScriptLab-* scheduled tasks as NT AUTHORITY\SYSTEM on the runner.

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 -ExcludeTag Elevated stays available if the time matters more on pull requests.

The checks that could not be made in the sandbox

  • CI on this branch after the commit: run 45151992404 passed all five jobs.
  • On a lab device as SYSTEM under Windows PowerShell 5.1, with the error preference Stop: the SYSTEM-context suite five times over, 15 passed and 0 failed with fix(harness): end a timed-out run without taskkill's errors #87, against 10 passed and 5 failed without it.

@fadwen

fadwen commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

The follow-up review was made against d710ce5. Both of its points are settled by commits that came after it.

@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.

Re-review after 693aa7e and the merges. Verdict: approve. The open should-fix is resolved.

  • Workflow comments (693aa7e): quality-gates.yml lines 11–12 and 190–191 now say that the hosted runner is elevated, and that the SYSTEM-context tests register and remove IntuneScriptLab-* scheduled tasks as SYSTEM on it.
  • Diff against #87: only this PR's change is left: the workflow comments, the CHANGELOG, and the two BeforeDiscovery blocks, which are unchanged from my earlier review.
  • Stacking: #87, with the -WhatIf:$false fix, 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.

@fadwen
fadwen merged commit d5bdffb into fix/process-tree-cleanup Nov 23, 2026
5 checks passed
@fadwen
fadwen deleted the test/skip-at-discovery branch November 23, 2026 10:37
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