web tests
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Test package marker for intra-suite imports."""
|
||||
@@ -5,8 +5,8 @@ from pydantic import ValidationError
|
||||
|
||||
from personal_mcp.registry.ingest.prompt import PromptFilesBundle
|
||||
from personal_mcp.registry.load import _build_prompt_record
|
||||
from personal_mcp.registry.load import _to_prompt_summary
|
||||
from personal_mcp.registry.load import load_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
|
||||
@@ -154,7 +154,7 @@ class TestPromptValidationGates:
|
||||
frontmatter = make_prompt_frontmatter_payload(prompt_id="initial")
|
||||
bundle = _make_prompt_bundle(slug="initial", frontmatter=frontmatter)
|
||||
record = _build_prompt_record(bundle=bundle)
|
||||
summary = _to_prompt_summary(record)
|
||||
summary = PromptSummaryRecord.from_record(record)
|
||||
|
||||
assert summary.model_dump() == {
|
||||
"prompt_id": "initial",
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from personal_mcp.registry.models.prompt import PromptArgumentEntry
|
||||
from personal_mcp.registry.models.registry import PromptRecord
|
||||
from personal_mcp.registry.models.registry import PromptSummaryPayload
|
||||
from personal_mcp.registry.models.registry import ReferenceRecord
|
||||
from personal_mcp.registry.models.registry import SkillPatternPayload
|
||||
from personal_mcp.registry.models.registry import SkillRecord
|
||||
from personal_mcp.registry.models.registry import SkillSummaryPayload
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
|
||||
def _make_skill_record() -> SkillRecord:
|
||||
return SkillRecord(
|
||||
skill_id="demo-skill",
|
||||
name="demo-skill",
|
||||
description="demo skill",
|
||||
version="1.2.3",
|
||||
tags=("testing", "catalog"),
|
||||
capabilities=("resource://skills/demo-skill/document", "resource://catalog/skills_index"),
|
||||
depends_on=("base-skill",),
|
||||
document_uri="resource://skills/demo-skill/document",
|
||||
document_relpath="skills/demo-skill/SKILL.md",
|
||||
document_content="# demo",
|
||||
references={
|
||||
"zeta": ReferenceRecord(
|
||||
ref_id="zeta",
|
||||
uri="resource://skills/demo-skill/references/zeta",
|
||||
relpath="skills/demo-skill/references/zeta.md",
|
||||
mime_type="text/markdown",
|
||||
title="Zeta",
|
||||
content="# zeta",
|
||||
),
|
||||
"alpha": ReferenceRecord(
|
||||
ref_id="alpha",
|
||||
uri="resource://skills/demo-skill/references/alpha",
|
||||
relpath="skills/demo-skill/references/alpha.md",
|
||||
mime_type="text/markdown",
|
||||
title="Alpha",
|
||||
content="# alpha",
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _make_prompt_record() -> PromptRecord:
|
||||
return PromptRecord(
|
||||
prompt_id="demo-prompt",
|
||||
name="demo-prompt",
|
||||
description="demo prompt",
|
||||
version="0.9.0",
|
||||
tags=("testing",),
|
||||
capabilities=("resource://prompts/demo-prompt/document",),
|
||||
arguments={
|
||||
"topic": PromptArgumentEntry(
|
||||
type="string",
|
||||
required=True,
|
||||
description="topic to discuss",
|
||||
)
|
||||
},
|
||||
document_uri="resource://prompts/demo-prompt/document",
|
||||
document_relpath="prompts/demo-prompt/PROMPT.md",
|
||||
document_content="# demo",
|
||||
)
|
||||
|
||||
|
||||
def test_skill_pattern_payload_from_record_shape() -> None:
|
||||
record = _make_skill_record()
|
||||
|
||||
payload = SkillPatternPayload.from_record(record).model_dump()
|
||||
|
||||
assert payload == {
|
||||
"id": "demo-skill",
|
||||
"name": "demo-skill",
|
||||
"version": "1.2.3",
|
||||
"description": "demo skill",
|
||||
"tags": ["testing", "catalog"],
|
||||
"depends_on": ["base-skill"],
|
||||
"capabilities": ["resource://skills/demo-skill/document", "resource://catalog/skills_index"],
|
||||
"resources": ["resource://skills/demo-skill/document", "resource://catalog/skills_index"],
|
||||
}
|
||||
|
||||
|
||||
def test_skill_summary_payload_from_record_shape() -> None:
|
||||
record = _make_skill_record()
|
||||
|
||||
payload = SkillSummaryPayload.from_record(record).model_dump()
|
||||
|
||||
assert payload == {
|
||||
"id": "demo-skill",
|
||||
"name": "demo-skill",
|
||||
"description": "demo skill",
|
||||
"tags": ["testing", "catalog"],
|
||||
"capabilities": ["resource://skills/demo-skill/document", "resource://catalog/skills_index"],
|
||||
"version": "1.2.3",
|
||||
"document_uri": "resource://skills/demo-skill/document",
|
||||
"detail_uri": "resource://catalog/skills/demo-skill",
|
||||
"resources": {
|
||||
"document": "resource://skills/demo-skill/document",
|
||||
"references": [
|
||||
"resource://skills/demo-skill/references/alpha",
|
||||
"resource://skills/demo-skill/references/zeta",
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_prompt_summary_payload_from_record_shape() -> None:
|
||||
record = _make_prompt_record()
|
||||
|
||||
payload = PromptSummaryPayload.from_record(record).model_dump()
|
||||
|
||||
assert payload == {
|
||||
"id": "demo-prompt",
|
||||
"name": "demo-prompt",
|
||||
"description": "demo prompt",
|
||||
"tags": ["testing"],
|
||||
"capabilities": ["resource://prompts/demo-prompt/document"],
|
||||
"version": "0.9.0",
|
||||
"document_uri": "resource://prompts/demo-prompt/document",
|
||||
"detail_uri": "resource://catalog/prompts/demo-prompt",
|
||||
}
|
||||
@@ -8,8 +8,8 @@ from pydantic import ValidationError
|
||||
from personal_mcp.registry.ingest.document import MarkdownDocument
|
||||
from personal_mcp.registry.ingest.skill import SkillFilesBundle
|
||||
from personal_mcp.registry.load import _build_skill_record
|
||||
from personal_mcp.registry.load import _to_summary
|
||||
from personal_mcp.registry.load import load_docs_registry
|
||||
from personal_mcp.registry.models.registry import SkillSummaryRecord
|
||||
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
|
||||
@@ -168,7 +168,7 @@ class TestSkillValidationGates:
|
||||
frontmatter = make_skill_frontmatter_payload(skill_id="alpha")
|
||||
bundle = _make_skill_bundle(slug="alpha", frontmatter=frontmatter)
|
||||
record = _build_skill_record(bundle=bundle, docs_by_relpath=_docs_index(bundle))
|
||||
summary = _to_summary(record)
|
||||
summary = SkillSummaryRecord.from_record(record)
|
||||
|
||||
assert summary.model_dump() == {
|
||||
"skill_id": "alpha",
|
||||
|
||||
+10
-6
@@ -2,11 +2,10 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
from collections.abc import AsyncIterator
|
||||
from collections.abc import Iterator
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from fastapi.testclient import TestClient
|
||||
from httpx import ASGITransport
|
||||
from httpx import AsyncClient
|
||||
from mcp import ClientSession
|
||||
from mcp.client.streamable_http import streamable_http_client
|
||||
@@ -14,10 +13,15 @@ from mcp.client.streamable_http import streamable_http_client
|
||||
from personal_mcp.web.app import create_app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client() -> Iterator[TestClient]:
|
||||
"""Provides a TestClient bound to a fresh application instance."""
|
||||
with TestClient(create_app()) as test_client:
|
||||
@pytest_asyncio.fixture
|
||||
async def client() -> AsyncIterator[AsyncClient]:
|
||||
"""Provides an AsyncClient bound to a fresh application instance."""
|
||||
app = create_app()
|
||||
async with AsyncClient(
|
||||
transport=ASGITransport(app=app),
|
||||
base_url="http://testserver",
|
||||
timeout=10.0,
|
||||
) as test_client:
|
||||
yield test_client
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from httpx import AsyncClient
|
||||
from mcp import ClientSession
|
||||
|
||||
pytestmark = pytest.mark.smoke
|
||||
@@ -13,9 +13,10 @@ class TestMcpHttpEndpoints:
|
||||
class TestHealthz:
|
||||
"""Covers health endpoint smoke behavior."""
|
||||
|
||||
def test_returns_ok_payload(self, client: TestClient) -> None:
|
||||
@pytest.mark.asyncio
|
||||
async def test_returns_ok_payload(self, client: AsyncClient) -> None:
|
||||
"""Ensures GET /healthz responds with a healthy status payload."""
|
||||
response = client.get("/healthz")
|
||||
response = await client.get("/healthz")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "ok"}
|
||||
@@ -23,9 +24,10 @@ class TestMcpHttpEndpoints:
|
||||
class TestDocsRoute:
|
||||
"""Covers static docs route smoke behavior."""
|
||||
|
||||
def test_serves_docs_entrypoint(self, client: TestClient) -> None:
|
||||
@pytest.mark.asyncio
|
||||
async def test_serves_docs_entrypoint(self, client: AsyncClient) -> None:
|
||||
"""Ensures GET /docs returns the docs site entrypoint response."""
|
||||
response = client.get("/docs")
|
||||
response = await client.get("/docs")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "text/html" in response.headers["content-type"]
|
||||
@@ -36,11 +38,11 @@ class TestMcpHttpEndpoints:
|
||||
@pytest.mark.asyncio
|
||||
async def test_rejects_get_stream_without_support(
|
||||
self,
|
||||
client: TestClient,
|
||||
client: AsyncClient,
|
||||
mcp_session: ClientSession,
|
||||
) -> None:
|
||||
"""Ensures GET /mcp returns method not allowed for current transport mode."""
|
||||
response = client.get(
|
||||
response = await client.get(
|
||||
"/mcp",
|
||||
headers={"Accept": "text/event-stream"},
|
||||
)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from mcp import ClientSession
|
||||
|
||||
pytestmark = pytest.mark.smoke
|
||||
|
||||
|
||||
class TestMcpCatalogSurface:
|
||||
"""Covers smoke-level MCP catalog discovery and tool execution paths."""
|
||||
|
||||
class TestTools:
|
||||
"""Covers MCP tool-list and tool-call smoke behavior."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_lists_core_catalog_tools(self, mcp_session: ClientSession) -> None:
|
||||
"""Ensures tools/list exposes the core catalog tool names."""
|
||||
result = await mcp_session.list_tools()
|
||||
tool_names = {tool.name for tool in result.tools}
|
||||
|
||||
assert {
|
||||
"search_patterns",
|
||||
"get_pattern_by_id",
|
||||
"get_skill_document_by_id",
|
||||
"search_prompts",
|
||||
"get_prompt_by_id",
|
||||
}.issubset(tool_names)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_calls_search_patterns_tool(self, mcp_session: ClientSession) -> None:
|
||||
"""Ensures tools/call succeeds for search_patterns with basic args."""
|
||||
result = await mcp_session.call_tool(
|
||||
"search_patterns",
|
||||
{
|
||||
"query": "pytest",
|
||||
"limit": 5,
|
||||
},
|
||||
)
|
||||
|
||||
assert result.isError is False
|
||||
assert result.content
|
||||
|
||||
class TestResources:
|
||||
"""Covers MCP resource and resource-template discovery."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_lists_catalog_resources(self, mcp_session: ClientSession) -> None:
|
||||
"""Ensures resources/list exposes core catalog resource URIs."""
|
||||
result = await mcp_session.list_resources()
|
||||
resource_uris = {str(resource.uri) for resource in result.resources}
|
||||
|
||||
assert "resource://catalog/skills_index" in resource_uris
|
||||
assert "resource://catalog/prompts_index" in resource_uris
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_lists_resource_templates(self, mcp_session: ClientSession) -> None:
|
||||
"""Ensures resources/templates/list includes skills and prompt templates."""
|
||||
result = await mcp_session.list_resource_templates()
|
||||
template_uris = {template.uriTemplate for template in result.resourceTemplates}
|
||||
|
||||
assert "resource://skills/{skill_id}/document" in template_uris
|
||||
assert "resource://prompts/{prompt_id}/document" in template_uris
|
||||
|
||||
class TestPrompts:
|
||||
"""Covers MCP prompt discovery surface."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_lists_registered_prompts(self, mcp_session: ClientSession) -> None:
|
||||
"""Ensures prompts/list returns at least one registered prompt."""
|
||||
result = await mcp_session.list_prompts()
|
||||
|
||||
assert result.prompts
|
||||
Reference in New Issue
Block a user