35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from pathlib import Path
|
|
|
|
from airouter.config import Config
|
|
from airouter.session import Session
|
|
|
|
from .fake import FakeProvider, turn_text
|
|
|
|
|
|
def test_compact_replaces_context_and_keeps_backup(tmp_path: Path):
|
|
provider = FakeProvider({"main-fake": [turn_text("Сводка работы: всё сделано.")]})
|
|
config = Config()
|
|
config.orchestrator_model = "main-fake"
|
|
|
|
async def scenario():
|
|
session = Session.create(
|
|
sessions_root=tmp_path / ".airouter" / "sessions",
|
|
config=config,
|
|
provider=provider,
|
|
cwd=tmp_path,
|
|
)
|
|
session.main_messages.append({"role": "user", "content": "старая задача"})
|
|
session.main_messages.append({"role": "assistant", "content": "старый ответ"})
|
|
summary = await session.compact()
|
|
assert "Сводка" in summary
|
|
assert len(session.main_messages) == 3
|
|
assert "СЖАТЫЙ КОНТЕКСТ" in session.main_messages[1]["content"]
|
|
backups = list(session.store.dir.glob("main.messages.before-compact-*.json"))
|
|
assert len(backups) == 1
|
|
await session.close()
|
|
|
|
asyncio.run(scenario())
|