Files
ykxmz/_build/test_public_clean.py
xmz7891 4cc368431c 新增 docs/优化实测数据.md:本轮所有优化的实测数字汇总
每一项都写清楚「改之前是多少、改之后是多少、怎么测的、受什么限制」,
以后有人问「这个改动到底有没有用」能直接翻数字,不用靠感觉。

内容包括:
  * 测量方法上的两个坑(从哪台机器测差很多、curl -I 验证 GET 是错的)
  * 下载吞吐 41 倍(含改之前/之后对照)
  * 隧道稳定性:配比对照表、QUIC 72% 拨号率的真因、
    MTU 1400 的效果、长时可用率
  * 长轮询 30 次数据(中位 61439ms)
  * 端到端延迟:局域网 0ms vs 本地中转 15ms
  * 局域网优化的四个真问题
  * 「按一下没反应」的完整证据链和根因
  * 独立验证发现的 9 个问题
  * 测试工具自己骗人的两次
  * 服务端部署脚本的三套测试
  * **没做到的部分**(98.5% 可用率的物理限制,如实记录)

这份是内部工程文档,已加进对外清洁度检查的允许清单
(和 docs/项目规矩.md、docs/双平台发布.md 同类)。
2026-10-07 19:02:57 +08:00

178 lines
6.1 KiB
Python

# -*- coding: utf-8 -*-
r'''守卫:对外公开的材料里不许出现「中转管理后台」。
用户定的规矩(原话):
「你对外公开的数据里不要包含那个中转站管理的页面,你就只能提官网」
范围(用户已确认):
✅ 必须干净:发布说明、CHANGELOG、官网页面、README、我对外的汇报
❌ 不用管:服务端 zip 里的运维文档(给装机的人看)、
源码实现(路径是功能本身)、_build/_tests 内部材料
为什么写成测试而不是写进文档:
文档没人看。这一天里我因为"以为记住了"翻了三次车,
所以把规矩变成会红的断言 —— 违反了立刻报错。
顺便也守住另外两条用户明确说过的:
* 官网里不能出现管理入口
* 发布说明只能是更新内容
'''
from __future__ import annotations
import re
import sys
from pathlib import Path
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
# 这些词一律不许出现在对外材料里
FORBIDDEN = [
"zhongzhuanzhan",
"/admin",
"管理后台",
"管理页",
"管理入口",
"管理面板",
"admin_password",
]
# 对外公开的文件(相对路径)
PUBLIC_FILES = [
"_build/CHANGELOG.md",
"README.md",
]
# 对外公开的目录:里面所有 .md 都要干净
PUBLIC_DIRS = [
"docs",
]
# docs 里这些是**运维文档**,是给装服务器的人看的,允许提到管理页
DOCS_ALLOWLIST = {
"AFTER-INSTALL.txt",
"BEFORE-INSTALL.txt",
"LICENSE.txt",
"项目规矩.md", # 这份文件本身就是在讲这条规矩
"免费托管方案.md", # 讲托管方案,不涉及
# 开发流程文档:里面要写"发布脚本会检查更新说明里有没有管理页字眼",
# 属于描述规则本身,不是对外宣传材料。
"双平台发布.md",
"EzHub-SSH诊断报告.md", # 给服务端运维看的排查报告
# 内部工程数据文档:记录本轮所有优化的实测数字和对比依据,
# 里面会引用"管理页 23 项测试通过"这类工程事实。
# 它不是发给用户的材料,是给自己和后人查数字用的。
"优化实测数据.md",
}
# 官网源码里这些词也不许有(landing.py 渲染出来的页面)
SITE_FILES = [
"relay/landing.py",
"relay/showcase.py",
]
passed = 0
failed = 0
def check(name: str, ok: bool, detail: str = "") -> None:
global passed, failed
if ok:
passed += 1
print(" [PASS] " + name)
else:
failed += 1
print(" [FAIL] " + name + " " + str(detail))
def scan(path: Path) -> list:
"""返回 [(行号, 关键词, 那一行)]"""
hits = []
try:
text = path.read_text(encoding="utf-8", errors="replace")
except OSError:
return hits
for index, line in enumerate(text.splitlines(), 1):
for word in FORBIDDEN:
if word in line:
hits.append((index, word, line.strip()[:70]))
return hits
def main() -> int:
print(" 一、对外公开的单文件")
for rel in PUBLIC_FILES:
path = ROOT / rel
if not path.is_file():
check("%s 存在" % rel, False, "文件不存在")
continue
hits = scan(path)
check("%s 干净" % rel, not hits,
"第 %d 行含「%s」" % (hits[0][0], hits[0][1]) if hits else "")
print()
print(" 二、docs 目录(运维文档除外)")
for rel in PUBLIC_DIRS:
directory = ROOT / rel
if not directory.is_dir():
continue
for path in sorted(directory.iterdir()):
if not path.is_file():
continue
if path.name in DOCS_ALLOWLIST:
print(" [跳过] %s(运维文档,允许提及)" % path.name)
continue
hits = scan(path)
check("docs/%s 干净" % path.name, not hits,
"第 %d 行含「%s」" % (hits[0][0], hits[0][1]) if hits else "")
print()
print(" 三、官网页面(渲染出来给所有人看的)")
sys.path.insert(0, str(ROOT / "relay"))
try:
import landing
html = landing.render_site([
{"name": "ykxmz-setup-1.8.0.exe", "size": 15066550},
{"name": "ykxmz-server-1.8.0.zip", "size": 214661},
{"name": "ykxmz-watch-1.8.0.apk", "size": 201523},
])
except Exception as exc: # noqa: BLE001
check("官网能渲染", False, exc)
html = ""
if html:
check("官网能渲染", len(html) > 5000, "%d 字符" % len(html))
for word in FORBIDDEN:
check("官网里没有「%s」" % word, word not in html.lower()
if word.isascii() else word not in html)
# 只允许链接到下载 / 截图 / 首页 / 图标 / 页内锚点。
# 出现别的站内路径就说明可能把管理入口又加回去了。
allowed = ("/download/", "/shot/", "/", "/favicon.ico", "#")
hrefs = set(re.findall(r'href="([^"]+)"', html))
bad = [h for h in hrefs
if h.startswith("/") and not h.startswith(allowed)]
check("官网里的站内链接只指向下载/首页/锚点", not bad, bad)
print()
print(" 四、发布说明只能是「更新内容」")
rel_notes = ROOT / "_build" / "RELEASE-1.8.0.md"
if rel_notes.is_file():
text = rel_notes.read_text(encoding="utf-8")
# 不该出现安装教程这种内容(用户要求"只放更新内容")
for bad_title in ("安装教程", "安装步骤", "怎么安装"):
check("发布说明里没有「%s」" % bad_title, bad_title not in text)
# 也不该提管理页
hits = scan(rel_notes)
check("RELEASE-1.8.0.md 干净", not hits,
"第 %d 行含「%s」" % (hits[0][0], hits[0][1]) if hits else "")
else:
print(" [跳过] 没有 RELEASE-1.8.0.md")
print()
print("=" * 54)
print(" 通过 %d 项,失败 %d 项" % (passed, failed))
return 0 if failed == 0 else 1
if __name__ == "__main__":
sys.exit(main())