Skip to content

Refactor: Extract provider and core helpers, add consistent prerequisite validation#119

Merged
blindzero merged 6 commits intomainfrom
copilot/refactor-provider-layout-structure
Jan 27, 2026
Merged

Refactor: Extract provider and core helpers, add consistent prerequisite validation#119
blindzero merged 6 commits intomainfrom
copilot/refactor-provider-layout-structure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 26, 2026

✅ Repository Structure Refactor Complete

Successfully refactored provider layout and split large files into cohesive, maintainable units.


📊 Summary of Changes

Provider Refactors (Phase 1)

AD Provider (src/IdLE.Provider.AD/)

  • Main file: New-IdleADIdentityProvider.ps1 692 → 681 lines (1.6% reduction)
  • New Private helpers:
    • Test-IdleADPrerequisites.ps1 - Structured prerequisite checking (does not throw)
    • ConvertTo-IdleADEntitlement.ps1 - Entitlement normalization/validation
  • ✅ Provider creation emits warnings for missing prerequisites (no throw)
  • ✅ Provider methods throw actionable errors when prerequisites missing at runtime
  • ✅ All 27 AD provider tests passing

EntraID Provider (src/IdLE.Provider.EntraID/)

  • Main file: New-IdleEntraIDIdentityProvider.ps1 873 → 853 lines (2.3% reduction)
  • New Private helpers:
    • Test-IdleEntraIDPrerequisites.ps1 - Structured prerequisite checking (does not throw)
    • ConvertTo-IdleEntraIDEntitlement.ps1 - Entitlement normalization/validation
  • ✅ Provider creation emits warnings for missing prerequisites (no throw)
  • ✅ Provider methods throw actionable errors when prerequisites missing at runtime
  • ✅ All 35 EntraID provider tests passing

ExchangeOnline Provider (src/IdLE.Provider.ExchangeOnline/) ✨ NEW

  • Main file: New-IdleExchangeOnlineProvider.ps1 372 → 394 lines
  • New Private helper:
    • Test-IdleExchangeOnlinePrerequisites.ps1 - Structured prerequisite checking (does not throw)
  • ✅ Provider creation emits warnings for missing prerequisites (no throw) - Fixed throwing behavior
  • ✅ Provider methods throw actionable errors when prerequisites missing at runtime
  • ✅ All 17 ExchangeOnline tests passing

Core Refactors (Phase 2)

New-IdlePlanObject.ps1 - 671 → 110 lines (83.6% reduction!)

  • Extracted 10 nested helper functions to Private/:
    • ConvertTo-NullIfEmptyString.ps1
    • Get-IdleOptionalPropertyValue.ps1
    • ConvertTo-IdleNormalizedCapability.ps1
    • ConvertTo-IdleRequiredCapabilities.ps1
    • Get-IdleProvidersFromMap.ps1
    • Get-IdleAvailableCapabilities.ps1
    • Assert-IdlePlanCapabilitiesSatisfied.ps1
    • Test-IdleWorkflowStepKey.ps1
    • Get-IdleWorkflowStepValue.ps1
    • ConvertTo-IdleWorkflowSteps.ps1

Invoke-IdlePlanObject.ps1 - 782 → 640 lines (18.2% reduction)

  • Extracted 2 nested helper functions to Private/:
    • Get-IdleCommandParameterNames.ps1
    • Get-IdleStepField.ps1
  • Enhanced existing helper:
    • Resolve-IdleStepHandler.ps1 (module-qualified name support)

Total Impact:

  • ~800 lines of code extracted to reusable, testable helpers
  • Private folder now contains 37 helper functions (13 newly created)
  • Public cmdlets reduced to their core responsibilities

✅ Quality Gates Passed

  • All tests passing: 333 passed, 3 skipped, 0 failed
  • PSScriptAnalyzer: Clean, no blocking findings
  • Demo verification: Mock examples work correctly
  • Module loading: All modules load without errors
  • Public API unchanged: No breaking changes to cmdlet signatures
  • Prerequisites policy implemented:
    • Provider creation warns but does not throw (all providers)
    • Provider methods fail-fast with actionable errors
  • IO separation maintained: All IO stays in adapters
  • Mapping logic extracted: Conversion logic in Private/ helpers
  • StrictMode consistency: All Private helpers use Set-StrictMode -Version Latest
  • AuthSession check order: Matches documented behavior across all providers

📋 Definition of Done

  • Provider factories reduced to facade only (IO in adapters, mapping in Private/)
  • Provider creation warns for missing prereqs (no throw) - Now includes ExchangeOnline
  • Provider methods throw actionable errors for missing prereqs
  • Core public functions delegate to Private/ helpers
  • No public API changes
  • All tests green (333 passed)
  • PSScriptAnalyzer green
  • Examples working (mock demos verified)
  • Git status clean
  • StrictMode consistency maintained
  • AuthSession check order corrected

📝 Technical Notes

Prerequisites Policy:

  • Module import remains non-blocking (warnings only)
  • Provider creation emits warnings but never throws (AD, EntraID, ExchangeOnline)
  • Provider methods check prerequisites at call time (fail-fast)
  • Prerequisite checks return structured IdLE.PrerequisitesResult objects
  • Test adapters bypass prerequisite validation (TypeName-based detection)

Code Organization:

  • Nested functions extracted to standalone Private/ helpers
  • Helpers are reusable, testable, and follow single responsibility principle
  • Public cmdlets now act as orchestrators/facades
  • Cohesive thematic grouping over arbitrary LOC thresholds
  • All Private helpers include Set-StrictMode -Version Latest for consistency

AuthSession Handling:

  • All providers follow documented check order:
    1. String access token
    2. Object with AccessToken property
    3. Object with GetAccessToken() method
    4. PSCredential
  • Use Where-Object for property/method checks to avoid StrictMode errors on empty collections

No Breaking Changes:

  • All public cmdlet signatures unchanged
  • All outputs remain identical
  • All existing workflows/tests work without modification
  • Dependency injection (-Adapter parameter) continues to work

🎯 Impact

This refactor significantly improves:

  • Maintainability: Smaller, focused files are easier to review and modify
  • Testability: Helper functions can be unit tested independently
  • Reusability: Private helpers reduce code duplication
  • Merge Safety: Reduced file sizes lower merge conflict risk
  • Onboarding: Clearer code structure for new contributors
  • Consistency: All providers now follow the same prerequisite validation pattern
  • Code Quality: StrictMode enforcement across all Private helpers catches errors early

The repository now follows best practices for PowerShell module structure with clear separation between public contracts and internal implementation details.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 26, 2026 21:24
Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
…lePlanObject to Private/ folder

Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor provider layout and split large files Refactor: Extract provider and core helpers, reduce file sizes by ~800 LOC Jan 26, 2026
Copilot AI requested a review from blindzero January 26, 2026 21:37
@blindzero blindzero changed the title Refactor: Extract provider and core helpers, reduce file sizes by ~800 LOC Refactor: Extract provider and core helpers, reduce file sizes by Jan 27, 2026
@blindzero blindzero changed the title Refactor: Extract provider and core helpers, reduce file sizes by Refactor: Extract provider and core helpers, reduce file lengths Jan 27, 2026
@blindzero blindzero changed the title Refactor: Extract provider and core helpers, reduce file lengths Refactor: Extract provider and core helpers, reduce file length Jan 27, 2026
Copy link
Copy Markdown
Owner

@blindzero blindzero left a comment

Choose a reason for hiding this comment

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

@copilot where is there no PreRequesite check for ExchangeOnline provider?

- Created Test-IdleExchangeOnlinePrerequisites.ps1 helper
- Updated provider to warn (not throw) on creation when prerequisites missing
- Added runtime prerequisite validation in ExtractAccessToken method
- Follows same pattern as AD and EntraID providers
- All 17 ExchangeOnline tests passing

Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 27, 2026

@copilot where is there no PreRequesite check for ExchangeOnline provider?

The ExchangeOnline provider was previously throwing an exception during provider creation when the ExchangeOnlineManagement module was missing (line 82 in the old code), which violated the Prerequisites Policy (rule D.2).

I've now added the prerequisite check to ExchangeOnline provider in commit 7683730:

  • Created Test-IdleExchangeOnlinePrerequisites.ps1 helper (follows same pattern as AD/EntraID)
  • Provider creation now emits warnings instead of throwing
  • Provider methods validate prerequisites at runtime and throw actionable errors
  • All 17 ExchangeOnline tests passing

Copilot AI changed the title Refactor: Extract provider and core helpers, reduce file length Refactor: Extract provider and core helpers, add consistent prerequisite validation Jan 27, 2026
Copilot AI requested a review from blindzero January 27, 2026 07:26
@ntt-matthias-fleschuetz ntt-matthias-fleschuetz marked this pull request as ready for review January 27, 2026 07:33
Copilot AI review requested due to automatic review settings January 27, 2026 07:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors large provider and core files by extracting nested functions into focused Private/ helpers, reducing main files by ~800 lines total. It also implements consistent prerequisite validation across all three providers (AD, EntraID, ExchangeOnline), fixing a violation where ExchangeOnline was throwing exceptions during provider creation instead of emitting warnings.

Changes:

  • Extracted 10 nested functions from New-IdlePlanObject.ps1 (671 → 110 lines, 83% reduction) and 2 from Invoke-IdlePlanObject.ps1 (782 → 640 lines, 18% reduction)
  • Added prerequisite validation helpers (Test-Idle*Prerequisites.ps1) for all three providers with consistent warning-at-creation / error-at-use pattern
  • Extracted entitlement conversion logic into ConvertTo-Idle*Entitlement.ps1 helpers for AD and EntraID providers
  • Enhanced Resolve-IdleStepHandler to support both hashtable and object StepRegistry types and module-qualified step names

Reviewed changes

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

Show a summary per file
File Description
New-IdleExchangeOnlineProvider.ps1 Added prerequisite checks at provider creation and method invocation; reordered AuthSession type checks
Test-IdleExchangeOnlinePrerequisites.ps1 New helper that validates ExchangeOnlineManagement module availability
New-IdleEntraIDIdentityProvider.ps1 Added prerequisite checks; extracted entitlement conversion; reordered AuthSession type checks
Test-IdleEntraIDPrerequisites.ps1 New helper that validates Invoke-RestMethod availability (minimal check for built-in dependency)
ConvertTo-IdleEntraIDEntitlement.ps1 Extracted entitlement normalization logic with Mail field support
New-IdleADIdentityProvider.ps1 Added prerequisite checks at provider creation and in GetEffectiveAdapter
Test-IdleADPrerequisites.ps1 New helper that validates ActiveDirectory module availability
ConvertTo-IdleADEntitlement.ps1 Extracted entitlement normalization logic
New-IdlePlanObject.ps1 Removed 10 nested functions, now calls extracted Private helpers (83% reduction)
Invoke-IdlePlanObject.ps1 Removed 2 nested functions, now calls extracted Private helpers (18% reduction)
Resolve-IdleStepHandler.ps1 Enhanced to support object/hashtable StepRegistry types and module-qualified handler names
10 new Core Private helpers Extracted planning and execution helpers with Set-StrictMode and proper documentation

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Added Set-StrictMode -Version Latest to all 5 Provider Private helpers
- Fixed AuthSession type check order in EntraID and ExchangeOnline to match documentation:
  1. String token
  2. Object with AccessToken property
  3. Object with GetAccessToken() method
  4. PSCredential
- Use Where-Object for property/method checks to avoid StrictMode errors on empty collections
- All 333 tests passing

Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
@blindzero blindzero merged commit 9049e3b into main Jan 27, 2026
7 checks passed
@blindzero blindzero linked an issue Jan 27, 2026 that may be closed by this pull request
11 tasks
@blindzero blindzero deleted the copilot/refactor-provider-layout-structure branch January 31, 2026 22:53
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.

Repository structure - provider layout refactor and large file splits

3 participants