# -*- coding: utf-8 -*- r'''检查两个 zip 里实际发出去的说明文档写了什么。 重点确认三件事: 1. 硬编码的作者中转地址(xxmxxs / 192.168.x.x)已经彻底没了 2. 「默认不带中转地址、要跨网络得自己部署」这句话真的在文档里 3. 版本号是 1.8.2,不是旧的 ''' from __future__ import annotations import re import sys import zipfile from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") AGENT = ROOT / "dist" / "ykxmz-agent-1.8.2.zip" SERVER = ROOT / "dist" / "ykxmz-server-1.8.2.zip" WANT = { "AGENT": [ ("README-agent.txt", ["没有内置任何中转地址", "自己部署", "deploy.sh"]), ("BEFORE-INSTALL.txt", ["不带任何中转地址", "deploy.sh", "安卓 7.0"]), ("AFTER-INSTALL.txt", ["中转地址默认为空", "1.8.2"]), ], "SERVER": [ ("README-server.txt", ["deploy.sh", "两种协议同时在跑", "边缘缓存"]), ], } BANNED = [b"relay.xxmxxs.top", b"192.168.2.156", b"192.168.10.105"] # 只扫文档,不扫 .sh / .py —— install.sh 这个名字本身就是脚本文件名, # 不是"文档里让用户去跑旧脚本"的证据。 DOC_SUFFIX = (".txt", ".md") ok = True def check(name: str, good: bool, detail: str = "") -> None: global ok print(" [%s] %s%s" % ("PASS" if good else "FAIL", name, (" " + detail) if detail else "")) if not good: ok = False for label, path in (("AGENT", AGENT), ("SERVER", SERVER)): print("=" * 62) print(" %s %s" % (label, path.name)) print("=" * 62) if not path.is_file(): check("%s 存在" % path.name, False) continue with zipfile.ZipFile(path) as z: names = z.namelist() # 1. 全包扫禁用串(只扫文档) hits = [] for name in names: if not name.endswith(DOC_SUFFIX): continue blob = z.read(name) for needle in BANNED: if needle in blob: hits.append("%s 含 %s" % (name, needle.decode().strip())) check("文档里没有硬编码的作者中转地址", not hits, "; ".join(hits[:3])) check("文档里没有让用户跑旧脚本 install.sh", not any( re.search(rb"(sudo\s+)?bash\s+install\.sh", z.read(n)) for n in names if n.endswith(DOC_SUFFIX)), "(README-server 里【关于 install.sh】那节只是说明它仍留在包里," "不是让用户去跑它 —— 那种是允许的)") # 2. 关键文档里该有的话 for fname, phrases in WANT.get(label, []): match = [n for n in names if n.endswith(fname)] if not match: check("%s 在包里" % fname, False) continue text = z.read(match[0]).decode("utf-8-sig", "replace") for phrase in phrases: check("%s 里有「%s」" % (fname, phrase), phrase in text) # 3. 版本号:只看**抬头**那几行。 # 正文里的「八、版本记录」本来就该列历史版本(1.7.1 等), # 把那些也算成"过期"是误判。 for fname in ("README-agent.txt", "README-server.txt", "BEFORE-INSTALL.txt", "AFTER-INSTALL.txt"): match = [n for n in names if n.endswith(fname)] if not match: continue text = z.read(match[0]).decode("utf-8-sig", "replace") head = "\n".join(text.splitlines()[:10]) stale = re.findall(r"\b1\.[0-7]\.\d+\b", head) check("%s 抬头没有旧版本号" % fname, not stale, "发现 %s" % set(stale) if stale else "") check("%s 抬头写了 1.8.2" % fname, "1.8.2" in head) print() print("=" * 62) print(" %s" % ("全部通过" if ok else "有失败项")) sys.exit(0 if ok else 1)