# ByteSize verification gate. # # Runs the four checks that have to be green before a change is done: # the frontend type gate, then the Rust check, lint and test passes. # # Run it from the repo root: # # powershell -File verify.ps1 # # Exit code 0 means everything passed. Any failure stops the run and names the # failing step, because a later step's output is noise once an earlier one broke. $root = $PSScriptRoot $failures = @() $passed = @() function Invoke-Step { param( [string]$Name, [scriptblock]$Body ) Write-Host "" Write-Host "=== $Name ===" -ForegroundColor Cyan # npm and cargo both write progress banners to stderr. Under # ErrorActionPreference=Stop that becomes a terminating NativeCommandError # in PowerShell 5.1, so relax it for the duration of the call and judge the # step on its exit code instead. $previous = $ErrorActionPreference $ErrorActionPreference = 'Continue' try { $output = & $Body 2>&1 | ForEach-Object { "$_" } $code = $LASTEXITCODE } finally { $ErrorActionPreference = $previous } $output | ForEach-Object { Write-Host $_ } if ($code -ne 0) { $script:failures += "$Name (exit $code)" return $false } Write-Host "ok: $Name" -ForegroundColor Green $script:passed += $Name return $true } if (-not (Test-Path (Join-Path $root 'node_modules'))) { Write-Host "node_modules is missing - the frontend gate cannot run." -ForegroundColor Yellow Write-Host "Install it with the per-command override, because the user-level" Write-Host "allow-scripts setting belongs to another project and npm 12 rejects it:" Write-Host "" Write-Host " `$env:npm_config_allow_scripts = ''; npm ci --no-audit --no-fund" Write-Host "" exit 1 } Push-Location $root try { $null = Invoke-Step 'svelte-check (frontend types)' { npm run check } # Type checking does not exercise Rollup, so a broken entry or import still # needs the real build to be caught. $null = Invoke-Step 'vite build' { npm run build } if ($failures.Count -eq 0) { $null = Invoke-Step 'cargo check' { cargo check --manifest-path src-tauri/Cargo.toml } } # -D warnings matters: clippy exits 0 when it only has warnings, so without # this the gate passes on a warning-laden build. --all-targets matters too: # without it clippy never compiles #[cfg(test)], so the test modules go # unlinted. if ($failures.Count -eq 0) { $null = Invoke-Step 'cargo clippy' { cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings } } if ($failures.Count -eq 0) { $null = Invoke-Step 'cargo test' { cargo test --manifest-path src-tauri/Cargo.toml } } } finally { Pop-Location } Write-Host "" if ($failures.Count -gt 0) { Write-Host "FAILED:" -ForegroundColor Red $failures | ForEach-Object { Write-Host " - $_" -ForegroundColor Red } exit 1 } Write-Host "All $($passed.Count) checks passed:" -ForegroundColor Green $passed | ForEach-Object { Write-Host " - $_" -ForegroundColor Green } exit 0