mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 01:00:12 +08:00
变更: - 在 Repository Hygiene 中校验已提交的路由指纹,与生成器和加载器共用算法。 验证: - 路由加载测试 5 项通过。 - 校验命令对有效索引通过,对过期、缺失和损坏的索引失败。 - 重新生成的索引没有差异,改动文件的 Ruff 检查通过。
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
"""Check the generated router index without loading the API."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
INDEX_PATH = Path(__file__).with_name("router_index.json")
|
|
|
|
|
|
def source_fingerprint() -> str:
|
|
digest = hashlib.sha256()
|
|
root = Path(__file__).with_name("routers")
|
|
for path in sorted(root.rglob("*.py")):
|
|
digest.update(str(path.relative_to(root)).encode())
|
|
digest.update(path.read_bytes())
|
|
return digest.hexdigest()
|
|
|
|
|
|
def main() -> None:
|
|
try:
|
|
recorded = json.loads(INDEX_PATH.read_text(encoding="utf-8"))["fingerprint"]
|
|
except (KeyError, OSError, TypeError, ValueError) as exc:
|
|
raise SystemExit(
|
|
f"Cannot read the router index fingerprint: {exc}. "
|
|
"Run python scripts/build_router_index.py."
|
|
) from exc
|
|
|
|
if recorded != source_fingerprint():
|
|
raise SystemExit(
|
|
"The router index fingerprint is out of date. Run python scripts/build_router_index.py."
|
|
)
|
|
|
|
print("The router index fingerprint matches the router sources.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|