Skip to content

refactor(machine-health): simplify audit scripts without behavior change - #14871

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14641

Summary

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

Simplified four of the eight listed machine-health audit scripts without changing their outputs, exit codes, written files, printed text, log lines, flags or exported names. The orchestrator now logs its elevated pass through one Add-PassLog helper, builds the cisa-kev message once for both the WARNING banner and the FATAL line, computes the remediation skip reason once and maps it to the report wording, and drops single-use variables. build-checkup-view.mjs shares one isScalar test, Test-BackupStatus reads each source's level in one expression, and Test-Battery inlines its pattern and uses ternaries. Format-ShortReport.ps1 and Get-ResearchCandidate.ps1 were already tight, so they are unchanged. run-tests.ps1 and Test-AppLastUse.ps1 are unchanged, as the issue requires. Nothing was moved or deduplicated across files: Format-ShortReport's Get-Field was not swapped for lib's Get-SnapshotField, because the two treat non-pscustomobject inputs differently.

Not verified

  • Pester suites (Invoke-MachineHealthCheck.Tests.ps1, Test-Battery.Tests.ps1, Test-BackupStatus.Tests.ps1) and tests/checkup-view.test.sh were not run: this lane cannot run pwsh, node or bash test scripts. Left to the PR's CI.
  • ci-status green is a PR check, so it is left to the PR's CI.
  • PSScriptAnalyzer and node lint were not run here (no wrapper in this lane); check-affected ran what it runs locally, and the rest is left to CI.
  • Tidy pass 5 (ai-slop:audit fix) could not run its detector, detect.sh, because this lane allows only its named wrappers. An inline rubric read of the fragment's one required line found no tells. The other tidy passes ran and needed no edits.
  • review-venue.txt was absent, so the review ran locally in one fresh-context subagent, not in the CI code-review lane.

Fix

  • plugins/machine-health/skills/audit/scripts/build-checkup-view.mjs: one isScalar helper replaces two copies of the string/number/boolean typeof test.
  • plugins/machine-health/skills/audit/scripts/windows/Invoke-MachineHealthCheck.ps1: Add-PassLog helper for the six timestamped elevated-pass log lines; the cisa-kev size message is built once and shared by the WARNING banner and the FATAL line (same text); the two consecutive $stateWritable blocks…
  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-BackupStatus.ps1: the per-source switch now only records present and needs-admin sources, and the level comes from one -in test (present, absent and unknown are OK; anything else is UNKNOWN).
  • plugins/machine-health/skills/audit/scripts/windows/checks/Test-Battery.ps1: the mWh pattern and verbose message are inlined, the fullPct rounding is on one line, and design_mwh/full_mwh use ternaries.
  • .changes/machine-health/work-resolve-issue-issue-14641-42704507759-1-a366a801.md: new patch fragment, '### Changed' with 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 30cdb17:

  • 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 (run before and after tidy and the review fix).
  • check-changed-skills: plugins/machine-health/skills/audit PASS, 0 errors, 4 pre-existing warnings about SKILL.md size and description.
  • check-affected: 12 passed, 7 skipped over 5 changed files; the rest is listed as CI only.
  • Local review: one fresh-context subagent read the whole diff against HEAD and found no behavior difference. It flagged one speculative edge case: an Int32-overflow cast inside a ForEach-Object script block in Test-Battery. I reverted that line to two plain statements to rule it out.
  • Tidy (code-tidying:tidy-diff) over 30 hunk rows: passes 1-4 found nothing more to change; pass 5 ran as an inline rubric read only.
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42704507759

Left out: the items under Not verified.

Related

#14641

Merge-Risk: max=MEDIUM demote=false head=30cdb174dcfc3d6a8803448079eeeea34f187fe0 rubric=8.2.0 rater=claude-opus-5-5 checker=claude-opus-5-5

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

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

Security review: PR #14871 (head 30cdb17)

I found no security issues.

I read every hunk of all 5 changed files. None of them matches a TRUSTED PATHS: glob, and no plugin manifest changed.

The PR says it simplifies the code without changing behaviour. The diff matches that:

  • build-checkup-view.mjs: the isScalar helper runs the same typeof test as before. text() still strips control and bidi characters, and itemEvidence still hides the same fields, including value when an exclusion applies. Rendered output gets no new content.
  • Invoke-MachineHealthCheck.ps1:
    • Elevated pass: the new Add-PassLog helper writes the same timestamped lines as before. The check that ResultFileId is a valid file ID, the script-path checks, the catalog validation and the dispatch are unchanged.
    • cisa-kev seed guard: the WARNING and FATAL text is now built once, and the guard still exits 2 for any mode other than first-run.
    • Remediation gate: $remediationsEnabled is computed the same way (not dry-run, no user load, state writable), so the approval gate is unchanged. $skipReason only picks the wording for the log line and the report.
    • Other edits: the catalog and overlay reads were inlined and the report-template regex extraction is unchanged.
  • Test-BackupStatus.ps1: present, absent and unknown still map to OK, and needs-admin and every other state still map to UNKNOWN.
  • Test-Battery.ps1: same regex and casts. The if/else blocks became ternaries.
  • The changelog fragment is text only.

No instruction surface, trust control, token scope or credential handling is touched. The PR context file has no embedded instructions aimed at this lane.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

Code review: PR #14871, refactor(machine-health): simplify audit scripts without behavior change

No findings. I read every hunk of all 5 changed files. None of them match a trusted-path glob, and the PR changes no plugin manifest.

Behavior-preservation checks

I checked each refactor against the head file. Nothing was run; this is a read-only review.

  • Invoke-MachineHealthCheck.ps1
    • Add-PassLog (L175): every call runs in the same script scope, in a plain foreach or catch, with no -Parallel and no new runspace. So the dynamically scoped $passLog resolves under Set-StrictMode -Version 3.0, and the timestamp and line format are the same as before.
    • cisa-kev text: the WARNING banner and FATAL line produce the same strings as the base. The machine-specific state leaked: prefix moved into the banner literal, and it was only ever in the WARNING text.
    • $skipReason (L603): $effectiveDry, $userLoaded and $stateWritable are last assigned at L147, L255 and L381/L386, all before L603. Nothing reassigns them before the log line (L662) or the report mapping (L873). The hashtable maps each of the four reason codes to its original wording.
    • Dropping $catalog = $null: under strict mode this is safe, because the catch at L402 always assigns $catalog.
    • Removed variables: $templatePath, $raw and $overlayRaw had no other uses. $raw inside Get-ReportTemplate is still a function-local variable.
    • Moving Initialize-Directory -Path $logsDir into the next if ($stateWritable) block keeps the same order.
  • Ternaries (? :): the scripts declare #Requires -Version 7.4, and sibling checks already use ternaries.
  • Test-BackupStatus.ps1: switch and -in both compare strings case-insensitively. A $null State gives UNKNOWN in both versions, and List[string].Add emits nothing, so the per-source levels stay the same.
  • Test-Battery.ps1: the inlined regex, the [int] casts and the ternaries for design_mwh/full_mwh give the same values.
  • build-checkup-view.mjs: isScalar is the same typeof test as the two copies it replaces, and it is defined before text.

Closing issue #14641 acceptance criteria

  • Behavior unchanged: I found no behavior change. Pester suites cover the touched files (Invoke-MachineHealthCheck.Tests.ps1, Test-BackupStatus.Tests.ps1, Test-Battery.Tests.ps1), and checkup-view.test.sh covers the JS file, per the PR.
  • Only listed files plus a fragment edited: met.
  • Size limits (≤400 changed lines, ≤15 files): met.
  • run-tests.ps1 and Test-AppLastUse.ps1 unchanged: met.
  • Changelog fragment: met. It sets bump: patch and contains ### Changed with "Internal simplification, no behavior change."
  • ci-status green: left to the PR's CI.

The PR author says the Pester and shell suites were not run in the authoring lane. That is author-claimed, and I did not verify it either. CI has to confirm the "same outputs" criterion.

The PR description and the issue contain no embedded instructions aimed at this lane.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 30cdb17

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-14871-30cdb174dcfc3d6a8803448079eeeea34f187fe0, expires on 2026-12-09.

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
Merged via the queue into main with commit 14c6e60 Nov 10, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14641-42704507759-1 branch November 10, 2026 01:04
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 (1 of 9)

0 participants