fix(test): 测试脚本改为位置无关,去除本地绝对路径

This commit is contained in:
subtrack
2026-10-18 19:46:50 +08:00
parent f047662129
commit e0741832d3
4 changed files with 50 additions and 15 deletions
+28 -7
View File
@@ -2,10 +2,11 @@
# 用法: powershell -NoProfile -ExecutionPolicy Bypass -File scripts\acceptance.ps1 -Base http://127.0.0.1:18090 -Db <测试库路径>
param(
[string]$Base = 'http://127.0.0.1:18090',
[string]$Db = 'F:\hupeE的代肝平台\testrun\daili.db',
[string]$Python = 'E:\Miniconda3\python.exe',
[string]$Tools = 'F:\hupeE的代肝平台\scripts\dbtool.py',
[string]$LogFile = 'F:\hupeE的代肝平台\testrun\acceptance-result.txt'
[string]$Root = '',
[string]$Db = '',
[string]$Python = '',
[string]$Tools = '',
[string]$LogFile = ''
)
try { Add-Type -AssemblyName System.Net.Http -ErrorAction Stop } catch { }
@@ -13,6 +14,26 @@ try { Add-Type -AssemblyName System.Net.Http -ErrorAction Stop } catch { }
$ErrorActionPreference = 'Continue'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$env:PYTHONIOENCODING = 'utf-8'
# ---- 路径与外部程序:全部基于脚本所在目录,换机器/换目录都不用改 ----
function Find-Python {
foreach ($c in @($env:PYTHON, 'python', 'py')) {
if (-not $c) { continue }
$cmd = Get-Command $c -ErrorAction SilentlyContinue
if ($cmd) { return $cmd.Source }
}
foreach ($p in @('E:\Miniconda3\python.exe', 'C:\Python312\python.exe', 'C:\Python311\python.exe')) {
if (Test-Path $p) { return $p }
}
throw '找不到 Python 解释器,请用 -Python 指定路径'
}
if (-not $Root) { $Root = Split-Path -Parent $PSScriptRoot }
if (-not $Db) { $Db = Join-Path $Root 'testrun\daili.db' }
if (-not $Tools) { $Tools = Join-Path $Root 'scripts\dbtool.py' }
if (-not $LogFile) { $LogFile = Join-Path $Root 'testrun\acceptance-result.txt' }
if (-not $Python) { $Python = Find-Python }
$BackupDir = Join-Path $Root 'testrun\backup'
$LogDir = Join-Path $Root 'testrun\logs'
$VerifyScript = Join-Path $Root 'scripts\verify-backup.py'
$script:results = @()
$script:fail = 0
$T = (Get-Date).Date
@@ -444,7 +465,7 @@ Check 'R-06' '日志 CSV 含操作人/动作' ((Has $csv3 '操作人') -and (Has
$r = Send $admin 'POST' '/settings/backup'
Check 'R-07' '手动备份生成文件' ((Has $r.Content '已备份')) "flash=$(Flash $r.Content)"
$verify = (& $Python 'F:\hupeE的代肝平台\scripts\verify-backup.py' 'F:\hupeE的代肝平台\testrun\backup') -join ' '
$verify = (& $Python $VerifyScript $BackupDir) -join ' '
Check 'R-07b' '备份文件可被标准 SQLite 打开且有数据' (($verify -match 'OK') -and ($verify -match 'customers\s+(\d+)')) $verify
Send $admin 'POST' '/settings' @{ warn_days = '3'; screen_refresh = '30' } | Out-Null
@@ -453,7 +474,7 @@ for ($i = 0; $i -lt 3; $i++) {
Start-Sleep -Milliseconds 1200
Send $admin 'POST' '/settings/backup' | Out-Null
}
$bk = @(Get-ChildItem 'F:\hupeE的代肝平台\testrun\backup' -Filter 'daili-*.db')
$bk = @(Get-ChildItem $BackupDir -Filter 'daili-*.db')
$pruneOk = ($keepShown -ge 1) -and ($bk.Count -le $keepShown) -and (($keepShown -gt 3) -or ($bk.Count -eq $keepShown))
Check 'R-08' "备份保留份数生效(配置 $keepShown 份)" $pruneOk "count=$($bk.Count) keep=$keepShown"
@@ -537,7 +558,7 @@ Check 'CF-02' '设置页展示备份目录与保留份数' ((Has $settingsHtml '
$anon2 = New-Sess
$r = Send $anon2 'GET' '/screen'
Check 'CF-03' '大屏免登录(screen_public = true)' ($r.Status -eq 200 -and $r.Path -eq '/screen') "status=$($r.Status) path=$($r.Path)"
$logs = @(Get-ChildItem 'F:\hupeE的代肝平台\testrun\logs' -Filter '*.log' -ErrorAction SilentlyContinue)
$logs = @(Get-ChildItem $LogDir -Filter '*.log' -ErrorAction SilentlyContinue)
$logText = ''
if ($logs.Count -ge 1) { $logText = Get-Content $logs[0].FullName -Raw -Encoding UTF8 }
Check 'CF-04' '运行日志落盘' ($logs.Count -ge 1 -and $logText.Length -gt 20) "files=$($logs.Count) bytes=$($logText.Length)"