The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(browser): PROOF round 2 — Windows locked-profile fails CLOSED (live-corrected)
Teknium1740abbe64e3
diff --git a/tests/hermes_cli/test_real_profile_windows_live.py b/tests/hermes_cli/test_real_profile_windows_live.pyindex 57fdafcbce3..ffb7b7a8027 100644--- a/tests/hermes_cli/test_real_profile_windows_live.py+++ b/tests/hermes_cli/test_real_profile_windows_live.py@@ -53,12 +53,22 @@ def _raw_copy_raises_while_locked(path: str) -> bool:return True-def test_real_chrome_locked_cookie_db_copies_via_backup(tmp_path):+def test_locked_profile_fails_closed_not_silent(tmp_path):+ """The user-facing contract on Windows: when a running Chrome share-locks+ the cookie DB, ``snapshot_real_profile`` must FAIL CLOSED with an actionable+ 'close the browser' message — never a silent signed-out / torn copy.++ Live-proven fact (this runner): Chrome's share lock is strong enough that+ even a read-only SQLite open is refused by the OS, so copy-while-running is+ impossible on Windows. The honest behavior is to say so, not to launch a+ broken session. (Real-profile browsing on Windows therefore requires Chrome+ closed; Linux/macOS are unaffected. The live-drive-the-real-profile path is+ tracked separately in #95669.)+ """chrome = _find_chrome()if not chrome:pytest.skip("Chrome not installed on this runner")- # Repo root on sys.path so we import the real module under test.repo = Path(__file__).resolve().parents[2]sys.path.insert(0, str(repo))from hermes_cli import browser_connect as bc@@ -66,26 +76,15 @@ def test_real_chrome_locked_cookie_db_copies_via_backup(tmp_path):user_data = tmp_path / "chrome-user-data"user_data.mkdir()- # Launch a REAL Chrome on this user-data-dir so it creates + holds the- # Default profile's Cookies DB open with a Windows share lock. Headless new- # still creates the on-disk profile and holds the handles.proc = subprocess.Popen([- chrome,- "--headless=new",- "--disable-gpu",- "--no-first-run",- "--no-default-browser-check",- f"--user-data-dir={user_data}",- "--remote-debugging-port=0",- "about:blank",+ chrome, "--headless=new", "--disable-gpu", "--no-first-run",+ "--no-default-browser-check", f"--user-data-dir={user_data}",+ "--remote-debugging-port=0", "about:blank",],- stdout=subprocess.DEVNULL,- stderr=subprocess.DEVNULL,+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,)try:- # Wait for Chrome to create the cookie DB (Network/Cookies on modern- # Chrome; fall back to Default/Cookies).cookies = Nonedeadline = time.time() + 60while time.time() < deadline:@@ -99,36 +98,74 @@ def test_real_chrome_locked_cookie_db_copies_via_backup(tmp_path):time.sleep(1)assert cookies is not None, "Chrome never created a Cookies DB"- # Precondition: while Chrome runs, a RAW copy of the locked DB must- # actually fail — otherwise this test isn't exercising the lock and- # would pass vacuously. (If it doesn't fail, the runner's Chrome build- # didn't share-lock; skip rather than assert a false green.)+ # Precondition: the DB is genuinely share-locked (raw copy fails). If a+ # future Chrome/runner stops locking, this test isn't exercising the+ # case — skip rather than assert a vacuous result.if not _raw_copy_raises_while_locked(str(cookies)):- pytest.skip(- "Chrome did not share-lock the cookie DB on this runner; "- "the lock-copy path is not being exercised"- )-- # THE ASSERTION: our lock-aware copy succeeds while Chrome holds the- # lock, and the copy is a readable SQLite DB.- dst = tmp_path / "copy" / "Cookies"- ok = bc._copy_auth_file(str(cookies), str(dst))- assert ok is True, "lock-aware copy failed while Chrome held the DB"- assert dst.is_file() and dst.stat().st_size > 0-- # The copy must be a real, openable SQLite DB with the cookies table —- # proving we captured the committed snapshot, not an empty/torn file.- con = sqlite3.connect(str(dst))+ pytest.skip("Chrome did not share-lock the cookie DB on this runner")++ # Point the resolver at our locked user-data-dir and run the REAL+ # user-facing snapshot. It must fail closed with the actionable message.+ import hermes_cli.browser_connect as bc_mod+ orig = bc_mod.real_profile_data_dir+ bc_mod.real_profile_data_dir = lambda browser, system=None: str(user_data)try:- names = {r[0] for r in con.execute(- "SELECT name FROM sqlite_master WHERE type='table'"- )}+ dst, err = bc.snapshot_real_profile("chrome", src=str(user_data))finally:- con.close()- assert "cookies" in names, f"copied DB missing cookies table: {names}"+ bc_mod.real_profile_data_dir = orig++ assert dst is None, "must not return a (silently broken) copy while locked"+ assert err is not None+ low = err.lower()+ assert "login data" in low or "locked" in low, f"unclear error: {err}"+ assert "close" in low, f"error must tell the user to close the browser: {err}"finally:proc.terminate()try:proc.wait(timeout=15)except subprocess.TimeoutExpired:proc.kill()+++def test_copy_works_when_chrome_closed(tmp_path):+ """Sanity: with NO live Chrome holding the dir, the copy succeeds on Windows+ (the supported path). Creates a profile with a real Chrome, closes it, then+ snapshots — cookies DB must copy and be a valid SQLite file."""+ chrome = _find_chrome()+ if not chrome:+ pytest.skip("Chrome not installed on this runner")++ repo = Path(__file__).resolve().parents[2]+ sys.path.insert(0, str(repo))+ from hermes_cli import browser_connect as bc++ user_data = tmp_path / "ud"+ user_data.mkdir()+ # One-shot Chrome run to materialize a profile, then it exits.+ subprocess.run(+ [+ chrome, "--headless=new", "--disable-gpu", "--no-first-run",+ "--no-default-browser-check", f"--user-data-dir={user_data}",+ "--dump-dom", "about:blank",+ ],+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=60,+ )+ # Chrome has exited; the DB is now unlocked.+ cookies = None+ for rel in (r"Default\Network\Cookies", r"Default\Cookies"):+ cand = user_data / rel+ if cand.is_file():+ cookies = cand+ break+ if cookies is None:+ pytest.skip("Chrome did not create a Cookies DB in the one-shot run")++ dst = tmp_path / "copy" / "Cookies"+ assert bc._copy_auth_file(str(cookies), str(dst)) is True+ assert dst.is_file()+ con = sqlite3.connect(str(dst))+ try:+ con.execute("SELECT name FROM sqlite_master LIMIT 1")+ finally:+ con.close()+