|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Run the native-Windows product-surface test suite for codebase-memory-mcp. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | + Builds the product binary (build/c/codebase-memory-mcp.exe) if it is not |
| 7 | + already present, then runs the deterministic Windows integration tests under |
| 8 | + tests/windows/ against a real codebase-memory-mcp.exe (real stdio / CLI / |
| 9 | + HTTP UI, real SQLite DB). |
| 10 | +
|
| 11 | + Two categories of test: |
| 12 | +
|
| 13 | + GUARDS - regression guards for Windows bugs already fixed on main. |
| 14 | + They must stay GREEN (exit 0); a RED (exit 1) means the fix |
| 15 | + regressed and fails this runner. |
| 16 | + * test_non_ascii_path.py guards #636/#357 (fixed by #700) |
| 17 | + * test_hook_augment.py guards #618 (fixed by #619) |
| 18 | + * test_ui_drive_listing.py guards #548 (roots field) |
| 19 | +
|
| 20 | + KNOWN REDS - genuine, still-open Windows bugs reproduced at the product |
| 21 | + surface. They are EXPECTED to be RED (exit 1) and are opt-in |
| 22 | + (never gate CI). If one turns GREEN the underlying bug was |
| 23 | + fixed and it should be promoted to a guard. |
| 24 | + * test_cli_non_ascii_arg.py reproduces #423/#20 (narrow |
| 25 | + argv main() - no wide command line) |
| 26 | +
|
| 27 | + Determinism: indexing runs in-process (CBM_INDEX_SUPERVISOR=0). These tests |
| 28 | + exercise path / hook / drive handling, not the index-supervisor subprocess |
| 29 | + path; the pass-level readers (#700's cbm_fopen routing) run in-process either |
| 30 | + way, so the guard coverage is identical while results stay independent of the |
| 31 | + local toolchain's worker-spawn behavior. |
| 32 | +
|
| 33 | + On native Windows the MinGW/LLVM toolchain ships no libasan/libubsan, so the |
| 34 | + build disables sanitizers (SANITIZE=). Where the toolchain provides |
| 35 | + AddressSanitizer/UBSan (Linux containers, WSL), prefer scripts/test.sh. |
| 36 | +
|
| 37 | +.PARAMETER Binary |
| 38 | + Path to an existing codebase-memory-mcp.exe. If omitted, the script builds it |
| 39 | + (target selected by -Target) into build/c/. |
| 40 | +
|
| 41 | +.PARAMETER Target |
| 42 | + Makefile.cbm target used when building: 'cbm-with-ui' (default; needed for the |
| 43 | + drive-picker guard's embedded HTTP UI) or 'cbm' (no UI - the drive guard then |
| 44 | + reports a precondition and is skipped). |
| 45 | +
|
| 46 | +.PARAMETER GuardsOnly |
| 47 | + Run only the green guards (the CI gate). Skips the opt-in known-red repros. |
| 48 | +
|
| 49 | +.PARAMETER Make |
| 50 | + Path to GNU make (default: 'make' on PATH; MSYS2 ships it at |
| 51 | + C:\msys64\usr\bin\make.exe). |
| 52 | +
|
| 53 | +.EXAMPLE |
| 54 | + pwsh -File scripts/test-windows.ps1 |
| 55 | +.EXAMPLE |
| 56 | + pwsh -File scripts/test-windows.ps1 -GuardsOnly -Binary build\c\codebase-memory-mcp.exe |
| 57 | +#> |
| 58 | +[CmdletBinding()] |
| 59 | +param( |
| 60 | + [string]$Binary, |
| 61 | + [ValidateSet("cbm-with-ui", "cbm")] |
| 62 | + [string]$Target = "cbm-with-ui", |
| 63 | + [switch]$GuardsOnly, |
| 64 | + [string]$Make = "make" |
| 65 | +) |
| 66 | + |
| 67 | +$ErrorActionPreference = "Stop" |
| 68 | +$repoRoot = Split-Path -Parent $PSScriptRoot |
| 69 | +Set-Location $repoRoot |
| 70 | + |
| 71 | +$python = (Get-Command python -ErrorAction SilentlyContinue) |
| 72 | +if (-not $python) { $python = (Get-Command py -ErrorAction SilentlyContinue) } |
| 73 | +if (-not $python) { throw "Python 3 is required to run the Windows tests." } |
| 74 | +$py = $python.Source |
| 75 | + |
| 76 | +# A writable Windows temp dir that GNU make forwards to the native gcc. MSYS2 |
| 77 | +# strips TMP/TEMP from the environment it hands native children, so pass them as |
| 78 | +# make command-line variables (make exports those to recipe processes). |
| 79 | +$tmp = $env:TEMP |
| 80 | +if (-not $tmp) { $tmp = "$env:USERPROFILE\AppData\Local\Temp" } |
| 81 | + |
| 82 | +function Resolve-Binary { |
| 83 | + param([string]$Explicit) |
| 84 | + if ($Explicit) { return (Resolve-Path $Explicit).Path } |
| 85 | + $built = Join-Path $repoRoot "build\c\codebase-memory-mcp.exe" |
| 86 | + if (Test-Path $built) { return $built } |
| 87 | + Write-Host "Building $Target via Makefile.cbm ..." -ForegroundColor Cyan |
| 88 | + & $Make "-j" "-f" "Makefile.cbm" $Target "SANITIZE=" "TMP=$tmp" "TEMP=$tmp" "TMPDIR=$tmp" |
| 89 | + if ($LASTEXITCODE -ne 0) { throw "build failed (exit $LASTEXITCODE)" } |
| 90 | + if (-not (Test-Path $built)) { throw "binary not produced at $built" } |
| 91 | + return $built |
| 92 | +} |
| 93 | + |
| 94 | +$bin = Resolve-Binary -Explicit $Binary |
| 95 | +Write-Host "Binary: $bin" -ForegroundColor Green |
| 96 | + |
| 97 | +$env:PYTHONUTF8 = "1" # encode argv/stdio as UTF-8 |
| 98 | +$env:CBM_INDEX_SUPERVISOR = "0" # in-process indexing (see .DESCRIPTION) |
| 99 | + |
| 100 | +# Green regression guards - must stay GREEN (exit 0). RED (exit 1) = the fix for |
| 101 | +# the referenced issue regressed. The drive-picker guard needs the embedded HTTP |
| 102 | +# UI (build target cbm-with-ui); against a non-UI binary it reports a precondition |
| 103 | +# (exit 2) and is skipped rather than failed. |
| 104 | +$guards = @( |
| 105 | + "tests\windows\test_non_ascii_path.py", |
| 106 | + "tests\windows\test_hook_augment.py", |
| 107 | + "tests\windows\test_ui_drive_listing.py" |
| 108 | +) |
| 109 | + |
| 110 | +# Opt-in known-red repros - EXPECTED red (exit 1); never gate CI. |
| 111 | +$knownReds = @( |
| 112 | + "tests\windows\test_cli_non_ascii_arg.py" |
| 113 | +) |
| 114 | + |
| 115 | +$guardFailures = @() |
| 116 | +$guardSkips = @() |
| 117 | +$fixedKeepers = @() |
| 118 | + |
| 119 | +Write-Host "`n--- Green guards ---" -ForegroundColor Cyan |
| 120 | +foreach ($t in $guards) { |
| 121 | + Write-Host "`n=== $t ===" -ForegroundColor Cyan |
| 122 | + & $py $t $bin |
| 123 | + $code = $LASTEXITCODE |
| 124 | + if ($code -eq 0) { |
| 125 | + Write-Host "GREEN ($t)" -ForegroundColor Green |
| 126 | + } elseif ($code -eq 1) { |
| 127 | + Write-Host "RED ($t) - REGRESSION: a fixed Windows bug is broken again" -ForegroundColor Red |
| 128 | + $guardFailures += $t |
| 129 | + } else { |
| 130 | + Write-Host "PRECONDITION ($t) exit=$code - skipped (see message above)" -ForegroundColor Yellow |
| 131 | + $guardSkips += $t |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +if (-not $GuardsOnly) { |
| 136 | + Write-Host "`n--- Known reds (opt-in, expected red) ---" -ForegroundColor Cyan |
| 137 | + foreach ($t in $knownReds) { |
| 138 | + Write-Host "`n=== $t ===" -ForegroundColor Cyan |
| 139 | + & $py $t $bin |
| 140 | + $code = $LASTEXITCODE |
| 141 | + if ($code -eq 1) { |
| 142 | + Write-Host "RED ($t) - expected; the underlying Windows bug is still open" -ForegroundColor DarkYellow |
| 143 | + } elseif ($code -eq 0) { |
| 144 | + Write-Host "GREEN ($t) - the bug appears FIXED; promote this to a guard" -ForegroundColor Green |
| 145 | + $fixedKeepers += $t |
| 146 | + } else { |
| 147 | + Write-Host "PRECONDITION ($t) exit=$code - skipped (see message above)" -ForegroundColor Yellow |
| 148 | + } |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +Write-Host "" |
| 153 | +if ($guardSkips.Count -gt 0) { |
| 154 | + Write-Host ("Guards skipped (precondition): {0} - e.g. the drive-picker guard " -f $guardSkips.Count) -ForegroundColor Yellow |
| 155 | + Write-Host "needs a UI build (-Target cbm-with-ui, the default)." -ForegroundColor Yellow |
| 156 | +} |
| 157 | +if ($fixedKeepers.Count -gt 0) { |
| 158 | + Write-Host ("Known-red repros that are now GREEN (promote to guards): {0}" -f ($fixedKeepers -join ", ")) -ForegroundColor Green |
| 159 | +} |
| 160 | +if ($guardFailures.Count -gt 0) { |
| 161 | + Write-Host ("REGRESSION: {0} green guard(s) went red: {1}" -f $guardFailures.Count, ($guardFailures -join ", ")) -ForegroundColor Red |
| 162 | + Write-Host "A previously-fixed Windows bug is broken again. See tests/windows/RED_TEST_ANALYSIS.md." -ForegroundColor Red |
| 163 | + exit 1 |
| 164 | +} |
| 165 | +Write-Host "All Windows green guards passed." -ForegroundColor Green |
| 166 | +exit 0 |
0 commit comments