Repository navigation
refactor(helpers): move four nested helpers into their own files - #100
Conversation
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
left a comment
There was a problem hiding this comment.
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 (
-RootPathfor the SARIF location; the allowed-value lists moved intoConvertTo-IslSettingsObject).-Metis now a[switch](FUN-20). Module.ErrorFlow.Tests.ps1passes 5/5:Get-IslSettingcalls the new function inside itstry/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' }givesSettingsInvalid,Test-IntuneScriptwith the same message onmainand 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.
|
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.
|
068949b fixes a regression in this pull request.
A second finding on this branch is older than the pull request: a 🤖 Generated with Claude Code |
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
Test-RuleSelectedinTest-IntuneScriptPrivate/Test-IslRuleSelected.ps1Get-CheckinTest-IntuneWin32RequirementPrivate/New-IslRequirementCheck.ps1-Metis a switch where it was[bool](FUN-20)Get-ArtifactLocationinExport-IntuneFindingSarifPrivate/ConvertTo-IslSarifLocation.ps1-RootPathConvertTo-SettingsObjectinGet-IslSettingPrivate/ConvertTo-IslSettingsObject.ps1ConvertTo-IslSettingsObjectends with$PSCmdlet.ThrowTerminatingError(), where the nested copy had no$PSCmdletand threw the record.Get-IslSettingalready calls it inside atrywith acatch, whichTests/Unit/Module.ErrorFlow.Tests.ps1checks. Onethrowis left in the module, inInvoke-IslGraphRequest;CLAUDE.mdsays so.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.FullyQualifiedErrorIdnow readsSettingsInvalid,ConvertTo-IslSettingsObject; the ID itself was added in this release.Verification
./Tests/Invoke-Tests.ps1 -CodeCoverageon PowerShell 7.6.10: 1,199 passed, 7 skipped, 95.18 percent coverage. 3 failed, the three that fail on this computer onmainas 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.ps1on Windows PowerShell 5.1.26100: 1,163 passed, 43 skipped, the same 3 failed../Build/Publish-Module.ps1 -WhatIf: staged, imported in a new process and verified; nothing published.quality-gates.ymlruns on this pull request.Notes
Get-CheckbecameNew-IslRequirementCheckbecause it builds an object rather than reading one.