support task-selectable SIP trunks
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import socket
|
||||
import struct
|
||||
import tempfile
|
||||
@@ -12,10 +13,12 @@ from agent_call.real_cell import (
|
||||
CellCallConfig,
|
||||
CellCallError,
|
||||
CellExecutionLedger,
|
||||
CellRoute,
|
||||
RealCellCall,
|
||||
RealCellWorker,
|
||||
RTPMedia,
|
||||
alaw_to_pcm16,
|
||||
load_cell_routes,
|
||||
voice_level,
|
||||
)
|
||||
|
||||
@@ -243,6 +246,90 @@ class RealCellTests(unittest.TestCase):
|
||||
"mka755",
|
||||
)
|
||||
|
||||
def test_route_map_binds_task_policy_to_trusted_trunk(self) -> None:
|
||||
routes = load_cell_routes(
|
||||
json.dumps(
|
||||
{
|
||||
"route-a": {
|
||||
"caller_profile_id": "caller-a",
|
||||
"trunk_id": "provider-second",
|
||||
"caller_id": "mbkq",
|
||||
"dial_prefix": "",
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
self.assertEqual(routes["route-a"].trunk_id, "provider-second")
|
||||
self.assertEqual(routes["route-a"].caller_id, "mbkq")
|
||||
with self.assertRaises(CellCallError):
|
||||
load_cell_routes(
|
||||
json.dumps(
|
||||
{
|
||||
"route-a": {
|
||||
"caller_profile_id": "caller-a",
|
||||
"trunk_id": "provider-second",
|
||||
"caller_id": "mbkq\nspoof",
|
||||
"dial_prefix": "",
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def test_worker_selects_installed_route_without_payload_sip_values(self) -> None:
|
||||
command = {
|
||||
"body": {
|
||||
"command_type": "call.execute",
|
||||
"tenant_id": "tenant-demo",
|
||||
"tenant_key": "tenant-key",
|
||||
"payload": {
|
||||
"execution_id": "exec-route-1",
|
||||
"agent_version_id": "agent_v1",
|
||||
"callee": "18625770806",
|
||||
"route_policy_id": "route-a",
|
||||
"caller_profile_id": "caller-a",
|
||||
},
|
||||
}
|
||||
}
|
||||
broker = FakeBroker([command])
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
ledger = CellExecutionLedger(Path(directory) / "ledger.sqlite3")
|
||||
fake_result = SimpleNamespace(
|
||||
as_dict=lambda: {"call_id": "call-route", "status": "failed", "turns": []}
|
||||
)
|
||||
|
||||
class FakeExecutor:
|
||||
def __init__(self) -> None:
|
||||
self.engine = SimpleNamespace(
|
||||
config={"agent_version_id": "agent_v1"}
|
||||
)
|
||||
self.calls: list[tuple[str, CellRoute | None]] = []
|
||||
|
||||
def start_authorized_call(
|
||||
self, callee: str, route: CellRoute | None = None
|
||||
) -> SimpleNamespace:
|
||||
self.calls.append((callee, route))
|
||||
return fake_result
|
||||
|
||||
fake_executor = FakeExecutor()
|
||||
worker = RealCellWorker(
|
||||
broker,
|
||||
"tenant-key",
|
||||
ledger,
|
||||
cast(RealCellCall, fake_executor),
|
||||
routes={
|
||||
"route-a": CellRoute(
|
||||
"route-a", "caller-a", "provider-second", "mbkq", ""
|
||||
)
|
||||
},
|
||||
)
|
||||
event = worker.process_once()
|
||||
if event is None:
|
||||
self.fail("worker did not publish a call.finished event")
|
||||
self.assertEqual(fake_executor.calls[0][0], "18625770806")
|
||||
selected_route = fake_executor.calls[0][1]
|
||||
assert selected_route is not None
|
||||
self.assertEqual(selected_route.trunk_id, "provider-second")
|
||||
|
||||
def test_ledger_marks_in_progress_as_in_doubt(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
ledger = CellExecutionLedger(Path(directory) / "ledger.sqlite3")
|
||||
|
||||
Reference in New Issue
Block a user