fix: stop panel description churn

This commit is contained in:
3252a8
2026-05-25 00:06:29 +03:00
parent 121f3c6ddf
commit 82cc33587c
13 changed files with 172 additions and 58 deletions
+25 -1
View File
@@ -3,7 +3,13 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "backend"))
from bot.utils.text_sanitizer import sanitize_display_name, sanitize_username, username_for_display
from bot.utils.text_sanitizer import (
looks_like_broken_panel_text,
panel_description_from_profile,
sanitize_display_name,
sanitize_username,
username_for_display,
)
def test_sanitize_username_preserves_underscore_suffixes():
@@ -22,3 +28,21 @@ def test_sanitize_username_rejects_free_form_values_instead_of_truncating():
def test_display_name_filters_still_apply_to_free_form_names():
assert sanitize_display_name("Name service") == "Name"
def test_panel_broken_text_detection_is_conservative_about_question_marks():
assert not looks_like_broken_panel_text("?")
assert not looks_like_broken_panel_text("alice??")
assert not looks_like_broken_panel_text("??? 123")
assert not looks_like_broken_panel_text("\U0001f0cf")
def test_panel_broken_text_detection_filters_replacement_garbage():
assert looks_like_broken_panel_text("????")
assert looks_like_broken_panel_text("???!")
assert looks_like_broken_panel_text("\ufffd\ufffd")
def test_panel_description_filters_only_broken_lines():
assert panel_description_from_profile("alice??", "????", "Smith") == "alice??\nSmith"
assert panel_description_from_profile(None, "????", "\ufffd\ufffd") == ""