param( [switch]$SkipRace, [switch]$SkipFuzz ) $ErrorActionPreference = "Stop" if (Get-Variable -Name PSNativeCommandUseErrorActionPreference -ErrorAction SilentlyContinue) { $PSNativeCommandUseErrorActionPreference = $false } function Invoke-Go { param( [string[]]$GoArgs, [switch]$CaptureOutput ) if ($CaptureOutput) { $output = & go @GoArgs 2>&1 return @{ Code = $LASTEXITCODE Output = $output } } & go @GoArgs if ($LASTEXITCODE -ne 0) { throw "go $(($GoArgs) -join ' ') failed with exit code $LASTEXITCODE" } } function Run-Step { param( [string]$Name, [scriptblock]$Script ) Write-Host "==> $Name" & $Script Write-Host "OK: $Name" } Run-Step "Unit Tests" { Invoke-Go -GoArgs @("test", "./...") } if (-not $SkipRace) { Write-Host "==> Race Precheck" $raceResult = Invoke-Go -GoArgs @("test", "-race", "fmt") -CaptureOutput if ($raceResult.Code -ne 0) { $raceText = ($raceResult.Output | Out-String) if ($raceText -match "runtime/race: package testmain: cannot find package") { Write-Warning "Race environment issue detected: runtime/race cannot build testmain." Write-Warning "Skip race on this machine. CI race-linux job remains the source of truth." } else { Write-Output $raceText throw "Race precheck failed." } } else { Run-Step "Race Tests" { Invoke-Go -GoArgs @("test", "-race", "./...") } } } Run-Step "Benchmark Smoke" { Invoke-Go -GoArgs @("test", ".", "-run", "^$", "-bench", "Benchmark", "-benchmem", "-benchtime=100x") } if (-not $SkipFuzz) { Run-Step "Fuzz Smoke (Text/JSON)" { Invoke-Go -GoArgs @("test", ".", "-run", "^$", "-fuzz=FuzzTextAndJSONFormatter", "-fuzztime=2s") } Run-Step "Fuzz Smoke (Keyword)" { Invoke-Go -GoArgs @("test", ".", "-run", "^$", "-fuzz=FuzzKeywordHighlight", "-fuzztime=2s") } } Write-Host "All selected checks completed."