chore: checkpoint current backend/runtime changes

This commit is contained in:
qzl
2026-03-06 17:28:17 +08:00
parent 2c59fe5ee2
commit b6087fd195
32 changed files with 1641 additions and 469 deletions
@@ -2,7 +2,7 @@ from __future__ import annotations
import pytest
from core.agent.infrastructure.queue.tasks import run_agent_task
from core.agent.infrastructure.queue.tasks import _build_redis_publisher, run_agent_task
class _FakeRunService:
@@ -67,3 +67,35 @@ async def test_run_agent_task_emits_error_event_on_exception() -> None:
)
assert events == ["RUN_STARTED", "RUN_ERROR"]
@pytest.mark.asyncio
async def test_run_agent_task_rejects_invalid_command() -> None:
with pytest.raises(ValueError, match="invalid command type"):
await run_agent_task({"command": "invalid", "session_id": "00000000-0000-0000-0000-000000000001"})
@pytest.mark.asyncio
async def test_run_agent_task_resume_requires_tool_call_id() -> None:
with pytest.raises(ValueError, match="tool_call_id is required"):
await run_agent_task(
{
"command": "resume",
"session_id": "00000000-0000-0000-0000-000000000001",
}
)
@pytest.mark.asyncio
async def test_build_redis_publisher_init_fail_raises_runtime_error(
monkeypatch: pytest.MonkeyPatch,
) -> None:
from core.agent.infrastructure.queue import tasks
async def _fake_get_client() -> object:
raise RuntimeError("Redis service initialization failed")
monkeypatch.setattr(tasks, "get_or_init_redis_client", _fake_get_client)
with pytest.raises(RuntimeError, match="Redis service initialization failed"):
await _build_redis_publisher()
@@ -0,0 +1,10 @@
from __future__ import annotations
from core.config.settings import Settings
def test_taskiq_uses_redis_url_by_default() -> None:
settings = Settings()
assert settings.taskiq_broker_url.startswith("redis://")
assert settings.taskiq_result_backend_url.startswith("redis://")
@@ -0,0 +1,37 @@
from __future__ import annotations
import importlib
import sys
import pytest
from core.taskiq.app import broker, bulk_broker, critical_broker, default_broker
def test_taskiq_broker_is_configured() -> None:
assert broker is not None
assert default_broker is broker
assert critical_broker is not None
assert bulk_broker is not None
def test_taskiq_app_configures_logging_on_import(
monkeypatch: pytest.MonkeyPatch,
) -> None:
sys.modules.pop("core.taskiq.app", None)
sys.modules.pop("core.taskiq", None)
called = {"count": 0, "args": None}
def _fake_configure_logging(*args: object, **__: object) -> None:
called["count"] += 1
called["args"] = args
monkeypatch.setattr("core.logging.configure_logging", _fake_configure_logging)
importlib.import_module("core.taskiq.app")
from core.config.settings import config
assert called["count"] == 1
assert called["args"] == (config,)