fix(repair): address Copilot review on #1227
Five Copilot review issues + the Python 3.9 CI failure rolled into one follow-up: * Replace ``dict | None`` annotated assignment with a type-comment so module load doesn't evaluate PEP 604 syntax on Python 3.9 (CI red). * Drop ``mempalace repair rebuild`` — the CLI only ships ``mempalace repair`` (rebuild) and ``mempalace repair-status``. Updated all user-facing messages, docstrings, and test assertions. * Replace ``_get_client()`` in ``tool_search`` with the safe ``_refresh_vector_disabled_flag`` probe so the fallback isn't defeated by the very chromadb client load it's trying to avoid. * Short-circuit ``tool_status`` to a pure-sqlite reader (``_tool_status_via_sqlite``) when divergence is detected so wing / room counts come back without ever opening the persistent client. * Wrap the recency-window query in ``_bm25_only_via_sqlite`` with an ``id``-ordered fallback so legacy schemas missing ``created_at`` don't break BM25 search. New test covers the sqlite-status short-circuit. 1409 tests pass.
This commit is contained in:
@@ -347,7 +347,7 @@ def test_repair_status_reports_diverged(tmp_path, capsys):
|
||||
out = repair_status(palace_path=str(tmp_path))
|
||||
captured = capsys.readouterr().out
|
||||
assert "DIVERGED" in captured
|
||||
assert "mempalace repair rebuild" in captured
|
||||
assert "mempalace repair`" in captured
|
||||
assert out["drawers"]["diverged"] is True
|
||||
|
||||
|
||||
@@ -360,4 +360,32 @@ def test_repair_status_quiet_on_healthy_palace(tmp_path, capsys):
|
||||
repair_status(palace_path=str(tmp_path))
|
||||
captured = capsys.readouterr().out
|
||||
assert "DIVERGED" not in captured
|
||||
assert "mempalace repair rebuild" not in captured
|
||||
assert "Recommended" not in captured
|
||||
|
||||
|
||||
# ── tool_status sqlite fallback (#1222 short-circuit) ─────────────────
|
||||
|
||||
|
||||
def test_tool_status_via_sqlite_returns_breakdown(palace_with_drawers, monkeypatch):
|
||||
"""When _vector_disabled is set, tool_status reads counts from sqlite
|
||||
instead of opening a chromadb client."""
|
||||
from mempalace import mcp_server
|
||||
|
||||
# _config.palace_path is a read-only property; swap the whole object
|
||||
# for a tiny stand-in so we don't have to monkey with the real
|
||||
# MempalaceConfig.
|
||||
class _Cfg:
|
||||
palace_path = str(palace_with_drawers)
|
||||
|
||||
monkeypatch.setattr(mcp_server, "_config", _Cfg())
|
||||
monkeypatch.setattr(mcp_server, "_vector_disabled", True)
|
||||
monkeypatch.setattr(mcp_server, "_vector_disabled_reason", "test divergence")
|
||||
|
||||
out = mcp_server._tool_status_via_sqlite()
|
||||
assert out["vector_disabled"] is True
|
||||
assert out["vector_disabled_reason"] == "test divergence"
|
||||
assert out["total_drawers"] == 3
|
||||
# Wing breakdown comes from the seeded palace_with_drawers fixture:
|
||||
# ops×2 (incident + repair runbook), design×1 (metaphor).
|
||||
assert out["wings"].get("ops") == 2
|
||||
assert out["wings"].get("design") == 1
|
||||
|
||||
Reference in New Issue
Block a user