# requires -version 5.1 # kb_bootpack_acceptance_v1.3.ps1 # Lecture-seule. Vérifie cohérence BootPack ↔ KB (SHA, entrées, blocages). # ASCII-only; UTF-8 BOM; no here-strings; no ternary. param( [Parameter(Mandatory=$true)][string]$Root ) function Get-Sha256Hex([string]$Path) { (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash } function Read-All([string]$Path) { Get-Content -LiteralPath $Path -Raw } # ---- Self-check (PS5.1): interdire '? :' hors chaînes/commentaires ---- $__scriptPath = $MyInvocation.MyCommand.Definition $__src = Read-All -Path $__scriptPath $__noComments = [regex]::Replace($__src, '(?m)#.*$', '') $__masked = [regex]::Replace($__noComments, "('[^']*')", "''") $__masked = [regex]::Replace($__masked, '("(?:[^"`]|`".)*")', '""') if($__masked -match '\?\s*:'){ Write-Host "[FAIL] STYLE_GUARD_PS51: opérateur ternaire détecté dans ce script." -ForegroundColor Red exit 2 } $bootPack = Join-Path $Root 'bootpack\bootpack.txt' $kbFile = Join-Path $Root 'bug_kb\BUG_KB.json.txt' $idxFile = Join-Path $Root 'rules\KB_BLOCKING_INDEX__docdigest_latest.txt' if(-not (Test-Path -LiteralPath $bootPack)){ Write-Host "[FAIL] BootPack introuvable: $bootPack"; exit 2 } if(-not (Test-Path -LiteralPath $kbFile)){ Write-Host "[FAIL] KB introuvable: $kbFile"; exit 2 } $bp = Read-All -Path $bootPack $ptrPath = "" $ptrShaNote = "" $entriesNote = -1 $lines = $bp -split "`r?`n" $inPtr = $false foreach($ln in $lines){ if($ln -match '^\s*\[BUG_KB_JSON_POINTER\]\s*$'){ $inPtr = $true; continue } if($inPtr){ if($ln -match '^\s*\['){ break } if($ln -match '^\s*Path\s*=\s*(.+)\s*$'){ $ptrPath = $Matches[1].Trim() } elseif($ln -match '^\s*SHA256\s*=\s*([0-9A-Fa-f]{64})\s*$'){ $ptrShaNote = $Matches[1].ToUpper() } elseif($ln -match '^\s*Entries\s*=\s*(\d+)\s*$'){ $entriesNote = [int]$Matches[1] } } } $ptrExists = $false $ptrShaMatch = $false $jsonEntries = 0 $blockingCount = 0 $kbSha = Get-Sha256Hex -Path $kbFile if(-not [string]::IsNullOrWhiteSpace($ptrPath)){ if(Test-Path -LiteralPath $ptrPath){ $ptrExists = $true } } if($ptrShaNote -ne ""){ if($kbSha.ToUpper() -eq $ptrShaNote){ $ptrShaMatch = $true } } Get-Content -LiteralPath $kbFile | ForEach-Object { $t = $_.Trim() if($t -match '^\{.*\}\s*$'){ $jsonEntries = $jsonEntries + 1 } if($t -match '"blocking"\s*:\s*true'){ $blockingCount = $blockingCount + 1 } } Write-Output ("entries={0}|blocking={1}|ptr_exists={2}|ptr_sha_match={3}|ptr_entries_note={4}|json_entries={5}" -f ` $jsonEntries, $blockingCount, $ptrExists, $ptrShaMatch, $entriesNote, $jsonEntries)