59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
|
|
"""ASR transcript logging helpers."""
|
||
|
|
|
||
|
|
from app.core.agent_logging import asr_transcript_log_enabled, log_asr_transcript_result
|
||
|
|
|
||
|
|
|
||
|
|
def test_asr_transcript_log_enabled_in_development(
|
||
|
|
monkeypatch,
|
||
|
|
) -> None:
|
||
|
|
from app.core.config import settings
|
||
|
|
|
||
|
|
monkeypatch.setattr(settings, "app_environment", "development", raising=False)
|
||
|
|
monkeypatch.setattr(settings, "log_level", "INFO", raising=False)
|
||
|
|
assert asr_transcript_log_enabled() is True
|
||
|
|
|
||
|
|
|
||
|
|
def test_asr_transcript_log_disabled_in_production_info(
|
||
|
|
monkeypatch,
|
||
|
|
) -> None:
|
||
|
|
from app.core.config import settings
|
||
|
|
|
||
|
|
monkeypatch.setattr(settings, "app_environment", "production", raising=False)
|
||
|
|
monkeypatch.setattr(settings, "log_level", "INFO", raising=False)
|
||
|
|
assert asr_transcript_log_enabled() is False
|
||
|
|
|
||
|
|
|
||
|
|
def test_log_asr_transcript_result_emits_info(
|
||
|
|
monkeypatch,
|
||
|
|
caplog,
|
||
|
|
) -> None:
|
||
|
|
import logging
|
||
|
|
|
||
|
|
from app.core.config import settings
|
||
|
|
|
||
|
|
caplog.set_level(logging.INFO)
|
||
|
|
monkeypatch.setattr(settings, "app_environment", "development", raising=False)
|
||
|
|
|
||
|
|
class _Logger:
|
||
|
|
def info(self, msg, *args):
|
||
|
|
caplog.records.append(
|
||
|
|
logging.LogRecord(
|
||
|
|
name="test",
|
||
|
|
level=logging.INFO,
|
||
|
|
pathname="",
|
||
|
|
lineno=0,
|
||
|
|
msg=msg.format(*args) if args else msg,
|
||
|
|
args=(),
|
||
|
|
exc_info=None,
|
||
|
|
)
|
||
|
|
)
|
||
|
|
|
||
|
|
log_asr_transcript_result(
|
||
|
|
_Logger(),
|
||
|
|
text="你好世界",
|
||
|
|
conversation_id="c1",
|
||
|
|
segment_index=0,
|
||
|
|
)
|
||
|
|
messages = [r.getMessage() for r in caplog.records]
|
||
|
|
assert any("ASR 识别结果" in m and "你好世界" in m for m in messages)
|