============================= test session starts ==============================
platform darwin -- Python 3.13.9, pytest-9.1.1, pluggy-1.5.0
PySide6 6.11.1 -- Qt runtime 6.11.1 -- Qt compiled 6.11.1
rootdir: /Users/forrest/GitHub/SIF
configfile: pyproject.toml
plugins: anyio-4.12.1, mock-3.15.1, flask-1.3.0, langsmith-0.6.2, asyncio-1.3.0, qt-4.5.0, logfire-4.32.1, respx-0.23.1, cov-7.0.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 31 items / 28 deselected / 3 selected

tests/unit/cli/test_context.py FFF                                       [100%]

=================================== FAILURES ===================================
_ TestContextConfirmationMarkupLiteral.test_add_bracket_named_target_persists_and_renders_literally _

self = <tests.unit.cli.test_context.TestContextConfirmationMarkupLiteral object at 0x10b977110>
tmp_path = PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-447/test_add_bracket_named_target_0')

    def test_add_bracket_named_target_persists_and_renders_literally(self, tmp_path) -> None:
        """Create branch: a bracket-named target exits 0 with exactly one row persisted.
    
        Pre-fix reproduction: exit 1 MarkupError from the create-branch
        confirmation print inside the open transaction rolled the write
        back — zero rows persisted on every retry.
        """
        typed = str(tmp_path / "notes [/3].md")
        canonical = normalize_path(typed)
        # Guard: normalization must keep the bracket sequence intact and
        # resolve the tmp-dir spelling (macOS /tmp -> /private/tmp makes the
        # explicit canonical the only safe expectation). The file need not
        # exist on disk — normalize_path preserves non-existent tail
        # components, so this tests display, not filesystem state.
        assert normalize_path(typed) == canonical
        assert "[/3]" in canonical
    
        db_path = tmp_path / "index.db"
        db = Database(db_path)
        db.init_schema()
        db.close()
    
        result = CliRunner().invoke(
            context_add,
            ["path", typed, "my note"],
            obj={"index_path": db_path},
        )
    
>       assert result.exit_code == 0
E       assert 1 == 0
E        +  where 1 = <Result MarkupError("closing tag '[/3]' at position 155 doesn't match any open tag")>.exit_code

tests/unit/cli/test_context.py:979: AssertionError
_ TestContextConfirmationMarkupLiteral.test_readd_bracket_named_target_updates_and_renders_literally _

self = <tests.unit.cli.test_context.TestContextConfirmationMarkupLiteral object at 0x10b977250>
tmp_path = PosixPath('/private/var/folders/1q/2qhztsp1673fnqgrpblxnpd40000gn/T/pytest-of-forrest/pytest-447/test_readd_bracket_named_targe0')

    def test_readd_bracket_named_target_updates_and_renders_literally(self, tmp_path) -> None:
        """Update branch: re-adding a bracket-named canonical row refreshes content.
    
        Pre-fix reproduction: exit 1 MarkupError from the update-branch
        confirmation print rolled the content refresh back — the row still
        held "old text" after every retry.
        """
        typed = str(tmp_path / "report [/].md")
        canonical = normalize_path(typed)
        # Guard: the re-add must resolve to the seeded canonical spelling.
        assert normalize_path(typed) == canonical
        assert "[/]" in canonical
    
        db_path = tmp_path / "index.db"
        self._seed(db_path, [canonical])
    
        result = CliRunner().invoke(
            context_add,
            ["path", typed, "new text"],
            obj={"index_path": db_path},
        )
    
>       assert result.exit_code == 0
E       assert 1 == 0
E        +  where 1 = <Result MarkupError("closing tag '[/green]' at position 165 doesn't match any open tag")>.exit_code

tests/unit/cli/test_context.py:1008: AssertionError
_ TestContextConfirmationMarkupLiteral.test_remove_confirmation_renders_markup_literally _

self = <tests.unit.cli.test_context.TestContextConfirmationMarkupLiteral object at 0x10b0e2650>

    def test_remove_confirmation_renders_markup_literally(self) -> None:
        """Remove print: a bracket-bearing context id renders literally (mock lock).
    
        Context ids are uuid4 so the raw-id interpolation is unreachable
        with real ids; this locks the print pattern itself. Pre-fix
        reproduction: exit 1 MarkupError from the remove confirmation print.
        """
        mock_db = MagicMock()
        mock_db.connection = MagicMock()
        ctx_obj = {"index_path": MagicMock(exists=lambda: True)}
    
        with patch("sif.cli.commands.context.Database") as mock_db_cls:
            mock_db_cls.return_value = mock_db
            mock_repo = MagicMock()
            mock_repo.delete.return_value = True
            with patch(
                "sif.cli.commands.context.ContextRepository",
                return_value=mock_repo,
            ):
                result = CliRunner().invoke(
                    context_remove,
                    ["[/3]"],
                    obj=ctx_obj,
                )
    
>       assert result.exit_code == 0
E       assert 1 == 0
E        +  where 1 = <Result MarkupError("closing tag '[/3]' at position 16 doesn't match any open tag")>.exit_code

tests/unit/cli/test_context.py:1038: AssertionError
- generated xml file: /Users/forrest/GitHub/SIF/.planning/tmp/tdd-red-05-12-junit.xml -
=========================== short test summary info ============================
FAILED tests/unit/cli/test_context.py::TestContextConfirmationMarkupLiteral::test_add_bracket_named_target_persists_and_renders_literally
FAILED tests/unit/cli/test_context.py::TestContextConfirmationMarkupLiteral::test_readd_bracket_named_target_updates_and_renders_literally
FAILED tests/unit/cli/test_context.py::TestContextConfirmationMarkupLiteral::test_remove_confirmation_renders_markup_literally
======================= 3 failed, 28 deselected in 0.11s =======================
