fix(asterisk): update telecom route and recording fallback

This commit is contained in:
Yera All
2026-04-17 12:16:51 +05:00
parent 4adaf192fb
commit feb0ce01e2
5 changed files with 140 additions and 1 deletions
+68
View File
@@ -205,6 +205,74 @@ def test_post_json_bearer_first_falls_back_to_legacy(monkeypatch):
assert DummyClient.seen_headers[1]["X-Role"] == "admin"
def test_upload_recording_bearer_first_fallback_rewinds_file(monkeypatch, tmp_path):
recording_path = tmp_path / "call.wav"
recording_bytes = b"recording-payload"
recording_path.write_bytes(recording_bytes)
class DummyClient:
def __init__(self, **kwargs):
self.kwargs = kwargs
def __enter__(self):
return self
def __exit__(self, exc_type, exc, tb):
return False
class DummyResponse:
def raise_for_status(self):
return None
def json(self):
return {"recording_id": "rec_uploaded"}
attempts: list[dict[str, object]] = []
def _fake_request_with_bridge_auth(client, *, retry_reset=None, headers=None, files=None, **kwargs):
del client, headers, kwargs
handle = files["file"][1]
attempts.append(
{
"chunk": handle.read(),
"has_retry_reset": callable(retry_reset),
}
)
assert callable(retry_reset)
retry_reset()
attempts.append(
{
"chunk": handle.read(),
"has_retry_reset": callable(retry_reset),
}
)
return DummyResponse()
monkeypatch.setenv("ASTERISK_BRIDGE_AUTH_MODE", "bearer_first")
monkeypatch.setenv("ASTERISK_BRIDGE_AUTH_FALLBACK_LEGACY", "1")
monkeypatch.setenv("ASTERISK_BRIDGE_AUTH_USER", "ast-bridge")
monkeypatch.setenv("ASTERISK_BRIDGE_AUTH_ROLE", "admin")
monkeypatch.setenv("APP_TOKEN_SECRET", "track9-test-secret")
monkeypatch.setattr(bridge_module.httpx, "Client", DummyClient)
monkeypatch.setattr(bridge_module, "_request_with_bridge_auth", _fake_request_with_bridge_auth)
result = bridge_module._upload_recording(
local_path=recording_path,
call_id="call_upload_fallback",
interaction_id="int_upload_fallback",
source_event_id="src_upload_fallback",
file_name="call.wav",
mime_type="audio/wav",
duration_seconds=3,
)
assert result == {"recording_id": "rec_uploaded"}
assert attempts == [
{"chunk": recording_bytes, "has_retry_reset": True},
{"chunk": recording_bytes, "has_retry_reset": True},
]
def test_assign_interaction_uses_patch(monkeypatch):
class DummyResponse:
status_code = 200