ec3d4229e3
`make reindex` and `make reindex-obsidian` built a `python -c` string with backslash continuations, which kept the tab indentation inside the code, so Python failed with IndentationError. The targets now call the existing `scripts.manage_vectorstore` CLI. Its `reindex` wiped everything but only re-indexed Paperless, dropping Obsidian notes; it now indexes both, and a new `reindex-obsidian` command re-embeds only the vault. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import sys
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
|
|
from scripts import manage_vectorstore as cli
|
|
|
|
|
|
@pytest.fixture
|
|
def calls(monkeypatch):
|
|
calls = []
|
|
monkeypatch.setattr(cli, "delete_all_documents", lambda: calls.append("delete_all"))
|
|
monkeypatch.setattr(
|
|
cli,
|
|
"delete_documents_by_metadata",
|
|
lambda k, v: calls.append(f"delete {k}={v}"),
|
|
)
|
|
monkeypatch.setattr(
|
|
cli, "index_documents", AsyncMock(side_effect=lambda: calls.append("paperless"))
|
|
)
|
|
monkeypatch.setattr(
|
|
cli,
|
|
"index_obsidian_documents",
|
|
AsyncMock(side_effect=lambda: calls.append("obsidian")),
|
|
)
|
|
monkeypatch.setattr(cli, "stats", MagicMock())
|
|
return calls
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"command, expected",
|
|
[
|
|
# A full reindex must not drop Obsidian notes after wiping everything.
|
|
("reindex", ["delete_all", "paperless", "obsidian"]),
|
|
("reindex-obsidian", ["delete source=obsidian", "obsidian"]),
|
|
],
|
|
)
|
|
def test_reindex_commands(calls, monkeypatch, command, expected):
|
|
monkeypatch.setattr(sys, "argv", ["manage_vectorstore", command])
|
|
cli.main()
|
|
assert calls == expected
|