Guarantee local estimate follow-up and refresh external MCP docs
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""Локальная смета всегда предлагает отдельный расчёт без автоматических сумм."""
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
from estimate_followup import maybe_followup, replace_done_result
|
||||
|
||||
|
||||
def test_incomplete_local_estimate_still_asks_about_separate_costs():
|
||||
answer = "Локальная смета. Итого прямые затраты: 3,27 руб. Для НР нужен ФОТ."
|
||||
suffix = maybe_followup("Составь локальную смету на 1 м3 работ", answer)
|
||||
assert "Нужен ли отдельный расчёт" in suffix
|
||||
assert "зимних" in suffix and "НДС" in suffix
|
||||
|
||||
|
||||
def test_no_duplicate_question_or_unrelated_intervention():
|
||||
answer = "Итого по локальной смете 100 руб. Нужен ли отдельный расчёт зимних затрат?"
|
||||
assert maybe_followup("Составь локальную смету", answer) == ""
|
||||
assert maybe_followup("Составь сводный сметный расчёт", "Итого 100 руб.") == ""
|
||||
assert maybe_followup("Какая ставка НДС?", "НДС 22 %") == ""
|
||||
|
||||
|
||||
def test_done_payload_matches_streamed_and_saved_answer():
|
||||
chunk = 'event: done\ndata: {"result":"старый ответ","usage":{"output_tokens":4}}\n\n'
|
||||
updated = replace_done_result(chunk, "старый ответ\n\nВопрос")
|
||||
payload = json.loads(updated.split("data: ", 1)[1])
|
||||
assert payload["result"] == "старый ответ\n\nВопрос"
|
||||
assert payload["usage"] == {"output_tokens": 4}
|
||||
|
||||
|
||||
def test_stream_persists_question_before_done(tmp_path, monkeypatch):
|
||||
import main
|
||||
|
||||
saved = []
|
||||
monkeypatch.setattr(main, "save_message", lambda _u, _t, role, body: saved.append((role, body)))
|
||||
monkeypatch.setattr(main, "get_work_dir", lambda _u, _t: tmp_path)
|
||||
monkeypatch.setattr(main, "_work_dir_snapshot", lambda _path: {})
|
||||
monkeypatch.setattr(main, "_maybe_autotitle", lambda *_: None)
|
||||
|
||||
async def fake_stream(*_):
|
||||
yield 'event: text\ndata: {"text":"Локальная смета. Итого 100 руб."}\n\n'
|
||||
yield 'event: done\ndata: {"result":"Локальная смета. Итого 100 руб.","usage":{}}\n\n'
|
||||
|
||||
monkeypatch.setattr(main, "stream_claude", fake_stream)
|
||||
|
||||
async def run():
|
||||
return [chunk async for chunk in main._stream_and_save("Составь локальную смету", "probe@local", "tab")]
|
||||
|
||||
chunks = asyncio.run(run())
|
||||
texts = [json.loads(chunk.split("data: ", 1)[1])["text"] for chunk in chunks
|
||||
if chunk.startswith("event: text")]
|
||||
done = next(chunk for chunk in chunks if chunk.startswith("event: done"))
|
||||
done_result = json.loads(done.split("data: ", 1)[1])["result"]
|
||||
answer = next(body for role, body in saved if role == "assistant")
|
||||
assert "Нужен ли отдельный расчёт" in "".join(texts)
|
||||
assert answer == done_result == "".join(texts)
|
||||
Reference in New Issue
Block a user