# gov_pipeline_guard_v1.1.ps1 # Pipeline preventif end-to-end : # 1) Ingest AUTO_*.txt (sanitation stricte a l'entree) # 2) Scrub ASCII de la KB (systematique) # 3) Emission bootpack dual (pointer-only) # 4) Tests d'acceptation (gate) avec tentative d'auto-fix optionnelle # 5) Quicklog # PS 5.1-safe, ASCII-only dans le code, pas de ternaire. [CmdletBinding()] param( [switch]$Preview, [switch]$Execute, [string]$Root = "\\DS-918\chatgpt\ChatGPT-Gouvernance-Projets\_registry", [string]$StageRoot = "C:\Temp_Gouvernance", [bool]$AutoFix = $true, [bool]$DoIngest = $true ) 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 $ts = NowIso Write-Host "== PIPELINE GUARD v1.1 :: $ts ==" Write-Host "Root : $Root" Write-Host "Stage : $StageRoot" if($Execute){ Write-Host "Mode : EXECUTE" } else { Write-Host "Mode : PREVIEW" } Write-Host ("DoIngest={0} AutoFix={1}" -f $DoIngest,$AutoFix) # Step 1: INGEST if($DoIngest){ Write-Host "-- Step 1 :: BULK INGEST --" $outPrev = Run-Sub $S_ingest @('-Preview','-StageRoot',$StageRoot) Write-Host ($outPrev -join "`r`n") if($Execute){ $outExec = Run-Sub $S_ingest @('-Execute','-StageRoot',$StageRoot) Write-Host ($outExec -join "`r`n") } } # Step 2: ASCII SCRUB (systematique) 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") } # Step 3: EMIT 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") } # Step 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 } } # Step 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 termine."