Files
Ananta-ps/tools/migration/audit_go.py
T

53 lines
2.5 KiB
Python
Vendored

"""List known incomplete migration artifacts; --check fails until they are ported.
This is a conservative static inventory, not a claim of gameplay compatibility.
"""
import argparse
import json
from pathlib import Path
import re
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument("--check", action="store_true")
args = parser.parse_args()
root = Path(__file__).resolve().parents[2]
ids = json.loads((root / "pkg/protocol/testdata/legacy_method_ids.json").read_text(encoding="utf-8"))
deps = set(subprocess.check_output(
["go", "list", "-deps", "./cmd/ananta-server"], cwd=root).decode().splitlines())
stubs, missing_tables, unknown_calls = [], [], []
for base in ("internal", "pkg"):
for path in sorted((root / base).rglob("*.go")):
if path.name.endswith("_test.go"):
continue
text = path.read_text(encoding="utf-8-sig")
rel = path.relative_to(root).as_posix()
names = re.findall(r"// (?:Router implementation for|Catalog helper) (\w+)", text)
if names:
stubs.append({"file": rel, "count": len(names), "functions": names})
for filename in re.findall(r'filepath.Join\(configDir, "([^"]+)"\)', text):
if not (root / "data/client_data/Configs" / filename).exists():
missing_tables.append({"file": rel, "table": filename})
# Only inspect the active server, not the unused generated skeletons.
if rel.startswith("internal/gameserver/") and "/routers/" not in rel:
for name in re.findall(r'MethodGetMethodIDDefault\("([^"]+)"', text):
if name not in ids:
unknown_calls.append({"file": rel, "method": name})
report = {
"baseline": "ca2e80f",
"stub_functions": sum(row["count"] for row in stubs),
"stub_files": len(stubs),
"generated_router_connected_to_main": "ananta-ps/internal/gameserver/routers" in deps,
"catalogs_connected_to_main": "ananta-ps/internal/catalogs" in deps,
"stubs": stubs,
"missing_catalog_inputs": missing_tables,
"unverified_notification_names": unknown_calls,
}
out = root / "docs/GO_MIGRATION_INVENTORY.json"
out.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
print(f"{report['stub_functions']} stub functions in {len(stubs)} files; "
f"{len(missing_tables)} missing catalog inputs; {len(unknown_calls)} unverified notifications")
print(f"Inventory: {out.relative_to(root)}")
if args.check and (stubs or missing_tables or unknown_calls):
raise SystemExit(1)