Files
omar 5d36fddd30
ci / static (push) Failing after 27s
ci / test-3.12 (push) Skipped
ci / test-3.13 (push) Skipped
ci / image (push) Skipped
ci / smoke (push) Skipped
ci / publish (push) Skipped
Add fetch MCP server with proxy routing, challenge solving and failure reports
Live reads go through an operator proxy pool (round-robin over the newest 100
entries, cooling on connect failures, no direct fallback); stored clearances are
replayed only on the exit that earned them. Identity, clearance, solver and
Turnstile rungs escalate automatically. fetch_pages reads up to 12 URLs four at
a time with per-item isolation. report/reports/reports_update keep a durable
queue of unreadable pages for the operator.

Ships a pinned multi-stage image (non-root 10001, data in /data), an ordered CI
with static gates, tests on 3.12 and 3.13 at 85% coverage, an offline image
smoke, and sha/latest publishing gated on main.
2026-11-28 19:29:46 +03:00

92 lines
2.8 KiB
Python

import json
import pytest
import identity
class Runner:
def __init__(self, stdout: str = "", code: int = 0, error: Exception | None = None) -> None:
self.stdout = stdout
self.code = code
self.error = error
self.args = None
def __call__(self, args, **kwargs):
self.args = args
if self.error:
raise self.error
class Done:
returncode = self.code
stdout = self.stdout
return Done()
PROFILE = json.dumps(
{
"transport": {
"profile": "safari_ios_26.2",
"headers": {"User-Agent": "UA-from-profile"},
"requests": {"headers": {"navigation": ["sec-fetch-dest: document", "user-agent", "accept: text/html"]}},
}
}
)
def test_from_profile_identity(monkeypatch):
monkeypatch.setattr(identity.subprocess, "run", Runner(PROFILE))
ident = identity.load(["wsl", "-e", "bash"])
assert ident.user_agent == "UA-from-profile"
assert ident.tls.endswith("_ios")
assert ident.as_headers()["user-agent"] == "UA-from-profile"
assert "accept" in ident.as_headers()
def test_wsl_runner_uses_cat(monkeypatch):
runner = Runner(PROFILE)
monkeypatch.setattr(identity.subprocess, "run", runner)
identity.load(["wsl"])
assert runner.args[:5] == ["wsl", "-e", "bash", "-lc", 'cat "$@"']
def test_local_path_reader(tmp_path, monkeypatch):
path = tmp_path / "profile.json"
path.write_text(PROFILE, "utf-8")
monkeypatch.setenv("MCP_SOLVER_PROFILE", str(path))
assert identity.load([]).user_agent == "UA-from-profile"
ident = identity.load([])
assert ident.user_agent == "UA-from-profile"
def test_missing_profile_falls_back(monkeypatch):
monkeypatch.setattr(identity.subprocess, "run", Runner("", error=OSError("no wsl")))
ident = identity.load(["wsl"])
assert ident.user_agent == identity._FALLBACK
assert ident.tls.endswith("_ios")
def test_broken_profile_falls_back(monkeypatch):
monkeypatch.setattr(identity.subprocess, "run", Runner("{}"))
assert identity.load(["wsl"]).user_agent == identity._FALLBACK
def test_tls_override_and_chrome_detection(monkeypatch):
monkeypatch.setenv("MCP_TLS_PROFILE", "chrome152")
assert identity._tls_for("safari_ios_26.2") == "chrome152"
monkeypatch.delenv("MCP_TLS_PROFILE")
assert identity._tls_for("chrome-131").startswith("chrome")
assert identity._tls_for("safari-26-ios").endswith("_ios")
def test_fallback_identity_is_coherent():
ident = identity.fallback()
assert ident.tls.endswith("_ios")
assert "iPhone" in ident.user_agent
@pytest.mark.parametrize("header", ["sec-fetch-dest: document", "accept-language: en-US,en;q=0.9"])
def test_navigation_headers_present(header):
assert header in identity.DEFAULT.headers