from __future__ import annotations from app.prompts import build_system_prompt def test_system_prompt_includes_rules_and_brand(): p = build_system_prompt("TOORX Assist") assert "TOORX Assist" in p # language is the prominent RULE #1 assert "RULE #1" in p assert "language" in p.lower() # a pinned language is forced verbatim pinned = build_system_prompt("X", language="portugués de Portugal (pt-PT)") assert "pt-PT" in pinned # anti-hallucination grounding assert "invent" in p.lower() # order verification (email + order number / postal code) assert "email" in p.lower() and "order number" in p.lower() and "postal code" in p.lower() assert "NEVER" in p # no full address / payment # tools referenced by name assert "escalate_to_human" in p assert "search_knowledge" in p and "search_products" in p and "lookup_order" in p # no emojis + don't translate identifiers assert "emoji" in p.lower() assert "variant_ids" in p def test_system_prompt_default_brand(): assert "Asistente" in build_system_prompt("") def test_prompt_channel_handoff_is_mutually_exclusive(): web = build_system_prompt("X", channel="web") wa = build_system_prompt("X", channel="whatsapp") assert "show_form" in web and "WhatsApp" not in web assert "WhatsApp" in wa and "show_form" not in wa def test_brand_name_braces_are_sanitized(): # a brand name with { } must not break .format or inject placeholders p = build_system_prompt("Acme {evil}") assert "{evil}" not in p assert "Acme" in p