227 lines
15 KiB
Python
227 lines
15 KiB
Python
"""Create a Chinese compatibility matrix from locally recorded evidence."""
|
||
|
||
import hashlib
|
||
import json
|
||
import re
|
||
import statistics
|
||
import xml.etree.ElementTree as ET
|
||
from collections import Counter
|
||
from datetime import datetime, timedelta, timezone
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parents[1]
|
||
RESULTS = ROOT / "test-results"
|
||
CORES = {"paper": "Paper", "purpur": "Purpur", "spigot": "Spigot", "folia": "Folia", "leaves": "Leaves"}
|
||
VERSIONS = ("1.21.1", "1.21.4", "1.21.8", "1.21.11")
|
||
JAR = ROOT / "build" / "libs" / "ItxiaohuiContentGuard-0.2.0-dev.jar"
|
||
|
||
|
||
def jread(path):
|
||
return json.loads(path.read_text(encoding="utf-8"))
|
||
|
||
|
||
def evidence(directory, pattern, expected):
|
||
for path in sorted(directory.glob(pattern), reverse=True):
|
||
data = jread(path)
|
||
if data.get("jar_sha256") == expected:
|
||
return path, data
|
||
return None, None
|
||
|
||
|
||
def integration(core, version, sha):
|
||
directory = RESULTS / core / version
|
||
file = directory / "summary.md"
|
||
environment = directory / "environment.txt"
|
||
if not file.exists() or not environment.exists() or f"plugin_sha256={sha}" not in environment.read_text(encoding="utf-8"):
|
||
reason = "未测"
|
||
if core == "folia" and version == "1.21.1":
|
||
reason = "Fill v3 发行接口返回 404"
|
||
if core == "leaves" and version == "1.21.11":
|
||
reason = "上游仅提供实验版"
|
||
return (reason, False, False)
|
||
text = file.read_text(encoding="utf-8")
|
||
passed = re.search(r"通过 (\d+),失败 (\d+),跳过 (\d+)", text)
|
||
stage = "ALPHA · " if core == "folia" and version == "1.21.4" else ""
|
||
read = f'{stage}[{passed.group(1)} 通过 / {passed.group(2)} 失败 / {passed.group(3)} 跳过]({core}/{version}/summary.md)'
|
||
return (read, int(passed.group(2)) == 0, int(passed.group(2)) > 0)
|
||
|
||
|
||
def stress_cell(core, version, sha):
|
||
directory = RESULTS / core / version
|
||
path, result = evidence(directory, "stress-*/evidence.json", sha)
|
||
if not result:
|
||
return "压力未完成", False
|
||
state = result["online_and_integrity_check"]
|
||
clients = max((case["online"] for case in result["cases"]), default=0)
|
||
link = path.parent.relative_to(RESULTS).as_posix() + "/stress-report.html"
|
||
return f"[{clients} 在线 · {state}]({link})", state == "FAIL"
|
||
|
||
|
||
def report():
|
||
with JAR.open("rb") as binary:
|
||
sha = hashlib.file_digest(binary, "sha256").hexdigest()
|
||
paragraphs = [
|
||
"# 真实服务端兼容与发布验收",
|
||
"",
|
||
"报告生成时间 " + datetime.now(timezone(timedelta(hours=8))).isoformat(timespec="seconds") + "。",
|
||
"",
|
||
"候选构建为 `0.2.0-dev`,SHA-256 为 `" + sha + "`。",
|
||
"",
|
||
"运行环境为 Windows 11 x64、Intel Core i9-12900KS(24 逻辑处理器)、Microsoft OpenJDK 21.0.13.0.2。"
|
||
"测试核心使用各自的发行包或 BuildTools 生成的 Spigot JAR,各自的世界、配置、插件目录、启动命令和日志。"
|
||
"协议客户端由本机程序驱动,连接到回环地址上的真实 Minecraft 服务端。",
|
||
"",
|
||
"## 正式兼容状态",
|
||
"",
|
||
"| 核心 | 真实启动与功能 | 1.21.8 并发抽样 | 1.21.8 故障抽样 | 最终状态 |",
|
||
"|---|---|---|---|---|",
|
||
]
|
||
version_rows = []
|
||
stress_rows = []
|
||
for core, name in CORES.items():
|
||
versions = [integration(core, version, sha) for version in VERSIONS]
|
||
version_stress = [stress_cell(core, version, sha) for version in VERSIONS]
|
||
version_faults = [evidence(RESULTS / core / version, "fault-*/evidence.json", sha) for version in VERSIONS]
|
||
directory = RESULTS / core / "1.21.8"
|
||
path, sample = evidence(directory, "stress-*/evidence.json", sha)
|
||
fault_path, faults = evidence(directory, "fault-*/evidence.json", sha)
|
||
failed = (any(item[2] for item in versions) or any(item[1] for item in version_stress)
|
||
or any(data and data["online_and_integrity_check"] == "FAIL" for _, data in version_faults))
|
||
stress = "未测"
|
||
failed |= bool(sample and sample["online_and_integrity_check"] != "PASS")
|
||
failed |= bool(faults and faults["online_and_integrity_check"] != "PASS")
|
||
if sample:
|
||
case = sample["cases"][-1] if sample["cases"] else {"online": 0, "messagesSent": 0, "booksSent": 0, "durationMs": 0}
|
||
state = sample["online_and_integrity_check"]
|
||
folder = path.parent.relative_to(RESULTS).as_posix()
|
||
stress = f'[{case["online"]} 在线 · {state}]({folder}/stress-report.html)'
|
||
host = [json.loads(line) for line in path.with_name("samples.jsonl").read_text(encoding="utf-8").splitlines()]
|
||
db = sample["db_after_stop"]
|
||
minimums = []
|
||
for line in sample["telemetry"]:
|
||
gauge = re.search(r"tps=\[([\d.]+)[^\]]*\] mspt=([\d.]+)", line)
|
||
if gauge:
|
||
minimums.append(tuple(map(float, gauge.groups())))
|
||
cpu = f'{max(row["cpu_percent"] for row in host):.1f}%' if host else "缺失"
|
||
memory = f'{max(row["rss_bytes"] for row in host) / (1024 ** 2):.0f}' if host else "缺失"
|
||
tps = f'{min(tps for tps, _ in minimums):.2f}' if minimums else "不可用"
|
||
mspt = f'{max(mspt for _, mspt in minimums):.2f}' if minimums else "不可用"
|
||
stress_rows.append(f'| {name} | {case["online"]} | {case["messagesSent"]} | {case["booksSent"]} | '
|
||
f'{case["durationMs"] / 1000:.2f} s | {sample["ai_requests"]} | {db.get("integrity", "缺失")} | '
|
||
f'{cpu} | {memory} MiB | {tps} / {mspt} | {len(sample["exceptions"])} |')
|
||
failure_view = (f'[{faults["online_and_integrity_check"]}]({fault_path.parent.relative_to(RESULTS).as_posix()}/stress-report.html)'
|
||
if faults else "未测")
|
||
count = sum(item[1] for item in versions)
|
||
final = "FAILED" if failed else "UNVERIFIED"
|
||
paragraphs.append(f"| {name} | {count} / {len(VERSIONS)} 目标组合实服通过 | {stress} | {failure_view} | **{final}** |")
|
||
version_cells = []
|
||
for version, load, (fault_file, fault) in zip(versions, version_stress, version_faults):
|
||
cell = f"{version[0]}<br>{load[0]}"
|
||
if fault:
|
||
link = fault_file.with_name("stress-report.html").relative_to(RESULTS).as_posix()
|
||
cell += f'<br>[故障 {fault["online_and_integrity_check"]}]({link})'
|
||
version_cells.append(cell)
|
||
version_rows.append("| " + name + " | " + " | ".join(version_cells) + " |")
|
||
|
||
paragraphs.extend(["", "## Minecraft 小版本矩阵", "",
|
||
"| 核心 | 1.21.1 | 1.21.4 | 1.21.8 | 1.21.11 |",
|
||
"|---|---|---|---|---|", *version_rows, "",
|
||
"每个版本目录包含环境、JAR SHA-256、独立启动/重启日志、调度权属探针、客户端输出、集成 HTML、"
|
||
"异常摘要与测试时间。Folia 1.21.4 测的是上游 ALPHA 构建。"])
|
||
suites = [ET.parse(path).getroot() for path in (RESULTS / "unit" / "candidate").rglob("TEST-*.xml")]
|
||
numbers = Counter()
|
||
for suite in suites:
|
||
for name in ("tests", "failures", "errors", "skipped"):
|
||
numbers[name] += int(suite.get(name, "0"))
|
||
paragraphs.extend(["", "## 自动化单元测试", "",
|
||
f'JUnit 5 共 {numbers["tests"]} 例,失败 {numbers["failures"]},错误 {numbers["errors"]},'
|
||
f'跳过 {numbers["skipped"]}。参见 [JUnit](unit/candidate/index.html)、'
|
||
'[MockBukkit](unit/candidate/mockbukkit/index.html) 和同目录 XML。', "",
|
||
"## 1.21.8 压力抽样", "",
|
||
"| 核心 | 峰值阶段客户端 | 该阶段发送聊天 | 该阶段提交书本 | 该阶段耗时含等待 | 全程 AI 到达 | SQLite | Java 进程 CPU 峰值 | RSS 峰值 | 最低 1 分钟 TPS / 最大采样 MSPT | 检测到的关键异常 |",
|
||
"|---|---:|---:|---:|---:|---:|---|---:|---:|---:|---:|", *stress_rows, "",
|
||
"上表聊天和书本数量为真实客户端发送量。服务端触发的事件、AI 接收数、送达观察值以及服务器限流结果见原始报告。"
|
||
"CPU 百分比按单逻辑处理器计,超过 100% 表示多个逻辑处理器。"
|
||
"Folia 的 TPS/MSPT 来自全局接口。区域活动由分区事件计数证明。"
|
||
"Spigot 缺少相同的 Bukkit 指标接口。每次运行另保存 RSS、线程、GC、AI/SMTP 队列和数据库操作耗时采样。"])
|
||
paragraphs.extend(["", "## 长时间稳定性", ""])
|
||
for tag, label in (("stability-30m", "30 分钟"), ("stability-2h", "2 小时"), ("stability-8h", "8 小时")):
|
||
manifests = sorted(RESULTS.glob(f"*/*/{tag}-*/run.json"), reverse=True)
|
||
manifest = manifests[0] if manifests else None
|
||
if manifest:
|
||
config = jread(manifest)
|
||
final = manifest.with_name("evidence.json")
|
||
if final.is_file():
|
||
outcome = jread(final)
|
||
status = f'已结束 · {outcome["online_and_integrity_check"]}'
|
||
samples = [json.loads(line) for line in manifest.with_name("samples.jsonl")
|
||
.read_text(encoding="utf-8").splitlines()]
|
||
if len(samples) >= 10:
|
||
window = max(3, len(samples) // 10)
|
||
initial = statistics.median(row["rss_bytes"] for row in samples[window:window * 2])
|
||
final_rss = statistics.median(row["rss_bytes"] for row in samples[-window:])
|
||
status += f" · 热身后/尾段 RSS 中位数 {initial / 1024 ** 2:.0f}/{final_rss / 1024 ** 2:.0f} MiB"
|
||
detail = final
|
||
else:
|
||
status = "已启动,等待完成证据"
|
||
detail = manifest.with_name("samples.jsonl")
|
||
if detail.is_file():
|
||
rows = detail.read_text(encoding="utf-8").splitlines()
|
||
if rows:
|
||
try:
|
||
status += ",最近采样 " + json.loads(rows[-1])["time"]
|
||
except (KeyError, ValueError):
|
||
pass
|
||
link = detail.relative_to(RESULTS).as_posix()
|
||
paragraphs.append(f'- {label} · {config["core"]} {config["minecraft"]} · {status} · [{detail.name}]({link})')
|
||
else:
|
||
paragraphs.append(f"- {label} · 未执行")
|
||
paragraphs.extend(["", "## 专项实服证据", ""])
|
||
for title, directory in (
|
||
("Folia 跨区域、离线回调及实体失效 1.21.8", "folia/1.21.8/folia-special"),
|
||
("Folia 跨区域、离线回调及实体失效 1.21.11", "folia/1.21.11/folia-special"),
|
||
("Folia 审核进行中热重载", "folia/1.21.8/folia-reload"),
|
||
("AI 关闭时本地审核", "spigot/1.21.8/mode-off"),
|
||
("AI RECORD", "paper/1.21.8/mode-record"),
|
||
("AI AUTO", "folia/1.21.8/mode-auto"),
|
||
("AI 无效 JSON 降级", "folia/1.21.8/invalid-json"),
|
||
("SMTP 直接 TLS", "paper/1.21.8/smtp-ssl"),
|
||
("SMTP STARTTLS", "folia/1.21.8/smtp-starttls"),
|
||
("SMTP 密码错误", "spigot/1.21.8/smtp-auth-error"),
|
||
("SMTP 端口拒绝", "purpur/1.21.8/smtp-port-closed"),
|
||
("SMTP 发送阶段超时", "leaves/1.21.8/smtp-timeout"),
|
||
*((f"{name} 私聊别名与词库管理", f"{core}/1.21.8/commands") for core, name in CORES.items()),
|
||
*((f"{name} 管理员通知与书本权限", f"{core}/1.21.8/permissions") for core, name in CORES.items()),
|
||
*((f"{name} SQLite 文件损坏与隔离恢复", f"{core}/1.21.8/db-corrupt") for core, name in CORES.items()),
|
||
*((f"{name} 实服 SQLite 页限故障", f"{core}/1.21.8/db-full") for core, name in CORES.items()),
|
||
*((f"{name} 无效配置热重载", f"{core}/1.21.8/reload-invalid") for core, name in CORES.items()),
|
||
*((f"{name} 聊天与书本协议边界", f"{core}/1.21.8/boundary") for core, name in CORES.items()),
|
||
):
|
||
if (RESULTS / directory / "summary.md").is_file():
|
||
paragraphs.append(f"- [{title}]({directory}/summary.md)")
|
||
for prefix, title in (("rich-books", "50 页书本并发"), ("smtp-queue", "SMTP 邮件队列饱和")):
|
||
for file in sorted(RESULTS.glob(f"*/*/{prefix}-*/evidence.json")):
|
||
outcome = jread(file)
|
||
if outcome.get("jar_sha256") == sha:
|
||
link = file.with_name("stress-report.html").relative_to(RESULTS).as_posix()
|
||
paragraphs.append(f'- [{outcome["core"]} {title} · {outcome["online_and_integrity_check"]}]({link})')
|
||
paragraphs.extend(["", "## 修复与复测", "",
|
||
"- Windows 控制台日志转码影响关闭标记。改用固定 ASCII 标记后复测自动关闭、重启。",
|
||
"- Spigot 新版正式构建返回包含 `-Spigot-` 的构建串。修复识别并补回归用例,四个小版本重测。",
|
||
"- Spigot 立即重启又关闭时碰到 SQLite 尚在初始化。关闭期间协调初始化,并检查重启后数据库真正就绪。",
|
||
"- Folia 协议客户端需要完成传送确认和常规移动同步,书本限速才会按真实客户端方式推进。三个 Folia 构建补齐协议后通过书本编辑与签署。",
|
||
"- Folia 首轮 100 并发仅 98 个进入游戏,并且测试探针在加入事件中调用传送失败。提高测试服容量并在玩家实体调度器运行传送,保留前两轮完整证据。",
|
||
"- 多轮失败与修复过程见各版本 `previous/` 或独立压力运行目录。",
|
||
"", "## 发布门禁余项", "",
|
||
"- 逐核心、逐版本的专项故障完整矩阵,以及所有队列满载、长时间内存趋势仍待完整证据。",
|
||
"- 磁盘空间不足使用探针对真实 SQLite 连接设置页数上限模拟。操作系统级磁盘配额未测试。",
|
||
"- 短时书本压测记录协议提交量与实际 Bukkit 事件数。Minecraft 自身的校验、频控及已签署物品会挡住部分重复提交。",
|
||
"- 超协议长度的聊天与书本标题由服务端解码器拒绝。协议边界报告保留预期断开原因与 Bukkit 实际收到的首个书本事件。",
|
||
"- 用户私聊命令只覆盖识别到的别名。第三方直接发消息需要服务接口。多页使用逐页本地匹配。默认禁言随进程重启清空。",
|
||
"", "更多使用与配置说明参见 [README](../README.md)。", ""])
|
||
(RESULTS / "README.md").write_text("\n".join(paragraphs), encoding="utf-8")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
report()
|