Repository navigation
fix(entra): surface Graph errors as Skipped in MT.1107-1109 instead of silent fail - #2174
Conversation
…f silent fail The outer catch in Test-MtEntitlementManagementDeletedGroups (MT.1107), Test-MtEntitlementManagementInactivePolicies (MT.1108) and Test-MtEntitlementManagementValidApprovers (MT.1109) collapsed any exception from the entitlement-management Graph calls into 'Write-Error' + 'return $false'. Because it never called Add-MtTestResultDetail, the test surfaced as a bare 'Failed' with no explanation. Replace it with the module's standard error-handling pattern (Add-MtTestResultDetail -SkippedBecause Error -SkippedError $_; return $null) so a failing/unavailable Graph call is reported as Skipped with the underlying error shown, matching the behaviour of ~200 other tests. The existing empty-tenant guard (packages.Count -eq 0 -> return $true) is unchanged, so a tenant with no access packages still passes cleanly.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThree entitlement management tests now record top-level exceptions as skipped results with error details and return ChangesEntitlement management error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Entitlement-management Graph exceptions now produce skipped results with error details rather than information-less failures, while tenants without access packages retain their clean pass behavior. No merge-blocking risk remains. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
merill
left a comment
There was a problem hiding this comment.
Good catch @earbona23
Thanks a lot for the fix!
…f silent fail (maester365#2174) The outer catch in Test-MtEntitlementManagementDeletedGroups (MT.1107), Test-MtEntitlementManagementInactivePolicies (MT.1108) and Test-MtEntitlementManagementValidApprovers (MT.1109) collapsed any exception from the entitlement-management Graph calls into 'Write-Error' + 'return $false'. Because it never called Add-MtTestResultDetail, the test surfaced as a bare 'Failed' with no explanation. Replace it with the module's standard error-handling pattern (Add-MtTestResultDetail -SkippedBecause Error -SkippedError $_; return $null) so a failing/unavailable Graph call is reported as Skipped with the underlying error shown, matching the behaviour of ~200 other tests. The existing empty-tenant guard (packages.Count -eq 0 -> return $true) is unchanged, so a tenant with no access packages still passes cleanly.
…f silent fail (maester365#2174) The outer catch in Test-MtEntitlementManagementDeletedGroups (MT.1107), Test-MtEntitlementManagementInactivePolicies (MT.1108) and Test-MtEntitlementManagementValidApprovers (MT.1109) collapsed any exception from the entitlement-management Graph calls into 'Write-Error' + 'return $false'. Because it never called Add-MtTestResultDetail, the test surfaced as a bare 'Failed' with no explanation. Replace it with the module's standard error-handling pattern (Add-MtTestResultDetail -SkippedBecause Error -SkippedError $_; return $null) so a failing/unavailable Graph call is reported as Skipped with the underlying error shown, matching the behaviour of ~200 other tests. The existing empty-tenant guard (packages.Count -eq 0 -> return $true) is unchanged, so a tenant with no access packages still passes cleanly.
📑 Description
Closes #2075
MT.1107, MT.1108 and MT.1109 report a bare Failed with no detail ("Test failed" and nothing else) when the entitlement-management Graph call raises an exception (e.g. in a tenant where entitlement management has never been provisioned / has no access packages).
Root cause
All three tests already short-circuit the genuinely-empty case:
So a tenant with zero access packages that returns cleanly already passes. The reported failure comes from the outer
catch, which swallows any exception without recording a result:Because
Add-MtTestResultDetailis never called on that path, the test surfaces as a Failed with no explanation — exactly the symptom in the issue.return $falsealso forces a hard fail for what is really an inability to evaluate the check.Fix
Replace the three outer catches with the module's standard error-handling pattern (used by ~200 other tests, e.g.
Test-MtTeamsRestrictParticipantGiveRequestControl, the XSPM suite):Add-MtTestResultDetail -SkippedBecause Errorrecords the underlying error in the report and callsSet-ItResult -Skipped, so the test now shows as Skipped with the actual error message instead of an information-less Failed — matching the expected behaviour in the issue ("whether Skipped or Error"). Returning$nullis already handled by the Pester wrappers (if ($null -ne $result) { ... }).The existing empty-tenant guard is untouched, so a tenant with no access packages continues to pass cleanly.
Scope
Only the outer catch of the three affected tests is changed (6 lines). No change to the empty-state handling, the detection logic, or the docs.
✅ Checks
/powershell/tests/pester.ps1locally. (Files parse clean, PSScriptAnalyzer reports 0 findings, and the empty/error paths were verified behaviourally: empty → Pass, exception → Skipped-with-detail +$null.)ℹ️ Additional Information
Verified with mocked
Invoke-MtGraphRequestfor all three tests:Summary by CodeRabbit