mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-15 18:19:10 +02:00
Docket provides background task execution and is now always available for all FastMCP servers. Only `enable_tasks` remains to control the SEP-1686 task protocol support. Changes: - Remove `enable_docket` setting and related validation - Docket/Worker lifecycle is always active in server lifespan - CurrentDocket and CurrentWorker dependencies work without config - Add server readiness signaling via `_started` event - Fix test timing issues with proper port probing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""Tests for the fastmcp tasks CLI."""
|
|
|
|
import pytest
|
|
|
|
from fastmcp.cli.tasks import check_distributed_backend, tasks_app
|
|
from fastmcp.utilities.tests import temporary_settings
|
|
|
|
|
|
class TestCheckDistributedBackend:
|
|
"""Test the distributed backend checker function."""
|
|
|
|
def test_succeeds_with_redis_url(self):
|
|
"""Test that it succeeds with Redis URL."""
|
|
with temporary_settings(docket__url="redis://localhost:6379/0"):
|
|
check_distributed_backend()
|
|
|
|
def test_exits_with_helpful_error_for_memory_url(self):
|
|
"""Test that it exits with helpful error for memory:// URLs."""
|
|
with temporary_settings(docket__url="memory://test-123"):
|
|
with pytest.raises(SystemExit) as exc_info:
|
|
check_distributed_backend()
|
|
|
|
assert isinstance(exc_info.value, SystemExit)
|
|
assert exc_info.value.code == 1
|
|
|
|
|
|
class TestWorkerCommand:
|
|
"""Test the worker command."""
|
|
|
|
def test_worker_command_parsing(self):
|
|
"""Test that worker command parses arguments correctly."""
|
|
command, bound, _ = tasks_app.parse_args(["worker", "server.py"])
|
|
assert command.__name__ == "worker" # type: ignore[attr-defined]
|
|
assert bound.arguments["server_spec"] == "server.py"
|
|
|
|
|
|
class TestTasksAppIntegration:
|
|
"""Test the tasks app integration."""
|
|
|
|
def test_tasks_app_exists(self):
|
|
"""Test that the tasks app is properly configured."""
|
|
assert "tasks" in tasks_app.name
|
|
assert "Docket" in tasks_app.help
|
|
|
|
def test_tasks_app_has_commands(self):
|
|
"""Test that all expected commands are registered."""
|
|
# Just verify the app exists and has the right metadata
|
|
# Detailed command testing is done in individual test classes
|
|
assert "tasks" in tasks_app.name
|
|
assert tasks_app.help
|