Skip to content

Commit 8cac127

Browse files
Constrain conformance policy to four cases
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 707fc2a commit 8cac127

4 files changed

Lines changed: 71 additions & 65 deletions

File tree

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,25 @@ The offline test gate runs the complete released `yaml-test-suite` data corpus
167167
at commit `6ad3d2c62885d82fc349026c136ef560838fdf3d` (generated from source
168168
commit `45db50ae`). The pinned archive contains 402 inputs:
169169

170-
- all 94 fixtures marked invalid are rejected;
171-
- 306 of 308 fixtures marked valid are accepted;
172-
- the other two valid-syntax fixtures, `2JQS` and `X38W`, are deliberately
173-
rejected because this module rejects duplicate mapping keys;
174-
- 282 fixtures include `in.json`; three belong to invalid inputs, 277 of the
175-
279 applicable constructions match exactly, and two use a different
176-
documented projection policy.
177-
178-
The two construction-policy differences are `565N`, where this module
179-
constructs `!!binary` as `byte[]` instead of a Base64 string, and `J7PZ`, where
180-
the explicitly supported `!!omap` tag becomes an ordered dictionary instead of
181-
remaining a sequence of one-entry mappings. The deterministic runner reports
182-
398 passing cases, four policy exclusions, and no unexplained failures.
170+
| Surface | Pass | PolicyDifference | Fail | NotApplicable |
171+
| --- | ---: | ---: | ---: | ---: |
172+
| Syntax and composition | 400 | 2 | 0 | 0 |
173+
| Representation events | 308 | 0 | 0 | 94 |
174+
| JSON projection | 277 | 2 | 0 | 123 |
175+
| `out.yaml` projection | 241 | 0 | 0 | 161 |
176+
| Emit and round trip | 306 | 0 | 0 | 96 |
177+
178+
All 94 fixtures marked invalid are rejected. The valid `2JQS` and `X38W`
179+
inputs are syntactically recognized and produce matching representation
180+
events, then are rejected during load validation because representation
181+
mapping keys must be unique. They are not unsupported grammar.
182+
183+
The two JSON projection differences are `565N`, where `!!binary` intentionally
184+
becomes `byte[]` instead of a Base64 string, and `J7PZ`, where legacy `!!omap`
185+
intentionally becomes `System.Collections.Specialized.OrderedDictionary`
186+
instead of remaining a sequence of one-entry mappings. No event mismatch is
187+
classified as policy. The deterministic runner reports no unexplained
188+
failures.
183189

184190
These results are a pinned compatibility measurement, not a claim that a finite
185191
corpus proves complete YAML 1.2.2 compliance.

tests/Conformance.Tests.ps1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,22 @@ Describe 'Released yaml-test-suite corpus accounting' {
3232
$suiteResults.Count | Should -Be 402
3333
}
3434

35-
It 'accounts for syntax acceptance, rejection, and policy differences' {
35+
It 'accounts for syntax recognition and representation-key load policy' {
3636
@($suiteResults | Where-Object SyntaxResult -EQ 'Pass').Count | Should -Be 400
3737
@($suiteResults | Where-Object SyntaxResult -EQ 'PolicyDifference').Count |
3838
Should -Be 2
3939
@($suiteResults | Where-Object SyntaxResult -EQ 'Fail').Count | Should -Be 0
4040
@($suiteResults | Where-Object SyntaxResult -EQ 'NotApplicable').Count |
4141
Should -Be 0
42-
@(
42+
$policyResults = @(
4343
$suiteResults |
4444
Where-Object SyntaxResult -EQ 'PolicyDifference' |
45-
Select-Object -ExpandProperty Case |
46-
Sort-Object
47-
) | Should -Be @('2JQS', 'X38W')
45+
Sort-Object Case
46+
)
47+
@($policyResults.Case) | Should -Be @('2JQS', 'X38W')
48+
@($policyResults.SyntaxReason | Select-Object -Unique) |
49+
Should -Be @('RepresentationMappingKeyUniqueness')
50+
@($policyResults | Where-Object EventResult -NE 'Pass').Count | Should -Be 0
4851
}
4952

5053
It 'accounts for parser representation/event comparisons' {
@@ -63,6 +66,16 @@ Describe 'Released yaml-test-suite corpus accounting' {
6366
@($suiteResults | Where-Object JsonResult -EQ 'Fail').Count | Should -Be 0
6467
@($suiteResults | Where-Object JsonResult -EQ 'NotApplicable').Count |
6568
Should -Be 123
69+
$policyResults = @(
70+
$suiteResults |
71+
Where-Object JsonResult -EQ 'PolicyDifference' |
72+
Sort-Object Case
73+
)
74+
@($policyResults.Case) | Should -Be @('565N', 'J7PZ')
75+
@($policyResults.JsonReason) | Should -Be @(
76+
'BinaryByteArrayProjection',
77+
'LegacyOrderedMapProjection'
78+
)
6679
}
6780

6881
It 'accounts for out.yaml representation comparisons' {

tests/Specification.Tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,20 @@ Describe 'Pinned yaml-test-suite reference cases' {
202202
$result.canonical,
203203
$result.generic
204204
) | Should -BeTrue
205+
, $result.canonical | Should -BeOfType [byte[]]
206+
, $result.generic | Should -BeOfType [byte[]]
207+
}
208+
209+
It 'projects the legacy ordered map in case J7PZ as an ordered dictionary' {
210+
$result = @'
211+
--- !!omap
212+
- Mark McGwire: 65
213+
- Sammy Sosa: 63
214+
- Ken Griffy: 58
215+
'@ | ConvertFrom-Yaml
216+
217+
$result | Should -BeOfType [System.Collections.Specialized.OrderedDictionary]
218+
@($result.Keys) | Should -Be @('Mark McGwire', 'Sammy Sosa', 'Ken Griffy')
219+
@($result.Values) | Should -Be @(65, 63, 58)
205220
}
206221
}

tests/tools/Invoke-YamlTestSuite.ps1

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -243,26 +243,19 @@ function ConvertTo-YamlSuiteReferenceSignature {
243243
return ($output -join ';')
244244
}
245245

246-
function Get-YamlSuitePolicyReason {
246+
function Get-YamlSuiteJsonPolicyReason {
247247
[CmdletBinding()]
248248
[OutputType([string])]
249249
param (
250-
[string] $YamlText,
251-
[string] $Expected,
252-
[string] $Actual,
253-
[string] $DefaultReason
250+
[Parameter(Mandatory)]
251+
[string] $Case
254252
)
255253

256-
if ($DefaultReason) {
257-
return $DefaultReason
258-
}
259-
if ($YamlText -cmatch '!!(?:binary|omap|pairs|set|timestamp)(?:[ \t\r\n,\[\]\{\}]|$)') {
260-
return 'StandardTagProjectionPolicy'
261-
}
262-
if (($Expected -match 'unsupported:' -or $Actual -match 'unsupported:')) {
263-
return 'PowerShellTypePolicy'
254+
switch -CaseSensitive ($Case) {
255+
'565N' { return 'BinaryByteArrayProjection' }
256+
'J7PZ' { return 'LegacyOrderedMapProjection' }
257+
default { return '' }
264258
}
265-
return ''
266259
}
267260

268261
function ConvertFrom-YamlSuiteEventText {
@@ -694,9 +687,10 @@ foreach ($inputFile in $inputFiles) {
694687
}
695688
if ($expectsError) {
696689
$syntaxResult = 'Pass'
697-
} elseif ($_.Exception.Data['YamlErrorId'] -eq 'YamlDuplicateKey') {
690+
} elseif ($casePath -cin @('2JQS', 'X38W') -and
691+
$_.Exception.Data['YamlErrorId'] -eq 'YamlDuplicateKey') {
698692
$syntaxResult = 'PolicyDifference'
699-
$syntaxReason = 'DuplicateKeyRejected'
693+
$syntaxReason = 'RepresentationMappingKeyUniqueness'
700694
} else {
701695
$syntaxResult = 'Fail'
702696
$syntaxReason = [string] $_.Exception.Data['YamlErrorId']
@@ -732,15 +726,8 @@ foreach ($inputFile in $inputFiles) {
732726
if (Compare-YamlSuiteCanonicalList -Left $actualEvents -Right $expectedEvents) {
733727
$eventResult = 'Pass'
734728
} else {
735-
$reason = Get-YamlSuitePolicyReason -YamlText $yaml -Expected ($expectedEvents -join "`n") `
736-
-Actual ($actualEvents -join "`n") -DefaultReason ''
737-
if ($reason) {
738-
$eventResult = 'PolicyDifference'
739-
$eventReason = $reason
740-
} else {
741-
$eventResult = 'Fail'
742-
$eventReason = 'EventMismatch'
743-
}
729+
$eventResult = 'Fail'
730+
$eventReason = 'EventMismatch'
744731
}
745732
}
746733
}
@@ -765,8 +752,7 @@ foreach ($inputFile in $inputFiles) {
765752
if ($projectedCanonical -ceq $expectedCanonical) {
766753
$jsonResult = 'Pass'
767754
} else {
768-
$reason = Get-YamlSuitePolicyReason -YamlText $yaml -Expected $expectedCanonical `
769-
-Actual $projectedCanonical -DefaultReason ''
755+
$reason = Get-YamlSuiteJsonPolicyReason -Case $casePath
770756
if ($reason) {
771757
$jsonResult = 'PolicyDifference'
772758
$jsonReason = $reason
@@ -794,15 +780,8 @@ foreach ($inputFile in $inputFiles) {
794780
if ($outCanonical -ceq $projectedCanonical) {
795781
$outYamlResult = 'Pass'
796782
} else {
797-
$reason = Get-YamlSuitePolicyReason -YamlText $yaml -Expected $projectedCanonical `
798-
-Actual $outCanonical -DefaultReason ''
799-
if ($reason) {
800-
$outYamlResult = 'PolicyDifference'
801-
$outYamlReason = $reason
802-
} else {
803-
$outYamlResult = 'Fail'
804-
$outYamlReason = 'OutYamlConstructionMismatch'
805-
}
783+
$outYamlResult = 'Fail'
784+
$outYamlReason = 'OutYamlConstructionMismatch'
806785
}
807786
} catch {
808787
if ($_.Exception.Data.Contains('IsYamlException')) {
@@ -820,7 +799,7 @@ foreach ($inputFile in $inputFiles) {
820799
$emitResult = 'NotApplicable'
821800
if ($expectsError) { $emitReason = 'InvalidSyntax' }
822801
} elseif ($projectionError) {
823-
$emitResult = 'PolicyDifference'
802+
$emitResult = 'Fail'
824803
$emitReason = $projectionError
825804
} elseif ($syntaxResult -eq 'PolicyDifference') {
826805
$emitResult = 'PolicyDifference'
@@ -855,19 +834,12 @@ foreach ($inputFile in $inputFiles) {
855834
if ($roundCanonical -ceq $projectedCanonical -and $roundReference -ceq $projectedReference) {
856835
$emitResult = 'Pass'
857836
} else {
858-
$reason = Get-YamlSuitePolicyReason -YamlText $yaml -Expected $projectedCanonical `
859-
-Actual $roundCanonical -DefaultReason ''
860-
if ($reason) {
861-
$emitResult = 'PolicyDifference'
862-
$emitReason = $reason
863-
} else {
864-
$emitResult = 'Fail'
865-
$emitReason = 'EmitRoundTripMismatch'
866-
}
837+
$emitResult = 'Fail'
838+
$emitReason = 'EmitRoundTripMismatch'
867839
}
868840
}
869841
} catch [System.NotSupportedException] {
870-
$emitResult = 'PolicyDifference'
842+
$emitResult = 'Fail'
871843
$emitReason = 'UnsupportedEmissionType'
872844
} catch {
873845
if ($_.Exception.Data.Contains('IsYamlException')) {

0 commit comments

Comments
 (0)