"""Tests for stealth fetching and the browse agent-as-tool (offline). StealthFetcher and BrowserTools run against in-test fakes with the real surface (stealthii get/shutdown, Playwright page); run_browse_task runs against a fake browser class plus a stubbed sub-agent prompt so no Chromium or network is ever touched. """ # retoor import unittest from unittest import mock from stealthii import StealthRequestError from blackcat.agent import BlackCatBot from blackcat.browse import ( BROWSER_SCHEMAS, BROWSER_TOOLS, MAX_BROWSE_STEPS, BrowserTools, run_browse_task, ) from blackcat.client import DeepSeekError from blackcat.http import StealthFetcher class _FakeResp: def __init__(self, status=200, text="", ctype="text/html"): self.status = status self._text = text self.headers = {"content-type": ctype} async def text(self): return self._text class _FakeStealth: def __init__(self, resp=None, error=None): self.resp = resp self.error = error self.got = [] self.shutdowns = 0 async def get(self, url, headers=None, timeout=None): self.got.append(url) if self.error is not None: raise self.error return self.resp async def shutdown(self): self.shutdowns += 1 class TestStealthFetcher(unittest.IsolatedAsyncioTestCase): async def test_html_becomes_text(self): stealth = _FakeStealth(_FakeResp( text="

Hi

Text here

")) out = await StealthFetcher(stealth=stealth).fetch( "https://a.org/p") self.assertIn("Hi", out["content"]) self.assertNotIn("