fix(voice): attribute provider terminal failures safely

This commit is contained in:
amirhosein mazaheri
2026-10-13 14:59:48 +03:30
parent 1139b31219
commit 15558fd850
5 changed files with 95 additions and 3 deletions
+34 -1
View File
@@ -6,7 +6,7 @@ from types import SimpleNamespace
import pytest
from tests.unit.test_realtime_phase1 import (
runner, persisted, make, input_turn, response, delta, done, until, commands,
runner, persisted, make, input_turn, response, delta, done, until, commands, terminal,
)
from tests.unit.test_realtime_repairs import Clock, without_ticker
@@ -368,3 +368,36 @@ def test_no_active_classifier_is_profile_and_signature_bounded(model, voice, acc
assert adapter.is_no_active(CAPTURED_NO_ACTIVE) is accepted
assert not adapter.is_no_active(dict(CAPTURED_NO_ACTIVE, code="other"))
assert not adapter.is_no_active(dict(CAPTURED_NO_ACTIVE, param="response_id"))
@pytest.mark.parametrize("status,details,reason", [
("failed", {"error": {"code": "server_error"}}, "PROVIDER_RESPONSE_SERVER_ERROR"),
("failed", {"error": {"code": "rate_limit_exceeded"}}, "PROVIDER_RESPONSE_RATE_LIMIT"),
("failed", {"error": {"code": "insufficient_quota"}}, "PROVIDER_RESPONSE_QUOTA"),
("incomplete", {"reason": "content_filter"}, "PROVIDER_RESPONSE_CONTENT_FILTER"),
("incomplete", {"reason": "PRIVATE_PAYLOAD"}, "PROVIDER_RESPONSE_INCOMPLETE"),
("failed", {"error": {"code": ["PRIVATE_PAYLOAD"]}}, "PROVIDER_RESPONSE_FAILED"),
("failed", {"error": {"code": "PRIVATE_PAYLOAD"}}, "PROVIDER_RESPONSE_FAILED"),
("failed", None, "PROVIDER_RESPONSE_FAILED"),
])
def test_terminal_failure_attribution_does_not_log_provider_payload(
runner, persisted, caplog, status, details, reason):
async def scenario():
runtime, transport, out = await make(SimpleNamespace(engine=None), runner, persisted)
try:
await input_turn(runtime)
await response(runtime, transport)
event = terminal(status=status)
event["response"]["status_details"] = details
event["response"]["private_text"] = "PRIVATE_PAYLOAD"
if isinstance(details, dict):
details["message"] = "PRIVATE_PAYLOAD"
await runtime.handle(event)
assert runtime.failure == "LIVE_PROVIDER_UNAVAILABLE"
assert f"reason={reason} " in caplog.text
assert f"terminal_{status}=1" in caplog.text
assert "PRIVATE_PAYLOAD" not in caplog.text
assert "PRIVATE_PAYLOAD" not in str(out)
finally:
await runtime.close()
asyncio.run(scenario())