Files
aigc-home/docs/hel-892/frames-document-evidence/request_counts.py
T

40 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Count actual local server GETs separately from browser intercepted requests."""
import collections
import json
import re
from pathlib import Path
OUT = Path(__file__).resolve().parent
def main():
text = (OUT / "service-0.txt").read_text()
gets = re.findall(r'"GET ([^ ]+) HTTP/', text)
polling = [p for p in gets if p in ["/api/jobs", "/api/events"]]
result = dict(
total=len(gets),
fixed_count=len(gets) - len(polling),
polling_count=len(polling),
paths=dict(collections.Counter(gets)),
readiness_included=1,
reason=(
"就绪GET单列1;浏览记录含Node直连及Playwright本地拦截的GET,"
"服务日志只含真正到后端者,不机械等同。"
"轮询可随计时边界±1,禁止请求始终零容忍。"
),
)
browser = json.loads((OUT / "browser-results.json").read_bytes())
assert browser["errors"] == []
assert all(r["method"] == "GET" for r in browser["requests"])
assert all(not p.startswith("/api/view") for p in gets)
assert abs(result["polling_count"] - browser["request_accounting"]["polling_count"]) <= 1
(OUT / "server-request-accounting.json").write_text(
json.dumps(result, ensure_ascii=False, indent=2) + "\n"
)
print(json.dumps(result, ensure_ascii=False))
if __name__ == "__main__":
main()