fix(chv): _load_playwright 须返回 sync_playwright() 实例

返回函数本身则无 __enter__,真实启动路径从未跑通过(P2 假实现
掩盖;2026-11-08 构建 #8 驱动 live 抓到)。回归测试钉死该契约。
This commit is contained in:
host committed 2026-11-08 09:45:00 +00:00
1 parent eb495892e1
commit 7361b0654f
2 files changed
+27 -2

No files matched your search

+22
View File
@@ -234,6 +234,28 @@ class ScreenshotTest(unittest.TestCase):
class CdpAndStatusTest(unittest.TestCase):
def test_load_playwright_returns_context_manager(self):
# 2026-11-08 live 根因:_load_playwright 返回 sync_playwright
# 函数本身(无 __enter__),真实启动路径从未跑通过。
import sys
import types
class FakeCM:
def __enter__(self):
return self
def __exit__(self, *exc):
return False
fake_mod = types.ModuleType("playwright.sync_api")
fake_mod.sync_playwright = lambda: FakeCM()
with mock.patch.dict(sys.modules,
{"playwright.sync_api": fake_mod}):
cm = BROWSER._load_playwright()
self.assertTrue(hasattr(cm, "__enter__"))
self.assertTrue(hasattr(cm, "__exit__"))
self.assertIsInstance(cm, FakeCM)
def test_cdp_returns_websocket_url(self):
with tempfile.TemporaryDirectory() as tmp:
agent, _c, _h = _agent([FakePage()], tmp)