Each run is diffed against the previous one (--compare-to, or the newest other run in ~/dl2-archive/checker-runs): changes.md lists every (event, field) that matched before and no longer does, how many now match, and how each field's counts moved; summary.md leads with the regression count. --file NAME checks one event and prints its table, writing no run folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
132 lines
5.5 KiB
Python
132 lines
5.5 KiB
Python
"""
|
|
The decode checker's runner and reports (decode checker, Tasks 5-7).
|
|
|
|
Runs on the fixture folder, which holds the binaries and their XML reports
|
|
side by side.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import gzip
|
|
import importlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
run = importlib.import_module("scratch.check_s3_decode")
|
|
|
|
FIX = Path(__file__).parent / "fixtures/decode-checker-10-29-26"
|
|
|
|
|
|
def test_find_pairs_dedupes_and_pairs(tmp_path):
|
|
(tmp_path / "Sent").mkdir()
|
|
for n in ("R352HIUI.F40W", "Sent/R352HIUI.F40W", "UM11719_20240404193109.IDFH"):
|
|
(tmp_path / n).write_bytes(b"x")
|
|
pairs = run.find_pairs(tmp_path, FIX)
|
|
assert [p[0] for p in pairs] == ["R352HIUI.F40W"]
|
|
assert pairs[0][2].name == "R352HIUI_F40W_XML.XML"
|
|
|
|
|
|
def test_check_event_rows_and_attrs():
|
|
out = run.check_event("M007HVWF.K30W", str(FIX / "M007HVWF.K30W"), str(FIX / "M007HVWF_K30W_XML.XML"))
|
|
assert out["attrs"]["range"] == "1.250" and out["attrs"]["model"] == "MiniMate Plus"
|
|
assert any(r[0] == "TranPPV" and r[1] == "mismatch" for r in out["results"])
|
|
|
|
|
|
def test_bad_input_is_one_error_row(tmp_path):
|
|
bad = tmp_path / "R352HIUI.F40W"
|
|
bad.write_bytes(b"not a blastware file")
|
|
out = run.check_event(bad.name, str(bad), str(FIX / "R352HIUI_F40W_XML.XML"))
|
|
assert out["results"] == [["event", "error", None, None, out["results"][0][4], None]]
|
|
|
|
|
|
def test_missing_reference_is_one_no_reference_row():
|
|
out = run.check_event("R352HIUI.F40W", str(FIX / "R352HIUI.F40W"), None)
|
|
assert [r[:2] for r in out["results"]] == [["event", "no_reference"]]
|
|
|
|
|
|
def test_cli_writes_results(tmp_path):
|
|
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "run"), "--jobs", "1"]) == 0
|
|
lines = gzip.open(tmp_path / "run/results.jsonl.gz", "rt").read().splitlines()
|
|
assert len(lines) == 7
|
|
assert json.loads((tmp_path / "run/run.json").read_text())["events"] == 7
|
|
|
|
|
|
def test_field_filter_keeps_only_matching_rows(tmp_path):
|
|
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "run"), "--jobs", "1",
|
|
"--field", "samples."]) == 0
|
|
for line in gzip.open(tmp_path / "run/results.jsonl.gz", "rt"):
|
|
assert all(r[0].startswith("samples.") for r in json.loads(line)["results"])
|
|
|
|
|
|
# ── Task 6: summary and detailed report ─────────────────────────────────────
|
|
|
|
report = importlib.import_module("scratch.decode_check_report")
|
|
|
|
|
|
def _write_results(path, events):
|
|
with gzip.open(path, "wt") as fh:
|
|
for ev in events:
|
|
fh.write(json.dumps(ev) + "\n")
|
|
|
|
|
|
def _ev(name, sr, verdict):
|
|
return {"file": name, "attrs": {"sample_rate": sr, "year": "2024"},
|
|
"results": [["SampleRate", verdict, sr + " sps", "1024", "", None]]}
|
|
|
|
|
|
def test_details_group_failures_by_what_they_share(tmp_path):
|
|
res = tmp_path / "results.jsonl.gz"
|
|
_write_results(res, [_ev("A.W", "2048", "mismatch"), _ev("B.W", "2048", "mismatch"),
|
|
_ev("C.W", "1024", "match")])
|
|
agg = report.aggregate(res)
|
|
report.write_details(agg, tmp_path / "details.json")
|
|
d = json.loads((tmp_path / "details.json").read_text())["SampleRate|mismatch"]
|
|
assert d["total"] == 2
|
|
assert d["groups"]["sample_rate"] == [
|
|
{"value": "2048", "failing": 2, "compared": 2, "rate": 1.0, "concentrated": True}]
|
|
assert d["examples"] and all("--file" in e["rerun"] for e in d["examples"])
|
|
|
|
|
|
def test_summary_counts_fields_fully_matching(tmp_path):
|
|
res = tmp_path / "results.jsonl.gz"
|
|
_write_results(res, [_ev("A.W", "2048", "mismatch"), _ev("C.W", "1024", "match")])
|
|
report.write_summary(report.aggregate(res), tmp_path / "summary.md")
|
|
text = (tmp_path / "summary.md").read_text()
|
|
assert "0 of 1 fields fully matching" in text and "| SampleRate |" in text
|
|
|
|
|
|
def test_a_run_writes_both_reports(tmp_path):
|
|
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "run"), "--jobs", "1"]) == 0
|
|
assert (tmp_path / "run/summary.md").exists() and (tmp_path / "run/details.json").exists()
|
|
|
|
|
|
# ── Task 7: run-to-run changes and the one-event view ───────────────────────
|
|
|
|
def _one(name, field, verdict):
|
|
return {"file": name, "attrs": {}, "results": [[field, verdict, "x", "y", "", None]]}
|
|
|
|
|
|
def test_compare_runs_finds_regressions_and_fixes(tmp_path):
|
|
prev, cur = tmp_path / "prev.jsonl.gz", tmp_path / "cur.jsonl.gz"
|
|
_write_results(prev, [_one("A.W", "SampleRate", "match"), _one("B.W", "notes", "sfm_blank")])
|
|
_write_results(cur, [_one("A.W", "SampleRate", "mismatch"), _one("B.W", "notes", "match")])
|
|
chg = report.compare_runs(prev, cur)
|
|
assert chg["regressions"] == [{"file": "A.W", "field": "SampleRate",
|
|
"before": "match", "after": "mismatch"}]
|
|
assert chg["fixed"] == 1
|
|
report.write_changes(chg, tmp_path / "changes.md")
|
|
assert "A.W" in (tmp_path / "changes.md").read_text()
|
|
|
|
|
|
def test_compare_to_marks_the_summary(tmp_path):
|
|
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "a"), "--jobs", "1"]) == 0
|
|
assert run.main([str(FIX), str(FIX), "--out", str(tmp_path / "b"), "--jobs", "1",
|
|
"--compare-to", str(tmp_path / "a")]) == 0
|
|
assert "**0 regressions**" in (tmp_path / "b/summary.md").read_text()
|
|
assert (tmp_path / "b/changes.md").exists()
|
|
|
|
|
|
def test_file_prints_one_event(tmp_path, capsys):
|
|
assert run.main([str(FIX), str(FIX), "--file", "M007HVWF.K30W"]) == 0
|
|
out = capsys.readouterr().out
|
|
assert any("TranPPV" in line and "mismatch" in line for line in out.splitlines())
|