Skip to content

Perf: batch Graph requests in guest and privileged-role tests#1318

Open
alflokken wants to merge 6 commits into
microsoft:devfrom
alflokken:perf/batch-graph-calls-in-tests
Open

Perf: batch Graph requests in guest and privileged-role tests#1318
alflokken wants to merge 6 commits into
microsoft:devfrom
alflokken:perf/batch-graph-calls-in-tests

Conversation

@alflokken

Copy link
Copy Markdown

What

Replace per-item Graph calls (N+1) with batched Invoke-ZtGraphBatchRequest in three assessment tests:

  • 21868: guest-owned app/SP check (batched owner lookups)
  • 21877: guest sponsor check (batched sponsor lookups)
  • 21818: privileged-role activation alerting (batched notification-rule lookups

Why

These tests issued one Graph request per user or role, which dominated runtime in larger tenants. Batching (~20 requests per round-trip) significantly reduces execution time without requiring additional permissions.

Behavior change (21818 only)

Implements the existing TODO, the check now evaluates all roles instead of stopping at the first failure.

Pass/fail behavior is unchanged, but failure reports now include all non-compliant roles. The note stating that the check stopped at the first failing role was removed.

Tests 21868 and 21877 are pure performance changes and produce identical results.

Copilot AI review requested due to automatic review settings June 17, 2026 15:35

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR optimizes several PowerShell assessment tests by replacing per-item Microsoft Graph calls with batched Graph requests to reduce request volume and improve run time.

Changes:

  • Switch guest sponsor lookups to Invoke-ZtGraphBatchRequest (bulk expand sponsors).
  • Refactor app/SP owner lookups into a shared helper (Get-GuestResourceOwner) and batch owner queries.
  • Batch retrieval of PIM activation notification rules and compute compliance after collecting results.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/powershell/tests/Test-Assessment.21877.ps1 Batch guest sponsor retrieval and aggregate results in a single pass.
src/powershell/tests/Test-Assessment.21868.ps1 Batch application/service principal owner retrieval via new helper function.
src/powershell/tests/Test-Assessment.21818.ps1 Batch role management rule retrieval and determine failure after consolidating rules.

Comment thread src/powershell/tests/Test-Assessment.21877.ps1
Comment thread src/powershell/tests/Test-Assessment.21818.ps1 Outdated
Comment thread src/powershell/tests/Test-Assessment.21818.ps1
@alflokken alflokken changed the base branch from main to dev June 18, 2026 08:58
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.

3 participants