odysseus/tests/test_attachment_refs.py
pewdiepie-archdaemon cf4e240ad1
Some checks failed
CI / Focused test guidance (report-only) (push) Has been cancelled
CI / Python syntax (compileall) (push) Has been cancelled
CI / JS syntax (node --check) (push) Has been cancelled
CI / Python tests (pytest) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Container scan / hadolint (Dockerfile lint) (push) Has been cancelled
Container scan (Trivy) / Trivy (image scan, advisory) (push) Has been cancelled
Container scan (Trivy) / Trivy (image scan + SARIF upload) (push) Has been cancelled
Dependency review / dependency-review (PR gate) (push) Has been cancelled
Dependency review / pip-audit (advisory) (push) Has been cancelled
ci / docker publish / build (amd64) (push) Has been cancelled
ci / docker publish / build (arm64) (push) Has been cancelled
Secret scan / gitleaks (push) Has been cancelled
Workflow security / actionlint (push) Has been cancelled
Workflow security / zizmor (Actions SAST) (push) Has been cancelled
ci / docker publish / merge manifest + tag (push) Has been cancelled
Merge verified Odysseus fixes
2026-07-23 14:49:08 +00:00

75 lines
2.1 KiB
Python

import json
from src.attachment_refs import (
attachment_ref,
persistable_message_content,
search_index_text,
)
def test_persistable_message_content_replaces_inline_media_with_attachment_ref():
metadata = {
"attachments": [
{
"id": "abc123.png",
"name": "diagram.png",
"mime": "image/png",
"size": 42,
"checksum_sha256": "sha256-digest",
"created_at": "2026-07-09T12:00:00",
"vision": "A small architecture diagram.",
}
]
}
content = [
{"type": "text", "text": "Please inspect this."},
{
"type": "image_url",
"image_url": {"url": "data:image/png;base64," + ("A" * 5000)},
},
]
stored = persistable_message_content(content, metadata)
assert "base64" not in stored
assert "A" * 100 not in stored
assert "Please inspect this." in stored
assert "Attachment: diagram.png" in stored
assert "id=abc123.png" in stored
assert "sha256=sha256-digest" in stored
assert "A small architecture diagram." in stored
def test_search_index_text_strips_legacy_serialized_data_url_blocks():
legacy = json.dumps([
{"type": "text", "text": "Find this useful caption"},
{
"type": "image_url",
"image_url": {"url": "data:image/jpeg;base64," + ("B" * 4096)},
},
])
indexed = search_index_text(legacy)
assert indexed == "Find this useful caption\n[1 inline media payload omitted]"
def test_attachment_ref_normalizes_hash_aliases():
ref = attachment_ref({
"id": "file-id",
"original_name": "report.pdf",
"mime": "application/pdf",
"size": 99,
"hash": "abc",
"uploaded_at": "2026-07-09T12:00:00",
})
assert ref == {
"type": "attachment_ref",
"attachment_id": "file-id",
"name": "report.pdf",
"mime": "application/pdf",
"size": 99,
"checksum_sha256": "abc",
"created_at": "2026-07-09T12:00:00",
}