102 lines
3.5 KiB
Python
102 lines
3.5 KiB
Python
"""Collect completed narrow browser evidence, exact GET and independent request/port checks."""
|
|
|
|
import collections
|
|
import hashlib
|
|
import json
|
|
import re
|
|
import shutil
|
|
import socket
|
|
from pathlib import Path
|
|
from urllib.parse import urlsplit
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
OUT = Path(__file__).resolve().parent
|
|
BROWSER = ROOT / ".local-evidence/animate-time/browser"
|
|
|
|
|
|
def main():
|
|
fresh = json.loads((BROWSER / "fresh-path-check.json").read_bytes())
|
|
assert fresh["existed_before_start"] is False
|
|
stopped = json.loads((BROWSER / "service-stop.json").read_bytes())
|
|
assert stopped["ports_released"] == [8247, 5173]
|
|
server = (BROWSER / "service-0.log").read_text()
|
|
assert "'imported': 155" in server
|
|
data = json.loads((BROWSER / "browser-results.json").read_bytes())
|
|
assert not data["errors"] and data["viewports"] == [1440, 390]
|
|
actual = json.loads((BROWSER / "actual-get.json").read_bytes())["doc_json"]
|
|
expected = json.loads(next(OUT.glob("actual-Wan*.json")).read_bytes())
|
|
assert actual == expected
|
|
backend = collections.Counter(
|
|
urlsplit(p).path for p in re.findall('"GET ([^ ]+) HTTP/1.1"', server)
|
|
)
|
|
fixed = data["request_accounting"]["fixed_paths"]
|
|
polling = data["request_accounting"]["polling_paths"]
|
|
expected_fixed = collections.Counter(fixed)
|
|
expected_fixed["/api/workflows"] += 1
|
|
assert {
|
|
p: n for p, n in backend.items() if p not in ["/api/jobs", "/api/events"]
|
|
} == expected_fixed
|
|
poll_delta = {p: backend[p] - polling.get(p, 0) for p in ["/api/jobs", "/api/events"]}
|
|
assert poll_delta["/api/events"] == 0 and poll_delta["/api/jobs"] in [0, 1]
|
|
ports = []
|
|
for port in [8247, 5173]:
|
|
with socket.socket() as s:
|
|
s.settimeout(1)
|
|
result = s.connect_ex(("127.0.0.1", port))
|
|
assert result != 0
|
|
with socket.socket() as s:
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
s.bind(("127.0.0.1", port))
|
|
ports.append(dict(port=port, connect_ex=result, independently_bindable=True))
|
|
counts = dict(
|
|
browser_fixed=fixed,
|
|
backend=dict(backend),
|
|
readiness_gets=1,
|
|
fixture_interceptions=0,
|
|
polling_snapshot_delta=poll_delta,
|
|
browser_fixed_count=sum(fixed.values()),
|
|
backend_fixed_count=sum(expected_fixed.values()),
|
|
browser_polling_count=sum(polling.values()),
|
|
backend_polling_count=sum(backend[p] for p in ["/api/jobs", "/api/events"]),
|
|
)
|
|
for name in [
|
|
"actual-get.json",
|
|
"browser-results.json",
|
|
"fresh-path-check.json",
|
|
"service-stop.json",
|
|
"service-0.log",
|
|
"service-1.log",
|
|
]:
|
|
shutil.copyfile(BROWSER / name, OUT / name.replace(".log", ".txt"))
|
|
screenshots = [
|
|
dict(path=p.name, sha256=hashlib.sha256(p.read_bytes()).hexdigest())
|
|
for p in sorted(BROWSER.glob("*.png"))
|
|
]
|
|
(OUT / "browser-collection.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
assertions=data["assertion_count"],
|
|
counts=counts,
|
|
ports=ports,
|
|
screenshots=screenshots,
|
|
actual_get_equals_isolated_doc=True,
|
|
original_full_7884_inherited_not_rerun=True,
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print(
|
|
"PASS narrow browser",
|
|
data["assertion_count"],
|
|
"screenshots",
|
|
len(screenshots),
|
|
counts,
|
|
"ports refused/bindable",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|