Skip to content

Correct FeatureFlag and Properties JSON schemas (#105) - #112

Merged
HeyItsGilbert merged 3 commits into
mainfrom
fix/schema-corrections-105
Nov 3, 2026
Merged

HeyItsGilbert merged 3 commits into
mainfrom
fix/schema-corrections-105

Conversation

@HeyItsGilbert

Copy link
Copy Markdown
Owner

Summary

Gatekeeper/Schemas/
├── FeatureFlag.json   # Operator enum (+2), Not: object → array, Rules minItems dropped, Value rejects null, $id fixed
└── Properties.json    # draft-07 → 2020-12, real $id, Minimum/Maximum: number → integer, type-conditional Validation keys
 # FeatureFlag.json $defs.condition.oneOf[2] (Not)
-"Not": { "$ref": "#/$defs/condition" }
+"Not": { "type": "array", "items": { "$ref": "#/$defs/condition" }, "minItems": 1 }

 # FeatureFlag.json $defs.condition.oneOf[3] (leaf)
 "Operator": { "enum": ["Equals", "NotEquals", "GreaterThan", +"GreaterThanOrEqual", "LessThan", +"LessThanOrEqual", "In", "NotIn"] }
-"Value": {}
+"Value": { "not": { "type": "null" } }

 # Properties.json additionalProperties
-"$schema": "http://json-schema.org/draft-07/schema#"
+"$schema": "https://json-schema.org/draft/2020-12/schema", "$id": ".../Properties.json"
 "Minimum"/"Maximum": { "type": -"number" +"integer" }
+if Type=="integer" then forbid MinLength/MaxLength/Pattern
+else if Type=="string" then forbid Minimum/Maximum
+else (boolean) forbid all five Validation keys

One deliberate, documented gap: Minimum > Maximum on the same property is not schema-enforced. Standard JSON Schema (2020-12 core) has no declarative way to compare two sibling property values — that needs a $data extension unsupported by Test-Json or the default jsonschema validators. Properties.json carries a $comment explaining this and pointing at ADR 0007 / issue #103 item 21, where the bind-time Property.ps1 check is already tracked as deferred, breaking PowerShell-code work — out of scope here per #104/#105 ("no change to PowerShell's evaluation code").

Evidence

Before: FeatureFlag.json's Operator enum had 6/8 values, Not took a single object, Rules required minItems: 1, leaf Value accepted null, $id was https://example.com/schema/rule-schema.json. Properties.json was draft-07, no $id, Minimum/Maximum typed number, any Validation key legal on any Type.

After: confirmed via direct Test-Json calls — empty Rules passes, array-shaped Not passes, the old single-object Not now rejects, all 8 operators (including GreaterThanOrEqual) validate, Value: null now rejects, a string-typed property with Minimum/Maximum now rejects, a float Minimum now rejects. All three existing tests/fixtures/*.json files re-validated against both tightened schemas — still pass, no fixture changes needed.

.\build.ps1 -Task Test
Tests Passed: 368, Failed: 0, Skipped: 5, Inconclusive: 0, NotRun: 0
Success: True

(5 skips are pre-existing, unrelated to this change.)

Reviewed along Standards and Spec axes (parallel subagents): no documented-standard violations, two acceptable judgement-call smells noted in the Properties.json conditional (minor type-dispatch duplication, inherent to JSON Schema's weak composition); spec review confirms every #105 acceptance checkbox is met, with the Minimum > Maximum exception pre-approved and correctly documented.

Merge Danger

Door: Two-way — schema data only, trivially revertable, no runtime behavior changes.

Schema files are already validated by Property.ps1's Test-Json -SchemaFile call (PS7+) and by tests/Fixtures.tests.ps1. Tightening Properties.json (e.g. number→integer, type-conditional Validation keys) narrows what a PropertySet file may contain going forward on PS7 — the one acknowledged PowerShell-visible effect, flagged in #104 and already covered by the fixture audit above (no existing fixture is affected).

Blast Radius: Low — two schema files, zero PowerShell code changes, zero fixture changes.

Closes #105.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 17:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Automated schema tests lack coverage for the feature-flag corrections, property type/key restrictions, and fractional-bound rejection, so regressions could leave the suite green.

2 open issues
What changed in this PR

Aligns Gatekeeper’s JSON schemas with the agreed language-neutral specification without changing PowerShell evaluation code.

Changes:

  • Updates FeatureFlag validation to support all eight operators, array-shaped Not, and empty Rules, while rejecting null leaf values.
  • Moves Properties to JSON Schema 2020-12 and restricts validation keys by property type, with integer-only bounds.
  • Sets versioned schema identifiers and documents deferred cross-field bound validation.
File Description
Gatekeeper/​Schemas/​Properties.json Updates schema metadata and tightens property validation constraints.
Gatekeeper/​Schemas/​FeatureFlag.json Corrects operator coverage, condition shapes, rule cardinality, and null handling.

Review effort: Balanced

Comment thread Gatekeeper/Schemas/FeatureFlag.json Resolved
Comment thread Gatekeeper/Schemas/Properties.json Resolved
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Test Results

    4 files    548 suites   12s ⏱️
  415 tests   407 ✅  8 💤 0 ❌
1 616 runs  1 559 ✅ 57 💤 0 ❌

Results for commit 2e3a084.

♻️ This comment has been updated with latest results.

HeyItsGilbert added a commit that referenced this pull request Nov 3, 2026
The PSDepend 0.7.0-beta1 bump alone did not fix CI - the real cause is
PowerShellBuild's own module manifest declaring `Pester >= 5.6.1` as a
RequiredModules dependency, with no upper bound. Install-Module always
auto-resolves a target's RequiredModules independently of whatever this
repo's own requirements.psd1 `Pester` entry pins, so whichever install
reaches the Gallery first wins a race: if PowerShellBuild's own install
gets there before our pinned Pester 6.1.0 is on disk, PowerShellGet
fetches whatever's newest on PSGallery as a second, stray copy -
confirmed reproducible locally and non-deterministic depending on
install order.

PowerShellBuild's bundled Test task (`Test-PSBuildPester.ps1`) then
calls `Import-Module Pester -MinimumVersion 5.0.0` with no exact
version pin. -MinimumVersion always resolves to the HIGHEST matching
version found anywhere on $env:PSModulePath - never whatever's already
loaded under that name - so that stray newer copy gets a fresh load
attempt and collides with the Pester.dll our own pinned import already
Add-Type'd into the process, throwing 'assembly already loaded'/
'incompatible version' on every CI job (seen identically on PR #112's
ubuntu/windows/macOS runners, and reproduced on this branch's own first
CI attempt despite the PSDepend bump).

Fix: install and globally import the pinned Pester *before* handing
off to Invoke-PSDepend, so PowerShellGet already finds a satisfying
version on disk when it resolves PowerShellBuild's RequiredModules and
never reaches for anything else; prune and reassert afterward as
defense in depth against any other stray copy.

Verified: 3/3 clean-slate local runs (.\build.ps1 -Bootstrap -Task Test)
pass consistently - 368 passed, 0 failed, 5 skipped - including with a
second, newer Pester version pre-seeded on disk to force the exact
collision this fixes.
HeyItsGilbert added a commit that referenced this pull request Nov 3, 2026
PR #112's CI failed on every hosted runner with:
  Add-Type: Could not load file or assembly 'Pester, Version=6.1.0.0, ...'.
  Assembly with same name is already loaded

Root cause: PowerShellBuild (0.7.2, installed via requirements.psd1)
declares `Pester >= 5.6.1` as its own RequiredModules dependency, with
no upper bound. Install-Module always auto-resolves a target's
RequiredModules independently of whatever this repo's own `Pester`
entry pins, so whichever install reaches the Gallery first wins a
race: if PowerShellBuild's own install gets there before our pinned
Pester 6.1.0 is on disk, PowerShellGet fetches whatever's newest on
PSGallery as a second, stray copy (confirmed non-deterministic
locally, depending on install order).

PowerShellBuild's bundled Test task (Test-PSBuildPester.ps1) then
calls `Import-Module Pester -MinimumVersion 5.0.0` with no exact
version pin. -MinimumVersion always resolves to the HIGHEST matching
version found anywhere on $env:PSModulePath - never whatever's already
loaded under that name - so that stray newer copy gets a fresh load
attempt and collides with the Pester.dll our own pinned import already
Add-Type'd into the process.

Fixes:
- requirements.psd1: PSDepend bumped to 0.7.0-beta1 (prerelease;
  AllowPrerelease flagged explicitly), whose transitive-dependency
  resolution (separate root installation contexts, transitive packages
  installed first) narrows this class of collision for dependencies
  PSDepend itself resolves.
- build.ps1 bootstrap:
  - PSDepend's own version is now read from requirements.psd1 and
    installed/imported by that exact (prerelease-aware) version,
    instead of "any version already on the machine" - the previous
    check never actually enforced the pin, and couldn't install a
    prerelease at all (Install-Module rejects a prerelease
    RequiredVersion without -AllowPrerelease).
  - Pester is now installed and globally imported at the pinned
    version *before* Invoke-PSDepend runs, so PowerShellGet already
    finds a satisfying version on disk when it resolves
    PowerShellBuild's RequiredModules and never reaches for anything
    else - closing the install-order race at its source.
  - A defense-in-depth pass after Invoke-PSDepend prunes any other
    installed Pester version and reasserts the pinned one, in case
    something else still lands a stray copy.

Verified:
- 3/3 clean-slate local runs (.\build.ps1 -Bootstrap -Task Test) pass
  consistently: 368 passed, 0 failed, 5 skipped, Analyze clean -
  including with a second, newer Pester version pre-seeded on disk to
  force the exact collision this fixes.
- Real CI on this branch: ubuntu-latest and macOS-latest both pass
  Run Tests (368/0/5 each) after two failed attempts that isolated the
  actual cause (PSDepend bump alone did not fix it; the install-order
  fix did). windows-latest's Pester task also passes 368/0/5 cleanly,
  confirming the collision itself is resolved on every platform; that
  job currently fails afterward in the unrelated ANALYZE task
  (PSScriptAnalyzer NullReferenceException in
  Test-PSBuildScriptAnalysis.ps1), a separate, pre-existing issue not
  touched by this change.
HeyItsGilbert added a commit that referenced this pull request Nov 3, 2026
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.
HeyItsGilbert added a commit that referenced this pull request Nov 3, 2026
## Summary

CI on PR #112 failed identically on every hosted runner:
```
Add-Type: Could not load file or assembly 'Pester, Version=6.1.0.0, ...'.
Assembly with same name is already loaded
```

```
build.ps1 Bootstrap
├── PSDepend: now installed/imported at the exact (prerelease-aware)
│   version requirements.psd1 pins, instead of "any version already present"
└── Pester: installed + globally imported *before* Invoke-PSDepend runs,
    closing an install-order race against PowerShellBuild's own
    RequiredModules-driven Pester install
```

**Root cause**: `PowerShellBuild` (0.7.2) declares `Pester >= 5.6.1` as
its own `RequiredModules` dependency, no upper bound. `Install-Module`
always auto-resolves a target's `RequiredModules` independently of
whatever this repo's own `requirements.psd1` `Pester` entry pins —
whichever install reaches the Gallery first wins a race. If
`PowerShellBuild`'s own install lands before our pinned Pester 6.1.0 is
on disk, PowerShellGet fetches whatever's newest on PSGallery as a
second, stray copy (confirmed non-deterministic locally across repeated
clean-slate runs).

`PowerShellBuild`'s bundled Test task (`Test-PSBuildPester.ps1`) then
calls `Import-Module Pester -MinimumVersion 5.0.0` — no exact pin.
`-MinimumVersion` always resolves to the *highest* matching version
found anywhere on `$env:PSModulePath`, never whatever's already loaded
under that name, so the stray newer copy gets a fresh load attempt and
collides with the `Pester.dll` already `Add-Type`'d into the process.

```diff
 # build.ps1 bootstrap, simplified
-if (-not (Get-Module -Name PSDepend -ListAvailable)) {
-    Install-Module -Name PSDepend -Repository PSGallery -Scope CurrentUser -Force
-}
-Import-Module -Name PSDepend -Verbose:$false
+# read PSDepend.Version from requirements.psd1, install/import exactly that
+...
+# install + globally import the pinned Pester *before* touching PowerShellBuild,
+# so PowerShellGet already finds it satisfying and never reaches for anything else
+...
 Invoke-PSDepend -Path './requirements.psd1' -Install -Import -Force -WarningAction SilentlyContinue
+# defense in depth: prune any other installed Pester version, reassert the pin
```

**Investigation note**: the first fix attempt (bumping `PSDepend` to
`0.7.0-beta1` alone, on the theory its new transitive-dependency
resolution would prevent the stray install) reproduced the *identical*
failure on real CI — confirming the bump alone wasn't sufficient and the
actual trigger was the install-order race above, not something
`PSDepend`'s own dependency graph controls (`PowerShellGet`'s native
`RequiredModules` auto-install, invoked inside a single `Install-Module`
call, happens beneath `PSDepend` entirely). The `PSDepend` bump is kept
— it's a legitimate improvement and narrows this class of collision for
dependencies `PSDepend` itself resolves — but the actual fix is the
install-order change in `build.ps1`.

## Evidence

**Before**: PR #112, all three `Run Tests (macOS/windows/ubuntu-latest)`
jobs failed identically at `./build.ps1 -Task Test -Bootstrap`, before
any test ran.

**After** (this branch, real CI):
- `ubuntu-latest`: **pass**, 368/0/5
- `macOS-latest`: **pass**, 368/0/5
- `windows-latest`: Pester task **passes cleanly**, 368/0/5 — confirming
the collision itself is resolved on every platform. That job currently
fails *afterward*, in the unrelated `ANALYZE` task (`PSScriptAnalyzer`
`NullReferenceException` in `Test-PSBuildScriptAnalysis.ps1`) — a
separate, pre-existing issue this change doesn't touch and didn't
introduce (nothing here touches `PSScriptAnalyzer` config, and the local
Linux `Analyze` task runs clean on every local run below).
- `PowerShell 5.1` job: pending at last check.

**Local** (3/3 consecutive clean-slate runs, each with a second, newer
Pester version pre-seeded on disk to force the exact collision):
```
Tests Passed: 368, Failed: 0, Skipped: 5, Inconclusive: 0, NotRun: 0
Success      : True
```

## Merge Danger

**Door:** Two-way — build-tooling/bootstrap only, no production code
touched; trivially revertable.

**Blast Radius:** Low, build/CI-only. `PSDepend 0.7.0-beta1` is a
prerelease, flagged explicitly via `AllowPrerelease` so the intent is
visible in `requirements.psd1`. The windows-latest `ANALYZE` failure is
called out above as a known, separate, pre-existing gap — not claimed as
fixed by this PR.
- 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
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.
….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.
@HeyItsGilbert
HeyItsGilbert force-pushed the fix/schema-corrections-105 branch from d107195 to 2e3a084 Compare November 3, 2026 19:58
HeyItsGilbert added a commit that referenced this pull request Nov 3, 2026
…hs (#114)

## Summary

```diff
 # .github/workflows/Pages.yaml
       additional_copies: |
         static/:docs/assets/images/
         guides/:docs/guides/
+        Gatekeeper/Schemas/:docs/schema/1.0.0/
```

Both schema files' `$id` now point at
`https://heyitsgilbert.github.io/Gatekeeper/schema/1.0.0/{FeatureFlag,Properties}.json`
(#105), but nothing ever published them there — the Pages workflow only
ever copied `static/` and `guides/` into `docs/` before the `mkdocs
build`. Those `$id` URLs have been 404 since the schema correction
landed.

Follows the exact `source:destination` pattern already in use for
`static/`/`guides/`. `mkdocs` copies non-Markdown files under `docs/` as
static assets verbatim, preserving the relative path — so both JSON
files land at exactly the `$id` path once published (confirmed via
`site_url: http://heyitsgilbert.github.io/Gatekeeper` +
`docs/schema/1.0.0/*.json` →
`https://heyitsgilbert.github.io/Gatekeeper/schema/1.0.0/*.json`).

## Evidence

**Before:** `Gatekeeper/Schemas/*.json` never copied into `docs/`; the
`$id` URLs 404.

**After (local verification):** replicated the reusable workflow's exact
`Copy-Item -Path $source -Destination $dest -Recurse -Force` logic
(confirmed a directory source with a trailing slash copies *contents*
into the destination, not a nested subfolder) against a scratch `docs/`
tree, then ran a real `mkdocs build` (Material theme + plugins from
`docs/requirements.txt`) against it:

```
INFO    -  Building documentation to directory: /tmp/site-build
INFO    -  Documentation built in 0.28 seconds
```

```
$ find /tmp/site-build/schema -type f
/tmp/site-build/schema/1.0.0/FeatureFlag.json
/tmp/site-build/schema/1.0.0/Properties.json
```

Both files land at exactly
`site-dir/schema/1.0.0/{FeatureFlag,Properties}.json`. Content in this
verification reflects `main`'s current *pre-#112* schema (placeholder
`$id`), since #112 hasn't merged yet — this PR is about the publish
*path*, not schema content; the correct `$id` values publish
automatically on the next Pages build once #112 lands, no further change
needed here.

## Merge Danger

**Door:** Two-way — one workflow-input line, trivially revertable.

**Blast Radius:** Low. Purely additive to the Pages build (new files
published under `/schema/1.0.0/`); doesn't touch any existing copied
path, nav entry, or schema file content.
@HeyItsGilbert
HeyItsGilbert merged commit e64a76e into main Nov 3, 2026
9 checks passed
@HeyItsGilbert
HeyItsGilbert deleted the fix/schema-corrections-105 branch November 3, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Correct the FeatureFlag and PropertySet JSON schemas

2 participants