Files
LihonT/tests/test_lihon_ai_prompt.py
cheb0chik 3540ac84ea LihonT 2.3.0 (Serena): profile music, AI video dubbing, PiP & bg play, fonts, cleaner
- Shared moderated MP3 profile music (with floating mini-player and MediaSession controls, zero bubble when absent)
- AI video dubbing into Russian with burned-in ASS subtitles inside AgentChat (`services/members/dub.py`)
- Picture-in-Picture 9:16 and background audio playback (`PlayControl` + `play_patch.py`)
- System/custom .ttf fonts & emoji packs (`FontsAndEmoji`), account cleaner (`AccountCleaner`)
- Feed blacklist, muted sound restoration, OLED burn-in shift, A/B flag editor, presets, long comments
- Updated site homepage (`src/web/index.html`) for LihonT 2.3.0 Serena
2026-11-26 15:40:32 +03:00

96 lines
4.3 KiB
Python
Raw 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.
"""Tests for the Lihon identity prompt attached to every model call."""
from __future__ import annotations
import importlib.util
import json
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SPEC = importlib.util.spec_from_file_location("lihon_ai_prompt", ROOT / "apps" / "lihon-ai" / "server.py")
assert SPEC and SPEC.loader
ai = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(ai)
class IdentityPromptTests(unittest.TestCase):
def test_prompt_is_first_message(self):
messages = ai.model_messages([{"role": "user", "content": "Кто ты?"}])
self.assertEqual(messages[0]["role"], "system")
self.assertEqual(messages[1]["content"], "Кто ты?")
self.assertEqual(len(messages), 2)
def test_prompt_names_lihon_v1(self):
self.assertIn("Lihon v1", ai.SYSTEM_PROMPT)
self.assertIn("API разных нейросетей", ai.SYSTEM_PROMPT)
self.assertNotIn("Ты — GPT", ai.SYSTEM_PROMPT)
self.assertIn("```svg", ai.SYSTEM_PROMPT)
self.assertIn("```chart", ai.SYSTEM_PROMPT)
for kind in ("bar", "hbar", "pie", "donut", "line"):
self.assertIn(kind, ai.SYSTEM_PROMPT)
def test_prompt_handles_model_data_probe(self):
self.assertIn('"model_name":"Lihon v1"', ai.SYSTEM_PROMPT)
self.assertIn('"knowledge_cutoff_date":null', ai.SYSTEM_PROMPT)
self.assertIn("размышления", ai.SYSTEM_PROMPT.lower())
def test_reasoning_guard_is_present(self):
html = (ROOT / "apps" / "lihon-ai" / "static" / "index.html").read_text(encoding="utf-8")
self.assertIn("REASONING_RISK", html)
self.assertIn("isIdentityQuestion", html)
self.assertIn("Подробности скрыты", html)
self.assertIn("REASONING_SENTENCE", html)
def test_reasoning_guard_does_not_trip_on_plain_words(self):
html = (ROOT / "apps" / "lihon-ai" / "static" / "index.html").read_text(encoding="utf-8")
line = next(row for row in html.splitlines() if "var REASONING_RISK" in row)
for word in ("\\bpolicy\\b", "\\binstructions?\\b", "\\bprompt\\b", "разработчик"):
self.assertNotIn(word, line)
def test_prompt_tells_model_not_to_refuse_harmless_requests(self):
self.assertIn("Не отказывай без настоящей причины", ai.SYSTEM_PROMPT)
self.assertIn("абсурд", ai.SYSTEM_PROMPT)
def test_web_prompt_requires_sources_and_no_invented_numbers(self):
self.assertIn("Источники", ai.WEB_PROMPT)
self.assertIn("не придумывай", ai.WEB_PROMPT)
self.assertIn("【", ai.WEB_PROMPT)
self.assertIn("официальн", ai.WEB_PROMPT)
def test_page_flattens_svg_css_and_removes_citation_markers(self):
html = (ROOT / "apps" / "lihon-ai" / "static" / "index.html").read_text(encoding="utf-8")
self.assertIn("flattenSvgStyles", html)
self.assertIn("cleanCitations", html)
self.assertIn("background:#fff;color:#17171a;background-image:none", html)
def test_prompt_forbids_code_and_fake_images_for_charts(self):
self.assertIn("attachment://", ai.SYSTEM_PROMPT)
self.assertIn("matplotlib", ai.SYSTEM_PROMPT)
self.assertIn("Никакого Python", ai.SYSTEM_PROMPT)
self.assertIn("сразу выдавай блок `chart`", ai.SYSTEM_PROMPT)
def test_page_drops_fake_attachment_images(self):
html = (ROOT / "apps" / "lihon-ai" / "static" / "index.html").read_text(encoding="utf-8")
self.assertIn("attachment|file|sandbox", html)
def test_chart_example_is_valid_json(self):
start = ai.SYSTEM_PROMPT.index("```chart") + len("```chart")
end = ai.SYSTEM_PROMPT.index("```", start)
example = json.loads(ai.SYSTEM_PROMPT[start:end].strip())
self.assertIn(example["type"], ("bar", "hbar", "pie", "donut", "line"))
self.assertEqual(len(example["labels"]), len(example["values"]))
def test_prompt_does_not_replace_history(self):
history = [
{"role": "user", "content": "раз"},
{"role": "assistant", "content": "два"},
{"role": "user", "content": "три"},
]
messages = ai.model_messages(history)
self.assertEqual(messages[1:], history)
if __name__ == "__main__":
unittest.main()