from pathlib import PurePosixPath import pytest from personal_mcp.registry.models.registry import DocsRegistry from personal_mcp.registry.models.registry import PromptRecord from personal_mcp.registry.models.registry import PromptSummaryRecord from personal_mcp.registry.read import read_docs_markdown_path from personal_mcp.registry.read import read_prompt_document pytestmark = pytest.mark.unit def _make_registry() -> DocsRegistry: prompt_path = PurePosixPath("prompts/demo-prompt/PROMPT.md") index_path = PurePosixPath("index.md") prompt = PromptRecord( prompt_id="demo-prompt", name="demo-prompt", description="demo prompt", version="1.0.0", tags=("testing",), capabilities=("resource://prompts/demo-prompt/document",), arguments={}, document_uri="resource://prompts/demo-prompt/document", document_relpath=prompt_path, document_content="# prompt", ) return DocsRegistry( docs_markdown_by_path={index_path: "# index"}, docs_markdown_path_index=(index_path,), prompts_by_id={prompt.prompt_id: prompt}, prompts_in_load_order=(prompt.prompt_id,), prompts_summary_in_load_order=(PromptSummaryRecord.from_record(prompt),), tag_to_prompt_ids={"testing": (prompt.prompt_id,)}, ) def test_reads_docs_path_from_string_boundary() -> None: payload = read_docs_markdown_path(_make_registry(), "index.md") assert payload == { "uri": "resource://docs/index.md", "format": "markdown", "source_path": "docs/index.md", "content": "# index", } def test_rejects_non_posix_docs_path() -> None: with pytest.raises(ValueError, match="POSIX separators"): read_docs_markdown_path(_make_registry(), "skills\\demo\\SKILL.md") def test_serializes_record_paths_in_document_payloads() -> None: registry = _make_registry() assert read_prompt_document(registry, "demo-prompt")["source_path"] == ("docs/prompts/demo-prompt/PROMPT.md")