# -*- coding: utf-8 -*- """更新过时断言:局域网功能已经(按要求)加回来了。 背景: 早先用户要求"既然用中转站了,局域网那套删掉", 于是 test_watch_relayonly.py 里写了: 没有 Discovery 调用 / 没有「自动搜索电脑」/ 没有 DiscoveryCore 后来用户又要求"首页加一个进入局域网连接页面", 这些断言就过时了 —— 功能回来了,断言还说不能有。 现在正确的设计是: * 首页**默认**还是"输入配对码连接"(走中转) * 但多了一个「局域网连接(同一个 WiFi)」入口,进去能搜局域网 * 原来那种"自动搜索弹一堆结果在首页"的旧交互不在了 """ from __future__ import annotations import ast import sys from pathlib import Path TEST = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\_tests" r"\test_watch_relayonly.py") OLD = ''' print() print("二、局域网那套已清掉") check("没有 Discovery 调用", "Discovery." not in code) check("没有 foundBox", "foundBox" not in code) check("没有 discovering", "discovering" not in code) check("没有「手动输入地址」按钮", 'bigButton("手动输入地址"' not in code) check("没有 toggleManual", "toggleManual" not in code) check("没有 hostInput", "hostInput" not in code) check("没有 portInput", "portInput" not in code) check("没有「自动搜索电脑」", "自动搜索电脑" not in code) check("没有 DiscoveryCore 引用", "DiscoveryCore" not in code)''' NEW = ''' print() print("二、局域网入口按新设计存在(但不再是旧交互)") # 注意:早期这里断言的是"局域网那套已清掉", # 那是用户要求删除时的版本。后来用户又要求把局域网连接加回来 # (首页 -> 局域网连接页面 -> 搜索/直连),所以这些断言反过来了。 check("首页有局域网入口", 'bigButton("局域网连接(同一个 WiFi)"' in code) check("有独立的局域网页面", "private void buildLanPanel()" in code) check("页面里能广播搜索", "Discovery.search(" in code) check("用 DiscoveryCore 的结果类型", "DiscoveryCore.Found" in code) # 旧交互确实不该再有:首页直接弹搜索框、手动填 IP 那一套 check("首页没有旧的「自动搜索电脑」按钮", 'bigButton("自动搜索电脑"' not in code) check("没有旧的手动输入地址按钮", 'bigButton("手动输入地址"' not in code) check("没有 toggleManual(旧交互)", "toggleManual" not in code) check("首页没有裸的 hostInput", "hostInput" not in code)''' # 顺带:标题也要改,不然读起来矛盾 TITLE_OLD = 'print("二、局域网那套已清掉")' TITLE_NEW = 'print("二、局域网入口(新设计)")' def main() -> int: text = TEST.read_text(encoding="utf-8") if "局域网入口按新设计存在" in text: print(" 已经更新过") return 0 if OLD not in text: print(" [失败] 锚点没找到") return 1 text = text.replace(OLD, NEW, 1) TEST.write_text(text, encoding="utf-8", newline="\n") try: ast.parse(text) print(" 已更新过时的局域网断言") except SyntaxError as exc: print(f" 语法错误: 行 {exc.lineno}: {exc.msg}") return 1 return 0 if __name__ == "__main__": sys.exit(main())