"""SS3 RQ1-P2 loader — the freeze-DERIVED run-index paired bootstrap, on SYNTHETIC pcaps only (docs/stage-05-rq1p2-pairing-clarification.md). These pin that the loader pairs the bridge-on (no-pad) and bridge-on+padding arms **by run index** into one `confirm.PairedCircuit` per index — the only balanced pairing the R=30 interleaved design supports — and that the frozen §6 decision function `confirm.rq1_p2_padding` consumes those units unchanged. NO confirmatory record is read (prereg §2 blinding): run dirs are hand-built with synthetic pcaps and metrics.json that carry a `run_index`. """ import json import struct from cmd_chat.sor.analysis import confirm, 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(" 0. assert all(d > 0.0 for d in deltas) def test_feeds_frozen_rq1_p2_padding_decision(tmp_path): for i in range(5): _write_arm_run(tmp_path, run_index=i, padding=False) _write_arm_run(tmp_path, run_index=i, padding=True) paired = confirm_load.collect_rq1_p2_paired(tmp_path, bins=4, hops=3) test = confirm.rq1_p2_padding(paired, seed=1, n_resamples=200) assert test.name == "RQ1-P2" and test.effect == "ΔAUC" assert test.ci.point > 0.0 and test.decision == "padding-effective" def test_graceful_when_a_run_index_missing_an_arm(tmp_path): # run_index 0,1 in both arms; run_index 2 only no-pad, run_index 3 only +pad. for i in (0, 1): _write_arm_run(tmp_path, run_index=i, padding=False) _write_arm_run(tmp_path, run_index=i, padding=True) _write_arm_run(tmp_path, run_index=2, padding=False) # unpaired _write_arm_run(tmp_path, run_index=3, padding=True) # unpaired paired = confirm_load.collect_rq1_p2_paired(tmp_path, bins=4, hops=3) # Only the two indices present in BOTH arms are paired; frozen R is not # silently redefined — the unpaired runs are simply dropped from the pairing. assert len(paired) == 2