Skip to content

Stop asserting on the machine's whole cmd.exe population - #11

Merged
thisjustin816 merged 1 commit into
mainfrom
fix/stop-process-tree-flake
Jul 29, 2026
Merged

thisjustin816 merged 1 commit into
mainfrom
fix/stop-process-tree-flake

Conversation

@thisjustin816

@thisjustin816 thisjustin816 commented Jul 29, 2026 •

Copy link
Copy Markdown
Owner

Stop-DevProcess.Tests.ps1 asserted Get-Process cmd | Should -BeNullOrEmpty — a query across
every cmd.exe on the host, not the one the test started. Any shell a CI agent happens to be
running falsifies it, which is why the identical commit passed on the PR build and failed on main
twelve minutes later.

It now keeps the object from Start-Process -PassThru and asserts HasExited. That is strictly
stronger than a PID lookup: it cannot be fooled by a name collision, nor by PID reuse in the window
between the kill and the assertion.

Worth knowing: these tests are -Skip:(-not $script:isAdmin), so they never run on a non-admin
developer machine. CI is the only place they execute, and the only place this could have surfaced.

The parent-and-child test failed on main right after #10 merged, then passed on a
plain re-run. It asserts `Get-Process cmd` is empty, which is a query across every
cmd.exe on the host rather than the one the test started, so any shell a CI agent
happens to be running fails it. It now holds the process object from Start-Process
and checks HasExited, which no name collision or PID reuse can spoof. The test is
admin-gated, so it only ever runs in CI.

Reading Stop-ProcessTree to confirm the contract turned up a real bug next to it:
the per-id loop resolved the entire -ProcessId array instead of the current id, so
the first id stopped every requested process. Later ids were already dead by their
turn, Win32_Process reported no children for them, and their descendants were
orphaned rather than stopped. Only single-id pipeline calls happen today, which is
why it stayed hidden.

- Assert HasExited on the spawned process instead of a global process-name query
- Resolve $id, not $ProcessId, so each tree is walked before it is killed
- Add mocked Stop-ProcessTree tests, verified to fail against the previous line
- Bump to 1.4.1
@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Test Results

162 tests  +5   162 ✅ +5   8m 35s ⏱️ -33s
 55 suites +1     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 491478d. ± Comparison against base commit f304118.

This pull request removes 7 and adds 12 tests. Note that renamed tests count towards both.
Unit Tests.-Intent parameter set.should preserve compound compatibility intents("DarkCyan","SubHeader","message")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents("DarkGray","MutedDetail","    message")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents("Gray","ActionDetail","  message")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents("Gray","Detail","  message")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents(null,"Default","message")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents(null,"Usage","  message")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents(null,"UsageStep","    message")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents("DarkCyan","message","SubHeader")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents("DarkGray","    message","MutedDetail")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents("Gray","  message","ActionDetail")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents("Gray","  message","Detail")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents(null,"    message","UsageStep")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents(null,"  message","Usage")
Unit Tests.-Intent parameter set.should preserve compound compatibility intents(null,"message","Default")
Unit Tests.should look up each requested process on its own
Unit Tests.should not stop the current process or its parent
Unit Tests.should stop a child before its parent
…

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Summary

Summary
Generated on: 7/29/2026 - 9:46:46 PM
Coverage date: 7/29/2026 - 9:36:33 PM
Parser: JaCoCo
Assemblies: 2
Classes: 32
Files: 32
Line coverage: 92.8% (533 of 574)
Covered lines: 533
Uncovered lines: 41
Coverable lines: 574
Total lines: 2087
Covered branches: 0
Total branches: 0
Method coverage: Feature is only available for sponsors
Tag: 40_30490701092

Coverage

src/Private - 80%
Name Line Branch
src/Private 80% ****
src/Private/Get-UsernameSID 100%
src/Private/Invoke-Timeout 75%
src/Public - 93.2%
Name Line Branch
src/Public 93.2% ****
src/Public/Add-AzPipelinesPathEntry 100%
src/Public/ConvertFrom-EncryptedSecureString 100%
src/Public/ConvertTo-Psd1 100%
src/Public/Enable-Tls12 100%
src/Public/Export-Screenshot 100%
src/Public/Get-EnvironmentVariable 100%
src/Public/Get-PatPSCredential 100%
src/Public/Get-PSVersion 100%
src/Public/Get-TempDirectory 100%
src/Public/Initialize-GitConfig 100%
src/Public/Install-NugetCLI 100%
src/Public/Install-RequiredModule 100%
src/Public/Reset-ConsoleColor 100%
src/Public/Set-EnvironmentVariable 100%
src/Public/Set-JsonFile 100%
src/Public/Show-ConsoleColor 100%
src/Public/Start-CliProcess 87.8%
src/Public/Start-StopWatch 100%
src/Public/Start-Timeout 100%
src/Public/Stop-DevProcess 92.5%
src/Public/Stop-ProcessTree 100%
src/Public/Stop-Stopwatch 100%
src/Public/Test-CommandAvailable 100%
src/Public/Test-IsAdmin 100%
src/Public/Test-IsFileLocked 0%
src/Public/Test-IsNonInteractiveShell 0%
src/Public/Test-PSEnvironment 100%
src/Public/Uninstall-ProgramByName 92.1%
src/Public/Write-ConsoleMessage 94.8%
src/Public/Write-ProgressToHost 100%

@thisjustin816
thisjustin816 merged commit 195c52f into main Jul 29, 2026
7 checks passed
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