Files
ykxmz/_build/close_windows_no_lockscreen.py
T
xmz7891 b705216e4a ykxmz 1.5.0锛氫慨澶嶆墜琛ㄧ TLS 璇佷功鏍¢獙 + MTU 淇缃戠粶绋冲畾鎬?
琚帶绔?- 淇 MTU 闂锛氬す MSS + 璺緞 MTU 鎺㈡祴锛堝叕缃戝彲鐢ㄧ巼 48% -> 100%锛?- 澶嶇敤 HTTP 杩炴帴锛堝厤鎺夋瘡娆℃柊寤?TLS 鐨?30% 鎻℃墜澶辫触锛?- 姣忓垎閽熷洖澶存壘灞€鍩熺綉锛岃嚜鍔ㄥ垏鍥炲揩 400 鍊嶇殑璺緞
- 鐢婚潰蹇冭烦甯э細闈欐鏃剁渷娴侀噺锛屽鎴风浠嶇煡閬撴祦鏄椿鐨?- 閿佸睆鏃剁粰鍑哄彲鎿嶄綔鐨勬彁绀?
鎵嬭〃绔?- 鍐呯疆 GTS Root R4 / GlobalSign Root CA锛屼慨 SSLHandshakeException
- 杩炴帴閿欒缈昏瘧鎴愪汉璇濓紙璇佷功/鏃堕棿/瑙f瀽/瓒呮椂鍒嗗埆鎻愮ず锛?- 缁忎腑杞繛涓婂悗鐢ㄦ湇鍔″櫒鎶ョ殑鍦板潃鍒锋柊宸查厤瀵硅褰?- 鏂板灞€鍩熺綉杩炴帴椤甸潰銆佹湇鍔″櫒寤惰繜妫€娴?
鏈嶅姟鍣ㄧ
- 鏀寔 chunked 璇锋眰浣擄紙淇瘡 16 绉掍竴娆$殑杩炴帴閿欎贡涓庡ぇ闈㈢Н 502锛?- 缃戠粶璋冧紭鑴氭湰 net-tune.sh锛堝紑鏈鸿嚜鍔ㄥ簲鐢級
- 绠$悊椤碉細鎵归噺鍒犻櫎銆佺綉缁滀綋妫€銆佷笅杞藉尯
- 闅ч亾鏀?HTTP/2 + 鍙岃繛鎺?
鏂囨。
- 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
2026-10-06 19:01:05 +08:00

168 lines
6.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""两件事(用户要求):
1. 跑全量时开的窗口,跑完要**自己关上**
测试会弹真实的 Tk 窗口(首次设置窗口、投图窗口、屏幕共享提示等)。
正常路径下测试自己会关,但一旦某个用例失败/超时,
进程挂着,窗口就留在屏幕上不走了。
做法:在 verify_all 结尾加一个收尾步骤,按进程把窗口关掉
(先 CloseMainWindow 好声好气关,再强杀兜底)。
2. 把"锁屏检查"从全量里删掉
之前我在 test_agent_protocol.py 里加了 desktop_locked(),
锁屏时打印一大段提示。用户要求以后都别做这个检查。
"""
from __future__ import annotations
import ast
import re
import sys
from pathlib import Path
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
VERIFY = ROOT / "_tests" / "verify_all.ps1"
PROTOCOL = ROOT / "_tests" / "test_agent_protocol.py"
# ===================== 1. 删掉锁屏检查 =====================
LOCK_BLOCK = '''def desktop_locked() -> bool:
"""屏幕锁了没。锁屏时 Windows 不给抓屏,相关断言必然失败 ——
那是环境,不是产品问题,要单独说清楚。"""
try:
from PIL import ImageGrab
ImageGrab.grab()
return False
except Exception:
return True
def main() -> int:
locked = desktop_locked()
if locked:
print()
print(" !检测到桌面锁了(锁屏/无桌面会话)。")
print(" 截屏和镜像相关的断言会失败,这是环境限制,不是产品问题。")
print(" 解锁屏幕后重跑即可。")
print()'''
NEW_MAIN = '''def main() -> int:'''
# ===================== 2. 收尾关窗口 =====================
CLEANUP_FUNC = '''function Close-TestWindows {
# 测试会弹真实的 Tk 窗口(首次设置、投图、屏幕共享提示…)。
# 正常路径下测试自己会关;但用例失败/超时时进程还挂着,
# 窗口就留在屏幕上不走了。这里统一收尾。
$closed = 0
Get-Process python, pythonw -ErrorAction SilentlyContinue |
Where-Object { $_.Id -ne $PID } |
ForEach-Object {
$line = (Get-CimInstance Win32_Process -Filter "ProcessId=$($_.Id)" -ErrorAction SilentlyContinue).CommandLine
if ($line -and ($line -match '_tests' -or $line -match 'run_agent' `
-or $line -match 'relay\\.py')) {
# 先好好关主窗口
try { $_.CloseMainWindow() | Out-Null } catch { }
Start-Sleep -Milliseconds 250
if (-not $_.HasExited) {
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
}
$closed++
}
}
# 被控端自己(测试起过 ykxmz.exe)
Get-Process ykxmz -ErrorAction SilentlyContinue | ForEach-Object {
try { $_.CloseMainWindow() | Out-Null } catch { }
Start-Sleep -Milliseconds 250
if (-not $_.HasExited) {
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
}
$closed++
}
# Java 测试进程
Get-Process java -ErrorAction SilentlyContinue | ForEach-Object {
$line = (Get-CimInstance Win32_Process -Filter "ProcessId=$($_.Id)" -ErrorAction SilentlyContinue).CommandLine
if ($line -and ($line -match 'JavaClientTest' -or $line -match 'JavaRelayTest')) {
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
$closed++
}
}
if ($closed -gt 0) {
Write-Host " 关了 $closed 个测试进程/窗口" -ForegroundColor DarkGray
}
Start-Sleep -Milliseconds 400
}
'''
SUMMARY_ANCHOR = """Banner "验证汇总\""""
def main() -> int:
ok = True
# ---- 1. 删锁屏检查 ----
text = PROTOCOL.read_text(encoding="utf-8")
if "desktop_locked" in text:
if LOCK_BLOCK in text:
text = text.replace(LOCK_BLOCK, NEW_MAIN, 1)
PROTOCOL.write_text(text, encoding="utf-8", newline="\n")
print(" 已删掉 test_agent_protocol.py 里的锁屏检查")
else:
# 锚点不完全一致时,用正则兜底
text = re.sub(
r"def desktop_locked\(\).*?\n\n\n(?=def main)", "", text,
count=1, flags=re.S)
text = re.sub(
r"def main\(\) -> int:\n locked = desktop_locked\(\)"
r".*?\n\n", "def main() -> int:\n", text, count=1, flags=re.S)
if "desktop_locked" in text:
print(" [警告] 锁屏检查没删干净,还有残留")
ok = False
else:
PROTOCOL.write_text(text, encoding="utf-8", newline="\n")
print(" 已删掉锁屏检查(正则兜底)")
else:
print(" 锁屏检查已经没有了")
# ---- 2. verify_all 加收尾 ----
raw = VERIFY.read_bytes()
had_bom = raw.startswith(b"\xef\xbb\xbf")
vtext = raw.decode("utf-8-sig")
if "Close-TestWindows" in vtext:
print(" verify_all 已经有 Close-TestWindows")
else:
# 函数插在 Stop-Strays 前面
anchor = "function Stop-Strays {"
if anchor in vtext:
vtext = vtext.replace(anchor, CLEANUP_FUNC + anchor, 1)
print(" 加了 Close-TestWindows 函数")
else:
print(" [失败] 找不到插入位置")
ok = False
# 在汇总之前调用
if SUMMARY_ANCHOR in vtext:
vtext = vtext.replace(
SUMMARY_ANCHOR,
'# 收尾:把测试过程中弹出来的窗口关掉(用户要求)\n'
'Close-TestWindows\n\n' + SUMMARY_ANCHOR, 1)
print(" 在汇总前调用了 Close-TestWindows")
else:
print(" [失败] 找不到汇总锚点")
ok = False
VERIFY.write_bytes((b"\xef\xbb\xbf" if had_bom else b"")
+ vtext.replace("\r\n", "\n").encode("utf-8"))
ast.parse(PROTOCOL.read_text(encoding="utf-8"))
print(" test_agent_protocol.py 语法 OK")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())