File size: 1,332 Bytes
4977b39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
"""Validate release paths and sizes without reading field values."""

from __future__ import annotations

import argparse
import json
from pathlib import Path


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("release_root", type=Path, nargs="?", default=Path.cwd())
    args = parser.parse_args()
    root = args.release_root.resolve()
    manifest = root / "metadata" / "cases.jsonl"
    rows = [json.loads(line) for line in manifest.read_text().splitlines() if line]
    missing = []
    size_mismatches = []
    for row in rows:
        file_path = root / row["release_path"]
        if not file_path.is_file():
            missing.append(row["release_path"])
            continue
        actual = file_path.stat().st_size
        if actual != row["file_bytes"]:
            size_mismatches.append(
                {"file": row["release_path"], "expected": row["file_bytes"], "actual": actual}
            )
    report = {
        "root": str(root),
        "manifest_rows": len(rows),
        "missing": missing,
        "size_mismatches": size_mismatches,
        "valid": not missing and not size_mismatches,
    }
    print(json.dumps(report, indent=2, sort_keys=True))
    return 0 if report["valid"] else 1


if __name__ == "__main__":
    raise SystemExit(main())