Skip to content

refactor(powershell-format): simplify the PSScriptAnalyzer check scripts - #14797

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14703-42645426470-1
Nov 9, 2026
Merged

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14703

Summary

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

Simplified powershell-check.ps1 and powershell-check.sh without changing behavior. In the .ps1, one exitTrust helper replaces the eleven repeated 'Write-Output "PSSA_TRUST <verdict>"; exit 6' pairs. A bad CustomRulePath entry now exits right away, where it used to set a flag and break. The loader, evaluator and using-kind lists move out of the per-file scan loop, the settings directory is computed once, and a redundant null check, two dead pre-initializations and a StringBuilder hex loop are gone. In the .sh, the list and output paths and the list's pwsh path are set once before the per-settings loop, and the cygpath arm of to_pwsh_path is one line. hooks/powershell-format.sh was already minimal and stays unchanged: none of /simplify's four checks found a change that keeps its behavior and makes it shorter.

Not verified

  • plugins/powershell-format/git-hooks/powershell-check.test.sh and hooks/powershell-format*.test.sh were not run here (this lane's Bash runs only the named wrappers and has no pwsh); left to the PR's CI
  • ci-status green is a PR CI check; left to the PR's CI
  • tidy skipped: the git-hooks code rows were dropped under tidy's GLOBAL HARD exclusion for local git-hook script directories, so passes 1-3 had no rows; on the fragment, write-for-humans made no change (text mandated by the issue) and the ai-slop detector could not run under this lane's Bash…
  • shellcheck/PSScriptAnalyzer lint not run directly on the touched files beyond what check-affected ran; left to the PR's CI

Fix

  • plugins/powershell-format/git-hooks/powershell-check.ps1: exitTrust helper replaces the repeated PSSA_TRUST write+exit 6 pairs; the bad-entry flag/break becomes a direct exit; $loaders/$evaluators/$loadKinds move out of the scan loop; $settingsDir is computed once and reused by Set-Location;…
  • plugins/powershell-format/git-hooks/powershell-check.sh: to_pwsh_path's cygpath arm reduced to one line with the same output; list/out paths and the list's pwsh path are set once before the per-settings loop
  • .changes/powershell-format/work-resolve-issue-issue-14703-42645426470-1-b0b490e9.md: new patch fragment, '### Changed' / 'Internal simplification, no behavior change.'

Verification

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

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

The run reports:

Left out: the items under Not verified.

Related

#14703

Merge-Risk: max=HIGH demote=true head=db0e9ecd98fc222a76858cfeea55ec59dad464d6 rubric=8.1.6 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 db0e9ecd98fc222a76858cfeea55ec59dad464d6: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #14797 (refactor(powershell-format): simplify the PSScriptAnalyzer check scripts)

No security issues found. I read every hunk of all 3 changed files. None of them matches a trusted-path glob. The change touches the PSScriptAnalyzer CustomRulePath trust gate, which decides whether repository-supplied rule code may run, so I checked that each rewritten step behaves exactly as before:

  • exitTrust helper (powershell-check.ps1 L50-53). It replaces each Write-Output "PSSA_TRUST <verdict>"; exit 6 pair with the same output line and exit code:
    • exit inside a function ends the whole script when it runs under pwsh -File.
    • exit is a flow-control signal, so the surrounding try/catch blocks (L146, L321-323) cannot catch it.
    • None of the calls sits inside an assignment that would capture its output. The GATE pssa-$signature verdict reaches the shell as one string.
  • Bad CustomRulePath entry (L63-81). It used to set a flag, break, and exit later. It now exits on the spot. The verdict (UNVERIFIABLE, exit 6) is the same and nothing runs between the two points, so it still fails closed.
  • Settings directory computed once (L60, L362). Set-Location now uses $settingsDir, which is Split-Path -Parent $env:PSSA_SETTINGS. The old argument $settings is set to $env:PSSA_SETTINGS at L354. Rule paths therefore still resolve from the same directory the gate pinned. Rules being pinned from one directory and loaded from another is not possible here.
  • Removed $null -ne $cmdAst.Parent check (L207). $null -is [PipelineAst] is $false, so the guard was redundant. The pipeline-position refusal (UNPINNABLE) is unchanged.
  • Constant lists moved out of the scan loop: $loaders, $evaluators and $loadKinds (L117-132). They hold the same values and are never changed. The Invoke-Expression/iex refusal and the using module/using assembly pinning still run on every scanned file.
  • Signature hex and removed pre-initializations. In L331-343, -join (... ToString("x2")) builds the same hex text as the old StringBuilder loop. An empty signature, or an exception that leaves $signature = "", still gives UNVERIFIABLE, so no shared approval marker can be created. The try/catch blocks still assign $sd and $signature on every path.
  • to_pwsh_path in the shell script (powershell-check.sh). If cygpath is missing or fails, it still falls through to printf '%s' "$1", and the return status is still 0.
    • list, list_arg and out are now set once before the loop. They are fixed paths under $CHECKS_TMP, and : >"$list" still empties the list on every pass.
    • Variables are quoted as before, and no new input reaches a shell string.
  • Changelog fragment: prose only.

Prompt-injection check. The PR context file contains no embedded instructions aimed at this review.

Plugin manifests. The diff changes no plugin.json or marketplace.json.

Prior findings. This is the lane's first review of this PR (blocking only: no), and there were no earlier posts to repeat.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

Code review: PR #14797, refactor(powershell-format): simplify the PSScriptAnalyzer check scripts

No findings. I read every hunk of all 3 changed files and then read both scripts in full at head. I found no change in behavior.

plugins/powershell-format/git-hooks/powershell-check.ps1

  • exitTrust helper (L50-L53): exit inside a function still ends the whole -File script with code 6. Write-Output still sends the same PSSA_TRUST <verdict> line to stdout. Bareword arguments bind as strings, and "GATE pssa-$signature" prints the same text as before. None of the calls sit inside a try whose catch could intercept the exit; the calls at L146 and L323 are in catch blocks. The function is defined before its first use.
  • A bad CustomRulePath entry now exits right away instead of setting a flag and breaking. The old path ran no other code between the break and the UNVERIFIABLE exit, so the output and exit code are the same.
  • $settingsDir is computed once (L60): $settings is $env:PSSA_SETTINGS (L354), so Set-Location -LiteralPath $settingsDir gets the same directory as before. Nothing reassigns $settingsDir.
  • $loaders, $evaluators and $loadKinds moved out of the per-file loop: they are constants that are only read. They are still inside the CustomRulePath block, before their first use.
  • Removed $null -ne $cmdAst.Parent: $null -is [PipelineAst] is already $false, so the check was redundant.
  • Removed pre-initializations of $sd and $signature: both branches of each try/catch assign the variable.
  • Hex string now built with -join + ForEach-Object over the 32-byte digest instead of the StringBuilder loop: the output is the same lowercase x2 hex.

plugins/powershell-format/git-hooks/powershell-check.sh

  • to_pwsh_path is one line: when cygpath is present and succeeds, the function prints its output and returns 0. When cygpath is missing or fails, it falls through to printf '%s' "$1". That matches the old cygpath ... || printf path, and set -e is not on.
  • list, list_arg and out are set once before the loop: their values don't change between iterations, and nothing in the loop or its callees reassigns them. The list in checks_skip_listed is declared local (lib/git-hooks/check-lib.sh:210).

Closing issue #14703 acceptance criteria

  • Behavior unchanged: met, by my reading of both scripts. No test in the repository checks the source text of the removed lines.
  • Edits only the listed files plus a changelog fragment: met. hooks/powershell-format.sh is unchanged, which the PR body explains.
  • Within 400 lines and 15 files: met.
  • Fragment says bump: patch, ### Changed, "Internal simplification, no behavior change.": met.
  • ci-status green: I can't check this from here. The PR says it is left to CI.

Verification

I could not run pwsh or the test suites (powershell-check.test.sh, hooks/powershell-format*.test.sh). The equivalence above comes from reading the code. The PR's verification results are the author's own claims, and I have not checked them.

No plugin manifest changed. Nothing in the PR text tried to instruct the review.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for db0e9ec

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-14797-db0e9ecd98fc222a76858cfeea55ec59dad464d6, 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 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit d1e62bc Nov 9, 2026
63 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14703-42645426470-1 branch November 9, 2026 21:03
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 git-hooks and hooks powershell-format plugin code

0 participants