Repository navigation
Make the PSScriptAnalyzer pin hold, and catch syntax errors - #18
Merged
Merged
Conversation
The Tests workflow installed PSScriptAnalyzer 1.25.0 so that a new rule could not fail a build that passed before, but nothing made the test use that copy. The windows-latest image installs its own, the newest when the image is built (1.25.0 in 20260907.229.1), and Windows PowerShell 5.1 cannot see the copy pwsh installs, so the 5.1 run always used the image's version. An image update would have changed the rules without any change here. - Tests.yml sets the version once, in PSSCRIPTANALYZER_VERSION, and installs that version. - The test imports exactly that version when the variable is set, and the newest installed copy otherwise. PowerShell itself would load the copy in the first PSModulePath folder that has one, whatever its version. With CI=true, a missing analyzer or pinned version fails the test instead of skipping it. - The test runs under PowerShell 7 only, and names the reason when it skips. 1.25.0 has the same 75 rules in both editions, and syntax only PowerShell 7 accepts already fails every 5.1 test file that imports the module. - Analyze with -Severity Error, ParseError. A syntax error has its own ParseError severity, so filtering on Error alone reported nothing for a planted missing parenthesis. - Research_Notes/File-Encoding-And-Line-Endings.md section 1 now measures a module manifest as well as a script, which is what the AGENTS.md rule for saving a non-ASCII manifest with a BOM cites. Checked: with a fake newer PSScriptAnalyzer first on PSModulePath, the pinned run loads 1.25.0 and passes; a pinned version that is not installed skips locally and fails with CI=true; a planted syntax error fails the test naming the file, line and rule.
The analyzer test and the Tests workflow rest on tool behavior that was measured but only written down in a commit message, and several of those facts change with the analyzer version or the runner image. Add Research_Notes/Test-Tooling-Behavior.md: syntax errors appear only under the ParseError severity; the analyzer's rules match across editions but its parsing does not; PowerShell loads the first copy of a module on PSModulePath, not the newest, and a 5.1 process started from pwsh cannot see pwsh's folders; and the runner image installs whatever analyzer version is newest when it is built. The note says what to repeat when PSSCRIPTANALYZER_VERSION changes, and the test and the workflow point at it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Nothing changes for someone using the module; this is test, CI, and contributor documentation only.
windows-latestimage installs its own (whatever is newest when the image is built), and Windows PowerShell 5.1 cannot see the copy the workflow installs for PowerShell 7, so the 5.1 run always used the image's version. The workflow now setsPSSCRIPTANALYZER_VERSIONonce and installs that version. The test imports exactly that version and runs under PowerShell 7 only. In CI it fails, rather than skips, when the pinned version is missing.-Severity Error, ParseError. A syntax error has its ownParseErrorseverity, so filtering onErroralone reported nothing.Research_Notes/File-Encoding-And-Line-Endings.mdsection 1 now measures a module manifest as well as a script, which is whatAGENTS.mdcites for saving a non-ASCII manifest with a BOM.Research_Notes/Test-Tooling-Behavior.mdrecords the measurements behind the test, and what to repeat whenPSSCRIPTANALYZER_VERSIONchanges.Under Windows PowerShell 5.1 the analyzer test now reports as skipped, with its reason. Nothing is lost: 1.25.0 has the same rules in both editions, and syntax only PowerShell 7 accepts already fails the 5.1 run when the module imports.
Release classification
Checklist
develop, ormainfor a hotfixCHANGELOG.mdhas an entry in the right section under[Unreleased](added if missing), or the change is not user-visible.\Tests\Invoke-Tests.ps1passes