fix: resolve #7693 — Cross-script title guard rejects valid CJK+English titles

When the user writes in CJK, the title language mismatch guard now allows
Latin characters in the title as long as the title also contains CJK
characters (cjk >= 2). This permits CJK titles with borrowed English
product/technical terms (e.g. 'WeChat Pay 回调失败排查', 'Python 代码修复')
while still rejecting pure-Latin titles for CJK conversations and
unrelated scripts (Cyrillic, Arabic, etc.).

Added regression tests: test_cjk_start_mixed_cjk_latin_title_is_allowed
and test_cjk_start_pure_latin_title_still_rejected.
This commit is contained in:
Ubuntu committed 2026-09-22 22:19:26 +05:00
1 parent e168b67e42
commit c42c5b4d30
2 files changed
+43 -1

No files matched your search

@@ -71,6 +71,35 @@ def test_cjk_start_english_title_is_rejected():
assert _title_language_mismatch("如何修复这个错误问题", "Fixing the Bug") is True
def test_cjk_start_mixed_cjk_latin_title_is_allowed():
"""CJK conversations frequently embed English product/technical terms in
titles (e.g. 'WeChat Pay 回调失败排查'). As long as the title also
contains CJK characters, Latin borrowed terms should not trigger rejection.
Regression test for #7693."""
from api.streaming import _title_language_mismatch
# Pure CJK user, CJK title with English product name
assert _title_language_mismatch(
"微信支付回调一直失败怎么办", "WeChat Pay 回调失败排查"
) is False
# CJK user, CJK title with English tech term
assert _title_language_mismatch(
"如何修复这个错误问题", "Python 代码修复"
) is False
# Mixed CJK+Latin user, mixed title
assert _title_language_mismatch(
"prores raw是否能选择压缩?", "ProRes RAW 压缩选项与 BRAW 对比"
) is False
def test_cjk_start_pure_latin_title_still_rejected():
"""A purely Latin title for a CJK conversation is still a genuine drift."""
from api.streaming import _title_language_mismatch
assert _title_language_mismatch("如何修复这个错误问题", "Fixing the Bug") is True
assert _title_language_mismatch("如何修复这个错误问题", "Python Error Guide") is True
# ── regression guards: legitimate same-script titles must NOT be rejected ───
def test_english_start_english_title_allowed():