Tighten up context cmdlets - #28
Open
RiverHeart wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens how the WPF control registry “context” is resolved across helper cmdlets, making explicit -ContextId usage strict (must exist) while improving fallback behavior when -ContextId is omitted (object context → active context → single context).
Changes:
- Added
Test-WPFControlContextIdand updated multiple helpers to validate explicit-ContextIdvalues rather than silently falling back. - Updated
Resolve-WPFControlContextIdto focus on fallback resolution and to error when an explicitly-bound-InputObjectis not associated with a context. - Expanded Pester coverage and updated keyword documentation for the new resolution rules (
Get-WPFWindow,Reference, registry context helpers).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/modules/WPF/Tests/RegistryContext.Tests.ps1 | Adds tests for fallback context resolution, explicit-null handling, and new context existence helper. |
| src/modules/WPF/Tests/Get-WPFWindow.Tests.ps1 | Updates behavior expectations for missing implicit context and adds “single context” fallback coverage. |
| src/modules/WPF/Public/Helpers/Register-WPFObject.ps1 | Reworks explicit -ContextId handling to either use an existing context or create it before registering. |
| src/modules/WPF/Public/Helpers/Get-WPFWindow.ps1 | Implements strict explicit context validation and fallback context resolution when -ContextId is omitted. |
| src/modules/WPF/Public/DSL/Helpers/Reference.ps1 | Implements strict explicit context validation and fallback context resolution. |
| src/modules/WPF/Private/ControlRegistry/Test-WPFControlContextId.ps1 | New helper to check context existence and optionally emit an error if missing. |
| src/modules/WPF/Private/ControlRegistry/Resolve-WPFControlContextId.ps1 | Simplifies context resolution rules and errors on explicitly-bound non-associated input objects. |
| src/modules/WPF/Private/ControlRegistry/Remove-WPFControlContext.ps1 | Uses strict explicit context validation semantics instead of resolving/falling back. |
| src/modules/WPF/Private/ControlRegistry/Get-WPFRegisteredObjectNames.ps1 | Uses strict explicit context validation semantics (empty when explicit context missing). |
| src/modules/WPF/Private/ControlRegistry/Get-WPFControlTable.ps1 | Uses strict explicit context validation/creation path before returning a control table. |
| src/modules/WPF/Private/ControlRegistry/Get-WPFControlContextId.ps1 | Tightens parameter contract and adds comment-based help. |
| src/modules/WPF/Docs/KeywordReference.md | Documents the strict -ContextId rules and fallback behavior for Get-WPFWindow and Reference. |
Comment on lines
64
to
66
| if ($State.ActiveContextId) { | ||
| return $State.ActiveContextId | ||
| } |
Comment on lines
+17
to
+26
| if ($PSBoundParameters.ContainsKey('ContextId')) { | ||
| if (Test-WPFControlContextId -ContextId $ContextId) { | ||
| $Id = $ContextId | ||
| } elseif ($CreateIfMissing) { | ||
| $Id = New-WPFControlContext -Name $Name -ContextId $ContextId -Activate:$Activate | ||
| } else { | ||
| [void] (Test-WPFControlContextId -ContextId $ContextId -ErrorIfMissing) | ||
| return $null | ||
| } | ||
| } else { |
Comment on lines
43
to
+47
| foreach($Item in $Name) { | ||
| $ResolvedContextId = Resolve-WPFControlContextId -ContextId $ContextId -InputObject $ScopeObject | ||
| if ($PSBoundParameters.ContainsKey('ContextId')) { | ||
| if (-not (Test-WPFControlContextId -ContextId $ContextId -ErrorIfMissing)) { | ||
| return | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.