"""Tests for IngestAgent.""" import pytest import numpy as np from formscout.agents.ingest import IngestAgent from formscout.types import IngestResult def _make_test_video(path, fps=30, n_frames=30, w=640, h=480): """Create a minimal test video using OpenCV.""" import cv2 out = cv2.VideoWriter(str(path), cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h)) for _ in range(n_frames): out.write(np.zeros((h, w, 3), dtype=np.uint8)) out.release() class TestIngestAgent: def test_returns_typed_result(self, tmp_path): p = tmp_path / "test.mp4" _make_test_video(p) agent = IngestAgent() result = agent.run(str(p)) assert isinstance(result, IngestResult) assert result.fps == pytest.approx(30.0, abs=2.0) assert len(result.frames) > 0 assert result.width == 640 assert result.height == 480 assert result.confidence == 1.0 def test_rejects_missing_file(self): agent = IngestAgent() result = agent.run("/nonexistent/path.mp4") assert result.confidence == 0.0 assert "not found" in result.notes.lower() def test_result_is_frozen(self, tmp_path): p = tmp_path / "test.mp4" _make_test_video(p, n_frames=10, w=64, h=64) agent = IngestAgent() result = agent.run(str(p)) with pytest.raises(Exception): result.fps = 999.0 def test_caps_frames(self, tmp_path): """Verify frame cap works on long videos.""" p = tmp_path / "long.mp4" _make_test_video(p, n_frames=600) agent = IngestAgent() result = agent.run(str(p)) assert len(result.frames) <= 300