Files
life-echo/api/tests/test_utterance_substance.py

47 lines
1.6 KiB
Python
Raw Normal View History

"""访谈轮次「实质内容」启发式(阶段 LLM / 记忆检索门控)。"""
import pytest
from app.agents.chat import utterance_substance as us
@pytest.fixture
def heuristic_on(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
"app.agents.chat.utterance_substance.settings.chat_substantive_heuristic_enabled",
True,
)
monkeypatch.setattr(
"app.agents.chat.utterance_substance.settings.chat_substantive_min_chars",
12,
)
def test_substantive_long_sentence(heuristic_on: None) -> None:
assert us.should_run_chat_stage_memory_heavy_work(
"我在下乡插队时住在生产队仓库里,印象最深的是冬天的早晨。"
)
def test_non_substantive_ack(heuristic_on: None) -> None:
assert not us.should_run_chat_stage_memory_heavy_work("")
assert not us.should_run_chat_stage_memory_heavy_work("对对")
def test_non_substantive_meta_process(heuristic_on: None) -> None:
assert not us.should_run_chat_stage_memory_heavy_work("我回忆起了许多快忘的细节")
def test_five_char_short_substantive_not_skipped(heuristic_on: None) -> None:
"""五字短句未命中应答/元话语时不应被当成非实质(评审:旧 >=6 会误杀)。"""
assert len("我进了工厂") == 5
assert us.should_run_chat_stage_memory_heavy_work("我进了工厂")
def test_heuristic_disabled_always_true(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
"app.agents.chat.utterance_substance.settings.chat_substantive_heuristic_enabled",
False,
)
assert us.should_run_chat_stage_memory_heavy_work("")