Skip to content

refactor(helpers): move four nested helpers into their own files - #100

Merged
fadwen-ai merged 3 commits into
mainfrom
refactor/helpers-small
Nov 25, 2026
Merged

fadwen-ai merged 3 commits into
mainfrom
refactor/helpers-small

Conversation

@fadwen

@fadwen fadwen commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Summary

The first part of #65, following the owner's decision there to move the nested helpers out. Four functions were nested inside the one function that used them, with no [CmdletBinding()], no help, untyped parameters and no output type (FUN-01, DOC-01, FUN-20, FUN-10, MOD-01). Each is now a private function in its own file, an advanced function with full comment-based help and an output type, and it takes as parameters what it used to read from the function around it. Behaviour does not change.

This starts a stack for #65: the next pull requests, one command or group at a time, will be based on this one.

Changes

Was Now Takes as parameters what it read from outside
Test-RuleSelected in Test-IntuneScript Private/Test-IslRuleSelected.ps1 nothing
Get-Check in Test-IntuneWin32Requirement Private/New-IslRequirementCheck.ps1 nothing; -Met is a switch where it was [bool] (FUN-20)
Get-ArtifactLocation in Export-IntuneFindingSarif Private/ConvertTo-IslSarifLocation.ps1 the root, as -RootPath
ConvertTo-SettingsObject in Get-IslSetting Private/ConvertTo-IslSettingsObject.ps1 the lists of allowed values, which moved with it
  • ConvertTo-IslSettingsObject ends with $PSCmdlet.ThrowTerminatingError(), where the nested copy had no $PSCmdlet and threw the record. Get-IslSetting already calls it inside a try with a catch, which Tests/Unit/Module.ErrorFlow.Tests.ps1 checks. One throw is left in the module, in Invoke-IslGraphRequest; CLAUDE.md says so.
  • A test file for each new function under Tests/Unit/Private: the rule filter's cases, a requirement that is met and one that is not, relative, escaped, case-insensitive and outside-the-root locations, and every settings value that is refused, with its ID and its source. The tests of the four commands are unchanged and pass.
  • CHANGELOG under Changed. The one thing a caller can see is the error of a settings value that is not allowed, whose FullyQualifiedErrorId now reads SettingsInvalid,ConvertTo-IslSettingsObject; the ID itself was added in this release.

Verification

Notes

  • The new names follow the module's prefix and an approved verb each. Get-Check became New-IslRequirementCheck because it builds an object rather than reading one.
  • The standards' compliance check finds no finding in the four new files, and DOC-01 and FUN-01 are gone from the four files the helpers left.

The first part of #65. Four functions were nested inside the one
function that used them, with no [CmdletBinding()], no help, untyped
parameters and no output type (FUN-01, DOC-01, FUN-20, FUN-10, MOD-01).
Each is now a private function in its own file, an advanced function
with full help, and takes as parameters what it read from the
function around it:

- Test-RuleSelected in Test-IntuneScript -> Test-IslRuleSelected
- Get-Check in Test-IntuneWin32Requirement -> New-IslRequirementCheck
- Get-ArtifactLocation in Export-IntuneFindingSarif ->
  ConvertTo-IslSarifLocation, with the root as -RootPath
- ConvertTo-SettingsObject in Get-IslSetting ->
  ConvertTo-IslSettingsObject, with the lists of allowed values

ConvertTo-IslSettingsObject ends with ThrowTerminatingError where the
nested copy had to throw, so one of the last two throw statements of
the module is gone. Each new function has a test file of its own; the
tests of the four commands are unchanged.

Refs #65.

@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.

Verdict: approve. One nit, on the CHANGELOG.

Reviewed against ai-powershell-standards (FUN-01, FUN-10, FUN-20, DOC-01, MOD-01). Checked in a Linux sandbox with pwsh 7.6.0 and Pester 6.2.0.

Verified

  • No change in behaviour (differential run): full unit suites on main (3b82ba2) and on this branch, same seed.
    • Passes went from 945 to 973, which are the 28 new tests.
    • The failure set is identical: nothing new and nothing fixed.
  • Extractions match: each extracted helper takes as parameters what it used to read from the function around it (-RootPath for the SARIF location; the allowed-value lists moved into ConvertTo-IslSettingsObject). -Met is now a [switch] (FUN-20).
  • Module.ErrorFlow.Tests.ps1 passes 5/5: Get-IslSetting calls the new function inside its try/catch.
  • CI on this PR: run 45498881431 passed all five jobs.

Nit: the CHANGELOG overstates what a caller sees. It says a refused settings value now has the FullyQualifiedErrorId SettingsInvalid,ConvertTo-IslSettingsObject. From the public command it doesn't change.

  • Test-IntuneScript -Settings @{ MinimumSeverity = 'Bogus' } gives SettingsInvalid,Test-IntuneScript with the same message on main and on this branch.
  • The new suffix shows only one level down, in Get-IslSetting, which is private.
  • Either drop the sentence, or say that the public ID is unchanged.

@fadwen

fadwen commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

The nit is addressed in 1555715.

Export-IntuneFindingSarif removes the trailing separator of -Root, so
the root / becomes an empty string, which the mandatory -RootPath of
ConvertTo-IslSarifLocation refused at binding. The nested function it
replaced compared with the empty string, and every path started with
it. -RootPath now allows an empty string.
@fadwen-ai

fadwen-ai commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

068949b fixes a regression in this pull request.

  • SARIF root on Linux: Export-IntuneFindingSarif removes the trailing separator of -Root, so the file system root / becomes an empty string. The mandatory -RootPath of ConvertTo-IslSarifLocation refused that at binding, and every result with a script path lost its location. The nested function it replaced compared with the empty string. -RootPath now carries [AllowEmptyString()], and a test gives the helper an empty root and a Linux path.

A second finding on this branch is older than the pull request: a Severity setting that is not a hashtable ends Test-IntuneScript with a strict-mode error instead of SettingsInvalid. It is #105, and its fix is #107, on top of #104.

🤖 Generated with Claude Code

@fadwen-ai
fadwen-ai merged commit 370d8a3 into main Nov 25, 2026
10 checks passed
@fadwen-ai
fadwen-ai deleted the refactor/helpers-small branch November 25, 2026 01:56
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