"""Verify all 3 provider prompts are identical and contain chart-translation rules.

This is a regression test for the bug where chart titles/legends/category labels
were left untranslated because the system prompt was too ambiguous about
"proper nouns or brand names".
"""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from services.providers.deepseek_provider import DEFAULT_TRANSLATION_PROMPT as P1
from services.providers.minimax_provider import DEFAULT_TRANSLATION_PROMPT as P3
from services.providers.openai_provider import DEFAULT_TRANSLATION_PROMPT as P2

REQUIRED_PHRASES = [
    "Chart elements",
    "MUST always be translated",
    "Translate month and weekday abbreviations",
    "Jan",
    "janvier",
    "Keep ONLY real proper nouns",
    "Google, Microsoft",
    "API, URL, HTTP, JSON",
]


def test_all_prompts_identical():
    assert P1 == P2 == P3, "All 3 provider prompts must be identical"


def test_prompt_contains_required_rules():
    for phrase in REQUIRED_PHRASES:
        assert phrase in P1, f"Missing rule: {phrase!r}"


def test_prompt_drops_old_ambiguous_rule():
    # The old "If the text contains proper nouns or brand names" rule was
    # the root cause of chart labels not being translated. The new prompt
    # uses a more specific rule that lists what counts as a proper noun.
    assert "If the text contains proper nouns or brand names" not in P1, (
        "Old ambiguous rule still present — chart labels will be skipped again"
    )


if __name__ == "__main__":
    test_all_prompts_identical()
    test_prompt_contains_required_rules()
    test_prompt_drops_old_ambiguous_rule()
    print("All prompt regression tests passed.")
