# gov_pipeline_guard_v1.0.ps1 # Pipeline "préventif" end-to-end : # - Ingest AUTO_*.txt (sanitation stricte à l'entrée) # - Scrub ASCII global de la KB (élimine tout non-ASCII résiduel) # - Émission bootpack dual (pointer-only) # - Tests d'acceptation comme "gate" (FAIL => tentative d'auto-fix si -AutoFix) # - Quicklog # PS 5.1-safe, pas de ternaire, ASCII-only dans le code. [CmdletBinding()] param( [switch]$Preview, [switch]$Execute, [string]$Root = "\\DS-918\chatgpt\ChatGPT-Gouvernance-Projets\_registry", [string]$StageRoot = "C:\Temp_Gouvernance", [bool]$AutoFix = $true, # tente un scrub+emit si l'acceptance fail en PREVIEW [bool]$DoIngest = $true # laisse a false si tu veux juste re-emit/valider ) function NowIso(){ (Get-Date).ToString("yyyy-MM-ddTHH:mm:ssK") } function Ensure-File([string]$p){ if(-not (Test-Path -LiteralPath $p)){ throw "Script manquant: $p" } } function Run-Sub([string]$script,[string[]]$moreArgs){ $psExe = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" $args = @('-NoProfile','-ExecutionPolicy','Bypass','-File', $script, '-Root', $Root) + $moreArgs & $psExe @args 2>&1 } $base = "C:\Temp_Gouvernance" $S_ingest = Join-Path $base "kb_bulk_ingest_v1.3.ps1" $S_scrub = Join-Path $base "kb_ascii_scrub_v1.0.ps1" $S_emit = Join-Path $base "kb_emit_bootpack_dual_v1.1.ps1" $S_accept = Join-Path $base "kb_acceptance_tests_v1.0.ps1" $S_quicklog = Join-Path $base "kb_quicklog_and_sync_v1.3.ps1" Ensure-File $S_ingest Ensure-File $S_scrub Ensure-File $S_emit Ensure-File $S_accept Ensure-File $S_quicklog Write-Host ("== PIPELINE GUARD v1.0 :: {0} ==" -f (NowIso())) Write-Host ("Root : {0}" -f $Root) Write-Host ("Stage : {0}" -f $StageRoot) Write-Host ("Mode : " + ($(if($Execute){"EXECUTE"}else{"PREVIEW"}))) Write-Host ("DoIngest={0} AutoFix={1}" -f $DoIngest,$AutoFix) # 1) INGEST if($DoIngest){ Write-Host "-- Step 1 :: BULK INGEST --" $outPrev = Run-Sub $S_ingest @('-Preview') $line = ($outPrev | Where-Object { $_ -match 'Candidates total:' } | Select-Object -Last 1) $cand=$null;$new=$null;$dup=$null if($line){ $m = [regex]::Match([string]$line,'Candidates total:\s*(\d+)\s+New:\s*(\d+)\s+Duplicates:\s*(\d+)') if($m.Success){ $cand=[int]$m.Groups[1].Value; $new=[int]$m.Groups[2].Value; $dup=[int]$m.Groups[3].Value } } Write-Host ($outPrev -join "`r`n") if($Execute){ $outExec = Run-Sub $S_ingest @('-Execute') Write-Host ($outExec -join "`r`n") } } # 2) SCRUB ASCII systématique (préventif) Write-Host "-- Step 2 :: ASCII SCRUB KB --" $prevScrub = Run-Sub $S_scrub @('-Preview','-StageRoot',$StageRoot) Write-Host ($prevScrub -join "`r`n") if($Execute){ $execScrub = Run-Sub $S_scrub @('-Execute','-StageRoot',$StageRoot) Write-Host ($execScrub -join "`r`n") } # 3) ÉMISSION BOOTPACK DUAL Write-Host "-- Step 3 :: EMIT BOOTPACK DUAL --" $prevEmit = Run-Sub $S_emit @('-Preview','-StageRoot',$StageRoot) Write-Host ($prevEmit -join "`r`n") if($Execute){ $execEmit = Run-Sub $S_emit @('-Execute','-StageRoot',$StageRoot) Write-Host ($execEmit -join "`r`n") } # 4) ACCEPTANCE (gate) Write-Host "-- Step 4 :: ACCEPTANCE (gate) --" $accPrev = Run-Sub $S_accept @('-Preview') Write-Host ($accPrev -join "`r`n") $passPrev = $false foreach($l in $accPrev){ if(([string]$l) -match 'Result:\s+PASS'){ $passPrev = $true } } if(-not $passPrev -and $AutoFix){ Write-Host "Acceptance FAIL en PREVIEW -> tentative d'auto-fix (scrub+emit) puis re-test..." if($Execute){ $null = Run-Sub $S_scrub @('-Execute','-StageRoot',$StageRoot) $null = Run-Sub $S_emit @('-Execute','-StageRoot',$StageRoot) } $accPrev2 = Run-Sub $S_accept @('-Preview') Write-Host ($accPrev2 -join "`r`n") $passPrev = $false foreach($l in $accPrev2){ if(([string]$l) -match 'Result:\s+PASS'){ $passPrev = $true } } } if(-not $passPrev){ Write-Host "[ERR] Acceptance gate FAIL. Abandon." if(-not $Preview -and $Execute){ exit 10 } else { exit 0 } } # 5) QUICKLOG Write-Host "-- Step 5 :: QUICKLOG --" if($Execute){ $ql = Run-Sub $S_quicklog @('-Execute') Write-Host ($ql -join "`r`n") } else { $qlp = Run-Sub $S_quicklog @('-Preview') Write-Host ($qlp -join "`r`n") } Write-Host "[OK] Pipeline guard terminé."