mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-24 01:15:24 +08:00
fix(storage): unify CAS persistence for inline images
- Externalize inline images in messages and run events before persistence - Keep snapshots, transcripts, and metadata free of inline payloads - Serialize messages after externalization to reduce peak memory usage - Preserve live messages, URL-only images, and SDK image retrieval behavior - Add regression tests for deduplication, redaction, storage failures, and serialization order
This commit is contained in:
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock
|
||||
import pytest
|
||||
|
||||
from langbot.pkg.agent.runner.run_journal import AgentRunJournal
|
||||
from langbot.pkg.storage.media import MediaCache
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -68,3 +69,21 @@ def test_event_snapshot_preserves_custom_values_and_redacts_nested_binary():
|
||||
assert saved['custom']['contents'][0]['image_base64'] is None
|
||||
assert saved['attachments'][0]['content'] is None
|
||||
assert data['custom']['contents'][0]['image_base64'] == 'secret'
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'image',
|
||||
[
|
||||
{'type': 'Image', 'base64': 'eA=='},
|
||||
{'type': 'image_base64', 'image_base64': 'eA=='},
|
||||
{'type': 'image_url', 'image_url': {'url': 'data:image/png;base64,eA=='}},
|
||||
],
|
||||
)
|
||||
def test_metadata_and_transcript_redaction_cover_all_image_encodings(image):
|
||||
content = AgentRunJournal._sanitize_content_item(image)
|
||||
event = AgentRunJournal._sanitize_event_data({'nested': [image]})
|
||||
assert not MediaCache.has_inline_images(content)
|
||||
assert not MediaCache.has_inline_images(event)
|
||||
assert content['content_redacted'] is True
|
||||
assert event['nested'][0]['content_redacted'] is True
|
||||
assert MediaCache.has_inline_images(image)
|
||||
|
||||
Reference in New Issue
Block a user