fix: multi-tab concurrency and metadata sync improvements

This commit is contained in:
liumangmang
2026-05-30 10:08:55 +08:00
parent 3ab3a5e26f
commit 5268f1119b
3 changed files with 36 additions and 6 deletions
+6
View File
@@ -12,6 +12,8 @@ def service():
def session(service):
fake_context = AsyncMock()
fake_page = AsyncMock()
# Playwright's page.on is synchronous
fake_page.on = MagicMock()
fake_page.is_closed = MagicMock(return_value=False)
fake_page.url = "https://initial.test"
fake_page.title = AsyncMock(return_value="Initial Tab")
@@ -34,6 +36,7 @@ def session(service):
@pytest.mark.asyncio
async def test_tab_capture(service, session):
new_page = AsyncMock()
new_page.on = MagicMock()
new_page.is_closed = MagicMock(return_value=False)
new_page.url = "https://new.test"
new_page.title = AsyncMock(return_value="New Tab")
@@ -42,6 +45,9 @@ async def test_tab_capture(service, session):
# Simulate page capture
service._handle_new_page(session, new_page)
# Wait for the background registration task to finish
await asyncio.sleep(0.1)
assert len(session.tabs) == 2
assert session.active_tab_id != "tab1"
new_tab_id = session.active_tab_id