Skip to content

Commit c6544ce

Browse files
Add comment-based help and inline parameter docs to Merge-Yaml private helpers
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 1035edf commit c6544ce

14 files changed

Lines changed: 255 additions & 0 deletions

src/functions/private/Add-YamlMergeIndexCandidate.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,33 @@ function Add-YamlMergeIndexCandidate {
22
<#
33
.SYNOPSIS
44
Adds one mapping key or sequence item to a structural candidate index.
5+
6+
.DESCRIPTION
7+
Adds a mapping entry or sequence item to an index bucket keyed by a
8+
structural fingerprint. It tracks effective node identities and
9+
dependencies so later mutations can invalidate only indexes that may be
10+
stale.
11+
12+
.EXAMPLE
13+
Add-YamlMergeIndexCandidate -Index $mappingIndex -Candidate $entry -Context $mergeContext
14+
15+
Indexes the entry's key as a candidate for future structural equality
16+
lookups.
17+
18+
.LINK
19+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
520
#>
621
[CmdletBinding()]
722
param (
23+
# The candidate index receiving the mapping key or sequence item.
824
[Parameter(Mandatory)]
925
[pscustomobject] $Index,
1026

27+
# The entry or item to index for later structural equality lookup.
1128
[Parameter(Mandatory)]
1229
[pscustomobject] $Candidate,
1330

31+
# Shared merge context provides work accounting and fingerprint/equality state.
1432
[Parameter(Mandatory)]
1533
[pscustomobject] $Context
1634
)

src/functions/private/Add-YamlMergeWork.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,38 @@ function Add-YamlMergeWork {
22
<#
33
.SYNOPSIS
44
Charges one or more deterministic operations to the YAML merge work budget.
5+
6+
.DESCRIPTION
7+
Increments the invocation work counter for deterministic merge operations
8+
such as indexing, fingerprinting, equality checks, and cloning. This
9+
centralizes budget enforcement so adversarial graphs cannot make merge
10+
processing unbounded.
11+
12+
.EXAMPLE
13+
Add-YamlMergeWork -State $mergeContext.WorkState -Count 3 -Operation 'index rebuild' -Node $node
14+
15+
Charges three index rebuild operations to the merge budget and throws if
16+
the configured limit is exceeded.
17+
18+
.LINK
19+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
520
#>
621
[CmdletBinding()]
722
param (
23+
# Shared work budget state records total charged operations.
824
[Parameter(Mandatory)]
925
[pscustomobject] $State,
1026

27+
# Allows callers to charge batched deterministic work without repeated calls.
1128
[Parameter()]
1229
[ValidateRange(1, 2147483647)]
1330
[int] $Count = 1,
1431

32+
# Names the work being charged for precise limit diagnostics.
1533
[Parameter(Mandatory)]
1634
[string] $Operation,
1735

36+
# Supplies source location for limit errors when a specific graph node caused the work.
1837
[Parameter()]
1938
[AllowNull()]
2039
[pscustomobject] $Node

src/functions/private/Assert-YamlMergeGraph.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,50 @@ function Assert-YamlMergeGraph {
22
<#
33
.SYNOPSIS
44
Validates the merged representation graph and its resource budgets.
5+
6+
.DESCRIPTION
7+
Walks merged documents to enforce final depth, node, alias, scalar, and
8+
tag budgets before emission. It also delegates graph validation so
9+
recursive or shared representation structures remain safe and well-formed
10+
after merging.
11+
12+
.EXAMPLE
13+
Assert-YamlMergeGraph -Documents $mergedDocuments -Depth 100 -MaxNodes 100000 -MaxAliases 1000 -MaxScalarLength 1048576 -MaxTagLength 1024 -MaxTotalTagLength 65536
14+
15+
Validates the merged document graph and throws a classified YAML merge
16+
exception if any limit is exceeded.
17+
18+
.LINK
19+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
520
#>
621
[CmdletBinding()]
722
param (
23+
# The merged document roots to validate as one resulting YAML stream.
824
[Parameter(Mandatory)]
925
[AllowEmptyCollection()]
1026
[object[]] $Documents,
1127

28+
# Limits traversal depth so deeply nested results cannot exhaust consumers.
1229
[Parameter(Mandatory)]
1330
[int] $Depth,
1431

32+
# Caps unique representation nodes in the result graph.
1533
[Parameter(Mandatory)]
1634
[int] $MaxNodes,
1735

36+
# Caps alias nodes after merge to keep reference expansion bounded.
1837
[Parameter(Mandatory)]
1938
[int] $MaxAliases,
2039

40+
# Caps decoded scalar size before the merged stream is emitted.
2141
[Parameter(Mandatory)]
2242
[int] $MaxScalarLength,
2343

44+
# Caps each expanded tag length in the merged graph.
2445
[Parameter(Mandatory)]
2546
[int] $MaxTagLength,
2647

48+
# Caps cumulative expanded tag text across the result graph.
2749
[Parameter(Mandatory)]
2850
[int] $MaxTotalTagLength
2951
)

src/functions/private/Copy-YamlMergeNode.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ function Copy-YamlMergeNode {
22
<#
33
.SYNOPSIS
44
Deep-clones a YAML representation graph with identity memoization.
5+
6+
.DESCRIPTION
7+
Deep-clones a representation node and descendants into the merge working
8+
graph so overlays never mutate caller-owned input graphs. Identity
9+
memoization preserves shared and cyclic references while enforcing clone
10+
creation budgets.
11+
12+
.EXAMPLE
13+
Copy-YamlMergeNode -Node $overlayNode -Cache $mergeContext.CloneCache -State $mergeContext.CloneState
14+
15+
Returns an independent clone of the overlay node registered in the merge
16+
clone cache.
17+
18+
.LINK
19+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
520
#>
621
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
722
'PSUseShouldProcessForStateChangingFunctions', '',
@@ -10,13 +25,16 @@ function Copy-YamlMergeNode {
1025
[CmdletBinding()]
1126
[OutputType([pscustomobject])]
1227
param (
28+
# The representation graph root to clone into merge-owned storage.
1329
[Parameter(Mandatory)]
1430
[pscustomobject] $Node,
1531

32+
# Memoizes source-to-clone identity so aliases, sharing, and cycles are preserved.
1633
[Parameter(Mandatory)]
1734
[AllowEmptyCollection()]
1835
[System.Collections.Generic.Dictionary[int, object]] $Cache,
1936

37+
# Tracks clone IDs and creation limits for the isolated working graph.
2038
[Parameter(Mandatory)]
2139
[pscustomobject] $State
2240
)

src/functions/private/Find-YamlMergeIndexMatch.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,33 @@ function Find-YamlMergeIndexMatch {
22
<#
33
.SYNOPSIS
44
Finds a collision-safe structural match in a YAML merge candidate index.
5+
6+
.DESCRIPTION
7+
Looks up a node's structural fingerprint in a candidate index and verifies
8+
any bucket collisions with full graph equality. This makes mapping-key and
9+
unique-sequence matching fast without trusting hashes as equality.
10+
11+
.EXAMPLE
12+
Find-YamlMergeIndexMatch -Index $retainedIndex -Node $overlayEntry.Key -Context $mergeContext
13+
14+
Returns the matching retained entry when the overlay key is structurally
15+
equal, or nothing when no match exists.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
519
#>
620
[CmdletBinding()]
721
[OutputType([pscustomobject])]
822
param (
23+
# The retained candidate index narrows possible structural matches.
924
[Parameter(Mandatory)]
1025
[pscustomobject] $Index,
1126

27+
# The overlay key or sequence item to match against retained candidates.
1228
[Parameter(Mandatory)]
1329
[pscustomobject] $Node,
1430

31+
# Shared merge context supplies fingerprint caches, equality state, and work limits.
1532
[Parameter(Mandatory)]
1633
[pscustomobject] $Context
1734
)

src/functions/private/Get-YamlMergeFingerprint.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,40 @@ function Get-YamlMergeFingerprint {
22
<#
33
.SYNOPSIS
44
Creates a deterministic structural candidate index for merge comparisons.
5+
6+
.DESCRIPTION
7+
Computes a deterministic structural fingerprint for a representation
8+
subgraph, resolving aliases and accounting for cycles without requiring
9+
object projection. The fingerprint narrows candidate comparisons for
10+
indexes and equality, while collision safety is provided by subsequent
11+
graph equality checks.
12+
13+
.EXAMPLE
14+
Get-YamlMergeFingerprint -Node $entry.Key -State $mergeContext.EqualityState -Cache $fingerprintCache -CandidateIndex $mappingIndex
15+
16+
Returns a deterministic hash used to place the key in a structural
17+
candidate bucket.
18+
19+
.LINK
20+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
521
#>
622
[CmdletBinding()]
723
[OutputType([string])]
824
param (
25+
# The subgraph root whose structure needs a candidate fingerprint.
926
[Parameter(Mandatory)]
1027
[pscustomobject] $Node,
1128

29+
# Provides hashing resources, work accounting, and index dependency maps.
1230
[Parameter(Mandatory)]
1331
[pscustomobject] $State,
1432

33+
# Reuses fingerprints for acyclic nodes to avoid repeated traversal work.
1534
[Parameter()]
1635
[AllowNull()]
1736
[System.Collections.Generic.Dictionary[int, string]] $Cache,
1837

38+
# Records node dependencies so mutations can invalidate this index.
1939
[Parameter()]
2040
[AllowNull()]
2141
[pscustomobject] $CandidateIndex

src/functions/private/Get-YamlMergeIndex.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,35 @@ function Get-YamlMergeIndex {
22
<#
33
.SYNOPSIS
44
Gets or rebuilds a mutation-aware structural candidate index.
5+
6+
.DESCRIPTION
7+
Retrieves the cached structural candidate index for a mapping or sequence,
8+
rebuilding it when mutations invalidated prior buckets. It lets recursive
9+
merge operations reuse fingerprint buckets while remaining correct after
10+
graph changes.
11+
12+
.EXAMPLE
13+
Get-YamlMergeIndex -Node $baseMapping -Kind Mapping -Context $mergeContext
14+
15+
Returns a valid mapping index for matching overlay keys against retained
16+
entries.
17+
18+
.LINK
19+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
520
#>
621
[CmdletBinding()]
722
[OutputType([pscustomobject])]
823
param (
24+
# The mapping or sequence node whose retained candidates need indexing.
925
[Parameter(Mandatory)]
1026
[pscustomobject] $Node,
1127

28+
# Selects whether entries or items are indexed for this node.
1229
[Parameter(Mandatory)]
1330
[ValidateSet('Mapping', 'Sequence')]
1431
[string] $Kind,
1532

33+
# Provides index caches, dependency tracking, and work accounting.
1634
[Parameter(Mandatory)]
1735
[pscustomobject] $Context
1836
)

src/functions/private/Get-YamlMergeNode.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@ function Get-YamlMergeNode {
22
<#
33
.SYNOPSIS
44
Resolves aliases to their effective YAML representation node.
5+
6+
.DESCRIPTION
7+
Follows alias targets until the effective representation node is reached.
8+
Merge comparison, indexing, and mutation bookkeeping use this canonical
9+
node so aliases do not create false differences.
10+
11+
.EXAMPLE
12+
Get-YamlMergeNode -Node $aliasNode
13+
14+
Returns the alias target node, or the original node when it is not an
15+
alias.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
519
#>
620
[CmdletBinding()]
721
[OutputType([pscustomobject])]
822
param (
23+
# The node to canonicalize before merge bookkeeping or comparison.
924
[Parameter(Mandatory)]
1025
[pscustomobject] $Node
1126
)

src/functions/private/Get-YamlMergeNodeTag.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@ function Get-YamlMergeNodeTag {
22
<#
33
.SYNOPSIS
44
Gets the effective tag used for YAML merge compatibility.
5+
6+
.DESCRIPTION
7+
Resolves aliases and returns the effective YAML tag used to decide merge
8+
compatibility. Scalars are resolved first so implicit tags reflect
9+
constructed values rather than presentation text.
10+
11+
.EXAMPLE
12+
Get-YamlMergeNodeTag -Node $candidateNode
13+
14+
Returns the effective tag, such as tag:yaml.org,2002:str, for merge
15+
comparisons.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
519
#>
620
[CmdletBinding()]
721
[OutputType([string])]
822
param (
23+
# The representation node whose effective compatibility tag is needed.
924
[Parameter(Mandatory)]
1025
[pscustomobject] $Node
1126
)

src/functions/private/Get-YamlMergePath.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,33 @@ function Get-YamlMergePath {
22
<#
33
.SYNOPSIS
44
Creates a stable diagnostic path for one YAML mapping entry.
5+
6+
.DESCRIPTION
7+
Builds a stable human-readable path for a child mapping key during
8+
recursive merge conflict reporting. Scalar string keys use property or
9+
quoted-index syntax, while complex keys fall back to deterministic entry
10+
indexes.
11+
12+
.EXAMPLE
13+
Get-YamlMergePath -Parent '$.spec' -Key $entry.Key -Index 2
14+
15+
Returns a diagnostic child path such as $.spec.name or $.spec{key:2}.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Merge-Yaml/
519
#>
620
[CmdletBinding()]
721
[OutputType([string])]
822
param (
23+
# Carries the already-resolved parent path for nested diagnostics.
924
[Parameter(Mandatory)]
1025
[string] $Parent,
1126

27+
# Determines the child path segment from the overlay mapping key.
1228
[Parameter(Mandatory)]
1329
[pscustomobject] $Key,
1430

31+
# Provides a deterministic fallback when the key is not a simple string.
1532
[Parameter(Mandatory)]
1633
[int] $Index
1734
)

0 commit comments

Comments
 (0)