Files
document-haness/scripts/verify.sh
T

72 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
export PYTHONPATH="$ROOT/src${PYTHONPATH:+:$PYTHONPATH}"
python3 -m unittest discover -s "$ROOT/tests" -v
python3 -m claridoc validate \
--brief "$ROOT/examples/briefs/retry-policy-blog.json" \
--sources "$ROOT/examples/sources/retry-policy-sources.json"
bash "$ROOT/scripts/run-demo.sh"
python3 - "$ROOT" <<'PY'
from __future__ import annotations
import ast
import hashlib
import json
import re
import sys
from pathlib import Path
root = Path(sys.argv[1]).resolve()
python_files = sorted((root / "src").rglob("*.py")) + sorted((root / "tests").rglob("*.py"))
for path in python_files:
ast.parse(path.read_text(encoding="utf-8"), filename=str(path), feature_version=(3, 10))
json_files = [
path for path in sorted(root.rglob("*.json"))
if not any(part in {"build", "dist", "__pycache__"} for part in path.parts)
]
for path in json_files:
json.loads(path.read_text(encoding="utf-8"))
link_pattern = re.compile(r"\[[^\]]*\]\(([^)]+)\)")
local_links = 0
for path in sorted(root.rglob("*.md")):
if any(part in {"build", "dist", "__pycache__"} for part in path.parts):
continue
for target in link_pattern.findall(path.read_text(encoding="utf-8")):
target = target.strip().split("#", 1)[0]
if not target or re.match(r"^[A-Za-z][A-Za-z0-9+.-]*:", target):
continue
local_links += 1
resolved = (path.parent / target).resolve()
if not resolved.exists():
raise SystemExit(f"broken local Markdown link: {path.relative_to(root)} -> {target}")
run_dir = root / "examples" / "output" / "retry-policy-demo"
run = json.loads((run_dir / "run.json").read_text(encoding="utf-8"))
if not run.get("passed"):
raise SystemExit("demo quality gate did not pass")
if not any("synthetic" in warning for warning in run.get("warnings", [])):
raise SystemExit("mock-run synthetic-score warning is missing")
manifest = json.loads((run_dir / "manifest.json").read_text(encoding="utf-8"))
for item in manifest["files"]:
artifact = run_dir / item["path"]
if artifact.stat().st_size != item["bytes"]:
raise SystemExit(f"manifest size mismatch: {item['path']}")
digest = hashlib.sha256(artifact.read_bytes()).hexdigest()
if digest != item["sha256"]:
raise SystemExit(f"manifest hash mismatch: {item['path']}")
print(
"VERIFIED: "
f"{len(python_files)} Python files parse with Python 3.10 grammar; "
f"{len(json_files)} JSON files parse; {local_links} local Markdown links resolve; "
f"demo PASS at {run['final_score']:.1f}/100 (synthetic mock score); manifest hashes match."
)
PY