A channel is over range when the unit's own peak (its summary's min / max) passes 2,000: 32,000 counts, full scale, on either geophone range; the mic in counts. Blastware prints OORANGE for that channel's peak, for the vector sum when any geophone is over, and its "Out of Range" line when the mic is (DL2, 2026-11-09): numeric up to 1,991 / 1,933, OORANGE from 2,001; the vector sum is OORANGE on all 43 events with a geophone over and on none of the 38 whose vector sum alone passes 10 in/s -- the open "vector sum alone" carve-out was never needed. PeakValues gains tran/vert/long/mic/pvs_over_range. The checker matches OORANGE by the flag, and calls a flag against a printed number a mismatch. Clipped events that the saturation carve-out used to accept now match outright; the carve-out stays as the fallback for a file without the unit's summary, and its guards are tested that way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALX2R8pghDaZuti9U7mEE9
176 lines
8.1 KiB
Python
176 lines
8.1 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"
|
|
# clipped at its own 1.250 ceiling: Blastware's OORANGE, matched by the unit's
|
|
# own peak since 2026-11-09 (it was accepted under the saturation carve-out)
|
|
assert ["TranPPV", "match"] in [r[:2] 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 "OORANGE" in line for line in out.splitlines())
|
|
|
|
|
|
# ── Final review fixes ──────────────────────────────────────────────────────
|
|
|
|
def test_a_matching_event_that_now_errors_is_a_regression(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", "match")])
|
|
_write_results(cur, [_one("A.W", "event", "error"), _one("B.W", "notes", "match")])
|
|
chg = report.compare_runs(prev, cur)
|
|
assert chg["regressions"] == [{"file": "A.W", "field": "SampleRate",
|
|
"before": "match", "after": "error"}]
|
|
|
|
|
|
def test_counts_moved_cover_only_shared_events(tmp_path):
|
|
prev, cur = tmp_path / "prev.jsonl.gz", tmp_path / "cur.jsonl.gz"
|
|
_write_results(prev, [_one("A.W", "SampleRate", "match")])
|
|
_write_results(cur, [_one("A.W", "SampleRate", "match"), _one("B.W", "SampleRate", "match")])
|
|
assert report.compare_runs(prev, cur)["fields"]["SampleRate"]["match"] == [1, 1]
|
|
|
|
|
|
def test_default_comparison_is_the_newest_completed_run_of_the_same_scope(tmp_path, monkeypatch):
|
|
runs = tmp_path / "runs"
|
|
monkeypatch.setattr(run, "RUNS_DIR", runs)
|
|
base = [str(FIX), str(FIX), "--jobs", "1"]
|
|
assert run.main(base + ["--out", str(runs / "20990101-000001")]) == 0 # same scope
|
|
assert run.main(base + ["--out", str(runs / "20990101-000002"), "--type", "W"]) == 0 # narrower
|
|
(runs / "20990101-000003").mkdir() # never finished
|
|
assert run.main(base + ["--out", str(runs / "20990101-000004")]) == 0
|
|
assert "20990101-000001" in (runs / "20990101-000004/changes.md").read_text().splitlines()[0]
|
|
|
|
|
|
def test_fields_fully_matching_need_a_match_and_skip_the_event_row(tmp_path):
|
|
res = tmp_path / "results.jsonl.gz"
|
|
_write_results(res, [
|
|
{"file": "A.W", "attrs": {}, "results": [["SampleRate", "match", "1", "1", "", None],
|
|
["UsbSummaryChannels", "no_reference", "", None, "", None]]},
|
|
{"file": "B.W", "attrs": {}, "results": [["event", "no_reference", None, None, "no XML report", None]]},
|
|
])
|
|
report.write_summary(report.aggregate(res), tmp_path / "summary.md")
|
|
text = (tmp_path / "summary.md").read_text()
|
|
assert "1 of 2 fields fully matching" in text
|
|
assert "1 event without a report" in text and "| event |" not in text
|