clap-retrieval-benchmark / tests /test_campaign_coverage.py
b4ph's picture
CLAP audio-text retrieval: pinned-protocol measurement release (v15)
fb47aa2 verified
Raw History Blame Contribute Delete
2.86 kB
"""Checks that run_v2.sh generates every result the report consumes.
Found in external review of v10: build_report.py read `p10c5_b1` and `p10_b1`,
but the campaign never produced them, so a fresh run on an empty results
directory could not reconstruct the report. This test fails if that drifts again.
"""
from __future__ import annotations
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
FAILS: list[str] = []
# Tags the campaign cannot produce by design: the clean-room rerun runs on its own
# host with its own tag, and is reproduced by the operator step, not by run_v2.sh.
EXEMPT = {"clean"}
def check(name: str, cond: bool, detail: str = "") -> None:
print(f"{'PASS' if cond else 'FAIL'} {name:<52}{detail}")
if not cond:
FAILS.append(name)
def campaign_tags(script: str) -> set[str]:
tags = set(re.findall(r'^\s*run\s+"([a-z0-9_]+)"', script, re.M))
tags |= set(re.findall(r"^\s*run\s+([a-z][a-z0-9_]*)\s+--models", script, re.M))
# loop bodies: b${b} / p10_b${b} expanded over the loop's literal list
loop_var = re.search(r"for\s+(\w+)\s+in\s+([0-9 ]+);\s*do", script)
if loop_var:
var, values = loop_var.group(1), loop_var.group(2).split()
for tpl in re.findall(r'run\s+"([a-z0-9_${}]+)"', script):
if "${" in tpl:
tags |= {tpl.replace("${%s}" % var, v) for v in values}
return tags
def report_tags(source: str) -> set[str]:
tags = set(re.findall(r'cell\([^)]*?,\s*"([a-z0-9_]+)"\s*\)', source))
# literal tag strings in tuples/lists passed to the spread helpers
tags |= set(re.findall(r'\(\s*"[a-z0-9_]+",\s*\(\s*"([a-z0-9_]+)"', source))
tags |= set(re.findall(r'"(p10c5_b1|p10_b1|p10_b8|p10_b8r|b2r|b2r2|b8r|bf16|repeat|canon)"',
source))
return tags
def main() -> int:
campaign = campaign_tags((ROOT / "run_v2.sh").read_text(encoding="utf-8"))
report = report_tags((ROOT / "build_report.py").read_text(encoding="utf-8"))
check("campaign defines tags", len(campaign) >= 10, f"{len(campaign)} tags")
missing = sorted(report - campaign)
check("report only uses tags the campaign produces", not missing, str(missing))
shipped = {p.name.split("__")[-1][:-5]
for p in (ROOT / "results_v2").glob("*.json")}
shipped.discard("summary")
orphans = sorted(shipped - campaign - EXEMPT)
check("every shipped result tag comes from the campaign", not orphans, str(orphans))
check("campaign produces the padded batch-1 cells", {"p10_b1", "p10c5_b1"} <= campaign)
check("campaign produces the batch-2 repeats", {"b2r", "b2r2"} <= campaign)
print("\n" + ("CAMPAIGN COVERAGE OK" if not FAILS else f"FAILURES: {FAILS}"))
return 0 if not FAILS else 1
if __name__ == "__main__":
raise SystemExit(main())