fix(windows): replace removed wmic with PowerShell Get-CimInstance#4
Merged
Conversation
wmic was removed in Windows 11 24H2 / Server 2025 (the image GitHub's windows-latest runner now uses), so the constructor crashed with "Undefined array key 'Caption'" before any test could run. Swap to Get-CimInstance Win32_OperatingSystem (same data, supported successor) and emit the same Key=Value lines the existing parser expects. Also null-coalesce the Caption lookup so a missing key degrades to "not a Server" instead of throwing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two issues survived the first wmic→PowerShell swap on windows-latest:
1. Win32_OperatingSystem.Version came through empty on the new Server
image, so getWindowsVersion('') threw InvalidArgumentException from
the constructor. Read the version from [Environment]::OSVersion
instead, which is always populated.
2. -Command with single quotes inside a cmd.exe double-quoted argument
is fragile. Switch to -EncodedCommand (UTF-16LE base64) so the shell
never has to interpret the script, which removes a whole class of
future quoting regressions.
Also soften getWindowsVersion to return null on malformed input — the
constructor calls it unconditionally, so a throw there propagates as a
hard crash in any consumer that just wants to print system info.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
windows-latestGitHub runners now use Windows 11 24H2 / Server 2025 images wherewmichas been removed, soShell::exec('wmic os get …')returned'wmic' is not recognized…and theWindowsconstructor crashed withUndefined array key "Caption"before any test could run (see run 26057554808).Get-CimInstance Win32_OperatingSystem(the supported successor) via PowerShell, formatted to emit the sameCaption=… / Version=… / BuildNumber=…lines the existing parser already handles, so the rest of the file is unchanged.?? ''on theCaptionlookup so a future missing key degrades to "not a Server" rather than throwing.Test plan
windows-latestmatrix jobs pass alongside the existing ubuntu/macos ones🤖 Generated with Claude Code