2026-06-08 20:05:30 -03:00
|
|
|
"""Canonical _truncate must tolerate non-string input (regression).
|
2026-06-03 00:35:54 +01:00
|
|
|
|
2026-06-08 20:05:30 -03:00
|
|
|
Originally this tested mcp_servers/_common.py's copy, which was deleted
|
|
|
|
|
since it had zero callers. Now it tests the canonical version.
|
|
|
|
|
"""
|
2026-06-03 00:35:54 +01:00
|
|
|
|
2026-06-08 20:05:30 -03:00
|
|
|
from src.tool_utils import _truncate
|
2026-06-03 00:35:54 +01:00
|
|
|
|
|
|
|
|
def test_truncate_handles_none_and_nonstring():
|
2026-06-08 20:05:30 -03:00
|
|
|
assert _truncate(None) == "" # pyright: ignore[reportArgumentType]
|
|
|
|
|
assert _truncate(12345) == "12345" # pyright: ignore[reportArgumentType]
|
2026-06-03 00:35:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_truncate_string_behaviour_unchanged():
|
2026-06-08 20:05:30 -03:00
|
|
|
assert _truncate("hello", limit=100) == "hello"
|
|
|
|
|
out = _truncate("x" * 50, limit=10)
|
2026-06-03 00:35:54 +01:00
|
|
|
assert out.startswith("x" * 10) and "truncated" in out
|