Skip to content

test: leave the tests that start processes out of the unit run - #157

Merged
fadwen merged 2 commits into
mainfrom
test/unit-time-budget
Nov 26, 2026
Merged

fadwen merged 2 commits into
mainfrom
test/unit-time-budget

Conversation

@fadwen

@fadwen fadwen commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of #70 (TST-47: the unit tests run in less than 30 seconds). The unit run took 157 seconds on a Windows 11 laptop, and 134 of them went to 28 files whose time came from tests that start processes: child imports of the module, hosts and scheduled tasks launched for real, scripts run as a caller would run them, a child Pester run. Those are integration tests that sit in the unit folders. This tags them, leaves them out of the unit run, and takes the waiting out of the mocked tests that remain. The unit run now takes 69 seconds in one process; the 30-second budget is not reached, and the Notes say what is left.

Changes

  • A test that starts a process, reads the real machine (CIM, the registry, logon sessions) or runs a script through Invoke-CallerScript is tagged Integration where it is: the child imports and the 5.1 load test of Module.Contract, the real runs of Module.WhatIf, Invoke-Tests.Tests.ps1, the process trees of Stop-IslProcessTree, the real child processes of Invoke-IslProcess, Get-IslDeviceFact and the machine readings of Get-IslFilterDeviceFact and Get-IslLogonSession, the host comparisons of Get-IslInboxModule and Get-IslCoreOnlyFeature, and the calling-script test of seven public commands. The two host comparisons had their host queries in the file's BeforeAll; they moved into the tagged context, so the unit run does not start the hosts either.
  • Tests/Invoke-Tests.ps1: -TestType Unit leaves the tag out unless -Tag Integration asks for it; -TestType Integration runs every test with the tag, in Tests/Integration and in the unit folders, and with -Tag of the caller's own keeps to Tests/Integration, since Pester's tag filter takes a test with any one tag; All is unchanged. The job summary heading names the tags. Tests/Unit/Build/Invoke-Tests.Tests.ps1 runs a copy of the runner on a fixture repository for six combinations and checks the exact tests each runs.
  • Invoke-IslProcess.Tests.ps1: the contexts that fake the Task Scheduler mock Get-Date and Start-Sleep with a clock of their own (TST-31). The polling loop no longer sleeps, and the two tests of a task that never starts check that the module gave up after about five seconds of its clock instead of waiting them out. The file's unit part takes 4.5 seconds instead of 18.
  • Module.WhatIf.Tests.ps1: the syntax-tree scan reads the module's own commands from inside it. From the test's scope Get-Command could not see the 111 private functions it was asked for, and searched every module on the path for each: 9.4 of the test's 10 seconds. It takes 2.3 now and checks the same calls.
  • Build/Invoke-Build.ps1 runs the tagged tests after the unit tests, in PowerShell 7 and in Windows PowerShell 5.1, so the build checks what it checked before. The ARM job runs them in a second run; the tests and 5.1 jobs run everything already.
  • CLAUDE.md, CONTRIBUTING.md (both add the tagged run to the 5.1 step before a push) and CHANGELOG.md.

Verification

  • ./Tests/Invoke-Tests.ps1 -TestType Unit on PowerShell 7.6: 2,211 passed in 78 seconds through the runner; 69 seconds in one process (Pester's discovery 4.1 s, framework 14.3 s, tests 50.2 s), against 157 before.
  • ./Build/Invoke-Build.ps1: help and rule reference unchanged, PSScriptAnalyzer clean in 355 files; PowerShell 7.6 unit 2,211 passed and tagged 57 passed; Windows PowerShell 5.1 unit 2,175 passed (37 skipped) and tagged 57 passed; no failures. Before the six selection tests were added, 2,211 + 51 and 2,175 + 51 were the counts of the single runs before this change.

Notes

TST-47. A test that starts a process, reads the real machine or runs a script as a caller would is tagged Integration, and Tests/Invoke-Tests.ps1 -TestType Unit leaves it out; -TestType Integration runs it with the integration suites. The scheduled-task tests of Invoke-IslProcess run on a clock of their own instead of waiting on the real one, and the WhatIf syntax scan reads the module's commands from inside it instead of searching every module for each private one. The unit run takes 69 seconds instead of 157 on a Windows 11 laptop; the build and the ARM job run the tagged tests in a run of their own.

Part of #70

@fadwen-ai fadwen-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Moving the tagged tests out of the unit run looks sound: I checked the mocked clock against the polling loop in Invoke-IslProcess, the moved BeforeAll blocks and the discovery-time -Skip flags, and the build and ARM runs that bring the tagged tests back. There are four small findings, all nits:

  1. Tests/Invoke-Tests.ps1:178: -TestType Integration -Tag <X> now also runs unit-folder tests tagged X, because the tag filter is an OR and Integration is added only when no tag is given.
  2. .github/workflows/quality-gates.yml:228: the second ARM run writes the same job-summary heading (Pester, Unit tests, ...) as the first.
  3. CLAUDE.md:171: the pre-push 5.1 command in Checks (-TestType Unit) now skips the process tests, including the 5.1 load test.
  4. Tests/Invoke-Tests.ps1:168: no test covers the new way the runner picks Unit and Integration tests.

Out of scope: none

🤖 Generated with Claude Code

Comment thread Tests/Invoke-Tests.ps1 Resolved
Comment thread .github/workflows/quality-gates.yml Resolved
Comment thread CLAUDE.md Resolved
Comment thread Tests/Invoke-Tests.ps1 Resolved
… summary, test the selection

Pester's tag filter takes a test with any one tag, so -TestType Integration with tags of the caller's own brought unit tests with those tags; with -Tag it keeps to Tests/Integration again. The job summary heading names the tags, so the ARM job's two unit runs can be told apart. Invoke-Tests.Tests.ps1 runs a copy of the runner on a fixture repository for each test type. CLAUDE.md and CONTRIBUTING.md add the tagged run to the 5.1 step before a push.
@fadwen

fadwen commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

Round 1: 4 fixed, 0 not changed.

  • Tests/Invoke-Tests.ps1:178: with -Tag, -TestType Integration keeps to Tests/Integration.
  • .github/workflows/quality-gates.yml:228: the summary heading names the tags.
  • CLAUDE.md:171: the 5.1 pre-push block runs the tagged tests too, as CONTRIBUTING.md now does.
  • Tests/Invoke-Tests.ps1:168: six selection cases on a fixture repository, passing on PowerShell 7.6 and 5.1.

./Build/Invoke-Build.ps1: PowerShell 7.6 unit 2,211 and tagged 57 passed; Windows PowerShell 5.1 unit 2,175 and tagged 57 passed; no failures; PSScriptAnalyzer clean. New head 1b1ddd9.

🤖 Generated with Claude Code

@fadwen-ai fadwen-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of 1b1ddd9 against main: all four round-1 findings are fixed and their threads are resolved.

  • With -Tag, -TestType Integration keeps to Tests/Integration, and the help says so.
  • The job-summary heading names the tags, so the second ARM run is labelled Unit tests tagged Integration.
  • The 5.1 pre-push blocks in CLAUDE.md and CONTRIBUTING.md run the tagged tests too.
  • Invoke-Tests.Tests.ps1 checks the exact tests that six selections run on a fixture repository. I ran the file at this head on PowerShell 7.6: 7 passed, 0 failed.

I found nothing new in the rest of the diff. The PR description matches the code.

Out of scope: none

🤖 Generated with Claude Code

@fadwen
fadwen merged commit 3286094 into main Nov 26, 2026
5 checks passed
@fadwen
fadwen deleted the test/unit-time-budget branch November 26, 2026 03:05
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.

2 participants