Skip to content

fix(gate): leave the contents of a Win32 Package folder out of a folder search - #40

Merged
fadwen merged 1 commit into
mainfrom
fix/gate-package-folder
Oct 15, 2026
Merged

fadwen merged 1 commit into
mainfrom
fix/gate-package-folder

Conversation

@fadwen

@fadwen fadwen commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Summary

Examples/Invoke-IntuneScriptGate.ps1 analyzed every .ps1 under the script folders, including the contents of a Win32 app's Package folder (Win32\<app>\Package\, the files that become the .intunewin, where Examples/IntuneScripts.Tests.ps1.template expects them). An install.ps1 there is run by the agent through the install command as 64-bit SYSTEM, but nothing in its name or folder tells the analysis that, so it fell to the portal default for an unnamed script: a user-context, 32-bit platform script. Every machine-wide write in the installer became an IslContextIssue warning, with IslArchitectureIssue warnings for HKLM:\SOFTWARE and $env:ProgramFiles on top, and the build failed at -FailOn Warning for findings that do not apply to an installer.

This is the same shape as the Pester-suite problem fixed in #38, and it is fixed in the same place: the gate's folder search.

Changes

  • Examples/Invoke-IntuneScriptGate.ps1: a folder search leaves out files under a Package segment, alongside *.Tests.ps1. Only the singular segment is matched: a Packages folder is one that holds Win32 apps (the script-type inference treats it as a Win32 folder hint), and the detection scripts under it stay in. A file named directly on -Path is still analyzed. The -Path help says so.
  • Examples/intune-script-gate.yml and README.md: the SCRIPT_PATHS comment and the gate paragraph name both exclusions.
  • Tests/Integration/ScriptGate.Tests.ps1: the fixture gains Win32\Widget\Package\install.ps1 (a machine-wide write) and Packages\Gadget\Detect.ps1 (clean); the new test checks the installer is absent from a folder run and analyzed when named, and that the Packages detection is still reported.
  • CHANGELOG.md: Fixed entry under Unreleased.

Verification

  • Tests/Integration/ScriptGate.Tests.ps1: 9 passed on PowerShell 7.6.6 and on Windows PowerShell 5.1.
  • PSScriptAnalyzer (Error, Warning) clean on the two changed .ps1 files; no line over 115 characters.
  • On the demo repository with an Intune\Win32\Widget\Package\install.ps1 that writes to HKLM:\SOFTWARE and Program Files: before the change the installer carried 3 IslContextIssue and 3 IslArchitectureIssue warnings and -FailOn Warning failed; after it the installer is absent from the output.

Notes

  • The exclusion lives in the gate, not in Test-IntuneScript, so the command's behaviour on a folder (every .ps1) is unchanged; the gate is what knows the suite template's layout.
  • The release PR for 0.33.0 is stacked on this branch.

…er search

The gate analyzed every .ps1 under the script folders, including the
contents of a Win32 app's Package folder, the files that become the
.intunewin. An install.ps1 there runs through the install command as
SYSTEM, but nothing in its name tells the analysis that, so it was read
as a user-context 32-bit platform script and its machine-wide writes
became warnings that failed the build at -FailOn Warning.

Files under a Package segment are left out of a folder search, next to
*.Tests.ps1. A Packages folder, which holds Win32 apps, stays in, and a
file named directly on -Path is still analyzed.

@fadwen fadwen left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes on the lines whose reason the diff does not show.

Where-Object { $_.Name -notlike '*.Tests.ps1' } | ForEach-Object { $_.FullName }
Where-Object {
$_.Name -notlike '*.Tests.ps1' -and
"$($_.DirectoryName)\" -notmatch '(?i)[\\/]Package[\\/]'

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The separator is appended so a Package folder that is the file's own parent matches too: DirectoryName ends in '\Package' with nothing after it, and the pattern needs a separator on both sides to reject 'Packages' and 'MyPackage'. The class accepts both slashes so the same line holds on a Linux runner.

[System.IO.File]::WriteAllText((Join-Path $script:Scripts 'Win32\Widget\Package\install.ps1'),
"New-Item -Path HKLM:\SOFTWARE\Widget -Force | Out-Null`r`nexit 0`r`n", $utf8Bom)
[System.IO.File]::WriteAllText((Join-Path $script:Scripts 'Packages\Gadget\Detect.ps1'),
"Write-Output 'installed'`r`nexit 0`r`n", $utf8Bom)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept clean on purpose. Its first version returned before exit 1 and carried an error-level finding, and 'Packages/Gadget' sorts before 'Remediations/Widget', so it became the first error annotation and the earlier test's assertion on that line failed. A clean Win32 detection still appears in the output through its IslAssumedContext line, which is all the new test needs.

@fadwen fadwen mentioned this pull request Oct 15, 2026
@fadwen
fadwen added this pull request to stack #42 October 15, 2026 14:37
@fadwen
fadwen merged commit efc8f5a into main Oct 15, 2026
4 checks passed
@fadwen
fadwen deleted the fix/gate-package-folder branch October 15, 2026 14:41
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.

1 participant