Files
breakpilot-compliance/consent-tester/routes_audit_walk.py
T
Benjamin Admin cb4b352846 feat(b17): Playwright Audit-Walk-Video (Stufe 1, #7)
Nimmt einen kompletten Site-Walk als WebKit-Browser-Session
inkl. Video auf. Reviewer kann nachträglich exakt nachvollziehen,
wie die Engine zum Befund kam.

consent-tester:
  - services/audit_walk_recorder.py: Playwright record_video_dir,
    iPhone-Viewport-free 1280×800. Goto homepage → Banner-Accept
    (Best-Effort: 12 Text-Phrasen + 5 CMP-Fallback-Selektoren) →
    Footer-Links sammeln (compliance-relevant gefiltert) →
    pro Link navigate + Dwell-Time → JSON-Action-Index mit
    UTC-Timestamps + SHA-256 vom Video als Manipulation-Schutz.
  - routes_audit_walk.py: POST /scan-audit-walk; statische
    Serves für /audit-walks/{walk_id}/video.webm + walk.json.
  - main.py: Router registriert.

backend:
  - _b17_wiring.py: Triggert /scan-audit-walk, speichert
    Walk-Metadata in state["audit_walk"]. Render-Block mit
    HTML-Tabelle aller Actions (HH:MM:SS + Aktion + Detail) +
    Links zu Video und walk.json.
  - _orchestrator.py: run_b17 nach run_b16, async-aufgerufen.
  - mail_render_v2/_compose.py: audit_walk_html im V2-Layout.
  - test_b17_audit_walk.py: 8 Tests (Render-Pfade + Wiring).

Stufe-2 (Akkordeon-Expansion) und Stufe-3 (DSMS-CID-Anchor)
folgen separat.

Real-World-Smoke gegen Elli:
  - 581 KB Video, SHA-256 verifizierbar
  - 3 Footer-Links besucht (Impressum, Datenschutzerkl., Nutzungs-)
  - 6 Actions im JSON-Index

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-07 17:20:13 +02:00

54 lines
1.6 KiB
Python

"""Routes für Audit-Walk-Recorder (POST /scan-audit-walk + Video-Serve)."""
from __future__ import annotations
import os
from pathlib import Path
from fastapi import APIRouter, HTTPException
from fastapi.responses import FileResponse
from pydantic import BaseModel
from services.audit_walk_recorder import WALK_ROOT, record_audit_walk
router = APIRouter()
class AuditWalkReq(BaseModel):
url: str
dwell_s: float = 5.0
max_links: int = 8
@router.post("/scan-audit-walk")
async def scan_audit_walk(req: AuditWalkReq) -> dict:
if not req.url or not req.url.startswith(("http://", "https://")):
raise HTTPException(400, "invalid url")
walk = await record_audit_walk(
req.url,
dwell_s=max(1.0, min(req.dwell_s, 10.0)),
max_links=max(1, min(req.max_links, 12)),
)
return walk
@router.get("/audit-walks/{walk_id}/video.webm")
async def serve_walk_video(walk_id: str):
# Basic path-traversal guard
if not walk_id.isalnum() or len(walk_id) > 32:
raise HTTPException(400, "invalid walk_id")
path = Path(WALK_ROOT) / walk_id / "video.webm"
if not path.exists():
raise HTTPException(404, "walk video not found")
return FileResponse(str(path), media_type="video/webm")
@router.get("/audit-walks/{walk_id}/walk.json")
async def serve_walk_meta(walk_id: str):
if not walk_id.isalnum() or len(walk_id) > 32:
raise HTTPException(400, "invalid walk_id")
path = Path(WALK_ROOT) / walk_id / "walk.json"
if not path.exists():
raise HTTPException(404, "walk.json not found")
return FileResponse(str(path), media_type="application/json")