gendesign/backend/tests/services/llm/test_prompts.py
Light1YT 645b3c14a3
All checks were successful
CI / frontend-tests (push) Has been skipped
CI / changes (push) Successful in 6s
CI / frontend-tests (pull_request) Has been skipped
CI / changes (pull_request) Successful in 6s
CI / backend-tests (pull_request) Successful in 6m24s
Deploy / build-frontend (push) Has been skipped
Deploy / build-worker (push) Successful in 3m5s
Deploy / deploy (push) Successful in 1m49s
CI / backend-tests (push) Successful in 6m24s
Deploy / changes (push) Successful in 5s
Deploy / build-backend (push) Successful in 2m8s
fix(chat): clean квартирография rendering in chat_system prompt (v2, #957)
Live chat rendered the recommended unit-mix as a garbled rank-hyphen-type
list ("2-1-к", "3-2-к" = "rank 2: 1-к"). Add rule 6 to chat_system@v2:
list квартирография/segments by clean TYPE (студия / 1-к / 2-к / 3-к /
80+ м²) + share %, no ordinal-number-hyphen-type concatenation. Bumped
prompt version 1->2 (versioned-prompt convention). Test locks v2 + the rule.

Refs #957
2026-06-09 15:07:14 +05:00

60 lines
2.2 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.

"""Prompt-scaffolding tests (#960) — render, версионирование, отсутствие шаблона."""
from __future__ import annotations
import pytest
from app.services.llm.prompts import (
PromptNotFoundError,
PromptTemplate,
get_template,
render,
)
def test_get_known_template() -> None:
tpl = get_template("system_base")
assert tpl.name == "system_base"
assert tpl.version == 1
assert tpl.key == "system_base@v1"
def test_get_unknown_template_raises() -> None:
with pytest.raises(PromptNotFoundError):
get_template("does_not_exist")
def test_render_known_template() -> None:
out = render("system_base")
assert "ассистент" in out
def test_chat_system_v2_has_unit_mix_formatting_rule() -> None:
"""chat_system@v2 (#957 fix): чистый рендер квартирографии, без «N-тип» склейки."""
tpl = get_template("chat_system")
assert tpl.version == 2
assert tpl.key == "chat_system@v2"
out = render("chat_system")
assert "квартирограф" in out.lower() # правило про перечисление сегментов
assert "«2-1-к»" in out # явный анти-пример (склейка номера с типом)
# ключевые жёсткие правила сохранены
assert "НИКОГДА не выдумывай" in out
assert "ВЕРБАТИМ" in out
def test_render_with_required_vars() -> None:
"""render подставляет переменные через str.format и валидирует required_vars."""
tpl = PromptTemplate(
name="probe",
version=1,
template="zone={zone}",
required_vars=("zone",),
)
# Прямой рендер шаблона (не из реестра) — проверяем format-механику.
assert tpl.template.format(zone="Ц-1") == "zone=Ц-1"
def test_render_missing_required_var_raises() -> None:
"""Если шаблон требует переменную, а её нет → KeyError (для зарегистрированного)."""
with pytest.raises(PromptNotFoundError):
render("missing_template", zone="Ц-1")