mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 07:09:11 +02:00
73 lines
1.6 KiB
Python
73 lines
1.6 KiB
Python
"""Fresh-interpreter import guards for the default HTTP server path."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
import textwrap
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.subprocess_heavy
|
|
def test_default_http_app_does_not_load_opt_in_integrations() -> None:
|
|
script = textwrap.dedent(
|
|
"""
|
|
import sys
|
|
|
|
from fastmcp import FastMCP
|
|
|
|
server = FastMCP("HTTP import guard")
|
|
|
|
@server.tool
|
|
def echo(value: str) -> str:
|
|
return value
|
|
|
|
app = server.http_app(transport="http", stateless_http=True)
|
|
assert app is not None
|
|
|
|
forbidden = (
|
|
"fastmcp.server.event_store",
|
|
"griffe",
|
|
"jsonref",
|
|
"key_value",
|
|
"prefab_ui",
|
|
)
|
|
loaded = [
|
|
name
|
|
for name in sys.modules
|
|
if any(name == root or name.startswith(f"{root}.") for root in forbidden)
|
|
]
|
|
assert not loaded, loaded
|
|
"""
|
|
)
|
|
|
|
result = subprocess.run(
|
|
[sys.executable, "-c", script],
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
|
|
assert result.returncode == 0, result.stderr
|
|
|
|
|
|
@pytest.mark.subprocess_heavy
|
|
def test_fastmcp_server_import_does_not_load_context() -> None:
|
|
script = textwrap.dedent(
|
|
"""
|
|
import sys
|
|
|
|
from fastmcp import FastMCP
|
|
|
|
assert FastMCP is not None
|
|
assert "fastmcp.server.context" not in sys.modules
|
|
"""
|
|
)
|
|
|
|
result = subprocess.run(
|
|
[sys.executable, "-c", script],
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
|
|
assert result.returncode == 0, result.stderr
|