SilverElixir commited on
Commit
8da7b15
·
1 Parent(s): 221264d

Fix the status ticker passing a language code where a chat id is expected

Browse files
lumen_status.py CHANGED
@@ -8,6 +8,8 @@ import time
8
 
9
  from aiogram.types import Message
10
 
 
 
11
  log = logging.getLogger("bot")
12
 
13
  _PROGRESS_FRAMES = (".", "..", "…")
@@ -49,8 +51,7 @@ class StatusMessage:
49
 
50
  def add_done(self, key: str, **kwargs: object) -> None:
51
  """Завершённый этап отдельной строкой над текущей фразой."""
52
- import bot
53
- self._done.append(bot._t(self.lang, key, **kwargs))
54
 
55
  async def set_phase(self, key: str, *, timed: bool = False) -> None:
56
  """Смена текущей фразы с немедленной правкой, не дожидаясь тика."""
@@ -65,13 +66,12 @@ class StatusMessage:
65
  self._phase_started = time.monotonic()
66
 
67
  def _render(self, frame_idx: int) -> str:
68
- import bot
69
  lines = list(self._done)
70
  if self._timed:
71
  elapsed = max(0, int(time.monotonic() - self._phase_started))
72
- lines.append(bot._t(self.lang, self._phrase_key, sec=elapsed))
73
  else:
74
- lines.append(bot._t(self.lang, self._phrase_key) + _PROGRESS_FRAMES[frame_idx % len(_PROGRESS_FRAMES)])
75
  return "\n".join(lines)
76
 
77
  async def _tick(self) -> None:
 
8
 
9
  from aiogram.types import Message
10
 
11
+ from lumen_lang import t as _lang_t
12
+
13
  log = logging.getLogger("bot")
14
 
15
  _PROGRESS_FRAMES = (".", "..", "…")
 
51
 
52
  def add_done(self, key: str, **kwargs: object) -> None:
53
  """Завершённый этап отдельной строкой над текущей фразой."""
54
+ self._done.append(_lang_t(self.lang, key, **kwargs))
 
55
 
56
  async def set_phase(self, key: str, *, timed: bool = False) -> None:
57
  """Смена текущей фразы с немедленной правкой, не дожидаясь тика."""
 
66
  self._phase_started = time.monotonic()
67
 
68
  def _render(self, frame_idx: int) -> str:
 
69
  lines = list(self._done)
70
  if self._timed:
71
  elapsed = max(0, int(time.monotonic() - self._phase_started))
72
+ lines.append(_lang_t(self.lang, self._phrase_key, sec=elapsed))
73
  else:
74
+ lines.append(_lang_t(self.lang, self._phrase_key) + _PROGRESS_FRAMES[frame_idx % len(_PROGRESS_FRAMES)])
75
  return "\n".join(lines)
76
 
77
  async def _tick(self) -> None:
lumen_streaming.py CHANGED
@@ -14,6 +14,7 @@ from aiogram.enums import ParseMode
14
  from aiogram.types import Message
15
 
16
  from lumen_formatting import _md_to_html, _split_text_chunks
 
17
  from lumen_message_parse import _history_user_text
18
  from lumen_model_speed import (
19
  speed_key as _model_speed_key,
@@ -53,7 +54,7 @@ async def _tick_waiting_dots(placeholder: Message) -> None:
53
  elapsed = max(0, int(time.monotonic() - started))
54
  with contextlib.suppress(Exception):
55
  await bot._tg_call(
56
- placeholder.edit_text, bot._t(lang, "progress_thinking", sec=elapsed),
57
  parse_mode=None, call_timeout=15.0,
58
  )
59
  await bot._dots_sleep(bot._DOTS_TICK_SEC)
 
14
  from aiogram.types import Message
15
 
16
  from lumen_formatting import _md_to_html, _split_text_chunks
17
+ from lumen_lang import t as _lang_t
18
  from lumen_message_parse import _history_user_text
19
  from lumen_model_speed import (
20
  speed_key as _model_speed_key,
 
54
  elapsed = max(0, int(time.monotonic() - started))
55
  with contextlib.suppress(Exception):
56
  await bot._tg_call(
57
+ placeholder.edit_text, _lang_t(lang, "progress_thinking", sec=elapsed),
58
  parse_mode=None, call_timeout=15.0,
59
  )
60
  await bot._dots_sleep(bot._DOTS_TICK_SEC)
tests/test_bot_streaming.py CHANGED
@@ -713,6 +713,8 @@ def test_waiting_dots_cycles_frames_then_stops_on_cancel(monkeypatch):
713
  assert calls[1:] == [bot._DOTS_TICK_SEC] * 3
714
  assert len(placeholder.edits) == 3
715
  assert all(text.startswith("Thinking") for text, _ in placeholder.edits)
 
 
716
 
717
 
718
  def test_streaming_fast_path_shows_no_dots_frames():
 
713
  assert calls[1:] == [bot._DOTS_TICK_SEC] * 3
714
  assert len(placeholder.edits) == 3
715
  assert all(text.startswith("Thinking") for text, _ in placeholder.edits)
716
+ # Код языка не должен утечь в chat_state строковым ключом (прод 28.10.2026).
717
+ assert "en" not in bot.chat_state
718
 
719
 
720
  def test_streaming_fast_path_shows_no_dots_frames():
tests/test_lumen_status.py CHANGED
@@ -37,4 +37,7 @@ def test_status_message_renders_done_lines_and_timer(monkeypatch):
37
  text = sent.edits[-1][0]
38
  assert "Searched the web · found 5" in text
39
  assert "Thinking… 0s" in text
 
 
 
40
  bot.chat_state.pop(999900, None)
 
37
  text = sent.edits[-1][0]
38
  assert "Searched the web · found 5" in text
39
  assert "Thinking… 0s" in text
40
+ # Язык статуса — это код языка, а не chat_id: строка "en" не должна
41
+ # попасть в chat_state как ключ (прод 28.10.2026).
42
+ assert "en" not in bot.chat_state
43
  bot.chat_state.pop(999900, None)