"""SS3 RQ1 loader — pcap→pairs plumbing, on SYNTHETIC pcaps only. These pin that the loader reconstructs the RQ1 (entry,exit) pair set from real per-hop pcap bytes and classifies runs by their persisted metrics.json — WITHOUT touching any confirmatory data (prereg §2 blinding). Detector accuracy itself is covered by test_sor_analysis/test_sor_confirm; here we only prove the wiring. """ import json import struct from cmd_chat.sor.analysis import confirm_load def _write_series_pcap(path, series): """Minimal LINKTYPE_RAW pcap placing one packet of size series[k] at t=k, so bin_pcap_bytes(path, bins=len(series)) reproduces `series` bin-for-bin.""" path.parent.mkdir(parents=True, exist_ok=True) with open(path, "wb") as f: f.write(struct.pack(" max(unlinked) def test_collect_rq1_p1_selects_only_bridge_on_nopad(tmp_path): # bridge=on (leak arm) — should be collected. on = tmp_path / "cell-on-r0" _write_metrics(on, "RQ1/topo=1house/selector=static/bridge=on", "RQ1", False) _write_circuit(on, "c0", [100, 10, 100, 10], [100, 10, 100, 10]) # bridge=on+padding — excluded (padding arm). pad = tmp_path / "cell-pad-r0" _write_metrics(pad, "RQ1/topo=1house/selector=static/bridge=on+padding", "RQ1", True) _write_circuit(pad, "c0", [50, 50, 50, 50], [50, 50, 50, 50]) # RQ2 cell — excluded (wrong RQ). rq2 = tmp_path / "cell-rq2-r0" _write_metrics(rq2, "RQ2/topo=directory-federated/selector=static/bridge=off", "RQ2", False) _write_circuit(rq2, "c0", [1, 2, 3, 4], [1, 2, 3, 4]) pairs = confirm_load.collect_rq1_p1_pairs(tmp_path, bins=4, hops=3) assert len(pairs) == 1 # only the 1-circuit bridge=on run assert pairs[0][1] is True # its single diagonal pair