Skip to content

refactor(helpers): move the Win32 app flow's helpers out - #104

Open
fadwen wants to merge 5 commits into
refactor/helpers-rulesfrom
refactor/helpers-win32
Open

fadwen wants to merge 5 commits into
refactor/helpers-rulesfrom
refactor/helpers-win32

Conversation

@fadwen

@fadwen fadwen commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Summary

The fifth part of #65. The four functions nested in Invoke-IntuneWin32AppTest are private functions in files of their own, each an advanced function with full comment-based help and an output type. They take as parameters what they used to read from the command. Behaviour does not change.

Stacked on #103, #102, #101 and #100.

Changes

Was Now Takes as parameters
Invoke-DetectionPass Invoke-IslWin32DetectionPass -Detection, the settings every detection shares, and -Warning, the run's warning list
Invoke-ContentCommand Invoke-IslWin32ContentCommand -Context, -Credential, -TimeoutSeconds and -Warning
Get-Outcome Get-IslWin32Outcome -ReturnCodes
ConvertTo-RelatedResult ConvertTo-IslWin32RelatedResult nothing new
  • The command builds two splats once, $passSplat and $contentSplat, and passes them to every pass and every install or uninstall.
  • Errors. The two that launch something end with the error of a step that could not be run, from a catch of their own; the nested copies relied on the command's try, which the error-flow test accepted only because they were nested. The detection inside a pass is still called with -ErrorAction Stop, for the reason fix(harness)!: raise run failures as terminating errors with IDs #92 gave: with nothing returned, the app would read as detected.
  • Two small differences. A detection pass now carries the type name IntuneScriptLab.Win32DetectionPass; it is internal and never returned to a caller. And Get-IslWin32Outcome gives failed for a run that has no exit code and did not time out, where the nested copy looked up a null key and would have failed with an error; no run reaches it that way today.
  • Tests: a file for each new function. The content command is tested on a real copy in the test drive with the launch mocked: the 32-bit cmd.exe, the copy present during the run and gone after it, both warnings about powershell.exe, and a content folder that is not there. The command's own tests are unchanged and pass.

Verification

  • ./Tests/Invoke-Tests.ps1 -CodeCoverage on PowerShell 7.6.10: 1,334 passed, 7 skipped, 95.26 percent coverage. 3 failed, the three that fail on this computer on main as well (Repair-IntuneScript corrupts an ANSI script on a host with a UTF-8 system code page #75 twice, In-box module table does not list UOPProviders, present on Windows 11 26H2 #76).
  • ./Tests/Invoke-Tests.ps1 on Windows PowerShell 5.1.26100: 1,298 passed, 43 skipped, the same 3 failed.
  • On the lab device as NT AUTHORITY\SYSTEM under Windows PowerShell 5.1.26100.9818, every suite: 1,297 passed, 0 failed, 47 skipped (they need PowerShell 7, PSScriptAnalyzer or the Proxmox host). The Win32 workflow and the runs as another account were among those that ran; the credential reaches the content command through a new parameter, which is why this one went to the lab.
  • Get-Help finds the help of each of the four functions. CI's analysis step locally: 0 findings, no line over 115 characters. The standards' check finds nothing in the four new files.
  • quality-gates.yml, started by hand on this branch because the pull request is not based on main.

The fifth part of #65. The four functions nested in
Invoke-IntuneWin32AppTest are private functions in files of their
own, advanced functions with full help and output types. They take as
parameters what they read from the command:

- Invoke-DetectionPass -> Invoke-IslWin32DetectionPass, with the
  detection settings as -Detection and the warning list as -Warning
- Invoke-ContentCommand -> Invoke-IslWin32ContentCommand, with
  -Context, -Credential, -TimeoutSeconds and -Warning
- Get-Outcome -> Get-IslWin32Outcome, with -ReturnCodes
- ConvertTo-RelatedResult -> ConvertTo-IslWin32RelatedResult

The command passes the shared values through two splats. The two that
launch something end with the error of a step that could not be run,
inside a catch of their own, where the nested copies relied on the
command's try. A detection pass now carries the type name
IntuneScriptLab.Win32DetectionPass. Each new function has a test file
of its own; the command's tests are unchanged.

Refs #65.
Invoke-IslWin32DetectionPass filtered null entries out of -Rule. A
dependency or superseded app whose DetectionRule held only nulls passed
the command's upfront check, since a list of two nulls is true, and its
pass then had no script and no rules, which reads as detected: the
dependency was reported Installed without being checked or installed.
The nested function this replaced passed each entry to
Test-IntuneWin32Rule, which refused the null.

A null entry now ends the pass with DetectionRuleEmpty, and a pass with
neither a script nor a rule ends with DetectionMissing.
@fadwen-ai

Copy link
Copy Markdown
Collaborator

183aa88 fixes a regression in this pull request.

  • Empty detection rules: Invoke-IslWin32DetectionPass filtered null entries out of -Rule. A dependency or a superseded app whose DetectionRule held only nulls passed the command's upfront check, because a list of two nulls is true, and its pass then had no script and no rules, which reads as detected: the dependency was reported Installed without being checked or installed. The nested function it replaced passed each entry to Test-IntuneWin32Rule, which refused the null. A null entry now ends the pass with DetectionRuleEmpty, and a pass with neither a script nor a rule ends with DetectionMissing. Every call of the pass is preceded by the command's own checks, so a valid app never reaches the second. A test through Invoke-IntuneWin32AppTest gives a dependency DetectionRule = @($null, $null) and checks that the command ends with DetectionRuleEmpty and starts no process; it fails on the code before the change, which raised nothing.

The branch also takes the fixes merged up from #100 and #101.

🤖 Generated with Claude Code

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.

2 participants