@@ -135,6 +135,7 @@ Describe 'Generated artifact package' {
135135 ' Format-Yaml' ,
136136 ' Import-Yaml' ,
137137 ' Merge-Yaml' ,
138+ ' Remove-YamlEntry' ,
138139 ' Test-Yaml'
139140 )
140141 @ ($manifest.FileList ) | Should - Contain ' Yaml.psm1'
@@ -263,4 +264,54 @@ if ($mergedValue['service']['image'] -cne 'example:v2' -or
263264 Should - BeFalse
264265 Write-Information - MessageData $runtime - InformationAction Continue
265266 }
267+
268+ It ' removes representation entries in a fresh PowerShell 7.6 Core process' `
269+ - Skip:($skipArtifactTests -or $null -eq (Get-Command pwsh - ErrorAction SilentlyContinue)) {
270+ $script = @'
271+ $ErrorActionPreference = 'Stop'
272+ $ps = $PSVersionTable.PSVersion
273+ if ($ps -lt [version] '7.6') {
274+ throw "Expected PowerShell 7.6 or newer but got $ps."
275+ }
276+ if ($PSVersionTable.PSEdition -cne 'Core') {
277+ throw "Expected PowerShell Core but got $($PSVersionTable.PSEdition)."
278+ }
279+ Import-Module -Name '__MANIFEST__' -Force
280+ $removed = @"
281+ root: &shared
282+ keep: true
283+ drop: false
284+ copy: *shared
285+ "@ | Remove-YamlEntry -Path '/copy/drop'
286+ if ($removed -match "`r" -or $removed.EndsWith("`n", [System.StringComparison]::Ordinal)) {
287+ throw 'The imported removal command did not normalize its output contract.'
288+ }
289+ $value = $removed | ConvertFrom-Yaml -AsHashtable
290+ if ($value['root'].Contains('drop') -or $value['copy'].Contains('drop')) {
291+ throw 'The imported removal command did not mutate the shared mapping.'
292+ }
293+ if (-not [object]::ReferenceEquals($value['root'], $value['copy'])) {
294+ throw 'The imported removal command lost shared mapping identity.'
295+ }
296+ $empty = Remove-YamlEntry "---`nfirst: true`n---`nsecond: true" '' -AllDocuments
297+ if ($empty -cne '') {
298+ throw 'The imported removal command did not remove every selected document.'
299+ }
300+ "remove-runtime=$ps;edition=$($PSVersionTable.PSEdition)"
301+ '@ .Replace(' __MANIFEST__' , $artifactManifestPath.Replace (" '" , " ''" ))
302+
303+ $output = @ (& pwsh - NoLogo - NoProfile - Command $script )
304+ $LASTEXITCODE | Should - Be 0
305+ $runtime = $output | Where-Object { $_ -like ' remove-runtime=*' } |
306+ Select-Object - Last 1
307+
308+ $runtimeMatch = [regex ]::Match(
309+ [string ] $runtime ,
310+ ' ^remove-runtime=(?<Version>\d+(?:\.\d+){1,3});edition=Core$'
311+ )
312+ $runtimeMatch.Success | Should - BeTrue
313+ ([version ] $runtimeMatch.Groups [' Version' ].Value) -lt [version ] ' 7.6' |
314+ Should - BeFalse
315+ Write-Information - MessageData $runtime - InformationAction Continue
316+ }
266317}
0 commit comments