Skip to content

refactor(machine-health): simplify audit Windows lib and Clear-TempFiles scripts - #15061

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14652-42794396598-1
Nov 10, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14652

Summary

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

Simplified six of the fifteen listed machine-health audit scripts without changing behavior. Write-ElevationBanner builds its banner and coverage markdown from array literals instead of a run of List.Add calls. Set-ApprovalState merges two identical get-or-create helpers into one $objectOf and computes the shipped catalog path once. Write-StateFile names its temp-file cleanup once. Write-HealthResult and Clear-TempFiles drop single-use variables and redundant guards. Test-ServiceTriggerStart's help text now says five start types, matching the five it lists. The other nine listed files (Read-StartupApproved, Read-UserAssist, Remove-OldCheckupView, Resolve-CheckupPick, Resolve-SkillRoot, Test-IsElevated, Write-CheckupPick, Write-ElevatedResult, Write-MachineHealthLog) were reviewed and left as they are: every candidate there was either a cross-file dedupe, which this issue puts out of scope, or not clearly simpler.

Not verified

  • Pester suites under plugins/machine-health/skills/audit/tests/windows (Write-ElevationBanner, Write-StateFile, Write-HealthResult, Set-ApprovalState, Clear-TempFiles) not run: this lane cannot run pwsh; left to the PR's CI
  • PSScriptAnalyzer lint over the changed .ps1 files not run here (no pwsh in this lane); left to the PR's CI
  • ai-slop detector script (detect.sh) not run on the changelog fragment: this lane's Bash runs only named wrappers; only the rubric read ran
  • Nine listed files reviewed but left unchanged (Read-StartupApproved, Read-UserAssist, Remove-OldCheckupView, Resolve-CheckupPick, Resolve-SkillRoot, Test-IsElevated, Write-CheckupPick, Write-ElevatedResult, Write-MachineHealthLog): candidates there were cross-file dedupes (out of scope) or not…
  • ci-status green is a PR CI check, not runnable here

Fix

  • plugins/machine-health/skills/audit/scripts/windows/lib/Write-ElevationBanner.ps1: banner lines and the coverage markdown body built as array literals with inline if/foreach in place of List[string].Add calls; output strings and order unchanged
  • plugins/machine-health/skills/audit/scripts/windows/lib/Set-ApprovalState.ps1: $remediationsOf and $reviewedOf merged into one $objectOf helper that takes the key; shipped checks.jsonc path computed once as $shippedCatalog
  • plugins/machine-health/skills/audit/scripts/windows/lib/Write-StateFile.ps1: the three identical temp-file Remove-Item calls replaced by one $discardTemp scriptblock
  • plugins/machine-health/skills/audit/scripts/windows/lib/Write-HealthResult.ps1: $Detail ?? {} in place of an if/else, the redundant AdminFields Count check dropped (truthiness already implies Count > 0 for string[]), and a single-use $line variable inlined
  • plugins/machine-health/skills/audit/scripts/windows/remediations/Clear-TempFiles.ps1: PSIsContainer test collapsed into one -and condition, the error field put on one line, and the single-use $a/$b variables in the -Human output inlined
  • plugins/machine-health/skills/audit/scripts/windows/lib/Test-ServiceTriggerStart.ps1: help text says five start types (it lists five)
  • .changes/machine-health/work-resolve-issue-issue-14652-42794396598-1-4e105640.md: patch fragment, ### Changed, 'Internal simplification, no behavior change.'

Verification

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

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

The run reports:

  • check-changelog-fragments: all 1 fragment valid
  • check-changed-skills: plugins/machine-health/skills/audit PASS, 0 errors, 4 warnings that were there before this change (description length, body length, token size, no Gotchas)
  • check-affected: 12 passed, 7 skipped over 7 changed files
  • fresh-context review subagent over the whole diff, looking for behavior differences: one finding, Write-ElevationBanner's Matrix guard changed from '$Matrix -and $Matrix.Count -gt 0' to a Count-only test, which differs for a one-element array holding a falsy value; fixed by putting the original…
  • tidy (code-tidying:tidy-diff) over the 23 changed hunks: no edits. One proposal: the '# $Doc[$Key], created as an empty object when absent.' comment in Set-ApprovalState could be dissolved by a more descriptive helper name (tidy-diff renames nothing). The markdown passes left the fragment's…
  • all three repository checks re-run after the review fix and tidy: all pass
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42794396598

Left out: the items under Not verified.

Related

#14652

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

Security review: PR #15061

I found no security issues. I read every hunk of all 7 changed files. None of them matches a trusted-path glob, and the PR touches no plugin manifest (plugin.json / marketplace.json), workflow, trust control, merge hold or standing instruction.

critical-findings: 0

What I checked:

  • Clear-TempFiles.ps1: the junction and reparse-point guard is unchanged: Test-IsReparsePoint still runs before recursion, at Clear-TempFiles.ps1#L59. The merged PSObject.Properties['PSIsContainer'] -and $entry.PSIsContainer test short-circuits, so the StrictMode-safe property check still runs first. Which entries get queued or returned for deletion is the same as before. The -Human output change only inlines two variables.
  • Set-ApprovalState.ps1: the merged $objectOf helper is only ever called with the literal keys 'remediations' and 'reviewed_checks', and no caller input reaches the key. Computing $shippedCatalog once points at the same shipped checks.jsonc. The shipped-ID and remediation-ID validation that runs before writing approvals or mutes is unchanged.
  • Write-StateFile.ps1: the $discardTemp scriptblock runs the same Remove-Item -LiteralPath $tempPath on the same three error and no-op paths, so it cleans up the same temp file.
  • Write-HealthResult.ps1, Write-ElevationBanner.ps1, Test-ServiceTriggerStart.ps1: these only rework output and help text. The elevation banner text, including the SHA-256 and UAC consent wording, is unchanged.
  • Changelog fragment: plain text, no executable content.

No text in the PR context tells the review lane what to do.

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk of all 7 changed files and found nothing that changes behavior.

  • Set-ApprovalState.ps1: The new $objectOf helper takes its key as a parameter. It does the same get-or-create on remediations and reviewed_checks that the two removed helpers did. $shippedCatalog is the same Join-Path result as before, now computed once.
  • Write-ElevationBanner.ps1: The @( … ) array literals with if/foreach inside them produce the same lines in the same order as the List.Add calls did. The $Matrix -and $Matrix.Count -gt 0 guard is kept as it was.
  • Write-HealthResult.ps1:
    • The file already has #Requires -Version 7.4, so the ?? operator is supported.
    • $Detail is typed [hashtable], so $Detail ?? @{} gives the same result as the old if/else.
    • Dropping the $AdminFields.Count -gt 0 check changes nothing for a [string[]]: an empty array is falsy, and a one-element array is truthy exactly when its element is, which the old -and chain also required.
  • Write-StateFile.ps1: $discardTemp is defined after $tempPath is assigned in the same function scope. Bare throw still rethrows the caught exception after the cleanup call, as it did when Remove-Item was called directly.
  • Clear-TempFiles.ps1: -and short-circuits, so $entry.PSIsContainer is still read only when the property exists, which keeps it StrictMode-safe. Truthiness is the same as the old [bool] cast. Inlining the single-use variables doesn't change the printed output.
  • Test-ServiceTriggerStart.ps1: The help text now says "five start types", which matches the five it lists (Boot, System, Automatic, Manual, Disabled).

Closing issue #14652 acceptance criteria:

  • Every edit is to a listed file, or is the changelog fragment.
  • The diff is about 120 changed lines across 6 hand-edited files, inside the 400-line / 15-file limit.
  • The fragment has bump: patch and ### Changed, with the required line.
  • The Pester runs and the green ci-status the PR mentions are the author's claims; I did not verify them. This lane cannot run pwsh, and the PR's own CI covers them.
  • The criterion "behavior is unchanged" is covered by the existing Pester suites the PR body names (Write-ElevationBanner, Write-StateFile, Write-HealthResult, Set-ApprovalState, Clear-TempFiles).

No plugin manifest changed. No settled threads and no prior findings applied (this is the lane's first review of the PR, so it was not limited to blocking findings). No changed file matches a trusted path. I found no directives embedded in the PR context.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for e3872af

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-15061-e3872af2b097591a6a4a5617ad8d5f8e66cb4c19, expires on 2026-12-10.

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 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 10, 2026
@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 6a4b761 Nov 10, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14652-42794396598-1 branch November 10, 2026 14:30
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 6a4b761bab4731261dc29fc46887341f38696166; 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 (9 of 9)

0 participants