"""Serve the Roborazzi report for local review: thumbnails scaled by CSS and
full images opened in a new tab. Expects a .preview/ directory mirroring the
app module layout (build/reports/roborazzi and src/test/screenshots)."""
import http.server
import os
import sys
ROOT = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".preview")
)
INJECT = """
"""
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=ROOT, **kwargs)
def do_GET(self):
path = self.translate_path(self.path)
if os.path.isdir(path):
path = os.path.join(path, "index.html")
if os.path.isfile(path) and path.endswith(".html"):
with open(path, "r", encoding="utf-8") as f:
html = f.read()
html = html.replace("