You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.8 KiB
80 lines
2.8 KiB
"""Voice forward plan helpers (P2-009)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from adn_server.application.bridge_use_cases import BridgeUseCases
|
|
from adn_server.application.subscription.store_sync import replace_store_from_bridges
|
|
from adn_server.domain import bytes_3
|
|
from adn_server.domain.dmr.bptc import encode_emblc
|
|
from adn_server.infrastructure.bridge_router_impl import InMemoryBridgeRouter
|
|
from adn_server.infrastructure.subscription_store import InMemorySubscriptionStore
|
|
from adn_server.infrastructure.talker_alias_emblc import default_ta_emblc_encoder
|
|
from tests.application.test_subscription_router import _row
|
|
from tests.harness.deterministic import minimal_config
|
|
|
|
|
|
def _bridge(bridges: dict, *, with_store: bool) -> BridgeUseCases:
|
|
config = minimal_config(("MASTER-A", "MASTER-B"))
|
|
router = InMemoryBridgeRouter()
|
|
router.set_bridges(bridges)
|
|
store = InMemorySubscriptionStore() if with_store else None
|
|
if store is not None:
|
|
replace_store_from_bridges(store, bridges)
|
|
return BridgeUseCases(
|
|
router,
|
|
config,
|
|
encode_emblc=encode_emblc,
|
|
ta_emblc_encoder=default_ta_emblc_encoder,
|
|
subscription_store=store,
|
|
)
|
|
|
|
|
|
def test_forward_plan_without_store_uses_router_tables_only():
|
|
"""Harness without a store falls back to BRIDGES index (unit-test shortcut)."""
|
|
bridges = {
|
|
"730444": [
|
|
_row(system="MASTER-A", ts=1, tgid=730444, active=True),
|
|
_row(system="MASTER-B", ts=1, tgid=730444, active=True),
|
|
]
|
|
}
|
|
bridge = _bridge(bridges, with_store=False)
|
|
tables, leg_keys = bridge._voice_forward_plan(
|
|
system_name="MASTER-A",
|
|
peer_id=b"\x00\x00\x03\xe9",
|
|
rf_src=b"\x00\x2f\x8b\x01",
|
|
dst_id=bytes_3(730444),
|
|
slot=1,
|
|
call_type="group",
|
|
stream_id=b"\x01\x02\x03\x04",
|
|
source_is_obp=False,
|
|
bridge_match_slot=1,
|
|
dst_int=730444,
|
|
)
|
|
assert tables == ("730444",)
|
|
assert leg_keys is None
|
|
|
|
|
|
def test_forward_plan_with_store_returns_leg_filter():
|
|
bridges = {
|
|
"730444": [
|
|
_row(system="MASTER-A", ts=1, tgid=730444, active=True),
|
|
_row(system="MASTER-B", ts=1, tgid=730444, active=True),
|
|
_row(system="OBP-CL", ts=1, tgid=730444, active=False),
|
|
]
|
|
}
|
|
bridge = _bridge(bridges, with_store=True)
|
|
tables, leg_keys = bridge._voice_forward_plan(
|
|
system_name="MASTER-A",
|
|
peer_id=b"\x00\x00\x03\xe9",
|
|
rf_src=b"\x00\x2f\x8b\x01",
|
|
dst_id=bytes_3(730444),
|
|
slot=1,
|
|
call_type="group",
|
|
stream_id=b"\x01\x02\x03\x04",
|
|
source_is_obp=False,
|
|
bridge_match_slot=1,
|
|
dst_int=730444,
|
|
)
|
|
assert tables == ("730444",)
|
|
assert leg_keys == frozenset({("MASTER-B", 1, 730444)})
|