SurfSense/surfsense_mcp/tests/test_rendering.py
DESKTOP-RTLN3BA\$punk 1fd58752a3 feat: update environment variables and enhance scraping capabilities
- Adjusted Google Maps and YouTube micro pricing in the .env.example file for better cost management.
- Introduced new environment variables for captcha solving and stealth browser hardening to improve scraping resilience.
- Removed outdated smoke test for scraper API endpoints to streamline testing.
- Enhanced anonymous chat agent's system prompt to clarify capabilities and suggest account creation for advanced features.
- Updated Reddit fetch logic to prioritize new session handling and improve resilience against IP-related issues.
- Added compacting functionality for scraper results to optimize data handling and presentation.
- Improved workspace and document management tools with clearer descriptions and enhanced functionality.
- Introduced new UI components for agent setup guidance in the web application.
2026-07-06 20:27:36 -07:00

42 lines
1.3 KiB
Python

"""Output shaping: clipping oversized text and JSON serialization."""
from __future__ import annotations
from surfsense_mcp.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]