| """Phase 2 — Priority 2: session reset vs login behavior.""" |
| import os |
| import sys |
|
|
| os.environ.setdefault("CEPHEUS_CLOUD", "1") |
| os.environ.setdefault("CEPHEUS_API_KEY", "test-key") |
|
|
| BACKEND_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| if BACKEND_DIR not in sys.path: |
| sys.path.insert(0, BACKEND_DIR) |
|
|
| import pytest |
| from fastapi.testclient import TestClient |
|
|
| import main |
|
|
| API_HEADERS = {"X-API-Key": "test-key"} |
|
|
|
|
| @pytest.fixture |
| def client(): |
| return TestClient(main.app) |
|
|
|
|
| def test_new_session_clears_tracking_not_login(client, monkeypatch): |
| """Explicit session reset clears data; routine API calls do not.""" |
| monkeypatch.setattr(main, "detections_history", [{"name": "MK", "camId": "cam-01"}]) |
| main.vision_engine.face_results["cam-01"] = [{"name": "MK"}] |
| if hasattr(main.vision_engine, "browser_feeds"): |
| main.vision_engine.browser_feeds["cam-01"] = {"status": "ACTIVE"} |
|
|
| r = client.post( |
| "/tracking/session/reset", |
| headers=API_HEADERS, |
| json={"broadcast": False, "full_reset": True, "clear_agent_steps": True}, |
| ) |
| assert r.status_code == 200 |
| assert main.detections_history == [] |
| assert main.vision_engine.face_results.get("cam-01", []) == [] |
|
|
|
|
| def test_global_reset_broadcast_requires_admin(client): |
| r = client.post( |
| "/tracking/session/reset", |
| headers=API_HEADERS, |
| json={"broadcast": True}, |
| ) |
| assert r.status_code == 403 |
|
|
|
|
| def test_operator_can_reset_own_session_without_broadcast(client, monkeypatch): |
| monkeypatch.setattr(main, "detections_history", [{"name": "X"}]) |
| r = client.post( |
| "/tracking/session/reset", |
| headers=API_HEADERS, |
| json={"broadcast": False, "full_reset": True}, |
| ) |
| assert r.status_code == 200 |
| assert main.detections_history == [] |
|
|