(tmp_path)
| 245 | |
| 246 | @pytest.mark.asyncio |
| 247 | async def test_checkpoint_and_rehydrate(tmp_path) -> None: |
| 248 | store = ArtifactStore(root=tmp_path / "artifacts") |
| 249 | artifact = store.store_text( |
| 250 | "database table users has columns id, email, created_at", |
| 251 | kind="tool-result", |
| 252 | role="tool", |
| 253 | tool_name="read_schema", |
| 254 | ) |
| 255 | messages = [{"role": "system", "content": "You are coding assistant."}] |
| 256 | for i in range(18): |
| 257 | messages.append({"role": "user", "content": f"turn {i} explain the migration status in detail"}) |
| 258 | messages.append({"role": "assistant", "content": f"assistant response {i} with a lot of detail " * 20}) |
| 259 | messages.append({"role": "user", "content": f"use {artifact.id} and artifact://{artifact.id} to answer"}) |
| 260 | |
| 261 | result = await compose_messages_semantic( |
| 262 | messages, |
| 263 | store, |
| 264 | CompositionPolicy( |
| 265 | checkpoint_threshold_tokens=300, |
| 266 | checkpoint_keep_last_messages=4, |
| 267 | checkpoint_min_messages=6, |
| 268 | ), |
| 269 | semantic_compressor=FakeSemanticCompressor(), |
| 270 | session_id="sess-2", |
| 271 | request=object(), |
| 272 | ) |
| 273 | |
| 274 | assert result.checkpoint_created is True |
| 275 | assert result.rehydrated_artifacts == 1 |
| 276 | assert result.semantic_calls >= 2 |
| 277 | assert any( |
| 278 | isinstance(msg, dict) and msg.get("role") == "system" and "checkpoint artifact://" in str(msg.get("content")) |
| 279 | for msg in result.messages |
| 280 | ) |
| 281 | latest_user = next(msg for msg in reversed(result.messages) if msg.get("role") == "user") |
| 282 | assert "Rehydrated artifact://" in latest_user["content"] |
| 283 | |
| 284 | |
| 285 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected