6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""Output shaping: clipping oversized text and JSON serialization."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from mcp_server.core.rendering import clip, compact_items, to_json
|
|
|
|
|
|
def test_clip_leaves_short_text_untouched():
|
|
assert clip("short", limit=100) == "short"
|
|
|
|
|
|
def test_clip_truncates_and_marks_dropped_characters():
|
|
clipped = clip("x" * 50, limit=10)
|
|
assert clipped.startswith("x" * 10)
|
|
assert "40 more characters truncated" in clipped
|
|
|
|
|
|
def test_to_json_serializes_non_native_values():
|
|
from datetime import datetime
|
|
|
|
rendered = to_json({"at": datetime(2026, 1, 2, 3, 4, 5)})
|
|
assert "2026-01-02" in rendered
|
|
|
|
|
|
def test_compact_items_drops_html_and_excerpts_long_fields():
|
|
result = {
|
|
"items": [
|
|
{"title": "t", "body": "b" * 5_000, "html": "<p>dup</p>", "upVotes": 3}
|
|
]
|
|
}
|
|
compacted = compact_items(result, field_limit=100)
|
|
item = compacted["items"][0]
|
|
assert "html" not in item
|
|
assert len(item["body"]) < 200 and "truncated" in item["body"]
|
|
assert item["upVotes"] == 3
|
|
# original untouched
|
|
assert "html" in result["items"][0]
|
|
|
|
|
|
def test_compact_items_passes_through_non_item_results():
|
|
assert compact_items({"ok": True}) == {"ok": True}
|
|
assert compact_items([1, 2]) == [1, 2]
|