test: 6 parallel agents — +40 test files across core, agent, translate, services, API routes, dataset_review. core 100%, agent 100%, services 100%, translate plugin mostly done. Pending: ~10 minor failures to fix
This commit is contained in:
@@ -351,4 +351,53 @@ class TestHealth:
|
||||
result = await health()
|
||||
assert result["status"] == "ok"
|
||||
# #endregion test_health
|
||||
|
||||
|
||||
# #region test_file_upload_parsing [C:2] [TYPE Function]
|
||||
# @BRIEF Test file upload branch — parse_upload called for valid small files.
|
||||
class TestFileUploadParsing:
|
||||
@pytest.mark.asyncio
|
||||
async def test_handler_parses_uploaded_file(self, mock_request, tmp_path):
|
||||
"""Valid small file triggers parse_upload and continues to stream."""
|
||||
from src.agent.app import agent_handler
|
||||
test_file = tmp_path / "test.txt"
|
||||
test_file.write_text("upload content for analysis")
|
||||
|
||||
message = {"text": "analyze", "files": [str(test_file)]}
|
||||
|
||||
with patch('src.agent.app.create_agent') as mock_create, \
|
||||
patch('src.agent.app.get_all_tools', return_value=[]), \
|
||||
patch('src.agent.app._save_conversation', AsyncMock()), \
|
||||
patch('src.agent.app.log_tool_event', AsyncMock()):
|
||||
agent = _make_agent_mock([
|
||||
{"event": "on_chat_model_stream", "data": {"chunk": MagicMock(content="result")}}
|
||||
])
|
||||
mock_create.return_value = agent
|
||||
results = [r async for r in agent_handler(message, [], mock_request, None, None)]
|
||||
assert len(results) > 0
|
||||
data = json.loads(results[0])
|
||||
assert data["metadata"]["type"] == "stream_token"
|
||||
# #endregion test_file_upload_parsing
|
||||
|
||||
|
||||
# #region test_app_main_block [C:2] [TYPE Function]
|
||||
# @BRIEF Test if __name__ == '__main__' block in app.py.
|
||||
class TestAppMainBlock:
|
||||
def test_app_main_block(self):
|
||||
"""if __name__ == '__main__' creates ChatInterface and launches."""
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
app_path = Path(__file__).parent.parent.parent / "src" / "agent" / "app.py"
|
||||
spec = importlib.util.spec_from_file_location("__main__", str(app_path))
|
||||
|
||||
mock_demo = MagicMock()
|
||||
with patch('gradio.ChatInterface') as mock_ci:
|
||||
mock_ci.return_value = mock_demo
|
||||
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
mock_demo.launch.assert_called_once()
|
||||
# #endregion test_app_main_block
|
||||
# #endregion Test.AgentChat.GradioApp
|
||||
|
||||
Reference in New Issue
Block a user