File size: 1,929 Bytes
c794b6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Phase 2 — Priority 5: MK-only gossip graph scenario."""
import os
import sys

os.environ.setdefault("CEPHEUS_CLOUD", "1")
BACKEND_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
FR = os.path.join(BACKEND_DIR, "Face_Recognition")
for p in (BACKEND_DIR, FR):
    if p not in sys.path:
        sys.path.insert(0, p)

import gossip_bridge  # noqa: E402


def test_mk_alone_produces_zero_edges_one_node():
    """
    User scenario: MK live on one feed; Urvi/Vidit not detected → no false edges.
    """
    gossip_bridge.clear_graph()
    gossip_bridge.clear_tracking_meta()
    gossip_bridge.register_enrolled_roster(["MK", "Urvi", "Vidit"])
    gossip_bridge.set_root_person("MK")
    gossip_bridge.start_tracking()

    gossip_bridge.on_detections(
        "cam-01",
        ["MK"],
        [(100, 100, 200, 200)],
        frame_width=640,
    )

    data = gossip_bridge.get_gossip_json("MK")
    links = data.get("links", [])
    nodes = data.get("nodes", [])
    node_names = {n.get("name") for n in nodes}

    assert len(links) == 0, f"Expected zero edges, got {links}"
    assert "MK" in node_names
    assert "Urvi" not in node_names or not any(
        l.get("source") == "Urvi" or l.get("target") == "Urvi" for l in links
    )
    assert "Vidit" not in node_names or not any(
        l.get("source") == "Vidit" or l.get("target") == "Vidit" for l in links
    )
    assert len([n for n in nodes if n.get("name") == "MK"]) == 1


def test_two_person_proximity_creates_one_edge():
    gossip_bridge.clear_graph()
    gossip_bridge.register_enrolled_roster(["MK", "Urvi"])
    gossip_bridge.set_root_person("MK")
    gossip_bridge.start_tracking()
    gossip_bridge.on_detections(
        "cam-01",
        ["MK", "Urvi"],
        [(100, 100, 200, 200), (110, 110, 210, 210)],
        frame_width=640,
    )
    data = gossip_bridge.get_gossip_json("MK")
    assert len(data.get("links", [])) >= 1