Files
resume-agent/backend/tests/test_chat_intents.py
T
hypandClaude ae2d9b128d feat: builder 简历生成 + 轻度优化 + 简历导入交付副本
自内部仓库剥离深度优化与 RAG 知识库后的交付版本:
- Builder 对话式简历生成(FSM + 意图路由 LLM 兜底增强)
- 条目级轻度优化:事实覆盖门禁 + STAR/bullet 修复链,功能/简介/成果与技术栈同级保护
- 简历导入:DOCX/PDF 解析、结构归一、手机号脱敏
- PostgreSQL 运行时 + Alembic 迁移链

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-05 11:08:30 +08:00

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"