WIP simplifying load/startup
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import PurePosixPath
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from personal_mcp.registry.ingest.document import MarkdownDocument
|
||||
from personal_mcp.registry.ingest.prompt import PromptFilesBundle
|
||||
from personal_mcp.registry.load import _build_prompt_record
|
||||
from personal_mcp.registry.load import load_docs_registry
|
||||
from personal_mcp.registry.load import get_docs_registry
|
||||
from personal_mcp.registry.models.registry import PromptSummaryRecord
|
||||
from tests.registry.models.test_document_validation import as_markdown
|
||||
from tests.registry.models.test_document_validation import assert_model_is_frozen
|
||||
from tests.registry.models.test_document_validation import make_markdown_document
|
||||
from tests.registry.models.test_document_validation import make_prompt_frontmatter_payload
|
||||
@@ -91,7 +93,7 @@ class TestPromptValidationGates:
|
||||
record = _build_prompt_record(bundle=bundle)
|
||||
|
||||
assert record.document_uri == "resource://prompts/initial/document"
|
||||
assert record.document_relpath == "prompts/initial/PROMPT.md"
|
||||
assert record.document_relpath == PurePosixPath("prompts/initial/PROMPT.md")
|
||||
|
||||
def test_preserves_argument_schema(self) -> None:
|
||||
"""Ensures argument metadata survives conversion unchanged."""
|
||||
@@ -114,21 +116,31 @@ class TestPromptValidationGates:
|
||||
class TestGate4GraphValidation:
|
||||
"""Gate 4: validate cross-entity identifier coherence."""
|
||||
|
||||
def test_prompt_id_collision_with_skill_id_fails(self, tmp_path) -> None:
|
||||
def test_prompt_id_collision_with_skill_id_fails(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Ensures prompt and skill ids cannot collide in published registry."""
|
||||
skill_dir = tmp_path / "skills" / "shared"
|
||||
prompt_dir = tmp_path / "prompts" / "shared"
|
||||
skill_dir.mkdir(parents=True)
|
||||
prompt_dir.mkdir(parents=True)
|
||||
|
||||
skill_frontmatter = make_skill_frontmatter_payload(skill_id="shared")
|
||||
prompt_frontmatter = make_prompt_frontmatter_payload(prompt_id="shared")
|
||||
documents = {
|
||||
PurePosixPath("skills/shared/SKILL.md"): make_markdown_document(
|
||||
"skills/shared/SKILL.md",
|
||||
frontmatter=skill_frontmatter,
|
||||
),
|
||||
PurePosixPath("prompts/shared/PROMPT.md"): make_markdown_document(
|
||||
"prompts/shared/PROMPT.md",
|
||||
frontmatter=prompt_frontmatter,
|
||||
),
|
||||
}
|
||||
|
||||
(skill_dir / "SKILL.md").write_text(as_markdown(skill_frontmatter), encoding="utf-8")
|
||||
(prompt_dir / "PROMPT.md").write_text(as_markdown(prompt_frontmatter), encoding="utf-8")
|
||||
def fake_from_root(_cls, _root):
|
||||
return documents
|
||||
|
||||
with pytest.raises(ValueError, match="prompt_id collides with existing skill_id"):
|
||||
load_docs_registry(package_anchor="personal_mcp", docs_root=str(tmp_path))
|
||||
monkeypatch.setattr(MarkdownDocument, "from_root", classmethod(fake_from_root))
|
||||
get_docs_registry.cache_clear()
|
||||
try:
|
||||
with pytest.raises(ValueError, match="prompt_id collides with existing skill_id"):
|
||||
get_docs_registry()
|
||||
finally:
|
||||
get_docs_registry.cache_clear()
|
||||
|
||||
class TestGate5ContractValidation:
|
||||
"""Gate 5: validate model_dump contract shape for API surfaces."""
|
||||
@@ -187,5 +199,4 @@ class TestPromptValidationGates:
|
||||
bundle = _make_prompt_bundle(slug="initial", frontmatter=frontmatter)
|
||||
record = _build_prompt_record(bundle=bundle)
|
||||
|
||||
with pytest.raises(ValidationError, match="Instance is frozen"):
|
||||
record.arguments["topic"].required = False
|
||||
assert_model_is_frozen(record.arguments["topic"], attr="required", value=False)
|
||||
|
||||
Reference in New Issue
Block a user