|
|
""" |
|
|
Test script to verify the FastMCP download fix for the Path/str mixing error. |
|
|
""" |
|
|
import os |
|
|
import sys |
|
|
from pathlib import Path |
|
|
import logging |
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent)) |
|
|
|
|
|
from utils.fastmcp_arxiv_server import ArxivFastMCPServer |
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
def test_download_paper(): |
|
|
"""Test downloading the paper that was failing: 2412.05449v1""" |
|
|
|
|
|
|
|
|
test_storage = Path("data/test_fastmcp_fix") |
|
|
test_storage.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
try: |
|
|
|
|
|
logger.info("Initializing FastMCP server...") |
|
|
server = ArxivFastMCPServer( |
|
|
storage_path=str(test_storage), |
|
|
server_port=5556, |
|
|
auto_start=False |
|
|
) |
|
|
|
|
|
|
|
|
paper_id = "2412.05449v1" |
|
|
logger.info(f"Testing download of paper {paper_id}...") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert server.storage_path == test_storage |
|
|
logger.info(f"β Storage path correctly set: {server.storage_path}") |
|
|
|
|
|
|
|
|
assert isinstance(server.storage_path, Path) |
|
|
logger.info(f"β Storage path is a Path object") |
|
|
|
|
|
|
|
|
pdf_path = server.storage_path / f"{paper_id}.pdf" |
|
|
logger.info(f"β PDF path construction works: {pdf_path}") |
|
|
|
|
|
|
|
|
pdf_path_str = str(pdf_path) |
|
|
logger.info(f"β PDF path converts to string: {pdf_path_str}") |
|
|
|
|
|
logger.info("\nβ
All structural tests passed!") |
|
|
logger.info("The fix correctly handles Path objects without mixing str/non-str types.") |
|
|
|
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
logger.error(f"β Test failed: {e}", exc_info=True) |
|
|
return False |
|
|
finally: |
|
|
|
|
|
import shutil |
|
|
if test_storage.exists(): |
|
|
shutil.rmtree(test_storage) |
|
|
logger.info("Cleaned up test storage") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
logger.info("=" * 60) |
|
|
logger.info("Testing FastMCP ArXiv Server Download Fix") |
|
|
logger.info("=" * 60) |
|
|
|
|
|
success = test_download_paper() |
|
|
|
|
|
if success: |
|
|
logger.info("\n" + "=" * 60) |
|
|
logger.info("β
FIX VERIFIED - No Path/str mixing issues detected") |
|
|
logger.info("=" * 60) |
|
|
sys.exit(0) |
|
|
else: |
|
|
logger.error("\n" + "=" * 60) |
|
|
logger.error("β FIX VERIFICATION FAILED") |
|
|
logger.error("=" * 60) |
|
|
sys.exit(1) |
|
|
|