nex_squid/scripts/win-tui-clean.ps1

31 lines
1.5 KiB
PowerShell
Raw Normal View History

The instruments that measured the two lies, on the box itself `squid-platform::console` now refuses to trust a console's answer about its own size or about the price of a glyph. It is entitled to that refusal only because somebody measured both, on the machine, with scripts that could not cheat. `win-tui-resize.py` grows the console *underneath* a running interface and reads the screen back, then asks how many columns the right-hand borders sit in: one column means a screen, two means two frames drawn on top of each other. That is the resize bug made countable, and its header keeps the five facts about Windows OpenSSH that shaped it — including that the resize has to be driven on `CONOUT$`, because after the alternate screen went up, the process asking for the resize is still describing the buffer nobody is looking at. `win-tui-widths.ps1` is the same trick applied to a single character: park the cursor on a known column, write one glyph, read the cursor back, and the cells it travelled are that glyph's width *in this console*. It measures both write paths separately — `WriteConsoleW` into the buffer, and encoded bytes through stdout — because they genuinely disagree, and it reads the cell's contents back too, so a character the code page quietly replaced cannot hide inside a width that happens to look right. This is the measurement `symbol_cells` now performs in-process; the script is what proved the answer was worth asking for, and it still answers for a console the program cannot see. `win-tui-clean.ps1` keeps the harness honest: a remote PowerShell left behind by a dropped ssh session keeps the release binary's file handle open, so the next build cannot overwrite it, and it later writes its `MARK_QUIT` into whichever report file exists — a previous round testifying on behalf of this one. It kills the tested binary and its own grower by command line, and nothing else.
2026-10-15 13:21:19 +00:00
# 清掉上一轮测试留在机器上的进程。测试台在每次运行前后各调一次。
#
# powershell -NoProfile -ExecutionPolicy Bypass -File win-tui-clean.ps1
#
# 为什么需要:测试台是通过 ssh 起的,本地 Ctrl-C 或 ssh 断掉并不会让远端那条
# PowerShell 结束 —— 它会一直卡在 WaitForExit 上,而它的子进程(squid.exe)
# 则一直占着那块控制台和一个 release 版 exe 文件句柄。后果有两个:
# 编译产物覆盖不了,以及旧进程会往报告文件里补写 MARK_QUIT,
# 让下一轮读到一份不属于这一轮的事实。
#
# 只杀两类,且都按命令行匹配,不碰用户自己开的窗口:
# * squid.exe(被测程序本身);
# * 命令行里带 win-tui-grow.ps1 的 powershell.exe(测试台自己),本进程除外。
$targets = @()
$binaries = Get-Process -Name squid -ErrorAction SilentlyContinue
foreach ($process in $binaries) {
$targets += [pscustomobject]@{ Id = $process.Id; Why = "squid.exe" }
}
$growers = Get-CimInstance -ClassName Win32_Process -Filter "Name = 'powershell.exe'" |
Where-Object { $_.ProcessId -ne $PID -and $_.CommandLine -match 'win-tui-grow\.ps1' }
foreach ($process in $growers) {
$targets += [pscustomobject]@{ Id = $process.ProcessId; Why = "win-tui-grow.ps1" }
}
foreach ($target in $targets) {
Write-Output "KILLED $($target.Why) pid=$($target.Id)"
Stop-Process -Id $target.Id -Force -ErrorAction SilentlyContinue
}
if ($targets.Count -eq 0) { Write-Output "CLEAN nothing to kill" }