[AZ-178] Add real-video streaming test, update e2e tests, mark task done

- Add tests/test_az178_realvideo_streaming.py: integration test that validates
  frame decoding begins while upload is still in progress using a real video fixture
- Add conftest.py: pytest plugin for per-test duration reporting
- Update e2e tests (async_sse, performance, security, streaming_video_upload, video)
  and run-tests.sh for updated test suite
- Move AZ-178 task to done/; add data/ to .gitignore (StreamingBuffer temp files)
- Update autopilot state to step 12 (Security Audit) for new feature cycle

Made-with: Cursor
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-04-01 05:02:25 +03:00
parent be4cab4fcb
commit 07c2afb62e
11 changed files with 142 additions and 261 deletions
+25 -30
View File
@@ -1,29 +1,28 @@
import base64
import json
import threading
import time
import uuid
from pathlib import Path
import pytest
import sseclient
FIXTURES_DIR = Path(__file__).resolve().parent.parent / "fixtures"
_VIDEO = str(FIXTURES_DIR / "video_test01.mp4")
def _make_jwt() -> str:
header = base64.urlsafe_b64encode(
json.dumps({"alg": "none", "typ": "JWT"}).encode()
).decode().rstrip("=")
raw = json.dumps(
{"exp": int(time.time()) + 3600, "sub": "test"}, separators=(",", ":")
).encode()
payload = base64.urlsafe_b64encode(raw).decode().rstrip("=")
return f"{header}.{payload}.signature"
def _chunked_reader(path: str, chunk_size: int = 64 * 1024):
with open(path, "rb") as f:
while True:
chunk = f.read(chunk_size)
if not chunk:
break
yield chunk
@pytest.fixture(scope="module")
def video_events(warm_engine, http_client):
media_id = f"video-{uuid.uuid4().hex}"
body = {}
token = _make_jwt()
if not Path(_VIDEO).is_file():
pytest.skip(f"missing fixture {_VIDEO}")
collected: list[tuple[float, dict]] = []
thread_exc: list[BaseException] = []
@@ -31,16 +30,13 @@ def video_events(warm_engine, http_client):
def _listen():
try:
with http_client.get("/detect/stream", stream=True, timeout=600) as resp:
with http_client.get("/detect/stream", stream=True, timeout=35) as resp:
resp.raise_for_status()
sse = sseclient.SSEClient(resp)
time.sleep(0.3)
for event in sse.events():
if not event.data or not str(event.data).strip():
continue
data = json.loads(event.data)
if data.get("mediaId") != media_id:
continue
collected.append((time.monotonic(), data))
if (
data.get("mediaStatus") == "AIProcessed"
@@ -54,22 +50,23 @@ def video_events(warm_engine, http_client):
th = threading.Thread(target=_listen, daemon=True)
th.start()
time.sleep(0.5)
time.sleep(0.3)
r = http_client.post(
f"/detect/{media_id}",
json=body,
headers={"Authorization": f"Bearer {token}"},
"/detect/video",
data=_chunked_reader(_VIDEO),
headers={"X-Filename": "video_test01.mp4", "Content-Type": "application/octet-stream"},
timeout=15,
)
assert r.status_code == 200
assert r.json() == {"status": "started", "mediaId": media_id}
assert done.wait(timeout=900)
assert done.wait(timeout=30)
th.join(timeout=5)
assert not thread_exc, thread_exc
return collected
@pytest.mark.slow
@pytest.mark.timeout(900)
@pytest.mark.timeout(30)
def test_ft_p_10_frame_sampling_ac1(video_events):
# Assert
processing = [d for _, d in video_events if d.get("mediaStatus") == "AIProcessing"]
@@ -79,8 +76,7 @@ def test_ft_p_10_frame_sampling_ac1(video_events):
assert final["mediaPercent"] == 100
@pytest.mark.slow
@pytest.mark.timeout(900)
@pytest.mark.timeout(30)
def test_ft_p_11_annotation_interval_ac2(video_events):
# Assert
processing = [
@@ -94,8 +90,7 @@ def test_ft_p_11_annotation_interval_ac2(video_events):
assert final["mediaPercent"] == 100
@pytest.mark.slow
@pytest.mark.timeout(900)
@pytest.mark.timeout(30)
def test_ft_p_12_movement_tracking_ac3(video_events):
# Assert
for _, e in video_events: