Skip to content

refactor(machine-health): simplify audit Windows checks and lib helpers (4 of 9) - #15258

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14646-42956282760-1
Nov 11, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14646-42956282760-1

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14646

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Applied behavior-preserving simplifications to 8 of the 15 listed machine-health audit scripts: merged WARN/INFO ladders that print the same message, removed checks that a later expression already makes redundant, merged the JSONC comment stripper's string-state branches so each character is appended in one place, and replaced list-builder boilerplate with array expressions. Test-TpmBitLocker.ps1 is unchanged, as the issue requires. The other six listed files (Add-TodoProposal, Assert-ApprovalState, Assert-CheckResult, Assert-StateBaseLocation, ConvertFrom-FileTimeBytes, Enter-RunLock) were reviewed and left as they are: they are already short, and every candidate edit would change an error path or output. Two candidate edits in Test-WingetUpgrades.ps1 were rejected for the same reason: hoisting the upgrade string out of the match path would read version fields on every upgrade under StrictMode, and dropping the Test-Path guard before New-Item would print an error when a file sits at the cache path.

Not verified

  • Pester suites for the touched scripts (tests/windows/checks/.Tests.ps1, tests/windows/lib/.Tests.ps1) were not run: this lane has no pwsh, so they are left to the PR's CI
  • PSScriptAnalyzer lint on the touched .ps1 files was not run (pwsh unavailable in this lane); left to the PR's CI
  • Tidy: the ai-slop pass's deterministic detector (detect.sh) could not run under this lane's Bash allowlist; the fragment got a hand-read rubric check only, which was clean
  • Six listed lib files (Add-TodoProposal, Assert-ApprovalState, Assert-CheckResult, Assert-StateBaseLocation, ConvertFrom-FileTimeBytes, Enter-RunLock) were left unchanged: no simplification was found that keeps their behavior identical

Fix

  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-TopProcesses.ps1: committed_pct and disk_latency_ms WARN/INFO ladders folded into one condition plus a ternary severity (WARN thresholds sit above INFO, so the results are identical)
  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-WindowsUpdate.ps1: dropped the redundant null early return in Test-PfroPending (a piped $null is filtered out) and the redundant LastDeploymentChangeTime re-check (Where-Object already guarantees it)
  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-WingetUpgrades.ps1: inlined the one-use $idLower variable, removed redundant parentheses, and joined the upgrade string onto one line
  • plugins/machine-health/skills/audit/scripts/windows/lib/Assert-CatalogEntry.ps1: removed the redundant Count -eq 0 clause from the empty-os check (-not on an empty array is already true)
  • plugins/machine-health/skills/audit/scripts/windows/lib/ConvertFrom-Jsonc.ps1: merged the escaped, in-string and quote branches of Remove-JsoncComment into one if/elseif chain that appends each character in one place
  • plugins/machine-health/skills/audit/scripts/windows/lib/ConvertTo-AppendixMarkdown.ps1: event-log first/last timestamps now share one formatting scriptblock
  • plugins/machine-health/skills/audit/scripts/windows/lib/ConvertTo-DetailMarkdown.ps1: replaced List[string] add-calls with array expressions
  • plugins/machine-health/skills/audit/scripts/windows/lib/ConvertTo-TopMetrics.ps1: removed one-use variables and a redundant null guard ($null fails every -is test)
  • .changes/machine-health/work-resolve-issue-issue-14646-42956282760-1-0c955190.md: new patch fragment, ### Changed, 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against ff56f6f:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • check-changelog-fragments: all 19 fragments valid
  • check-changed-skills: plugins/machine-health/skills/audit PASS, 0 errors, 4 warnings that were already there (description length, body size)
  • check-affected: 12 passed, 7 skipped over 9 changed files
  • fresh-context review subagent over the whole diff: one finding (a falsy non-string hotfix description would have rendered as text instead of an empty cell); that hunk was reverted, and every other hunk was judged equivalent for all inputs
  • grep of the tests: Assert-CatalogEntry.Tests.ps1 parses validCategories from the source, so that list was left untouched
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42956282760

Left out: the items under Not verified.

Related

#14646

Merge-Risk: max=MEDIUM demote=false head=ff56f6f37a920d08134a37a254763e83ed052a97 rubric=8.4.1 rater=claude-opus-5-5 checker=claude-opus-5-5

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed ff56f6f37a920d08134a37a254763e83ed052a97: read 9 of 9 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15258 (head ff56f6f)

No security issues found.

I read every hunk of all 9 changed files. None of them falls under a listed trusted path, and the PR changes no trust control, workflow, plugin manifest or standing instruction. The scope is a changelog fragment plus small refactors of local PowerShell audit scripts under plugins/machine-health/skills/audit/scripts/windows/.

What I checked for security relevance:

  • ConvertFrom-Jsonc.ps1 (Remove-JsoncComment). This is the only code that parses input. I read the merged string-state chain against the base version (L39-L75):
    • An escaped character is still appended and clears the escape state.
    • Inside a string, \ sets the escape state and keeps the string open. An unescaped " closes the string.
    • An opening " enters a string.
    • Comment detection still runs only outside strings. The comment-skip paths still continue before the shared append.
    • The behavior is the same for every input, so a crafted string can't hide a // or /* from the stripper, and the stripper can't swallow string content.
  • Assert-CatalogEntry.ps1. The empty-os check still throws on an empty list: -not of an empty array is true.
  • Other files. Test-TopProcesses, Test-WindowsUpdate, Test-WingetUpgrades, ConvertTo-AppendixMarkdown, ConvertTo-DetailMarkdown and ConvertTo-TopMetrics only fold severity conditions, inline variables or reshape how lists are built. None of these changes touches credentials, external input sinks, command construction or file paths.

PR context: no embedded directives aimed at the review lane.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed ff56f6f37a920d08134a37a254763e83ed052a97: read 9 of 9 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings. I read every hunk of all 9 changed files. Each edit gives the same results as the base code for every input I traced.

File Change Why it gives the same results
Test-TopProcesses.ps1 WARN/INFO ladders folded into one ternary The bands are CommittedPct INFO 60 / WARN 80 and DiskMs INFO 25 / WARN 50. WARN is always the higher number, so the folded condition is equivalent. The -ge/-gt comparison runs before ?:, which has the lowest precedence. The script already requires 7.4 and uses ternaries elsewhere.
Test-WindowsUpdate.ps1 Null early return dropped $null | Where-Object { -not IsNullOrWhiteSpace($_) } produces nothing, so Count -gt 0 is $false, as before.
Test-WindowsUpdate.ps1 LastDeploymentChangeTime re-check dropped The Where-Object { $_.LastDeploymentChangeTime } filter above it already guarantees the field is set.
Test-WingetUpgrades.ps1 Variable inlined, parentheses removed Indexing binds tighter than -join. The upgrade string is still built only on the match path.
Assert-CatalogEntry.ps1 Count -eq 0 clause removed An empty array is falsy, so -not @(...) already catches that case.
ConvertFrom-Jsonc.ps1 String-state branches merged into one chain The escaped, in-string and opening-quote branches now fall through to the single append at the end of the loop. An escaped character is still copied without being read. A \ inside a string sets $escaped and keeps the string open. A closing " ends the string. Only text outside strings reaches the // and /* handling, which still uses continue and skips the append.
ConvertTo-AppendixMarkdown.ps1 Shared $stamp scriptblock Same expression, run once per field.
ConvertTo-DetailMarkdown.ps1 List builder replaced by array expressions $shown is already an @() array of strings, and the joined output is the same.
ConvertTo-TopMetrics.ps1 $null guard dropped $null fails every -is test, so $isScalar stays false.

Closing issue #14646, acceptance criteria:

  • Behavior unchanged: met, judged by reading the code (see above).
  • Diff edits only listed files plus fragments: met. All 8 scripts are on the issue's list, plus one fragment.
  • Size (400 lines / 15 files): met. The change is small.
  • Fragment: met. It has bump: patch, ### Changed, and the exact line "Internal simplification, no behavior change."
  • Test-TpmBitLocker.ps1 unchanged: met. It is not in the diff.
  • ci-status green: not something I can check here.

Not verified: I had no shell, so I did not run Pester or PSScriptAnalyzer. The PR body also says these did not run; they are left to CI. The PR's other verification claims are the author's and I did not confirm them.

The .claude/rules files whose paths match target skill and agent prose, not these script edits. Nothing in them applies. No plugin manifest changed. No embedded instructions were found in the PR context.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head ff56f6f37a920d08134a37a254763e83ed052a97, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for ff56f6f

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-15258-ff56f6f37a920d08134a37a254763e83ed052a97, expires on 2026-12-11.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit babe144 Nov 11, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14646-42956282760-1 branch November 11, 2026 05:29
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit babe1448e10a870bcb7a1adb9b5abf57c38050fc; later checks count it verified from this comment.

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.

Simplify the audit machine-health plugin code (4 of 9)

0 participants