From 50dc79904bfe3c63d55dfed430670d6d56e89701 Mon Sep 17 00:00:00 2001 From: HeyItsGilbert Date: Tue, 3 Nov 2026 17:09:28 +0000 Subject: [PATCH 1/3] Correct FeatureFlag and Properties JSON schemas (#105) - FeatureFlag.json: Operator enum gains GreaterThanOrEqual/LessThanOrEqual (8 total); Not becomes a 1+-element array (NOR semantics, ADR 0003) instead of a single condition object; Rules drops minItems:1 so an empty Rules array (pure-DefaultEffect flag) validates; leaf Value rejects an explicit JSON null; $id moves from the example.com placeholder to the real heyitsgilbert.github.io schema URL. - Properties.json: $schema moves from draft-07 to JSON Schema 2020-12; gains a real $id; Minimum/Maximum are typed integer (not number); a 2020-12 if/then/else conditional restricts which Validation keys are legal per Type (Minimum/Maximum only on integer, MinLength/MaxLength/ Pattern only on string, none on boolean), per ADR 0007. - Minimum > Maximum rejection is intentionally left unenforced by the schema (documented via $comment): JSON Schema cannot compare two sibling property values declaratively without a extension unsupported by Test-Json or the default jsonschema validators. That check is bind-time PowerShell code work, already tracked as a deferred, breaking fix by ADR 0007 / issue #103 item 21. - Audited all three tests/fixtures/*.json against both corrected schemas via Test-Json; all three still validate, no fixture changes needed. Verified via Test-Json: empty Rules, array-shaped Not, all 8 operators, null-Value rejection, and the old object-shaped Not all behave as expected; type-conditional Validation restriction confirmed to reject cross-type keys and non-integer Minimum/Maximum. Full suite: .\build.ps1 -Task Test passes, 368 passed / 0 failed / 5 skipped (pre-existing skips, unrelated to this change). Resolves #105 --- Gatekeeper/Schemas/FeatureFlag.json | 19 ++++++--- Gatekeeper/Schemas/Properties.json | 62 ++++++++++++++++++++++++++--- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/Gatekeeper/Schemas/FeatureFlag.json b/Gatekeeper/Schemas/FeatureFlag.json index 0d2f1d0..9efe1ba 100644 --- a/Gatekeeper/Schemas/FeatureFlag.json +++ b/Gatekeeper/Schemas/FeatureFlag.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schema/rule-schema.json", + "$id": "https://heyitsgilbert.github.io/Gatekeeper/schema/1.0.0/FeatureFlag.json", "title": "Evaluation Rule Set", "type": "object", "required": [ @@ -38,8 +38,7 @@ "type": "array", "items": { "$ref": "#/$defs/rule" - }, - "minItems": 1 + } } }, "$defs": { @@ -115,7 +114,11 @@ ], "properties": { "Not": { - "$ref": "#/$defs/condition" + "type": "array", + "items": { + "$ref": "#/$defs/condition" + }, + "minItems": 1 } }, "additionalProperties": false @@ -136,12 +139,18 @@ "Equals", "NotEquals", "GreaterThan", + "GreaterThanOrEqual", "LessThan", + "LessThanOrEqual", "In", "NotIn" ] }, - "Value": {} + "Value": { + "not": { + "type": "null" + } + } }, "additionalProperties": false } diff --git a/Gatekeeper/Schemas/Properties.json b/Gatekeeper/Schemas/Properties.json index 3c10fcd..d4c2485 100644 --- a/Gatekeeper/Schemas/Properties.json +++ b/Gatekeeper/Schemas/Properties.json @@ -1,5 +1,6 @@ { - "$schema": "http://json-schema.org/draft-07/schema#", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://heyitsgilbert.github.io/Gatekeeper/schema/1.0.0/Properties.json", "title": "Property Metadata Schema", "type": "object", "properties": { @@ -29,10 +30,10 @@ "type": "object", "properties": { "Minimum": { - "type": "number" + "type": "integer" }, "Maximum": { - "type": "number" + "type": "integer" }, "MinLength": { "type": "integer" @@ -48,6 +49,57 @@ "additionalProperties": false } }, - "additionalProperties": false - } + "additionalProperties": false, + "if": { + "properties": { + "Type": { + "const": "integer" + } + } + }, + "then": { + "properties": { + "Validation": { + "properties": { + "MinLength": false, + "MaxLength": false, + "Pattern": false + } + } + } + }, + "else": { + "if": { + "properties": { + "Type": { + "const": "string" + } + } + }, + "then": { + "properties": { + "Validation": { + "properties": { + "Minimum": false, + "Maximum": false + } + } + } + }, + "else": { + "properties": { + "Validation": { + "properties": { + "Minimum": false, + "Maximum": false, + "MinLength": false, + "MaxLength": false, + "Pattern": false + } + } + } + } + } + }, + "$comment": "Minimum > Maximum on the same property is not enforced here: JSON Schema cannot compare two sibling values declaratively (no $data support in Test-Json or the default jsonschema validators). That check is bind-time PowerShell work tracked by ADR 0007 / issue #103 item 21." } From b5b936eb908e119e1c6d9ced25d7f77233da971f Mon Sep 17 00:00:00 2001 From: HeyItsGilbert Date: Tue, 3 Nov 2026 19:11:43 +0000 Subject: [PATCH 2/3] test: add schema regression tests addressing PR #112 review feedback tests/Fixtures.tests.ps1 only ever validated the three existing fixtures, none of which exercise an empty Rules array, either new operator, a nonempty array-shaped Not, or a null leaf Value - so reverting any of those FeatureFlag.json corrections would still leave the suite green. Likewise no fixture exercises a forbidden Validation-key/Type combination or a fractional Minimum/Maximum, so reverting the Properties.json type-conditional restriction or the number->integer bound change would also go unnoticed. Adds tests/Schemas.tests.ps1, asserting both schema files directly via Test-Json against minimal inline JSON documents (not fixtures), one case per corrected rule: - FeatureFlag.json: empty Rules validates; all 8 Operator values validate individually (parameterized) and a 9th, out-of-enum value is rejected; a nonempty (and multi-element) array-shaped Not validates; the pre-correction single-object Not and an empty-array Not are both rejected; a null leaf Value is rejected, a non-null one validates. - Properties.json: parameterized cases cross Type x Validation key for every forbidden combination (Minimum/Maximum on string or boolean, MinLength/MaxLength/Pattern on integer or boolean) alongside the legal combination per Type; a fractional Minimum and Maximum are each rejected on an integer property; Enum is confirmed unrestricted across all three Types (explicitly unchanged by this correction). Verified the new file actually regression-tests (not just restates) the fix: temporarily restored both schema files to their pre-#105 content and reran tests/Schemas.tests.ps1 in isolation - 16 of the 31 cases failed exactly as expected (the ones asserting a corrected behavior), 0 false failures on cases that were already true before #105. Restored the corrected schemas and reran the full suite: .\build.ps1 -Bootstrap -Task Test passes, 399 passed (368 + 31 new), 0 failed, 5 skipped, Analyze clean. --- tests/Schemas.tests.ps1 | 167 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 tests/Schemas.tests.ps1 diff --git a/tests/Schemas.tests.ps1 b/tests/Schemas.tests.ps1 new file mode 100644 index 0000000..aeadcf2 --- /dev/null +++ b/tests/Schemas.tests.ps1 @@ -0,0 +1,167 @@ +# Regression tests for the schema corrections made to Gatekeeper/Schemas/*.json +# (see issue #105). These assert the schema *files* directly via Test-Json, so a +# revert of either file - or of any single corrected rule inside it - fails here, +# independent of whatever any particular fixture under tests/fixtures/ happens to +# exercise. +BeforeAll { + $script:featureFlagSchema = Join-Path $PSScriptRoot '..\Gatekeeper\Schemas\FeatureFlag.json' + $script:propertiesSchema = Join-Path $PSScriptRoot '..\Gatekeeper\Schemas\Properties.json' + + function Test-AgainstSchema { + param( + [Parameter(Mandatory)][string]$Json, + [Parameter(Mandatory)][string]$SchemaFile + ) + try { + Test-Json -Json $Json -SchemaFile $SchemaFile -ErrorAction Stop + } catch { + $false + } + } + + # Minimal otherwise-valid FeatureFlag document; $Condition is spliced into the + # single rule's Condition so each case only has to describe the piece under test. + function New-FeatureFlagJson { + param([Parameter(Mandatory)][hashtable]$Condition) + $rule = @{ + Name = 'Rule' + Effect = 'Allow' + Condition = $Condition + } | ConvertTo-Json -Depth 10 -Compress + @{ + Name = 'Flag' + Description = 'Desc' + Version = '1.0.0' + DefaultEffect = 'Deny' + Rules = @(ConvertFrom-Json $rule) + } | ConvertTo-Json -Depth 10 + } +} + +Describe 'FeatureFlag.json' { + Context 'Rules cardinality' { + It 'Validates an empty Rules array with only a DefaultEffect' { + $json = @{ + Name = 'Flag' + Description = 'Desc' + Version = '1.0.0' + DefaultEffect = 'Allow' + Rules = @() + } | ConvertTo-Json + Test-AgainstSchema -Json $json -SchemaFile $script:featureFlagSchema | Should -BeTrue + } + } + + Context 'Operator enum' -ForEach @( + @{ Operator = 'Equals' } + @{ Operator = 'NotEquals' } + @{ Operator = 'GreaterThan' } + @{ Operator = 'GreaterThanOrEqual' } + @{ Operator = 'LessThan' } + @{ Operator = 'LessThanOrEqual' } + @{ Operator = 'In' } + @{ Operator = 'NotIn' } + ) { + It "Validates Operator ''" { + $json = New-FeatureFlagJson -Condition @{ Property = 'Tier'; Operator = $Operator; Value = 1 } + Test-AgainstSchema -Json $json -SchemaFile $script:featureFlagSchema | Should -BeTrue + } + } + + It 'Rejects an Operator outside the enum' { + $json = New-FeatureFlagJson -Condition @{ Property = 'Tier'; Operator = 'Contains'; Value = 1 } + Test-AgainstSchema -Json $json -SchemaFile $script:featureFlagSchema | Should -BeFalse + } + + Context 'Not shape' { + It 'Validates a nonempty array-shaped Not (NOR semantics, ADR 0003)' { + $json = New-FeatureFlagJson -Condition @{ + Not = @(@{ Property = 'Tier'; Operator = 'Equals'; Value = 1 }) + } + Test-AgainstSchema -Json $json -SchemaFile $script:featureFlagSchema | Should -BeTrue + } + + It 'Validates a multi-element array-shaped Not' { + $json = New-FeatureFlagJson -Condition @{ + Not = @( + @{ Property = 'Tier'; Operator = 'Equals'; Value = 1 } + @{ Property = 'Tier'; Operator = 'Equals'; Value = 2 } + ) + } + Test-AgainstSchema -Json $json -SchemaFile $script:featureFlagSchema | Should -BeTrue + } + + It 'Rejects the pre-correction single-object Not shape' { + $json = New-FeatureFlagJson -Condition @{ + Not = @{ Property = 'Tier'; Operator = 'Equals'; Value = 1 } + } + Test-AgainstSchema -Json $json -SchemaFile $script:featureFlagSchema | Should -BeFalse + } + + It 'Rejects an empty-array Not (minItems: 1)' { + $json = New-FeatureFlagJson -Condition @{ Not = @() } + Test-AgainstSchema -Json $json -SchemaFile $script:featureFlagSchema | Should -BeFalse + } + } + + Context 'Leaf Value' { + It 'Rejects an explicit JSON null Value' { + $json = New-FeatureFlagJson -Condition @{ Property = 'Tier'; Operator = 'Equals'; Value = $null } + Test-AgainstSchema -Json $json -SchemaFile $script:featureFlagSchema | Should -BeFalse + } + + It 'Validates a non-null Value' { + $json = New-FeatureFlagJson -Condition @{ Property = 'Tier'; Operator = 'Equals'; Value = 'Staging' } + Test-AgainstSchema -Json $json -SchemaFile $script:featureFlagSchema | Should -BeTrue + } + } +} + +Describe 'Properties.json' { + Context 'Validation keys applicable per Type' -ForEach @( + @{ Type = 'integer'; Validation = @{ Minimum = 0; Maximum = 10 }; Expected = $true } + @{ Type = 'integer'; Validation = @{ MinLength = 1 }; Expected = $false } + @{ Type = 'integer'; Validation = @{ MaxLength = 1 }; Expected = $false } + @{ Type = 'integer'; Validation = @{ Pattern = '^\d+$' }; Expected = $false } + @{ Type = 'string'; Validation = @{ MinLength = 1; MaxLength = 5; Pattern = '^\d+$' }; Expected = $true } + @{ Type = 'string'; Validation = @{ Minimum = 0 }; Expected = $false } + @{ Type = 'string'; Validation = @{ Maximum = 10 }; Expected = $false } + @{ Type = 'boolean'; Validation = @{ Minimum = 0 }; Expected = $false } + @{ Type = 'boolean'; Validation = @{ MinLength = 1 }; Expected = $false } + ) { + It "Type '' with Validation key(s) '' -> expected " { + $json = @{ + Prop = @{ Type = $Type; Validation = $Validation } + } | ConvertTo-Json -Depth 10 + Test-AgainstSchema -Json $json -SchemaFile $script:propertiesSchema | Should -Be $Expected + } + } + + Context 'Minimum/Maximum bound type' { + It 'Validates integer-typed Minimum/Maximum' { + $json = @{ Prop = @{ Type = 'integer'; Validation = @{ Minimum = 0; Maximum = 10 } } } | ConvertTo-Json -Depth 10 + Test-AgainstSchema -Json $json -SchemaFile $script:propertiesSchema | Should -BeTrue + } + + It 'Rejects a fractional Minimum' { + $json = @{ Prop = @{ Type = 'integer'; Validation = @{ Minimum = 0.5 } } } | ConvertTo-Json -Depth 10 + Test-AgainstSchema -Json $json -SchemaFile $script:propertiesSchema | Should -BeFalse + } + + It 'Rejects a fractional Maximum' { + $json = @{ Prop = @{ Type = 'integer'; Validation = @{ Maximum = 10.5 } } } | ConvertTo-Json -Depth 10 + Test-AgainstSchema -Json $json -SchemaFile $script:propertiesSchema | Should -BeFalse + } + } + + Context 'Enum applies to every Type (unchanged by this correction)' -ForEach @( + @{ Type = 'string' } + @{ Type = 'integer' } + @{ Type = 'boolean' } + ) { + It "Validates an Enum on a '' property" { + $json = @{ Prop = @{ Type = $Type; Enum = @() } } | ConvertTo-Json -Depth 10 + Test-AgainstSchema -Json $json -SchemaFile $script:propertiesSchema | Should -BeTrue + } + } +} From 2e3a084532d1ce20a07554f152fa2a03ba14c9eb Mon Sep 17 00:00:00 2001 From: HeyItsGilbert Date: Tue, 3 Nov 2026 19:22:09 +0000 Subject: [PATCH 3/3] fix: skip new schema tests on PowerShell 5.1, matching Fixtures.tests.ps1 Real CI caught it: Windows PowerShell 5.1's Test-Json doesn't support the JSON Schema 2020-12 features (oneOf, $defs, if/then/else) these schemas use, exactly the same gap tests/Fixtures.tests.ps1 already works around (-Skip:($PSVersionTable.PSVersion.Major -lt 7) on 'matches the schema'). tests/Schemas.tests.ps1 didn't carry that skip, so on PS 5.1 every Test-AgainstSchema call that expects $true threw and fell through to the catch block's $false - correctly flagged as a real failure by CI, not a flake. Added the same -Skip at the Describe level for both FeatureFlag.json and Properties.json. Verified: 31/31 still run (not skipped) and pass on pwsh 7 locally; full suite 399 passed, 0 failed, 5 skipped. --- tests/Schemas.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Schemas.tests.ps1 b/tests/Schemas.tests.ps1 index aeadcf2..24ed778 100644 --- a/tests/Schemas.tests.ps1 +++ b/tests/Schemas.tests.ps1 @@ -38,7 +38,7 @@ BeforeAll { } } -Describe 'FeatureFlag.json' { +Describe 'FeatureFlag.json' -Skip:($PSVersionTable.PSVersion.Major -lt 7) { Context 'Rules cardinality' { It 'Validates an empty Rules array with only a DefaultEffect' { $json = @{ @@ -117,7 +117,7 @@ Describe 'FeatureFlag.json' { } } -Describe 'Properties.json' { +Describe 'Properties.json' -Skip:($PSVersionTable.PSVersion.Major -lt 7) { Context 'Validation keys applicable per Type' -ForEach @( @{ Type = 'integer'; Validation = @{ Minimum = 0; Maximum = 10 }; Expected = $true } @{ Type = 'integer'; Validation = @{ MinLength = 1 }; Expected = $false }