tooling(scratch): decode-check run-to-run changes and a one-event view
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
This commit is contained in:
1 parent
5e85cf1018
commit
c8fc649568
3 files changed
+111
No files matched your search
@@ -131,6 +131,30 @@ def _git_head() -> Optional[str]:
|
||||
return None
|
||||
|
||||
|
||||
def _previous_run(out_dir: Path) -> Optional[Path]:
|
||||
"""The newest other run in the runs folder -- only for runs kept there."""
|
||||
if out_dir.parent.resolve() != RUNS_DIR.resolve():
|
||||
return None
|
||||
runs = sorted(p for p in RUNS_DIR.iterdir() if p.is_dir() and p.resolve() != out_dir.resolve())
|
||||
return runs[-1] if runs else None
|
||||
|
||||
|
||||
def _print_one(name: str, pairs: list[tuple[str, Path, Optional[Path]]]) -> int:
|
||||
"""--file: check one event and print its table; no run folder."""
|
||||
match = [p for p in pairs if p[0].upper() == name.upper()]
|
||||
if not match:
|
||||
print(f"{name}: no such event file under the binaries folder", file=sys.stderr)
|
||||
return 1
|
||||
n, b, x = match[0]
|
||||
ev = check_event(n, str(b), str(x) if x else None)
|
||||
print(f"{n} {ev['attrs']}")
|
||||
print(f"{'field':30s} {'verdict':12s} {'Blastware':30s} {'SFM':30s} detail")
|
||||
for field, verdict, bw, sfm, detail, carveout in ev["results"]:
|
||||
note = f"{detail} {('[' + carveout + ']') if carveout else ''}".strip()
|
||||
print(f"{field:30.30s} {verdict:12s} {str(bw):30.30s} {str(sfm):30.30s} {note}")
|
||||
return 0
|
||||
|
||||
|
||||
def main(argv: Optional[list[str]] = None) -> int:
|
||||
ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
|
||||
ap.add_argument("bin_dir", type=Path)
|
||||
@@ -149,6 +173,8 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
|
||||
started = time.monotonic()
|
||||
pairs = find_pairs(args.bin_dir, args.xml_dir)
|
||||
if args.file:
|
||||
return _print_one(args.file, pairs)
|
||||
if args.serial:
|
||||
prefixes = tuple(_filename_prefix(s) for s in args.serial)
|
||||
pairs = [p for p in pairs if p[0].upper().startswith(prefixes)]
|
||||
@@ -185,6 +211,11 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
"seconds": round(time.monotonic() - started, 1)}
|
||||
(out_dir / "run.json").write_text(json.dumps(run, indent=2))
|
||||
agg = report.aggregate(out_dir / "results.jsonl.gz")
|
||||
prev = args.compare_to or _previous_run(out_dir)
|
||||
if prev is not None and (prev / "results.jsonl.gz").exists():
|
||||
chg = report.compare_runs(prev / "results.jsonl.gz", out_dir / "results.jsonl.gz")
|
||||
report.write_changes(chg, out_dir / "changes.md")
|
||||
agg["regressions"] = len(chg["regressions"])
|
||||
report.write_summary(agg, out_dir / "summary.md")
|
||||
report.write_details(agg, out_dir / "details.json")
|
||||
print(out_dir)
|
||||
|
||||
@@ -141,3 +141,51 @@ def _pick_examples(agg: dict, key: str, groups: dict) -> list[dict]:
|
||||
rerun = f"python scratch/check_s3_decode.py {agg['bin_dir']} {agg['xml_dir']} --file "
|
||||
return [{"file": e["file"], "bw": e["bw"], "sfm": e["sfm"], "detail": e["detail"],
|
||||
"rerun": rerun + e["file"]} for e in picked]
|
||||
|
||||
|
||||
def _verdicts(results_path: Path) -> dict[tuple[str, str], str]:
|
||||
out = {}
|
||||
with gzip.open(results_path, "rt", encoding="utf-8") as fh:
|
||||
for line in fh:
|
||||
ev = json.loads(line)
|
||||
for row in ev["results"]:
|
||||
out[(ev["file"], row[0])] = row[1]
|
||||
return out
|
||||
|
||||
|
||||
def compare_runs(prev_results: Path, cur_results: Path) -> dict:
|
||||
"""What changed between two runs: per-field verdict counts before and
|
||||
after, every (event, field) that used to match and no longer does, and how
|
||||
many non-matches now match."""
|
||||
before, after = _verdicts(prev_results), _verdicts(cur_results)
|
||||
fields: dict[str, dict[str, list[int]]] = defaultdict(lambda: defaultdict(lambda: [0, 0]))
|
||||
for (_, field), v in before.items():
|
||||
fields[field][v][0] += 1
|
||||
for (_, field), v in after.items():
|
||||
fields[field][v][1] += 1
|
||||
regressions = [{"file": f, "field": fld, "before": "match", "after": v}
|
||||
for (f, fld), v in sorted(after.items())
|
||||
if v != "match" and before.get((f, fld)) == "match"]
|
||||
fixed = sum(1 for k, v in after.items() if v == "match" and before.get(k) not in (None, "match"))
|
||||
return {"fields": {f: dict(c) for f, c in fields.items()}, "regressions": regressions,
|
||||
"fixed": fixed, "prev": str(prev_results)}
|
||||
|
||||
|
||||
def write_changes(chg: dict, path: Path) -> None:
|
||||
regs = chg["regressions"]
|
||||
lines = [f"# Changes since {chg.get('prev', 'the previous run')}", "",
|
||||
f"{len(regs)} regressions · {chg['fixed']} fixed", ""]
|
||||
if regs:
|
||||
lines += ["## Regressions (matched before, not now)", "", "| file | field | now |", "|---|---|---|"]
|
||||
lines += [f"| {r['file']} | {r['field']} | {r['after']} |" for r in regs[:500]]
|
||||
if len(regs) > 500:
|
||||
lines.append(f"| … {len(regs) - 500} more | | |")
|
||||
lines.append("")
|
||||
moved = {f: c for f, c in chg["fields"].items() if any(b != a for b, a in c.values())}
|
||||
if moved:
|
||||
lines += ["## Fields whose counts moved (before → after)", "",
|
||||
"| field | " + " | ".join(VERDICTS) + " |", "|---|" + "---|" * len(VERDICTS)]
|
||||
for f in sorted(moved):
|
||||
lines.append(f"| {f} | " + " | ".join(
|
||||
f"{moved[f].get(v, [0, 0])[0]} → {moved[f].get(v, [0, 0])[1]}" for v in VERDICTS) + " |")
|
||||
Path(path).write_text("\n".join(lines) + "\n")
|
||||
@@ -97,3 +97,35 @@ def test_summary_counts_fields_fully_matching(tmp_path):
|
||||
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())
|
||||
Reference in new issue
Block a user