From 87ea3191d7e01387dcc5db02c485b5cc3bc6216c Mon Sep 17 00:00:00 2001 From: Curry Date: Fri, 10 Jul 2026 06:29:54 +0800 Subject: [PATCH] fix(tests): patch AsyncSessionLocal in agent-mode protocol tests test_collect_agent_mode_ws_protocol_not_implemented and test_collect_agent_mode_unknown_protocol didn't patch backend.database.AsyncSessionLocal like the sibling tests in this file, so collect()'s agent-endpoint resolution hit the real (unmigrated) DB and failed with 'no such table: browser_bindings'. Wire them to the db_engine fixture the same way test_health_check_* already does. --- tests/unit/channels/test_opencli_channel.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unit/channels/test_opencli_channel.py b/tests/unit/channels/test_opencli_channel.py index e5ea926..fae929a 100644 --- a/tests/unit/channels/test_opencli_channel.py +++ b/tests/unit/channels/test_opencli_channel.py @@ -531,7 +531,7 @@ async def test_collect_agent_mode_http_success(channel): @pytest.mark.asyncio -async def test_collect_agent_mode_ws_protocol_not_implemented(channel): +async def test_collect_agent_mode_ws_protocol_not_implemented(channel, db_engine): """Agent mode with ws protocol returns fail (not yet implemented).""" from unittest.mock import create_autospec @@ -553,6 +553,7 @@ async def test_collect_agent_mode_ws_protocol_not_implemented(channel): with ( patch("backend.browser_pool.get_pool", return_value=mock_pool), patch("backend.config.get_settings", return_value=mock_settings), + patch("backend.database.AsyncSessionLocal", _sessionmaker(db_engine)), ): result = await channel.collect( {"site": "example.com", "command": "list"}, {} @@ -563,7 +564,7 @@ async def test_collect_agent_mode_ws_protocol_not_implemented(channel): @pytest.mark.asyncio -async def test_collect_agent_mode_unknown_protocol(channel): +async def test_collect_agent_mode_unknown_protocol(channel, db_engine): """Agent mode with unknown protocol returns fail.""" from unittest.mock import create_autospec @@ -584,6 +585,7 @@ async def test_collect_agent_mode_unknown_protocol(channel): with ( patch("backend.browser_pool.get_pool", return_value=mock_pool), patch("backend.config.get_settings", return_value=mock_settings), + patch("backend.database.AsyncSessionLocal", _sessionmaker(db_engine)), ): result = await channel.collect( {"site": "example.com", "command": "list"}, {}