@@ -26,78 +26,3 @@ if (-not $isValid) {
2626 exit 1
2727}
2828Write-Host ' ✓ Settings conform to JSON schema'
29-
30- # Load expected reference settings
31- Write-Host ' Comparing with reference settings...'
32- $referencePath = Join-Path $PSScriptRoot ' Settings.json'
33- $expectedSettings = Get-Content $referencePath - Raw | ConvertFrom-Json
34-
35- function Test-ObjectStructure {
36- <#
37- . SYNOPSIS
38- Compares the structure of two objects.
39-
40- . DESCRIPTION
41- Recursively compares the structure of an actual object against an expected object,
42- validating that all expected properties exist in the actual object.
43-
44- . OUTPUTS
45- System.String[]
46- Returns an array of error messages for any structural mismatches.
47- #>
48- [CmdletBinding ()]
49- param (
50- # The actual object to validate.
51- $Actual ,
52-
53- # The expected object structure to validate against.
54- $Expected ,
55-
56- # The current path in the object hierarchy (used for error reporting).
57- $Path = ' Root'
58- )
59-
60- $errors = @ ()
61-
62- # Get all properties from expected object
63- $expectedProps = $Expected.PSObject.Properties.Name
64- foreach ($prop in $expectedProps ) {
65- $currentPath = " $Path .$prop "
66-
67- if (-not $Actual.PSObject.Properties.Name.Contains ($prop )) {
68- $errors += " Missing property: $currentPath "
69- continue
70- }
71-
72- $actualValue = $Actual .$prop
73- $expectedValue = $Expected .$prop
74-
75- # Check if both are objects (not arrays or primitives)
76- if ($expectedValue -is [PSCustomObject ] -and $actualValue -is [PSCustomObject ]) {
77- $errors += Test-ObjectStructure - Actual $actualValue - Expected $expectedValue - Path $currentPath
78- } elseif ($expectedValue -is [array ] -and $actualValue -is [array ]) {
79- # For arrays, just verify they're both arrays - don't compare contents
80- Write-Host " ✓ Array property: $currentPath "
81- } elseif ($null -eq $expectedValue -and $null -eq $actualValue ) {
82- # Both null is fine
83- Write-Host " ✓ Null property: $currentPath "
84- } elseif (($null -eq $expectedValue -and $null -ne $actualValue ) -or ($null -ne $expectedValue -and $null -eq $actualValue )) {
85- # One null, one not - this is an error
86- $errors += " Null mismatch at $currentPath (Expected null: $ ( $null -eq $expectedValue ) , Actual null: $ ( $null -eq $actualValue ) )"
87- }
88- }
89-
90- return $errors
91- }
92-
93- $structureErrors = Test-ObjectStructure - Actual $settings - Expected $expectedSettings
94-
95- if ($structureErrors.Count -gt 0 ) {
96- Write-Host ' '
97- Write-Host " Structure validation failed with $ ( $structureErrors.Count ) error(s):" - ForegroundColor Red
98- $structureErrors | ForEach-Object { Write-Host " - $_ " - ForegroundColor Red }
99- Write-Error ' Settings structure does not match expected layout. See errors above.'
100- exit 1
101- }
102-
103- Write-Host ' ✓ Settings structure matches expected layout'
0 commit comments