-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.ps1
More file actions
446 lines (375 loc) · 15.7 KB
/
test.ps1
File metadata and controls
446 lines (375 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<#
.SYNOPSIS
Run RSS-Lance test suites with clear per-test PASS/FAIL output.
.DESCRIPTION
Runs Python fetcher tests (pytest), Go API + DB tests, and
frontend tests (Jest, requires Node.js).
Output is designed to be easy to scan for humans and AI agents.
.EXAMPLE
.\test.ps1 # Run all tests
.\test.ps1 python # Python fetcher tests only
.\test.ps1 go # Go API + DB tests only
.\test.ps1 frontend # Frontend tests only (requires Node.js)
.\test.ps1 backend # Python + Go (no frontend)
.\test.ps1 database # Python DB integration tests only
.\test.ps1 api # Go API tests only
.\test.ps1 e2e # End-to-end integration test (builds server with test version)
#>
param(
[Parameter(Position = 0)]
[ValidateSet("all", "python", "go", "frontend", "backend", "database", "api", "e2e", "help")]
[string]$Suite = "all"
)
$ErrorActionPreference = "Stop"
$ProjectRoot = $PSScriptRoot
$ServerDir = Join-Path $ProjectRoot "server"
# ── Counters ───────────────────────────────────────────────────────────────────
$script:totalPassed = 0
$script:totalFailed = 0
$script:totalSkipped = 0
$script:failedTests = @()
$script:suitesRun = @()
# ── Helpers ────────────────────────────────────────────────────────────────────
function Write-Section($title) {
Write-Host ""
Write-Host ("=" * 70) -ForegroundColor Cyan
Write-Host " $title" -ForegroundColor Cyan
Write-Host ("=" * 70) -ForegroundColor Cyan
Write-Host ""
}
function Write-SubSection($title) {
Write-Host ""
Write-Host (" --- $title ---") -ForegroundColor DarkCyan
Write-Host ""
}
function Write-TestResult($name, $status, $detail) {
switch ($status) {
"PASS" {
Write-Host " [PASS] $name" -ForegroundColor Green
$script:totalPassed++
}
"FAIL" {
Write-Host " [FAIL] $name" -ForegroundColor Red
if ($detail) {
$detail -split "`n" | ForEach-Object {
$l = $_.Trim()
if ($l) { Write-Host " $l" -ForegroundColor DarkRed }
}
}
$script:totalFailed++
$script:failedTests += $name
}
"SKIP" {
Write-Host " [SKIP] $name" -ForegroundColor Yellow
$script:totalSkipped++
}
}
}
# ── Python Tests ───────────────────────────────────────────────────────────────
function Run-PythonTests {
param([string[]]$TestPaths = @("tests/python/"))
$label = if ($TestPaths.Count -eq 1 -and $TestPaths[0] -ne "tests/python/") {
"Python Tests ($($TestPaths[0]))"
} else { "Python Fetcher Tests" }
Write-Section $label
$script:suitesRun += $label
$python = Join-Path $ProjectRoot ".venv\Scripts\python.exe"
if (-not (Test-Path $python)) {
Write-Host " [SKIP] Python venv not found at .venv\" -ForegroundColor Yellow
Write-Host " Run: .\build.ps1 setup" -ForegroundColor Yellow
return
}
# Ensure pytest is available
& $python -m pytest --version 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host " Installing pytest..." -ForegroundColor Yellow
& (Join-Path $ProjectRoot ".venv\Scripts\pip.exe") install pytest -q 2>$null
}
Push-Location $ProjectRoot
# Run pytest with verbose one-line-per-test output
$rawOutput = & $python -m pytest @TestPaths -v --tb=short --no-header 2>&1 | Out-String
# Parse pytest verbose lines: "path::Class::method PASSED [ N%]"
$inFailureBlock = $false
$failLines = ""
$failTestName = ""
foreach ($line in ($rawOutput -split "`n")) {
$trimmed = $line.Trim()
if ($trimmed -match '^(.+?)\s+(PASSED|FAILED|SKIPPED|ERROR)\s*(\[.*\])?\s*$') {
# Flush any pending failure detail
if ($inFailureBlock -and $failTestName) {
Write-TestResult $failTestName "FAIL" $failLines
$inFailureBlock = $false
$failLines = ""
}
$testName = $Matches[1]
$result = $Matches[2]
# Clean up long path for display
$testName = $testName -replace '^tests/python/', '' -replace '\.py::', ' > '
switch ($result) {
"PASSED" { Write-TestResult $testName "PASS" }
"SKIPPED" { Write-TestResult $testName "SKIP" }
"FAILED" {
$failTestName = $testName
$inFailureBlock = $true
$failLines = ""
}
"ERROR" {
Write-TestResult $testName "FAIL" "Collection/import error"
}
}
}
# Capture short traceback lines for failures
elseif ($inFailureBlock) {
if ($trimmed -match '^(FAILURES|={5,}|-{5,}|\d+ (passed|failed))') {
Write-TestResult $failTestName "FAIL" $failLines
$inFailureBlock = $false
$failLines = ""
$failTestName = ""
} elseif ($trimmed) {
$failLines += "$trimmed`n"
}
}
}
# Flush trailing
if ($inFailureBlock -and $failTestName) {
Write-TestResult $failTestName "FAIL" $failLines
}
Pop-Location
}
# ── Go Tests ───────────────────────────────────────────────────────────────────
function Run-GoTestPackage {
param([string]$Package, [string]$Label)
Write-SubSection $Label
Push-Location $ServerDir
$rawOutput = go test "./$Package/" -v -count=1 -timeout 300s 2>&1 | Out-String
# Parse go test -v output: "--- PASS: TestName (0.00s)" / "--- FAIL: TestName (0.00s)"
$failBlock = ""
$currentTest = ""
$inFail = $false
foreach ($line in ($rawOutput -split "`n")) {
$trimmed = $line.TrimEnd()
if ($trimmed -match '^\s*--- PASS:\s+(\S+)\s+\(') {
if ($inFail -and $currentTest) {
Write-TestResult "$Package/$currentTest" "FAIL" $failBlock
$inFail = $false; $failBlock = ""
}
Write-TestResult "$Package/$($Matches[1])" "PASS"
}
elseif ($trimmed -match '^\s*--- FAIL:\s+(\S+)\s+\(') {
if ($inFail -and $currentTest) {
Write-TestResult "$Package/$currentTest" "FAIL" $failBlock
}
$currentTest = $Matches[1]
$inFail = $true
$failBlock = ""
}
elseif ($trimmed -match '^\s*--- SKIP:\s+(\S+)\s+\(') {
if ($inFail -and $currentTest) {
Write-TestResult "$Package/$currentTest" "FAIL" $failBlock
$inFail = $false; $failBlock = ""
}
Write-TestResult "$Package/$($Matches[1])" "SKIP"
}
elseif ($inFail) {
if ($trimmed -match '^(FAIL|ok)\s' -or $trimmed -match '^---\s+(PASS|FAIL|SKIP):') {
Write-TestResult "$Package/$currentTest" "FAIL" $failBlock
$inFail = $false; $failBlock = ""
} else {
$failBlock += "$trimmed`n"
}
}
}
if ($inFail -and $currentTest) {
Write-TestResult "$Package/$currentTest" "FAIL" $failBlock
}
# Detect build failures
if ($rawOutput -match 'FAIL\s+.*\[build failed\]') {
Write-TestResult "$Package (build)" "FAIL" "Compilation failed"
}
Pop-Location
}
function Ensure-GoEnv {
$goExe = Get-Command go -ErrorAction SilentlyContinue
if (-not $goExe) {
if (Test-Path "C:\Program Files\Go\bin\go.exe") {
$env:PATH = "C:\Program Files\Go\bin;$env:PATH"
} else {
return $false
}
}
$gccExe = Get-Command gcc -ErrorAction SilentlyContinue
if (-not $gccExe) {
foreach ($dir in @("C:\msys64\ucrt64\bin", "C:\msys64\mingw64\bin", "C:\mingw64\bin")) {
if (Test-Path "$dir\gcc.exe") {
$env:PATH = "$dir;$env:PATH"
$gccExe = $true
break
}
}
if (-not $gccExe) { return $false }
}
$env:CGO_ENABLED = "1"
$env:CGO_CFLAGS = "-I$ServerDir\include"
$env:CGO_LDFLAGS = "-static $ServerDir\lib\windows_amd64\liblancedb_go.a -lws2_32 -luserenv -lntdll -lpthread"
return $true
}
function Cleanup-GoEnv {
Remove-Item Env:\CGO_ENABLED -ErrorAction SilentlyContinue
Remove-Item Env:\CGO_CFLAGS -ErrorAction SilentlyContinue
Remove-Item Env:\CGO_LDFLAGS -ErrorAction SilentlyContinue
}
function Run-GoTests {
param([string[]]$Packages = @("api", "db"))
Write-Section "Go Server Tests"
$script:suitesRun += "Go Server Tests"
if (-not (Ensure-GoEnv)) {
Write-Host " [SKIP] Go or GCC/MinGW not found (required for CGo)" -ForegroundColor Yellow
Write-Host " Install Go: https://go.dev/dl/" -ForegroundColor Yellow
Write-Host " Install GCC: pacman -S mingw-w64-ucrt-x86_64-gcc (MSYS2)" -ForegroundColor Yellow
return
}
foreach ($pkg in $Packages) {
Run-GoTestPackage $pkg "Go $($pkg)/ package"
}
Cleanup-GoEnv
}
# ── Frontend Tests ─────────────────────────────────────────────────────────────
function Run-FrontendTests {
Write-Section "Frontend Tests (Jest)"
$script:suitesRun += "Frontend Tests"
$npmExe = Get-Command npm -ErrorAction SilentlyContinue
if (-not $npmExe) {
Write-Host " [SKIP] Node.js/npm not found" -ForegroundColor Yellow
Write-Host " Install Node.js, then: cd frontend && npm install && npm test" -ForegroundColor Yellow
return
}
$frontendDir = Join-Path $ProjectRoot "frontend"
Push-Location $frontendDir
if (-not (Test-Path "node_modules")) {
Write-Host " Installing dependencies..." -ForegroundColor DarkGray
npm install 2>$null
}
$rawOutput = npx jest --verbose --no-color 2>&1 | Out-String
foreach ($line in ($rawOutput -split "`n")) {
$trimmed = $line.TrimEnd()
# Jest suite-level: "PASS tests/file.test.js" or "FAIL tests/file.test.js"
if ($trimmed -match '^\s*(PASS|FAIL)\s+tests/(.+)$') {
# Suite header - don't count, individual tests below
}
# Jest individual test (verbose): lines with checkmark or cross
elseif ($trimmed -match '^\s+[√✓]\s+(.+?)(\s+\(\d+\s*m?s\))?\s*$') {
Write-TestResult $Matches[1] "PASS"
}
elseif ($trimmed -match '^\s+[×✕]\s+(.+?)(\s+\(\d+\s*m?s\))?\s*$') {
Write-TestResult $Matches[1] "FAIL"
}
# Fallback: "pass" / "fail" text markers
elseif ($trimmed -match '^\s+pass\s+(.+)$') {
Write-TestResult $Matches[1] "PASS"
}
elseif ($trimmed -match '^\s+fail\s+(.+)$') {
Write-TestResult $Matches[1] "FAIL"
}
}
Pop-Location
}
# ── E2E Test ───────────────────────────────────────────────────────────────────
function Run-E2ETest {
Write-Section "E2E Integration Test (build + version verification)"
$script:suitesRun += "E2E Integration"
$python = Join-Path $ProjectRoot ".venv\Scripts\python.exe"
if (-not (Test-Path $python)) {
Write-Host " [SKIP] Python venv not found at .venv\" -ForegroundColor Yellow
Write-Host " Run: .\build.ps1 setup" -ForegroundColor Yellow
return
}
# Generate a unique test version ID
$testVersion = "test-" + -join ((48..57) + (97..102) | Get-Random -Count 12 | ForEach-Object { [char]$_ })
Write-Host " Test version: $testVersion" -ForegroundColor DarkGray
# Build server with test version
Write-Host " Building server with BUILD_VERSION=$testVersion ..." -ForegroundColor DarkGray
$env:BUILD_VERSION = $testVersion
try {
& "$ProjectRoot\build.ps1" server
if ($LASTEXITCODE -ne 0) {
Write-TestResult "Build server with test version" "FAIL" "build.ps1 server failed"
return
}
Write-TestResult "Build server with test version" "PASS"
} finally {
Remove-Item Env:\BUILD_VERSION -ErrorAction SilentlyContinue
}
# Run e2e test with version verification
Write-Host " Running e2e_test.py --build-version $testVersion ..." -ForegroundColor DarkGray
$rawOutput = & $python tests/e2e_test.py --build-version $testVersion 2>&1 | Out-String
# Parse e2e output: lines like " [PASS] name" or " [FAIL] name"
foreach ($line in ($rawOutput -split "`n")) {
$trimmed = $line.TrimEnd()
if ($trimmed -match '^\s*\[PASS\]\s+(.+)$') {
Write-TestResult $Matches[1] "PASS"
}
elseif ($trimmed -match '^\s*\[FAIL\]\s+(.+)$') {
$detail = ""
Write-TestResult $Matches[1] "FAIL" $detail
}
elseif ($trimmed -match 'WARNING:.*Server.*crash|WARNING:.*binary.*replaced') {
Write-Host " $trimmed" -ForegroundColor Red
}
}
}
# ── Main ───────────────────────────────────────────────────────────────────────
switch ($Suite) {
"help" {
Get-Help $MyInvocation.MyCommand.Path -Detailed
return
}
"python" { Run-PythonTests }
"go" { Run-GoTests }
"frontend" { Run-FrontendTests }
"backend" { Run-PythonTests; Run-GoTests }
"database" { Run-PythonTests -TestPaths @("tests/python/test_db.py") }
"api" { Run-GoTests -Packages @("api") }
"e2e" { Run-E2ETest }
"all" {
Run-PythonTests
Run-GoTests
Run-FrontendTests
}
}
# ── Summary ────────────────────────────────────────────────────────────────────
$total = $script:totalPassed + $script:totalFailed + $script:totalSkipped
Write-Host ""
Write-Host ("=" * 70) -ForegroundColor Cyan
Write-Host " TEST SUMMARY" -ForegroundColor Cyan
Write-Host ("=" * 70) -ForegroundColor Cyan
Write-Host ""
if ($script:suitesRun.Count -gt 0) {
Write-Host " Suites: $($script:suitesRun -join ', ')" -ForegroundColor DarkGray
}
Write-Host " Total: $total tests" -ForegroundColor White
if ($script:totalPassed -gt 0) {
Write-Host " Passed: $($script:totalPassed)" -ForegroundColor Green
}
if ($script:totalFailed -gt 0) {
Write-Host " Failed: $($script:totalFailed)" -ForegroundColor Red
}
if ($script:totalSkipped -gt 0) {
Write-Host " Skipped: $($script:totalSkipped)" -ForegroundColor Yellow
}
if ($script:failedTests.Count -gt 0) {
Write-Host ""
Write-Host " Failed tests:" -ForegroundColor Red
foreach ($t in $script:failedTests) {
Write-Host " - $t" -ForegroundColor Red
}
}
Write-Host ""
if ($script:totalFailed -eq 0 -and $total -gt 0) {
Write-Host " ALL TESTS PASSED" -ForegroundColor Green
} elseif ($script:totalFailed -gt 0) {
Write-Host " SOME TESTS FAILED" -ForegroundColor Red
exit 1
} else {
Write-Host " NO TESTS RUN" -ForegroundColor Yellow
}
Write-Host ""