Skip to content

fix(entra): surface Graph errors as Skipped in MT.1107-1109 instead of silent fail - #2174

Merged
merill merged 1 commit into
maester365:mainfrom
earbona23:fix/mt1107-1109-empty-access-packages
Sep 15, 2026
Merged

merill merged 1 commit into
maester365:mainfrom
earbona23:fix/mt1107-1109-empty-access-packages

Conversation

@earbona23

@earbona23 earbona23 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

📑 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:

if ($packages.Count -eq 0) {
    Add-MtTestResultDetail -Result "✅ No access packages found in the tenant."
    return $true
}

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:

} catch {
    Write-Error "Error checking ...: $($_.Exception.Message)"
    return $false
}

Because Add-MtTestResultDetail is never called on that path, the test surfaces as a Failed with no explanation — exactly the symptom in the issue. return $false also 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):

} catch {
    Add-MtTestResultDetail -SkippedBecause Error -SkippedError $_
    return $null
}

Add-MtTestResultDetail -SkippedBecause Error records the underlying error in the report and calls Set-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 $null is 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

  • My pull request adheres to the code style of this project.
  • My code requires changes to the documentation.
  • I have updated the documentation as required. (N/A — behaviour of the error path only; generated docs describe remediation, not the skip/error state.)
  • The build and unit tests pass after running /powershell/tests/pester.ps1 locally. (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-MtGraphRequest for all three tests:

Scenario Before After
No access packages (clean empty) Pass Pass (unchanged)
Graph call throws Failed, no detail Skipped, error shown

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for entitlement management checks.
    • Failures are now reported as skipped test results with error details, rather than being marked as failed checks.

…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.
@earbona23
earbona23 requested a review from a team as a code owner September 6, 2026 14:44
@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 529267aa-f5c8-40ab-a39d-9ef49cc79104

📥 Commits

Reviewing files that changed from the base of the PR and between 200ebdf and 991f09b.

📒 Files selected for processing (3)
  • powershell/public/maester/entra/Test-MtEntitlementManagementDeletedGroups.ps1
  • powershell/public/maester/entra/Test-MtEntitlementManagementInactivePolicies.ps1
  • powershell/public/maester/entra/Test-MtEntitlementManagementValidApprovers.ps1

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Three entitlement management tests now record top-level exceptions as skipped results with error details and return $null instead of writing errors and returning $false.

Changes

Entitlement management error handling

Layer / File(s) Summary
Record top-level errors as skipped results
powershell/public/maester/entra/Test-MtEntitlementManagementDeletedGroups.ps1, powershell/public/maester/entra/Test-MtEntitlementManagementInactivePolicies.ps1, powershell/public/maester/entra/Test-MtEntitlementManagementValidApprovers.ps1
The catch blocks call Add-MtTestResultDetail -SkippedBecause Error -SkippedError $_ and return $null instead of writing an error and returning $false.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 991f0

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: samerde

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the affected entitlement-management tests and the primary behavior change: Graph errors now surface as Skipped instead of silent Failed results.
Description check ✅ Passed The description is complete. It explains the issue, root cause, fix, scope, validation, and expected behavior. It also includes the required checklist and issue reference.
Linked Issues check ✅ Passed The changes satisfy issue #2075. The three affected tests now record Graph exceptions with Add-MtTestResultDetail and return $null, so they report Skipped with error details instead of an information-…
Out of Scope Changes check ✅ Passed The changes are limited to the outer error handlers in the three tests named in issue #2075. No unrelated detection logic, empty-state behavior, documentation, or public declarations changed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@merill merill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch @earbona23

Thanks a lot for the fix!

@merill
merill merged commit b761abf into maester365:main Sep 15, 2026
2 checks passed
Snozz-Al pushed a commit to soulemike/maester that referenced this pull request Sep 27, 2026
…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.
Snozz-Al added a commit to soulemike/maester that referenced this pull request Sep 27, 2026
…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.
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.

🪲 MT.1107 - MT.1109 failing with unspecified error although no access packages are defined

2 participants