127 lines
8.6 KiB
PowerShell
127 lines
8.6 KiB
PowerShell
# fpcollect E2E test battery (Loong verify discipline: DoD matrix + regression + read-back)
|
|
# ASCII-only source (PS 5.1 reads no-BOM as ANSI; runtime Chinese output is fine)
|
|
param(
|
|
[string]$RunDir = (Join-Path $PSScriptRoot ('..\runs\fpcollect-e2e-verify-' + (Get-Date -Format 'yyyyMMdd')))
|
|
)
|
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
$Base = 'http://localhost:5090'
|
|
if (-not (Test-Path $RunDir)) { New-Item -ItemType Directory -Path $RunDir -Force | Out-Null }
|
|
$RunDir = (Resolve-Path $RunDir).Path
|
|
$results = New-Object System.Collections.ArrayList
|
|
$script:fail = 0
|
|
function Check($name, $ok, $detail) {
|
|
$script:fail += (-not $ok)
|
|
[void]$script:results.Add(([pscustomobject]@{ name = $name; pass = [bool]$ok; detail = "$detail" }))
|
|
Write-Output ("{0} {1} - {2}" -f ($(if ($ok) {'PASS'} else {'FAIL'})), $name, $detail)
|
|
}
|
|
|
|
# T1 infrastructure
|
|
$proc = Get-Process fpcollect-agent -ErrorAction SilentlyContinue
|
|
Check 'T1.1 agent-process' ($null -ne $proc) $(if ($proc) { "pid=$($proc.Id)" } else { 'not running' })
|
|
$tcp = New-Object Net.Sockets.TcpClient
|
|
$portOk = $tcp.ConnectAsync('127.0.0.1', 5090).Wait(2000); $tcp.Close()
|
|
Check 'T1.2 port-5090' $portOk $(if ($portOk) { 'listening' } else { 'closed' })
|
|
$task = Get-ScheduledTask -TaskName 'FpCollectGiteaSync' -ErrorAction SilentlyContinue
|
|
Check 'T1.3 sync-task' ($null -ne $task) $(if ($task) { $task.State } else { 'missing' })
|
|
|
|
# T2 auth
|
|
$login = Invoke-RestMethod -Uri "$Base/api/login" -Method Post -ContentType 'application/json' -Body '{"name":"admin","pwd":"admin123"}' -TimeoutSec 8
|
|
$tok = $login.token
|
|
Check 'T2.1 login-ok' $login.ok "level=$($login.level)"
|
|
$bad = Invoke-RestMethod -Uri "$Base/api/login" -Method Post -ContentType 'application/json' -Body '{"name":"admin","pwd":"wrong"}' -TimeoutSec 8
|
|
Check 'T2.2 bad-pwd-rejected' (-not $bad.ok) $bad.msg
|
|
$h = @{ Authorization = "Bearer $tok" }
|
|
|
|
# T3 device + capture lifecycle
|
|
$dev = Invoke-RestMethod -Uri "$Base/api/device" -Headers $h -TimeoutSec 8
|
|
Check 'T3.1 device-info' ($dev.running -eq $true -and $dev.version) "ver=$($dev.version) ch=$($dev.channels) fps=$($dev.fps)"
|
|
if (-not $dev.running) {
|
|
$s = Invoke-RestMethod -Uri "$Base/api/capture/start" -Method Post -ContentType 'application/json' -Headers $h -Body '{"rollMode":false}' -TimeoutSec 20
|
|
Start-Sleep 4
|
|
}
|
|
$stop = Invoke-RestMethod -Uri "$Base/api/capture/stop" -Method Post -ContentType 'application/json' -Headers $h -Body '{}' -TimeoutSec 30
|
|
Start-Sleep 1
|
|
$dev2 = Invoke-RestMethod -Uri "$Base/api/device" -Headers $h -TimeoutSec 8
|
|
Check 'T3.2 stop-works' ($dev2.running -eq $false) "state=$($dev2.state)"
|
|
$st = Invoke-RestMethod -Uri "$Base/api/capture/start" -Method Post -ContentType 'application/json' -Headers $h -Body '{"rollMode":false}' -TimeoutSec 20
|
|
Check 'T3.3 restart-capture' $st.ok $(if ($st.ok) { $st.device } else { $st.msg })
|
|
Start-Sleep 6
|
|
$snap = Invoke-RestMethod -Uri "$Base/api/capture/snapshot" -Headers $h -TimeoutSec 15
|
|
Check 'T3.4 snapshot-frame' ($snap.ok -and $snap.imageB64.Length -gt 1000) "b64len=$($snap.imageB64.Length)"
|
|
$cls = $null
|
|
try { $cls = Invoke-RestMethod -Uri "$Base/api/capture/classify" -Headers $h -TimeoutSec 60 } catch {}
|
|
Check 'T3.5 classify-no-crash' ($null -ne $cls -and $null -ne $cls.ok) "ok=$($cls.ok) $(if ($cls.ok) { $cls.pattern } else { $cls.msg })(无手指时'无法识别'为正确行为)"
|
|
|
|
# T3.6 WebSocket stream (binary frame + text telemetry)
|
|
try {
|
|
$ws = New-Object System.Net.WebSockets.ClientWebSocket
|
|
$ct = New-Object System.Threading.CancellationTokenSource
|
|
[void]$ct.CancelAfter(12000)
|
|
$ws.ConnectAsync([Uri]"ws://localhost:5090/ws", $ct.Token).Wait(6000) | Out-Null
|
|
$buf = New-Object byte[] 262144
|
|
$gotBin = $false; $gotTxt = $false; $frames = 0
|
|
while ($frames -lt 3 -and $ws.State -eq 'Open') {
|
|
$seg = New-Object ArraySegment[byte] (,$buf)
|
|
$r = $ws.ReceiveAsync($seg, $ct.Token).Result
|
|
if ($r.MessageType -eq 'Binary' -and $r.Count -gt 500) { $gotBin = $true }
|
|
if ($r.MessageType -eq 'Text') { $gotTxt = [Text.Encoding]::UTF8.GetString($buf, 0, $r.Count) -match 'fingerPresent' }
|
|
$frames++
|
|
}
|
|
[void]$ws.CloseAsync([System.Net.WebSockets.WebSocketCloseStatus]::NormalClosure, 'done', [System.Threading.CancellationToken]::None)
|
|
Check 'T3.6 ws-stream' ($gotBin -and $gotTxt) "frames=$frames binary=$gotBin telemetry=$gotTxt"
|
|
} catch { Check 'T3.6 ws-stream' $false $_.Exception.Message }
|
|
|
|
# T4 orders + report regression (baseline = sample HuangSirui)
|
|
$ordName = 'e2e-' + (Get-Date -Format 'HHmmss')
|
|
$ord = Invoke-RestMethod -Uri "$Base/api/orders" -Method Post -ContentType 'application/json' -Headers $h -Body ('{"orderNo":"' + $ordName + '","username":"' + $ordName + '","sex":"male","birth":""}')
|
|
Check 'T4.1 order-create' $ord.ok "id=$($ord.id) no=$ordName"
|
|
$list = Invoke-RestMethod -Uri "$Base/api/orders?q=$ordName" -Headers $h
|
|
Check 'T4.2 order-query' ($list.orders.Count -ge 1) "count=$($list.orders.Count)"
|
|
$prev = Invoke-RestMethod -Uri "$Base/api/orders/$($ord.id)/report/preview?r0=19&r1=10&r2=9&r3=14&r4=6&r5=19&r6=6&r7=9&r8=13&r9=9" -Headers $h
|
|
$expect = @{ L1 = 151.7; R1 = 151.7; L4 = 129.3; R4 = 120.1; R5 = 92.9; L2 = 83.6; L3 = 83.1; R3 = 83.1; L5 = 61.9; R2 = 50.1 }
|
|
$bad = @()
|
|
foreach ($r in $prev.report.regions) { if ([Math]::Abs($r.strength - $expect[$r.code]) -gt 0.05) { $bad += "$($r.code)=$($r.strength)" } }
|
|
Check 'T4.3 formula-regression' ($prev.report.trc -eq 114 -and $bad.Count -eq 0) "trc=$($prev.report.trc) drift=$($bad -join ',')"
|
|
Check 'T4.4 conclusions' ($prev.report.learningChannel -eq '听觉型' -and $prev.report.thinkingMode -eq '动机型' -and $prev.report.brainSide -eq '感性') "$($prev.report.learningChannel)/$($prev.report.thinkingMode)/$($prev.report.brainSide)"
|
|
$save = Invoke-RestMethod -Uri "$Base/api/orders/$($ord.id)/ridges" -Method Post -ContentType 'application/json' -Headers $h -Body '{"ridges":[19,10,9,14,6,19,6,9,13,9]}'
|
|
$rep = Invoke-RestMethod -Uri "$Base/api/orders/$($ord.id)/report" -Headers $h
|
|
Check 'T4.5 report-persist' ($save.ok -and $rep.report.trc -eq 114 -and $rep.report.advice.L1.Count -gt 0) "adviceL1=$($rep.report.advice.L1.Count) trcAdvice=$($rep.report.trcAdvice.Length)"
|
|
|
|
# T5 frontend pages
|
|
foreach ($p in @(@('/', '皮纹采集系统'), @('/capture.html', '实时采集'), @('/ridges.html', '订单'), @('/report.html?order=1', '天赋'))) {
|
|
$pg = Invoke-WebRequest -Uri "$Base$($p[0])" -UseBasicParsing -TimeoutSec 8
|
|
$body = [Text.Encoding]::UTF8.GetString($pg.RawContentStream.ToArray())
|
|
Check "T5 page $($p[0])" ($pg.StatusCode -eq 200 -and $body.Contains($p[1])) "len=$($body.Length)"
|
|
}
|
|
|
|
# T6 crash self-heal: kill agent -> watchdog revives -> token persists -> autocapture recovers
|
|
$oldTok = $tok
|
|
Get-Process fpcollect-agent -ErrorAction SilentlyContinue | Stop-Process -Force
|
|
$revived = $false
|
|
foreach ($i in 1..15) { Start-Sleep 2; if (Get-Process fpcollect-agent -ErrorAction SilentlyContinue) { $revived = $true; break } }
|
|
Check 'T6.1 watchdog-revive' $revived "waited=$($i*2)s"
|
|
$apiBack = $false
|
|
foreach ($i in 1..10) { Start-Sleep 1; try { $d = Invoke-RestMethod -Uri "$Base/api/device" -Headers @{Authorization="Bearer $oldTok"} -TimeoutSec 3; $apiBack = $true; break } catch {} }
|
|
Check 'T6.2 token-persists' $apiBack $(if ($apiBack) { 'old token accepted after restart' } else { '401' })
|
|
$capBack = $false
|
|
foreach ($i in 1..15) { Start-Sleep 2; try { $d = Invoke-RestMethod -Uri "$Base/api/device" -Headers @{Authorization="Bearer $oldTok"} -TimeoutSec 3; if ($d.running) { $capBack = $true; break } } catch {} }
|
|
Check 'T6.3 autocapture-recovers' $capBack $(if ($capBack) { "fps=$($d.fps)" } else { 'still idle' })
|
|
|
|
# T7 Gitea read-back (verify-external-writes)
|
|
try {
|
|
$gh = @{ Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes('kenyang:AIBay666')) }
|
|
$rc = Invoke-RestMethod -Uri 'http://39.108.95.179:3000/api/v1/repos/kenyang/fpcollect/commits?limit=1' -Headers $gh -TimeoutSec 10
|
|
$remoteHead = $rc[0].sha
|
|
Check 'T7 gitea-readback' ($remoteHead.Length -ge 7) "remote HEAD=$($remoteHead.Substring(0,7))"
|
|
} catch { Check 'T7 gitea-readback' $false $_.Exception.Message }
|
|
|
|
# summary + artifacts
|
|
$summary = [pscustomobject]@{
|
|
total = $results.Count; passed = @($results | Where-Object pass).Count; failed = @($results | Where-Object { -not $_.pass }).Count
|
|
finished_at = (Get-Date -Format 'yyyy-MM-ddTHH:mm:sszzz')
|
|
}
|
|
$results | ConvertTo-Json -Depth 4 | Out-File (Join-Path $RunDir 'verify-results.json') -Encoding utf8
|
|
$summary | ConvertTo-Json | Out-File (Join-Path $RunDir 'verify-summary.json') -Encoding utf8
|
|
Write-Output ("==== E2E SUMMARY: {0}/{1} passed, {2} failed ====" -f $summary.passed, $summary.total, $summary.failed)
|
|
exit $summary.failed
|