2026-09-10 09:23:22 +08:00
|
|
|
import asyncio
|
|
|
|
|
import sys
|
|
|
|
|
|
2026-09-09 21:55:37 +08:00
|
|
|
import pytest
|
|
|
|
|
|
2026-09-10 09:23:22 +08:00
|
|
|
if sys.platform == "win32":
|
|
|
|
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
|
|
|
|
2026-09-09 21:55:37 +08:00
|
|
|
from app.core.contracts import AgentDefinition, CoreResult, ResolvedAgentConfig
|
|
|
|
|
from app.service.agent.base import BaseAgent
|
|
|
|
|
from app.service.agent.factory import AgentFactory
|
|
|
|
|
from app.service.agent.governance import review_output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def governance():
|
|
|
|
|
class TestGovernance:
|
|
|
|
|
async def resolve(self, definition, context):
|
|
|
|
|
return ResolvedAgentConfig(config_version="test", prompt_version="test",
|
|
|
|
|
model_endpoint="test")
|
|
|
|
|
|
|
|
|
|
async def recall(self, context):
|
|
|
|
|
return ()
|
|
|
|
|
|
|
|
|
|
async def review(self, result, context, config, memories):
|
|
|
|
|
return review_output(result, context, config, memories)
|
|
|
|
|
|
|
|
|
|
return TestGovernance()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def acceptance_registry(monkeypatch, governance):
|
|
|
|
|
"""Explicit test registration; production does not silently create business Agents."""
|
|
|
|
|
class TestAgent(BaseAgent):
|
|
|
|
|
async def handle(self, request, context):
|
|
|
|
|
return CoreResult(text="test result")
|
|
|
|
|
|
|
|
|
|
definition = AgentDefinition(agent_type="customer_service", version="test",
|
|
|
|
|
allowed_roles=("customer",), allowed_portals=("api",))
|
|
|
|
|
registry = AgentFactory(governance)
|
|
|
|
|
registry.register(definition, lambda _: TestAgent(definition))
|
|
|
|
|
monkeypatch.setattr("app.service.agent_run_application_service.get_agent_factory",
|
|
|
|
|
lambda: registry)
|
|
|
|
|
return registry
|