From 4f504805dff6be83b0292668755a7c3b3a36199c Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 18 Nov 2026 04:06:30 +1000 Subject: [PATCH] =?UTF-8?q?fix(=D0=A2=D0=A1=D0=9D):=20=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20GLM=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=20=D1=80?= =?UTF-8?q?=D0=B0=D1=81=D1=87=D1=91=D1=82=D0=BD=D1=83=D1=8E=20=D1=86=D0=B5?= =?UTF-8?q?=D0=BD=D1=83,=20=D0=B0=20=D0=BD=D0=B5=20=D0=BF=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D0=BD=D0=B0=20=D1=80=D0=B0=D1=81=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D0=B4=D0=BA=D0=B5=20current?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit calc_position отдаёт current словарём (ПЗ/ОТ/ЭМ/МАТ), а подстановка форматировала его как число: ошибка тонула в общем перехвате и человек получал «база недоступна». Теперь из словаря берётся ПЗ, в тексте названы выпуск и коэффициент; при настоящем сбое сообщение честное («справку собрать не удалось») и пишется в журнал. Co-Authored-By: Claude Code --- qa_inject.py | 16 ++++++++++++---- tests/test_tsn_qa_inject.py | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/qa_inject.py b/qa_inject.py index 7dac967..670ee26 100644 --- a/qa_inject.py +++ b/qa_inject.py @@ -19,6 +19,7 @@ GLM/Q&A-путь НЕ исполняет инструменты (function-callin """ from __future__ import annotations +import logging import re # ---------- хелперы разбора вопроса (переехали из claude_bridge_glm) ---------- @@ -994,11 +995,18 @@ def tsn_qa_inject(message: str) -> str: f"{_tsn_money(base.get('pz'))} руб. в ценах 2000 года " f"(ОТ {_tsn_money(base.get('ot'))}, ЭМ {_tsn_money(base.get('em'))}, " f"МАТ {_tsn_money(base.get('mat'))})") - if res.get("current") is not None: - out += (f"; коэффициент: {res.get('method') or ''} → расчётная текущая " - f"{_tsn_money(res['current'])} руб. Это расчёт, не официальная текущая цена.") + cur = res.get("current") + if isinstance(cur, dict): # calc_position отдаёт раскладку, а не одно число + cur = cur.get("pz") + if cur is not None: + idx = res.get("index") or {} + issue = f" (выпуск {idx.get('issue_no')}, коэффициент {_tsn_money(idx.get('value'))})" \ + if idx.get("issue_no") else "" + out += (f"; пересчёт{issue} → расчётная текущая {_tsn_money(cur)} руб. " + f"Это расчёт, не официальная текущая цена.") else: out += "; коэффициент выпуска не найден — текущую цену не называю." return out except Exception: # noqa: BLE001 — интент распознан: честный сбой вместо "" - return "База ТСН-2001 сейчас недоступна — чисел не называю." + logging.getLogger(__name__).exception("tsn_qa_inject failed") + return "Справку по ТСН-2001 собрать не удалось — чисел не называю." diff --git a/tests/test_tsn_qa_inject.py b/tests/test_tsn_qa_inject.py index 59d4226..b6ab7be 100644 --- a/tests/test_tsn_qa_inject.py +++ b/tests/test_tsn_qa_inject.py @@ -23,7 +23,8 @@ def _rate(monkeypatch): monkeypatch.setattr(tsn_calc, "calc_position", lambda code, qty=1.0, as_of=None: { "status": "ok", "code": code, "base": {"pz": 320.63, "ot": 5.79, "em": 314.84, "mat": 0.0}, - "current": 23405.99, "method": "3.1-5-1 × 73.0 (выпуск 222)", + "current": {"pz": 23405.99, "ot": 5.79, "em": 23400.2, "mat": 0.0}, + "method": "rate_index", "index": {"value": 73.0, "issue_no": "222", "quarter": 4, "year": 2026}, }) @@ -33,6 +34,7 @@ def test_moscow_rate_gives_base_and_calculated_price(monkeypatch): out = qa_inject.tsn_qa_inject("Проверь расценку 1-5-1 по Москве") assert "1-5-1" in out and "320,63" in out, out assert "2000" in out and "выпуск 222" in out, out + assert "23 405,99" in out, out assert "расчёт" in out, out assert "find_in_tsn" not in out and "mcp__" not in out, "имена инструментов в тексте"