Files

43 lines
1.5 KiB
Python
Raw Permalink Normal View History

from __future__ import annotations
from typing import TYPE_CHECKING
from auto_reverse.doc.engine import DocEngine
if TYPE_CHECKING:
from pathlib import Path
from auto_reverse.models import CapturedFlow
from auto_reverse.store import FlowStore, ScopeFilter
def _flow(path: str, resp: bytes) -> CapturedFlow:
return CapturedFlow(
method="GET", host="ex.com", path=path, query={}, req_headers={},
req_body=None, status=200,
resp_headers={"content-type": "application/json"}, resp_body=resp,
timestamp=0.0,
)
def test_engine_writes_spec_and_markdown(tmp_path: Path):
store = FlowStore(ScopeFilter(target_hosts={"ex.com"}))
engine = DocEngine(store, out_dir=tmp_path, title="ex.com API", use_llm=False)
store.ingest(_flow("/api/users", b'[{"id": 1}]'))
sig = store.endpoints()[0].signature
engine.document(sig)
spec = (tmp_path / "openapi.yaml").read_text()
assert "/api/users" in spec
assert (tmp_path / "API.md").read_text().startswith("# ex.com API")
def test_engine_infers_response_schema(tmp_path: Path):
store = FlowStore(ScopeFilter(target_hosts={"ex.com"}))
engine = DocEngine(store, out_dir=tmp_path, title="x", use_llm=False)
store.ingest(_flow("/api/users", b'[{"id": 1, "name": "Ada"}]'))
sig = store.endpoints()[0].signature
engine.document(sig)
rec = store.get(sig)
assert rec is not None
assert rec.response_schema is not None
assert rec.response_schema["type"] == "array"