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

122 lines
3.8 KiB
Python

import json
import pytest
import reports
def build(**overrides) -> reports.Report:
data = {"host": "example.com", "category": "js_required", "needed": "price", "url": "https://example.com/x"}
data.update(overrides)
return reports.Report(**data)
def test_add_creates_open_row(reports_file):
row = reports.add(build())
assert row.id and row.status == "open" and row.hits == 1
assert reports_file.exists()
assert json.loads(reports_file.read_text("utf-8").splitlines()[0])["host"] == "example.com"
def test_repeat_merges_and_raises_hits(reports_file):
first = reports.add(build())
second = reports.add(build(attempts=["solver"], note="shell", url="https://example.com/y"))
assert first.id == second.id
assert second.hits == 2
assert "solver" in second.attempts
assert "shell" in second.note
assert second.url == first.url
def test_host_is_normalised(reports_file):
row = reports.add(build(host="WWW.Example.COM."))
assert row.host == "example.com."
def test_unknown_category_becomes_other(reports_file):
assert reports.add(build(category="weird")).category == "other"
def test_listing_sorts_by_hits_and_filters_status(reports_file):
low = reports.add(build(host="a.com"))
reports.add(build(host="b.com"))
for _ in range(3):
reports.add(build(host="b.com"))
listed = reports.listing()
assert [row.host for row in listed] == ["b.com", "a.com"]
reports.update(low.id, "closed")
assert [row.host for row in reports.listing()] == ["b.com"]
assert len(reports.listing("all")) == 2
def test_update_status_and_note(reports_file):
row = reports.add(build())
closed = reports.update(row.id, "closed", "accepted")
assert closed.status == "closed" and "accepted" in closed.note
reopened = reports.update(row.id, "open")
assert reopened.status == "open"
def test_update_rejects_bad_status_and_id(reports_file):
with pytest.raises(ValueError):
reports.update("nope", "closed")
row = reports.add(build())
with pytest.raises(ValueError):
reports.update(row.id, "weird")
def test_counts(reports_file):
reports.add(build(host="a.com"))
other = reports.add(build(host="c.com"))
reports.update(other.id, "ignored")
assert reports.counts() == {"open": 1, "closed": 0, "ignored": 1}
def test_broken_lines_are_skipped(reports_file):
reports_file.write_text(
'not json\n{"host": 5}\n'
+ json.dumps(
{
"host": "ok.com",
"category": "other",
"needed": "x",
"id": "1",
"status": "open",
"hits": 1,
"first_seen": "now",
"last_seen": "now",
"url": "",
"attempts": [],
"note": "",
"snapshot": "",
"route": "",
"proxy": "",
"user_agent": "",
"error": "",
}
)
+ "\n",
"utf-8",
)
assert [row.host for row in reports.listing()] == ["ok.com"]
def test_row_cap_trims_oldest(reports_file, monkeypatch):
monkeypatch.setattr(reports, "_MAX_ROWS", 3)
for index in range(5):
reports.add(build(host=f"h{index}.com"))
rows = [json.loads(line) for line in reports_file.read_text("utf-8").splitlines()]
assert len(rows) == 3
assert rows[-1]["host"] == "h4.com"
def test_rows_persist_and_unknown_keys_are_tolerated(reports_file):
row = reports.add(build())
stored = json.loads(reports_file.read_text("utf-8"))
stored["expires"] = 1
stored["surprise"] = True
reports_file.write_text(json.dumps(stored) + "\n", "utf-8")
reports.add(build(host="other.com"))
hosts = [json.loads(line)["host"] for line in reports_file.read_text("utf-8").splitlines()]
assert row.host in hosts and "other.com" in hosts