mcaxl/tests/test_docs_loader.py
Ryan Malloy ca6956e826 Rename to mcaxl + scrub for public PyPI release
Renames the package from `mcp-cucm-axl` to `mcaxl` to fit the
operator's mc<interface> naming convention (mcusb, mcaxl, …),
and scrubs Bingham-specific defaults so the package works for
anyone, anywhere.

Rename:
  - pyproject.toml: name, scripts entry point, description
  - src/mcp_cucm_axl/ → src/mcaxl/ (git mv preserves history)
  - All Python imports updated via sed
  - Cache directory: ~/.cache/mcp-cucm-axl/ → ~/.cache/mcaxl/
  - Log prefix [mcp-cucm-axl] → [mcaxl]
  - Package version lookup: importlib.metadata.version("mcaxl")
  - .mcp.json command updated to invoke `mcaxl` script
  - All 155 tests pass under the new name (verified)

Bingham-specific scrubs:
  - docs_loader._DEFAULT_INDEX_DIR: hardcoded /home/rpm/bingham/...
    path removed; defaults to None. Operators set CISCO_DOCS_INDEX_PATH
    env var; without it, prompts gracefully degrade with a fallback
    notice instructing the LLM to use the cisco-docs MCP search_docs
    tool instead.
  - prompts/_common.docs_or_empty_msg: removed the explicit
    /home/rpm/bingham/... path from the fallback message text.
  - server.py: removed dead-code copy of _docs_or_empty_msg() that
    was leftover from before the prompts package extraction.
  - README.md: completely rewritten as a public-facing readme. Lead
    paragraph names CUCM as the target platform, install instructions
    cover uvx / pip / Claude Code MCP add. Recommends cisco-cucm-mcp
    as the operations counterpart.

PyPI metadata:
  - Initial CalVer version: 2026.04.27
  - License: MIT (LICENSE file added)
  - Project URLs: Homepage / Source / Issues / Changelog all point
    at git.supported.systems/mcp/mcaxl (newly-created Gitea repo
    in the mcp/ org for PyPI releases)
  - Classifiers: Beta / Telecommunications Industry / Topic:Telephony
  - Keywords: mcp, cisco, cucm, axl, risport, voip, sip, audit
  - sdist excludes: CLAUDE.md, .env*, axlsqltoolkit.zip, audits/,
    tests/, pytest/ruff caches. Verified clean: wheel ships only the
    mcaxl/ source tree + LICENSE + METADATA + entry_points.

CHANGELOG.md added with a 2026.04.27 initial-release entry,
documenting tool/prompt counts, structural read-only guarantees,
Hamilton review closure, live-cluster verification, and known
limitations.

Build verification:
  - `uv build` produces clean wheel + sdist
  - Wheel: 22 source files, 195KB total, no Bingham-specific files
  - Sdist excludes verified: no CLAUDE.md, no axlsqltoolkit.zip
  - Entry point: `mcaxl = mcaxl.server:main`
  - Package installs as mcaxl==2026.4.27
2026-04-27 12:53:54 -06:00

100 lines
3.2 KiB
Python

"""Tests for the docs index loader (chunk filtering for prompt enrichment)."""
import json
from pathlib import Path
import pytest
from mcaxl.docs_loader import DocsIndex
@pytest.fixture
def fake_index(tmp_path: Path) -> Path:
chunks = [
{
"id": "cucm::v15::admin::Route-Plan-Overview::0",
"text": "The route plan defines how calls are routed through the cluster.",
"heading_path": ["Route Plan Overview"],
"source_path": str(tmp_path / "fake.md"),
"product": "cucm",
"version": "v15",
"doc": "admin",
},
{
"id": "cucm::v15::admin::Translation-Patterns::0",
"text": "Translation patterns rewrite digits before routing.",
"heading_path": ["Call Routing", "Translation Patterns"],
"source_path": str(tmp_path / "fake.md"),
"product": "cucm",
"version": "v15",
"doc": "admin",
},
{
"id": "cer::v15::admin::Caller-ID::0",
"text": "Caller ID handling for emergency calls.",
"heading_path": ["Caller ID"],
"source_path": str(tmp_path / "fake.md"),
"product": "cer",
"version": "v15",
"doc": "admin",
},
]
(tmp_path / "chunks.jsonl").write_text(
"\n".join(json.dumps(c) for c in chunks)
)
(tmp_path / "index_meta.json").write_text(
json.dumps({"model_name": "test", "embedding_dim": 384, "products": ["cucm", "cer"]})
)
return tmp_path
def test_load_index(fake_index: Path):
idx = DocsIndex.load(fake_index)
assert idx is not None
assert len(idx.chunks) == 3
def test_load_missing_returns_none(tmp_path: Path):
assert DocsIndex.load(tmp_path / "nope") is None
def test_find_filters_by_product(fake_index: Path):
idx = DocsIndex.load(fake_index)
assert idx is not None
cucm_only = idx.find(["caller"], product="cucm")
assert all(c.get("doc") for c in cucm_only)
cer_only = idx.find(["caller"], product="cer")
assert any("Caller" in (c["heading_path"] or [""])[0] for c in cer_only)
def test_find_scores_heading_higher_than_text(fake_index: Path):
idx = DocsIndex.load(fake_index)
assert idx is not None
results = idx.find(["translation"], product="cucm")
assert results
# The chunk with "Translation Patterns" in heading should rank above
# any other chunk that just mentions translation incidentally
assert "Translation" in " ".join(results[0]["heading_path"] or [])
def test_find_no_matches(fake_index: Path):
idx = DocsIndex.load(fake_index)
assert idx is not None
assert idx.find(["xyzzyplugh"]) == []
def test_format_for_prompt_includes_heading_and_text(fake_index: Path):
idx = DocsIndex.load(fake_index)
assert idx is not None
chunks = idx.find(["route plan"], product="cucm")
rendered = idx.format_chunks_for_prompt(chunks)
assert "Route Plan Overview" in rendered
assert "route plan defines" in rendered.lower()
def test_format_empty_chunks(fake_index: Path):
idx = DocsIndex.load(fake_index)
assert idx is not None
rendered = idx.format_chunks_for_prompt([])
assert "No matching" in rendered