File size: 3,719 Bytes
58f8c8a | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #!/usr/bin/env python3
"""Check release integrity without loading a model or running an agent."""
from __future__ import annotations
import argparse
from collections import Counter
import hashlib
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
NESTED_FIELDS = ("knowledge", "workspace", "evaluation_contract", "reference_solution")
def require(condition, message):
if not condition:
raise ValueError(message)
def verify(check_parquet=False):
manifest = json.loads((ROOT / "manifest.json").read_text(encoding="utf-8"))
for name, expected in manifest["files"].items():
actual = hashlib.sha256((ROOT / name).read_bytes()).hexdigest()
require(actual == expected["sha256"], f"Checksum mismatch: {name}")
records = [json.loads(line) for line in (ROOT / "tasks.jsonl").read_text(encoding="utf-8").splitlines()]
require(len(records) == 50, "Expected 50 tasks")
require([r["id"] for r in records] == [f"hybrid-{i:03d}" for i in range(1, 51)], "Unexpected task IDs/order")
require(len({r["knowledge"]["source_task_id"] for r in records}) == 50, "Sources must be distinct")
require(dict(Counter(r["workspace"]["scenario"] for r in records)) == manifest["scenario_counts"], "Scenario counts differ")
require(all(len(r["knowledge"]["rag_corpus"]) == 12 for r in records), "Expected 12 retrieval documents per task")
semantic_hash = hashlib.sha256(json.dumps(records, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
require(semantic_hash == manifest["canonical_data"]["parsed_records_sha256"], "Semantic checksum mismatch")
replay = json.loads((ROOT / "audit/verification.json").read_text(encoding="utf-8"))
audit = json.loads((ROOT / "audit/revision_audit.json").read_text(encoding="utf-8"))
require(replay["dataset_sha256"] == semantic_hash, "Replay does not match release")
require(audit["dataset_sha256"] == manifest["files"]["tasks.jsonl"]["sha256"], "Source audit does not match release")
plan = json.loads((ROOT / "attacks/attack_plan.json").read_text(encoding="utf-8"))
expected_pairs = {(r["id"], f"m{m}_g{g}") for r in records for m in (2, 3, 4, 6) for g in (1, 2, 3, 4)}
pairs = [(e["task_id"], e["attack"]) for e in plan["entries"]]
require(len(pairs) == 800 and set(pairs) == expected_pairs, "Attack coverage mismatch")
if check_parquet:
import pyarrow.parquet as pq
rows = pq.read_table(ROOT / "data/test.parquet").to_pylist()
reconstructed = [{"id": r["id"], "schema_version": r["schema_version"], "query": r["query"],
**{f: json.loads(r[f + "_json"]) for f in NESTED_FIELDS}} for r in rows]
require(reconstructed == records, "Parquet view is not lossless")
statuses = {r["task_id"]: r["knowledge_status"] for r in audit["rows"]}
for row, record in zip(rows, records):
require(row["scenario"] == record["workspace"]["scenario"], "Scenario view mismatch")
for field in ("source_task_id", "question", "reference_answer"):
require(row[field] == record["knowledge"][field], f"View mismatch: {field}")
require(row["evidence_status"] == statuses[row["id"]], "Evidence status mismatch")
print(f"Verified 50 tasks, 600 retrieval documents, 800 attack entries, {len(manifest['files'])} file checksums" +
(", and lossless Parquet round-trip." if check_parquet else "."))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--check-parquet", action="store_true", help="Also require pyarrow and check the Hub view")
args = parser.parse_args()
verify(args.check_parquet)
|