Live reads go through an operator proxy pool (round-robin over the newest 100 entries, cooling on connect failures, no direct fallback); stored clearances are replayed only on the exit that earned them. Identity, clearance, solver and Turnstile rungs escalate automatically. fetch_pages reads up to 12 URLs four at a time with per-item isolation. report/reports/reports_update keep a durable queue of unreadable pages for the operator. Ships a pinned multi-stage image (non-root 10001, data in /data), an ordered CI with static gates, tests on 3.12 and 3.13 at 85% coverage, an offline image smoke, and sha/latest publishing gated on main.
74 lines
3.6 KiB
Python
74 lines
3.6 KiB
Python
"""On-demand end-to-end smoke: exercise the wire protocol against public pages."""
|
|
|
|
import asyncio
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from mcp import ClientSession, StdioServerParameters
|
|
from mcp.client.stdio import stdio_client
|
|
|
|
|
|
async def main() -> None:
|
|
child = StdioServerParameters(
|
|
command=sys.executable,
|
|
args=[str(Path(__file__).with_name("server.py"))],
|
|
env={**__import__("os").environ, "MCP_LIVE_ROUTE": "direct", "MCP_SOLVE_TURNSTILE": "0"},
|
|
)
|
|
async with stdio_client(child) as streams, ClientSession(*streams) as client:
|
|
await client.initialize()
|
|
listed = await client.list_tools()
|
|
assert [t.name for t in listed.tools] == ["fetch_page", "fetch_pages"]
|
|
|
|
async def call(label: str, **args):
|
|
result = await client.call_tool("fetch_page", args)
|
|
if result.isError or result.structuredContent is None:
|
|
raise RuntimeError(f"{label}: {result.content}")
|
|
page = result.structuredContent
|
|
assert len(page["content"]) <= args.get("max_chars", 4000)
|
|
print(label, json.dumps(page, ensure_ascii=True), flush=True)
|
|
return page
|
|
|
|
example = await call("simple", url="https://example.com/", mode="text", max_chars=500)
|
|
assert example["title"] == "Example Domain"
|
|
assert "documentation examples" in example["content"] and "<html" not in example["content"].lower()
|
|
toc = await call("outline", url="https://docs.python.org/3.13/library/tomllib.html", max_chars=1200)
|
|
snapshot = toc["snapshot"]
|
|
assert "conversion table" in toc["content"].lower()
|
|
section = await call("section", snapshot=snapshot, mode="section", value="Conversion Table", max_chars=400)
|
|
assert "integer" in section["content"].lower()
|
|
more = (
|
|
await call(
|
|
"continue",
|
|
snapshot=snapshot,
|
|
mode="section",
|
|
value="Conversion Table",
|
|
offset=section["next_offset"],
|
|
max_chars=90,
|
|
)
|
|
if section["next_offset"] is not None
|
|
else None
|
|
)
|
|
assert not more or more["total_chars"] == section["total_chars"]
|
|
hit = await call("find", snapshot=snapshot, mode="find", value="parse_float", context_lines=1, max_chars=900)
|
|
assert "**@" in hit["content"] and "parse_float" in hit["content"].replace("\\_", "_")
|
|
table = await call("css", snapshot=snapshot, mode="css", value="table", max_chars=480)
|
|
assert "integer" in table["content"].lower() and "|" in table["content"]
|
|
api = await call("json-outline", url="https://pypi.org/pypi/sampleproject/4.0.0/json", max_chars=450)
|
|
fields = await call("json-field", snapshot=api["snapshot"], mode="jsonpath", value="$.urls[*].filename")
|
|
assert "sampleproject-4.0.0.tar.gz" in json.loads(fields["content"])
|
|
invalid = await client.call_tool("fetch_page", {"snapshot": "expired-example"})
|
|
assert invalid.structuredContent is not None and invalid.structuredContent["ok"] is False
|
|
assert invalid.structuredContent["error"] == "invalid"
|
|
batch = await client.call_tool(
|
|
"fetch_pages", {"urls": ["https://example.com/", "https://example.com/nope-404"]}
|
|
)
|
|
assert batch.structuredContent is not None
|
|
items = batch.structuredContent["results"]
|
|
assert batch.structuredContent["ok_count"] == 1 and items[1]["ok"] is False
|
|
print("PASS: public HTML, documentation, JSON, snapshots, batch isolation and MCP error reporting.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|