109 lines
4.2 KiB
Python
109 lines
4.2 KiB
Python
"""Collect final foreground browser evidence and verify typed document equality."""
|
|
|
|
import hashlib
|
|
import json
|
|
import re
|
|
import shutil
|
|
import socket
|
|
from collections import Counter
|
|
|
|
from build_definition import OUT, PATHS, REPO, canonical
|
|
|
|
|
|
def sha(path):
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def require_same_types(left, right):
|
|
assert type(left) is type(right)
|
|
if isinstance(left, dict):
|
|
assert left.keys() == right.keys()
|
|
for key in left:
|
|
require_same_types(left[key], right[key])
|
|
elif isinstance(left, list):
|
|
assert len(left) == len(right)
|
|
for a, b in zip(left, right, strict=True):
|
|
require_same_types(a, b)
|
|
else:
|
|
assert left == right
|
|
|
|
|
|
def main():
|
|
browser = REPO / ".local-evidence/batch172-mh4r/browser"
|
|
data = REPO / ".local-evidence/batch172-mh4r/server"
|
|
result = json.loads((browser / "browser-results.json").read_bytes())
|
|
assert not result["errors"]
|
|
assert len(result["interceptions"]) == 6
|
|
actual = json.loads((browser / "actual-get.json").read_bytes())
|
|
isolated = json.loads((OUT / "actual-video_minimax_h3_r2v_4ref_API.json").read_bytes())
|
|
assert canonical(actual["doc_json"]) == canonical(isolated)
|
|
require_same_types(actual["doc_json"], isolated)
|
|
block = isolated["fixed_version"]
|
|
for field in block["fields"]:
|
|
original = json.loads((REPO / PATHS[0]).read_bytes())[field["node_id"]]["inputs"][
|
|
field["field"]
|
|
]
|
|
require_same_types(original, field["value"])
|
|
report = (OUT.parent / "MiniMaxH3四参考图生视频API固定参考中文说明.md").read_text()
|
|
report_block = json.loads(report.split("```json\n", 1)[1].rsplit("\n```", 1)[0])
|
|
assert canonical(report_block) == canonical({k: v for k, v in block.items() if k != "matched"})
|
|
backend = Counter(
|
|
re.findall(r'"GET ([^ ]+) HTTP/1.1"', (browser / "service-0.log").read_text())
|
|
)
|
|
fixed = Counter(result["request_accounting"]["fixed_paths"])
|
|
polls = Counter(result["request_accounting"]["polling_paths"])
|
|
expected = fixed + polls
|
|
expected["/api/workflows"] += 1 # Wrapper readiness before browser.
|
|
intercepted = Counter(
|
|
__import__("urllib.parse", fromlist=["urlsplit"]).urlsplit(r["url"]).path
|
|
for r in result["interceptions"]
|
|
)
|
|
expected.subtract(intercepted)
|
|
delta = backend - expected
|
|
assert not (expected - backend)
|
|
assert set(delta) <= {"/api/jobs"} and delta.get("/api/jobs", 0) <= 1
|
|
stop = json.loads((browser / "service-stop.json").read_bytes())
|
|
assert stop["ports_released"] == stop["independent_connection_refused"] == [8247, 5173]
|
|
for port in (8247, 5173):
|
|
with socket.socket() as sock:
|
|
sock.settimeout(1)
|
|
assert sock.connect_ex(("127.0.0.1", port)) != 0
|
|
with socket.socket() as sock:
|
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
sock.bind(("127.0.0.1", port))
|
|
pngs = [
|
|
dict(file=p.name, bytes=p.stat().st_size, sha256=sha(p))
|
|
for p in sorted(browser.glob("*.png"))
|
|
]
|
|
assert len(pngs) == 54
|
|
for p in browser.iterdir():
|
|
if p.is_file() and p.suffix != ".png":
|
|
shutil.copyfile(p, OUT / p.name)
|
|
shutil.copyfile(REPO / PATHS[0], OUT / "original-video_minimax_h3_r2v_4ref_API.json")
|
|
validation = dict(
|
|
assertions=result["assertion_count"],
|
|
groups=result["assertionGroups"],
|
|
final_screenshots=pngs,
|
|
actual_get_equals_isolated_json=True,
|
|
canonical_sha256=hashlib.sha256(canonical(isolated)).hexdigest(),
|
|
float_dom="解析值/类型,不称HTTP原字节或float DOM原字节",
|
|
report_reversible=True,
|
|
forbidden_requests=0,
|
|
http_fixtures=6,
|
|
readiness_get=1,
|
|
backend_paths=dict(backend),
|
|
browser_accounting=result["request_accounting"],
|
|
intercepted_paths=dict(intercepted),
|
|
polling_delta=dict(delta),
|
|
ports_refused_bindable=[8247, 5173],
|
|
fresh_db_path=str(data.relative_to(REPO)),
|
|
)
|
|
(OUT / "validation-results.json").write_text(
|
|
json.dumps(validation, ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
print("PASS typed GET/doc/report equality, request ledger,54PNG, released ports")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|