#!/usr/bin/env python3 """ The phone's photo backup section (photo-sync-settings.js), rendered in Chrome on its page (android-sync-page.js) at phone widths with names nobody would choose for a fixture. Only the Android application has this section, and its engine is Chromium, so one engine is the whole of it. The bridge is a stand-in that answers the way the phone does; the group connection (`connection-pool.js`) is replaced in the copy by one that hands out a node with long, space-free folder names, because those are what widen a page (CLAUDE.md). Four states: choosing where backups go, setting up photos, set up with a refusal showing, and setting up with only selected photos allowed. photo_sync_probe.py prints one JSON object, keyed """ import functools import http.server import json import shutil import socketserver import subprocess import sys import tempfile import threading from pathlib import Path STATIC = Path(__file__).resolve().parents[2] / "src" / "meshbay_hub" / "static" LONG_FOLDER = "Media/Photos/Family_holidays_summer_2026_at_the_seaside_with_everyone_and_the_dog" LONG_GROUP = "A_group_name_with_no_spaces_at_all_whatsoever_long" LONG_OWNER = "someone_with_a_long_handle" FAKE_POOL = """ export class ConnectionPool { async connect() { return { transport: { fetchIndex: async () => ({ roots: [{ name: 'Media', writable: true, available: true }], dirs: ['Media/Photos', 'Media/Photos/Some_Band_Complete_Discography_1992-2000_FLAC_and_more_pictures', '__FOLDER__'], }), }, ack: { photo_directories: ['Media/Photos'] }, }; } closeAll() {} } """.replace("__FOLDER__", LONG_FOLDER) PROBE = """
""".replace("__GROUP__", LONG_GROUP).replace("__OWNER__", LONG_OWNER) \ .replace("__FOLDER__", LONG_FOLDER) OUTER = """ """ class _Quiet(http.server.SimpleHTTPRequestHandler): def log_message(self, *args) -> None: pass def main() -> int: with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) / "static" shutil.copytree(STATIC, root) (root / "connection-pool.js").write_text(FAKE_POOL, encoding="utf-8") (root / "probe.html").write_text(PROBE, encoding="utf-8") (root / "outer.html").write_text(OUTER, encoding="utf-8") handler = functools.partial(_Quiet, directory=str(root)) with socketserver.TCPServer(("127.0.0.1", 0), handler) as httpd: port = httpd.server_address[1] threading.Thread(target=httpd.serve_forever, daemon=True).start() try: dom = subprocess.run( ["google-chrome", "--headless=new", "--disable-gpu", "--no-first-run", f"--user-data-dir={tmp}/profile", "--virtual-time-budget=8000", "--dump-dom", f"http://127.0.0.1:{port}/outer.html"], capture_output=True, text=True, timeout=120).stdout finally: httpd.shutdown() start = dom.find('
')
    if start < 0:
        print(json.dumps({"error": "no result in the page"}))
        return 1
    body = dom[start + len('
'):dom.index("
", start)] for entity, char in ((""", '"'), ("<", "<"), (">", ">"), ("&", "&")): body = body.replace(entity, char) print(json.dumps(json.loads(body))) return 0 if __name__ == "__main__": sys.exit(main())