From ec3b8b42ae56064e8d1abf1774863afa1086eb1c Mon Sep 17 00:00:00 2001 From: "Denis Kutuzov (Rybak27)" <64220408+R8CEH@users.noreply.github.com> Date: Wed, 3 Jun 2026 10:14:34 +0500 Subject: [PATCH] fix: auto-naming for 24h time format (#1374) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: auto-naming for 24h time format needs_auto_name() required AM/PM suffix for default frontend-generated names like 'deepseek-v4-flash 17:46:02'. Frontend uses toLocaleTimeString() which outputs 24h format in most locales — so the regex never matched and auto-naming silently skipped. Made AM/PM optional and added re.IGNORECASE for 'am'/'pm'. * test: add regression tests for needs_auto_name (24h + 12h + custom) --------- Co-authored-by: Calculator Dev --- routes/chat_helpers.py | 2 +- tests/test_chat_helpers.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/test_chat_helpers.py diff --git a/routes/chat_helpers.py b/routes/chat_helpers.py index f9e8e76..cc20036 100644 --- a/routes/chat_helpers.py +++ b/routes/chat_helpers.py @@ -121,7 +121,7 @@ def needs_auto_name(name: str) -> bool: if name.startswith("Chat:") or name == "Chat": return True # Default frontend name: "modelname HH:MM:SS AM/PM" - if re.match(r'^.+ \d{1,2}:\d{2}:\d{2}\s*(AM|PM)$', name): + if re.match(r"^.+ \d{1,2}:\d{2}:\d{2}(\s*(AM|PM))?$", name, re.IGNORECASE): return True return False diff --git a/tests/test_chat_helpers.py b/tests/test_chat_helpers.py new file mode 100644 index 0000000..f86ff26 --- /dev/null +++ b/tests/test_chat_helpers.py @@ -0,0 +1,29 @@ +import pytest +from routes.chat_helpers import needs_auto_name + + +@pytest.mark.parametrize("name,expected", [ + # 24h format (the bug this PR fixes) + ("deepseek-v4-flash 14:05:33", True), + ("qwq 17:46:02", True), + ("gemma3 23:59:59", True), + ("claude-sonnet 4 0:00:00", True), + + # 12h format (was already working) + ("deepseek-v4-flash 2:05:33 PM", True), + ("qwq 06:46:02 AM", True), + ("claude-sonnet-4 8:05:17 am", True), + + # empty / default + ("", True), + (" ", False), + ("Chat: something", True), + + # custom titles – should NOT trigger auto-naming + ("custom title", False), + ("CW Decoder for STM32", False), + ("my chat about python", False), + ("Fix the login bug", False), +]) +def test_needs_auto_name(name, expected): + assert needs_auto_name(name) == expected, f"needs_auto_name({name!r}) should be {expected}"