feat(testing): add fixed tool simulations

This commit is contained in:
Xin Wang
2026-08-26 09:36:37 +08:00
parent 26582bfb87
commit 239b9027ca
16 changed files with 1525 additions and 237 deletions
+25 -9
View File
@@ -7,7 +7,11 @@ from pipecat.processors.aggregators.llm_context import LLMContext
from services.brains import BrainRuntime, build_brain
from services.brains.base import GREETING_CONTEXT_MARKER
from services.runtime_variables import DynamicVariableStore, prepare_dynamic_config
from services.test_runs.mock_tools import MockToolExecutor, TextClientToolPort
from services.test_runs.mock_tools import (
MockToolExecutor,
TextClientToolPort,
ToolSimulationResolver,
)
from services.test_runs.text_runner import (
_TextCaptureProcessor,
_opening_speech_from_message,
@@ -16,7 +20,7 @@ from services.test_runs.text_runner import (
_wait_for_startup,
_wait_for_quiescence,
)
from test_schemas import BatchRunCreate, BatchStartupResult
from test_schemas import BatchRunCreate, BatchStartupResult, FixedToolSimulation
class FakeLLM:
@@ -154,8 +158,24 @@ class DebugAutoTestContractTests(unittest.TestCase):
"message_started",
)
def test_text_client_port_records_automatic_message_confirmation(self):
port = TextClientToolPort()
def test_text_client_port_records_configured_message_confirmation(self):
resolver = ToolSimulationResolver(
[
FixedToolSimulation.model_validate(
{
"toolId": "tool_message",
"functionName": "show_message",
"mode": "fixed",
"response": {
"outcome": "success",
"body": '{"action":"confirmed"}',
"delayMs": 0,
},
}
)
]
)
port = TextClientToolPort(resolver)
result = asyncio.run(
port.call(
@@ -230,12 +250,9 @@ class DebugAutoTestRuntimeTests(unittest.IsolatedAsyncioTestCase):
brain = build_brain(cfg)
llm = FakeLLM()
call_end = FakeCallEnd()
executor_holder = {}
def create_executor(store):
executor = MockToolExecutor(store)
executor_holder["executor"] = executor
return executor
return MockToolExecutor(store, ToolSimulationResolver([]))
await brain.setup(
cfg,
@@ -256,7 +273,6 @@ class DebugAutoTestRuntimeTests(unittest.IsolatedAsyncioTestCase):
self.assertTrue(call_end.ending)
self.assertEqual(call_end.reason, "测试完成")
self.assertEqual(params.result["action"], "ending_call")
self.assertEqual(executor_holder["executor"].unmocked_calls, [])
async def test_text_capture_keeps_runtime_records_for_auto_test_ui(self):
event = {