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.

4.3 KB
Raw Blame
"""
Tests for note SQLAlchemy models.

Focuses on __repr__ safety when attributes are None (unsaved/pre-flush
instances) and basic structural checks.
"""

from local_deep_research.database.models.note import (
    NoteLink,
    NoteResearch,
    NoteSynthesis,
    NoteSynthesisSource,
    NoteVersion,
)


# ---------------------------------------------------------------------------
# NoteVersion
# ---------------------------------------------------------------------------


class TestNoteVersionRepr:
    def test_repr_with_full_document_id(self):
        obj = NoteVersion(
            id="11111111-2222-3333-4444-555555555555",
            document_id="abcdef01-1234-5678-9abc-def012345678",
            title="t",
            content="c",
            change_type="manual_save",
            content_hash="a" * 64,
        )
        result = repr(obj)
        assert "abcdef01" in result
        assert "11111111" in result

    def test_repr_with_none_document_id(self):
        """Must not raise TypeError when document_id is None (unsaved instance)."""
        obj = NoteVersion(
            id="11111111-2222-3333-4444-555555555555",
            document_id=None,
            title="t",
            content="c",
            change_type="auto_save",
            content_hash="b" * 64,
        )
        result = repr(obj)
        assert "None" in result

    def test_repr_with_short_document_id(self):
        """document_id shorter than 8 chars should not raise."""
        obj = NoteVersion(
            id="11111111-2222-3333-4444-555555555555",
            document_id="abc",
            title="t",
            content="c",
            change_type="auto_save",
            content_hash="c" * 64,
        )
        result = repr(obj)
        assert "abc" in result


# ---------------------------------------------------------------------------
# NoteLink
# ---------------------------------------------------------------------------


class TestNoteLinkRepr:
    def test_repr_with_full_ids(self):
        obj = NoteLink(
            source_document_id="src-uuid-1234-5678-9abc-def012345678",
            target_document_id="tgt-uuid-abcd-ef01-2345-678901234567",
            link_text="[[My Note]]",
        )
        result = repr(obj)
        assert "src-uuid" in result
        assert "tgt-uuid" in result

    def test_repr_with_none_source(self):
        """Must not raise TypeError when source_document_id is None."""
        obj = NoteLink(
            source_document_id=None,
            target_document_id="tgt-uuid-abcd-ef01-2345-678901234567",
            link_text="[[My Note]]",
        )
        result = repr(obj)
        assert "None" in result

    def test_repr_with_none_target(self):
        """Must not raise TypeError when target_document_id is None."""
        obj = NoteLink(
            source_document_id="src-uuid-1234-5678-9abc-def012345678",
            target_document_id=None,
            link_text="[[My Note]]",
        )
        result = repr(obj)
        assert "None" in result

    def test_repr_with_both_none(self):
        """Must not raise TypeError when both IDs are None."""
        obj = NoteLink(
            source_document_id=None,
            target_document_id=None,
            link_text="[[My Note]]",
        )
        result = repr(obj)
        assert result.count("None") == 2


# ---------------------------------------------------------------------------
# Other models — smoke tests for __repr__
# ---------------------------------------------------------------------------


class TestOtherNoteModelReprs:
    def test_note_research_repr(self):
        obj = NoteResearch(document_id="doc-id", research_id="res-id")
        result = repr(obj)
        assert "NoteResearch" in result

    def test_note_synthesis_repr(self):
        obj = NoteSynthesis(
            synthesis_type="merge",
        )
        obj.sources = [
            NoteSynthesisSource(source_document_id="a"),
            NoteSynthesisSource(source_document_id="b"),
        ]
        result = repr(obj)
        assert "merge" in result
        assert "2" in result

    def test_note_synthesis_repr_no_sources(self):
        """Empty sources list must render without raising."""
        obj = NoteSynthesis(
            synthesis_type="compare",
        )
        result = repr(obj)
        assert "compare" in result