Files
git.stella-ops.org/scripts/corpus/validate-corpus.py

55 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Validate golden corpus case structure."""
from __future__ import annotations
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
CORPUS = ROOT / "bench" / "golden-corpus" / "categories"
REQUIRED = [
"case-manifest.json",
"run-manifest.json",
"input/sbom-cyclonedx.json",
"input/sbom-spdx.json",
"input/image.tar.gz",
"expected/verdict.json",
"expected/evidence-index.json",
"expected/unknowns.json",
"expected/delta-verdict.json",
]
def validate_case(case_dir: Path) -> list[str]:
missing = []
for rel in REQUIRED:
if not (case_dir / rel).exists():
missing.append(rel)
return missing
def main() -> int:
if not CORPUS.exists():
print(f"Corpus path not found: {CORPUS}")
return 1
errors = []
cases = sorted([p for p in CORPUS.rglob("*") if p.is_dir() and (p / "case-manifest.json").exists()])
for case in cases:
missing = validate_case(case)
if missing:
errors.append({"case": str(case.relative_to(ROOT)), "missing": missing})
if errors:
print(json.dumps({"status": "fail", "errors": errors}, indent=2))
return 1
print(json.dumps({"status": "ok", "cases": len(cases)}, indent=2))
return 0
if __name__ == "__main__":
raise SystemExit(main())