Skip to content

refactor(machine-health): simplify audit Windows check scripts (3 of 9) - #15322

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14643

Summary

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

Simplified five of the listed Windows check scripts without changing what they emit: Test-Drivers now splits CodeIntegrity events in one pass (it ran Test-DefenderPlatformEvent twice per event) and names the repeated pending-updates test once; Test-EnvironmentHealth replaces hand-written List/foreach filters with Where-Object/Select-Object; Test-EventLogErrors, Test-NetworkListeners and Test-Services fold repeated comparisons, switch cases and ternaries, and NetworkListeners stops scanning writable roots after the first match. Test-FirewallRules and Test-StorageTopN were reviewed and left as they are, because the remaining candidates (Measure-Object on an empty set, the Ordinal dictionary lookup) could change output on edge inputs. The four files the issue says must stay unchanged (Test-Reliability, Test-ScheduledTasks, Test-SdkVersions, Test-StartupItems) were not touched.

Not verified

  • Pester suites for the five changed checks (tests/windows/checks/Test-{Drivers,EnvironmentHealth,EventLogErrors,NetworkListeners,Services}.Tests.ps1) not run: this lane cannot run pwsh; left to the PR's CI
  • PSScriptAnalyzer lint of the changed .ps1 files not run: no pwsh in this lane; left to the PR's CI
  • tidy recorded as skipped: passes 1-4 ran and changed nothing, but pass 5 (ai-slop) could not run its detect.sh under this lane's Bash limits; the one fragment line was read against the rubric by hand and is the exact text the issue requires
  • ci-status green is a PR CI check, not runnable here

Fix

  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-Drivers.ps1: one .Where(..., 'Split') pass replaces two Test-DefenderPlatformEvent filters; ternary for the platform version; $hasPendingUpdates names the repeated check; summary list built from an initial array
  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-EnvironmentHealth.ps1: List/foreach builders for allVars, Path-row lookups, unique norms, other scopes/paths, truthy/falsy DISABLE_AUTOUPDATER and shadow warns replaced by array concatenation and Where-Object/Select-Object
  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-EventLogErrors.ps1: two provider -eq tests merged into -in; if/else to ternary for first/last seen
  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-NetworkListeners.ps1: three identical switch cases merged into one; inner writable-root loop breaks on first match
  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-Services.ps1: delayed-auto flag as one -and expression; uptime minutes computed once for summary and detail
  • .changes/machine-health/work-resolve-issue-issue-14643-42995349847-1-89834218.md: patch fragment, ### Changed, 'Internal simplification, no behavior change.'

Verification

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

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

The run reports:

  • check-changelog-fragments: all 13 fragments valid (run before and after tidy)
  • check-changed-skills: plugins/machine-health/skills/audit PASS, 0 errors, 4 pre-existing size/description warnings
  • check-affected: 12 passed, 7 skipped over 6 changed files
  • fresh-context review subagent over the whole diff and the matching Pester tests: no behavior-changing problem found (checked StrictMode 3, pipeline unrolling, -in/-or precedence, empty .Where Split, break scope, switch on $null, mock interactions)
  • diff size: 6 files, 33 added and 67 removed lines, within the 400-line and 15-file limits
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42995349847

Left out: the items under Not verified.

Related

#14643

Merge-Risk: max=MEDIUM demote=false head=ce5212fd4df599944364906e086fab8f6de3ea00 rubric=8.4.2 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 ce5212fd4df599944364906e086fab8f6de3ea00: read 6 of 6 changed file(s); 0 finding(s), 0 as inline comments.

Security review: no security issues found

I read the whole diff: all 6 listed files and every hunk. This was a full review (0 earlier heads reviewed, blocking only: no).

What changed: the pull request refactors five local Windows check scripts for the machine-health audit skill (Test-Drivers, Test-EnvironmentHealth, Test-EventLogErrors, Test-NetworkListeners, Test-Services) and adds one patch changelog fragment. The edits are local rewrites that produce the same results: ternaries, -in instead of chained -eq, .Where(..., 'Split') in place of two filters, Where-Object/Select-Object in place of hand-written list loops, and a break once a writable root matches.

Security surface checked:

  • None of the changed files match a trusted path. The diff does not touch workflows, actions, the token broker, the kill switch, merge holds, trusted-actor lists or plugin manifests (plugin.json / marketplace.json). It changes no trust control.
  • It adds no new input source, no command or path built from external data, and no network, credential or secret handling. In Test-EnvironmentHealth, the credential-named-variable logic is untouched. The refactored lines only rebuild the same lists (allVars, truthyDisable, shadowWarns, others).
  • The detection outputs that matter for security keep their meaning:
    • The writable-root flag in Test-NetworkListeners.ps1 is still $true on any match; break only stops the loop earlier.
    • The Test-DefenderPlatformEvent exclusion in Test-Drivers.ps1 splits on the same predicate as before. The Split result keeps the non-matching events, which are what the base kept.
  • The diff deletes or softens no standing instruction (no skill or agent body, CLAUDE.md, or hook list). The instruction-surface lens does not apply.
  • The PR context contains no embedded instructions aimed at the lane.

No spend or cost impact.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: PR #15322 (refactor(machine-health): simplify audit Windows check scripts, 3 of 9)

No findings. I read the whole change in all 6 listed files. Where a rewritten expression depends on surrounding code, I also read that code at head.

What was checked

  • Test-Drivers.ps1
    • The single .Where({...}, 'Split') pass gives the same partition as the two earlier Where-Object filters. An empty $ciEvents still skips Get-ActiveDefenderPlatformVersion and yields two empty collections, so .Count keeps working under StrictMode 3.
    • The [List[string]]@(...) cast keeps the same summary order.
    • $hasPendingUpdates was already evaluated on every path, because the old trailing if always ran. Computing it earlier does not touch $pendingDriverUpdates in a new state.
  • Test-EnvironmentHealth.ps1
    • Read-PersistentEnvironment returns , $rows, so @($userVars) + @($machineVars) adds no $null rows.
    • Select-Object -Unique matches case-sensitively, the same as the old List[string].Contains.
    • $others always has at least 1 element by the time $others.scope and $others.path run, because the uniqueNorms.Count -lt 2 guard comes first. So member enumeration never runs on an empty array under StrictMode.
    • $truthyDisable.Count -lt $disableFindings.Count is exactly the old falsy-count-greater-than-0 test, since the two sets split the list between them.
  • Test-EventLogErrors.ps1: The comma operator binds tighter than -in, and -or binds loosest, so the merged provider test parses as intended. The ternaries are valid inside the hashtable literal under #Requires -Version 7.4.
  • Test-NetworkListeners.ps1
    • The merged switch case is case-insensitive like the string cases it replaces, and it does not overlap 'kernel' or default.
    • The new break exits only the inner foreach ($root ...) loop, and $writable ends up the same.
  • Test-Services.ps1: $uptime is set (or left $null) before line 91. $uptimeMinutes ?? 0 gives the same summary text as before, and uptime_minutes gets the same value.
  • Mocks: No Pester suite for the changed checks asserts how many times Test-DefenderPlatformEvent is called, so calling it once per event instead of twice breaks no assertion.

Closing issue #14643

  • Edits only listed files plus a fragment: met. The diff edits 5 of the 11 listed files and adds one changelog fragment.
  • Test-Reliability, Test-ScheduledTasks, Test-SdkVersions and Test-StartupItems unchanged: met. None of the four is in the diff.
  • Fragment: met. bump: patch, ### Changed, and the exact line "Internal simplification, no behavior change."
  • Size: met. 33 lines added and 67 removed across 6 files.
  • Behavior unchanged: I found no change in behavior by reading the code. The existing Pester suites for all five changed checks would catch a regression.
  • ci-status green: I could not check it from this lane.

The PR body says the Pester and PSScriptAnalyzer runs were not done. The checks it does report (fragment check, skill check, check-affected, a subagent review) are the author's claims; I did not run them and have not verified them.

No .claude/rules/ file's paths: glob covers what these .ps1 changes do. The rules that match plugins/*/skills/** govern skill text and cost claims, not script behavior. No plugin manifest changed.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for ce5212f

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-15322-ce5212fd4df599944364906e086fab8f6de3ea00, 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 102c2aa Nov 11, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14643-42995349847-1 branch November 11, 2026 10:56
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 102c2aa02e772e174aa37520a065894797f02e01; 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 (3 of 9)

0 participants