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

114 lines
3.7 KiB
Python

import pytest
import json_reader
from html_reader import render_html
DOC = b"""<html><head><title>Doc</title></head><body>
<nav><a href="/top">top</a></nav>
<article>
<h1>Guide</h1>
<p>Intro text.</p>
<h2 id="auth">Authentication</h2>
<p>Use the token <code>parse_float</code> parameter.</p>
<h3>Details</h3>
<p>Deeper.</p>
<h2>Limits</h2>
<table><tr><th>k</th><th>v</th></tr><tr><td>a</td><td>1</td></tr></table>
<p><a href="/rel">relative link</a></p>
</article></body></html>"""
def test_outline_numbers_headings_and_keeps_real_anchor():
title, outline = render_html(DOC, "https://example.com/x", None, "outline", None, 2)
assert title == "Doc"
assert "@1" in outline and "Guide" in outline
assert "#auth" in outline
assert "nav" not in outline
def test_outline_without_headings():
_, outline = render_html(b"<html><body><p>x</p></body></html>", "https://e.com/", None, "outline", None, 2)
assert "no headings" in outline.lower()
def test_section_by_label_and_by_id():
_, by_label = render_html(DOC, "https://example.com/", None, "section", "Authentication", 2)
assert "parse_float" in by_label
_, by_id = render_html(DOC, "https://example.com/", None, "section", "@2", 2)
assert "parse_float" in by_id
def test_section_unknown_heading():
with pytest.raises(ValueError):
render_html(DOC, "https://example.com/", None, "section", "nope", 2)
def test_find_is_literal_and_case_insensitive():
_, found = render_html(DOC, "https://example.com/", None, "find", "PARSE_FLOAT", 1)
assert "**@2" in found
assert "parse" in found.replace("\\_", "_")
def test_find_without_match_returns_message():
_, found = render_html(DOC, "https://example.com/", None, "find", "absent", 1)
assert "No matches" in found
def test_css_selects_and_absolutizes_links():
_, table = render_html(DOC, "https://example.com/a/b", None, "css", "table", 2)
assert "| a | 1 |" in table
_, link = render_html(DOC, "https://example.com/a/b", None, "css", "article p a", 2)
assert "https://example.com/rel" in link
def test_css_invalid_selector():
with pytest.raises(ValueError):
render_html(DOC, "https://example.com/", None, "css", "[[", 2)
def test_text_mode_renders_markdown():
_, text = render_html(DOC, "https://example.com/", None, "text", None, 2)
assert "## Authentication" in text
assert "| k | v |" in text
def test_unknown_mode():
with pytest.raises(ValueError):
render_html(DOC, "https://example.com/", None, "jsonpath", None, 2)
DATA = {
"info": {"name": "pkg", "tags": ["a", "b"]},
"urls": [{"filename": "x.whl"}, {"filename": "y.tar.gz"}],
"none": None,
}
def test_shape_reports_types_without_values():
shape = json_reader.shape(DATA)
assert shape["type"] == "object"
assert shape["fields"]["info"]["fields"]["name"] == "string"
assert shape["fields"]["urls"]["type"] == "array"
def test_select_field_index_and_wildcard():
assert json_reader.select(DATA, "$.info.name") == "pkg"
assert json_reader.select(DATA, "$.urls[1].filename") == "y.tar.gz"
assert json_reader.select(DATA, "$.urls[*].filename") == ["x.whl", "y.tar.gz"]
assert json_reader.select(DATA, '$["info"]["name"]') == "pkg"
@pytest.mark.parametrize("path", ["info", "$.missing", "$.info.name.deeper", "$[9]"])
def test_select_errors(path):
with pytest.raises(ValueError):
json_reader.select(DATA, path)
def test_render_json_modes():
body = b'{"a": 1}'
assert json_reader.render_json(body, "outline", None).startswith('{"type"')
assert json_reader.render_json(body, "jsonpath", "$.a") == "1"
assert json_reader.render_json(body, "text", None) == '{"a":1}'
with pytest.raises(ValueError):
json_reader.render_json(body, "css", None)