5b36b3f367
Snapshot-Detailseite wird zu Modul-Tabs (Cookies & Tracking | Impressum).
Backend GET /snapshots/{id}/impressum-check laeuft den v3 ImpressumAgent auf
dem gespeicherten Impressum-Text (kein Re-Crawl); Input-Erzeugung in
impressum_input_from_snapshot() ausgelagert (pure + getestet: Text/Scope/
company_name-Fallback/None-Pfad). Frontend laedt lazy beim Tab-Wechsel und
rendert mit dem bestehenden AgentResultTab (keine zweite Engine).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""impressum_input_from_snapshot — Snapshot → ImpressumAgent-Input (pure).
|
|
|
|
Deckt die Glue des /snapshots/{id}/impressum-check-Endpoints ohne DB/LLM ab:
|
|
Text-Extraktion, Scope-Ableitung (Profil), company_name-Fallback, None-Pfad.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from compliance.api.agent_check._agent_outputs import (
|
|
impressum_input_from_snapshot,
|
|
)
|
|
|
|
|
|
def _snap(text: str = "x" * 200, **over) -> dict:
|
|
s = {
|
|
"doc_entries": [{"doc_type": "impressum", "text": text}],
|
|
"profile": {}, "scan_context": None,
|
|
"site_label": "BMW", "site_domain": "bmw.de",
|
|
}
|
|
s.update(over)
|
|
return s
|
|
|
|
|
|
def test_builds_input_from_impressum_text():
|
|
inp = impressum_input_from_snapshot(_snap())
|
|
assert inp is not None
|
|
assert inp["doc_type"] == "impressum"
|
|
assert inp["text"].startswith("x")
|
|
assert inp["company_name"] == "BMW" # site_label-Fallback
|
|
assert inp["origin_domain"] == "bmw.de"
|
|
assert isinstance(inp["business_scope"], list)
|
|
|
|
|
|
def test_none_when_no_or_short_impressum_text():
|
|
assert impressum_input_from_snapshot(_snap(doc_entries=[])) is None
|
|
assert impressum_input_from_snapshot(
|
|
{"doc_entries": [{"doc_type": "impressum", "text": "zu kurz"}]}) is None
|
|
|
|
|
|
def test_scope_includes_profile_derived():
|
|
inp = impressum_input_from_snapshot(_snap(profile={"has_online_shop": True}))
|
|
assert "ecommerce" in inp["business_scope"]
|
|
|
|
|
|
def test_company_name_prefers_profile_over_site_label():
|
|
inp = impressum_input_from_snapshot(_snap(profile={"company_name": "ACME AG"}))
|
|
assert inp["company_name"] == "ACME AG"
|