baseball-engine / tests /test_pitching_ml_coach_validation.py
github-actions[bot]
Automated Deploy: c6740dc30c6da8c1add9680c0c571ec78bec8366
66d2e51
Raw History Blame Contribute Delete
1.25 kB
"""Audit utility must not overwrite evidence or accept a substituted source video."""
import hashlib
import pytest
from tools.validate_pitching_ml_coach import AuditError, check_output, verify_file
def test_audit_output_guard_preserves_existing_and_source_evidence(tmp_path):
source = tmp_path / "source"
source.mkdir()
sentinel = source / "manifest.json"
sentinel.write_text("original evidence")
existing = tmp_path / "existing"
existing.mkdir()
for output in (source, source / "new-audit", existing):
with pytest.raises(AuditError):
check_output(source, output)
assert sentinel.read_text() == "original evidence"
assert not (source / "new-audit").exists()
check_output(source, tmp_path / "new-audit")
def test_audit_rejects_same_length_substituted_video(tmp_path):
video = tmp_path / "clip.mp4"
original = b"original-source-video"
video.write_bytes(original)
checksum = hashlib.sha256(original).hexdigest()
verify_file(video, checksum, len(original))
video.write_bytes(b"substitute-source-vid")
assert video.stat().st_size == len(original)
with pytest.raises(AuditError, match="checksum mismatch"):
verify_file(video, checksum, len(original))