54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
|
|
from auto_reverse.doc.engine import DocEngine
|
||
|
|
from auto_reverse.models import CapturedFlow
|
||
|
|
from auto_reverse.store import FlowStore, ScopeFilter
|
||
|
|
from auto_reverse.tools import build_registry
|
||
|
|
|
||
|
|
|
||
|
|
class FakeBrowser:
|
||
|
|
def navigate(self, url):
|
||
|
|
return {"url": url, "title": "T", "elements": []}
|
||
|
|
|
||
|
|
def click(self, selector):
|
||
|
|
return {"url": "u", "title": "T", "elements": []}
|
||
|
|
|
||
|
|
def type_text(self, selector, text):
|
||
|
|
return {"url": "u", "title": "T", "elements": []}
|
||
|
|
|
||
|
|
def snapshot(self):
|
||
|
|
return {"url": "u", "title": "T", "elements": []}
|
||
|
|
|
||
|
|
|
||
|
|
def _store_with_endpoint(tmp_path):
|
||
|
|
store = FlowStore(ScopeFilter(target_hosts={"ex.com"}))
|
||
|
|
store.ingest(CapturedFlow(
|
||
|
|
method="GET", host="ex.com", path="/api/users", query={}, req_headers={},
|
||
|
|
req_body=None, status=200,
|
||
|
|
resp_headers={"content-type": "application/json"}, resp_body=b"[]",
|
||
|
|
timestamp=0.0,
|
||
|
|
))
|
||
|
|
engine = DocEngine(store, out_dir=tmp_path, title="x", use_llm=False)
|
||
|
|
return store, engine
|
||
|
|
|
||
|
|
|
||
|
|
def test_registry_has_expected_tools(tmp_path):
|
||
|
|
store, engine = _store_with_endpoint(tmp_path)
|
||
|
|
reg = build_registry(FakeBrowser(), store, engine)
|
||
|
|
names = {schema["name"] for schema, _ in reg.values()}
|
||
|
|
assert {"browser_navigate", "browser_click", "flows_search", "doc_document"} <= names
|
||
|
|
|
||
|
|
|
||
|
|
def test_flows_search_handler_returns_matches(tmp_path):
|
||
|
|
store, engine = _store_with_endpoint(tmp_path)
|
||
|
|
reg = build_registry(FakeBrowser(), store, engine)
|
||
|
|
_, handler = reg["flows_search"]
|
||
|
|
result = handler({"query": "users"})
|
||
|
|
assert any("/api/users" in ep["path"] for ep in result["endpoints"])
|
||
|
|
|
||
|
|
|
||
|
|
def test_browser_navigate_handler(tmp_path):
|
||
|
|
store, engine = _store_with_endpoint(tmp_path)
|
||
|
|
reg = build_registry(FakeBrowser(), store, engine)
|
||
|
|
_, handler = reg["browser_navigate"]
|
||
|
|
result = handler({"url": "http://x"})
|
||
|
|
assert result["url"] == "http://x"
|