assistant/tests/test_blocker.py

66 lines
3.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""前置阻断:按 resolution 生成不同的问句,并保证「同角色顺带办」和「找别人办」两条路不会串。"""
from __future__ import annotations
from backend.orchestrator import orchestrator as orc
class TestPrerequisiteLookup:
def test_finds_declared_prerequisite(self, business):
step = business["workflow"][1]
assert orc._prerequisite(step, "return_verification")["title"] == "返校核验"
def test_unknown_id_returns_none(self, business):
assert orc._prerequisite(business["workflow"][1], "没声明过的前置") is None
def test_step_without_prerequisites(self):
assert orc._prerequisite({"step_id": "x"}, "anything") is None
class TestBlockerQuestion:
def test_self_resolution_offers_to_do_it_now(self, business):
prereq = orc._prerequisite(business["workflow"][1], "profile_complete")
question = orc._blocker_question(prereq, "请先完善个人信息")
assert "完善个人信息" in question
assert "顺带帮你办吗" in question
assert "回复「是」" in question and "回复「否」" in question
def test_other_role_says_it_cannot_be_done_here(self, business):
prereq = orc._prerequisite(business["workflow"][1], "return_verification")
question = orc._blocker_question(prereq, "存在未返校记录")
assert "联系辅导员先完成返校核验" in question
assert "替你办不了" in question
assert "已处理" in question
# 不能给出「我顺带帮你办」的承诺:这件事要别的角色在自己的客户端做
assert "顺带帮你办吗" not in question
def test_self_resolution_without_business_id_cannot_offer_to_do_it(self):
# 声明了 self 但没给 business_id,系统里没有对应业务可跑,只能请用户自己处理
prereq = {"id": "x", "title": "补充材料", "resolution": "self"}
question = orc._blocker_question(prereq, "缺少材料")
assert "顺带帮你办吗" not in question
assert "已处理" in question
def test_undeclared_prerequisite_still_gives_the_user_a_way_out(self):
question = orc._blocker_question(None, "系统说必须先做某件事")
assert "系统说必须先做某件事" in question
assert "不在我知道的前置事项里" in question
assert "已处理" in question and "取消" in question
def test_message_from_the_page_is_always_quoted(self, business):
prereq = orc._prerequisite(business["workflow"][1], "return_verification")
assert "存在 3 条未返校记录" in orc._blocker_question(prereq, "存在 3 条未返校记录")
def test_falls_back_to_id_when_title_missing(self):
question = orc._blocker_question({"id": "return_verification", "resolution": "other_role"}, "msg")
assert "return_verification" in question
class TestPrerequisitesBlock:
def test_lists_prerequisites_for_the_prompt(self, business):
block = orc._prerequisites_block(business["workflow"][1])
assert "return_verification" in block and "profile_complete" in block
def test_step_without_prerequisites_adds_nothing(self):
assert orc._prerequisites_block({"step_id": "x"}) == ""