Files
breakpilot-compliance/backend-compliance/compliance/tests/test_agb_agent.py
T
Benjamin Admin 32e45f0797 feat(agb): wire validated routed AGB engine into live check path
Consolidate the AGB C-lean engine (71% FP -> ~0, validated vs 7-company
Opus GT) onto the canonical checker library and into the live check path.

- AGBAgent.evaluate now runs routed C-lean: keyword (L1/L2) -> business-
  model gate -> per-item decision_method routing (embedding/reference/llm
  via services/checkers/) -> severity re-tiering (LOW -> recommendation),
  honoring context.skip_llm.
- New agb/_pipeline.py orchestrates the routing; agent.py stays thin.
- Remove the 3 AGB-local checker duplicates (_reference_check,
  _embedding_rescue, _llm_judge); services/checkers/ is now canonical.
- Wire "agb" into _agent_outputs._TOPIC_AGENTS so the live check emits a
  validated AGB tab (was snapshot-only).
- Run topic agents concurrently (asyncio.gather) + emit each tab via SSE
  as it finishes -> progressive results, no wait on the slowest agent.
- Tests: checker units (mocked), routed agent (gate/rescue/re-tier),
  topic wiring; existing AGB tests made offline-safe.

dev-only, no deploy.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-21 10:40:08 +02:00

53 lines
1.6 KiB
Python

"""AGBAgent (v2, routed). Embedding/LLM offline-gestubbt → kein Netzwerk."""
import asyncio
import pytest
import compliance.services.specialist_agents.agb._pipeline as pipeline
from compliance.services.checkers.base import CheckResult
from compliance.services.specialist_agents import REGISTRY, AgentInput
class _Stub:
def __init__(self, present):
self._p = present
async def check(self, ctrl, doc):
return CheckResult(present=self._p)
@pytest.fixture(autouse=True)
def _offline(monkeypatch):
monkeypatch.setattr(pipeline, "_EMB", _Stub(None))
monkeypatch.setattr(pipeline, "_LLM", _Stub(None))
def _run(text: str):
return asyncio.run(
REGISTRY.get("agb").evaluate(AgentInput(doc_type="agb", text=text)))
def test_agb_agent_registered():
assert REGISTRY.get("agb") is not None
def test_agb_detects_core_clauses():
text = (
"Allgemeine Geschaeftsbedingungen. Geltungsbereich: Diese AGB gelten "
"fuer alle Vertraege. Vertragsschluss durch Bestellung. Preise inkl. "
"MwSt. Lieferung. Zahlung. Widerrufsrecht. Gewaehrleistung. Haftung. "
"Gerichtsstand Muenchen. ") * 4
out = _run(text)
assert out.agent == "agb"
assert out.mc_total >= 1
ok = [c.label for c in out.mc_coverage if c.status == "ok"]
assert any("Geltungsbereich" in lbl for lbl in ok)
# Titel/Maßnahme kurz (ChecklistAgent-Vertrag)
assert all(len(f.action) < 110 for f in out.findings)
def test_agb_short_text_skips():
out = _run("zu kurz")
assert out.confidence == 0.0
assert all(c.status == "skipped" for c in out.mc_coverage)