testsAndMisc/python_pkg/archwiki_rag/tests/test_main_entry.py
Krzysztof kuhy Rudnicki 86565bdef6 archwiki_rag: offline semantic search over the Arch Wiki
Indexes the arch-wiki-docs dump that is already on disk and exposes it
to the knowledge-rag MCP server, so Arch questions can be asked by
symptom ("why doesn't my systemd user unit see DISPLAY under i3")
rather than by page title, with no network round-trip at query time.

The one Arch-specific MCP server in the wild fetches pages over the
network and bundles pacman operations that duplicate the local yay-mcp.
This does neither: it only searches, against a local corpus.

install.sh installs its own dependencies, wires the MCP config and
registers a pacman hook so the index follows package updates. The
generated index is machine-specific and regenerable, so it is
gitignored rather than committed.

_reindex_entry runs under the knowledge-rag interpreter, where
mcp_server is importable and this repo's packages are not. Resolving
that import with importlib.import_module states the deferral outright
instead of a function-level import statement that reads as an oversight,
and the backend failure path now re-raises as SystemExit, so the
exit-code translation is explicit rather than a swallowed exception.
Both replace lint suppressions; the package carries none.

pylint runs in its own venv, so beautifulsoup4 and markdownify are
declared there too — being in meta/requirements.txt does not make them
resolvable to the hook.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQLwdquDCNmWtvgi3Lk72J
2026-08-10 15:33:18 +02:00

23 lines
632 B
Python

"""Tests for the archwiki_rag module entry point."""
from __future__ import annotations
import runpy
import sys
from unittest.mock import MagicMock, patch
import pytest
class TestModuleEntry:
@patch("python_pkg.archwiki_rag.cli.main", return_value=0)
def test_runs_cli_main(self, mock_main: MagicMock) -> None:
with (
patch.object(sys, "argv", ["python_pkg.archwiki_rag", "sync"]),
pytest.raises(SystemExit) as excinfo,
):
runpy.run_module("python_pkg.archwiki_rag", run_name="__main__")
assert excinfo.value.code == 0
mock_main.assert_called_once()