Refactor code structure for improved readability and maintainability; optimize performance in key functions.
This commit is contained in:
54
scripts/corpus/validate-corpus.py
Normal file
54
scripts/corpus/validate-corpus.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/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())
|
||||
Reference in New Issue
Block a user