# -*- coding: utf-8 -*- """把重连放到重启之后。 正确的顺序应该是: 爆破测试 → 重启被控端 → **重新建立连接** → 合法配对 → 其余测试 之前重连建在爆破之前,重启后那个 socket 已经死了。 """ from __future__ import annotations import sys from pathlib import Path E2E = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\_tests" r"\test_e2e_features.py") def main() -> int: text = E2E.read_text(encoding="utf-8") # 1. 去掉放在爆破之前的那次重连 wrong = ''' print() print("一、配对(重启之后重新连)") time.sleep(0.5) client = Client("127.0.0.1", PORT) ''' if wrong in text: text = text.replace(wrong, ' print()\n print("一、配对")\n', 1) print(" 已移除放错位置的重连") # 2. 在重启确认之后建立新连接 anchor = ' check("重启后被控端重新在监听", restarted)\n time.sleep(1.0)\n' if anchor not in text: print(" [失败] 找不到重启确认那一行") return 1 replacement = (anchor + '\n' ' # 重启之后必须重新建连接(旧的 socket 已经断了)\n' ' client = Client("127.0.0.1", PORT)\n') text = text.replace(anchor, replacement, 1) print(" 重连已挪到重启之后") E2E.write_text(text, encoding="utf-8") import ast try: ast.parse(E2E.read_text(encoding="utf-8")) print(" 语法 OK") except SyntaxError as exc: print(f" 语法错误: {exc}") return 1 # 打印顺序确认 print() lines = E2E.read_text(encoding="utf-8").splitlines() for i, line in enumerate(lines): s = line.strip() if 'print("' in s and ("、" in s or "重启" in s): print(f" {i+1}: {s[:70]}") if "Client(\"127.0.0.1\", PORT)" in s and "breaker" not in s and "probe" not in s: print(f" {i+1}: >>> {s.strip()}") return 0 if __name__ == "__main__": sys.exit(main())