protocol: add generated bindings and conformance fixtures
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check the content-addressed Phase 3A conformance corpus."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
MANIFEST = ROOT / "fixtures/manifest.json"
|
||||
|
||||
|
||||
def digest(paths: list[str]) -> str:
|
||||
value = hashlib.sha256()
|
||||
for relative in paths:
|
||||
path = ROOT / relative
|
||||
value.update(relative.encode("utf-8"))
|
||||
value.update(b"\0")
|
||||
value.update(path.read_bytes())
|
||||
value.update(b"\0")
|
||||
return value.hexdigest()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
manifest = json.loads(MANIFEST.read_text(encoding="utf-8"))
|
||||
paths = sorted(path.relative_to(ROOT).as_posix() for path in (ROOT / "fixtures/conformance").glob("*.tsv"))
|
||||
if paths != manifest.get("files"):
|
||||
raise ValueError("fixture manifest file list is stale")
|
||||
actual = digest(paths)
|
||||
expected = manifest.get("corpus_sha256")
|
||||
if not expected or actual != expected:
|
||||
raise ValueError(f"fixture corpus hash mismatch: {actual}")
|
||||
print(f"Fixture corpus SHA256 {actual}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
raise SystemExit(main())
|
||||
except (OSError, ValueError, json.JSONDecodeError) as exc:
|
||||
print(f"fixture_digest: {exc}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
Reference in New Issue
Block a user