mcaxl/tests/test_docs_loader.py
Ryan Malloy 8b3da9d729 Initial mcp-cucm-axl
Read-only MCP server for Cisco Unified CM 15 AXL — built for LLM-driven
cluster auditing, with a particular focus on the Route Plan Report:
partitions, calling search spaces, route patterns, translation patterns,
called/calling party transformations, and digit-discard instructions.

Pairs intentionally with the sibling mcp-cisco-docs server (live
cluster state + vendor docs in one LLM context).

Architecture:
  - zeep SOAP client to CUCM AXL
  - WSDL bootstrap from Cisco's axlsqltoolkit.zip (auto-extract on
    first launch; zip is gitignored, vendor-licensed)
  - SQLite response cache at ~/.cache/mcp-cucm-axl/responses/
  - Schema-grounded prompts that pull chunks from the sibling
    cisco-docs index (docs_loader.py)

Read-only by structural guarantee — never registers AXL write methods
(no executeSQLUpdate, no add*/update*/remove*/apply*/reset*/restart*
tools). SQL queries also client-side validated (sql_validator.py) to
begin with SELECT or WITH.

Tools exposed:
  Foundational: axl_version, axl_sql, axl_list_tables,
                axl_describe_table, cache_stats, cache_clear
  Route plan:   route_partitions, route_calling_search_spaces,
                route_patterns, route_inspect_pattern,
                route_lists_and_groups, route_translation_chain,
                route_digit_discard_instructions

Prompts (schema-grounded):
  route_plan_overview, investigate_pattern, audit_routing,
  cucm_sql_help

Tests cover cache, docs_loader, normalize, sql_validator, wildcard.
2026-04-25 20:29:18 -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 mcp_cucm_axl.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