Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.5 KB
Raw Blame
"""Tests for the shared formatting helpers."""

import pytest

from local_deep_research.utilities.formatting import short_id


class TestShortId:
    """short_id renders ids without a misleading ellipsis (#5583)."""

    def test_long_id_truncates_with_ellipsis(self):
        assert short_id("doc-raced-long") == "doc-race..."

    def test_short_id_renders_as_is(self):
        assert short_id("dockey") == "dockey"

    def test_exactly_eight_chars_gets_no_ellipsis(self):
        assert short_id("12345678") == "12345678"

    def test_nine_chars_truncates(self):
        assert short_id("123456789") == "12345678..."

    def test_empty_id_renders_as_empty(self):
        assert short_id("") == ""

    def test_uuid_shortens_to_its_first_group(self):
        assert short_id("550e8400-e29b-41d4-a716-446655440000") == (
            "550e8400..."
        )

    def test_length_counts_characters_not_bytes(self):
        assert short_id("é" * 8) == "é" * 8
        assert short_id("é" * 9) == "é" * 8 + "..."

    def test_custom_width(self):
        digest = "a" * 64
        assert short_id(digest, 12) == "a" * 12 + "..."
        assert short_id("a" * 12, 12) == "a" * 12

    @pytest.mark.parametrize("length", range(0, 20))
    def test_ellipsis_appears_exactly_when_the_id_was_cut(self, length):
        """``...`` must mean truncation, whatever the id length."""
        value = "x" * length
        rendered = short_id(value)
        if length <= 8:
            assert rendered == value
        else:
            assert rendered == "x" * 8 + "..."