E2E smoke hardening + Android lock/capture fixes #8

Merged
yuanyuanxiang merged 2 commits from review/e2e-android-fixes into main 2026-11-22 21:11:43 +00:00
Showing only changes of commit be19744898 - Show all commits
+47 -14
View File
@@ -61,6 +61,9 @@ public static class E2E
[DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr h);
[DllImport("user32.dll")] public static extern bool IsWindow(IntPtr h);
[DllImport("user32.dll")] static extern IntPtr SendMessage(IntPtr h, uint m, IntPtr w, IntPtr l);
// 带超时的 SendMessage:目标 UI 线程卡死时不能把测试脚本一起挂死(这正是要抓的回归)。
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern IntPtr SendMessageTimeout(IntPtr h, uint m, IntPtr w, IntPtr l, uint flags, uint timeout, out IntPtr result);
[DllImport("user32.dll")] public static extern bool PostMessage(IntPtr h, uint m, IntPtr w, IntPtr l);
[DllImport("user32.dll")] static extern int GetDlgCtrlID(IntPtr h);
[DllImport("user32.dll")] static extern IntPtr GetMenu(IntPtr h);
@@ -146,9 +149,14 @@ public static class E2E
return found;
}
/// <summary>跨进程发整型消息;目标 UI 线程 2 秒无响应时返回 -1(调用方据此判失败)。</summary>
public static int SendInt(IntPtr h, uint msg, int w, int l)
{
return (int)SendMessage(h, msg, (IntPtr)w, (IntPtr)l);
const uint SMTO_ABORTIFHUNG = 0x0002;
IntPtr result;
IntPtr ok = SendMessageTimeout(h, msg, (IntPtr)w, (IntPtr)l, SMTO_ABORTIFHUNG, 2000, out result);
if (ok == IntPtr.Zero) return -1; // 超时/目标线程不响应
return (int)result;
}
public static void PostCommand(IntPtr main, int id)
@@ -204,6 +212,15 @@ if ($running.Count -gt 0) {
}
if (-not (Test-Path $ServerExe)) { throw "找不到 Debug 服务端: $ServerExe(可加 -Build 先编译)" }
if ($ExternalClient -and -not (Test-Path $ClientExe)) { throw "找不到 Debug 客户端: $ClientExe" }
if ($Build) {
Write-Host "==> 编译 Debug 服务端/客户端 ..." -ForegroundColor Cyan
# 每次编译后单独检查退出码:只在第二次编译后查会让"服务端编译失败、客户端成功"
# 被 $LASTEXITCODE=0 掩盖,后面用旧二进制跑出一堆假 PASS/FAIL。
& powershell -NoProfile -File (Join-Path $repo 'build.ps1') -Config Debug -Platform x64 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "Debug 服务端编译失败(退出码 $LASTEXITCODE)" }
& powershell -NoProfile -File (Join-Path $repo 'build.ps1') -Config Debug -Platform x64 -ClientOnly | Out-Null
if ($LASTEXITCODE -ne 0) { throw "Debug 客户端编译失败(退出码 $LASTEXITCODE)" }
}
# 端口检查:6543 是客户端必须能连上的端口,被占用就直接失败。
# MCP/Web 端口(settings.ini 的 McpPort/WebSvrPort)如果已被别的实例占用(例如正在跑的
@@ -230,6 +247,7 @@ try { $udp = @(Get-NetUDPEndpoint -ErrorAction Stop | Select-Object -ExpandPrope
if (($ports -contains 6543) -or ($udp -contains 6543)) {
throw "端口 6543 已被占用,无法启动隔离的 Debug 测试实例。"
}
try {
if ($settingsBackup -ne $null) {
$cfg = $settingsBackup
if (($ports -contains 6545) -or ($udp -contains 6545)) {
@@ -244,13 +262,8 @@ if ($settingsBackup -ne $null) {
[System.IO.File]::WriteAllText($settingsPath, $cfg, [System.Text.Encoding]::Default)
}
}
} catch { Restore-Settings; throw }
if ($Build) {
Write-Host "==> 编译 Debug 服务端/客户端 ..." -ForegroundColor Cyan
& powershell -NoProfile -File (Join-Path $repo 'build.ps1') -Config Debug -Platform x64 | Out-Null
& powershell -NoProfile -File (Join-Path $repo 'build.ps1') -Config Debug -Platform x64 -ClientOnly | Out-Null
if ($LASTEXITCODE -ne 0) { throw "编译失败(退出码 $LASTEXITCODE)" }
}
$server = $null
$client = $null
@@ -298,12 +311,30 @@ try {
}
$count = 0
$ok = Wait-Until {
if ($script:server.HasExited) { throw '服务端进程已退出(客户端崩溃或被安全软件拦截)' }
if ($ExternalClient -and $script:client.HasExited) { throw '外部客户端进程已退出' }
$script:count = [E2E]::SendInt($script:list, $LVM_GETITEMCOUNT, 0, 0)
return ($script:count -ge 1)
} $ClientOnlineTimeoutSec
# 这里不用 Wait-Until:它无法提前退出(进程死了还要空等满超时),也无法区分
# "单次 UI 忙" 与 "持续无响应"。手写循环:
# · 进程一退出立刻失败;
# · $uiHung 只在最近一次请求超时时为真,下一次成功即清零(粘性标志会把启动
# 瞬间的忙误报成界面死锁)。
$dead = $null
$uiHung = $false
$ok = $false
$deadline = (Get-Date).AddSeconds($ClientOnlineTimeoutSec)
while ((Get-Date) -lt $deadline) {
if ($server.HasExited) { $dead = '服务端进程已退出(客户端崩溃或被安全软件拦截)'; break }
if ($ExternalClient -and $client.HasExited) { $dead = '外部客户端进程已退出'; break }
$c = [E2E]::SendInt($list, $LVM_GETITEMCOUNT, 0, 0)
if ($c -lt 0) {
$uiHung = $true
} else {
$uiHung = $false
$count = $c
if ($c -ge 1) { $ok = $true; break }
}
Start-Sleep -Milliseconds 250
}
if (-not $ok -and $dead) { throw $dead }
if (-not $ok -and $uiHung) { throw '服务端 UI 线程 2 秒无响应(LVM_GETITEMCOUNT 超时),可能是界面死锁' }
if (-not $ok) {
# 内置客户端失败时通常会弹一个消息框(例如内核 DLL 未就绪),把它的文字打出来。
$diag = @([E2E]::TopDialogs($server.Id, $main) | ForEach-Object { [E2E]::Text($_) } | Where-Object { $_ })
@@ -314,7 +345,9 @@ try {
# 选中第一行;列表项需要先选中,工具栏命令才会对这台主机下发。
[E2E]::Click($list, 40, 40)
$selected = Wait-Until {
return ([E2E]::SendInt($script:list, $LVM_GETITEMSTATE, 0, $LVIS_SELECTED) -ne 0)
$st = [E2E]::SendInt($script:list, $LVM_GETITEMSTATE, 0, $LVIS_SELECTED)
if ($st -lt 0) { return $false } # SendMessage 超时
return (($st -band $LVIS_SELECTED) -ne 0)
} 5
if (-not $selected) { throw "在线列表第 1 行没有被选中(点击坐标/列表布局可能变了)" }