FFF.FFFFFF                                                               [100%]
=================================== FAILURES ===================================
__________ TestAliasPathResolution.test_get_by_alias_path_hits_index ___________

self = <tests.unit.cli.test_get.TestAliasPathResolution object at 0x1401ea710>
alias_documents = (PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_get_by_alias_pa..., updated_at=datetime.datetime(2026, 11, 6, 0, 51, 14, 746938, tzinfo=datetime.timezone.utc), chunks=[], metadata={})])

    def test_get_by_alias_path_hits_index(
        self, alias_documents: tuple[Path, Path, list[Document]]
    ) -> None:
        """An alias path is canonicalized to the stored real path before lookup.
    
        The ``Collection:`` header proves the index row matched — the disk
        fallback prints no collection line.
        """
        db_path, notes_alias, documents = alias_documents
    
        result = self._invoke(db_path, "get", str(notes_alias / "alpha.md"))
    
        assert result.exit_code == 0, result.output
        assert "first line" in result.output
>       assert "Collection: collection-1" in result.output
E       AssertionError: assert 'Collection: collection-1' in '/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_get_by_alias_path_hits_in0/notes_alias/alpha.md\nfirst line\nsecond line\nthird line\n'
E        +  where '/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_get_by_alias_path_hits_in0/notes_alias/alpha.md\nfirst line\nsecond line\nthird line\n' = <Result okay>.output

tests/unit/cli/test_get.py:305: AssertionError
_________ TestAliasPathResolution.test_multi_get_alias_list_and_raw_id _________

self = <tests.unit.cli.test_get.TestAliasPathResolution object at 0x1401eaad0>
alias_documents = (PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_multi_get_alias..., updated_at=datetime.datetime(2026, 11, 6, 0, 51, 14, 772216, tzinfo=datetime.timezone.utc), chunks=[], metadata={})])

    def test_multi_get_alias_list_and_raw_id(
        self, alias_documents: tuple[Path, Path, list[Document]]
    ) -> None:
        """A comma list resolves an alias path and a raw document ID together."""
        db_path, notes_alias, documents = alias_documents
    
        result = self._invoke(
            db_path, "multi-get", f"{notes_alias / 'alpha.md'},{documents[1].id}"
        )
    
        assert result.exit_code == 0, result.output
>       assert "Found 2 matching document(s)" in result.output
E       AssertionError: assert 'Found 2 matching document(s)' in 'Found 1 matching document(s)\n\n=== /private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_multi_get_alias_list_and_0/notes_real/beta.txt ===\nbeta content\n\n'
E        +  where 'Found 1 matching document(s)\n\n=== /private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_multi_get_alias_list_and_0/notes_real/beta.txt ===\nbeta content\n\n' = <Result okay>.output

tests/unit/cli/test_get.py:319: AssertionError
__________ TestAliasPathResolution.test_multi_get_alias_glob_pattern ___________

self = <tests.unit.cli.test_get.TestAliasPathResolution object at 0x140469350>
alias_documents = (PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_multi_get_alias..., updated_at=datetime.datetime(2026, 11, 6, 0, 51, 14, 791463, tzinfo=datetime.timezone.utc), chunks=[], metadata={})])

    def test_multi_get_alias_glob_pattern(
        self, alias_documents: tuple[Path, Path, list[Document]]
    ) -> None:
        """An absolute glob with a symlinked directory prefix matches stored paths."""
        db_path, notes_alias, documents = alias_documents
    
        result = self._invoke(db_path, "multi-get", str(notes_alias / "*.md"))
    
        assert result.exit_code == 0, result.output
>       assert "Found 1 matching document(s)" in result.output
E       AssertionError: assert 'Found 1 matching document(s)' in 'No documents matching pattern: /private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_multi_get_alias_glob_patt0/notes_alias/*.md\n'
E        +  where 'No documents matching pattern: /private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_multi_get_alias_glob_patt0/notes_alias/*.md\n' = <Result okay>.output

tests/unit/cli/test_get.py:332: AssertionError
___________ TestDatabaseClosure.test_get_closes_database_on_success ____________

self = <tests.unit.cli.test_get.TestDatabaseClosure object at 0x1401ea990>
alias_documents = (PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_get_closes_data..., updated_at=datetime.datetime(2026, 11, 6, 0, 51, 14, 828500, tzinfo=datetime.timezone.utc), chunks=[], metadata={})])
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x1406769c0>

    def test_get_closes_database_on_success(
        self,
        alias_documents: tuple[Path, Path, list[Document]],
        monkeypatch: pytest.MonkeyPatch,
    ) -> None:
        """Every Database constructed by get is closed after a successful run."""
        db_path, notes_alias, _documents = alias_documents
        TrackingDatabase.created.clear()
        monkeypatch.setattr("sif.cli.commands.get.Database", TrackingDatabase)
    
        result = self._invoke(db_path, "get", str(notes_alias / "alpha.md"))
    
        assert result.exit_code == 0, result.output
        assert TrackingDatabase.created, "get must construct its Database"
        for instance in TrackingDatabase.created:
>           assert instance._connection is None
E           assert <sqlite3.Connection object at 0x140745120> is None
E            +  where <sqlite3.Connection object at 0x140745120> = <tests.unit.cli.test_get.TrackingDatabase object at 0x1404b7770>._connection

tests/unit/cli/test_get.py:369: AssertionError
__________ TestDatabaseClosure.test_get_closes_database_on_exception ___________

self = <tests.unit.cli.test_get.TestDatabaseClosure object at 0x1401eac10>
alias_documents = (PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_get_closes_data..., updated_at=datetime.datetime(2026, 11, 6, 0, 51, 14, 843892, tzinfo=datetime.timezone.utc), chunks=[], metadata={})])
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x140711950>

    def test_get_closes_database_on_exception(
        self,
        alias_documents: tuple[Path, Path, list[Document]],
        monkeypatch: pytest.MonkeyPatch,
    ) -> None:
        """A repository failure still closes every Database get constructed."""
        db_path, _notes_alias, documents = alias_documents
        TrackingDatabase.created.clear()
        monkeypatch.setattr("sif.cli.commands.get.Database", TrackingDatabase)
    
        with patch.object(DocumentRepository, "get_by_id", side_effect=RuntimeError("boom")):
            result = self._invoke(db_path, "get", documents[0].id)
    
        assert result.exit_code != 0
        assert TrackingDatabase.created, "get must construct its Database"
        for instance in TrackingDatabase.created:
>           assert instance._connection is None
E           assert <sqlite3.Connection object at 0x140744220> is None
E            +  where <sqlite3.Connection object at 0x140744220> = <tests.unit.cli.test_get.TrackingDatabase object at 0x140719e50>._connection

tests/unit/cli/test_get.py:387: AssertionError
________ TestDatabaseClosure.test_multi_get_closes_database_on_success _________

self = <tests.unit.cli.test_get.TestDatabaseClosure object at 0x140469810>
alias_documents = (PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_multi_get_close..., updated_at=datetime.datetime(2026, 11, 6, 0, 51, 14, 859770, tzinfo=datetime.timezone.utc), chunks=[], metadata={})])
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x140712150>

    def test_multi_get_closes_database_on_success(
        self,
        alias_documents: tuple[Path, Path, list[Document]],
        monkeypatch: pytest.MonkeyPatch,
    ) -> None:
        """Every Database constructed by multi-get is closed after a successful run."""
        db_path, notes_alias, _documents = alias_documents
        TrackingDatabase.created.clear()
        monkeypatch.setattr("sif.cli.commands.get.Database", TrackingDatabase)
    
        result = self._invoke(db_path, "multi-get", str(notes_alias / "*.md"))
    
        assert result.exit_code == 0, result.output
        assert TrackingDatabase.created, "multi-get must construct its Database"
        for instance in TrackingDatabase.created:
>           assert instance._connection is None
E           assert <sqlite3.Connection object at 0x140746200> is None
E            +  where <sqlite3.Connection object at 0x140746200> = <tests.unit.cli.test_get.TrackingDatabase object at 0x140719f90>._connection

tests/unit/cli/test_get.py:404: AssertionError
_______ TestDatabaseClosure.test_multi_get_closes_database_on_exception ________

self = <tests.unit.cli.test_get.TestDatabaseClosure object at 0x1404695b0>
alias_documents = (PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_multi_get_close..., updated_at=datetime.datetime(2026, 11, 6, 0, 51, 14, 878873, tzinfo=datetime.timezone.utc), chunks=[], metadata={})])
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x140746990>

    def test_multi_get_closes_database_on_exception(
        self,
        alias_documents: tuple[Path, Path, list[Document]],
        monkeypatch: pytest.MonkeyPatch,
    ) -> None:
        """A repository failure still closes every Database multi-get constructed."""
        db_path, _notes_alias, documents = alias_documents
        TrackingDatabase.created.clear()
        monkeypatch.setattr("sif.cli.commands.get.Database", TrackingDatabase)
    
        with patch.object(DocumentRepository, "get_by_id", side_effect=RuntimeError("boom")):
            result = self._invoke(db_path, "multi-get", documents[0].id)
    
        assert result.exit_code != 0
        assert TrackingDatabase.created, "multi-get must construct its Database"
        for instance in TrackingDatabase.created:
>           assert instance._connection is None
E           assert <sqlite3.Connection object at 0x140746e30> is None
E            +  where <sqlite3.Connection object at 0x140746e30> = <tests.unit.cli.test_get.TrackingDatabase object at 0x14073cfc0>._connection

tests/unit/cli/test_get.py:422: AssertionError
___________________ test_get_document_alias_path_normalized ____________________

backend = <sif.mcp.backend.SearchBackend object at 0x140798980>
tmp_path = PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_get_document_alias_path_n0')

    @pytest.mark.asyncio
    async def test_get_document_alias_path_normalized(backend, tmp_path: Path):
        """get_document canonicalizes a symlink-alias path before the path lookup."""
        real_dir = tmp_path / "notes_real"
        real_dir.mkdir()
        (real_dir / "a.md").write_text("hello", encoding="utf-8")
        alias_dir = tmp_path / "notes_alias"
        os.symlink(real_dir, alias_dir)
        alias_arg = str(alias_dir / "a.md")
    
        mock_doc = MagicMock()
        mock_doc.id = "doc1"
        mock_doc.path = str(real_dir / "a.md")
        mock_doc.title = "Test"
        mock_doc.content = "Hello"
        mock_doc.metadata = {}
        mock_doc.collection_id = "coll1"
    
        with (
            patch("sif.mcp.backend.DocumentRepository") as mock_repo,
            patch("sif.mcp.backend.CollectionRepository") as mock_coll_repo,
        ):
            mock_repo.return_value.get_by_id.return_value = None
            mock_repo.return_value.get_by_path.return_value = mock_doc
            mock_coll_repo.return_value.list_all.return_value = [MagicMock(id="coll1")]
            result = await backend.get_document(alias_arg)
    
        assert result is not None
        assert result.doc_id == "doc1"
        get_by_path_args = mock_repo.return_value.get_by_path.call_args.args
>       assert get_by_path_args[0] == normalize_path(alias_arg)
E       AssertionError: assert '/private/var...es_alias/a.md' == '/private/var...tes_real/a.md'
E         
E         Skipping 114 identical leading characters in diff, use -v to show
E         - _n0/notes_real/a.md
E         ?           --
E         + _n0/notes_alias/a.md
E         ?             +++

tests/unit/mcp/test_backend.py:218: AssertionError
------------------------------ Captured log setup ------------------------------
WARNING  sif.sif.mcp.backend:backend.py:61 Failed to load embedder; vector search will be unavailable
__________________ test_get_documents_by_pattern_alias_prefix __________________

backend = <sif.mcp.backend.SearchBackend object at 0x1401eb750>
tmp_path = PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-367/test_get_documents_by_pattern_0')

    @pytest.mark.asyncio
    async def test_get_documents_by_pattern_alias_prefix(backend, tmp_path: Path):
        """A glob whose directory prefix is a symlink alias matches stored real paths."""
        real_dir = tmp_path / "notes_real"
        real_dir.mkdir()
        (real_dir / "a.md").write_text("hello", encoding="utf-8")
        alias_dir = tmp_path / "notes_alias"
        os.symlink(real_dir, alias_dir)
    
        mock_doc = MagicMock()
        mock_doc.id = "doc1"
        mock_doc.path = str(real_dir / "a.md")
        mock_doc.filename = "a.md"
        mock_doc.title = "Test"
        mock_doc.content = "Hello"
        mock_doc.metadata = {}
        mock_doc.collection_id = "coll1"
    
        with (
            patch("sif.mcp.backend.CollectionRepository") as mock_coll_repo,
            patch("sif.mcp.backend.DocumentRepository") as mock_doc_repo,
        ):
            mock_coll_repo.return_value.list_all.return_value = [MagicMock(id="coll1")]
            mock_doc_repo.return_value.list_by_collection.return_value = [mock_doc]
            docs, errors = await backend.get_documents_by_pattern(str(alias_dir / "*.md"))
    
>       assert len(docs) == 1
E       assert 0 == 1
E        +  where 0 = len([])

tests/unit/mcp/test_backend.py:248: AssertionError
------------------------------ Captured log setup ------------------------------
WARNING  sif.sif.mcp.backend:backend.py:61 Failed to load embedder; vector search will be unavailable
=========================== short test summary info ============================
FAILED tests/unit/cli/test_get.py::TestAliasPathResolution::test_get_by_alias_path_hits_index
FAILED tests/unit/cli/test_get.py::TestAliasPathResolution::test_multi_get_alias_list_and_raw_id
FAILED tests/unit/cli/test_get.py::TestAliasPathResolution::test_multi_get_alias_glob_pattern
FAILED tests/unit/cli/test_get.py::TestDatabaseClosure::test_get_closes_database_on_success
FAILED tests/unit/cli/test_get.py::TestDatabaseClosure::test_get_closes_database_on_exception
FAILED tests/unit/cli/test_get.py::TestDatabaseClosure::test_multi_get_closes_database_on_success
FAILED tests/unit/cli/test_get.py::TestDatabaseClosure::test_multi_get_closes_database_on_exception
FAILED tests/unit/mcp/test_backend.py::test_get_document_alias_path_normalized
FAILED tests/unit/mcp/test_backend.py::test_get_documents_by_pattern_alias_prefix
9 failed, 1 passed in 0.77s
