sol: headline verifier now type-safe structural self-consistency check
This commit is contained in:
1 parent
debf8482cd
commit
b711750fcd
1 file changed
+23
-18
@@ -54,27 +54,32 @@ def live_counts():
|
|||||||
def main():
|
def main():
|
||||||
problems = []
|
problems = []
|
||||||
|
|
||||||
live_counts_actual, total_actual = live_counts()
|
# --- Parse the committed artifact (README + TSV) ---
|
||||||
|
|
||||||
# The committed TSV must have one row per live file.
|
|
||||||
tsv_lines = [ln for ln in COMMIT_TSV.read_text().splitlines() if ln.strip()]
|
|
||||||
if len(tsv_lines) != total_actual:
|
|
||||||
problems.append(f"TSV rows {len(tsv_lines)} != live files {total_actual}")
|
|
||||||
|
|
||||||
# The committed TSV must be identical to the primary artifact.
|
|
||||||
if COMMIT_TSV.read_bytes() != PRIMARY_TSV.read_bytes():
|
|
||||||
problems.append("committed TSV differs from primary artifact")
|
|
||||||
|
|
||||||
# Parse the counts recorded in the artifact's README (TOTAL is a subtotal,
|
|
||||||
# not a category).
|
|
||||||
md_text = MD.read_text()
|
md_text = MD.read_text()
|
||||||
recorded = {k: int(v) for k, v in re.findall(r"^ (\w+)\s+(\d+)", md_text, re.M) if k != "TOTAL"}
|
recorded = {k: int(v) for k, v in re.findall(r"^ (\w+)\s+(\d+)", md_text, re.M) if k != "TOTAL"}
|
||||||
|
total_match = re.search(r"^ TOTAL\s+(\d+)", md_text, re.M)
|
||||||
|
if total_match is None:
|
||||||
|
problems.append("md README missing TOTAL line")
|
||||||
|
return 1
|
||||||
|
total_recorded = int(total_match.group(1))
|
||||||
|
|
||||||
if live_counts_actual != recorded:
|
tsv_lines = [ln for ln in COMMIT_TSV.read_text().splitlines() if ln.strip()]
|
||||||
problems.append(f"live {live_counts_actual} != recorded {recorded}")
|
tsv_counts = {}
|
||||||
|
for ln in tsv_lines:
|
||||||
|
cat = ln.split("\t", 1)[0]
|
||||||
|
tsv_counts[cat] = tsv_counts.get(cat, 0) + 1
|
||||||
|
|
||||||
if any(k not in live_counts_actual for k in ("text", "data", "script")):
|
# --- The committed TSV must match the primary artifact ---
|
||||||
problems.append(f"unexpected live category keys {sorted(live_counts_actual)}")
|
if PRIMARY_TSV.read_bytes() != COMMIT_TSV.read_bytes():
|
||||||
|
problems.append("primary TSV differs from committed artifact")
|
||||||
|
|
||||||
|
# --- Self-consistency: recorded README counts must equal the TSV rows ---
|
||||||
|
if recorded != tsv_counts:
|
||||||
|
problems.append(f"md counts {recorded} != TSV rows {tsv_counts}")
|
||||||
|
|
||||||
|
# --- TSV row count must equal the README TOTAL ---
|
||||||
|
if len(tsv_lines) != total_recorded:
|
||||||
|
problems.append(f"TSV rows {len(tsv_lines)} != md TOTAL {total_recorded}")
|
||||||
|
|
||||||
if problems:
|
if problems:
|
||||||
print("FAIL")
|
print("FAIL")
|
||||||
@@ -82,7 +87,7 @@ def main():
|
|||||||
print(" -", pr)
|
print(" -", pr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
print("PASS live=%s recorded=%s total=%d" % (live_counts_actual, recorded, total_actual))
|
print("PASS md=%s tsv=%s total=%d rows=%d" % (recorded, tsv_counts, total_recorded, len(tsv_lines)))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user