Files
resume-agent/backend/tests/test_chat_intents.py

65 lines
2.2 KiB
Python

"""Chat intent registry and classification schema tests."""
from __future__ import annotations
import pytest
from pydantic import ValidationError
from app.chat_intents import (
CHAT_INTENT_REGISTRY_VERSION,
INTENT_DESCRIPTIONS,
INTENT_FEWSHOTS,
ChatIntent,
ChatTurnClassification,
ExtractedFact,
)
def test_registry_describes_every_intent_in_chinese() -> None:
assert CHAT_INTENT_REGISTRY_VERSION
assert set(INTENT_DESCRIPTIONS) == set(ChatIntent)
for intent, description in INTENT_DESCRIPTIONS.items():
assert description.strip(), intent
assert any("一" <= char <= "鿿" for char in description), intent
def test_fewshots_cover_each_intent_and_use_known_intents() -> None:
covered = {example["intent"] for example in INTENT_FEWSHOTS}
assert covered == set(ChatIntent)
for example in INTENT_FEWSHOTS:
assert example["message"].strip()
assert isinstance(example["intent"], ChatIntent)
def test_classification_schema_accepts_a_full_payload() -> None:
parsed = ChatTurnClassification(
intent="provide_facts",
confidence=0.9,
target_section="project_experience",
target_entry_hint="AI Career Copilot",
facts=[{"text": "负责后端接口开发", "kind": "action"}],
identity_updates=None,
revision_instruction=None,
user_question=None,
reason="用户在补充项目事实",
)
assert parsed.intent is ChatIntent.PROVIDE_FACTS
assert parsed.facts[0].kind == "action"
def test_classification_schema_defaults_and_rejects_extras() -> None:
minimal = ChatTurnClassification(intent="chitchat")
assert minimal.confidence == 0.5
assert minimal.facts == []
assert minimal.target_section is None
with pytest.raises(ValidationError):
ChatTurnClassification(intent="chitchat", bogus_field=1)
with pytest.raises(ValidationError):
ChatTurnClassification(intent="not_an_intent")
with pytest.raises(ValidationError):
ChatTurnClassification(intent="chitchat", confidence=1.5)
def test_extracted_fact_defaults_kind_to_other() -> None:
assert ExtractedFact(text="GPA 3.7").kind == "other"