Add source-linked inline comparison for uploaded estimates
This commit is contained in:
@@ -141,5 +141,32 @@ def test_stream_links_estimate_to_answer_before_sending_event(tmp_path, monkeypa
|
||||
assert json.loads(saved[estimate_id - 1][1])["_assistant_id"] == assistant_id
|
||||
|
||||
|
||||
def test_stream_attaches_file_comparison_to_same_answer(tmp_path, monkeypatch):
|
||||
import main
|
||||
|
||||
saved = []
|
||||
def save(_user, _tab, role, content):
|
||||
saved.append((role, content))
|
||||
return len(saved)
|
||||
monkeypatch.setattr(main, "save_message", save)
|
||||
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 stream(*_):
|
||||
yield 'event: text\ndata: {"text":"Сверка файлов"}\n\n'
|
||||
yield 'event: done\ndata: {"result":"Сверка файлов","usage":{}}\n\n'
|
||||
|
||||
monkeypatch.setattr(main, "stream_claude", stream)
|
||||
chunks = asyncio.run(_collect(main._stream_and_save("Сравни цены КА с ЛСР", "alice@x", "tab")))
|
||||
event = next(json.loads(chunk.split("data: ", 1)[1]) for chunk in chunks
|
||||
if chunk.startswith("event: file_compare"))
|
||||
assistant_id = next(i for i, (role, _) in enumerate(saved, 1) if role == "assistant")
|
||||
compare_id = next(i for i, (role, _) in enumerate(saved, 1) if role == "file_compare")
|
||||
assert event["_assistant_id"] == assistant_id
|
||||
assert event["_message_id"] == compare_id
|
||||
assert event["mode"] == "ka_lsr"
|
||||
|
||||
|
||||
async def _collect(stream):
|
||||
return [chunk async for chunk in stream]
|
||||
|
||||
Reference in New Issue
Block a user